void base_c::draw() { if (this->active == true) { glPushMatrix(); glRotateZ(45); // angle for grid glTranslatef(grid_draw.x, grid_draw.y, 0.1); // translate into position engine.get_meshtable()->get_default_mesh()->draw(); glPopMatrix(1); } }
void RubiksCube::Draw(touchPosition touchXY) { int viewport[]={0,0,255,191}; // used later for gluPickMatrix() int16 vx, vy, vz, vsize; vx = f32tov16(Position.X); vy = f32tov16(Position.Y); vz = f32tov16(Position.Z); vsize = f32tov16(Size); glPushMatrix(); { glRotateY(90); glRotateZ(180); if(Twisting||AutoTwisting) { int ax=0; // Rotate so we draw the cube the right way round while(ax<Twist.axis) { glRotateX(90); glRotateZ(90); ax++; } if(Twist.position==0 || Twist.position==3) glRotateZ(Twist.rotation); DrawSide(Twist.left.side,Twist.axis,Position.X,Position.Y,Position.Z,Size,false); glBegin(GL_QUADS); glColor3f(0,0,0); glVertex3v16(vx + vsize, vy, vz + f32tov16(divf32(Size,inttof32(3)))); glVertex3v16(vx, vy, vz + f32tov16(divf32(Size,inttof32(3)))); glVertex3v16(vx, vy + vsize, vz + f32tov16(divf32(Size,inttof32(3)))); glVertex3v16(vx + vsize, vy + vsize, vz + f32tov16(divf32(Size,inttof32(3)))); glEnd(); if(Twist.position==0 || Twist.position==3) glRotateZ(-Twist.rotation); glRotateY(180); if(Twist.position==2 || Twist.position==3) glRotateZ(-Twist.rotation); DrawSide(Twist.right.side,Twist.axis+3,Position.X,Position.Y,Position.Z,Size,false); glBegin(GL_QUADS); glColor3f(0,0,0); glVertex3v16(vx + vsize, vy, vz + f32tov16(divf32(Size,inttof32(3)))); glVertex3v16(vx, vy, vz + f32tov16(divf32(Size,inttof32(3)))); glVertex3v16(vx, vy + vsize, vz + f32tov16(divf32(Size,inttof32(3)))); glVertex3v16(vx + vsize, vy + vsize, vz + f32tov16(divf32(Size,inttof32(3)))); glEnd(); if(Twist.position==2 || Twist.position==3) glRotateZ(Twist.rotation); glRotateY(90); glRotateX(-90); if(Twist.position==1 || Twist.position==3) glRotateX(Twist.rotation); glBegin(GL_QUADS); glColor3f(0,0,0); glVertex3v16(vx + f32tov16(divf32(Size,inttof32(3))), vy, vz); glVertex3v16(vx + f32tov16(divf32(Size,inttof32(3))), vy + vsize, vz); glVertex3v16(vx + f32tov16(divf32(Size,inttof32(3))), vy + vsize, vz + vsize); glVertex3v16(vx + f32tov16(divf32(Size,inttof32(3))), vy, vz + vsize); glVertex3v16(vx + f32tov16(divf32(Size,inttof32(3)))*2, vy, vz); glVertex3v16(vx + f32tov16(divf32(Size,inttof32(3)))*2, vy, vz + vsize); glVertex3v16(vx + f32tov16(divf32(Size,inttof32(3)))*2, vy + vsize, vz + vsize); glVertex3v16(vx + f32tov16(divf32(Size,inttof32(3)))*2, vy + vsize, vz); glEnd(); if(Twist.position==1 || Twist.position==3) glRotateX(-Twist.rotation); for(int i=0;i<4;i++) { if(Twist.position==0) glRotateX(Twist.rotation); DrawLine(Twist.left.line[i],Position.X,Position.Y,Position.Z,Size/3); if(Twist.position==0) glRotateX(-Twist.rotation); if(Twist.position==1) glRotateX(Twist.rotation); DrawLine(Twist.middle.line[i],Position.X+(Size/3),Position.Y,Position.Z,Size/3); if(Twist.position==1) glRotateX(-Twist.rotation); if(Twist.position==2) glRotateX(Twist.rotation); DrawLine(Twist.right.line[i],Position.X+(Size/3*2),Position.Y,Position.Z,Size/3); if(Twist.position==2) glRotateX(-Twist.rotation); glRotateX(90); } }else{ for(int i=0;i<3;i++) { DrawSide(Side[i],i,Position.X,Position.Y,Position.Z,Size, false); glRotateY(180); DrawSide(Side[i+3],i+3,Position.X,Position.Y,Position.Z,Size, false); glRotateX(90); glRotateZ(-90); } } } glPopMatrix(1); if(Picking) { glPushMatrix(); for(int i=0;i<3;i++) clicked[i]=0; closeW = 0x7FFFFFFF; //reset the distance //set the viewport to just off-screen, this hides all rendering that will be done during picking glViewport(0,192,0,192); // setup the projection matrix for picking glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPickMatrix((touchXY.px),(191-touchXY.py),4,4,viewport); // render only what is below the cursor gluPerspective(70, 256.0 / 192.0, 0.1, 20); // this must be the same as the original perspective matrix glMatrixMode(GL_MODELVIEW); // switch back to modifying the modelview matrix for drawing { glRotateY(90); glRotateZ(180); for(int i=0;i<3;i++) { DrawSide(Side[i],i,Position.X,Position.Y,Position.Z,Size, true); glRotateY(180); DrawSide(Side[i+3],i+3,Position.X,Position.Y,Position.Z,Size, true); glRotateX(90); glRotateZ(-90); } } glViewport(0,0,255,191); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70, 256.0 / 192.0, 0.1, 20); glMatrixMode(GL_MODELVIEW); if(closeW<0x7FFFFFFF) { if(Painting) { if(Side[clicked[0]].tile[clicked[1]][clicked[2]].color!=paintColour) { if(undoQueue.numEntries==0) { undoQueue.numEntries++; undoQueue.currentEntry=0; } else if(undoQueue.currentEntry < (undoQueue.numEntries-1)) { undoQueue.currentEntry++; undoQueue.numEntries=undoQueue.currentEntry+1; } else if(undoQueue.numEntries==20) { for(int i=0; i<19; i++) { undoQueue.entry[i]=undoQueue.entry[i+1]; } } else { undoQueue.numEntries++; undoQueue.currentEntry++; } undoQueue.entry[undoQueue.currentEntry].from=Side[clicked[0]].tile[clicked[1]][clicked[2]].color; undoQueue.entry[undoQueue.currentEntry].to=paintColour; for(int i=0; i<3; i++) undoQueue.entry[undoQueue.currentEntry].position[i]=clicked[i]; Side[clicked[0]].tile[clicked[1]][clicked[2]].color=paintColour; } }else{ Grabbing=true; Picking=false; } } glPopMatrix(1); }else{ //Twisting=false; } }