![]() |
| | #1 |
| 'AlHamdulillah Join Date: Feb 2003
Posts: 790
| rotation mathematics.... equation 3.12 Code: // R is the rotated vector P, O is the angle of the rotation R.x = P.x cos O - P.y sin O; R.y = P.y cos O + P.x sin O; now, then there is equation 3.19 which is rotating about an arbitrary axis represented by a unit vector Code: //again, R is the rotated vector, A is the axis, and P is the original Vector, and O is the angle which the vector is rotated //through R = P cos O + (A X P) sin O + A(A . P) (1 - cos O); now my question is, how does game tutorials get this : Code:
void CCamera::RotateView(float angle, float x, float y, float z)
{
CVector3 vNewView;
// Get the view vector (The direction we are facing)
CVector3 vView = m_vView - m_vPosition;
// Calculate the sine and cosine of the angle once
float cosTheta = (float)cos(angle);
float sinTheta = (float)sin(angle);
// Find the new x position for the new rotated point
vNewView.x = (cosTheta + (1 - cosTheta) * x * x) * vView.x;
vNewView.x += ((1 - cosTheta) * x * y - z * sinTheta) * vView.y;
vNewView.x += ((1 - cosTheta) * x * z + y * sinTheta) * vView.z;
// Find the new y position for the new rotated point
vNewView.y = ((1 - cosTheta) * x * y + z * sinTheta) * vView.x;
vNewView.y += (cosTheta + (1 - cosTheta) * y * y) * vView.y;
vNewView.y += ((1 - cosTheta) * y * z - x * sinTheta) * vView.z;
// Find the new z position for the new rotated point
vNewView.z = ((1 - cosTheta) * x * z - y * sinTheta) * vView.x;
vNewView.z += ((1 - cosTheta) * y * z + x * sinTheta) * vView.y;
vNewView.z += (cosTheta + (1 - cosTheta) * z * z) * vView.z;
// Now we just add the newly rotated vector to our position to set
// our new rotated view of our camera.
m_vView = m_vPosition + vNewView;
}
|
| EvBladeRunnervE is offline | |
| | #2 |
| 'AlHamdulillah Join Date: Feb 2003
Posts: 790
| nevermind, i figured it out. |
| EvBladeRunnervE is offline | |
| | #3 |
| Banned Join Date: Jan 2003
Posts: 1,708
| yeah it's on pages 61-62 it's kinda tricky, but the meat of the math is on page 61 where they describe the parallel and perpendicular components. To be honest, if you read and understand the math of vector projections, you'll have enough understanding to program a pretty cool 3d graphics engine (that's basically all I know besides a little physics here and there) |
| Silvercord is offline | |
| | #4 |
| 'AlHamdulillah Join Date: Feb 2003
Posts: 790
| Well, i was mistaking the crossproduct to meaning it rotated in only 90 degree increments when all that is doing is providing a plane to rotate on. i.e. an axis of <0,1,0> and a vector <1,0,1> , the cross would be a vector along the X-axis. I know I could do better on explaining, but its hard enough learning it without having to explain it. P.S. @ Silver : that whiteboard idea did wonders for figuring this one out. |
| EvBladeRunnervE is offline | |
| | #5 |
| Banned Join Date: Jan 2003
Posts: 1,708
| yep, best piece of hardware i've bought in a long time |
| Silvercord is offline | |
| | #6 |
| 'AlHamdulillah Join Date: Feb 2003
Posts: 790
| Now the question still remains, how did gametutorials get it the way they have it? With my rotate function, it looks pretty much like the second equation because I have overloaded operators for my Vector class so I dont have to do things individually. does gametutorials(which i have noticed has bugs in quite a bit of its programs) just simply use the same function, just dividing it into all the different components? Also, I figured out most of it, however, i am still somewhat unsure on what Code: A(A.P)(1 -Cos O) |
| EvBladeRunnervE is offline | |
| | #7 |
| Banned Join Date: Jan 2003
Posts: 1,708
| it's just re-arranged algebraically. the real equation, in the normal human form is this; (P - (A . P)A) * cos + (AxP)sin + (A.P)A the final they give is: Pcos + (AxP)sin + A(A.P)(1-cos) the 1-cos comes from the P-(A.P)A. In my code, I use the first version P - (A.P)A gives you the perpendicular component. This is hard to explain if you don't already understand it, but A.P gives you a length (its a dotproduct), and when you multiply that by A (which should be a normalized unit vector) you get the vector component that is the projection of P onto A. When you subtract the projection of P onto A from P it gives you the perpendicular component. you don't need the last part in the normal human form of the equation if the vectors are already orthogonal, but if they aren't already orthogonal you need to add it in in order for it to represent a rotation (preserve lengths). Last edited by Silvercord; 12-09-2003 at 10:57 AM. |
| Silvercord is offline | |
| | #8 | ||
| 'AlHamdulillah Join Date: Feb 2003
Posts: 790
| ah, i figured it had something to do with the (P -A(A.P)), but i was looking at it with the wrong perspective(should of used a whiteboard or a piece of paper instead of trying to think it out). in full, the way the final form was derived was: (P - A(A.P))Cos + (AxP)sin + A(A.P) Pcos + (AxP)sin + A(A.P) - A(A.P)cos which factored down becomes: Pcos + (AxP)sin +A(A.P)(1 - cos) The original equation I find much easier to visualize(because its in parts that make sense by themselves, thank god for trig). P.S. Quote:
i.e. with two vectors, A = <0,1,0> and L= <3,4,0> it is pretty easy to see that when we use the dot product which is 4 (0*3 + 1*4 + 0*0), which when multiplied times A gives us <0,4,0> that when we subtract that from L, we get <3,0,0> which is orthagonal to A. P.S.S. Quote:
P.S.S. how is your engine going by the way? I havent seen anything new on it recently. Last edited by EvBladeRunnervE; 12-09-2003 at 11:49 AM. | ||
| EvBladeRunnervE is offline | |
| | #9 |
| Banned Join Date: Jan 2003
Posts: 1,708
| vector projections and mathematics using dotproducts are used in almost every aspect of a major 3d engine, from the collision detection to lighting routines to AI. my engine is going good, but there's still a small problem with collision detection every once in a great while. we're making a small level with a 'horny bert' that chases you around and you have to kill him with grenades. |
| Silvercord is offline | |
| | #10 | |
| 'AlHamdulillah Join Date: Feb 2003
Posts: 790
| Quote:
have you ever thought about making any 3D math tutorials? btw, my project isnt going that well, as the way I have tiles, it isnt very "realistic", im going to have to probably come up with a new format for my tiles that would lend itself better to heightmapping(thanks to DavidP for using heightmaps for tiles). I decided after a long hard look at 2D that I just wouldnt like doing 2D as I would rather have something that would heavily challenge my math skills ,and since I would be implementing 3d objects, mine as well make the whole thing 3d. In otherwords, Im keeping with my project, but I am still in the phase of putting together prototypes to see what works best. | |
| EvBladeRunnervE is offline | |
| | #11 |
| Banned Join Date: Jan 2003
Posts: 1,708
| the acceleration due to gravity problem had to do with my equations ( i was using the wrong equations. I can explain in more detail if you want me to). I don't have weapons implemented really, I've just got it so that you shoot a ball around the world and it bounces around the world. It looks incredibly realistic, and the physics for it will be used for the grenade launcher. Also, horny bert doesn't have animations...it's going to be stupid |
| Silvercord is offline | |
| | #12 |
| 'AlHamdulillah Join Date: Feb 2003
Posts: 790
| Sure, i would like to hear about it more in detail, however, as this thread has gotten off topic, i think we should move it to Private messaging. |
| EvBladeRunnervE is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| camera rotation matrix | Vick jr | Game Programming | 5 | 05-26-2009 08:16 AM |
| Image rotation - doesn't always work | ulillillia | C Programming | 12 | 05-03-2007 12:46 PM |
| Mathematics? (Peculiar Camera Rotation) | Epo | Game Programming | 10 | 04-14-2005 04:18 PM |
| Binary Search Trees Part III | Prelude | A Brief History of Cprogramming.com | 16 | 10-02-2004 03:00 PM |
| one final problem with rotation | DavidP | Game Programming | 3 | 11-19-2003 03:50 AM |