artofillusion.math
Class Mat4

java.lang.Object
  extended by artofillusion.math.Mat4

public class Mat4
extends java.lang.Object

This class represents a 4x4 matrix. It is typically used for representing coordinate transformations.


Field Summary
 double m11
           
 double m12
           
 double m13
           
 double m14
           
 double m21
           
 double m22
           
 double m23
           
 double m24
           
 double m31
           
 double m32
           
 double m33
           
 double m34
           
 double m41
           
 double m42
           
 double m43
           
 double m44
           
 
Constructor Summary
Mat4(java.io.DataInputStream in)
          Create a Mat4 by reading in information that was written by writeToFile().
Mat4(double e11, double e12, double e13, double e14, double e21, double e22, double e23, double e24, double e31, double e32, double e33, double e34, double e41, double e42, double e43, double e44)
          Create a new Mat4 by explicitly setting its components.
 
Method Summary
static Mat4 axisRotation(Vec3 axis, double angle)
          This routine creates a matrix to rotate a vector around an arbitrary axis.
 boolean equals(java.lang.Object o)
           
 int hashCode()
           
static Mat4 identity()
          Create an identity matrix.
static Mat4 objectTransform(Vec3 orig, Vec3 zdir, Vec3 updir)
          Create a matrix which is the inverse of the viewTransform matrix.
static Mat4 perspective(double d)
          Create a matrix to implement a perspective projection.
static Mat4 scale(double sx, double sy, double sz)
          Create a matrix to scale x, y, and z by sx, sy, and sz respectively.
 Mat4 times(Mat4 a)
          Create a new Mat4 by multiplying two matrices.
 Vec3 times(Vec3 v)
          Multiply this matrix (M) by a vector (v) and return the product Mv.
 Vec3 timesDirection(Vec3 v)
          This method is identical to times(), except that v is assumed to be a direction vector.
 Vec2 timesXY(Vec3 v)
          This method works exactly like the times() method, except that it only calculates the x and y components of the output vector.
 Vec2 timesXY(Vec3 v, Vec2 result)
          This method works exactly like the times() method, except that it only calculates the x and y components of the output vector.
 double timesZ(Vec3 v)
          This method works like the times() method, except that it only calculates the z component of the output vector.
 java.lang.String toString()
           
 void transform(Vec3 v)
          This method works like times(), except that the calculation is done in place.
 void transformDirection(Vec3 v)
          This method works like timesDirection(), except that the calculation is done in place.
static Mat4 translation(double dx, double dy, double dz)
          Create a matrix to translate a vector by (dx, dy, dz).
static Mat4 viewTransform(Vec3 orig, Vec3 zdir, Vec3 updir)
          Create a matrix for transforming from world coordinates to viewing coordinates.
 void writeToFile(java.io.DataOutputStream out)
          Write out a serialized representation of this object.
static Mat4 xrotation(double angle)
          Create a matrix that rotates a vector around the X axis.
static Mat4 yrotation(double angle)
          Create a matrix that rotates a vector around the Y axis.
static Mat4 zrotation(double angle)
          Create a matrix that rotates a vector around the Z axis.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

m11

public final double m11

m12

public final double m12

m13

public final double m13

m14

public final double m14

m21

public final double m21

m22

public final double m22

m23

public final double m23

m24

public final double m24

m31

public final double m31

m32

public final double m32

m33

public final double m33

m34

public final double m34

m41

public final double m41

m42

public final double m42

m43

public final double m43

m44

public final double m44
Constructor Detail

Mat4

public Mat4(double e11,
            double e12,
            double e13,
            double e14,
            double e21,
            double e22,
            double e23,
            double e24,
            double e31,
            double e32,
            double e33,
            double e34,
            double e41,
            double e42,
            double e43,
            double e44)
Create a new Mat4 by explicitly setting its components.


Mat4

public Mat4(java.io.DataInputStream in)
     throws java.io.IOException
Create a Mat4 by reading in information that was written by writeToFile().

Throws:
java.io.IOException
Method Detail

times

public final Mat4 times(Mat4 a)
Create a new Mat4 by multiplying two matrices.


times

public final Vec3 times(Vec3 v)
Multiply this matrix (M) by a vector (v) and return the product Mv. Both the input and output vectors are assumed to be in homogeneous coordinates, and to have an implicit fourth element equal to 1.


timesDirection

public final Vec3 timesDirection(Vec3 v)
This method is identical to times(), except that v is assumed to be a direction vector. That is, the implicit fourth element is assumed to be 0.


timesXY

public final Vec2 timesXY(Vec3 v)
This method works exactly like the times() method, except that it only calculates the x and y components of the output vector. This can save several operations when the z component is not of interest, for example, when applying a perspective projection.


timesXY

public final Vec2 timesXY(Vec3 v,
                          Vec2 result)
This method works exactly like the times() method, except that it only calculates the x and y components of the output vector. This can save several operations when the z component is not of interest, for example, when applying a perspective projection. Also, rather than creating a new object, it allows you to pass in an existing object to receive the results.


timesZ

public final double timesZ(Vec3 v)
This method works like the times() method, except that it only calculates the z component of the output vector. This is useful, for example, for determining whether a point lies in front of or behind the viewer.


transform

public final void transform(Vec3 v)
This method works like times(), except that the calculation is done in place.


transformDirection

public final void transformDirection(Vec3 v)
This method works like timesDirection(), except that the calculation is done in place.


identity

public static Mat4 identity()
Create an identity matrix.


scale

public static Mat4 scale(double sx,
                         double sy,
                         double sz)
Create a matrix to scale x, y, and z by sx, sy, and sz respectively.


translation

public static Mat4 translation(double dx,
                               double dy,
                               double dz)
Create a matrix to translate a vector by (dx, dy, dz).


xrotation

public static Mat4 xrotation(double angle)
Create a matrix that rotates a vector around the X axis.

Parameters:
angle - the rotation angle, in radians

yrotation

public static Mat4 yrotation(double angle)
Create a matrix that rotates a vector around the Y axis.

Parameters:
angle - the rotation angle, in radians

zrotation

public static Mat4 zrotation(double angle)
Create a matrix that rotates a vector around the Z axis.

Parameters:
angle - the rotation angle, in radians

axisRotation

public static Mat4 axisRotation(Vec3 axis,
                                double angle)
This routine creates a matrix to rotate a vector around an arbitrary axis.

Parameters:
axis - the axis around which to rotate
angle - the rotation angle, in radians

viewTransform

public static Mat4 viewTransform(Vec3 orig,
                                 Vec3 zdir,
                                 Vec3 updir)
Create a matrix for transforming from world coordinates to viewing coordinates. This matrix transforms coordinates such that the position vector orig is translated to the origin, the direction vector zdir lies along the positive z axis, and the direction vection updir lies the positive y half of the yz plane.


objectTransform

public static Mat4 objectTransform(Vec3 orig,
                                   Vec3 zdir,
                                   Vec3 updir)
Create a matrix which is the inverse of the viewTransform matrix. That is, it first rotates the rotates the z axis to lie along the direction of zdir and the y axis to lie in the updir direction, then translates the origin to the point orig. This is useful for transforming from object coordinates to world coordinates.


perspective

public static Mat4 perspective(double d)
Create a matrix to implement a perspective projection. The center of projection is at (0, 0, -d), and the projection plane is given by z=1.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

writeToFile

public void writeToFile(java.io.DataOutputStream out)
                 throws java.io.IOException
Write out a serialized representation of this object.

Throws:
java.io.IOException


Copyright © 1999-2011 by Peter Eastman.