//Draw arm of player who is throwing
float p1_x = ent1->GetMapX();
float p1_y = ent1->GetMapY();
float p2_x = ent2->GetMapX();
float p2_y = ent2->GetMapY();
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, g_textureID[ent1->GetTextureID()]);
switch(turn)
{
case PLAYER1_TURN:
glRotatef((float)ent1->GetAngle(), 0.0f, 0.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(SPRITE_SIZE * 2, SPRITE_SIZE * 6); glVertex2f((float)(p1_x * TILE_SIZE), (float)(p1_y * TILE_SIZE)); // Bottom Left Of The Texture and Quad
glTexCoord2f(SPRITE_SIZE * 3, SPRITE_SIZE * 6); glVertex2f((float)(p1_x * TILE_SIZE + TILE_SIZE), (float)(p1_y * TILE_SIZE)); // Bottom Right Of The Texture and Quad
glTexCoord2f(SPRITE_SIZE * 3, SPRITE_SIZE * 7); glVertex2f((float)(p1_x * TILE_SIZE+ TILE_SIZE), (float)(p1_y * TILE_SIZE - TILE_SIZE)); // Top Right Of The Texture and Quad
glTexCoord2f(SPRITE_SIZE * 2, SPRITE_SIZE * 7); glVertex2f((float)(p1_x * TILE_SIZE), (float)(p1_y * TILE_SIZE - TILE_SIZE)); // Top left of the texture and quad
glEnd();
break;
case PLAYER2_TURN:
glRotatef((float)ent1->GetAngle(), 0.0f, 0.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(SPRITE_SIZE * 2, SPRITE_SIZE * 6); glVertex2f((float)(p1_x * TILE_SIZE), (float)(p1_y * TILE_SIZE)); // Bottom Left Of The Texture and Quad
glTexCoord2f(SPRITE_SIZE * 3, SPRITE_SIZE * 6); glVertex2f((float)(p1_x * TILE_SIZE + TILE_SIZE), (float)(p1_y * TILE_SIZE)); // Bottom Right Of The Texture and Quad
glTexCoord2f(SPRITE_SIZE * 3, SPRITE_SIZE * 7); glVertex2f((float)(p1_x * TILE_SIZE+ TILE_SIZE), (float)(p1_y * TILE_SIZE - TILE_SIZE)); // Top Right Of The Texture and Quad
glTexCoord2f(SPRITE_SIZE * 2, SPRITE_SIZE * 7); glVertex2f((float)(p1_x * TILE_SIZE), (float)(p1_y * TILE_SIZE - TILE_SIZE)); // Top left of the texture and quad
glEnd();
break;
}
Z rotation issue
hiya,
When I attempt to rotate a quad on it's z-axis using glRotate3f() I get odd results. Instead of rotation on it's axis as if it was on a fan, as described in NeHe's tuts, it rotates on a BIG arc. Am I missing a call somewhere that may be causing this problem?
Here is some code...Now the angle would be the angle that is currently set for the quad to rotate on (obviously).
I have set the MODELVIEW_MATRIX about this im my app as well. Anything I am missing?
[edit]Also, when rotating a quad or shape, if I rotate based on a variable I have initialized to 45 degrees will the quad change positions in it's axis everytime I call Render()? Or will it be always just the quad shown the same way everytime without changing position?? I'm not sure I totally understand how glRotate is used.
I *believe* it's because of the way you're specifying the tiles. I'm not positive (a bit rusty), but I believe you should be:
1) glTranslate
2) glRotate
3) draw the polygon at the origin
The translation and rotation in that order should position it and rotate it correctly. I *think*.
I think I am rendering things incorrectly. This is my rendering code:Should I be using glTranslate3f() instead of the way I am using glVertext() calls?
void Video::Render(HDC &hDC, Entity *ent1, Entity *ent2, Sprite *map[3][MAP_HEIGHT][MAP_WIDTH], int turn){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor3f(1.0f, 1.0f, 1.0f); glEnable(GL_TEXTURE_2D); if(g_bBlendOutColorKey == true) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } //Tile the sky glBindTexture(GL_TEXTURE_2D, g_textureID[2]); for(int y = 0; y < MAP_HEIGHT; y++) { for(int x = 0; x < MAP_WIDTH; x++) { if(map[0][y][x] != NULL) { glBegin(GL_QUADS); glTexCoord2f((float)map[0][y][x]->left, (float)map[0][y][x]->bottom); glVertex2f((float)(x * TILE_SIZE), (float)(y * TILE_SIZE + TILE_SIZE)); // Bottom Left Of The Texture and Quad glTexCoord2f((float)map[0][y][x]->right, (float)map[0][y][x]->bottom); glVertex2f((float)(x * TILE_SIZE + TILE_SIZE), (float)(y * TILE_SIZE + TILE_SIZE)); // Bottom Right Of The Texture and Quad glTexCoord2f((float)map[0][y][x]->right, (float)map[0][y][x]->top); glVertex2f((float)(x * TILE_SIZE + TILE_SIZE), (float)(y * TILE_SIZE)); // Top Right Of The Texture and Quad glTexCoord2f((float)map[0][y][x]->left, (float)map[0][y][x]->top); glVertex2f((float)(x * TILE_SIZE), (float)(y * TILE_SIZE)); // Top left of the texture and quad glEnd(); } } } //Tile the buildings glBindTexture(GL_TEXTURE_2D, g_textureID[1]); for(int y = 0; y < MAP_HEIGHT; y++) { for(int x = 0; x < MAP_WIDTH; x++) { if(map[1][y][x] != NULL) { glBegin(GL_QUADS); glTexCoord2f((float)map[1][y][x]->left, (float)map[1][y][x]->bottom); glVertex2f((float)(x * TILE_SIZE), (float)(y * TILE_SIZE + TILE_SIZE)); // Bottom Left Of The Texture and Quad glTexCoord2f((float)map[1][y][x]->right, (float)map[1][y][x]->bottom); glVertex2f((float)(x * TILE_SIZE + TILE_SIZE), (float)(y * TILE_SIZE + TILE_SIZE)); // Bottom Right Of The Texture and Quad glTexCoord2f((float)map[1][y][x]->right, (float)map[1][y][x]->top); glVertex2f((float)(x * TILE_SIZE + TILE_SIZE), (float)(y * TILE_SIZE)); // Top Right Of The Texture and Quad glTexCoord2f((float)map[1][y][x]->left, (float)map[1][y][x]->top); glVertex2f((float)(x * TILE_SIZE), (float)(y * TILE_SIZE)); // Top left of the texture and quad glEnd(); } } } //Draw arm of player who is throwing float p1_x = ent1->GetMapX(); float p1_y = ent1->GetMapY(); float p2_x = ent2->GetMapX(); float p2_y = ent2->GetMapY(); glLoadIdentity(); glBindTexture(GL_TEXTURE_2D, g_textureID[ent1->GetTextureID()]); switch(turn) { case PLAYER1_TURN: glRotatef((float)ent1->GetAngle(), 0.0f, 0.0f, 1.0f); glBegin(GL_QUADS); glTexCoord2f(SPRITE_SIZE * 2, SPRITE_SIZE * 6); glVertex2f((float)(p1_x * TILE_SIZE), (float)(p1_y * TILE_SIZE)); // Bottom Left Of The Texture and Quad glTexCoord2f(SPRITE_SIZE * 3, SPRITE_SIZE * 6); glVertex2f((float)(p1_x * TILE_SIZE + TILE_SIZE), (float)(p1_y * TILE_SIZE)); // Bottom Right Of The Texture and Quad glTexCoord2f(SPRITE_SIZE * 3, SPRITE_SIZE * 7); glVertex2f((float)(p1_x * TILE_SIZE+ TILE_SIZE), (float)(p1_y * TILE_SIZE - TILE_SIZE)); // Top Right Of The Texture and Quad glTexCoord2f(SPRITE_SIZE * 2, SPRITE_SIZE * 7); glVertex2f((float)(p1_x * TILE_SIZE), (float)(p1_y * TILE_SIZE - TILE_SIZE)); // Top left of the texture and quad glEnd(); break; case PLAYER2_TURN: glRotatef((float)ent1->GetAngle(), 0.0f, 0.0f, 1.0f); glBegin(GL_QUADS); glTexCoord2f(SPRITE_SIZE * 2, SPRITE_SIZE * 6); glVertex2f((float)(p1_x * TILE_SIZE), (float)(p1_y * TILE_SIZE)); // Bottom Left Of The Texture and Quad glTexCoord2f(SPRITE_SIZE * 3, SPRITE_SIZE * 6); glVertex2f((float)(p1_x * TILE_SIZE + TILE_SIZE), (float)(p1_y * TILE_SIZE)); // Bottom Right Of The Texture and Quad glTexCoord2f(SPRITE_SIZE * 3, SPRITE_SIZE * 7); glVertex2f((float)(p1_x * TILE_SIZE+ TILE_SIZE), (float)(p1_y * TILE_SIZE - TILE_SIZE)); // Top Right Of The Texture and Quad glTexCoord2f(SPRITE_SIZE * 2, SPRITE_SIZE * 7); glVertex2f((float)(p1_x * TILE_SIZE), (float)(p1_y * TILE_SIZE - TILE_SIZE)); // Top left of the texture and quad glEnd(); break; } //Draw players glLoadIdentity(); glBegin(GL_QUADS); //player 1 glTexCoord2f(ent1->GetImage().left, ent1->GetImage().bottom); glVertex2f((float)(p1_x * TILE_SIZE), (float)(p1_y * TILE_SIZE)); // Bottom Left Of The Texture and Quad glTexCoord2f(ent1->GetImage().right, ent1->GetImage().bottom); glVertex2f((float)(p1_x * TILE_SIZE + TILE_SIZE), (float)(p1_y * TILE_SIZE)); // Bottom Right Of The Texture and Quad glTexCoord2f(ent1->GetImage().right, ent1->GetImage().top); glVertex2f((float)(p1_x * TILE_SIZE+ TILE_SIZE), (float)(p1_y * TILE_SIZE - TILE_SIZE)); // Top Right Of The Texture and Quad glTexCoord2f(ent1->GetImage().left, ent1->GetImage().top); glVertex2f((float)(p1_x * TILE_SIZE), (float)(p1_y * TILE_SIZE - TILE_SIZE)); // Top left of the texture and quad //player 2 glTexCoord2f(ent2->GetImage().left, ent2->GetImage().bottom); glVertex2f((float)(p2_x * TILE_SIZE), (float)(p2_y * TILE_SIZE)); // Bottom Left Of The Texture and Quad glTexCoord2f(ent2->GetImage().right, ent2->GetImage().bottom); glVertex2f((float)(p2_x * TILE_SIZE + TILE_SIZE), (float)(p2_y * TILE_SIZE)); // Bottom Right Of The Texture and Quad glTexCoord2f(ent2->GetImage().right, ent2->GetImage().top); glVertex2f((float)(p2_x * TILE_SIZE+ TILE_SIZE), (float)(p2_y * TILE_SIZE - TILE_SIZE)); // Top Right Of The Texture and Quad glTexCoord2f(ent2->GetImage().left, ent2->GetImage().top); glVertex2f((float)(p2_x * TILE_SIZE), (float)(p2_y * TILE_SIZE - TILE_SIZE)); // Top left of the texture and quad glEnd(); glDisable(GL_TEXTURE_2D); //Put Scores on screen glBindTexture(GL_TEXTURE_2D, g_textureID[3]); PrintGL(20, 420, 1, "Player 1"); glBindTexture(GL_TEXTURE_2D, g_textureID[3]); PrintGL(480, 420, 1, "Player 2"); glDisable(GL_BLEND); SwapBuffers(hDC);}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement