•      Sign In
• Create Account

## HLSL Camera view angle to object with object rotation

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.

2 replies to this topic

### #1danromeo  Members

238
Like
0Likes
Like

Posted 07 June 2014 - 06:06 PM

How do I determine camera view angle to an object with the object's rotation factored in, to display a 2d "imposter" based on the actual view angle of the object?

I can get the camera angle to the object with:



half3 center = mul(input.inPos, xWorld);
half3 EyeVector = normalize(center-CameraPosition);
float lookYaw = atan2(EyeVector.x, EyeVector.z);



But I'm not having any luck determining the view angle with object rotation factored in either by adding or subtracting the EyeVector with the ObjectRotation vector or by atan2'ing the ObjectRotation vector and adding or subtracting the result with lookYaw.  All vectors in question are normalized.

Hope this makes sense.  Thanks!

### #2Jason Z  Members

6417
Like
0Likes
Like

Posted 07 June 2014 - 08:39 PM

Can you describe what you are trying to accomplish in a little more detail?  Are you trying to make a billboard face toward the camera?  Perhaps there is a simpler way to do what you need, as calculating the arctan in a shader seems a bit more than necessary for aligning a 2D object the right way...

Jason Zink :: DirectX MVP

Direct3D 11 engine on CodePlex: Hieroglyph 3

Games: Lunar Rift

### #3imoogiBG  Members

2909
Like
0Likes
Like

Posted 09 June 2014 - 04:27 AM

float lookYaw = atan2(EyeVector.x, EyeVector.z);

atan2 Args are usually in reversed order

float lookYaw = atan2(EyeVector.z, EyeVector.x);

However we need more information about the coordinate systems that you're using. If we are talking about the planar case atan2 should do the trick.

If you want a billbord effect in 3D space use the lookAt matrix basis to create the billboard orientation.

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.