topical media & game development
graphic-processing-algorithm-Ch03-p83-MyPoint.pde / pde
class MyPoint {
float x, y; // members of class
boolean isSelected = false; // is this point selected?
//********** 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(PI/180*angle);
sina = sin(PI/180*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;
}
//************* Select
boolean select(float xpick, float ypick, float tolerance){
if(abs(x - xpick) < tolerance &&
abs(y - ypick) < tolerance ) {
isSelected = true;
return true;
}
else {
isSelected = false;
}
return false;
}
}
(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.