topical media & game development
graphic-processing-algorithm-Ch09-p214-MyPoint.pde / pde
class MyPoint{
float x,y,z; //a 3D coordinate
MyPoint(float xin, float yin, float zin){
x = xin;
y = yin;
z = zin;
}
void rotatez (float angle, MyPoint ref) {
float cosa, sina;
cosa = cos(angle);
sina = sin(angle);
//Rotates point around z-axis
float newx = (x-ref.x) * cosa - (y-ref.y) * sina + ref.x;
float newy = (y-ref.y) * cosa + (x-ref.x) * sina + ref.y;
x = newx;
y = newy;
}
void rotatex (float angle, MyPoint ref) {
float cosa, sina;
cosa = cos(angle);
sina = sin(angle);
//Rotates point around x-axis
float newx = (x-ref.x) * cosa + (z-ref.z) * sina + ref.x;
float newz = (z-ref.z) * cosa - (x-ref.x) * sina + ref.z;
x = newx;
z = newz;
}
void rotatey (float angle, MyPoint ref) {
float cosa, sina;
cosa = cos(angle);
sina = sin(angle);
//Rotates point around y-axis
float newy = (y-ref.y) * cosa + (z-ref.z) * sina + ref.y;
float newz = (z-ref.z) * cosa - (y-ref.y) * sina + ref.z;
y = newy;
z = newz;
}
void scale (float sx, float sy, float sz, MyPoint ref) {
x = (x-ref.x)*sx + ref.x;
y = (y-ref.y)*sy + ref.y;
z = (z-ref.z)*sz + ref.z;
}
void move(float xoff, float yoff, float zoff){
x += xoff;
y += yoff;
z += zoff;
}
}
(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.