Local and World transformations

I’m trying to write Julia Quaternion for VRay, so far I’ve gotten the basics to work:

http://www.niksula.cs.hut.fi/~jylilamm/graphics/VRayJulia\_02.jpg

However I’m having some trouble with object transformations.

I have

Vector rayp = worldToObj * ray.p;
Vector raydir = worldToObj * ray.dir;

Before the intersection calculations and

Vector hitPoint= objToWorld * localHitPoint;
Vector normalDir= objToWorld * localNormalDirection;

After the intersection calculations are done and I want to return intersection results.

This works fine for rotation and scaling. However it doesn’t seem to give me correct results in translation, if I move the object even a little, it seems to move a lot, like ten to fifty times the amount I move it in viewport.

I get the tranformation matrixes used above like this:

objToWorld=toTransform(node->GetObjTMAfterWSM(t));
worldToObj=objToWorld.makeInverse();

- Jerry Ylilammi

When you use the ‘*’ operator on a transform and a vector, it assumes you want to transform a point. This is true for ray.p, but not for ray.dir, which is a direction, and not a point. Instead, you should do this:

Vector rayp = worldToObj * ray.p;
Vector raydir = worldToObj.m * ray.dir; // Use the matrix portion only for the direction

and

Vector hitPoint = objToWorld * localHitPoint;
Vector normalDir = objToWorld.m * localNormalDirection; // Use matrix portion only for the direction

Best regards,
Vlado

Thank you vlado!

Damn I should have noticed that myself. Anyway, you can see the results here: http://www.chaosgroup.com/forums/vbulletin/showthread.php?t=42429

- Jerry Ylilammi