• Advertisement
Sign in to follow this  

Spotlight problem

This topic is 4708 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

When i comment out light.Position then the program works. When i want to use light.Position then he proramm sucks. Can anybody help me? Many thanks in advance Olaf I use following code to make a spotlight: D3DLIGHT9 light; //set light source D3DXVECTOR3 position(-0.0f, -0.0f, 4.0f); //set light colour D3DXCOLOR color(10.0f,0.0f, 0.0f, 1.0f); //set light direction D3DXVECTOR3 direction(0.0f, 0.0f, 1.0f); ZeroMemory(&light, sizeof(light)); //directional light light.Type = D3DLIGHT_SPOT; //parallel lightning // light.Position = position; light.Ambient = color * 1.0f; //color of ambient light light.Specular = color *1.0f; //color of specular light light.Diffuse = color*1.0f; //color of difuse light light.Direction = direction; //direction of light light.Theta=0.5f; light.Phi=0.7f; light.Falloff=0.0f; light.Attenuation0= 1.0f; light.Attenuation1= 1.0f; light.Attenuation2= 1.0f; light.Range = 100.0f; //light range //activate light app.global_pDevice->SetLight(1, &light); app.global_pDevice->LightEnable(1, true);

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure but possibly DX does not like a negative zero for a position. What do you mean by:


//set light source
D3DXVECTOR3 position(-0.0f, -0.0f, 4.0f);

Share this post


Link to post
Share on other sites
What do you mean the "program sucks"? When you commen out the position, you're implicitly setting the position to (0,0,0), since the ZeroMemory call sets all the members to 0 (and 0.0f == 0x00000000 with IEEE format floating point numbers)

Share this post


Link to post
Share on other sites
What is the position of the object that is being illuminated? As Evil mentioned, if you don't specify the light's position, it is set to the origin from the world coordinate system.
Since the spot light has the z-axis direction (pointing to positive values) and the light "works" when its position is set to (0.0f,0.0f,0.0f), so, maybe the object was placed inside the [0.0f,4.0f] z-interval. In this case, try to set the light's position to:

D3DXVECTOR3 position(0.0f,0.0f,-4.0f);

Share this post


Link to post
Share on other sites
Yes the light was placed inside. Many thanks for your help.
But I have another question for the spot light.
How can I make it happens that the spotlight itself
lights?
I want to make an afterburner for a spaceship with a spotlight.

Many Greetings

Olaf

Share this post


Link to post
Share on other sites
There is no such thing as a light bulb in common 3D graphics. Light is only used to calculate the lighting of surfaces; no light rays or such exist. You have to create such effects yourself. One simple approach is to use a sphere or some other geometry and set the emmissive material values, but it is a rather bleak approximation. If you want the good stuff, look into more sophisticated effects such as glow, bloom, hdr, etc.

Greetz,

Illco.

Share this post


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

  • Advertisement