tracer
Class Vec3

java.lang.Object
  extended by tracer.Vec3

public class Vec3
extends java.lang.Object

Represents a 3-dimensional vector. Note that all the `operator' methods return a new Vec3 object.


Field Summary
 float x
           
 float y
           
 float z
           
 
Constructor Summary
Vec3()
          Default constructor.
Vec3(float x, float y, float z)
          Constructor from floats.
Vec3(Vec3 that)
          Copy constructor
 
Method Summary
 Vec3 add(Vec3 that)
          Vector addition.
 Vec3 cross(Vec3 b)
          Vector cross-product.
 float dot(Vec3 that)
          Vector dot-product.
 boolean equals(Vec3 that)
           
 boolean isNewVec()
           
 float length()
          Returns the length of this vector.
 float lengthSquared()
          Return the square of the length of this vector.
 Vec3 minus(Vec3 that)
          Vector subtraction.
 void normalize()
          Normalizes this vector.
 void parse(Parser p)
          Reads a vector in the form "<number, number, number>" from the Parser p.
static Vec3 perlinVec()
           
static Vec3 random(float length)
          Returns a Vec3 of specified length with a random direction.
 Vec3 times(float f)
          Multiplication by a scalar.
 Vec3 times(Vec3 that)
          Component-wise multiply
 java.lang.String toString()
          Returns a string representation of this vector, of the form "<number, number, number>" as can be parsed by the parse(Parser) method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public float x

y

public float y

z

public float z
Constructor Detail

Vec3

public Vec3(Vec3 that)
Copy constructor


Vec3

public Vec3(float x,
            float y,
            float z)
Constructor from floats.


Vec3

public Vec3()
Default constructor. Makes the vector (0,0,0)

Method Detail

random

public static Vec3 random(float length)
Returns a Vec3 of specified length with a random direction.


equals

public boolean equals(Vec3 that)

perlinVec

public static Vec3 perlinVec()

parse

public void parse(Parser p)
           throws java.io.IOException
Reads a vector in the form "<number, number, number>" from the Parser p. Changes this vector.

Throws:
java.io.IOException
See Also:
toString

minus

public Vec3 minus(Vec3 that)
Vector subtraction. Returns a new Vec3 equal to this - that.


add

public Vec3 add(Vec3 that)
Vector addition. Returns a new Vec3 equal to this + that.


times

public Vec3 times(float f)
Multiplication by a scalar. Returns a new Vec3 equals to f * this.


times

public Vec3 times(Vec3 that)
Component-wise multiply


length

public float length()
Returns the length of this vector. Use lengthSquared() instead if you're going to square the result anyway: lengthSquared() is more efficient.

See Also:
lengthSquared

lengthSquared

public float lengthSquared()
Return the square of the length of this vector.

See Also:
length

dot

public float dot(Vec3 that)
Vector dot-product. Returns a new Vec3 equal to this dot that.


cross

public Vec3 cross(Vec3 b)
Vector cross-product. Returns a new Vec3 equal to this cross that. (added: We take it that the parameter is the vector to be multiplied with, ie the parameter is w in the formula v x w)


normalize

public void normalize()
Normalizes this vector. Warning: this actually changes this instance, contrary to most methods.


isNewVec

public boolean isNewVec()

toString

public java.lang.String toString()
Returns a string representation of this vector, of the form "<number, number, number>" as can be parsed by the parse(Parser) method.

Overrides:
toString in class java.lang.Object
See Also:
parse