Problem with JOGL picking after using glTranslate

I decided to re-use my topic instead of spam the board since it’s not really that active, so i just edited this.

The following posts were to do with my original problem so it hasn’t been answered yet.

Anyway…

Im having a problem with Picking/Selecting whatever you want to call it, i had it working perfectly but if i want to move the drawing of the model then it dosn’t work.

Here is the method to render the vertices of the model which IS VISIBLE, not the picking method;

public void renderVertices(GL gl)
	{	
		gl.glPushMatrix();
		gl.glTranslatef(5f, 0.0f, 0f);
		//gl.glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
		gl.glDisable(GL.GL_LIGHTING);
		gl.glBegin(GL.GL_QUADS);	
		for (Vertex v : vertices)
		{
			gl.glColor3f(0.0f, 0.5f, 0.0f);
			float xMinus = v.x - 0.01f;
			float yMinus = v.y - 0.02f;
			float zMinus = v.z - 0.01f;
			float xPlus = v.x + 0.01f;
			float yPlus = v.y;
			float zPlus = v.z + 0.01f;
			gl.glVertex3f(xPlus, yPlus, zPlus);
			gl.glVertex3f(xPlus, yMinus, zPlus);
			gl.glVertex3f(xPlus, yMinus, zMinus);
			gl.glVertex3f(xPlus, yPlus, zMinus);
			gl.glVertex3f(xPlus, yPlus, zMinus);
			gl.glVertex3f(xPlus, yMinus, zMinus);
			gl.glVertex3f(xMinus, yMinus, zMinus);
			gl.glVertex3f(xMinus, yPlus, zMinus);
			gl.glVertex3f(xMinus, yPlus, zMinus);
			gl.glVertex3f(xMinus, yMinus, zMinus);
			gl.glVertex3f(xMinus, yMinus, zPlus);
			gl.glVertex3f(xMinus, yPlus, zPlus);
			gl.glVertex3f(xMinus, yPlus, zPlus);
			gl.glVertex3f(xMinus, yMinus, zPlus);
			gl.glVertex3f(xPlus, yMinus, zPlus);
			gl.glVertex3f(xPlus, yPlus, zPlus);
			gl.glVertex3f(xMinus, yPlus, zMinus);
			gl.glVertex3f(xMinus, yPlus, zPlus);
			gl.glVertex3f(xPlus, yPlus, zPlus);
			gl.glVertex3f(xPlus, yPlus, zMinus);
			gl.glVertex3f(xMinus, yMinus, zPlus);
			gl.glVertex3f(xMinus, yMinus, zMinus);
			gl.glVertex3f(xPlus, yMinus, zMinus);
			gl.glVertex3f(xPlus, yMinus, zPlus);
		}
		gl.glEnd();
		gl.glPopMatrix();
		gl.glEnable(GL.GL_LIGHTING);
	}

Picking works perfectly if i take out the translation and rotation parts.

Here is the method for rendering the vertices using picking, i have made it so that it performs a loop so i can set the “names” for each vertice by doing;


gl.glPushName(index);
model.renderVertice(index, gl);
gl.glPopName();

index being the variable of the for statement.

So anyway, here is the picking rendering method;

public void renderVertex(int index, GL gl)
	{
		gl.glDisable(GL.GL_LIGHTING);
		gl.glPushMatrix();
		gl.glTranslatef(5f, 0.0f, 0f);
		//gl.glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
		Vertex v = vertices[index];
		gl.glBegin(GL.GL_QUADS);
		float xMinus = v.x - 0.01f;
		float yMinus = v.y - 0.02f;
		float zMinus = v.z - 0.01f;
		float xPlus = v.x + 0.01f;
		float yPlus = v.y;
		float zPlus = v.z + 0.01f;
		gl.glVertex3f(xPlus, yPlus, zPlus);
		gl.glVertex3f(xPlus, yMinus, zPlus);
		gl.glVertex3f(xPlus, yMinus, zMinus);
		gl.glVertex3f(xPlus, yPlus, zMinus);
		gl.glVertex3f(xPlus, yPlus, zMinus);
		gl.glVertex3f(xPlus, yMinus, zMinus);
		gl.glVertex3f(xMinus, yMinus, zMinus);
		gl.glVertex3f(xMinus, yPlus, zMinus);
		gl.glVertex3f(xMinus, yPlus, zMinus);
		gl.glVertex3f(xMinus, yMinus, zMinus);
		gl.glVertex3f(xMinus, yMinus, zPlus);
		gl.glVertex3f(xMinus, yPlus, zPlus);
		gl.glVertex3f(xMinus, yPlus, zPlus);
		gl.glVertex3f(xMinus, yMinus, zPlus);
		gl.glVertex3f(xPlus, yMinus, zPlus);
		gl.glVertex3f(xPlus, yPlus, zPlus);
		gl.glVertex3f(xMinus, yPlus, zMinus);
		gl.glVertex3f(xMinus, yPlus, zPlus);
		gl.glVertex3f(xPlus, yPlus, zPlus);
		gl.glVertex3f(xPlus, yPlus, zMinus);
		gl.glVertex3f(xMinus, yMinus, zPlus);
		gl.glVertex3f(xMinus, yMinus, zMinus);
		gl.glVertex3f(xPlus, yMinus, zMinus);
		gl.glVertex3f(xPlus, yMinus, zPlus);
		gl.glEnd();
		gl.glPopMatrix();
		gl.glEnable(GL.GL_LIGHTING);
	}

Like i said, if i don’t add the translation part it works fine, but it’s included in both methods so im not sure why it’s not working.

Thanks for any help.

it’s probably the lighting.

the screenshot below is definitely rendered without lighting. and the function enables lighting at the very end.

have a look at the setup of your lights!

no light is expected no ?

and the following will set vertex color painting no ?

gl.glColor3f(t.getRed(), t.getGreen(), t.getBlue());

try to replace by:

gl.glColor3f(1.0f,1.0f,1.0f);

That just colours the vertices of the floor tiles which can be rendered before or after and still cause the problem.

I know but your dwarf warrior seems as the tiles a little colored too

Ok thanks i put that at the end and it worked.

Now, would you know how to draw the mesh, or outlines of the model but not actually colour it?

I was thinking about using gl.glDrawLine but it would be harder having to join vertex 1-2, 2-3, 3-4, 4-5, 5-1 or however many vertices there are in each polygon.

Before rendering the shape, call gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) before you draw everything normally. This causes front and back facing polygons to be rendered as a wireframe. To turn it back to solid polygons use GL.GL_FILL instead of GL_LINE. You can also use GL_FRONT and GL_BACK instead of GL_FRONT_AND_BACK to control the mode for individual facings.

HTH

Ok i changed the question.

I would create a new post