Bullet direction problem

Started by
2 comments, last by Kris2456 19 years, 11 months ago
Hello, i am building a 3D TieFighter game, and i have recently added lasers too it. However, in my game, when you move the mouse, the tie fighter rotates acording to how far the mouse is from the centreof the screen. to get an idea, here is a screenshot: My problem is that when the tie fighter rotates, the bullets follow it, like there was a big pole stuck out the front of it. also, here is my code:

int DrawGLScene(GLvoid)									// Here's Where We Do All The Drawing

{   
    POINT pt;
    GetCursorPos(&pt);
    GLfloat tiery = (float)(400 - pt.x)/35;
    GLfloat tierx = (float)(300 - pt.y)/35;
    crossx = (float)(pt.x/800);
    crossy = (float)(pt.y/800);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer											// Done Drawing The Triangle

    
    glLoadIdentity();
    glTranslatef(0, -0.3, tiez);
    glRotatef(tiery,0,1,0);
    glRotatef(tierx,1,0,0);
    TieFighter();
    glBegin(GL_TRIANGLES);
    glColor3f(1,0,0);
    glNormal3f(0.0f,0.0f,0.0f);
    glVertex3f(crossx,crossy,-6);
    glVertex3f(crossx-0.03,crossy-0.03,-6);
    glVertex3f(crossx+0.03,crossy-0.03,-6);
    glColor3f(1,1,1);
    glEnd();
    glPushMatrix();
    glTranslatef(-0.1, 0, -0.01);
    DrawParticles(TexID[1],1.0f,1.0f,1.0f,50.0,0.03);
    glTranslatef(0.2, 0, 0);
    DrawParticles(TexID[1],1.0f,1.0f,1.0f,50.0,0.03);
    glPopMatrix();
    glPushMatrix();
    glLoadIdentity();
    DrawRadar();
    glPopMatrix();
            //                   //                //

    gluLookAt(g_Camera.m_vPosition.x, g_Camera.m_vPosition.y, g_Camera.m_vPosition.z,	
			  g_Camera.m_vView.x,	  g_Camera.m_vView.y,     g_Camera.m_vView.z,	
			  g_Camera.m_vUpVector.x, g_Camera.m_vUpVector.y, g_Camera.m_vUpVector.z); 	  
   	
    glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);

   	glEnable(GL_LIGHT1);
    
    glPushMatrix();
    glTranslatef(0.0f,-30.0f,-20.0f);
    glBindTexture(GL_TEXTURE_2D, TexID[0]);

   glBegin(GL_QUADS);
        glNormal3f(0.0f,1.0f,0.0f);
        glTexCoord2f(0.0f, 2.0f);glVertex3f(-100.0f,0.0f,-100.0f);
        glTexCoord2f(2.0f, 2.0f);glVertex3f(100.0f,0.0f,-100.0f);
        glTexCoord2f(2.0f, 0.0f);glVertex3f(100.0f,0.0f,100.0f);
        glTexCoord2f(0.0f, 0.0f);glVertex3f(-100.0f,0.0f,100.0f);
 	glEnd();
 	glTranslatef(0.0f,10.0f,0.0f);
 	DrawGrid(10,10);

    glPopMatrix();
    
    float rdia=0.0f;
    glBindTexture(GL_TEXTURE_2D, TexID[2]);
   	glEnable(GL_TEXTURE_GEN_S);
	glEnable(GL_TEXTURE_GEN_T);
	glTranslatef(rdia,-20,0);
    gluSphere(quadratic,2.0f,32,32);
   	glDisable(GL_TEXTURE_GEN_S);
	glDisable(GL_TEXTURE_GEN_T);
    
	return TRUE;										// Everything Went OK

}

And my particle system code:
   
typedef struct
{
bool active;
float life;
float fade;

float r;
float g;
float b;

float x;
float y;
float z;

float xi;
float yi;
float zi;

float xg;
float yg;
float zg;

}particles;

particles particle[MAX_PARTICLES];
GLuint	loop;
void InitParticles(float sizex,float sizey,float sizez,float spreadx,float spready,float spreadz,float life,bool active)
{
for(loop=0;loop<MAX_PARTICLES;loop++)
{
    particle[loop].active=active;
    particle[loop].life=life;
    particle[loop].fade=float(rand()%100)/10000.0f+0.003f;
    
    particle[loop].xi=((rand()%50)-spreadx)*sizex;
    particle[loop].yi=((rand()%50)-spready)*sizey;
    particle[loop].zi=((rand()%50)-spreadz)*sizez;
    
    particle[loop].x=0;
    particle[loop].y=0;
    particle[loop].z=0;
    
    particle[loop].xg=0.0f;
    particle[loop].yg=-0.1f;
    particle[loop].zg=0.0f;
}
}
void DrawParticles(unsigned int texture,float r,float g,float b,float slowdown,float size)
{

//Bind the particle texture

glBindTexture(GL_TEXTURE_2D,texture);

//Asign values to particles


for (loop=0;loop<MAX_PARTICLES;loop++)
	{
	if (particle[loop].active)
		{
		glPushMatrix();
		float x=particle[loop].x;
		float y=particle[loop].y;
		float z=particle[loop].z;
		
        glEnable(GL_BLEND);
		glColor4f(r,g,b,particle[loop].life);
	    glBegin(GL_TRIANGLE_STRIP);
	    glNormal3f(0.0f,0.0f,1.0f);
		glTexCoord2d(1,1); glVertex3f(x+size,y+size,z); // Top Right

		glTexCoord2d(0,1); glVertex3f(x-size,y+size,z); // Top Left

		glTexCoord2d(1,0); glVertex3f(x+size,y-size,z); // Bottom Right

		glTexCoord2d(0,0); glVertex3f(x-size,y-size,z); // Bottom Left

		glEnd();
        glDisable(GL_BLEND);
        glColor4f(1,1,1,1);
        
		particle[loop].xi+=particle[loop].xg;
		particle[loop].yi+=particle[loop].yg;
		particle[loop].zi+=particle[loop].zg;
        
		particle[loop].x+=particle[loop].xi/(slowdown*1000);
		particle[loop].y+=particle[loop].yi/(slowdown*1000);
		particle[loop].z+=particle[loop].zi/(slowdown*1000);
		
		
		particle[loop].life-=particle[loop].fade;
		if (particle[loop].life<0.0f)
		{
			particle[loop].life=1.0f;
			particle[loop].x=0.0f;					// Center On X Axis

			particle[loop].y=0.0f;					// Center On Y Axis

			particle[loop].z=0.0f;
			particle[loop].active=false;
		}
		glPopMatrix();
	}
}
}
void ActivateParticle(int id)
{
particle[id].active=true;
}
thx for any help, and sorry for this post being so massive. EDIT: Damit, y wont my pic link. Ok fine to see it go to this adress http://www.freewebs.com/blue_cyclone/screentie.jpg. ---------- "Here lies a toppled God, His fall was not a small one, We but built his pedastle, A narrow, and a tall one" Frank Herbert (Dune:Messiah) [edited by - Kris2456 on May 20, 2004 6:07:46 PM] [edited by - Kris2456 on May 21, 2004 3:32:42 AM]
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)
Advertisement
lol, 120 people have seen this. And no one has a clue. Man, my explaining must be crap.
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)
quote:glLoadIdentity();
glPushMatrix();
glTranslatef(0, -0.3, tiez);
glRotatef(tiery,0,1,0);
glRotatef(tierx,1,0,0);
TieFighter();
glBegin(GL_TRIANGLES);
glColor3f(1,0,0);
glNormal3f(0.0f,0.0f,0.0f);
glVertex3f(crossx,crossy,-6);
glVertex3f(crossx-0.03,crossy-0.03,-6);
glVertex3f(crossx+0.03,crossy-0.03,-6);
glColor3f(1,1,1);
glEnd()
glPopMatrix();

Try that?
nope, didnt help
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)

This topic is closed to new replies.

Advertisement