Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

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

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Synthesizer   Members   


Posted 01 August 2012 - 05:27 AM

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,


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.

Attached Thumbnails

  • lightConeProblem1.jpg

#2 MJP   Moderators   


Posted 01 August 2012 - 11:54 AM

The Matrix class already has the CreateWorld method, which does what you want. No need to make a view matrix. Posted Image

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.

#3 Synthesizer   Members   


Posted 03 August 2012 - 12:28 PM

Hi Matt,
thanks for your answer, the info you gave me tempted me to dig more on matrices & now I understand them much better Posted Image

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! Posted Image 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!


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.