Jump to content


gah *sigh*, finding roll orientation


5 replies to this topic

#1 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 18 September 2008 - 08:15 PM

I asked a question a while back that was about finding the yaw and pitch rotations for the equivelant of a direction (normalized) vector. That's no longer a problem (thanks again Reed), but now I am doing a billboarded light beam and I need the z rotation (aka roll)

So I already have the x and y rotations, how do I compute roll with the direction vector from my camera to the light.

Thanks in advance.
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5311 posts
  • LocationSanta Clara, CA

Posted 18 September 2008 - 08:54 PM

One vector isn't enough to pin down the roll. You can see that rolling the vector would just rotate it around its own axis and wouldn't change it at all. Roll only matters when you have a full coordinate system with three axes.

That being said, you can calculate roll by looking at the left/right axis of the coordinate system. If you use the convention of x = forward, y = left, z = up, then the roll is atan2(left.z, sqrt(left.x^2 + left.y^2)). Note that you can only roll up to +/- 90 degrees in this scheme; then there will be a discontinuity in the Euler angles.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 18 September 2008 - 10:42 PM

Thanks for the advice.

You're making it sound a bit like I'm going about this wrong. My goal here is (and I'm sure your familiar with it) I have a 2D light beam that has a fixed X and Y orientation (those being the direction that the spot light is pointed in). The only thing left to do is to keep the side of the beam facing towards me (hence billboarding).

Is there a better or more elegant way to achieve this?
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 5311 posts
  • LocationSanta Clara, CA

Posted 18 September 2008 - 11:06 PM

In that case, you can use the camera's view direction. If your beam texture is laid out with the direction of the light parallel to the U axis, you can calculate the V axis for the texture in world space by crossing the spotlight direction with the camera's view direction. Those U and V axes should be enough to construct the appropriate screen-facing quad.
reedbeta.com - developer blog, OpenGL demos, and other projects

#5 EddyCharly

    New Member

  • Members
  • PipPip
  • 25 posts

Posted 18 September 2008 - 11:10 PM

take the cross product of your view vector and beam vector, it will give you the side vector.

#6 EddyCharly

    New Member

  • Members
  • PipPip
  • 25 posts

Posted 18 September 2008 - 11:21 PM

and use an object space quad instead of a screen space billboard.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users