topical media & game development
graphic-processing-algorithm-Ch10-p259-MyVector.pde / pde
class MyVector{
float x,y,z;
MyVector(){
x=y=z=0.;
}
MyVector(float xin, float yin, float zin){
x = xin;
y = yin;
z = zin;
}
MyVector buildVector( MyPoint vert2, MyPoint vert1){
x = vert2.x-vert1.x;
y = vert2.y-vert1.y;
z = vert2.z-vert1.z;
return this;
}
float dot(MyVector v1){
return v1.x*x+v1.y*y+v1.z*z;
}
void cross(MyVector a){
MyVector temp = new MyVector(0.,0.,0.);
temp.x = a.y * z - a.z * y;
temp.y = x * a.z - z * a.x;
temp.z = a.x * y - a.y * x;
x = temp.x;
y = temp.y;
z = temp.z;
}
void norm(){
float t = sqrt(x*x+y*y+z*z);
x = x/t;
y = y/t;
z = z/t;
}
void print(){
println("x:" + x);
println("y:" + y);
println("z:" + z);
}
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.