PDA

View Full Version : Modulus of angle



cronodragon
02-03-2006, 03:15 PM
Hi! :D

Maybe some math's guru here could help me o this problem :D I'm moving a cursor over a grid in 3D using the keyboard, so it moves in 6 fixed directions. The camera rotates around that cursor, and the problem is that the controls become confusing, since for example, I'm looking at the cursor from behind, and now right is left and left is right. I could turn the cursor in order to make it move properly, but I need some formula to turn it 90 degrees, so it keeps on the right path thru the grid. How could I calculate the yaw of that cursor depending on the yaw of the camera? The angles are radians.

Regards!

Traveler
02-03-2006, 03:36 PM
I'm not entirely sure what you mean, but if you already know the rotation of the origional position, wouldn't it be possible to add/deduct the value of the camera when it rotates?

cronodragon
02-03-2006, 03:39 PM
The idea is not to adjust the camera, but the direction of the cursor, in a way that it moves relative to the point of view of the camera, and over the axis of the grid.

User137
03-03-2006, 12:56 PM
You could project a ray from screen to cursor that passes through the grid. Then calculating the point where it goes through the grid plane. Assuming this was freely rotatable 3D world? Implementation of this depends now of used graphics engine.

Edit: Hmm.. maybe that was not asked :P

Maybe this helps:

// Rotate point around (cx, cy)
// Angle in radians
procedure Rotate(var px,py: double; _angle,cx,cy: double);
var et,k: double;
begin
et:=hypot(py-cy,px-cx);
k:=arctan2(py-cy,px-cx)+_angle;
px:=cx+cos(k)*et; py:=cy+sin(k)*et;
end;

cronodragon
03-03-2006, 02:13 PM
Hmm, I think isn't that complicated... it should be something like making the modulus of the camera's angle (the camera is always pointing to the cursor, and turns around it), I could do it with several if, but I was looking for an elegant solution of a few lines. If I solve it, I will post it here 8)

cronodragon
03-03-2006, 03:26 PM
Here it is:

Cursor.Rotate(0, Trunc((CameraYaw+Pi/4)*2/Pi)*Pi/2, 0);

CameraYaw is the angle of the camera over the Y-axis, that is rotating around the cursor.