15-462 Programming Lab 4: Physics Simulation
Due Tuesday, December 6th, 11:59 PM
Overview
In this assignment, you will be implementing a simple physics
simulation. You will implement physically-correct motion of
simple geometrical objects in an environment. For this, you will
need to know how to handle physical object properties that cannot
be directly observed, such as mass and momentum. Your code will
be required to model sphere/plane and sphere/sphere collisions,
but you can do more if you wish. As with the previous starter
codes, the code you are provided with will extend the ray tracer
starter code so that you will be able to combine any part(s) of
the previous three labs if you wish.
Briefing of Tasks
- Applying Forces - First, you will need to
implement basic forces acting on your objects, such as
gravity and initial velocity, as your world evolves in
time. In order to do this, you will need to update
your world by a realistic timestep. This will make
your objects look like they have some mass.
-
Collision Detection - Finding a collision in a
physics world will be similar in some ways to your ray
tracer implementation. You will need to use
mathematical representation of your objects to solve
for intersections. Keep efficiency in mind since your
simulation is supposed to run in real time.
-
Collision Response - Your objects need to react
realistically when they hit each other. Depending on
the contact points between objects, you will determine
the exchange of momentum between them.
- Test! - The final step will be to make sure that
there are no bugs in your simulation that
break it severely. Some minor errors should be
expected as your simulation updates are at descrete
timesteps and if some objects are moving too quickly
or the timestep is too large, your object may fail to
collide. There are ways to compensate for this but are
not required.
Basic Physics
Rigid body movements rely on mainly on a few formulas
Force: F = ma
Momentum: p = mv
Conservation of Momentum: p1 = -p2 (remember that this is per-axis)
Implementation
Starter Code
The starter code [1]
has been set up to be able to built in both Visual Studio 2005 and with the Makefile
in Linux. As mentioned before, the starter code should be familiar to you from the
previous projects, and so objects are loaded in the same way that they are in the
ray tracer with modifications to load in other attributes such as mass and initial
velocity.
A good starting point will be to understand how the various objects work in the
normal renderer. The Scene loads a Gravity Vector and each SceneObject loads with
a mass, initialVelocity, and initialTransform. The two parts you will need to
update on the Scene will be the Matrix currentTransform and Vector
currentVelocity in the SceneObject classes. The currentVelocity
variable is there only as a placeholder for you to use to be able to update
the objects' transformation matrix. As a side note, a mass of 0.0 or less should
mean infinite-mass or one that is not affected by forces such as gravity.
The transformation matrices are ordered such that the member variables
are accessed as _RowColumn. e.g. matrix._14 gives the element at row-1, column-4.
There are a couple of additional functions that have been added in Utils.h for your
convenience also: BuildTranslation, BuildRotationX,
BuildRotationY, BuildRotationZ, BuildScale,
and finally BuildTransform which combines all together.
Grading Criteria
Your program must:
- (20%) have objects move realistically with forces and updates
- (20%) detect Sphere-Sphere Collision
- (20%) detect Sphere-Plane Collision
- (25%) handle Collision Response
- (10%) be reasonably commented and written in an understandable manner-- we will read your code.
- (5%) be summitted along with at least 1 good test scene file to demonstrate your simulation features.
You must also submit a movie of 99 frames maximum in JPEG named (00.jpg - 99.jpg).
Put XML scene files and corresponding .3ds or .obj files in a sub-directory called scenes
and JPEG files in a sub-directory called images.
- (required) Be submitted along with a readme file documenting your program's features and
describing the approaches you took to each of the open-ended problems we posed here.
This is especially crucial if you have done something spectacular for which you wish
to receive extra credit!
- (required) Be submitted to your turnin directory as documented in the
submission section.
Submission
Please submit your project to
/afs/andrew/scs/cs/15-462/turnin/your_andrew_id/.
Copy your modified src directory into that directory.
When we run "make" in the src directory it should compile your program successfully.
Also within asst4, make a sub-directory called scenes and images,
and place your representative XML scene files and JPEG snapshots into the
respectively sub-directory.
Tips
- Start this assignment as soon as you can. This project may not be
as tough and long as the ray tracer but can still take a long time to get right.
- Review the ray tracer write-up to understand the scene format and getting a
general idea of how things should work.
- Again, think before you hack! There are several cases that need consideration.
To give one, the conservation of momentum may end up giving you extra velocity each
time and might need damping.
- Leave time to work on your representative screenshots.
You'll want to show off your work! Especially if you integrate it with the ray tracer.
Extras
Here are some suggestions for extra credit ideas:
- Angular Momentum - implement angular momentum.
- Warped-Sphere - allow ellipsoidal sphere to work.
- Convex Hulls - allow your simulation to handle more than just round-objects.
- Spatial Partitioning: put your model objects in an octtree, BSP tree, or spatial
hash data structure to accelerate your collision detection.
- Ray-traced Simulation - (WARNING: THIS MAY TAKE A WHILE TO RENDER!)
Other cool things will get extra credit as well (talk to the TAs before you actually implement it).
Please note that the amount of extra credit awarded will not
exceed 10% of this assignment's total value.
Links
[1] Starter
code