Translate along an arbitrary axis?
by Lee Latham · in Torque Game Engine · 08/12/2008 (10:37 pm) · 0 replies
Hello,
Does anyone know an algorithm to translate along an arbitrary vector an arbitrary real (game) distance?
I've been getting by by obtaining the vector I need (which is not a problem), and then simply scaling it, and then adding or subtracting the scaled vector from my starting point. But now I've got an issue where I need to generate multiple, parallel vectors, and the scaling is breaking the code because when the player looks up or down, the scale produces a much larger vector.
Picture a shotgun, only except of a random spread of pellets you've got a perfect grid of them (which is exactly what I'm doing, actually. So what I'm doing in a nutshell, and simplified for readability (thanks to all whose code I've ripped off so far):
So what's happening is that the spread changes depending on which way you're facing (up or down, that is). Not only that but it tends to cant to the left or right, which also gets worse when you shoot up or down as well.
So I reckon I've either made a mistake (not improbable) or I've got the wrong idea, and using VectorScale to move along the vectors is the wrong way to go. Any input would be greatly appreciated!
Does anyone know an algorithm to translate along an arbitrary vector an arbitrary real (game) distance?
I've been getting by by obtaining the vector I need (which is not a problem), and then simply scaling it, and then adding or subtracting the scaled vector from my starting point. But now I've got an issue where I need to generate multiple, parallel vectors, and the scaling is breaking the code because when the player looks up or down, the scale produces a much larger vector.
Picture a shotgun, only except of a random spread of pellets you've got a perfect grid of them (which is exactly what I'm doing, actually. So what I'm doing in a nutshell, and simplified for readability (thanks to all whose code I've ripped off so far):
%vector = %obj.getMuzzleVector(%slot); %objectVelocity = %obj.getVelocity(); %vector1 = VectorScale(%vector, %projectile.muzzleVelocity); %vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor); //all this is just getting the %velocity = VectorAdd(%vector1,%vector2); //starting velocity %xAngle = 0; %yAngle = 0; %zAngle = 1.5; %matrix = MatrixCreateFromEuler( %xAngle SPC %yAngle SPC %zAngle); //getting perpendicular "X" vector %xresultVector = MatrixMulVector( %matrix, %velocity ); %xresultVector = Vectorscale (%xresultVector, 0.01); //here's scale #1 %xAngle = 0; %yAngle = 0; %zAngle = 3.14; %matrix = MatrixCreateFromEuler( %xAngle SPC %yAngle SPC %zAngle); //getting perpendicular "Y" %yresultVector = MatrixMulVector( %matrix, %velocity ); %yresultVector = Vectorscale (%yresultVector, 0.1); //here's scale #2 //now I start distributing pellets: %pellet[0] = VectorSub ( %velocity, %xresultVector); %pellet[1] = VectorAdd ( %velocity, %xresultVector); %pellet[2] = VectorAdd ( %velocity, %x2resultVector); %pellet[3] = VectorSub ( %velocity, %x2resultVector); ... //omitting most of the array assignment for brevity %pellet[13] = VectorSub (%pellet[3], %yresultVector); %pellet[14] = VectorAdd (%pellet[3], %yresultVector); %pellet[15] = VectorSub (%pellet[13], %yresultVector); //and then a simple for loop that creates projectiles at the various %pellet[] vectors.
So what's happening is that the spread changes depending on which way you're facing (up or down, that is). Not only that but it tends to cant to the left or right, which also gets worse when you shoot up or down as well.
So I reckon I've either made a mistake (not improbable) or I've got the wrong idea, and using VectorScale to move along the vectors is the wrong way to go. Any input would be greatly appreciated!