Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 68 additions & 81 deletions src/common/mathlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,34 @@
****/
// mathlib.h

#ifdef __cplusplus
extern "C"
{
#endif
typedef float vec_t;
typedef vec_t vec3_t[3];
typedef vec_t vec4_t[4]; // x,y,z,w
typedef vec_t vec5_t[5];
#pragma once

#include <cmath>
#include "hl/vector.h"

typedef float vec_t;
typedef vec_t vec4_t[4]; // x,y,z,w
typedef vec_t vec5_t[5];

typedef short vec_s_t;
typedef vec_s_t vec3s_t[3];
typedef vec_s_t vec4s_t[4]; // x,y,z,w
typedef vec_s_t vec5s_t[5];
typedef short vec_s_t;
typedef vec_s_t vec3s_t[3];
typedef vec_s_t vec4s_t[4]; // x,y,z,w
typedef vec_s_t vec5s_t[5];

typedef int fixed4_t;
typedef int fixed8_t;
typedef int fixed16_t;
typedef int fixed4_t;
typedef int fixed8_t;
typedef int fixed16_t;

#ifndef M_PI
#define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h
#endif

struct mplane_s;
struct mplane_s;

extern vec3_t vec3_origin;
extern int nanmask;
extern Vector vec3_origin;
extern int nanmask;

#define IS_NAN(x) (((*(int *)&x) & nanmask) == nanmask)

#ifndef VECTOR_H
#define DotProduct(x, y) ((x)[0] * (y)[0] + (x)[1] * (y)[1] + (x)[2] * (y)[2])
#endif
#define IS_NAN(x) (((*(int*)&x) & nanmask) == nanmask)

#define VectorSubtract(a, b, c) \
{ \
Expand All @@ -65,43 +61,63 @@ extern "C"
(b)[1] = (a)[1]; \
(b)[2] = (a)[2]; \
}
#define VectorClear(a) \
{ \
(a)[0] = 0.0; \
(a)[1] = 0.0; \
(a)[2] = 0.0; \
}
inline void VectorClear(float* a)
{
a[0] = 0.0;
a[1] = 0.0;
a[2] = 0.0;
}

void VectorMA(const float* veca, float scale, const float* vecb, float* vecc);

void VectorMA(const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc);
bool VectorCompare(const float* v1, const float* v2);
float Length(const float* v);
void CrossProduct(const float* v1, const float* v2, float* cross);
float VectorNormalize(float* v); // returns vector length
void VectorInverse(float* v);
void VectorScale(const float* in, float scale, float* out);
int Q_log2(int val);

vec_t _DotProduct(vec3_t v1, vec3_t v2);
void _VectorSubtract(vec3_t veca, vec3_t vecb, vec3_t out);
void _VectorAdd(vec3_t veca, vec3_t vecb, vec3_t out);
void _VectorCopy(vec3_t in, vec3_t out);
void R_ConcatRotations(float in1[3][3], float in2[3][3], float out[3][3]);
void R_ConcatTransforms(float in1[3][4], float in2[3][4], float out[3][4]);

int VectorCompare(const vec3_t v1, const vec3_t v2);
float Length(const vec3_t v);
void CrossProduct(const vec3_t v1, const vec3_t v2, vec3_t cross);
float VectorNormalize(vec3_t v); // returns vector length
void VectorInverse(vec3_t v);
void VectorScale(const vec3_t in, vec_t scale, vec3_t out);
int Q_log2(int val);
void FloorDivMod(double numer, double denom, int* quotient, int* rem);
fixed16_t Invert24To16(fixed16_t val);
int GreatestCommonDivisor(int i1, int i2);

void R_ConcatRotations(float in1[3][3], float in2[3][3], float out[3][3]);
void R_ConcatTransforms(float in1[3][4], float in2[3][4], float out[3][4]);
void AngleVectors(const Vector& angles, Vector* forward, Vector* right, Vector* up);
void AngleVectorsTranspose(const Vector& angles, Vector* forward, Vector* right, Vector* up);
#define AngleIVectors AngleVectorsTranspose

// Here are some "manual" INLINE routines for doing floating point to integer conversions
extern short new_cw, old_cw;
void AngleMatrix(const float* angles, float (*matrix)[4]);
void AngleIMatrix(const Vector& angles, float (*matrix)[4]);
void VectorTransform(const float* in1, float in2[3][4], float* out);

typedef union DLONG
{
int i[2];
double d;
float f;
} DLONG;
void NormalizeAngles(float* angles);
void InterpolateAngles(float* start, float* end, float* output, float frac);
float AngleBetweenVectors(const float* v1, const float* v2);

void VectorMatrix(const Vector& forward, Vector& right, Vector& up);
void VectorAngles(const float* forward, float* angles);

int InvertMatrix(const float* m, float* out);

int BoxOnPlaneSide(const Vector& emins, const Vector& emaxs, struct mplane_s* plane);
float anglemod(float a);

extern DLONG dlong;
// Here are some "manual" INLINE routines for doing floating point to integer conversions
extern short new_cw, old_cw;

typedef union DLONG
{
int i[2];
double d;
float f;
} DLONG;

extern DLONG dlong;

// wtf is even going on here??
#ifdef _WIN32
void __inline set_fpu_cw(void)
{
Expand Down Expand Up @@ -134,35 +150,6 @@ extern "C"
#define set_fpu_cw() /* */
#define quick_ftol(f) ftol(f)
#define restore_fpu_cw() /* */
#endif

void FloorDivMod(double numer, double denom, int *quotient,
int *rem);
fixed16_t Invert24To16(fixed16_t val);
int GreatestCommonDivisor(int i1, int i2);

void AngleVectors(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
void AngleVectorsTranspose(const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
#define AngleIVectors AngleVectorsTranspose

void AngleMatrix(const vec3_t angles, float (*matrix)[4]);
void AngleIMatrix(const vec3_t angles, float (*matrix)[4]);
void VectorTransform(const vec3_t in1, float in2[3][4], vec3_t out);

void NormalizeAngles(vec3_t angles);
void InterpolateAngles(vec3_t start, vec3_t end, vec3_t output, float frac);
float AngleBetweenVectors(const vec3_t v1, const vec3_t v2);

void VectorMatrix(vec3_t forward, vec3_t right, vec3_t up);
void VectorAngles(const vec3_t forward, vec3_t angles);

int InvertMatrix(const float *m, float *out);

int BoxOnPlaneSide(vec3_t emins, vec3_t emaxs, struct mplane_s *plane);
float anglemod(float a);

#ifdef __cplusplus
}
#endif

#define BOX_ON_PLANE_SIDE(emins, emaxs, p) \
Expand Down
1 change: 1 addition & 0 deletions src/game/client/angelscript/ASClientBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// Master Sword includes
#include "mslogger.h"
#include "sharedutil.h"
#include <mathlib.h>

// External client globals
extern cl_enginefunc_t gEngfuncs;
Expand Down
31 changes: 1 addition & 30 deletions src/game/client/cl_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ inline struct cvar_s *CVAR_CREATE(const char *cv, const char *val, const int fla
#define ServerCmd (*gEngfuncs.pfnServerCmd)
#define ClientCmd (*gEngfuncs.pfnClientCmd)
#define SetCrosshair (*gEngfuncs.pfnSetCrosshair)
#define AngleVectors (*gEngfuncs.pfnAngleVectors)
//#define AngleVectors (*gEngfuncs.pfnAngleVectors)

// Gets the height & width of a sprite, at the specified frame
inline int SPR_Height(HLSPRITE x, int f) { return gEngfuncs.pfnSPR_Height(x, f); }
Expand Down Expand Up @@ -155,35 +155,6 @@ inline void PlayHUDSound(const char *Sound, float vol) { PlaySound((char *)Sound
void ScaleColors(int &r, int &g, int &b, int a);

#define DotProduct(x, y) ((x)[0] * (y)[0] + (x)[1] * (y)[1] + (x)[2] * (y)[2])
#define VectorSubtract(a, b, c) \
{ \
(c)[0] = (a)[0] - (b)[0]; \
(c)[1] = (a)[1] - (b)[1]; \
(c)[2] = (a)[2] - (b)[2]; \
}
#define VectorAdd(a, b, c) \
{ \
(c)[0] = (a)[0] + (b)[0]; \
(c)[1] = (a)[1] + (b)[1]; \
(c)[2] = (a)[2] + (b)[2]; \
}
#define VectorCopy(a, b) \
{ \
(b)[0] = (a)[0]; \
(b)[1] = (a)[1]; \
(b)[2] = (a)[2]; \
}
inline void VectorClear(float *a)
{
a[0] = 0.0;
a[1] = 0.0;
a[2] = 0.0;
}
float Length(const float *v);
void VectorMA(const float *veca, float scale, const float *vecb, float *vecc);
void VectorScale(const float *in, float scale, float *out);
float VectorNormalize(float *v);
void VectorInverse(float *v);

// ugh, some bits of the client code expect a float[3] while others expect a Vector, and there's a macro that pretends they're the same
// handle the extern with the correct types in the places where it's required
Expand Down
1 change: 1 addition & 0 deletions src/game/client/entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "ms/hudscript.h"
#include "ms/clglobal.h"
#include "script.h"
#include <mathlib.h>

#undef DLLEXPORT //Master Sword
#define DLLEXPORT EXPORT
Expand Down
1 change: 1 addition & 0 deletions src/game/client/ev_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "eventscripts.h"
#include "event_api.h"
#include "mathlib.h"

/*
=================
Expand Down
25 changes: 12 additions & 13 deletions src/game/client/ev_hldm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@
#include "event_api.h"
#include "event_args.h"
#include "in_defs.h"
#include "mathlib.h"

#include <string.h>

extern "C" float* vec3_origin;

static int tracerCount[32];

void V_PunchAxis(int axis, float punch);
Expand Down Expand Up @@ -474,7 +473,7 @@ void EV_FireGlock1(event_args_t *args)
VectorCopy(args->velocity, velocity);

empty = args->bparam1;
AngleVectors(angles, forward, right, up);
AngleVectors(angles, &forward, &right, &up);

shell = gEngfuncs.pEventAPI->EV_FindModelIndex("models/shell.mdl"); // brass shell

Expand Down Expand Up @@ -528,7 +527,7 @@ void EV_FireGlock2(event_args_t *args)
VectorCopy(args->angles, angles);
VectorCopy(args->velocity, velocity);

AngleVectors(angles, forward, right, up);
AngleVectors(angles, &forward, &right, &up);

shell = gEngfuncs.pEventAPI->EV_FindModelIndex("models/shell.mdl"); // brass shell

Expand Down Expand Up @@ -583,7 +582,7 @@ void EV_FireShotGunDouble(event_args_t *args)
VectorCopy(args->angles, angles);
VectorCopy(args->velocity, velocity);

AngleVectors(angles, forward, right, up);
AngleVectors(angles, &forward, &right, &up);

shell = gEngfuncs.pEventAPI->EV_FindModelIndex("models/shotgunshell.mdl"); // brass shell

Expand Down Expand Up @@ -649,7 +648,7 @@ void EV_FireShotGunSingle(event_args_t *args)
VectorCopy(args->angles, angles);
VectorCopy(args->velocity, velocity);

AngleVectors(angles, forward, right, up);
AngleVectors(angles, &forward, &right, &up);

shell = gEngfuncs.pEventAPI->EV_FindModelIndex("models/shotgunshell.mdl"); // brass shell

Expand Down Expand Up @@ -710,7 +709,7 @@ void EV_FireMP5(event_args_t *args)
VectorCopy(args->angles, angles);
VectorCopy(args->velocity, velocity);

AngleVectors(angles, forward, right, up);
AngleVectors(angles, &forward, &right, &up);

shell = gEngfuncs.pEventAPI->EV_FindModelIndex("models/shell.mdl"); // brass shell

Expand Down Expand Up @@ -769,7 +768,7 @@ void EV_FirePython(event_args_t *args)
VectorCopy(args->angles, angles);
VectorCopy(args->velocity, velocity);

AngleVectors(angles, forward, right, up);
AngleVectors(angles, &forward, &right, &up);

if (EV_IsLocal(idx))
{
Expand Down Expand Up @@ -866,7 +865,7 @@ void EV_FireGauss(event_args_t *args)
m_iBeam = gEngfuncs.pEventAPI->EV_FindModelIndex("sprites/smoke.spr");
m_iBalls = m_iGlow = gEngfuncs.pEventAPI->EV_FindModelIndex("sprites/hotglow.spr");

AngleVectors(angles, forward, right, up);
AngleVectors(angles, &forward, &right, &up);

VectorMA(vecSrc, 8192, forward, vecDest);

Expand Down Expand Up @@ -968,7 +967,7 @@ void EV_FireGauss(event_args_t *args)
VectorMA(tr.endpos, 8.0, forward, vecSrc);
VectorMA(vecSrc, 8192.0, forward, vecDest);

gEngfuncs.pEfxAPI->R_TempSprite(tr.endpos, vec3_origin, 0.2, m_iGlow, kRenderGlow, kRenderFxNoDissipation, flDamage * n / 255.0, flDamage * n * 0.5 * 0.1, FTENT_FADEOUT);
gEngfuncs.pEfxAPI->R_TempSprite(tr.endpos, Vector(0,0,0), 0.2, m_iGlow, kRenderGlow, kRenderFxNoDissipation, flDamage * n / 255.0, flDamage * n * 0.5 * 0.1, FTENT_FADEOUT);

{
vec3_t fwd;
Expand All @@ -990,7 +989,7 @@ void EV_FireGauss(event_args_t *args)
// tunnel
EV_HLDM_DecalGunshot(&tr, BULLET_MONSTER_12MM);

gEngfuncs.pEfxAPI->R_TempSprite(tr.endpos, vec3_origin, 1.0, m_iGlow, kRenderGlow, kRenderFxNoDissipation, flDamage / 255.0, 6.0, FTENT_FADEOUT);
gEngfuncs.pEfxAPI->R_TempSprite(tr.endpos, Vector(0,0,0), 1.0, m_iGlow, kRenderGlow, kRenderFxNoDissipation, flDamage / 255.0, 6.0, FTENT_FADEOUT);

// limit it to one hole punch
if (fHasPunched)
Expand Down Expand Up @@ -1047,7 +1046,7 @@ void EV_FireGauss(event_args_t *args)

EV_HLDM_DecalGunshot(&beam_tr, BULLET_MONSTER_12MM);

gEngfuncs.pEfxAPI->R_TempSprite(beam_tr.endpos, vec3_origin, 0.1, m_iGlow, kRenderGlow, kRenderFxNoDissipation, flDamage / 255.0, 6.0, FTENT_FADEOUT);
gEngfuncs.pEfxAPI->R_TempSprite(beam_tr.endpos, Vector(0,0,0), 0.1, m_iGlow, kRenderGlow, kRenderFxNoDissipation, flDamage / 255.0, 6.0, FTENT_FADEOUT);

// balls
{
Expand All @@ -1073,7 +1072,7 @@ void EV_FireGauss(event_args_t *args)
{
// slug doesn't punch through ever with primary
// fire, so leave a little glowy bit and make some balls
gEngfuncs.pEfxAPI->R_TempSprite(tr.endpos, vec3_origin, 0.2, m_iGlow, kRenderGlow, kRenderFxNoDissipation, 200.0 / 255.0, 0.3, FTENT_FADEOUT);
gEngfuncs.pEfxAPI->R_TempSprite(tr.endpos, Vector(0,0,0), 0.2, m_iGlow, kRenderGlow, kRenderFxNoDissipation, 200.0 / 255.0, 0.3, FTENT_FADEOUT);

{
vec3_t fwd;
Expand Down
Loading