• Advertisement
Sign in to follow this  

HLSL Camera view angle to object with object rotation

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

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!

 

 

Share this post


Link to post
Share on other sites
Advertisement

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...

Share this post


Link to post
Share on other sites
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.

Share this post


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

  • Advertisement