Jump to content
  • Advertisement
Sign in to follow this  
3dnewbie

how do i focus on a object in 3d space

This topic is 4249 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 would like that with every rendering pass my program focusses on one of the many objects in my 3d space. Hmm maybe not though. If i later have a lot of objects, it would slow down to much. Just when adding an object i mean. I would like it to focus on that object. How would i go about achieving this ? I use this code to display all the objects (3d quads) in the 3d space:
GLvoid display_objects(GLvoid)
{
	/* Here we draw the objects that our in our database on the main grid. We
	search through our database for xyz coordinates and we use a bitmapfont 
        to draw some information of the object. */
	objects *tmp=o_head;
	
	while(tmp!=NULL) {
	glPushMatrix();
	glTranslatef(atof(tmp->x),atof(tmp->y),atof(tmp->z));
		
	glBegin(GL_QUADS);
		glVertex3f( -OBJECT_SIZE_X, OBJECT_SIZE_Y,-0.2f);			
		glVertex3f(-OBJECT_SIZE_X,OBJECT_SIZE_Y,-0.2f);			
		glVertex3f(OBJECT_SIZE_X,OBJECT_SIZE_Y, 0.2f);			
		glVertex3f(OBJECT_SIZE_X,OBJECT_SIZE_Y, 0.2);			
			
		glVertex3f( OBJECT_SIZE_X,-OBJECT_SIZE_Y,0.2f);			
		glVertex3f(-OBJECT_SIZE_X,-OBJECT_SIZE_Y,0.2f);			
		glVertex3f(-OBJECT_SIZE_X,-OBJECT_SIZE_Y,-0.2f);			
		glVertex3f( OBJECT_SIZE_X,-OBJECT_SIZE_Y,-0.2f);		
					
		glVertex3f(OBJECT_SIZE_X,OBJECT_SIZE_Y, 0.2f);			
		glVertex3f(-OBJECT_SIZE_X,OBJECT_SIZE_Y,0.2);			
		glVertex3f(-OBJECT_SIZE_X,-OBJECT_SIZE_Y,0.2f);			
		glVertex3f(OBJECT_SIZE_X,-OBJECT_SIZE_Y,0.2f);		
				
		glVertex3f(OBJECT_SIZE_X,-OBJECT_SIZE_Y,-0.2f);			
		glVertex3f(-OBJECT_SIZE_X,-OBJECT_SIZE_Y,-0.2f);			
		glVertex3f(-OBJECT_SIZE_X, OBJECT_SIZE_Y,-0.2f);			
		glVertex3f( OBJECT_SIZE_X, OBJECT_SIZE_Y,-0.2f);			
			
		glVertex3f(-OBJECT_SIZE_X,OBJECT_SIZE_Y, 0.2f);			
		glVertex3f(-OBJECT_SIZE_X,OBJECT_SIZE_Y,-0.2f);			
		glVertex3f(-OBJECT_SIZE_X,-OBJECT_SIZE_Y,-0.2f);		
		glVertex3f(-OBJECT_SIZE_X,-OBJECT_SIZE_Y, 0.2f);		
				
		glVertex3f( OBJECT_SIZE_X,OBJECT_SIZE_Y,-0.2f);			
		glVertex3f(OBJECT_SIZE_X,OBJECT_SIZE_Y, 0.2f);			
		glVertex3f(OBJECT_SIZE_X,-OBJECT_SIZE_Y,0.2f);			
		glVertex3f(OBJECT_SIZE_X,-OBJECT_SIZE_Y,-0.2f);			
	glEnd();						
	
	/* Set title of objects to a white color so we can see it */
	glColor4f(1.0f,1.0f,1.0f,0.1f);
	/* If you're annoyed by the title of the object being obscured
	by the object itself when blending is off, increase x by 0.4 */
	renderbitmapfont(0.0,0,0,"%s",tmp->hostname);
	tmp=tmp->next;
	glPopMatrix();
	}
}
I tried to use the same method to do what i would like, but i can't get it to work.

Share this post


Link to post
Share on other sites
Advertisement
There's nothing scary about that function. ;)

The first 3 parameters are the x, y and z coördinates of your camera. The second set of 3 are the coördinates of the point you're looking at. The last set of 3 form the up vector of the camera. With this vector you can control the roll of your camera, for example, by inverting this vector your camera will look up-side down.

Share this post


Link to post
Share on other sites
That depends on how you want to look at those objects. If it's a sort of RTS-like top-down view, then you can simply use the location of the object, and up the height somewhat, so you'll look straight down at it. Try fiddling with some values, it really isn't difficult. :)

Share this post


Link to post
Share on other sites
I think that if you set the matrix mode to GL_PROJECTION and retrieve the matrix (if such a function exists) you can get the camera XYZ coords, target XYZ coords and the UP vector.

I would personally make a camera class that handled the camera stuff.


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.

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!