Announcement

Collapse
No announcement yet.

Local and World transformations

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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/~jylila...ayJulia_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
    http://www.ylilammi.com/

  • #2
    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:

    Code:
    Vector rayp = worldToObj * ray.p;
    Vector raydir = worldToObj.m * ray.dir; // Use the matrix portion only for the direction
    and
    Code:
    Vector hitPoint = objToWorld * localHitPoint;
    Vector normalDir = objToWorld.m * localNormalDirection; // Use matrix portion only for the direction
    Best regards,
    Vlado
    I only act like I know everything, Rogers.

    Comment


    • #3
      Thank you vlado!

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

      - Jerry Ylilammi
      http://www.ylilammi.com/

      Comment

      Working...
      X