bazalddo

01-03-2012, 08:16 AM

Hi Guys,

I need some help with a graphics application I am building.

I am trying to create a object dynamically i.e. sphere, teapot. I am doing this by right clicking the mouse and selecting the object I want to create. A passive mouse function then picks up the coordinates of the mouse and I tty to get the Z value by using glReadPixels. The problem is that the object is not being created in the correct place.

See the code below

smaElement *pE = createNewElement();

pE->isWireframe = 0;

strcpy(pE->m_cvType, "sphere");

pE->m_fvAmb[0] = 0.8f;

pE->m_fvAmb[1] = 0.1f;

pE->m_fvAmb[2] = 0.1f;

pE->m_fvAmb[3] = 1.0f;

pE->m_fvDif[0] = 0.8f;

pE->m_fvDif[1] = 0.1f;

pE->m_fvDif[2] = 0.1f;

pE->m_fvDif[3] = 1.0f;

pE->m_fvSpe[0] = 0.1f;

pE->m_fvSpe[1] = 0.2f;

pE->m_fvSpe[2] = 0.2f;

pE->m_fvSpe[3] = 1.0f;

pE->m_iSize = 2;

GLint viewport[4];

GLdouble modelview[16];

GLdouble projection[16];

GLfloat winX, winY, winZ;

GLdouble posX, posY, posZ;

glGetDoublev( GL_MODELVIEW_MATRIX, modelview );

glGetDoublev( GL_PROJECTION_MATRIX, projection );

glGetIntegerv( GL_VIEWPORT, viewport );

winX = (float)iXPos;

winY = (float)viewport[3] - (float)iYPos;

glReadPixels( iXPos, (winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );

gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);

pE->m_fvPos[0] = posX;

pE->m_fvPos[1] = posY;

pE->m_fvPos[2] = posZ;

pushHead(pE);

renderList();

primitive = 0;

Thanks for your help

Baz

I need some help with a graphics application I am building.

I am trying to create a object dynamically i.e. sphere, teapot. I am doing this by right clicking the mouse and selecting the object I want to create. A passive mouse function then picks up the coordinates of the mouse and I tty to get the Z value by using glReadPixels. The problem is that the object is not being created in the correct place.

See the code below

smaElement *pE = createNewElement();

pE->isWireframe = 0;

strcpy(pE->m_cvType, "sphere");

pE->m_fvAmb[0] = 0.8f;

pE->m_fvAmb[1] = 0.1f;

pE->m_fvAmb[2] = 0.1f;

pE->m_fvAmb[3] = 1.0f;

pE->m_fvDif[0] = 0.8f;

pE->m_fvDif[1] = 0.1f;

pE->m_fvDif[2] = 0.1f;

pE->m_fvDif[3] = 1.0f;

pE->m_fvSpe[0] = 0.1f;

pE->m_fvSpe[1] = 0.2f;

pE->m_fvSpe[2] = 0.2f;

pE->m_fvSpe[3] = 1.0f;

pE->m_iSize = 2;

GLint viewport[4];

GLdouble modelview[16];

GLdouble projection[16];

GLfloat winX, winY, winZ;

GLdouble posX, posY, posZ;

glGetDoublev( GL_MODELVIEW_MATRIX, modelview );

glGetDoublev( GL_PROJECTION_MATRIX, projection );

glGetIntegerv( GL_VIEWPORT, viewport );

winX = (float)iXPos;

winY = (float)viewport[3] - (float)iYPos;

glReadPixels( iXPos, (winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );

gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);

pE->m_fvPos[0] = posX;

pE->m_fvPos[1] = posY;

pE->m_fvPos[2] = posZ;

pushHead(pE);

renderList();

primitive = 0;

Thanks for your help

Baz