topical media & game development
graphic-processing-algorithm-Ch04-p102-MyGroup.pde / pde
class MyGroup {
// members of class
MyShape[] shapes; // array of shapes
int numShapes; //number of shapes
boolean isSelected = false; // is this shape selected?
//********** Constructor
MyGroup(int numInputShapes, MyShape[] inputShapes){
numShapes = numInputShapes;
shapes = new MyShape[numShapes];
for(int i=0; i<numShapes; i++)
shapes[i] = inputShapes[i];
}
//********** Move
void move(float xoff, float yoff){
for(int i=0; i<numShapes; i++)
shapes[i].move(xoff, yoff);
}
//********** Rotate
void rotate (float angle, MyPoint ref) {
for(int i=0; i<numShapes; i++)
shapes[i].rotate(angle, ref);
}
//********** Scale
void scale(float xs, float ys, MyPoint ref){
for(int i=0; i<numShapes; i++)
shapes[i].scale(xs, ys, ref);
}
//*********** draw
void draw( ){
for(int i=0; i<numShapes; i++)
shapes[i].draw();
}
//******** Select
boolean select(float xpick, float ypick, float tolerance){
for(int i=0; i<numShapes; i++){
if(shapes[i].select(xpick, ypick, tolerance)==true){
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.