Set Matrix Forward Direction
For some reason I'm struggling with something that should be very simple. I have a Matrix with a position and scale. For my object, I also have a forward vector. I want to set the matrix so that my object faces the same direction as the forward vector. No matter what I try, it seems to affect the scale of the object.
For example, I have set the position of the object to 20, 2, 10. I have set its scale to 1.7. Now I want update the direction every frame to match the forward vector.
So I start with a matrix and position that looks like this.
x {x=1.70000000 y=0.00000000 z=0.00000000}
y {x=0.00000000 y=1.70000000 z=0.00000000}
z {x=0.00000000 y=0.00000000 z=1.70000000}
pos {x=20.00000000 y=2.00000000 z=10.00000000}
I then use the following code to set the direction I want the object to face.
Vec f = Vec(forward.x,0,forward.y);
f.normalize();
matrix.setDir(f, Vec(0,1,0));
In this example, let's say forward is equal to the following.
Vec2 forward = Vec2(0,1);
I then end up with a matrix and position that looks like this.
x {x=0.00000000 y=0.00000000 z=1.00000000}
y {x=0.00000000 y=1.00000000 z=0.00000000}
z {x=1.00000000 y=0.00000000 z=0.00000000}
pos {x=20.00000000 y=2.00000000 z=10.00000000}
My object now faces the correct direction, but its scale is gone. If I try to set the scale back, then the object no longer faces the correct direction.
Can anyone explain to me how I scale my object and get it to face the correct direction at the same time?
(This post was last modified: 07242010 01:57 AM by fatcoder.)
