topical media & game development
graphic-processing-algorithm-Ch03-p80-MyPoint.pde / pde
class MyPoint {
float x, y; // members of class
//Constructor
MyPoint(float xin, float yin){
x = xin;
y = yin;
}
//Move
void move(float xoff, float yoff){
x += xoff;
y += yoff;
}
//Rotate
void rotate(float angle, MyPoint ref){
float cosa, sina;
cosa = cos(radians(angle));
sina = sin(radians(angle));
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;
}
//Scale
void scale(float xs, float ys, MyPoint ref){
x = (x-ref.x)*xs + ref.x;
y = (y-ref.y)*ys + ref.y;
}
}
(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.