Sign in to follow this  

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

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 [url=""]http://www.chriskugl...en-two-vectors/[/url] 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,


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
The Matrix class already has the [url=""]CreateWorld[/url] method, which does what you want. No need to make a view matrix. [img][/img]

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 [img][/img]

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! [img][/img] 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!


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