PDA

View Full Version : Problem with move



Radek_1
01-19-2013, 10:27 AM
1) So I have a 3d plane and terrain. It's flight forward. The plane is armed with 2 bombs.

2) I shoot bomb, it faster than plane.

3) The problem is when I want move my plane. The bomb is moving with plane :(

4) I want that bomb move independent after shoot, how can I make it?

I'm beginer in OpenGL :( I've tired with glPushMatrix and glPopMatrix but it doesn't work. Anyone can help me?

The code:


void renderScene(void) {
hMap.DrawHeightMap(); // Draw terrain

glPushMatrix();
glTranslatef(xo,yo,zo); // Plane's position
glRotatef(graus, 1.0, 0.0, 0.0); //Change plane position
glRotatef(grausz, 0.0, 0.0, 1.0);

plane->draw(); // Draw plane

// Bombs, connect it to "plane position"
glPushMatrix();
glTranslatef(-0.35f,-0.22f,bomb1air+(-0.5f));
bomb1->draw();
glTranslatef(0.70f,0.0f,bomb2air+(0.0f-bomb1air));
bomb2->draw();
glTranslatef(-0.35f,0.22f,(0.5f-(bomb1air+bomb2air)));
glPopMatrix();

glPopMatrix();
glFlush();
}


When I click shoot, I'm changing bomb1air/bomb2air position+0.01 so it moves faster than plane (in the glutIdleFunc() function).

I've made an image to show you what i mean but unfortunetly I can't post any links.

tonyo_au
01-19-2013, 04:38 PM
You are pushing the matrix but not resetting before you draw your bomb.

You logic should be

push matrix
set matrix to a know value (usually the identity)
modify matrix
draw obj
pop matrix

do the same thing for the next obj

Radek_1
01-20-2013, 08:17 AM
Everything works fine (bombs are connected under wings and move with plane) until I shoot bomb. Its fly away from the plane. I want turn left the plane and bomb which I've shooted also turn left.

I've tired something like that:


void renderScene(void) {
glLoadIdentity();

//Camera
gluLookAt(camx+xo, camy+yo, camz+zo
xo, yo, zo,
0.0f, 1.0f, 0.0f);

hMap.DrawHeightMap(); // Draw terrain

glPushMatrix();
glTranslatef(xo,yo,zo); // Plane's position
glRotatef(graus, 1.0, 0.0, 0.0); //Change plane position
glRotatef(grausz, 0.0, 0.0, 1.0);
plane->draw(); // Draw plane
glPopMatrix();

// Bombs, connect it to "plane position"
glPushMatrix();
glLoadIdentity();
glTranslatef(xo,yo,zo); // Plane's position (connect it under wing)
glTranslatef(-0.35f,-0.22f,bomb1air+(-0.5f));
bomb1->draw();
glTranslatef(0.70f,0.0f,bomb2air+(0.0f-bomb1air));
bomb2->draw();
glTranslatef(-0.35f,0.22f,(0.5f-(bomb1air+bomb2air)));
glPopMatrix();

glFlush();
}


But I don't even see the bombs now.

Btw. I've also camera connected with plane (camera is placed behind airplane)


Edit:
It works! Problem was with the camera setting, thanks tonyo_au! :)