PDA

View Full Version : A view that displays my entire model?



anime.igala.net
07-18-2008, 02:36 AM
I have seen this FAQs: How can I automatically calculate a view that displays my entire model?
http://www.opengl.org/resources/faq/technical/viewing.htm

But this code does not run (for me), does any one know where is error on my code? I cannot see any thing on the screen with this code.



void Viewer::initGLES(){
glClearColor(0.f ,1.0f, 1.0f, 1.f);
glDisable(GL_DEPTH_TEST);
float diam = 1500;
float zNear = 1.3f;
float zFar = zNear + diam;

int cx = 0, cy = 0, cz = 0;

float left = cx - diam;
float right = cx + diam;
float bottom = cy - diam;
float top = cy + diam;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

float aspect = iScreenWidth / iScreenHeight; // 240 x 320

if ( aspect < 1.0 ) { // window taller than wide
bottom /= aspect;
top /= aspect;
} else {
left *= aspect;
right *= aspect;
}

//glOrtho(left, right, bottom, top, zNear, zFar);
glOrthof(left, right, bottom, top, zNear, zFar);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//gluLookAt(0., 0., 2.*diam, cx, cy, cz, 0.0, 1.0, 0.0);
}
//------------------------------------
void Viewer::drawFP(){
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glEnableClientState(GL_VERTEX_ARRAY);
//glTranslatef (0,0,-5.f);

glColor4f(0,1,0,1);

static const GLfloat vertices[3 * 3] =
{
-1000, 1000, 0,
1000, -1000, 0,
1000, 1000, 0
};

glVertexPointer( 3, GL_FLOAT, 0, vertices );

glDrawArrays( GL_LINES, 0, 3);
}


Thanks all,

dletozeun
07-18-2008, 03:08 AM
float zFar = zNear + diam;


I think this is wrong even if it is in the FAQ, because this should also depend on the bounding sphere center position.
For instance if the bounding sphere diameter of the scene is 1.0 and the sphere center is on z axis at z = -100.0 and if the eye is at (0, 0, 0) with its view axis toward z axis negative, you will see nothing because zfar = znear + diam = 1.0 + 1.0 = 2.0 (if I assume that znear is 1.0).

EDIT: reading further your code, you have taken a particular case where the scene center is at (0,0,0) and the eye too. If you uncomment the line with gluLookAt(...) to move back the camera, do you still see nothing?

anime.igala.net
07-18-2008, 05:09 AM
If you uncomment the line with gluLookAt(...) to move back the camera, do you still see nothing?


The same thing, I don't see any thing on the screen. :(

dletozeun
07-18-2008, 06:48 AM
are you sure of all your values? I see a vertices array with coordinates around 1000, so diameter should not be around 2000?

anime.igala.net
07-18-2008, 07:58 AM
So what is the value of diameter should be ?

thanks

dletozeun
07-20-2008, 10:13 AM
Since you are drawing vertices with coordinates around 1000 on one axis. In the worst case you have a vertex at (1000, 1000, 1000) which is around 1732 away from the scene center, so a a sphere diameter around 3500 is needed...