Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Lighting and glMultMatrixf problem

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 Spoon Thumb   Members   

121
Like
0Likes
Like

Posted 22 July 2012 - 05:25 AM

I've written a basic graphics engine for OpenGL-ES 1.1 in Java for Android. I use the following code to orientate the spaceships in my game to point in the direction of travel:
[source lang="java"]gl.glPushMatrix();transforms[i].transform(gl);gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, light0Position); model.drawVertexBufferObjects((GL11) gl);gl.glPopMatrix();[/source]

[source lang="java"]public void transform(GL10 gl) { gl.glTranslatef(xyz[0], xyz[1], xyz[2]); // where xyz holds the coordinates of the spaceship gl.glScalef(scale,scale,scale); Orientate(gl); }[/source]
[source lang="java"]private FloatBuffer startMatrixFB;protected void Orientate(GL10 gl){ if(startMatrixFB==null){ ByteBuffer byteBuffer = ByteBuffer.allocateDirect(16 * 4); byteBuffer.order(ByteOrder.nativeOrder()); startMatrixFB = byteBuffer.asFloatBuffer(); } startMatrixFB.position(0); startMatrixFB.put((float) -rightOrientationVector.mX); startMatrixFB.put((float) -rightOrientationVector.mY); startMatrixFB.put((float) -rightOrientationVector.mZ); startMatrixFB.put(0); startMatrixFB.put((float) upOrientationVector.mX); startMatrixFB.put((float) upOrientationVector.mY); startMatrixFB.put((float) upOrientationVector.mZ); startMatrixFB.put(0); startMatrixFB.put((float) directionVector.mX); startMatrixFB.put((float) directionVector.mY); startMatrixFB.put((float) directionVector.mZ); startMatrixFB.put(0); startMatrixFB.put(0); startMatrixFB.put(0); startMatrixFB.put(0); startMatrixFB.put(1); startMatrixFB.position(0); gl.glMultMatrixf(startMatrixFB);}[/source]
The problem is that this doesn't affect the diffuse lighting. The lighting on the ship appears without taking into account the changes made by the Orientate() method. I.e. the light is always in the same place relative to the model:

lighting_problem_iridian.png

If anyone can help me solve this, I'd be most appreciative

Thanks
James
Android Developer for Crystalline Green

#2 dpadam450   Members   

2330
Like
1Likes
Like

Posted 22 July 2012 - 10:39 AM

Thats because you have the light transformed exactly how your model is. Say your model has normals and lets treat the light as a normal as well.

If you rotate your model (and its normals) then you are rotating the light normal as well. Only call glLightfv() after you have applied the camera matrix only.
Identity()
cameramatrix()
glLight()

Identity()
ObjectMatrix()
Draw()

#3 Spoon Thumb   Members   

121
Like
0Likes
Like

Posted 22 July 2012 - 12:48 PM

Ah, thanks! could have sworn I'd already tried that...
Android Developer for Crystalline Green




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.