Advertisement
Luninariel

289 - Rotation Matrix X

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