glrotatef rotates custom glnormalf

Hi guys,

I am using custom normals that always should be pointing in the same direction. I started adding cars into my game and they should turn and go up and down hills and so on (rotate) while not changing the normal.

When applying rotate it always rotates the normal as well even if I put it before glPushMatrix or before the glRotatef or inside the begin or wherever.

Does anyone have an idea without have to mimic glrotatef and send the rotated values to glVertex3f?

Example:

GL11.glPushMatrix();
	GL11.glNormal3f(getNormal().getX(), getNormal().getY(), getNormal().getZ());
	GL11.glTranslatef(getPosition().getX(), getPosition().getY(), getPosition().getZ());
	GL11.glRotatef(getRotation().getX(), 1, 0, 0);
	GL11.glRotatef(getRotation().getY(), 0, 1, 0);
	GL11.glRotatef(getRotation().getZ(), 0, 0, 1);
	GL11.glBegin(GL11.GL_QUADS);
		GL11.glVertex3f(0, 0, 0);
		GL11.glVertex3f(1, 0, 0);
		GL11.glVertex3f(1, 0, 1);
		GL11.glVertex3f(0, 0, 1);
	GL11.glEnd();
GL11.glPopMatrix();

Vertex attributes only get sent to the graphics card when you call glVertex, and then the current matrix (as controlled by glRotatef) is applied. So it doesn’t matter if you call glRotatef before or after glNormal.

However I cannot conceive of a situation where you wouldn’t want the normal to rotate along with the rest of the geometry. Exactly what effect are you trying to achieve? Likely there’s a better/easier way of doing it.

I’m using custom normals that are calculated when the landscape is altered to give soft dynamic shadows without having to draw everything twice.

I guess that seeing as it’s sent together I’ll have to rotate the vertexes manually instead of using the glrotatef function :frowning:

IMO you’re embarking down the wrong path. If you could post some screenshots of what you’re trying to do, and where glrotate causes a problem, I’m sure we can come up with some alternatives.

The obvious solution would be to use shaders and just send the custom normal down as a vertex attribute. If you can’t/won’t use shaders and want to stick to the fixed-function path then I’d suggest (ab)using texture coords and a light gradient texture to do your lighting.

Kinda hard to recommend anything more specific from such vague details though.

Orangy Tang: I was looking into abusing the texture coords, seeing as I’ll want to put textures on it as well by using it then that is probably the way to go. I didn’t know for sure though as I thought it might mess something else up, but you seem to know what you’re talking about so I’ll give it a shot. Thanks! :slight_smile:

Ihkbob: I know I’m doing something that isn’t conventional, but it took something unconventional to get dynamic shadows and 200 fps out of my old laptop :wink: Once I’m done with the cars (which I hope is tomorrow) I’ll post a screenshot of the result.

Whatever works for you :wink: the unconventional can be fun as long as it doesn’t screw you in the long run

I tried the texture part but glrotate still rotates the glnormal. Am I doing something wrong or doesn’t it work after all? I tried moving the glMatrixMode outside the glPushMatrix or surround it with it’s own glPushMatrix or skip the glLoadIdentity and so on but I can’t seem to get it to work.

GL11.glPushMatrix();
	GL11.glNormal3f(getNormal().getX(), getNormal().getY(), getNormal().getZ());
	GL11.glTranslatef(getPosition().getX(), getPosition().getY(), getPosition().getZ());
	GL11.glRotatef(getRotation().getX(), 1, 0, 0);
	GL11.glRotatef(getRotation().getY(), 0, 1, 0);
	GL11.glRotatef(getRotation().getZ(), 0, 0, 1);
	GL11.glMatrixMode(GL11.GL_TEXTURE);
		GL11.glLoadIdentity();
		GL11.glNormal3f(vehicle.getNormal().getX(), vehicle.getNormal().getY(), vehicle.getNormal().getZ());
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	GL11.glBegin(GL11.GL_QUADS);
		GL11.glVertex3f(0, 0, 0);
		GL11.glVertex3f(1, 0, 0);
		GL11.glVertex3f(1, 0, 1);
		GL11.glVertex3f(0, 0, 1);
	GL11.glEnd();
GL11.glPopMatrix();

The normal will always be transformed by the rotational component of the modelview matrix, using the current modelview matrix when the glVertex call was made.

The texture matrix only transforms the texture coordinates, so what you’d want to do is put your soft-shadow/lighting into a texture and compute texture coordinates to do the look-up. I think that’s what he meant.

Oh, that won’t do it. I’ll rotate the normal first then with the negative degree number so when glrotatef rotates it it rotates it back to the original.

Thanks for the ideas and thoughts :slight_smile:

Oh, and I promised a screen shot. I have no texture on the cars and the normal doesn’t work (which you already know…).

I’m running it on my laptop with the dynamic shadows from the landscape (you can adjust the landscape in real time and the shadows affects the trees and roads) @ 140-210fps depending on zoom level.