Skip to main content
GameDev.net gamedev.net
🔒 Locked

Displaying Very Large Objects

Started by Soulstormgr Aug 27, 2008 at 1:44 PM 3 replies 850+ views
Original Post
Soulstormgr
Soulstormgr
Well, as you may recall from a previews thread, I am building a .obj file loader. I succeeded in doing so, and I also succeeded in displaying that object on screen. Materials are also used. (I hope I can implement textures into the next few days...) I have a problem, though. I have made an application which loads and displays a model. However, as you imagine, the dimensions of each model are completely different. One model could have vertices that have coordinates like those: x: 1000 y: 8673 z: 9344 Other models may have vertices like those: x: 9,34 y:7,34 z: 9,44 My problem is that I can't think of any good way of resetting the view each time I load a new model to something that produces a viewable result. My display code so far is the following: My initGL code:

        float yRot;
	float xRot;
	float standardRotationDegrees;
	
	float upAndDownTranslation;
	float leftAndRightTranslation;
	float nearAndFarTrasnlation;
        NSRect bounds = [self bounds];
	//NSLog(@"reshaping: %f, %f", NSWidth(bounds), NSHeight(bounds));
	glViewport(0, 0, NSWidth(bounds), NSHeight(bounds));
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45, NSWidth(bounds)/NSHeight(bounds), 0.1f, 1000.0f);
	//	glOrtho(-20, 20, -20, 20, -100, 100);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

and the actual display code is this

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	glLoadIdentity();
	
	
	//glTranslatef(0.0f, 0.0f, -20.0f);
	
	gluLookAt(0, 0, nearAndFarTrasnlation, 0, 0, 0, 0, 1, 0);
	glTranslatef(leftAndRightTranslation, 0, 0);
	glRotatef(xRot, 1.0f, 0.0f, 0.0f);
	glRotatef(yRot, 0.0f, 0.0f, 1.0f);
	
	//draw the model
	for (int i=0; i<model.numTriangles(); i++) {
		model.drawFaceAtIndex(i);
	}
	

	[[self openGLContext]flushBuffer];

Although you can clearly see some objective-c commands, please stick to the ones specific for OpenGL, since the other ones do not play any role to my problem. So, as you can see I have used gluPerspective() with gluLookAt(). Although some models are displayed correctly, I have a model that has vertices like x:300.0 y:20.0 z:1000.0. That model is not displayed at all. Can you recommend any way of coping with that problem?
Project Soulstorm -- Articles, Programs, Forums, 3D art, and many more.
MARS_999
MARS_999
Wow, a mesh with 1000 on Z, what is this terrain?

Anyway, what about keeping track of the largest Z values and adjusting the far plane accordingly? That is if you want to see the whole mesh, but with something like that I would think culling would be a good choice or LOD on that mesh.
mmakrzem
mmakrzem
This is what I would suggest. After you load in your model, figure out how big it is by calculating the max/min coordinates that will enclose the model. Knowing how big it is, you can now normalize it so that it will fit into what ever size/region you want.

The better way to handle this problem, is to prescale your models before you load them into your program.
jezham
jezham
I too would pre-scale in your situation. But you might as well just use a glScalef() before your draw code (push matrix before scale, pop after draw - or your next translations etc will be scaled too - unless you push/pop elsewhere...).
VizOne
VizOne
I'd also go for the scaling approach: calculate the bounding box of the model during load time, determine the largest dimension and scale the model by the reciprocal. Furthermore shift the object by -center. You should now have an object which is not larger than 1x1x1 centered at [0,0,0]. Should be a good starting point. You can then let the user rotate, zoom and translate around the model.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.