Remove vadd/vsub/vmul/vdiv
FossilOrigin-Name: 0c8fc2f1482a22d97a114b5b35f2a4d55d2d72a113178070d87fffab40fa8586
This commit is contained in:
parent
fa66ee85fd
commit
e91d88fd2b
6 changed files with 54 additions and 67 deletions
|
@ -288,13 +288,8 @@ extern bool demoplayback;
|
||||||
|
|
||||||
// simplistic vector ops
|
// simplistic vector ops
|
||||||
#define dotprod(u, v) ((u).x * (v).x + (u).y * (v).y + (u).z * (v).z)
|
#define dotprod(u, v) ((u).x * (v).x + (u).y * (v).y + (u).z * (v).z)
|
||||||
#define vmul(u, f) u = OFMultiplyVector3D(u, f)
|
|
||||||
#define vdiv(u, f) u = OFMultiplyVector3D(u, (f) / 1.0f)
|
|
||||||
#define vadd(u, v) u = OFAddVectors3D(u, v)
|
|
||||||
#define vsub(u, v) u = OFSubtractVectors3D(u, v)
|
|
||||||
#define vdist(d, v, e, s) \
|
#define vdist(d, v, e, s) \
|
||||||
OFVector3D v = s; \
|
OFVector3D v = OFSubtractVectors3D(s, e); \
|
||||||
vsub(v, e); \
|
|
||||||
float d = (float)sqrt(dotprod(v, v));
|
float d = (float)sqrt(dotprod(v, v));
|
||||||
#define vreject(v, u, max) \
|
#define vreject(v, u, max) \
|
||||||
((v).x > (u).x + (max) || (v).x < (u).x - (max) || \
|
((v).x > (u).x + (max) || (v).x < (u).x - (max) || \
|
||||||
|
|
|
@ -294,9 +294,9 @@ pickup(int n, DynamicEntity *d)
|
||||||
lastjumppad = lastmillis;
|
lastjumppad = lastmillis;
|
||||||
OFVector3D v = OFMakeVector3D((int)(char)ents[n].attr3 / 10.0f,
|
OFVector3D v = OFMakeVector3D((int)(char)ents[n].attr3 / 10.0f,
|
||||||
(int)(char)ents[n].attr2 / 10.0f, ents[n].attr1 / 10.0f);
|
(int)(char)ents[n].attr2 / 10.0f, ents[n].attr1 / 10.0f);
|
||||||
player1.velocity =
|
player1.velocity = OFAddVectors3D(
|
||||||
OFMakeVector3D(player1.velocity.x, player1.velocity.y, 0);
|
OFMakeVector3D(player1.velocity.x, player1.velocity.y, 0),
|
||||||
vadd(player1.velocity, v);
|
v);
|
||||||
playsoundc(S_JUMPPAD);
|
playsoundc(S_JUMPPAD);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -292,18 +292,19 @@ moveplayer4(DynamicEntity *pl, int moveres, bool local, int curtime)
|
||||||
|
|
||||||
// slowly apply friction and direction to
|
// slowly apply friction and direction to
|
||||||
// velocity, gives a smooth movement
|
// velocity, gives a smooth movement
|
||||||
vmul(pl.velocity, fpsfric - 1);
|
OFVector3D velocity = OFMultiplyVector3D(pl.velocity, fpsfric - 1);
|
||||||
vadd(pl.velocity, d);
|
velocity = OFAddVectors3D(velocity, d);
|
||||||
vdiv(pl.velocity, fpsfric);
|
velocity = OFMultiplyVector3D(velocity, 1.0f / fpsfric);
|
||||||
d = pl.velocity;
|
pl.velocity = velocity;
|
||||||
vmul(d, speed); // d is now frametime based velocity vector
|
// d is now frametime based velocity vector
|
||||||
|
d = OFMultiplyVector3D(velocity, speed);
|
||||||
|
|
||||||
pl.blocked = false;
|
pl.blocked = false;
|
||||||
pl.moving = true;
|
pl.moving = true;
|
||||||
|
|
||||||
if (floating) {
|
if (floating) {
|
||||||
// just apply velocity
|
// just apply velocity
|
||||||
vadd(pl.origin, d);
|
pl.origin = OFAddVectors3D(pl.origin, d);
|
||||||
if (pl.jumpNext) {
|
if (pl.jumpNext) {
|
||||||
pl.jumpNext = false;
|
pl.jumpNext = false;
|
||||||
pl.velocity =
|
pl.velocity =
|
||||||
|
|
|
@ -121,10 +121,9 @@ render_particles(int time)
|
||||||
if (pt->gr)
|
if (pt->gr)
|
||||||
p->o.z -= ((lastmillis - p->millis) / 3.0f) *
|
p->o.z -= ((lastmillis - p->millis) / 3.0f) *
|
||||||
curtime / (pt->gr * 10000);
|
curtime / (pt->gr * 10000);
|
||||||
OFVector3D a = p->d;
|
OFVector3D a = OFMultiplyVector3D(p->d, time);
|
||||||
vmul(a, time);
|
a = OFMultiplyVector3D(a, 1.0f / 20000.0f);
|
||||||
vdiv(a, 20000.0f);
|
p->o = OFAddVectors3D(p->o, a);
|
||||||
vadd(p->o, a);
|
|
||||||
pp = &p->next;
|
pp = &p->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,10 +153,10 @@ void
|
||||||
particle_trail(int type, int fade, const OFVector3D *s, const OFVector3D *e)
|
particle_trail(int type, int fade, const OFVector3D *s, const OFVector3D *e)
|
||||||
{
|
{
|
||||||
vdist(d, v, *s, *e);
|
vdist(d, v, *s, *e);
|
||||||
vdiv(v, d * 2 + 0.1f);
|
v = OFMultiplyVector3D(v, 1.0f / (d * 2 + 0.1f));
|
||||||
OFVector3D p = *s;
|
OFVector3D p = *s;
|
||||||
for (int i = 0; i < ((int)d * 2); i++) {
|
for (int i = 0; i < ((int)d * 2); i++) {
|
||||||
vadd(p, v);
|
p = OFAddVectors3D(p, v);
|
||||||
OFVector3D d =
|
OFVector3D d =
|
||||||
OFMakeVector3D(rnd(11) - 5, rnd(11) - 5, rnd(11) - 5);
|
OFMakeVector3D(rnd(11) - 5, rnd(11) - 5, rnd(11) - 5);
|
||||||
newparticle(&p, &d, rnd(fade) + fade, type);
|
newparticle(&p, &d, rnd(fade) + fade, type);
|
||||||
|
|
|
@ -390,26 +390,22 @@ VAR(demodelaymsec, 0, 120, 500);
|
||||||
// spline interpolation
|
// spline interpolation
|
||||||
#define catmulrom(z, a, b, c, s, dest) \
|
#define catmulrom(z, a, b, c, s, dest) \
|
||||||
{ \
|
{ \
|
||||||
OFVector3D t1 = b, t2 = c; \
|
OFVector3D t1 = OFSubtractVectors3D(b, z); \
|
||||||
|
t1 = OFMultiplyVector3D(t1, 0.5f); \
|
||||||
\
|
\
|
||||||
vsub(t1, z); \
|
OFVector3D t2 = OFSubtractVectors3D(c, a); \
|
||||||
vmul(t1, 0.5f); \
|
t2 = OFMultiplyVector3D(t2, 0.5f); \
|
||||||
vsub(t2, a); \
|
|
||||||
vmul(t2, 0.5f); \
|
|
||||||
\
|
\
|
||||||
float s2 = s * s; \
|
float s2 = s * s; \
|
||||||
float s3 = s * s2; \
|
float s3 = s * s2; \
|
||||||
\
|
\
|
||||||
dest = a; \
|
dest = OFMultiplyVector3D(a, 2 * s3 - 3 * s2 + 1); \
|
||||||
OFVector3D t = b; \
|
OFVector3D t = OFMultiplyVector3D(b, -2 * s3 + 3 * s2); \
|
||||||
\
|
dest = OFAddVectors3D(dest, t); \
|
||||||
vmul(dest, 2 * s3 - 3 * s2 + 1); \
|
t1 = OFMultiplyVector3D(t1, s3 - 2 * s2 + s); \
|
||||||
vmul(t, -2 * s3 + 3 * s2); \
|
dest = OFAddVectors3D(dest, t1); \
|
||||||
vadd(dest, t); \
|
t2 = OFMultiplyVector3D(t2, s3 - s2); \
|
||||||
vmul(t1, s3 - 2 * s2 + s); \
|
dest = OFAddVectors3D(dest, t2); \
|
||||||
vadd(dest, t1); \
|
|
||||||
vmul(t2, s3 - s2); \
|
|
||||||
vadd(dest, t2); \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
42
src/weapon.m
42
src/weapon.m
|
@ -77,12 +77,9 @@ createrays(const OFVector3D *from, const OFVector3D *to)
|
||||||
{
|
{
|
||||||
vdist(dist, dvec, *from, *to);
|
vdist(dist, dvec, *from, *to);
|
||||||
float f = dist * SGSPREAD / 1000;
|
float f = dist * SGSPREAD / 1000;
|
||||||
for (int i = 0; i < SGRAYS; i++) {
|
for (int i = 0; i < SGRAYS; i++)
|
||||||
#define RNDD (rnd(101) - 50) * f
|
#define RNDD (rnd(101) - 50) * f
|
||||||
OFVector3D r = OFMakeVector3D(RNDD, RNDD, RNDD);
|
sg[i] = OFAddVectors3D(*to, OFMakeVector3D(RNDD, RNDD, RNDD));
|
||||||
sg[i] = *to;
|
|
||||||
vadd(sg[i], r);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if lineseg hits entity bounding box
|
// if lineseg hits entity bounding box
|
||||||
|
@ -91,8 +88,8 @@ intersect(DynamicEntity *d, const OFVector3D *from, const OFVector3D *to)
|
||||||
{
|
{
|
||||||
OFVector3D v = *to, w = d.origin;
|
OFVector3D v = *to, w = d.origin;
|
||||||
const OFVector3D *p;
|
const OFVector3D *p;
|
||||||
vsub(v, *from);
|
v = OFSubtractVectors3D(v, *from);
|
||||||
vsub(w, *from);
|
w = OFSubtractVectors3D(w, *from);
|
||||||
float c1 = dotprod(w, v);
|
float c1 = dotprod(w, v);
|
||||||
|
|
||||||
if (c1 <= 0)
|
if (c1 <= 0)
|
||||||
|
@ -102,9 +99,8 @@ intersect(DynamicEntity *d, const OFVector3D *from, const OFVector3D *to)
|
||||||
if (c2 <= c1)
|
if (c2 <= c1)
|
||||||
p = to;
|
p = to;
|
||||||
else {
|
else {
|
||||||
float f = c1 / c2;
|
v = OFMultiplyVector3D(v, c1 / c2);
|
||||||
vmul(v, f);
|
v = OFAddVectors3D(v, *from);
|
||||||
vadd(v, *from);
|
|
||||||
p = &v;
|
p = &v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,8 +195,9 @@ radialeffect(
|
||||||
dist = 0;
|
dist = 0;
|
||||||
int damage = (int)(qdam * (1 - (dist / RL_DAMRAD)));
|
int damage = (int)(qdam * (1 - (dist / RL_DAMRAD)));
|
||||||
hit(cn, damage, o, at);
|
hit(cn, damage, o, at);
|
||||||
vmul(temp, (RL_DAMRAD - dist) * damage / 800);
|
temp =
|
||||||
vadd(o.velocity, temp);
|
OFMultiplyVector3D(temp, (RL_DAMRAD - dist) * damage / 800);
|
||||||
|
o.velocity = OFAddVectors3D(o.velocity, temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,8 +270,8 @@ moveprojectiles(float time)
|
||||||
float dtime = dist * 1000 / p.speed;
|
float dtime = dist * 1000 / p.speed;
|
||||||
if (time > dtime)
|
if (time > dtime)
|
||||||
dtime = time;
|
dtime = time;
|
||||||
vmul(v, time / dtime);
|
v = OFMultiplyVector3D(v, time / dtime);
|
||||||
vadd(v, p.o);
|
v = OFAddVectors3D(v, p.o);
|
||||||
if (p.local) {
|
if (p.local) {
|
||||||
for (id player in players)
|
for (id player in players)
|
||||||
if (player != [OFNull null])
|
if (player != [OFNull null])
|
||||||
|
@ -354,8 +351,8 @@ hitpush(int target, int damage, DynamicEntity *d, DynamicEntity *at,
|
||||||
{
|
{
|
||||||
hit(target, damage, d, at);
|
hit(target, damage, d, at);
|
||||||
vdist(dist, v, *from, *to);
|
vdist(dist, v, *from, *to);
|
||||||
vmul(v, damage / dist / 50);
|
v = OFMultiplyVector3D(v, damage / dist / 50);
|
||||||
vadd(d.velocity, v);
|
d.velocity = OFAddVectors3D(d.velocity, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -404,17 +401,16 @@ shoot(DynamicEntity *d, const OFVector3D *targ)
|
||||||
from.z -= 0.2f; // below eye
|
from.z -= 0.2f; // below eye
|
||||||
|
|
||||||
vdist(dist, unitv, from, to);
|
vdist(dist, unitv, from, to);
|
||||||
vdiv(unitv, dist);
|
unitv = OFMultiplyVector3D(unitv, 1.0f / dist);
|
||||||
OFVector3D kickback = unitv;
|
OFVector3D kickback =
|
||||||
vmul(kickback, guns[d.gunSelect].kickamount * -0.01f);
|
OFMultiplyVector3D(unitv, guns[d.gunSelect].kickamount * -0.01f);
|
||||||
vadd(d.velocity, kickback);
|
d.velocity = OFAddVectors3D(d.velocity, kickback);
|
||||||
if (d.pitch < 80.0f)
|
if (d.pitch < 80.0f)
|
||||||
d.pitch += guns[d.gunSelect].kickamount * 0.05f;
|
d.pitch += guns[d.gunSelect].kickamount * 0.05f;
|
||||||
|
|
||||||
if (d.gunSelect == GUN_FIST || d.gunSelect == GUN_BITE) {
|
if (d.gunSelect == GUN_FIST || d.gunSelect == GUN_BITE) {
|
||||||
vmul(unitv, 3); // punch range
|
unitv = OFMultiplyVector3D(unitv, 3); // punch range
|
||||||
to = from;
|
to = OFAddVectors3D(from, unitv);
|
||||||
vadd(to, unitv);
|
|
||||||
}
|
}
|
||||||
if (d.gunSelect == GUN_SG)
|
if (d.gunSelect == GUN_SG)
|
||||||
createrays(&from, &to);
|
createrays(&from, &to);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue