Jump to content
  • Advertisement
Sign in to follow this  
shahmirj

Rotation after Collision

This topic is 3649 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Any one here can help me or point me to the right Direction would be nice I have collided and solved the impulse of 2 polygon objects now i want to do the last and hard part which is rotate them according to the collision. I need to basically figure out the Angular Velocity of the objects. My program can rotate objects clockwise and anti clockwise using positive or negative angular velocity. Any body here can even post a link to somebody who has explained this would be nice. Thanks

Share this post


Link to post
Share on other sites
Advertisement
Depends, if you want a 'true to life' example, you will need to consider momentum of inertia, mass, copute the points of contact, apply collision impulse at the points of contact, that will change your linear and angular momentum.

Look at Chris Hecker's article on physics for a full explanation, and I have a rigid body demo as well.

Share this post


Link to post
Share on other sites

int FindSupportPoints(const Vector& N, float t,
const Vector* A, int Anum,
const Vector& PA, const Vector& VA,
const Matrix& OA, Vector* S)
{
Vector Norm = N ^ OA;
float d[32];
float dmin;
dmin = d[0] = A[0] * Norm;

for(int i = 1; i < Anum; i ++)
{
d = A * Norm;

if (d < dmin)
{
dmin = d;
}
}

int Snum = 0;

const float threshold = 1.0E-3f;

for(int i = 0; i < Anum; i ++)
{
if (d < dmin + threshold)
{
S[Snum++] = Transform(A, PA, VA, OA, t);

if (Snum == 2)
return Snum;
}
}
return Snum;
}



Thats from the doc in that link you gave me ollii. Here is what i dont understand

The parameter Vector A, Should be one entity of a vector and not a whole list. Is A donating all the points in the polygon.

Also N is that the minimun Interval Axis or is that each axis we go by.

OA is another concept that completely flies over my head.

You see in my code the objects are rotated by changing each of the points of the polygon from the center point of the polygon. Therefore i dont understand the concept of OriginalA, Is that part to do with rotating the point on an angle.

The whole conecpt of that function is just going straight over from my head.

Im sorry any ideas?

Share this post


Link to post
Share on other sites
The function gives you the supporting vertices along a given direction. That is, if you imagine a box sitting flat on a table, and the supporting axis vertical, (vector(0, 1)), the function will give you the two vertices at the bottom of the box. in 2D, there is only a maximum of two vertices that can support a convex object.

OA is the orientation matrix, and it is derived from the orientation angle.


OA = ( cos(a) sin(a) )
(-sin(a) cos(a) )


PA is the centre of the object A. VA its velocity. the array S[] is the support opint of the polygon, transformed by the polygon's orientation, position and velocity. Basically the position of the supporting vertex at time t.

All this support point malarkey it to compute the contact points on an object.

If you have a sphere, it's much simpler, since there will always be one.

BTW, that code would be simpler if the contact points stored in the collision report were all relative to the bodies's space. So there would not be any transforms until the collision is resolve. I'll sort it out later.

EDIT : You've been looking at the docs. Ignore them, they are old stuff that's been deprecated. The code in example 7 should make more sense.

Share this post


Link to post
Share on other sites
Quote:
PA is the centre of the object A. VA its velocity. the array S[]


I have all that i have also calculated the S[]

Obviously as i understand it. Before i can even begin about rotation i need the support points or in other words exactly where are the polygons colliding

Thats is the part that is confusing me beyond repair

Cause i look at the Tutorial 7 and i find we need pa and pb


Vector pa = m_contacts.m_contact.m_position[0];
Vector pb = m_contacts.m_contact.m_position[1];
Vector ra = pa - a->m_position;
Vector rb = pb - b->m_position;


If i can get pa and pb i can get ra and rb, and if i can get ra and rb i can do

a->m_angvelocity += (ra ^ impulse) * a->m_invinertia;
b->m_angvelocity -= (rb ^ impulse) * b->m_invinertia;

lets just leave the impulse and m_invinertia alone for now.

So if you can simplify this for me.. The contact points. how do i get that projection.

Please let me show you my code so you understand at what point have i gotton

bool pPhysics::PolyCollision(int index){

float Interval;
float minInterval = 0.0;
Vector translationAxis;
Vector axis;
Vector Vab, Vn, Vc, Vt;

//Return the Object
cObjects* obj = getObjects();

//calculate the min interval and the translation axis using the seperation axis theorm

//Push Back the Object using the Translation Axis
//Round the the Values so we dont end up inside again
ov.position.x += floorf((minInterval * translationAxis.x) * 0.5f);
ov.position.y += floorf((minInterval * translationAxis.y) * 0.5f);

//os.v = os.v - Vc;

Vab = os.v - obj->poly[index]->os.v;
float dot = Vab.DotProduct(translationAxis);
Vn = translationAxis * dot;
Vt = Vab - Vn;

Vc = (Vt * -1) + (Vn * -2);

float MassA = os.mass / (os.mass + obj->poly[index]->os.mass);
float MassB = obj->poly[index]->os.mass / (os.mass + obj->poly[index]->os.mass);

if (!obj->poly[index]->isStatic) { obj->poly[index]->os.v = obj->poly[index]->os.v - (Vc * MassA); }
os.v = os.v + (Vc * MassB);

os.v.Round();


//Return true to say there has been a collision
return true;
}




Note: it dosent show the objects being tranlated to their new angles. But it does it in another function so therefore imagine if they are. The actual loops do the SAT but they are left out as we are not discussing about that, so the minInterval and translationAxis are calculated using that theorm, Also elacticiyt and Friction is left at constant for now

Share this post


Link to post
Share on other sites
There is a difference between the support points and the contact points.

I use the support points to derive the contact points.

in 2D, there are three main cases for finding out the contact points.

1) vertex on A vs edge on B.
2) edge on A vs vertex on B.
3) edge on A vs edge on B.

the other case (vertex on vertex) should never occur, but what the hell, it's handled as well.

finding the support points will give you one of the three cases. You will find that the supports will either be an edge (2 points) or just a vertex (one point).

So, given the support point configuration, you can derive the contact points (which is what example 6 is about).

to derive the contacts from the supports, it's relatively straight forward in 2D, and quite intuitive.

see picture below.



case 1), it is vertex [C] against an edge [AB].

[A] and will be the support points on polygon 1, [C] will be the support point on polygon 2.

contacts work by pairs. You need one point on contact on each polygon. Therefore, from the case 1), contact on polygon 2 will be the vertex [C] itself, and the contact on polygon 1 will be the point on edge [AB] closest to [C].

for case 2), both support are edges (respectively [AB] for poly 1, and [CD] for poly 2). There are several methods to find the contact points (vertices [C] and , paired with their projections on the opposite edges).

I used a rather simplistic approach, by finding all possible 4 contacts pairs for [A], , [C] and [D], pairing them with the closest points on the opposite edge, and sorting the contacts by distance between the points in the pairs. The obvious choices would be the two contact pairs with the minimum distance.

This 'closest point' method isn't the fastest, but it's very simple. All you need to know is the three possible cases you can be confronted with, and what support vertices converts to what contact points in the three cases.

so, the principle is this.

1) perform the SAT test.
2) find the MTD vector.
3) the MTD will give you the normal of collision and distance of intersection.
4) find the support vertices on both polygons along the normal of collision. You will have either one, or two support vertices for each polygon.
5) from the support point configuration, derive the contact pairs. You will have a maximum of two contact pairs.
6) compute the impulse at the contacts. that impulse will generate linear change in momentum, and a angular change on momentum.

Hope that helps

Share this post


Link to post
Share on other sites
Thanks man starting to make alot more scence

Let me first try to rig up the contact points and then figure out the support points.

Its alot clearer when i understood the difference between the two.

I think i might have a problem later in actually figuring out the rotation velocity after this step. But we will see when we get there.

Il post if i have further problems, And post the final result if it works

Thanks ollii you are the best

Share this post


Link to post
Share on other sites
you're welcome. Do look at Chris Hecker's articles on physics. It's basic Newtonian A level physics, or about. It uses the conservation of momentum to derive the equations.

Share this post


Link to post
Share on other sites
On the Third Post

Is "A[0] * Norm;" is equall to A.DotProduct(Norm)

Or are you multiplying

If you are multiplying how are you getting a float number by multiplying two vectors together?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!