   angle of rotation from one point to another
  Say you have point p1 at position 4,4,4 and I want it to point to p2 which is at 0,0,0. p1 has a direction vector of 0,0,1 (straight down teh z axis). Now what rotations do I have to apply to make p1 point to p2. Is there an general formula for this?Thanks for any help   :::: [ Triple Buffer V2.0 ] ::::
  if p2 is (0, 0, 0) then, assuming you're doing rotations about the origin (0, 0, 0), no rotation will get you from p1 (4, 4, 4) to p2.  You'll need to translate, or rotate about some other point (which involves two translations and a rotation).  You can pick any point that is equidistant from both p1 and p2 about which to rotate, so there's not really a standard formula...Edit: oooh.. I get what you're asking now... Atheist's answer sounds reasonable.  Next time, don't call it a "point".  Try "ray" or "arrow" or somesuch.   [edited by - Geoff the Medio on July 31, 2003 10:47:16 AM];  You can rotate around any point that has the same distance from p1 as from p2 (the point inbetween is easiest because you rotate 180 degrees around any axis perpendicular to the connection vector). The big problem with your question is: What do you want to do? Bringing p1 to p2? p1=p2 will do so I guess that´s not all. btw.: What is the direction vector of a point?   EDIT: I think I got you r question now. You want to rotate the vector v=(0,0,1) so that it points towards (-1,-1,-1). hm... I´ll take a minute to think about that.   [edited by - Atheist on July 31, 2003 10:04:47 AM]EDIT2: The axis of rotation is given by the cross-product of v=(0,0,1) and v'= 1/SQRT(3) (-1,-1,-1) so r=v x x'. The angle should be given by angle=arccos(v * v') (<- scalar product, I ran into problems using arcsin(|r|) because it only covers angles up to 90°). There might be a "-" nessecary but you´ll see that yourself.    [edited by - Atheist on July 31, 2003 10:14:52 AM];  sorry. didnt mean to confuse you guys. You kinda got what I was asking. I do want to actually turn a vector from one dirrection to another, but I dont know the other direction. Instead of calling it a point call it a camera. The camera resides in the world at position 4,4,4 and It''s pointing straight down the z axis (vector 0,0,1). I need to rotate about the x and y axis to make the camera point to the origin (point 0,0,0). I dont know how many degrees to rotate about the x and how many about the y.Athiest:everything you said went whoosh over my head. Sorry, I''m really a math noob, I was letting d3dx (math library with directx sdk) do all the math for me before. Now I need to do it myself. ;  Can''t you just tell the camera to look at a point?  There''s something like D3DXMatrixLookAtLH which you can then use as one of the matrices for rendering...Or do you need it to smoothly interpolate? ;quote:Medio Can''t you just tell the camera to look at a point? There''s something like D3DXMatrixLookAtLH which you can then use as one of the matrices for rendering... I can. but like i said, i cant use d3dx this time around. Im gonna try and break it down really nicely this time Matrix4x4 Point( xeye, yeye, zeye, xat, yat, zat ){    float xrot, yrot;    Matrix4x4 matRotation, matTranslastion;    // Sets up a translation matrix    matTranslation.SetTranslation( xeye, yeye, zeye );    // Creates three rotation matrices (x/y/z axii) and then    // sets matRotation to the matrix resulting in the concatenation    // of the x/y/z matrices    matRotation.SetRotationXYZ( xrot, yrot, 0 );    return matRotation * matTranslation}Now being as specific as possible, my problem is finding values for xrot and yrot. ;  Ah.  I thought you meant you were using D3DX to do all your projection, but this was something you didn''t think you could do with D3DX functions.As for the actual problem:  I think that X and Y rotations are based on axes aligned to your object.  As such, the rotation you need to use to get you facing where you want depend on what the ''up'' vector of your view is prior to the rotation.  They also probably depend on whether you''re using a right or left handed coordinate system.  You might want to figure those things out.I have a few ideas of how to go about actually solving the problem, though I''ve never done it myself, so I''ll leave the actual answering to someone who has... unless nobody has... which seems unlikely.You might want to ask in the graphics forum as well. ;  up vector is +y. And that wont be changing so I wont need any z rotation values.About left/right handed coordinate systems...will being in either a LH or RH coord system make a difference in the way you calculate xrot and yrot? Im using a RH coord system though.   quote:You might want to ask in the graphics forum as well. yeah right! Dont you know GDNet'ers by now. If you cross post someone WILL kill you [Edit]Realized the crosspost comment[/Edit]    [edited by - ifoobar on July 31, 2003 4:57:01 PM];  The way to find the angle between two vectors is by taking the acos of the dot product between them. This will return radians,  tt only returns an angle between 0 and 180 degrees.  So it will not tell you which way to rotate.Heres some psuedo code to find one angle with normalized vectors;Ignore the y component to find the angle for rotating around the y axis and so on.{Vector Orientation;Vector DesiredOrientation;float angle;angle = DotProduct(Orientation, DesiredOrientation);angle = acos(angle);} [edited by - galagaew on July 31, 2003 5:00:55 PM];quote:up vector is +y. And that wont be changing so I wont need any z rotation values.If you don''t want the components of vectors in the y direction to change, you need to rotate about the y axis only.  If you rotate about z or x, you''ll change the y parts of vectors.  "x-rotation" means rotation about the x axis, not rotation of the x axis about some other axis (which would be ambiguous since you could pick any axis, including by not limited to the y or z, which would produce different results)Additionally, you are rotating the y components of your vector, since you need to go from (-1, 0, 0) to (1, 1, 1) (scaled if you prefer) and that''s a change in the y component.  Your up vector has to change, otherwise you''d just be rotating from (-1, 0, 0) to (1, 0, 1) (which is a rotation a about the y axis only).My suggestion (based partly on Galagaew''s comment) is to find the angle between the vector you have and the vector you want''s projection in the xz plane (just ignore the y component).  Find the rotation matrix (about the y axis) to get you to there.  Then find the rotation matrix in the yz plane to tilt your view up to the desired angle.  You can then concatenate these matrices and do the actual rotations in one step.I''m guessing you don''t know how to do that either though...? (if you didn''t understand any of Atheist''s post).quote:will being in either a LH or RH coord system make a difference in the way you calculate xrot and yrot?In RH coords, the z axis points in the direction the thumb of your right hand points if you curl your right hand''s fingers in the direction of rotation from the x axis to the y axis.  In LH, the same applies to the left hand thumb and fingers.  If you alternate between these, the direction of rotations is reversed.  At worst, you might need to put in a - sign somewhere and your objects might be mirrored from how you designed them when you render.quote:yeah right! Dont you know GDNet''ers by now. If you cross post someone WILL kill you I''ve managed to sneak past once I guess... despite specifically stating that I hadn''t gotten an answer elsewhere.  Maybe that''s the trick?  I mean, if you tried anotehr forum, and nobody knew, why is it bad to try again?  I''m not talking about blanket posting to all forums simultaneously...If you''re really scared, use an alias. 