topical media & game development
graphic-processing-algorithm-Ch10-p259-MyPoint.pde / pde
class MyPoint {
float x,y,z;
color c;
MyPoint(float i, float j, float k){
x = i;
y = j;
z = k;
}
void setColor(color cin){
c = cin;
}
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;
}
void draw(){
beginShape(POINTS);
vertex(x,y,z);
endShape();
}
float xscreen(){
float sx = screenX(x, y, z);
return sx;
}
float yscreen(){
return screenY(x, y, 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.