Results 1 to 6 of 6

Thread: Modulus of angle

  1. #1

    Modulus of angle

    Hi!

    Maybe some math's guru here could help me o this problem 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!

  2. #2

    Modulus of angle

    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?

  3. #3

    Modulus of angle

    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.

  4. #4

    Modulus of angle

    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

    Maybe this helps:
    Code:
    // 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;

  5. #5

    Modulus of angle

    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

  6. #6

    Modulus of angle

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •