Advertisement
Luninariel

289 - Translation Matrix

Apr 8th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. //
  2. //  TranslationMatrix.java
  3. //  Easel
  4. //
  5. //  Created by Philip Rhodes on 7/31/05.
  6. //  Copyright 2005 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. /** This class imlements matrices for translation (i.e. moving in space) */
  10. public class TranslationMatrix extends Matrix {
  11.  
  12.    /** Creates a default matrix that translates by 0 in all directions.
  13.     *  That is, it does nothing.
  14.     */
  15.    public TranslationMatrix(){
  16.    
  17.    }
  18.  
  19.    /** Create a translation matrix that will translate points (vertices) by
  20.     *  by the specified distances for each axis.
  21.     */
  22.    public TranslationMatrix(double dx, double dy, double dz){
  23.           float  [][] transform_matrix = {{1.0f, 0.0f, 0.0f, (float)dx},
  24.                                           {0.0f, 1.0f, 0.0f, (float)dy},
  25.                                           {0.0f, 0.0f, 1.0f, (float)dz},    
  26.                                           {0.0f, 0.0f, 0.0f, 1.0f}
  27.                                          };
  28.  
  29.           matrix = transform_matrix;
  30.    }
  31.    
  32.    /** Set the distances for all three axes.*/
  33.    public void setDistances(double dx, double dy, double dz){
  34.       // Write me!
  35.        matrix[0][3] = (float)dx;
  36.        matrix[1][3] = (float)dy;
  37.        matrix[2][3] = (float)dz;
  38.  
  39.    }
  40.      
  41.    /** Calling copy on a translation matrix is dangerous, since the result might not
  42.     *  be a translation matrix.
  43.     */      
  44.    public void copy(Matrix m){
  45.    
  46.       System.out.println("TranslationMatrix.java: copy(Matrix) can only be called on a generic Matrix.");
  47.       System.exit(1);  
  48.    }
  49.  
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement