﻿ Getting horizontal and vertical perpendicular vectors relative to muzzlevector

Author Topic: Getting horizontal and vertical perpendicular vectors relative to muzzlevector  (Read 1301 times)

King of the Bill

This is basically related to my last topic, but I've narrowed down what exactly I don't know how to do.
Basically, I've figured out how rotation in Torque works now (more or less) but the vector math is still giving me loads of stuff. I can rotate vectors around axes of my choice, but I need to know those axes. Specifically, I need a way to get vectors that are perpendicular to the muzzlevector; the horizontal perpendicular should run parallel to the ground plane, while the vertical perpendicular should be perpendicular to both the muzzlevector and the horizontal perpendicular.
I have no clue how to do this. Can anyone help?

Xalos

%axis0 = vectorNormalize(vectorCross(%muzzleVec, "0 0 1"));
%axis1 = vectorNormalize(vectorCross(%muzzleVec, %axis0));

%axis0 is the horizontal axis, and %axis1 is the "vertical" axis.  If %axis1 is in the wrong direction, flip the order of %muzzleVec and %axis0.

In case you're interested in the vector math going on here, the cross product of two vectors produces an output vector that is perpendicular to both input vectors.

King of the Bill

%axis0 = vectorNormalize(vectorCross(%muzzleVec, "0 0 1"));
%axis1 = vectorNormalize(vectorCross(%muzzleVec, %axis0));

%axis0 is the horizontal axis, and %axis1 is the "vertical" axis.  If %axis1 is in the wrong direction, flip the order of %muzzleVec and %axis0.
I actually tried that earlier and it wasn't working right (specifically, the "0 0 1" seemed to be causing problems), though I could probably stand to try it again.

Anyway, I got it working now (the manual, inefficient way), now I just gotta clean up the code.