Bowcaster bolt direction fix (@MuadDib)

This commit is contained in:
Simon 2022-11-26 18:09:24 +00:00
parent 693dbc210c
commit bec2177392
3 changed files with 29 additions and 1 deletions

View file

@ -28,6 +28,8 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
#include "g_functions.h"
#include "bg_local.h"
#include <JKVR/VrClientInfo.h>
//-------------------
// Wookiee Bowcaster
//-------------------
@ -111,7 +113,10 @@ static void WP_BowcasterMainFire( gentity_t *ent )
AngleVectors( angs, dir, NULL, NULL );
missile = CreateMissile( start, dir, vel, 10000, ent );
vec3_t rotatedDir;
VectorRotateAroundAxis(dir, forward, vr->weaponangles[ROLL], rotatedDir);
missile = CreateMissile( start, rotatedDir, vel, 10000, ent );
missile->classname = "bowcaster_proj";
missile->s.weapon = WP_BOWCASTER;

View file

@ -1302,6 +1302,28 @@ float DistanceHorizontalSquared( const vec3_t p1, const vec3_t p2 )
return v[0]*v[0] + v[1]*v[1]; //Leave off the z component
}
void VectorRotateAroundAxis( vec3_t in, vec3_t axis, float angle, vec3_t out ) {
// https://stackoverflow.com/a/67468546
vec3_t normAxis;
VectorNormalize2(axis, normAxis);
float dotProduct = DotProduct(normAxis, in);
vec3_t crossProduct;
CrossProduct(normAxis, in, crossProduct);
float angleRad = DEG2RAD(angle);
float cosA = cosf(angleRad);
float sinA = sinf(angleRad);
vec3_t tmp1;
VectorScale( in, cosA, tmp1 );
vec3_t tmp2;
VectorScale(crossProduct, sinA, tmp2);
vec3_t tmp3;
VectorScale(normAxis, dotProduct * (1 - cosA), tmp3);
VectorAdd(tmp1, tmp2, out);
VectorAdd(out, tmp3, out);
}
/*
================
MakeNormalVectors

View file

@ -276,6 +276,7 @@ void VectorRotate( const vec3_t in, matrix3_t matrix, vec3_t out );
void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
void PerpendicularVector( vec3_t dst, const vec3_t src );
float DotProductNormalize( const vec3_t inVec1, const vec3_t inVec2 );
void VectorRotateAroundAxis( vec3_t vector, vec3_t axis, float angle, vec3_t out );
#define VectorScaleVector(a,b,c) (((c)[0]=(a)[0]*(b)[0]),((c)[1]=(a)[1]*(b)[1]),((c)[2]=(a)[2]*(b)[2]))
#define VectorInverseScaleVector(a,b,c) ((c)[0]=(a)[0]/(b)[0],(c)[1]=(a)[1]/(b)[1],(c)[2]=(a)[2]/(b)[2])