Advertisement
Southclaw

Rotation and Elevation angles between two points in 3D space

Aug 23rd, 2012
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 0.73 KB | None | 0 0
  1. new
  2.     Float:vecX, // = DIFFERENCE BETWEEN THE TWO X VALUES something like: floatabs(x1-x2)
  3.     Float:vecY, // = SAME AS ABOVE, WITH Y
  4.     Float:vecZ, // = TAKE A GUESS LOL (same but with Z)
  5.  
  6. angR = 90-(atan2(vecY, vecX));
  7. if(angR<0.0)angR=360.0+angR;
  8. angE = -(floatabs(atan2(floatsqroot(floatpower(vecX, 2.0) + floatpower(vecY, 2.0)), vecZ))-90.0);
  9.  
  10. // You now have the angles, to get a position, use a similar function as GetXYInFrontOfPlayer:
  11.  
  12. stock GetXYZFromAngle(&Float:x, &Float:y, &Float:z, Float:angle, Float:elevation, Float:distance)
  13. {
  14.     x += ( distance*floatsin(angle,degrees)*floatcos(elevation,degrees) );
  15.     y += ( distance*floatcos(angle,degrees)*floatcos(elevation,degrees) );
  16.     z += ( distance*floatsin(elevation,degrees) );
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement