load a weapon ?

Started by
4 comments, last by GameDev.net 19 years, 3 months ago
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
Advertisement
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
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 :(
You don't have to move it to where it should be, you could cheat a little instead.

first render the scene and all other things normaly(but not the weapon or hud).
then reset the modelview matrix, transform/rotate it a little and then render the gun as you see fit.
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"



Just load the weapon and render it before any of the global scene translations or rotations. It will stay in fron of the camera always.


Just after :

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


but, before any rotation or translation to the cmaera view.

This topic is closed to new replies.

Advertisement