topical media & game development
graphic-processing-algorithm-Ch10-p265-MySolid.pde / pde
class MySolid {
MyFace[] faces;
int nfaces;
color c;
boolean isSelected = false;
//*****************************
MySolid(MyPoint[] inPoints, float height){
nfaces = 0;
faces = new MyFace[inPoints.length + 2];
//bottom
faces[0] = new MyFace(inPoints);
nfaces++;
//top
faces[ nfaces] = new MyFace(inPoints);
faces[ nfaces].move(0., 0., height);
nfaces++;
MyPoint[] side;
side = new MyPoint[4];
for(int i=0; i<inPoints.length-1; i++){
side[0] = new MyPoint(faces[0].points[i].x, faces[0].points[i].y, faces[0].points[i].z );
side[1] = new MyPoint(faces[0].points[i+1].x,faces[0].points[i+1].y,faces[0].points[i+1].z );
side[2] = new MyPoint(faces[1].points[i+1].x,faces[1].points[i+1].y,faces[1].points[i+1].z );
side[3] = new MyPoint(faces[1].points[i].x, faces[1].points[i].y, faces[1].points[i].z );
faces[ nfaces] = new MyFace(side);
nfaces++;
}
// last side face
int last = inPoints.length-1;
side[0] = new MyPoint(faces[0].points[last].x, faces[0].points[last].y, faces[0].points[last].z );
side[1] = new MyPoint(faces[0].points[0].x,faces[0].points[0].y,faces[0].points[0].z );
side[2] = new MyPoint(faces[1].points[0].x,faces[1].points[0].y,faces[1].points[0].z );
side[3] = new MyPoint(faces[1].points[last].x, faces[1].points[last].y, faces[1].points[last].z );
faces[ nfaces] = new MyFace(side);
nfaces++;
// reverse the order of the bottom face
MyPoint[] revPoints;
revPoints = new MyPoint[inPoints.length];
for(int i=0; i<inPoints.length; i++){
revPoints[i] = new MyPoint(inPoints[inPoints.length-1-i].x,
inPoints[inPoints.length-1-i].y,
inPoints[inPoints.length-1-i].z);
}
faces[0] = new MyFace(revPoints);
}
MySolid(MyFace[] inFaces){
nfaces = inFaces.length;
faces = new MyFace[nfaces];
for(int i=0; i<nfaces; i++)
faces[i] = new MyFace(inFaces[i].points);
}
void setColor(color cin){
for(int i=0; i< nfaces; i++)
faces[i].setColor(cin);
}
void draw(){
for(int i=0; i< nfaces; i++)
//if(faces[i].isVisible())faces[i].draw();
faces[i].draw();
}
void rotatex (float angle, MyPoint ref) {
for(int i=0; i< nfaces; i++)
faces[i].rotatex(angle, ref);
}
void rotatey (float angle, MyPoint ref) {
for(int i=0; i< nfaces; i++)
faces[i].rotatey(angle, ref);
}
void rotatez (float angle, MyPoint ref) {
for(int i=0; i< nfaces; i++)
faces[i].rotatez(angle, ref);
}
void scale(float xs, float ys, float zs, MyPoint ref) {
for(int i=0; i< nfaces; i++)
faces[i].scale(xs, ys, zs, ref);
}
void move(float xoff, float yoff, float zoff){
for(int i=0; i< nfaces; i++)
faces[i].move(xoff, yoff, zoff);
}
void setSelected(boolean what){
for(int i=0; i< nfaces; i++)
faces[i].setSelected(what);
}
boolean pick(int xmouse, int ymouse){
for(int i=0; i< nfaces; i++)
if(faces[i].pick(xmouse,ymouse))
return true;
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.