PDA

View Full Version : finding the angle around a normal


WFinlay
09-13-2005, 12:24 AM
What I'm looking for is a way to find the camera's relative angle around the surface normal at a point at rendertime. That is, I'm after a rotational angle around the axis of the normal at a point, not the elevation angle between the normal and tangent. I see that the rayDirection attribute of samplerInfo gives the vector from the camera to the sample point and normalCamera gives the vector of the normal at the sampled point, so I'm guessing I have to compare these values somehow. I just don't see how to compare these two to find the angle value I need. Do I need to convert both values to objectSpace for the comparison to have meaning?
I'm not very adept with mel, but it doesn't scare me. It just seems like it should be a simple value to find. Maybe mel isn't even necessary for this.

Bill

Jboy
09-13-2005, 01:01 AM
I think you want the SamplerInfo node, and specifically, the facing ratio attribute.

edit:typo

WFinlay
09-13-2005, 01:11 AM
Thanks JBoy, but facingRatio returns a 0-1 value depending on how close the camera view is to being in line with the surface normal. In other words, the camera's elevation angle from the surface. I want the angle around the normal's axis.

Bill

Jboy
09-13-2005, 03:00 AM
ah, yes, I see that you mentioned that in the original post.

Maybe the tangentVcamera or tangentUcamera is what you're looking for.

WFinlay
09-13-2005, 06:16 AM
As you noted, JBoy, tangentUcamera and tangentVcamera are both 90 degrees off the normal, so I need a value that describes how close the camera angle is to one of the tangents. Since facingRatio is the cosine of the difference between rayDirection and normalCamera, I tried taking the dot product of rayDirection and tangentVcamera (via a vectorProduct node with normalize turned on). This seems to work in practice, but when I connected the vectorProduct's output to the vCoord of a Ramp node to test it, Maya gave the following error:
// Error: vectorProduct2: found a zero-length output vector. Result is unpredictable. //
Hopefully that won't come back to bite me later; the results APPEAR predictable...

Bill

Jboy
09-13-2005, 07:33 AM
hmmm, yeah when you get deep into the matrix/vector calculations I always get confused. I was struggling with a similar problem the other day and found this page about finding a quat value to rotate between two vectors... maybe that would help? looks like you need the dot product AND the cross product....

http://www.euclideanspace.com/maths/algebra/vectors/angleBetween/minorlogic.htm

soopagenius
09-13-2005, 01:24 PM
Can't give you specifics on how to implement the solution in mel, but I can sketch out step by step the math you have to do.

The basic idea is to find two orthogonal vectors on the plane tangent to the surface, then project the camera vector onto it. The angle relative to tangentUcamera can be obtained using a tan inverse function (dunno if that exists in mel, though).

Let's call the normal n, the camera vector v, and tangentUcamera tu. Then take tv = crossprod(n, tu). (You can't just use tangentVcamera, because it's not necessarily orthogonal to tangentUcamera).

Then let

x = dotprod(tu, v)
y = dotprod(tv, v)

Then the angle you seek is atan2(y, x).

In the above, I assumed n, tu, and tv to be of unit length. You may have to normalize them first.

Hope that helps.

Kevin Atkinson

CGTalk Moderation
09-13-2005, 01:24 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.