void CPaintDlg::DrawRobots() { Invalidate(); AfxGetApp()->PumpMessage(); OnPaint(); if (cameraLock > -1) { upperleftCellCoords[0] = robots[cameraLock]->x-fieldSide/2; upperleftCellCoords[1] = robots[cameraLock]->y-fieldSide/2; if (upperleftCellCoords[0]<0) upperleftCellCoords[0]+=FieldParameters.fieldWidth; if (upperleftCellCoords[0]>=FieldParameters.fieldWidth) upperleftCellCoords[0]-=FieldParameters.fieldWidth; if (upperleftCellCoords[1]<0) upperleftCellCoords[1]+=FieldParameters.fieldHeight; if (upperleftCellCoords[1]>=FieldParameters.fieldHeight) upperleftCellCoords[1]-=FieldParameters.fieldHeight; } int xlocal = 0; int ylocal = 0; int xreal, yreal; for (int x = upperleftCellCoords[0]; x < upperleftCellCoords[0]+n; x++) { xreal = x; if (xreal<0) xreal+=FieldParameters.fieldWidth; if (xreal>=FieldParameters.fieldWidth) xreal-=FieldParameters.fieldWidth; for (int y = upperleftCellCoords[1]; y < upperleftCellCoords[1]+n; y++) { yreal = y; if (yreal<0) yreal+=FieldParameters.fieldHeight; if (yreal>=FieldParameters.fieldHeight) yreal-=FieldParameters.fieldHeight; if (matrix[xreal][yreal] > -1) DrawRobot(xlocal,ylocal,robots[matrix[xreal][yreal]]->color); else if (matrix[xreal][yreal] == SEVERAL) DrawRobot(xlocal,ylocal,Black); else if (matrix[xreal][yreal] == OBJ_DEAD) DrawRobot(xlocal,ylocal,White); else if (matrix[xreal][yreal] < -1) DrawObject(xlocal,ylocal,matrix[xreal][yreal]); ylocal++; } xlocal++; ylocal = 0; } }
//************************************************************************* // display callback //************************************************************************* void display(void) { // clear the window glClear (GL_COLOR_BUFFER_BIT); // working with the GL_MODELVIEW Matrix glMatrixMode(GL_MODELVIEW); //********************************** // we work on a copy of the current MODELVIEW matrix, hence we need to... //********************************** //********************************** // Rotate the robot around the x-axis and y-axis according to the relevant angles //********************************** // draw the robot DrawRobot(); //********************************** // not anymore on a local reference system //********************************** // flush drawing routines to the window glutSwapBuffers(); }
void Render() { glEnable(GL_DEPTH_TEST); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); angle += 1.0f; if (angle >= 360.0f) { angle = 0.0f; } glPushMatrix(); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -30.0f); glRotatef(angle, 0.0f, 1.0f, 0.0f); DrawRobot(0.0f,0.0f,0.0f); glPopMatrix(); glFlush(); SwapBuffers(wndDC); }
void NETHER::draw_game(bool shadows) { { MINY=-8*zoom; MINX=-(10+viewp.z*4)*zoom; MAXY=(9+viewp.z*4)*zoom; MAXX=8*zoom; } if (!explosions.EmptyP()) { int minstep=128; List<EXPLOSION> l; EXPLOSION *n; float offs=0.0,r; l.Instance(explosions); l.Rewind(); while(l.Iterate(n)) { if (n->size==2 && n->step<minstep) minstep=n->step; } /* while */ r=(128-minstep)/256.0; offs=sin(minstep)*r; gluLookAt(viewp.x+camera.x*zoom+offs,viewp.y+camera.y*zoom+offs,viewp.z+camera.z*zoom,viewp.x+offs,viewp.y+offs,viewp.z,0,0,1); } else { gluLookAt(viewp.x+camera.x*zoom,viewp.y+camera.y*zoom,viewp.z+camera.z*zoom,viewp.x,viewp.y,viewp.z,0,0,1); } /* if */ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* Draw: */ /* Draw the map: */ drawmap(shadows); /* Draw the robots and bullets: */ { int i; List<ROBOT> l; List<BULLET> l2; ROBOT *r; BULLET *b; for(i=0;i<2;i++) { l.Instance(robots[i]); l.Rewind(); while(l.Iterate(r)) { if (r->pos.y>=(viewp.y+MINY) && r->pos.y<=(viewp.y+MAXY) && r->pos.x>=(viewp.x+MINX) && r->pos.x<=(viewp.x+MAXX)) { glPushMatrix(); glTranslatef(r->pos.x,r->pos.y,r->pos.z); DrawRobot(r,i,shadows); glPopMatrix(); } /* if */ } /* while */ } /* for */ l2.Instance(bullets); l2.Rewind(); while(l2.Iterate(b)) { if (b->pos.y>=(viewp.y+MINY) && b->pos.y<=(viewp.y+MAXY) && b->pos.x>=(viewp.x+MINX) && b->pos.x<=(viewp.x+MAXX)) { glPushMatrix(); glTranslatef(b->pos.x,b->pos.y,b->pos.z); DrawBullet(b,shadows); glPopMatrix(); } /* if */ } /* while */ } /* Draw the ship: */ glPushMatrix(); glTranslatef(shipp.x,shipp.y,shipp.z); if (!shadows) ship->draw(0.7,0.7,0.7); glPopMatrix(); if (shadows) { float sx,sy; float x[2],y[2]; float minz; Vector light; light=lightposv; light=light/light.z; sx=shipp.x-light.x*shipp.z; sy=shipp.y-light.y*shipp.z; if (controlled==0) { x[0]=sx+ship->shdw_cmc.x[0]; x[1]=sx+ship->shdw_cmc.x[1]; y[0]=sy+ship->shdw_cmc.y[0]; y[1]=sy+ship->shdw_cmc.y[1]; minz=MapMaxZ(x,y); } else { minz=controlled->pos.z; } /* if */ glPushMatrix(); glTranslatef(sx,sy,minz+0.05); if (shadows) ship->DrawShadow(0,0,0,0.5); glPopMatrix(); } /* Draw the extras: */ /* Draw nuclear explosions: */ if (!shadows) { List<EXPLOSION> l; EXPLOSION *n; float a,r; l.Instance(explosions); l.Rewind(); while(l.Iterate(n)) { a=(128.0f-n->step)/80.0f; r=1.0; if (n->size==0) { r=(float(n->step)/512.0f)+0.1; } /* if */ if (n->size==1) { r=(float(n->step)/96.0f)+0.5; } /* if */ if (n->size==2) { r=(float(n->step)/48.0f)+1.0; } /* if */ if (a<0) a=0; if (a>1) a=1; glPushMatrix(); glTranslatef(n->pos.x,n->pos.y,n->pos.z); glColor4f(1.0f,0.5f,0.0,a); glDepthMask(GL_FALSE); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glutSolidSphere(r,8,8); glDisable(GL_BLEND); glDepthMask(GL_TRUE); glPopMatrix(); } /* while */ } /* Draw the particles: */ if (!shadows) { List<PARTICLE> l; PARTICLE *p; l.Instance(particles); l.Rewind(); while(l.Iterate(p)) { if (p->pos.y>=(viewp.y+MINY) && p->pos.y<=(viewp.y+MAXY) && p->pos.x>=(viewp.x+MINX) && p->pos.x<=(viewp.x+MAXX)) DrawParticle(p); } /* if */ } /* if */ } /* NETHER::draw_screen */