Jump to content
  • Advertisement
Sign in to follow this  
Niddles

OpenGL My selection mode is not transforming correctly

This topic is 3318 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to implement opengl picking into a program. Even though I am doing the same transformations for both, where I am clicking is not corresponding to what I am picking. It is like the y values for the pick matrix are skewed, because the x is 'mostly' correct. The way I know this is I turned GL_SELECT off and am rendering it directly. The X is working, but it's almost like the Y is reflected and translated a bit. Can anybody pick out what could be causing this (no pun intended)?
//Here is the main drawing

	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
	go3D();
	glPushAttrib(GL_VIEWPORT_BIT);
	glViewport(150, 0, m_width - 150, m_height - 23);
	gluLookAt(0.0, 5.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
	glScalef(m_windowscale.x, m_windowscale.y, m_windowscale.z);
	glRotatef(m_camrotation.x, 1.0, 0.0, 0.0);
	glRotatef(m_camrotation.y, 0.0, 1.0, 0.0);
	glRotatef(m_camrotation.z, 0.0, 0.0, 1.0);
	if(m_gridon)
	{
		drawGrid();
	}
	for(std::vector<Entity*>::iterator it = m_entities.begin(); it != m_entities.end(); it++)
	{
		(*it)->draw();
	}
	if(m_picking)
	{
		beginSelection();
		for(std::vector<Entity*>::iterator it = m_entities.begin(); it != m_entities.end(); it++)
			(*it)->drawPick();
		m_numofhits = endSelection();
	}
	glPopAttrib();

//Begin Selection
void MapBuilderApp::beginSelection()
{
	static int xpos = 0;
	static int ypos = 0;
	glSelectBuffer(m_pickbuffersize, m_pickbuffer);
	//glRenderMode(GL_SELECT);
	glfwGetMousePos(&xpos, &ypos);
	GLint view[4];
	glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
	glGetIntegerv(GL_VIEWPORT, view);
	gluPickMatrix((double)xpos, (double)ypos, 10.0, 10.0, view);
	gluPerspective(45.0, m_width / (float)m_height, 1.0, 1000.0);
	glMatrixMode(GL_MODELVIEW);
	glInitNames();
}
//End Selection
int MapBuilderApp::endSelection()
{
	int hits;
	
	glMatrixMode(GL_PROJECTION);
		glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
		glFlush();
	
	hits = glRenderMode(GL_RENDER);
	
	return hits;
	
}
//And here is draw() and drawpick()
void Light::draw()
{
	glEnable(GL_POINT_SMOOTH);
	glPushAttrib(GL_COLOR_BUFFER_BIT);
	glPushMatrix();
		glRotatef(m_rotation.x, 1.0, 0.0, 0.0);
		glRotatef(m_rotation.y, 0.0, 1.0, 0.0);
		glRotatef(m_rotation.z, 0.0, 0.0, 1.0);
		glTranslatef(m_position.x, m_position.y, m_position.z);
		glPointSize(15.0);
		glBegin(GL_POINTS);
			glColor3fv(m_diffuse.GetArray());
			glVertex3f(0.0, 0.0, 0.0);
		glEnd();
	glPopMatrix();
	glBegin(GL_LINES);
		glVertex3f(m_position.x, m_position.y, m_position.z);
		glVertex3f(m_position.x, 0.0, m_position.z);
	glEnd();
	glPopAttrib();
	glDisable(GL_POINT_SMOOTH);
}

void Light::drawPick()
{
	glPushName(m_id);
	glPushMatrix();
	draw();
	glPopMatrix();
	glPopName();
}


Any help is appreciated. P.S. I know OpenGL Selection mode is deprecated, I am still going to use it for this little app.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!