Original Post
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: and the actual display code is this 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?
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();
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];