Sign in to follow this  
anvil

managed directx C# - possible to move a spotlight to follow an object in your scene?

Recommended Posts

anvil    122
Hi I have tried doing this but my attempts havent worked. Firstly in theory you are supposed to create your lights in OnCreateDevice() so that eliminates the possibility of updating the direction of the light constantly. For a test firstly I tried including just the Device.Lights[1].Direction() in the OnFrameRender() by itself and updating the direction constantly and no luck. Then tried moving everything related to this spotlight (from creation to color to position to direction) in the onFrameRender still no luck. Both those attempts the light stays in the same direction all the time, even though new values are being passed to the .Direction() constantly. Any ideas if this is possible or not? Regards

Share this post


Link to post
Share on other sites
remigius    1172
Are you calling Device.Lights[1].Update() after you make the changes to the direction vector (Commit() in older versions of the SDK)? This is needed to make the device actually use the new light settings.

Also, what do you mean by 'including' the vector? Assigning Device.Lights[1].Direction to a new vector struct and changing the x,y,z values on that won't work even if you do call the Update() method. It took me a while to get used to too, but Vector3's are value types so they are immutable, just like ints, floats, bools etc. You expressly need to assign a Vector3 with the new values to the Direction property of the light.

Hope this helps!

Share this post


Link to post
Share on other sites
anvil    122
oh ok I havent used update()... will try that out

What happens is soon as the coordinates change for the spotlight and update is called it just seems to turn off all together...

Share this post


Link to post
Share on other sites
remigius    1172
Try adding Device.Lights[1].Enabled = true after you set the direction and before you call the Update() method... shouldn't be necessary, but it doesn't hurt to try. Other than that, are you sure the direction vectors are correct? If they are facing away from the object to be lit it won't work of course, so you could try changing to a directional light for testing.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this