First Person Objects (Gun) in OpenGL
What have you tried? Did you read the red book chapter on transformations? Are there parts of it you need explained in greater detail?
Don't give up
Sir, e^iπ + 1 = 0, hence God exists; reply!
OK!
I won't give up.
Here's what I've tried:
• Removing all transforms in drawPlayer(), then placing the call to drawPlayer() before glLoadIdentity() ( In display() ). This should work...
• The same as above, yet placing the call to drawPlayer() after glLoadIdentity() but before the camera transforms (glTranslate(-xp,-yp,-zp) ).
• ... And after both the camera transforms and glLoadIdentity().
PS. When I have the call before glLoadIdentity, and this :
as my function, the green (cuboid!?!?!?) appears inside one of the 'flats' (cuboid + imagination)!
I won't give up.
Here's what I've tried:
• Removing all transforms in drawPlayer(), then placing the call to drawPlayer() before glLoadIdentity() ( In display() ). This should work...
• The same as above, yet placing the call to drawPlayer() after glLoadIdentity() but before the camera transforms (glTranslate(-xp,-yp,-zp) ).
• ... And after both the camera transforms and glLoadIdentity().
PS. When I have the call before glLoadIdentity, and this :
Code:
void drawPlayer(void)
{
//glLoadIdentity();
glPushMatrix();
//glLoadIdentity();
//glTranslatef( xp,5.0f,zp+5);
//glRotatef(-pitch,1.0f,0.0f,0.0f);
// glTranslatef(2.0f,2.0f,2.0f );
//glRotatef(-heading,0.0f,1.0f,0.0f);
//glRotatef(pitch,0.0f ,0.0f,1.0f);
glColor3f(0.0f,1.0f,0.0f);
glutSolidCube(2);
//glLoadIdentity();
glPopMatrix();
//glFlush();
//glLoadIdentity();
}as my function, the green (cuboid!?!?!?) appears inside one of the 'flats' (cuboid + imagination)!
~ Bring a Pen ~
Sorry to keep repeating myself, but since you keep dancing around it,
I can understand that you'd rather just bang out some code and have it work than learn the theory, but this is very unhealthy for you as a developer. You need to learn the theory so you can break the dependency on other developers helping you along the way every time you have to do something with transformations. I could give you the exact answer you need to solve this particular problem, but I would be doing you a disservice, since it doesn't actually teach you what you need in the long term.
ThemsAllTook Wrote:Did you read the red book chapter on transformations? Are there parts of it you need explained in greater detail?
I can understand that you'd rather just bang out some code and have it work than learn the theory, but this is very unhealthy for you as a developer. You need to learn the theory so you can break the dependency on other developers helping you along the way every time you have to do something with transformations. I could give you the exact answer you need to solve this particular problem, but I would be doing you a disservice, since it doesn't actually teach you what you need in the long term.
Oooh. That's frustrating

, but I understand
. I have read the section on transformations, and used your own MatrixPlayground. I think I know enough.
glTranslate moves the current matrix (or adds/subtracts) in the specified directions(x,y,z).
glRotate rotates it. glLoadIdentity resets the values of the current matrix to the identity matrix, etc, etc.


, but I understand
. I have read the section on transformations, and used your own MatrixPlayground. I think I know enough. glTranslate moves the current matrix (or adds/subtracts) in the specified directions(x,y,z).
glRotate rotates it. glLoadIdentity resets the values of the current matrix to the identity matrix, etc, etc.
~ Bring a Pen ~
Ah! Now that I know you've gotten that far...
The reason you're not seeing your cube is that it's being drawn at the origin (0, 0, 0), which is the location of the viewer (you can confirm this in the glutSolidCube man page). This means that the cube is being drawn around your point of view, so you're looking out from the inside of it.
I can think of two reasons this would cause you not to be able to see it: 1) If you have GL_CULL_FACE enabled (which is a useful optimization, so you usually will want to), back faces won't be drawn, so you'll never see the inside of the cube; 2) If your near clipping plane (in your call to glOrtho/glFrustum/gluPerspective) is closer than the size of your cube, the closest face won't be far enough away to be visible. In either of these cases, you'll want to translate to a different location where the cube will be visible. Remember that in screen space, the axes left to right (x), bottom to top (y), and back to front (z).
Anyway, I didn't mean to be playing games with you, but there was some discussion about this sort of thing recently which elaborates on my reasons for responding this way. But now that I know you're going about this the right way and just want a nudge in the right direction to understand, we can help with that.
The reason you're not seeing your cube is that it's being drawn at the origin (0, 0, 0), which is the location of the viewer (you can confirm this in the glutSolidCube man page). This means that the cube is being drawn around your point of view, so you're looking out from the inside of it.
I can think of two reasons this would cause you not to be able to see it: 1) If you have GL_CULL_FACE enabled (which is a useful optimization, so you usually will want to), back faces won't be drawn, so you'll never see the inside of the cube; 2) If your near clipping plane (in your call to glOrtho/glFrustum/gluPerspective) is closer than the size of your cube, the closest face won't be far enough away to be visible. In either of these cases, you'll want to translate to a different location where the cube will be visible. Remember that in screen space, the axes left to right (x), bottom to top (y), and back to front (z).
Anyway, I didn't mean to be playing games with you, but there was some discussion about this sort of thing recently which elaborates on my reasons for responding this way. But now that I know you're going about this the right way and just want a nudge in the right direction to understand, we can help with that.
Thankyou very very much! 

I will keep the source of this game as a reference for others!


I will keep the source of this game as a reference for others!
~ Bring a Pen ~
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Third Person Control | PAD Games | 4 | 2,620 |
Jun 22, 2005 01:59 AM Last Post: PAD Games |
|
| 3rd person camera | JeroMiya | 3 | 2,636 |
Jan 11, 2004 07:13 PM Last Post: JeroMiya |
|
| Releasing OpenGL Objects | Jake | 3 | 2,513 |
Dec 10, 2003 11:21 AM Last Post: arekkusu |
|
| openGL 2d drawing problems, objects appear to overlap | matthew | 12 | 4,799 |
Oct 5, 2003 07:53 PM Last Post: matthew |
|
| drawing objects in openGL, plane question. | xDexx | 7 | 4,628 |
Apr 28, 2003 01:06 PM Last Post: OneSadCookie |
|

