Hello,
I have a 3D animation where I draw a set of particles. Before launching the animation, I initialize the view of the particles set (the set represents a galaxy) in order to give to the user a good starting full view.
I have commented the drawing function used :
w_width = 600;
w_height = 600;
g_nearPlane = 0.1f;
g_farPlane = 1000.0f;
void GLWidget::draw()
{
// Boolean for initializing the first display of the scene
if (isDisplayFirst)
{
isDisplayFirst = false;
// Create VBO
createVBO();
// Reset line scale value
// lineScaleValue = abs(Galaxy->pos[3]-Galaxy->pos[0])*3;
lineScaleValue = 100.0f;
// Initialize View
glViewport(0, 0, w_width, w_height);
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// perspective good initial
gluPerspective(45.0f, (float) w_width/w_height, g_nearPlane, g_farPlane);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrixi
// I would like to remove the two lines below and put directly
// gluLookAt (0.0, 0.0, 100.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
// This way, the camera would be put at z = 3 / 0.03 = 100
gluLookAt (0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glScalef(0.03f, 0.03f, 0.03f);
}
rotateScene();
glClearColor(0.0 ,0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_POINT_SPRITE);
glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_NV);
glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE);
glUseProgram(mprogram);
glUniform1f( glGetUniformLocation(mprogram, "pointRadius"), m_particleRadius );
glUniform1f( glGetUniformLocation(mprogram, "pointScale"),m_pointScale);
// Drawing particles
if (not hideClassicMatter)
{
GLuint vbo_disk = 0;
glBindBuffer(GL_ARRAY_BUFFER, vbo_disk);
glVertexPointer(4, GL_DOUBLE, 4*sizeof(double), Galaxy->pos);
glEnableClientState(GL_VERTEX_ARRAY);
glColor4f(1.0f, 1.0f, 1.0f, 0.2f);
glDrawArrays(GL_POINTS, 0, Galaxy->getNumParticles_disk());
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDisableClientState(GL_VERTEX_ARRAY);
}
// Drawing particles
if (not hideDarkMatter)
{
GLuint vbo_halo = 0;
glBindBuffer(GL_ARRAY_BUFFER, vbo_halo);
glVertexPointer(4, GL_DOUBLE, 4*sizeof(double), &Galaxy->pos[4*Galaxy->getNumParticles_disk()]);
glEnableClientState(GL_VERTEX_ARRAY);
glColor4f(0.0f, 0.0f, 1.0f, 0.2f);
glDrawArrays(GL_POINTS, 0, Galaxy->getNumParticles_halo());
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDisableClientState(GL_VERTEX_ARRAY);
}
glDisable(GL_BLEND);
glDisable(GL_POINT_SPRITE);
}
So instead of having :
gluLookAt (0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glScalef(0.03f, 0.03f, 0.03f);
I would have :
gluLookAt (0.0, 0.0, 100.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
But with this replacement, I have strange results, it seems that a lot of particles are hidden or have disappeared.
To illustrate this, I show you on the two figures below this problem; The first one corresponds to the original code (using gluLookAt (0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glScalef(0.03f, 0.03f, 0.03f) :
The second one corresponds to the replacement case ( using only gluLookAt (0.0, 0.0, 100.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)) :
Maybe the problem is about a wrong near or far values but I have set :
g_nearPlane = 0.1f;
g_farPlane = 1000.0f;
From your experience, What this issue is related to ?
Thanks