Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Problem with move

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    2

    Problem with move

    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:
    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.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,105
    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

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2013
    Posts
    2
    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:
    Code :
    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!
    Last edited by Radek_1; 01-20-2013 at 09:13 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •