Advertisement
Luninariel

289 - Scaling Matrix

Apr 8th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. //
  2. //  ScalingMatrix.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 implements matrices for scaling. */
  10. public class ScalingMatrix extends Matrix{
  11.  
  12.    /** Creates a default matrix that scales all dimensions by
  13.     *  1.0. That is, it does nothing.
  14.     */
  15.    public ScalingMatrix(){
  16.    
  17.    }
  18.  
  19.    /** Creates a scaling matrix that scales by the factors specified as
  20.     *  parameters.
  21.     */
  22.    public ScalingMatrix(double xscale, double yscale, double zscale){
  23.           float  [][] scale_matrix = {{(float)xscale, 0.0f,          0.0f,          0.0f},
  24.                                       {0.0f,          (float)yscale, 0.0f,          0.0f},
  25.                                       {0.0f,          0.0f,          (float)zscale, 0.0f},
  26.                                       {0.0f,          0.0f,          0.0f,          1.0f}
  27.                                      };
  28.  
  29.           matrix = scale_matrix;
  30.    }
  31.  
  32.    /** Set the scale factors to the given values.*/
  33.    public void setScales(double xscale, double yscale, double zscale){
  34.       // Write me!
  35.        matrix[0][0] = (float)xscale;
  36.        matrix[1][1] = (float)yscale;
  37.        matrix[2][2] = (float)zscale;
  38.    }
  39.    
  40.    /** Calling copy on a scaling matrix is dangerous, since the result might not
  41.     *  be a scaling matrix.
  42.     */
  43.    public void copy(Matrix m){
  44.    
  45.       System.out.println("ScalingMatrix.java: copy(Matrix) can only be called on a generic Matrix.");
  46.       System.exit(1);  
  47.    }
  48.    
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement