Sign in to follow this  
too_many_stars

Physical (non user input) 2D rotation help

Recommended Posts

Hi Guys,

 

Without user assisted rotation, I am unsure how to best to program a rotation for a simple physical OBB simulation.

 

Given a single OBB, and a "ground" with a normal of (0.0f,-1.0f), a Vector 2D class, and a Matrix 2D class with a defined rotation function and the following integration as found here:

 

http://gamedevelopment.tutsplus.com/tutorials/how-to-create-a-custom-2d-physics-engine-oriented-rigid-bodies--gamedev-8032

void OBB::integrate(float dt){


	if(i_mass==0.0f)
		return; 

	vel+=gravity*dt;
	ang_vel+=torque/moment_of_inertia*dt;
	center+=vel*dt;
	orient+=ang_vel*dt;

	
	calcNormals();
	
}

what happens and where after a contact with the ground. For example, knowing the contact point(s), when and where is the Matrix 2d class rotation function called, and how often?

 

How exactly is an impulse applied to a point?

 

How does one store the rotation of an object without resetting to 0 degrees on each update, and then re rotating it back to a desired position?

 

I am unable to walk my way through the entire rotation processes from start to finish without getting confused.

 

Thanks,

 

Mike

 

 

Share this post


Link to post
Share on other sites

A rigid body will store it's current orientation somehow. In 2D you can store a scalar value which represents a rotation about the conceptual z axis. Then, to render the OBB you can construct a rotation matrix from this scalar. However, when you integrate the orientation you only apply a portion of the angular velocity to the current orientation. This represents stepping forward in time by some small amount.

 

If you take any point on a rigid body and wish to calculate it's velocity (the body can be spinning and translating), the equation is:

 

velocityAtPoint = v + cross( w, r )

 

Omega (w) is angular velocity. V is linear velocity. r is the vector from COM to the point in question. This equation is in a lot of text books and online, and falls under the category of relative motion and rigid body dynamics. Here's a nice webpage on this I just googled: http://emweb.unl.edu/NEGAHBAN/EM373/note15/note.htm

 

So if we want to apply an impulse to a rigid body we can make use of a similar equation and do:

 

linearVelocity += impulse

angularVelocity += Cross( r, impulse )

 

The above equations will apply an instantaneous change in velocity. Usually we multiply these lines by inverse mass and inverse moment of inertia when applying equal and opposite forces to two rigid bodies simultaneously (see the bottom of the article you linked). Usually this kind of equation is called "r cross f", where we take a vector from center of mass to the point in question, called r, and cross it with a force (or in our case an impulse).

 

So the whole process might look like:

 

Compute collision pairs

Find point of contacts for each pair

Apply impulses to each point of contact for the two associated rigid bodies

Use the final velocities for integration, where we update position a single time

Go back to step 1

Edited by Randy Gaul

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this