CMPT466 - Computer Animation
Programming Assignment 3:
Rigid Body Simulation (15 points)
Spring 2025
Due date: 23:59 Tuesday April 1, 2025
Marks for late assignments will be discounted by 10% each day. That is, if you are one day late, your marks will be multiplied by 0.9, two days late by 0.9*0.9 …
In this assignment, you are going to implement a rigid body simulator using forward dynamics. You will need to simulate the motion of two rigid bodies (a dice and a ball) when they are dropped from mid-air and collide onto the ground. The coding environment will be in Unity.
Unity Setup
To begin, download and extract CMPT466-Assignment3.zip. Open the extracted folder
CMPT466-Assignment3 as a Unity project in Unity Hub and select 2022.3.56f1 as the editor version. Later versions should also work, but if you run into issues, use the listed version. It
should take a while to open the project for the first time.
Once the project is opened, open the scene in Assets → Scenes → Assignment3 to begin the assignment.
Demos
Demo link: Assignment3Demos
Project Script. files
All the C# script. files are contained in Assets/Scripts folder. Here are some brief details on what they do:
1) CameraController.cs
This script. controls the camera movement. If you like, you may modify this script to have the controls bind to different keys.
2) StateController.cs Do not edit this file.
This script. adds key controls to control the simulation state.
3) Matrix3x3.cs Do not edit this file.
This script. defines a 3x3 Matrix class which you can use for this assignment. The documentation is documented in the file.
4) BaseRigidbody.cs File you need to modify.
This script. will be the file that simulates the motion of a rigid body. All the forward dynamics should be implemented here.
5) DiceRigidBody.cs File you need to modify.
Script. for Dice rigid body that extends the base rigid body and overrides the local vertices and inertia matrix.
6) BallRigidbody.cs File you need to modify.
Script. for Ball rigid body that extends the base rigid body and overrides the local vertices and inertia matrix.
Introduction to the project
When you first open the project, you’ll be greeted with two dice and two balls in the scene.
The white objects will move according to your implementation of the forward dynamics. The yellow objects will follow the dynamics from Unity’s built in physics engine. When you first run the project, the white objects will not move since nothing has been implemented yet. However, the yellow objects will begin to fall and collide with the ground.
You can press ‘r’ to reset the simulation state, press ‘space’ to pause the simulation, and press ‘right arrow’ to advance a single timestep while the simulation is paused.
There are some simulation parameters for each rigid body that you can change via the Unity editor interface. Click on the respective GameObjects (WhiteDie and Ball) and you’ll see some properties you can modify under their script. components. Here are the default values when you first open the project:
Here is a brief description of what they do:
• Initial Position: The initial position of the object. This also changes the initial position of the corresponding yellow object.
• Initial Rotation: The initial orientation of the object. The corresponding yellow object will have the same initial orientation.
• Initial Velocity: The initial velocity of the object. The corresponding yellow object will have the same initial velocity.
• Dt: The simulation step of the object. The corresponding yellow object will have the same value.
• Mass: The mass of the object.
• Ks: The penalty coefficient.
• Kd: The damping coefficient.
• Mu: The coefficient of friction.
Note that the parameters mass, ks, kd, mu are exclusive only to the white objects and do not affect the yellow objects.
Part 1: Inertia Matrix
(0.5/15 points) Implement the InertiaRefMatrix in DiceRigidbody.cs.
(0.5/15 points) Implement the InertiaRefMatrix in BallRigidbody.cs.
You can refer to lecture notes for the inertia matrix of different shapes.
Part 2: Collision Detection
(2/15 points) Complete the following function:
private List GetCollidedVertices()
This function should return a list of the object’s vertices which have collided onto the ground. You can assume that the ground is at height zero, thus a vertex is in collision when its y value is negative.
You are given a list LocalVertices which contains the local positions of the vertices that are relative to its center of mass. You must first transform. them into global positions before checking for ground collision.
Part 3: Calculate Forces and Torques
(5/15 points) Complete the following function:
private (Vector3, Vector3) ComputeForceAndTorque()
This function should return the net force and net torque applied to the object at the current simulation state. You can assume a gravity of -9.81. The penalty method should be used to compute the collision force on each collided vertex, and you will need to take account of the damping force and dynamic frictional force. You must aggregate each vertex’s collision force and torque into the net force and torque.
You will need to use the properties mass, ks, kd, mu to compute the relevant forces. Their values can be modified via the editor, as described before.
Part 4: Integrate Timestep
(4/15 points) Complete the following function:
private void Integrate(float deltaTime)
This function should update the position, rotation, linear_velocity, and angular_velocity state variables with simulation timestep deltaTime. It should be implemented using the Semi-Implicit method.
You can get the inertia matrix of the objects via IntertiaRefMatrix property. Note that this returns the inertia matrix in an object’s local body frame, you’ll have to transform it into the global frame. given the object’s current rotation state.
After you’ve implemented part 1 through 3, you should see the objects start to fall and tumble on the ground. If you’ve implemented everything correctly, your results should be similar to the result shown in demo1.mp4 in the demo folder. The default parameters are used in this demo.
Part 5: Parameters Tuning
(1.5/15 points) As you may see, simulating the objects with default parameters does not resemble the simulation of the yellow objects. Try to play around with the parameters and report the best values you can find that can result in a similar motion as the yellow objects in a text file answer.txt. Ensure you have reported the parameter values for both the die and the ball.
For reference, you may have a look at demo2.mp4 to see what the simulation can look like with some better parameter values.
(1.5/15 points) In answer.txt, write a few sentences to explain how you can achieve different motions by tuning each parameter.
Submission
Please create a zip named studentid.zip (e.g. 123456789.zip) containing your BaseRigidbody.cs, DiceRigidbody.cs, BallRigidbody.cs, and answer.txt. At the top of your files, please leave a comment that includes both your name and student id.
Submit your zip file on CourSys.