jpview.graphics
Class Vec3f

java.lang.Object
  extended by jpview.graphics.Vec3f

public class Vec3f
extends java.lang.Object

The Vec3f class provides a vector object for 3 dimensional locations or RGB pixel values. The class offers static methods for standard vector operations.

Author:
clyon

Constructor Summary
Vec3f()
          Creates a new instance of Vec3
Vec3f(float[] f)
          Creates a new Vec3f object using the provided float [] as the underlying values.
Vec3f(float x, float y, float z)
          Creates an new Vec3f object using the provided float values
 
Method Summary
static Vec3f convertPixel(int pixel)
          Converts a 32 bit pixel value with RGB in the lower 24 bits to a Vec3f object
 Vec3f cross(Vec3f v)
          Returns the cross product of this Vec3f and the Vec3f provided to the method
 Vec3f diff(Vec3f v)
          Returns the difference of two vectors.
 float dot(Vec3f vector)
          Returns the dot product of this Vec3f and the Vec3f provided to the method
 boolean equals(Vec3f that)
          Returns true if this vector is the same as the provided vector
 float len()
          Returns the length of the Vec3f vector
 Vec3f normalize()
          Normalizes the vector.
 void perturb()
          Perturbs the normal slightly
static Vec3f reflect(Vec3f normal, Vec3f incedent)
          Returns a vector representing the reflection of the provided incedent vector.
 Vec3f scale(float s)
          Scales this vector by the provided float value
 Vec3f sum(Vec3f v)
          Adds two Vec3f objects together
 float[] toFloat()
          Returns the underlying float array for the Vec3f object.
 int toPixel()
          Returns a representation of this vector as a colored pixel value, with RGB in the lower 24 bits.
 java.lang.String toString()
          Returns a string representation of this vector.
 float x()
          Returns the x component of the vector (x,y,z)
 void x(float f)
          Sets the x component of the vector (x,y,z) to the provided value
 float y()
          Returns the y component of the vector (x,y,z)
 void y(float f)
          Sets the y component of the vector (x,y,z) to the provided value
 float z()
          Returns the z component of the vector (x,y,z)
 void z(float f)
          Sets the z component of the vector (x,y,z) to the provided value
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Vec3f

public Vec3f()
Creates a new instance of Vec3


Vec3f

public Vec3f(float[] f)
Creates a new Vec3f object using the provided float [] as the underlying values.

Parameters:
f - an array of 3 float values.

Vec3f

public Vec3f(float x,
             float y,
             float z)
Creates an new Vec3f object using the provided float values

Parameters:
x - first float value
y - second float value
z - third float value
Method Detail

convertPixel

public static Vec3f convertPixel(int pixel)
Converts a 32 bit pixel value with RGB in the lower 24 bits to a Vec3f object

Parameters:
pixel - the 32 bit pixel value
Returns:
a new Vec3f object with the pixels r,b,g values as the elements of the Vec3f

toFloat

public float[] toFloat()
Returns the underlying float array for the Vec3f object.

Returns:
the underlying float [] used for the object.

len

public float len()
Returns the length of the Vec3f vector

Returns:
the length of the vector as a float

normalize

public Vec3f normalize()
Normalizes the vector. For convenience, returns itself.

Returns:
the normalized vector.

x

public float x()
Returns the x component of the vector (x,y,z)

Returns:
the x component of the vector (x,y,z)

y

public float y()
Returns the y component of the vector (x,y,z)

Returns:
the y component of the vector (x,y,z)

z

public float z()
Returns the z component of the vector (x,y,z)

Returns:
the z component of the vector (x,y,z)

x

public void x(float f)
Sets the x component of the vector (x,y,z) to the provided value

Parameters:
f - the x component of the vector (x,y,z)

y

public void y(float f)
Sets the y component of the vector (x,y,z) to the provided value

Parameters:
f - the y component of the vector (x,y,z)

z

public void z(float f)
Sets the z component of the vector (x,y,z) to the provided value

Parameters:
f - the z component of the vector (x,y,z)

dot

public float dot(Vec3f vector)
Returns the dot product of this Vec3f and the Vec3f provided to the method

Parameters:
vector - The Vec3f object representing the right-hand side of the dot product
Returns:
The dot product of this Vec3f and the Vec3f provided to the method.

cross

public Vec3f cross(Vec3f v)
Returns the cross product of this Vec3f and the Vec3f provided to the method

Parameters:
v - The Vec3f object representing the right-hand side of the cross product
Returns:
The cross product of this Vec3f and the Vec3f provided to the method.

scale

public Vec3f scale(float s)
Scales this vector by the provided float value

Parameters:
s - the amount by which each component of the vector is multiplied
Returns:
a new scaled vector (the underlying vector does not change)

sum

public Vec3f sum(Vec3f v)
Adds two Vec3f objects together

Parameters:
v - The vector to which this vector will be added
Returns:
a new vector representing the sum of this vector and the provided vector. (this vector is unchanged)

diff

public Vec3f diff(Vec3f v)
Returns the difference of two vectors.

Parameters:
v - The vector representing the right-hand side of the difference.
Returns:
This difference of this vector and the provided vector

toString

public java.lang.String toString()
Returns a string representation of this vector.

Overrides:
toString in class java.lang.Object
Returns:
a human-readable String representation of this vector

reflect

public static Vec3f reflect(Vec3f normal,
                            Vec3f incedent)
Returns a vector representing the reflection of the provided incedent vector.

Parameters:
normal - The normal vector for the particular poiont.
incedent - The vector representing incedent light.
Returns:
The reflection of the incendent vector.

equals

public boolean equals(Vec3f that)
Returns true if this vector is the same as the provided vector

Parameters:
that - The vector to be compared with this vector
Returns:
true if the this vector and the provided vector are equivalent.

toPixel

public int toPixel()
Returns a representation of this vector as a colored pixel value, with RGB in the lower 24 bits.

Returns:
The 32 bit pixel representation of this vector.

perturb

public void perturb()
Perturbs the normal slightly