0
\$\begingroup\$

I'm trying to take a steady grip on Sharp DX. Already done some work like translating, scaling and rotating objects. Now i have to calculate the rotation matrix using only direction vector and arbitrary UP vector which is Unit Y vector (0,1,0). And this is where everything I know about Direct X graphics falls apart: I filled the Matrix.Forward with the normalized DIRECTION vector, and then crossed it with arbitrary UP (exactly this: DIR cross UP, not the other way), the resulting vector put in Matrix.Right property. Now if I put (0,1,0) in the Matrix.Up property, my model is facing the exact opposite direction to the expected direction (it faces backwards). Further investigation brought me to the fact that the Matrix.Identity matrix faces the NEGATIVE Z direction, which is weird to me as I thought that Identity would face positive X,Y,Z axes. Now I can overcome my problems by flipping any of the axes, but this clearly is not comforting to me, as there is something i must have missed in the meantime. So the ultimate question is: Why my Identity matrix points positive Y axis (good), positive X axis (nice, i expect this) and NEGATIVE Z (help!)

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

A cross product gives you the perpendicular line. Both the negative and the positive vector represent the same perpendicular line. You'll have to change your order of operations to get the positive vector. Eg. DIR cross UP and UP cross DIR will give the same perpendicular line but might change the sign of the vector. (It's too early to do matrix computations to show that :P)

\$\endgroup\$
2
  • \$\begingroup\$ Thank you for the quick answer. Of course I can arbitrarily change the order of operations, or arbitrarily flip my axes to achieve the desired effect. The problem is: My arbitrary calculations DO work but I don't know WHY they work, which makes me feel like i'm loosing control over all of this. If i change the order of operations, I have to change my FORWARD vector to the opposite-facing vector, and I don't feel very comfortable with such hacks. Also: the Identity matrix has -1 Z in its .Forward component. Why so? :( SharpDX uses left-handed system, just like DX \$\endgroup\$
    – user31060
    Commented May 23, 2013 at 8:36
  • 1
    \$\begingroup\$ Well you can always just do a cross product on paper to see what happens, the order of operations is important and it will matter. \$\endgroup\$
    – Roy T.
    Commented May 23, 2013 at 14:54

You must log in to answer this question.