Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

BigMac

Rotating points (plane)

This topic is 5231 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

Hello, I''ve got 3 vertices and I use them to create the plane. I would like to rotate the plane so I could detect collisions precisely. I don''t know how to start. Is there any easy way to rotate the plane ? I thought that I could multiply the plane''s normal by rotation matrix but it would be rotated around the origin (0,0,0), I guess ? So maybe should I multiply all points by rotation matrix ? But what should that matrix look like ? Like this (y rotation):? |cos(angle) 0 sin(angle) point1.x| | 0 1 0 point1.y| |-sin(angle) 0 cos(angle) point1.z| | 0 0 0 1 | I really don''t know how to do it Thanks in advance for any help.

Share this post


Link to post
Share on other sites
Advertisement
just rotate the normal, and keep using that point in the plane to calculate D in:

A x + B y + C z + D = 0

that should work.

Assuming your collision detection code uses planes as vec4s.

Share this post


Link to post
Share on other sites
*sigh*

stating what the plane equation is rarely helps anyone, try this:

let me explain what this does. given a point you want to rotate 'p', the angle you want to rotate it 'theta' and a line about which 'p' will rotate, RotPtByLn returns the new positon.

p1 should be the center of the triangle, p2 the normal + the center, and p is one of the verts. This should do the trick, but remember to always precalculate the normal and center to use during all three rotations because it will change as you move each vertex.

Tell me if this helps

EDIT: oh, V3F is just defined as "typedef D3DXVECTOR3 V3F;"


//-----------------------------------------------------------------------------

// Name: RotPtByLn()

// Desc:

// Auth: http://astronomy.swin.edu.au/~pbourke/geometry/rotate/

//-----------------------------------------------------------------------------

V3F RotPtByLn( V3F p, float theta, V3F p1, V3F p2 )
{
D3DXVECTOR3 u, q1, q2;
float d;

q1.x = p.x - p1.x;
q1.y = p.y - p1.y;
q1.z = p.z - p1.z;

u.x = p2.x - p1.x;
u.y = p2.y - p1.y;
u.z = p2.z - p1.z;

u /= sqrtf( u.x * u.x + u.y * u.y + u.z * u.z );

d = sqrtf( u.y * u.y + u.z * u.z );

float temp = d;

if( temp < 0 ) temp = -temp;

if( temp > 0.000001 )
{
q2.x = q1.x;
q2.y = q1.y * u.z / d - q1.z * u.y / d;
q2.z = q1.y * u.y / d + q1.z * u.z / d;
}
else
{
q2 = q1;
}

q1.x = q2.x * d - q2.z * u.x;
q1.y = q2.y;
q1.z = q2.x * u.x + q2.z * d;


q2.x = q1.x * cosf( theta ) - q1.y * sinf( theta );
q2.y = q1.x * sinf( theta ) + q1.y * cosf( theta );
q2.z = q1.z;

q1.x = q2.x * d + q2.z * u.x;
q1.y = q2.y;
q1.z = - q2.x * u.x + q2.z * d;

temp = d;

if( temp < 0 ) temp = -temp;

if( temp > 0.000001 )
{
q2.x = q1.x;
q2.y = q1.y * u.z / d + q1.z * u.y / d;
q2.z = - q1.y * u.y / d + q1.z * u.z / d;
}
else
{
q2 = q1;
}

q1.x = q2.x + p1.x;
q1.y = q2.y + p1.y;
q1.z = q2.z + p1.z;

return q1;
}


[edited by - Mulligan on February 27, 2004 12:23:08 PM]

Share this post


Link to post
Share on other sites
Thank you all for reply

Mulligan:

In my case isn't it esasier to calculate the new normal and distance than to multiply all 3 points and then create the plane?

I'm rather new at all this staff and I'm just worried that your approach is out of my league at this moment

Regards.



[edited by - BigMac on February 27, 2004 2:47:55 PM]

Share this post


Link to post
Share on other sites
well, i probably dont full understand what youre doing i guess. What are you trying to accomplish? Some background info would do.

Share this post


Link to post
Share on other sites
I''ve got a bounding box consisted of 3 planes. I want them to rotate with the object so I could detect collisions more precisely.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!