Directional Lights in DX7...

Started by
3 comments, last by VyvyanBasterd 23 years, 10 months ago
OK, I''m having a few problems with my directional light source under DX7. I want the light source to point in the same direction (at the ground), but what keeps happening is that the light source "follows" the camera movement! Do I need to multiply the direction by my world matrix every time the camera rotates? Should I put this code in before or after my call to BeginScene()? James
Advertisement
I had the reverse problem before (the light didn´t want to follow the camera). Have you tried to set the lights direction every render lap? Like this:

D3DLIGHT7 light;
m_pD3DDev->GetLight(0, &light);

light.dvDirection.x = 0;
light.dvDirection.y = -1;
light.dvDirection.z = 0;
m_pD3DDev->SetLight(0, &light);

Gandalf the White

Gandalf the Black
Well, I was actually re-initializing it every game frame (i.e., filling in the light structure each time), not using the GetLight() function. Is the direction affected by the World Matrix?

James
The Light sources are not affected by any transformation matrix and should always be defined in world coordinates. If the light never moves you only need to set it once.

- WitchLord

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

OK...figured out my problem.

My problem was one of OVER "optimization". I was attempting to eliminate having to use the view matrix, by simply updating the world matrix. This was very fast, but as I showed, lighting was completely fubar''d. So the moral of the story is, don''t optimize until it works.

Thanks, WitchLord!

Vyvyan

This topic is closed to new replies.

Advertisement