Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: don't understand angle source in calculations

  1. #1
    Intern Contributor
    Join Date
    May 2017
    Posts
    80

    don't understand angle source in calculations

    I'm currently doing a work up of FPS camera math. I know that there is an overwhelming slant to the matrix based approach, but my white whale lately has been the trigonometric math for FPS movement. I was following along in the tutorial: http://www.java-gaming.org/index.php?topic=37448.0 and professed I did not know where the angle "A" came from in the picture from below:

    Click image for larger version. 

Name:	fps_photo.png 
Views:	9 
Size:	1.9 KB 
ID:	2544

    And when it reappears here as a "rotation":

    float adjacent = hypotenuse * Math.cos(Math.toRadians(rotation)); // note, toRadians because we were working in degrees
    float opposite = hypotenuse * Math.sin(Math.toRadians(rotation)); // cos and sin only accept radians
    I know better how to build my camera class if I can understand angle A.

    I understand why it is there as far as the trig fx, but how is the angle calculated and where does it come from for use in the trig fx?
    Last edited by technologist; 11-13-2017 at 07:52 PM. Reason: clairity

  2. #2
    Intern Contributor
    Join Date
    May 2017
    Posts
    80
    Is the angle A localized to XY space?
    Is rotation (below) equal to Angle A?

    Here, the :float adjacent = hypotenuse * Math.cos(Math.toRadians(rotation))

    Confused: which axis does rotation belong to? I need specifics.

    I understand you use the sides of the triangles to translate...without knowing how to solve the angle its pointless.
    Last edited by technologist; 11-14-2017 at 06:05 PM.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2017
    Posts
    9

    It's just an FOV calculation

    Quote Originally Posted by technologist View Post
    I'm currently doing a work up of FPS camera math. I know that there is an overwhelming slant to the matrix based approach, but my white whale lately has been the trigonometric math for FPS movement. I was following along in the tutorial: http://www.java-gaming.org/index.php?topic=37448.0 and professed I did not know where the angle "A" came from in the picture from below:
    This would be only one angle for the FOV || Field of View. Its not telling you how to set it but giving the a basic pothagorem therum to demonstrate how to calculate the FOV of the players camera. Allowing to let the operation know what it is to draw.

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2017
    Posts
    9

    Wink much simpler way

    [QUOTE=technologist;1289343]I'm currently doing a work up of FPS camera math. I know that there is an overwhelming slant to the matrix based approach, but my white whale lately has been the trigonometric math for FPS movement. I was following along in the tutorial: http://www.java-gaming.org/index.php?topic=37448.0 and professed I did not know where the angle "A" came from in the picture from below:


    This guy is making things way to complicated. There is a much easier way as far as I'm concerned, and always allow elevation to control the verticle movement.

    It's degned for a mouse but will work directly the same if it's the center focus of your translation. Current scale can be used as a speed variable without any major adjustments to your systems layout. There is no reason for doing all that fancy stuff when it can be broken down into 4 quadrants since; at all 4 quadrants you will have to evaluate a different measure anyway.

    If this doesn't make since draw a circle on the floor representing a compass , break it down into 4 quadrants and further more into 8 subquadrants , and it should make perfect sense then. each one has to be evaluated in order to determin the azmath ( degree of rotation ). this is within 1 moa ( minut of angle ) off less than 1 inch throughout the span of travel

    If you are moving on an elevation save a copy of the variables calculated the difference afterwards and add a degenerative effect for uphill vs downhill if you want a more realistic engine. It's not that much extra code and can be evaluated easily. Or just pass the degeneration as a part of currentScale , never realized how portable this was. But you only need pass the Horizontal plane to the function in order to obtain your movement. Vertical plane with horizontal plane would be for a flight simulator or underwater simulator more than a FPS.

    Code :
    // hi ( this value is for the dominate of the area )
    // lo ( this value is for the subordinate of the quadrant )
    double newLocationHi ( double angle , double move , double currentScaleCubed ) { return abs((( ( 90 - angle ) * move ) * currentScaleCubed )); }
    double newLocationLo ( double angle , double move , double currentScaleCubed ) { return abs(( ( angle * move ) * currentScaleCubed )); }
    // can also be determined for the movement of an object and the direction it is facing
    void moveMouse
    ( int xMove , int yMove , bool xRight , bool zUp , double currentScale ,
    mouseControls * MouseControls ,
    rotation * Rotation )
    {
     // this value was added for a way to scale the objects to a default size upon init obj::obj(); vs having to do it later
     // it can be removed and replaced with whatever value you use to determine how far the object is moving
     double cubed = ( currentScale * currentScale * currentScale );
     // my default horizontal rotation
     /*  pointless.  can't believe I left It there all this time...  i'm ashamed..
     if ( ( Rotation->y == 0.0 ) || ( Rotation->y == 360.0 ) )
     {
      if ( zUp ) MouseControls->MouseCurrentLocation.z += (yMove*currentScale)/10;
      else if ( !zUp ) MouseControls->MouseCurrentLocation.z -= ( yMove*currentScale)/10;
      if ( xRight ) MouseControls->MouseCurrentLocation.x += (xMove*currentScale)/10;
      else if ( !xRight ) MouseControls->MouseCurrentLocation.x -= (xMove*currentScale)/10;
      return;
     }
     */
     // keep rotation between 0 and 360 I should remove this since I recently made it a safeguard of the
     // class itself
     if ( Rotation->y < 0.0 ) Rotation->y += 360.0;
     if ( Rotation->y <= 90.0 )
     {
      // can be switched with your keys
      // e.g. xRight would be 'D' I guess
      // zUp would be W (!zUp) would be S
      if ( xRight )
      {
    	MouseControls->MouseCurrentLocation.x += newLocationHi( Rotation->y,xMove,cubed);
    	MouseControls->MouseCurrentLocation.z += newLocationLo( Rotation->y,xMove,cubed);
      }
      else if ( !xRight )
      {
       MouseControls->MouseCurrentLocation.x -= newLocationHi(Rotation->y,xMove,cubed);
       MouseControls->MouseCurrentLocation.z -= newLocationLo(Rotation->y,xMove,cubed);
      }
      if ( zUp )
      {
       MouseControls->MouseCurrentLocation.x += newLocationLo ( Rotation->y,yMove,cubed);
       MouseControls->MouseCurrentLocation.z -= newLocationHi ( Rotation->y,yMove,cubed);
      }
      else if ( !zUp )
      {
       MouseControls->MouseCurrentLocation.x -= newLocationLo ( Rotation->y,yMove,cubed);
       MouseControls->MouseCurrentLocation.z += newLocationHi ( Rotation->y,yMove,cubed);
      }
     }
     else if ( Rotation->y <= 180 )
     {
      if ( zUp )
      {
       MouseControls->MouseCurrentLocation.x += newLocationHi ( ( Rotation->y - 90 ) , yMove , cubed );
       MouseControls->MouseCurrentLocation.z += newLocationLo ( ( Rotation->y - 90 ) , yMove , cubed );
      }
      else if ( !zUp )
      {
       MouseControls->MouseCurrentLocation.x -= newLocationHi ( ( Rotation->y - 90 ) , yMove,cubed);
       MouseControls->MouseCurrentLocation.z -= newLocationLo ( ( Rotation->y - 90 ) , yMove,cubed);
      }
      if ( xRight )
      {
       MouseControls->MouseCurrentLocation.x -= newLocationLo ( ( Rotation->y - 90 ) , xMove,cubed);
       MouseControls->MouseCurrentLocation.z += newLocationHi ( ( Rotation->y - 90 ) , xMove,cubed);
      }
      if ( !xRight )
      {
       MouseControls->MouseCurrentLocation.x += newLocationLo ( ( Rotation->y - 90 ) , xMove , cubed );
       MouseControls->MouseCurrentLocation.z -= newLocationHi ( ( Rotation->y - 90 ) , xMove , cubed );
      }
     }
     else if ( Rotation->y <= 270 )
     {
      if ( xRight )
      {
       MouseControls->MouseCurrentLocation.x -= newLocationHi ( ( Rotation->y - 180 ) , xMove , cubed );
       MouseControls->MouseCurrentLocation.z -= newLocationLo ( ( Rotation->y - 180 ) , xMove , cubed );
      }
      else if ( !xRight )
      {
       MouseControls->MouseCurrentLocation.x += newLocationHi ( ( Rotation->y - 180 ) , xMove , cubed );
       MouseControls->MouseCurrentLocation.z += newLocationLo ( ( Rotation->y - 180 ) , xMove , cubed );
      }
      if ( zUp )
      {
       MouseControls->MouseCurrentLocation.z += newLocationHi ( ( Rotation->y - 180 ) , yMove , cubed );
       MouseControls->MouseCurrentLocation.x -= newLocationLo ( ( Rotation->y - 180 ) , yMove , cubed );
      }
      else if ( !zUp )
      {
       MouseControls->MouseCurrentLocation.z -= newLocationHi ( ( Rotation->y - 180 ) , yMove , cubed );
       MouseControls->MouseCurrentLocation.x += newLocationLo ( ( Rotation->y - 180 ) , yMove , cubed );
      }
     }
     else if ( Rotation->y <= 360.0 )
     {
      if ( xRight )
      {
       MouseControls->MouseCurrentLocation.z -= newLocationHi ( ( Rotation->y - 270 ) , xMove , cubed );
       MouseControls->MouseCurrentLocation.x += newLocationLo ( ( Rotation->y - 270 ) , xMove , cubed );
      }
      else if ( !xRight )
      {
       MouseControls->MouseCurrentLocation.z += newLocationHi ( ( Rotation->y - 270 ) , xMove , cubed );
       MouseControls->MouseCurrentLocation.x -= newLocationLo ( ( Rotation->y - 270 ) , xMove , cubed );
      }
      if ( zUp )
      {
       MouseControls->MouseCurrentLocation.x -= newLocationHi ( ( Rotation->y - 270 ) , yMove , cubed );
       MouseControls->MouseCurrentLocation.z -= newLocationLo ( ( Rotation->y - 270 ) , yMove , cubed );
      }
      else if ( !zUp )
      {
       MouseControls->MouseCurrentLocation.x += newLocationHi ( ( Rotation->y - 270 ) , yMove , cubed );
       MouseControls->MouseCurrentLocation.z += newLocationLo ( ( Rotation->y - 270 ) , yMove , cubed );
      }
     }
    }
    Last edited by didydriver; 12-04-2017 at 02:27 AM.

Posting Permissions

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