Jump to content
  • Advertisement
Sign in to follow this  
hury

Camera movement issue

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i have a strange bug, that i dont understand. In order to explain, i attach 2 screenshots: http://www.captured-dreams.de/temp/screen1.jpg http://www.captured-dreams.de/temp/screen2.jpg On screen 1 you see the startup look. Now i try zooming into the scene by adjusting the zeye value: zeye--; here is my display() function:
void display ( void )   // Create The Display Function
{
	// Clear Screen And Depth Buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	

	gluLookAt (xeye, yeye, zeye, xfocus, yfocus, zfocus, 0,1,0);
	
	// Draw the Cube
	myCube.draw();										


    
	  // Draw the items
	  DrawItems();											

  glutSwapBuffers();									// Swap The Buffers To Not Be Left With A Clear Screen
}
As you see the camera zooms into the cube, but the icons have somehow moved. They dont keep their old position. I cant figure out why. Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Any changes to the modelview matrix (which is what gluLookAt does) affect every call that comes after them. You may want to consider switching to an orthographic projection for your icons. Alternatively, adding glMatrixMode(GL_MODELVIEW); glPushMatrix() before the call to gluLookAt and glPopMatrix() before the call to DrawItems.

Share this post


Link to post
Share on other sites
First of all, changing the zeye value does not perform a zoom; it performs a translation of the camera along the global z axis instead! Besides that, the OP gives absolutely no hint what is furthur done inside myCube.draw() and DrawItems() to the matrix stack.

Share this post


Link to post
Share on other sites
Hi,

i tried your suggestions, but no success - nothing changed.

Cube.draw:

void Cube::draw() {


glLineStipple(2, (short) 0x00FF);
glEnable(GL_LINE_STIPPLE);

glBegin(GL_LINES);

glColor3f(0.4f,0.69f,1.0f); //Blau

glVertex3f(-2.5, -2.0, 0.0); //Links unten horizontal
glVertex3f(-2.5, -2.0, -3.0);

glVertex3f(-2.5, -2.0, -3.0); //Hinten unten horizontal
glVertex3f(2.5, -2.0, -3.0);

glVertex3f(2.5, -2.0, -3.0); //Rechts unten horizontal
glVertex3f(2.5, -2.0, 0.0);

glVertex3f(2.5, -2.0, 0.0); //Rechts vorne vertikal
glVertex3f(2.5, 2.0, 0.0);

glVertex3f(2.5, 2.0, 0.0); //Rechts oben horizontal
glVertex3f(2.5, 2.0, -3.0);

glVertex3f(2.5, 2.0, -3.0); //Rechts hinten vertikal
glVertex3f(2.5, -2.0, -3.0);

glVertex3f(2.5, 2.0, -3.0); //Hinten oben horizontal
glVertex3f(-2.5, 2.0, -3.0);

glVertex3f(-2.5, 2.0, -3.0); //Hinten links vertikal
glVertex3f(-2.5, -2.0, -3.0);

glVertex3f(-2.5, -2.0, 0.0); //Vorne unten horizontal
glVertex3f(2.5, -2.0, 0.0);

glVertex3f(-2.5, -2.0, 0.0); //Vorne links vertikal
glVertex3f(-2.5, 2.0, 0.0);

glVertex3f(-2.5, 2.0, 0.0); //Oben links horizontal
glVertex3f(-2.5, 2.0, -3.0);

glVertex3f(-2.5, 2.0, 0.0); //Vorne oben horizontal
glVertex3f(2.5, 2.0, 0.0);


glEnd();
glDisable(GL_LINE_STIPPLE);
}

------------------------------------------

DrawItems():
void DrawItems() {
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

// Set position
glTranslatef(x , y, z);


// Draw all icons in the vector
for(int i=0; i < myIcons.getIconVectorALL().size(); i++) {
glLoadIdentity();
glPushMatrix();

glBegin(GL_QUADS); // Quad
glTexCoord2f(0, 0); glVertex3f(-0.08f, 0.08f, 0.02f);
glTexCoord2f(0, 1); glVertex3f(-0.08f,-0.08f, 0.02f);
glTexCoord2f(1, 1); glVertex3f( 0.08f,-0.08f, 0.02f);
glTexCoord2f(1, 0); glVertex3f( 0.08f, 0.08f, 0.02f);
glEnd();

glPopMatrix();
}


How would you zoom into the scene?

Share this post


Link to post
Share on other sites
it depends what you mean by zoom. If you mean 'move closer' then you're already doing the right thing. If you mean 'simulate a camera zoom lense' you should try changing your field of view. You don't say how you're setting up your projection, but googling 'opengl fov' should give you some ideas.

Share this post


Link to post
Share on other sites
Hi,

yes I mean getting closer to the scene.
My problem is that i´m getting closer to the cube, which is drawn in cube.draw, but the icons, which are drawn in DrawItems() stay at the same distance from the camera. So when i move camera into the scene, the icons step away from the camera.

Share this post


Link to post
Share on other sites
I'm not sure I understand what you're trying to achieve - when you move towards the box, do you want the icons to stay in the same position on screen OR do you want to move towards / through them as well?

The transformations you're doing in DrawItems seem a little confused (possibly my fault, sorry!). At the moment you're doing this:

translate
for (all icons):
  set the current matrix to identity (what this does will depend on the most recent call to glMatrixMode, but assuming GL_MODELVIEW, you're just undoing the previous translation!)
  store the current matrix state (the identity)
  draw a quad
  reset the current matrix to what was stored (the identity)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!