Rotation of a vector
by Lance Hampton · in Technical Issues · 04/04/2008 (1:33 pm) · 3 replies
Ok. I'm not really looking for math explanation as much as I am looking for documentation of the same.
The simplest explanation of my problem can be reduced to, "how can I raise the programatically raise the angle of a fired weapon?" My problem is a bit more complex and can't be solved by remounting the weapon or changing the facing, I'd still need to change the angles at run time.
Looking at starter.fps when the crossbow is fired:
I can see that there is a function getMuzzleVector. What I'm looking for is code that will let me get the muzzle vector +10 degrees relative to the weapon's orientation.
I would want to take something like the %obj below (the weapon), find my vector which is 10% raised from that. Multiply by the object's transform, then get a vector from the resulting transform. There basically doesn't seem to be a getVector() function that can be called against a transform.
From the documentation I was looking at, I keep seeing the same reference to six or so Matrix functions.
It would definitely seem that "you can't get there from here" using Torquescript (without doing the matrix math longhand).
The reason I ask this is that I'm accustomed to having all the same math functions available for local and world geometry, with simple transforms between the two.
It feels like I'm missing something that should be there. Am I wrong, move to C++?
The simplest explanation of my problem can be reduced to, "how can I raise the programatically raise the angle of a fired weapon?" My problem is a bit more complex and can't be solved by remounting the weapon or changing the facing, I'd still need to change the angles at run time.
Looking at starter.fps when the crossbow is fired:
I can see that there is a function getMuzzleVector. What I'm looking for is code that will let me get the muzzle vector +10 degrees relative to the weapon's orientation.
I would want to take something like the %obj below (the weapon), find my vector which is 10% raised from that. Multiply by the object's transform, then get a vector from the resulting transform. There basically doesn't seem to be a getVector() function that can be called against a transform.
function CrossbowImage::onFire(%this, %obj, %slot)
{
%projectile = %this.projectile;
// Decrement inventory ammo. The image's ammo state is update
// automatically by the ammo inventory hooks.
%obj.decInventory(%this.ammo,1);
// Determine initial projectile velocity based on the
// gun's muzzle point and the object's current velocity
%muzzleVector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%muzzleVelocity = VectorAdd(
VectorScale(%muzzleVector, %projectile.muzzleVelocity),
VectorScale(%objectVelocity, %projectile.velInheritFactor));
// Create the projectile object
%p = new (%this.projectileType)() {
dataBlock = %projectile;
initialVelocity = %muzzleVelocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
return %p;
}From the documentation I was looking at, I keep seeing the same reference to six or so Matrix functions.
It would definitely seem that "you can't get there from here" using Torquescript (without doing the matrix math longhand).
The reason I ask this is that I'm accustomed to having all the same math functions available for local and world geometry, with simple transforms between the two.
It feels like I'm missing something that should be there. Am I wrong, move to C++?
Torque Owner Jason MacWilliams
%muzzleVelocity = VectorAdd( VectorScale(%muzzleVector, %projectile.muzzleVelocity), VectorScale(%objectVelocity, %projectile.velInheritFactor)); // new --> %mat = MatrixCreateFromEuler("-10 0 0"); %muzzleVelocity = MatrixMulVector(%mat, %muzzleVelocity); // <-- new // Create the projectile object %p = new (%this.projectileType)() {Which will cause projectiles to come out 10 degrees above (negative means above here) the muzzle vector. If you want something like 10%, you'll have to get the muzzle vector's rotation value and use the same technique.