Jump to content
  • Advertisement
Sign in to follow this  
Synthesizer

[XNA] Spotlight cone model rotation. ViewMatrix Decompose Problem.

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

Hi everyone!

I'm having a little issue when trying to decompose a view matrix:

I basically have a spot light which works fine.
I added an alpha blended cone model to create a light volume effect. It looks allright & everything is fine except its rotation.
I thought I could probably create a view matrix for the light (with position & target) & decompose it to get an automatically made rotation matrix (to apply to the cone & get the same rotation as the light).
But when I decompose it, the values I get don't seem to be correct. The translation matrix is not working for me & the rotation doesn't seem to be right.

I wonder why is this happening &, in case I cannot achieve it like this, how may I get a rotation from a source & a target point in 3D (this http://www.chriskugl...en-two-vectors/ didn't work for me, maybe I'm doing smth wrong, but I don't know...)

Here's how I create the view matrix & then I decompose it:
[source lang="csharp"]light.view = Matrix.CreateLookAt(light.position, myPlayer.animatedModel.position, Vector3.Up);
bool deco=light.view.Decompose(out scaleView, out rotationView, out translationView);[/source]


I also attach a pic showing the light (following the player) & the cone (moving in a way that sometimes matches the light movement but it's not right). The light diameter is exagerated to illustrate the case, the idea is that the cone is scaled depending on the light diameter, I just have to tweak it a bit somehow to match). The cone doesn't seem to move in X, it moves in Z following the light movement but not matching it. It moves in a very restricted range & X movement seems to be rendered in Z.

Thanks in advance,

Synth

P.S.: I'm not sure I'm posting this in the right forum because it mixes math, graphics & xna elements, so forgive me if I'm wrong. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
The Matrix class already has the CreateWorld method, which does what you want. No need to make a view matrix. smile.png

FYI, what that function does is generate a "right" vector by crossing the "forward" and "up" vectors and normalizing the result. Then it generates a new "up" vector by crossing "right", and "forward". These three vectors are the basis vectors for your orientation, so you just stick them in the first three rows of a matrix (right in the first row, up in the second, forward in the third). The position then goes in the translation portion of the matrix, which is the last row.

Share this post


Link to post
Share on other sites
Hi Matt,
thanks for your answer, the info you gave me tempted me to dig more on matrices & now I understand them much better smile.png

After I read more, played with matrices & applied the Matrix.CreateWorld, the problem persisted anyway. I spent all the afternoon double & triple checking everything & I wasn't able to find anything wrong in the code! So I created the model over & over again... I recorded a video showing the problem & I was already writing here a new message when I had an insight...: "am I exporting the model left handed...?" Daaaaaaamn that was the problem! tongue.png Half of me felt as a dumb @ss, but the other half shouted: "YEEEEEEAAAH!!"

hehe, so it works like a charm!
I actually want to thank you for pointing me out this info (I didn't know how matrices were storing this data) as now I understand it & it helps me for future usages!

Cheers,
Synth

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!