HLSL Camera view angle to object with object rotation

Started by
1 comment, last by ongamex92 9 years, 10 months ago

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!

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

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.

This topic is closed to new replies.

Advertisement