Skip to main content
gamedev.net
🔒 Locked

load a weapon ?

Started by Meane Dec 31, 2004 at 6:19 AM 4 replies 1.2k views
Original Post
Meane
Meane
hi :) so.. i have make a small fps.. now i have juste coded, the camera, the load world (with collision) but.. now i must load the weapon.. i have created a simple rectangle on 3dsMAX (.ASE):) for simul a small weapon :D how i can place this weapon juste in front of the camera ? (like a normal fps... :) ) thx
Steve132
Steve132
First you have to find a way to get the model data into your program, and to render it. I suggest wotsit.org for looking up the .ASE format. Then, after you know how to load and render models, do this:
push ModelView Matrix
load Identity Matrix
Render your model where the end of the gun is -Z
pop ModelView Matrix
Meane
Meane
ho.. yes yes.. i have aleardy a load of .ASE.. i have loaded my world with texture..

but for the weapon position it hard :(

i have test it !

//draw weapon
//distance entre vue.x et position.x
double aX=g_Camera.m_vView.x-g_Camera.m_vPosition.x;
//distance entre vue.z et position.z
double aZ=g_Camera.m_vView.z-g_Camera.m_vPosition.z;
//on obtient l'angle en radians
double angle = atan(aZ/aX);
angle*=-1;
//on le converti en degré
angle_perso=(180*angle)/PI;
if (aX<0) angle_perso-=180;
//à l'origine l'arme n'est pas à 0 degré
angle_perso-=90;

//on cherche maintenant l'angle de hauteur
double aY = g_Camera.m_vView.y-g_Camera.m_vPosition.y;
//la distance
float X=pow(g_Camera.m_vPosition.x-g_Camera.m_vView.x,2);
float Z=pow(g_Camera.m_vPosition.z-g_Camera.m_vView.z,2);
float result=X+Z;
//on obtient le 2eme argument
double somme=sqrt(result);
angle = atan(aY/somme);
float angle_arme = (180*angle)/PI;

//on active la texture
//glBindTexture(GL_TEXTURE_2D, g_Texture2[1]);
//la position de l'arme
glTranslatef(g_Camera.m_vPosition.x,12,g_Camera.m_vPosition.z);
//on fait les rotations
glRotatef(angle_perso,0.f,1.f,0.f);
glRotatef(angle_arme,1.f,0.f,0.f);
//on rétréci un peu l'arme
glScaled(0.4,0.4,0.4);

and i draw the .ASE file..

but i doesnt have a wepon in front of my cam :(
Krohm
Krohm
Quote:
Original post by lc_overlord
You don't have to move it to where it should be, you could cheat a little instead.

Definetly correct.
By the way, to avoid having the gun inside the walls, you may want to play a bit with the zBuffer. Clearing it completely is pretty fast by now and also quite easy to work out.
Other methods could be reverse the zRange (but I don't remember how to do this now) but they're somewhat less straightfoward.
Previously "Krohm"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.