onsdag 13 mars 2019

Finished!

The simulation is now finished.

We made the final large addition of being able to control the ball. This means hitting the ball with different golf clubs. The putter is bound to the left mouse button, the drive to the middle one, and the wedge to the right mouse button.

To make the simulation better, we also made some final tweaks to the wind and friction values. The decision was also made to include some boundary walls to the course, in order for the ball to not fly off.

The changes can be seen in the final video, showing a demonstration of the final simulation. 

The course:

The boundary wall:

tisdag 12 mars 2019

Camera, wind, angular friction, air resistance

Today was spent implementing some smaller systems and tweaking some details. We created simple systems for simulating wind and air resistance. When implementing friction, we stumbled into some issues with the models, and decided to simplify the problem slightly. The result was a less realistic and sophisticated model, but much less work required for the implementation.

A very simple camera controller script was also made.

måndag 11 mars 2019

Golf course

We spent an afternoon designing and constructing a simple golf course using planes of different materials. Calculating the positions of the planes so that there would be no gaps was surprisingly time-consuming. It was done through repeated simple trigonometric equations. The resulting golf course can be seen in the video below (to be added). Note that we also added the skybox from lab 2 into the scene.



Additionally, we fixed a problem with the ball intersecting with the plane. It was an issue concerning the order of updating positions and calculating velocities. Now the ball is able to rest on a surface instead of sinking into it repeatedly.

onsdag 6 mars 2019

Material rendering

Materials can now be rendered. In the current state, this simply means that each type of collision material has a .mat file associated with them, which is loaded at the start of the simulation. The .mat file is currently just a simple material with no texture, just a flat color, but it will be easy to change the texture of the materials at a later time.

See some example use of the materials in the video below:



Note that changing material also changes friction/energyloss values but since those aren't added yet the simulation breaks


tisdag 5 mars 2019

Collision response and friction works! Materials do not.

We were able to finish the implementation of collision response and friction. The friction model we use is an Impulse-based friction model. Here is the Wikipedia article: https://en.wikipedia.org/wiki/Collision_response#Impulse-based_friction_model.

The results can be seen in the video below.



Note that only the friction for the test material has been implemented and tested. The other materials that are planned have not been tested or been given proper values.

We also started to overhaul the materials, and so far most of it works. Work still remains on getting the materials to render properly.

måndag 4 mars 2019

Started to implement collision response

We have started to implement the collision response method mentioned in our previous blog post. To our help we have used the inertia tensor of a solid sphere, which we found in this Wikipedia article: https://en.wikipedia.org/wiki/List_of_moments_of_inertia#List_of_3D_inertia_tensors.

The response seems to work partially, where the balls collide with and are stopped by the planes, but no bouncing seems to occur. This can be seen in the video below.


fredag 1 mars 2019

Potential collision response method

While exploring the subject of collision response, we found something called the impulse-based reaction model. Here is the Wikipedia article: https://en.wikipedia.org/wiki/Collision_response#Impulse-based_reaction_model

If we want to use this model for collisions between ball and planes, we will be able to simplify it by assuming that the plane has a mass approaching infinity and has no velocity. Including energy loss and friction in our collisions will be possible, through the impulse-based friction model.

The models require us to simplify the collisions to be instantaneous rather than to happen during a period of time. The models also require us to implement a way for the balls to have an angular velocity.

torsdag 28 februari 2019

Cleanup and physics exploration

Today we did some cleanup of the code in the old project that we base our project on. This involved some standardizing of code style, and separating some code into smaller functions and classes.

We also started implementing different materials for the surfaces of collision.

We tried exploring how to realistically implement collision reaction. In the process, we broke the old code. Now the balls cannot bounce off surfaces at all, they land and get stuck on the plane. Figure 1 shows this behavior.

Figure 1

To aid or exploration of the subject, we came across these videos explaining collision in a context similar to ours:

https://www.youtube.com/watch?v=1IvUNya9Zf0

https://www.youtube.com/watch?v=hz_KCgV_nkw

Our next step will be to adapt and implement what is said in the videos to three dimensions and non-vertical walls.

måndag 25 februari 2019

Project Specification



Golf Course Simulation using Unity

Specification of project in DD1354 Models and Simulation 

Royal Institute of Technology KTH



Michael Mathsson  mathsso@kth.se

Anders Steen     astee@kth.se


Grade ambition: C

1 Background

Collision detection is a physical phenomenon that is very naturally part of our world. Therefore, a physical simulation that does not implement collision detection will be extremely lacking. Multiple different methods exist for simulating collisions, with varying sophistication. The geometry of an object determines the best way of detecting collisions. Spheres, e.g golf balls, are defined by a point in space and a radius. Detecting collisions between spheres simply means checking whether the points of two spheres are closer to each other than the sum of their radii.

Simulating realistic collisions does not only involve correctly detecting the collisions, but the simulation responding to the collision in a realistic manner. Objects bouncing off surfaces should have their momentum changed according to certain rules. For instance, a golf ball landing on grass will bounce in a way distinct from a golf ball landing in sand.

The interest for this kind of simulation came from lectures in the course and a collision detection project done by other students. Another source of inspiration is games such as Wii Sports Golf, which implements collision detection and reaction in a real-time gameplay setting.

The base of the project is an unfinished project by one of the group members which implements simple circle-plane hit detection and pseudo-physics for collisions.


2 Problem

Implementing collision detection between a sphere and a plane or mesh, as well as simulating realistic collision reaction is the initial problem. This means changing an object’s momentum according to attack angle, velocity and material of the colliding objects. Achieving further realism is the secondary problem. Implementing wind simulation and creating a realistic golf course environment are included in this secondary problem.


Figure 1

3 Implementation

The first implementation goal is to create working collision detection and reaction between a sphere and a plane and mesh. This will be done in Unity using a combination of Unity’s built-in objects and our own collision detection methods. As few Unity assets as possible will be used, they are only meant to provide visuals for the simulation.

After the implementation of the core features is complete, more variation will be introduced. This will be in the form of different materials of colliding objects creating different collision reactions. Air resistance and wind changing the momentum of golf balls will also be implemented if time permits.
The final result will be a real-time simulation in Unity that handles collision detection and reaction in a golf course setting. The realism of the simulation will depend on how difficult the core features turn out to be to implement. See Figure 1 for a conceptual picture of the best-case end result.

3.1 Specification ideas

Our planned features, in descending order of relevance and priority.

  • Collision detection
    • Sphere to plane 
    • Sphere to sphere 
    • Sphere to mesh 
  • Realistic bouncing 
    • Correct angle 
    • Realistic conservation of energy 
  • Collision with different materials 
    • Bounciness varying based on terrain 
    • Friction when rolling 
    • Materials: 
      • Grass 
        • Rough 
        • Green 
        • Fairway 
      • Sand 
      • Water 
  • Wind simulation 
    • Air resistance 
      • Specific to the shape of a golf ball
    • Affecting golf balls 
    • Calculated using rigorous methods such as Navier-Stokes equations
  • Aesthetically pleasing environment 

4 Risks and challenges

Below is a table describing potential risks and challenges specific to this project.

DescriptionContingency plan
Finding accurate physics equationsIf we can’t figure out how it works in reality we can complement it with pseudo-physics.
Combining Unity assets with our codeEither use more of Unity’s assets or make our own assets and settle for an ugly simulation and more work required.
Some physical phenomenon are difficult to implementThose difficult features can be discarded from the project, be simplified or possibly included through unity assets.

5 References

  1. Project blog: https://modsimspheres.blogspot.com/
  2. Collision detection in course lecture slides: https://www.kth.se/social/files/5c5c028f56be5b3639e2695f/DD1354%20Particle%20Systems%20and%20Collision%20Detection%202019.pdf
  3. Descriptions of collision reaction: 
    1. https://en.wikipedia.org/wiki/Inelastic_collision
    2. https://en.wikipedia.org/wiki/Momentum#Conservation
  4. Wii Sports Golf example: https://www.youtube.com/watch?v=-Mm7xoaTzdM