Advertisement
Luninariel

289 - Rotation Matrix Y

Apr 8th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. //
  2. //  RotationMatrixY.java
  3. //  Easel
  4. //
  5. //  Created by Philip Rhodes on 7/29/05.
  6. //  Copyright 2005 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. /** This class represents matrices that rotate vertices around the y axis.
  10.   * according to the "right hand rule".
  11.   */
  12. public class RotationMatrixY extends RotationMatrix{
  13.  
  14.    /** Constructs a rotation matrix with rotation angle 0. */
  15.    public RotationMatrixY(){
  16.       // The default constructor will set this matrix
  17.       // equal to the identity, so do nothing here.
  18.      
  19.    }
  20.  
  21.  
  22.    /** Construct a matrix that will rotate vertices around the y axis by the
  23.     *  angle theta, expressed in radians."
  24.     */
  25.    RotationMatrixY(double theta){
  26.       // Write me!
  27.       float  [][] rotationx_matrix =
  28.               {{(float)Math.cos(theta), 0.0f, (float)Math.sin(theta), 0.0f},
  29.               {0.0f,                    1.0f,    0.0f,                 0.0f},
  30.               {-(float)Math.sin(theta),  0.0f, (float)Math.cos(theta),  0.0f},
  31.               {0.0f,                    0.0f,    0.0f,                 1.0f}
  32.       };
  33.  
  34.       matrix = rotationx_matrix;
  35.    }
  36.    
  37.    /** Set the angle of rotation to theta, expressed in radians.  */
  38.    public void setAngle(double theta){
  39.      // Write me!
  40.       matrix[0][0] = (float)Math.cos(theta);
  41.       matrix[0][2] = (float)Math.sin(theta);
  42.       matrix[2][0] = -(float)Math.sin(theta);
  43.       matrix[2][2] = (float)Math.cos(theta);
  44.    }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement