I am using the GLUT to render a scene but I have the problem that in certain position cameras some objects of the scene dissapear. Someone knows what is the problem? I add two screenshots of the scene one with the object in scene and other just change the camera position that object dissapear.
I can only speculate on the problem without seeing code, but what is most likely happening is that the geometry that is “dissapearing” is being culled because they are not inside of the viewing volume defined by the orthographic or perspective projection that you are using. See here:
This is the code:
void DrawWireBox(const NxBox& obb, const NxVec3& color, float lineWidth)
{
// Compute obb vertices
NxVec3 pp[8];
NxComputeBoxPoints(obb, pp);
// Draw all lines
const NxU32* Indices = NxGetBoxEdges();
for(NxU32 i=0;i<12;i++)
{
NxU32 VRef0 = *Indices++;
NxU32 VRef1 = *Indices++;
DrawLine(pp[VRef0], pp[VRef1], color, lineWidth);
}
}
void DrawWireBox(NxShape* box, const NxVec3& color, float lineWidth)
{
NxBox obb;
box->isBox()->getWorldOBB(obb);
DrawWireBox(obb, color, lineWidth);
}
void DrawBox(NxShape* box, const NxVec3& color)
{
NxMat34 pose = box->getGlobalPose();
glPushMatrix();
SetupGLMatrix(pose.t, pose.M);
NxVec3 boxDim = box->isBox()->getDimensions();
glScalef(boxDim.x, boxDim.y, boxDim.z);
RenderBox(2.0);
glPopMatrix();
}
void DrawWireShapeIME(NxShape *shape, const NxVec3& color)
{
glColor4f(color.x, color.y, color.z, 1.0f);
switch(shape->getType())
{
case NX_SHAPE_PLANE:
DrawWirePlane(shape, color);
break;
case NX_SHAPE_BOX:
DrawWireBox(shape, color);
break;
case NX_SHAPE_SPHERE:
DrawWireSphere(shape, color);
break;
case NX_SHAPE_CAPSULE:
DrawWireCapsule(shape, color);
break;
case NX_SHAPE_CONVEX:
DrawWireConvex(shape, color);
break;
case NX_SHAPE_MESH:
DrawWireMesh(shape, color);
break;
default:
break;
}
}
void DrawShapeIME(NxShape* shape, const NxVec3& color)
{
glColor4f(color.x, color.y, color.z, 1.0f);
switch(shape->getType())
{
case NX_SHAPE_PLANE:
DrawPlane(shape);
break;
case NX_SHAPE_BOX:
DrawBox(shape, color);
break;
case NX_SHAPE_SPHERE:
DrawSphere(shape, color);
break;
case NX_SHAPE_CAPSULE:
DrawCapsule(shape, color);
break;
case NX_SHAPE_CONVEX:
DrawConvex(shape, color);
break;
case NX_SHAPE_MESH:
DrawMesh(shape, color);
break;
case NX_SHAPE_WHEEL:
DrawWheelShape(shape);
break;
default:
break;
}
}
void DrawActorIME(NxActor* actor)
{
if(actor != NULL)
{
NxShape*const* shapes = actor->getShapes();
NxU32 nShapes = actor->getNbShapes();
if (actor == NULL || actor->getName() == NULL)
{
while (nShapes--)
{
DrawWireShapeIME(shapes[nShapes], NxVec3(1,1,1));
}
}
else
{
if (strcmp(actor->getName(), "Campo") == 0)
{
while (nShapes--)
{
DrawShapeIME(shapes[nShapes], NxVec3(0,1,0)); //Verde
}
}
else if(strcmp(actor->getName(), "Bola") == 0)
{
while (nShapes--)
{
DrawShapeIME(shapes[nShapes], NxVec3(5,0.5,0)); //Laranja //1,0.5,0
}
}
else if(strcmp(actor->getName(), "Robo1") == 0 || strcmp(actor->getName(), "Robo2") == 0 || strcmp(actor->getName(), "Robo3") == 0 || strcmp(actor->getName(), "Robo4") == 0 || strcmp(actor->getName(), "Robo5") == 0)
{
while (nShapes--)
{
DrawShapeIME(shapes[nShapes], NxVec3(0,0,1)); //Azul
}
}
else if(strcmp(actor->getName(), "Robo6") == 0 || strcmp(actor->getName(), "Robo7") == 0 || strcmp(actor->getName(), "Robo8") == 0 || strcmp(actor->getName(), "Robo9") == 0 || strcmp(actor->getName(), "Robo10") == 0)
{
while (nShapes--)
{
DrawShapeIME(shapes[nShapes], NxVec3(1,1,0)); //Amarelo
}
}
else
{
while (nShapes--)
{
DrawShapeIME(shapes[nShapes], NxVec3(1,1,1)); //Branco
}
}
}
}
}
void Simulation::IdleCallback()
{
glutPostRedisplay();
}
void Simulation::ReshapeCallback(int width, int height)
{
glViewport(0, 0, width, height);
}
void Simulation::setupCamera()
{
// Setup projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0f, (float)glutGet(GLUT_WINDOW_WIDTH) / (float)glutGet(GLUT_WINDOW_HEIGHT), 1.0f, 10000.0f);
gluLookAt(gEye.x, gEye.y, gEye.z, gEye.x + gDirection.x, gEye.y + gDirection.y, gEye.z + gDirection.z, 0.0f, 1.0f, 0.0f);
// Setup modelview matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void Simulation::RenderCallback()
{
// Clear buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//Setup camera
setupCamera();
//Draw
glPushMatrix();
for (NxU32 i = 0; i < gMaxScenes; ++i)
{
if (gScenes[i])
{
glColor4f(0.6f,0.6f,0.6f,1.0f);
for(unsigned int j = 0 ; j < gScenes[i]->getNbActors() ; j++ )
{
DrawActorIME(gScenes[i]->getActors()[j]);
}
}
}
glPopMatrix();
//glFlush();
glutSwapBuffers();
}
void Simulation::main(int argc, char **argv)
{
#if defined(_XBOX) || defined(__CELLOS_LV2__)
glutRemapButtonExt(8, '1', false); // Left shoulder to save
glutRemapButtonExt(9, 'c', false); // Right shoulder to clear
glutRemapButtonExt(8, '3', true); // Shift + left shoulder to load
#endif
// Initialize Glut
glutInit(&argc, argv);
glutInitWindowSize(512, 512);
//glutFullScreen();
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
gMainHandle = glutCreateWindow("Simulacao");
glutSetWindow(gMainHandle);
glutDisplayFunc(RenderCallback);
glutReshapeFunc(ReshapeCallback);
glutIdleFunc(IdleCallback);
glutKeyboardFunc(callback_key);
glutKeyboardUpFunc(callback_keyUp);
glutSpecialFunc(ArrowKeyCallback);
glutMouseFunc(MouseCallback);
glutMotionFunc(MotionCallback);
MotionCallback(0, 0);
atexit(ReleaseNx);
// Setup default render states
glClearColor(0.3f, 0.4f, 0.5f, 1.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
#if !defined(__PPCGEKKO__)
glEnable(GL_CULL_FACE);
#endif
// Setup lighting
glEnable(GL_LIGHTING);
float AmbientColor[] = { 0.0f, 0.1f, 0.2f, 0.0f };
glLightfv(GL_LIGHT0, GL_AMBIENT, AmbientColor);
float DiffuseColor[] = { 1.0f, 1.0f, 1.0f, 0.0f };
glLightfv(GL_LIGHT0, GL_DIFFUSE, DiffuseColor);
float SpecularColor[] = { 0.0f, 0.0f, 0.0f, 0.0f };
glLightfv(GL_LIGHT0, GL_SPECULAR, SpecularColor);
float Position[] = { 100.0f, 100.0f, 400.0f, 1.0f };
glLightfv(GL_LIGHT0, GL_POSITION, Position);
glEnable(GL_LIGHT0);
// Initialize physics scene and start the application main loop if scene was created
if (true)
glutMainLoop();
}
Problem solved. Problem with depth buffer.