# OpenGL Help, adding a weapon model to a shooter.

This topic is 3554 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello people, I'm a noob at opengl but as a final project at college i decided to make a simple shooter (very simple one). so i made the world and everything, i used glLookAt() function to explore the world with camera , and now i wanted to add a gun model instead of the mouse cursor, that means i want a 3d gun model (.MD2 / .3DS / .MD3) to be fixed at the bottom/center of the screen like a real shooter. i tried to use GL_PERSPECTIVE to achieve that , but i never get the desired outcome. i'll add code and everything needed ! please , i'm running out of time... Thanks for your time.

##### Share on other sites
Hi,

After you draw the scene, use glLoadIdentity() to reset your matrices and display the gun like you would do to just render the gun.

##### Share on other sites
hey, thanks for the fast response.
i tried what you told me to like so:
	.        . // rest of the scene        .        drawGunSight();	glLoadIdentity();	m16->Draw(); // draw 3ds weapon model

and i don't see the gun at all.

i made sure he would be painted in the right place.

##### Share on other sites
you may be rendering the gun outside the clipping area of your screen.

What are are near and far clipping planes set to?

Render your gun with an offset so that it shows up infront of your camera rather than at the location of the camera.

##### Share on other sites
Hey, wow thanks guys finally i made it, i got the gun up and running, but as i progress a new problem arise , now the gun won't stop reloading(bullets) and shooting animation .. i tried to set the animation number for a different int other then 0 , but still nothing , it keeps moving. here is the code i used.

glTranslatef(0.05 , -.03, -.1); // pos of gun
glRotatef(205.0 , 0.0 , 1.0 , 0.0);
glRotatef(-15.0 , 1.0 , 0.0 , 0.0);
glRotatef(-5.0 , .0 , 0.0 , 1.0);
Pickup.DrawModel ( bAnimated ? timesec : 0.0 ); //draw md2 model

the definition of timesec is like so:

CTimer::GetInstance()->Update();
float timesec = CTimer::GetInstance()->GetTimeMSec() / 1000.0;

i'm sure there's a smarter way of doing that :) , thanks.

1. 1
2. 2
Rutin
22
3. 3
JoeJ
18
4. 4
5. 5

• 15
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631725
• Total Posts
3001905
×