Author Topic: How do i rotate a godamn angle vector (FIXED)  (Read 2635 times)

I think it's unlikely that that can be fixed. I'll look into it tomorrow when I have more time.
I think using the working code from earlier I can probably take the players forward vector and then rotate it 1.57.. radians upwards to get the proper up vector

edit: works, posting solution in one minute
« Last Edit: February 26, 2016, 01:02:58 AM by Swollow »

Code: [Select]
function gunImage::onFire(%db,%pl,%slot)
{
%up = %pl.getUpVector();
%muzVec = %pl.getMuzzleVector(%slot);
%forward = %pl.getForwardVector();
%muzPoint = %pl.getMuzzlePoint(%slot);

%rightVec = vectorCross(%forward,%up);
%upHack = %pl.getUpVectorHack();

%proj_or[0] = 0.2 SPC %rightVec;
%proj_or[1] = -0.2 SPC %rightVec;
%proj_or[2] = 0.2 SPC %upHack;
%proj_or[3] = -0.2 SPC %upHack;

for(%i=0;%i<4;%i++)
{
%ang = getWord(%proj_or[%i],0);
%axis = getWords(%proj_or[%i],1,3);
%vec = vectorAngleRotate(%muzVec,%axis,%ang);
%p = new (%db.projectileType)()
{
dataBlock = %db.projectile;
initialVelocity = vectorScale(%vec,60);
initialPosition = %muzPoint;
sourceObject = %pl;
sourceSlot = %slot;
client = %pl.client;
};
MissionCleanup.add(%p);
}
}
function vectorAngleRotate(%vec,%axis,%ang)
{
%x = getWord(%vec,0);
%y = getWord(%vec,1);
%z = getWord(%vec,2);
%u = getWord(%axis,0);
%v = getWord(%axis,1);
%w = getWord(%axis,2);
%cos = mCos(%ang);
%sin = mSin(%ang);
return %u*(%u*%x+%v*%y+%w*%z)*(1-%cos)+%x*%cos+(%v*%z-%w*%y)*%sin SPC %u*(%u*%x+%v*%y+%w*%z)*(1-%cos)+%y*%cos+(%w*%x-%u*%z)*%sin SPC %u*(%u*%x+%v*%y+%w*%z)*(1-%cos)+%z*%cos+(%u*%y-%v*%x)*%sin;
}
function player::getUpVectorHack(%pl)
{
%muz = %pl.getMuzzleVector(0);
%forward = %pl.getForwardVector();
%up = %pl.getUpVector();
return vectorAngleRotate(%muz,vectorCross(%forward,%up),$PI/2);
}
heres a vector rotate function which amade did all the work for
input the base vector, the upwards orientation, and the angle

getUpVectorHack is a vector that actually represents the players eye point rotated 90 degrees upwards

the code for the gun fires 4 projectiles all rotated 0.2 radians to the left/right and up/down
« Last Edit: February 26, 2016, 12:05:40 PM by Swollow »

spherical bullet spread

Code: [Select]
function gunImage::onFire(%db,%pl,%slot)
{
%up = %pl.getUpVector();
%muzVec = %pl.getMuzzleVector(%slot);
%forward = %pl.getForwardVector();
%muzPoint = %pl.getMuzzlePoint(%slot);

%rightVec = vectorCross(%forward,%up);
%upHack = %pl.getUpVectorHack();

for(%i=0;%i<25;%i++)
{
%a = (getRandom()-0.5)*3.1415926*2;
%x = mCos(%a)*getRandom()*0.05;
%y = mSin(%a)*getRandom()*0.05;
%vec = vectorAngleRotate(vectorAngleRotate(%muzVec,%upHack,%x),%rightVec,%y);
%p = new (%db.projectileType)()
{
dataBlock = %db.projectile;
initialVelocity = vectorScale(%vec,60);
initialPosition = %muzPoint;
sourceObject = %pl;
sourceSlot = %slot;
client = %pl.client;
};
MissionCleanup.add(%p);
}
}

Two minor things to note:
  • Using %player.getUpVector() instead of "0 0 1" will ensure that the code works when the player is in a vehicle
  • Using %player.getMuzzleVector(%slot) instead of the eye vector will keep your gun from shooting sideways when the player turns their head

Two minor things to note:
  • Using %player.getUpVector() instead of "0 0 1" will ensure that the code works when the player is in a vehicle
  • Using %player.getMuzzleVector(%slot) instead of the eye vector will keep your gun from shooting sideways when the player turns their head
eck good point
fixed
« Last Edit: February 26, 2016, 10:34:36 AM by Swollow »