|
En enkel demo av bruk av gob. Fallende klosser.
void drawFallingBoxes()
{
// a demo with some falling boxes
hb.setBackground(new Color(1.0f,1.0f,1.0f));
// use default viewport and ortho, full applet
// boxes are "falling" in the direction of pos y
hb.translate(FALLWIDTH/2.0f+3.0f,0.0f,0.0f);
for(int ix=0;ix< BOX_COUNT;ix++)
{
boxpos[ix]+=FALLSTEP;
if(boxpos[ix] > FALLHEIGHT)
boxpos[ix]-=FALLHEIGHT;
hb.pushMatrix();
hb.translate(0.0f,boxpos[ix],0.0f);
if(ix%2==0)
hb.rotateZ(vz);
else
hb.rotateZ(-2*vz);
if(ix%3==0)
hb.rotateX(vx);
else
hb.rotateX(-vx);
if(ix%2==0)
hb.rotateY(2*vy);
else
hb.rotateY(vy);
hb.setColor(boxcolor[ix]);
hb.drawBox(BOX_SIDE,BOX_SIDE,BOX_SIDE,gob.FILL);
hb.popMatrix();
}
Rotasjonsvinklene vx,vy,vz blir oppdatert i appletens Run-metode. Du kan stoppe appleten med høyre klikk og justere rotasjonen med venstre-drag. Full source: a3dfalling.java |