PDA

View Full Version : Render weapons in players viewport



Luminous Blue
07-23-2002, 05:09 AM
How to render a weapon model in the player viewport ?

thx

davepermen
07-23-2002, 05:20 AM
http://www.gamedev.net/community/forums/topic.asp?topic_id=102818
http://www.gamedev.net/community/forums/topic.asp?topic_id=104922

Luminous Blue
07-23-2002, 06:43 AM
Thx http://www.opengl.org/discussion_boards/ubb/smile.gif davepermen for the quick reply !
I work on it !

Luminous Blue
07-23-2002, 09:15 AM
I looked at the discussion at gamedev and tested gluOrtho2D but it doesn't work well.
I thougth about the Modelview and the result is that some things are so simple.

Hope that's right or are there any other solutions? (it works fine!)


// Start Rendering

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();


glPushMatrix();

gluLookAt(..........);


DrawTheLevel <----------------

glPopMatrix();


glDisable(GL_DEPTH_TEST);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glTranslatef( 10.0f, -10.0f, -5.0f); // Set the position
glRotatef(0.0f, 1.0f, 0.0f, 0.0f);
glRotatef(-270.0f, 0.0f, 1.0f, 0.0f); // Rotate the weapon -> Y axis


DrawTheWeapon <----------------

glPopMatrix();
glEnable(GL_DEPTH_TEST);

// End Rendering

Nutty
07-23-2002, 09:27 AM
What exactly is the problem? The way I do my guns in the current game I'm working on, is to simply render them at the players position. The artists setup the mesh, so that theres a camera at the pivot point in the mesh in Maya/Max, so that they can see how the weapon will be viewed ingame.

You also need to stop it intersecting with world-geometry. Simplest way is to simply clear the Zbuffer before drawing the gun. But there are probably faster methods out there.

Nutty

Luminous Blue
07-23-2002, 01:36 PM
1st forget glDisable(GL_DEPTH_TEST) it's a bad way to draw a 3d weapon model.
Use glClear(GL_DEPTH_BUFFER_BIT) thx Nutty!

I use 3ds files for the level and the weapons
1. update camera (camclass->glulookat)
2. render the level Ok fine
3. render the weapon on players position
(player pos is the 1st camera in the scene)

The problem:

The weapon will not rotate with the camera when i update the pos/-viewvector by mouse or keyboard. (Camera Class works fine in the given scene)

thx
LB

ScottManDeath
07-24-2002, 06:14 AM
Hi

I would do it in the following way

1. clear all buffers
2. apply camera transform
3. render scene
4. set modelview matrix to identity
5. disable depth writes
6. render the weapon, hud
7. enable depth writes
8. swap buffers

so your weapons, the hud are always facing towards the screen

Bye
ScottManDeath

Nutty
07-24-2002, 09:39 AM
IF you disable Z writes, your weapons wont be rendered correctly. What if it draws the polys near the player 1st? The polys at the end of the gun will over-write it. Also your method wont prevent your gun intersecting walls when you get up close.

You could depth sort your guns poly list. But you're better off just clearing the Z buffer, you know for a fact it will render perfectly then.

As for having the gun rotate. You should just be able to rotate the weapon with the same angle as the camera. Or render with an identity matrix, so that camera position/rotation is completely neglected when rendering the gun. Only problem then is linking up with stuff happening in the transformed world.

Nutty

[This message has been edited by Nutty (edited 07-24-2002).]

ScottManDeath
07-24-2002, 11:08 AM
Originally posted by Nutty:
IF you disable Z writes, your weapons wont be rendered correctly. What if it draws the polys near the player 1st? The polys at the end of the gun will over-write it. Also your method wont prevent your gun intersecting walls when you get up close.


Hi

you are right. I mixed it up with rendering HUD. OK just clear the Z buffer and render it
bye
ScottManDeath

knackered
07-24-2002, 12:15 PM
Why don't you implement a hiearchy?
Your gun with simply be a child of your camera, so the guns transform would be multiplied with its parent (ie. the camera) and would therefore be locked in front of the camera. It's much more elegant than loading identity, etc.

Luminous Blue
07-24-2002, 01:25 PM
Hi
I be back it was a hard day at work (thing i need some freetime)

-> ScottManDeath
This is the way i do but with clearing the Z buffer (now - look above)

->knackered
i think about it (test it)

(i need sleep)

Thx 4 help
LB