PDA

View Full Version : API. Problem with normal transformation


smaragden
09-27-2002, 09:26 AM
I have a problem with the transformation of an normal from worldspace
to cameraspace in the Maya4.0 API.
I'm successfylly transform the point with no problem, just: (point in
worldspace) * (cameras inversetransformationmatrix).
I thougt that (normal in worldspace).transformAsNormal(cameras
inversetransformationmatrix) would do the same but but the right way
for normals.
But i cant't get it to work. Here's the snippet of code relevant to
the problem.

//CODE////////////////////////////////////////////////////////
MDagpath objDPath = nurbsobjects dagpath
MDagPath camDPath = cameras dagpath
MVector SNormal;
MPoint SPoint;
MFnCamera Camera;
MFnNurbsSurface Sphere;

currentNurbsObject.setObject( objDPath );
SNormal = currentNurbsObject.normal(u,v,MSpace::kWorld ,&status);
currentNurbsObject.getPointAtParam(u,v,SPoint,MSpace::kWorld);

worldToCam = CamDpath.inclusiveMatrixInverse();

SPoint = SPoint * worldToCam;
SNormal = SNormal.transformAsNormal(worldToCam);
SNormal.normalize() ;
//CODE////////////////////////////////////////////////////////

SPoint is in Camera Space after this, but SNormal is not.
What am i missing about transformation of normals?

Regards
Fredrik Brännbacka

playmesumch00ns
09-27-2002, 10:42 AM
Ayyy the whole thing about transforming vectors is that you add a '0' to the end of the vector when you promote it to homogenous co-ordinates. So, for example, [1 1 1] would become [1 1 1 0] when you do the transformation, and then you drop the 0 when you convert back to a 3D vector.

Now, I'm assuming that Maya's transformAsNormal() should do this for you. However! If it's not there is a simple work-around that should work fine for most cases ('cept it'll take twice as much CPU-time). All you do is think of your normal as a directed line segment. So you take the point that you've got, and do this:

SPoint2 = SPoint + SNormal;

SPoint = SPoint * worldToCam;
SPoint2 = SPoint2 * worldToCam;
SNormal = SPoint2 - SPoint;

Since you know that the point transformation works, just treat your normal as a directed line segment and transform it that way. It's not ideal I know, and doesn't solve your problem, but it's guaranteed to work!

btw, do you know the API very well? I'm thinking of getting into writing a plugin, but it's quite a daunting task!

artifish
09-27-2002, 11:33 AM
hi, the api docs say
"Normal vectors are not transformed in the same way as position vectors or points. If this vector is treated as a normal vector then it needs to be transformed by post multiplying it by the inverse transpose of the transformation matrix. This method will apply the proper transformation to the vector as if it were a normal."

as far as i understand your code, you are only providing the inverse matrix only ... don't know if the "transformAsNormal" function will do the transpose for you, but you might try to do the transpose yourself and see if this will give you the correct normal.

cheers, carsten

playmesumch00ns
09-28-2002, 11:30 AM
doh...that was the other thing you have to do!

CGTalk Moderation
01-13-2006, 05:00 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.