#### Archived

This topic is now archived and is closed to further replies.

# Bullet direction problem

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

## Recommended Posts

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

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();
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]);

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);
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 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;
{
for(loop=0;loop<MAX_PARTICLES;loop++)
{
particle[loop].active=active;
particle[loop].life=life;

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);

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]

##### Share on other sites
lol, 120 people have seen this. And no one has a clue. Man, my explaining must be crap.

##### Share on other sites
quote:
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

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

• 14
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631722
• Total Posts
3001892
×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!