- Replaced the vector math routines with the ones I developed for the FP code.

SVN r454 (trunk)
This commit is contained in:
Randy Heit 2007-01-19 02:00:39 +00:00
parent f0f976c4f5
commit 47c401f4ec
20 changed files with 2279 additions and 1395 deletions

View file

@ -1,3 +1,6 @@
January 18, 2007
- Replaced the vector math routines with the ones I developed for the FP code.
January 15, 2007
- Added a summonfoe CCMD, which is analagous to summonfriend but forces the
summoned creature to be hostile instead.

View file

@ -482,13 +482,13 @@ fixed_t DCajunMaster::FakeFire (AActor *source, AActor *dest, ticcmd_t *cmd)
th->target = source; // where it came from
vec3_t velocity;
float speed = (float)th->Speed;
FVector3 velocity;
velocity[0] = FIXED2FLOAT(dest->x - source->x);
velocity[1] = FIXED2FLOAT(dest->y - source->y);
velocity[2] = FIXED2FLOAT(dest->z - source->z);
VectorNormalize (velocity);
velocity.MakeUnit();
th->momx = FLOAT2FIXED(velocity[0] * speed);
th->momy = FLOAT2FIXED(velocity[1] * speed);
th->momz = FLOAT2FIXED(velocity[2] * speed);

View file

@ -3,7 +3,7 @@
**
**
**---------------------------------------------------------------------------
** Copyright 1998-2006 Randy Heit
** Copyright 1998-2007 Randy Heit
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without

View file

@ -148,18 +148,18 @@ END_DEFAULTS
int ALoreShot::DoSpecialDamage (AActor *target, int damage)
{
vec3_t thrust;
FVector3 thrust;
thrust[0] = float(this->target->x - target->x);
thrust[1] = float(this->target->y - target->y);
thrust[2] = float(this->target->z - target->z);
thrust.X = float(this->target->x - target->x);
thrust.Y = float(this->target->y - target->y);
thrust.Z = float(this->target->z - target->z);
VectorNormalize (thrust);
VectorScale (thrust, float((255*50*FRACUNIT) / (target->Mass ? target->Mass : 1)), thrust);
thrust.MakeUnit();
thrust *= float((255*50*FRACUNIT) / (target->Mass ? target->Mass : 1));
target->momx += fixed_t(thrust[0]);
target->momy += fixed_t(thrust[1]);
target->momz += fixed_t(thrust[2]);
target->momx += fixed_t(thrust.X);
target->momy += fixed_t(thrust.Y);
target->momz += fixed_t(thrust.Z);
return damage;
}

View file

@ -233,7 +233,7 @@ DWORD FNodeBuilder::AddMiniseg (int v1, int v2, DWORD partner, DWORD seg1, DWORD
newseg.next = DWORD_MAX;
newseg.planefront = true;
newseg.hashnext = NULL;
newseg.storedseg = NULL;
newseg.storedseg = DWORD_MAX;
newseg.frontsector = NULL;
newseg.backsector = NULL;

View file

@ -692,7 +692,7 @@ static void CreateStartSpot (fixed_t *pos, mapthing2_t *start)
static void CalcPlane (SlopeWork &slope, secplane_t &plane)
{
vec3_t pt[3];
FVector3 pt[3];
long j;
slope.x[0] = slope.wal->x; slope.y[0] = slope.wal->y;
@ -711,23 +711,13 @@ static void CalcPlane (SlopeWork &slope, secplane_t &plane)
-slope.dy, slope.x[2]-slope.wal->x);
slope.z[2] += Scale (slope.heinum, j, slope.i);
pt[0][0] = float(slope.dx);
pt[0][1] = float(-slope.dy);
pt[0][2] = 0.f;
pt[0] = FVector3(slope.dx, -slope.dy, 0);
pt[1] = FVector3(slope.x[2] - slope.x[0], slope.y[0] - slope.y[2], (slope.z[2] - slope.z[0]) / 16);
pt[2] = (pt[0] ^ pt[1]).Unit();
pt[1][0] = float(slope.x[2] - slope.x[0]);
pt[1][1] = float(slope.y[0] - slope.y[2]);
pt[1][2] = float(slope.z[2] - slope.z[0]) / 16.f;
CrossProduct (pt[0], pt[1], pt[2]);
VectorNormalize (pt[2]);
if ((pt[2][2] < 0 && plane.c > 0) ||
(pt[2][2] > 0 && plane.c < 0))
if ((pt[2][2] < 0 && plane.c > 0) || (pt[2][2] > 0 && plane.c < 0))
{
pt[2][0] = -pt[2][0];
pt[2][1] = -pt[2][1];
pt[2][2] = -pt[2][2];
pt[2] = -pt[2];
}
plane.a = fixed_t(pt[2][0]*65536.f);

View file

@ -423,21 +423,20 @@ void P_DrawSplash2 (int count, fixed_t x, fixed_t y, fixed_t z, angle_t angle, i
}
}
void P_DrawRailTrail (AActor * source, vec3_t start, vec3_t end, int color1, int color2, float maxdiff, bool silent)
void P_DrawRailTrail (AActor *source, const FVector3 &start, const FVector3 &end, int color1, int color2, float maxdiff, bool silent)
{
float length;
double length, lengthsquared;
int steps, i;
float deg;
vec3_t step, dir, pos, extend;
FAngle deg;
FVector3 step, dir, pos, extend;
VectorSubtract (end, start, dir);
length = VectorLength (dir);
steps = (int)(length*0.3333f);
dir = end - start;
lengthsquared = dir | dir;
length = sqrt(lengthsquared);
steps = int(length / 3);
if (length)
if (steps)
{
length = 1 / length;
if (!silent)
{
int sound;
@ -451,27 +450,27 @@ void P_DrawRailTrail (AActor * source, vec3_t start, vec3_t end, int color1, int
// The railgun's sound is special. It gets played from the
// point on the slug's trail that is closest to the hearing player.
AActor *mo = players[consoleplayer].camera;
vec3_t point;
float r;
FVector3 point;
double r;
float dirz;
if (abs(mo->x - FLOAT2FIXED(start[0])) < 20 * FRACUNIT
&& (mo->y - FLOAT2FIXED(start[1])) < 20 * FRACUNIT)
if (abs(mo->x - FLOAT2FIXED(start.X)) < 20 * FRACUNIT
&& (mo->y - FLOAT2FIXED(start.Y)) < 20 * FRACUNIT)
{ // This player (probably) fired the railgun
S_SoundID (mo, CHAN_WEAPON, sound, 1, ATTN_NORM);
}
else
{
// Only consider sound in 2D (for now, anyway)
r = ((start[1] - FIXED2FLOAT(mo->y)) * (-dir[1]) -
(start[0] - FIXED2FLOAT(mo->x)) * (dir[0])) * length * length;
r = ((start.Y - FIXED2FLOAT(mo->y)) * (-dir.Y) -
(start.X - FIXED2FLOAT(mo->x)) * (dir.X)) * length * length;
dirz = dir[2];
dir[2] = 0;
VectorMA (start, r, dir, point);
dir[2] = dirz;
dirz = dir.Z;
dir.Z = 0;
point = start + r * dir;
dir.Z = dirz;
S_SoundID (FLOAT2FIXED(point[0]), FLOAT2FIXED(point[1]), mo->z,
S_SoundID (FLOAT2FIXED(point.X), FLOAT2FIXED(point.Y), mo->z,
CHAN_WEAPON, sound, 1, ATTN_NORM);
}
}
@ -482,20 +481,37 @@ void P_DrawRailTrail (AActor * source, vec3_t start, vec3_t end, int color1, int
return;
}
VectorScale2 (dir, length);
PerpendicularVector (extend, dir);
VectorScale2 (extend, 3);
VectorScale (dir, 3, step);
dir /= length;
//Calculate PerpendicularVector (extend, dir):
double minelem = 1;
int epos;
for (epos = 0, i = 0; i < 3; ++i)
{
if (fabs(dir[i]) < minelem)
{
epos = i;
minelem = fabs(dir[i]);
}
}
FVector3 tempvec(0,0,0);
tempvec[epos] = 1;
extend = tempvec - (dir | tempvec) * dir;
//
extend *= 3;
step = dir * 3;
// Create the outer spiral.
if (color1 != -1)
{
color1 = color1==0? -1: ColorMatcher.Pick(RPART(color1), GPART(color1), BPART(color1));
VectorCopy (start, pos);
deg = 270;
color1 = color1 == 0 ? -1 : ColorMatcher.Pick(RPART(color1), GPART(color1), BPART(color1));
pos = start;
deg = FAngle(270);
for (i = steps; i; i--)
{
particle_t *p = NewParticle ();
vec3_t tempvec;
FVector3 tempvec;
if (!p)
return;
@ -505,20 +521,18 @@ void P_DrawRailTrail (AActor * source, vec3_t start, vec3_t end, int color1, int
p->fade = FADEFROMTTL(35);
p->size = 3;
RotatePointAroundVector (tempvec, dir, extend, deg);
p->velx = FLOAT2FIXED(tempvec[0])>>4;
p->vely = FLOAT2FIXED(tempvec[1])>>4;
p->velz = FLOAT2FIXED(tempvec[2])>>4;
VectorAdd (tempvec, pos, tempvec);
deg += 14;
if (deg >= 360)
deg -= 360;
p->x = FLOAT2FIXED(tempvec[0]);
p->y = FLOAT2FIXED(tempvec[1]);
p->z = FLOAT2FIXED(tempvec[2]);
VectorAdd (pos, step, pos);
tempvec = FMatrix3x3(dir, deg) * extend;
p->velx = FLOAT2FIXED(tempvec.X)>>4;
p->vely = FLOAT2FIXED(tempvec.Y)>>4;
p->velz = FLOAT2FIXED(tempvec.Z)>>4;
tempvec += pos;
p->x = FLOAT2FIXED(tempvec.X);
p->y = FLOAT2FIXED(tempvec.Y);
p->z = FLOAT2FIXED(tempvec.Z);
pos += step;
deg += FAngle(14);
if (color1==-1)
if (color1 == -1)
{
int rand = M_Random();
@ -538,13 +552,13 @@ void P_DrawRailTrail (AActor * source, vec3_t start, vec3_t end, int color1, int
}
}
// Create the inner trail.
if (color2 != -1)
{
color2 = color2==0? -1: ColorMatcher.Pick(RPART(color2), GPART(color2), BPART(color2));
vec3_t diff;
VectorSet (diff, 0, 0, 0);
color2 = color2 == 0 ? -1 : ColorMatcher.Pick(RPART(color2), GPART(color2), BPART(color2));
FVector3 diff(0, 0, 0);
VectorCopy (start, pos);
pos = start;
for (i = steps; i; i--)
{
particle_t *p = JitterParticle (33);
@ -556,27 +570,24 @@ void P_DrawRailTrail (AActor * source, vec3_t start, vec3_t end, int color1, int
{
int rnd = M_Random ();
if (rnd & 1)
diff[0] = clamp<float> (diff[0] + ((rnd & 8) ? 1 : -1), -maxdiff, maxdiff);
diff.X = clamp<float> (diff.X + ((rnd & 8) ? 1 : -1), -maxdiff, maxdiff);
if (rnd & 2)
diff[1] = clamp<float> (diff[1] + ((rnd & 16) ? 1 : -1), -maxdiff, maxdiff);
diff.Y = clamp<float> (diff.Y + ((rnd & 16) ? 1 : -1), -maxdiff, maxdiff);
if (rnd & 4)
diff[2] = clamp<float> (diff[2] + ((rnd & 32) ? 1 : -1), -maxdiff, maxdiff);
diff.Z = clamp<float> (diff.Z + ((rnd & 32) ? 1 : -1), -maxdiff, maxdiff);
}
vec3_t postmp;
VectorCopy (pos, postmp);
VectorAdd (postmp, diff, postmp);
FVector3 postmp = pos + diff;
p->size = 2;
p->x = FLOAT2FIXED(postmp[0]);
p->y = FLOAT2FIXED(postmp[1]);
p->z = FLOAT2FIXED(postmp[2]);
p->x = FLOAT2FIXED(postmp.X);
p->y = FLOAT2FIXED(postmp.Y);
p->z = FLOAT2FIXED(postmp.Z);
if (color1 != -1)
p->accz -= FRACUNIT/4096;
VectorAdd (pos, step, pos);
pos += step;
if (color2==-1)
{
if (color2 == -1)
{
int rand = M_Random();
@ -587,8 +598,6 @@ void P_DrawRailTrail (AActor * source, vec3_t start, vec3_t end, int color1, int
else
p->color = grey1;
}
p->color = white;
}
else
{
p->color = color2;

View file

@ -32,6 +32,7 @@
*/
#include "vectors.h"
#include "tables.h"
#define FX_ROCKET 0x00000001
#define FX_GRENADE 0x00000002
@ -58,7 +59,7 @@ void P_RunEffects (void);
void P_RunEffect (AActor *actor, int effects);
void P_DrawRailTrail (AActor * source, vec3_t start, vec3_t end, int color1, int color2, float maxdiff = 0, bool silent = false);
void P_DrawRailTrail (AActor *source, const FVector3 &start, const FVector3 &end, int color1, int color2, float maxdiff = 0, bool silent = false);
void P_DrawSplash (int count, fixed_t x, fixed_t y, fixed_t z, angle_t angle, int kind);
void P_DrawSplash2 (int count, fixed_t x, fixed_t y, fixed_t z, angle_t angle, int updown, int kind);
void P_DisconnectEffect (AActor *actor);

View file

@ -3081,7 +3081,7 @@ void P_RailAttack (AActor *source, int damage, int offset, int color1, int color
fixed_t vx, vy, vz;
angle_t angle, pitch;
fixed_t x1, y1;
vec3_t start, end;
FVector3 start, end;
FTraceResults trace;
pitch = (angle_t)(-source->pitch) >> ANGLETOFINESHIFT;
@ -3100,7 +3100,9 @@ void P_RailAttack (AActor *source, int damage, int offset, int color1, int color
y1 += offset*finesine[angle];
RailHits.Clear ();
VectorFixedSet (start, x1, y1, shootz);
start.X = FIXED2FLOAT(x1);
start.Y = FIXED2FLOAT(y1);
start.Z = FIXED2FLOAT(shootz);
Trace (x1, y1, shootz, source->Sector, vx, vy, vz,
8192*FRACUNIT, MF_SHOOTABLE, ML_BLOCKEVERYTHING, source, trace,
@ -3179,7 +3181,9 @@ void P_RailAttack (AActor *source, int damage, int offset, int color1, int color
P_TraceBleed (damage, x, y, z, RailHits[i].HitActor, angle, pitch);
}
VectorFixedSet (end, trace.X, trace.Y, trace.Z);
end.X = FIXED2FLOAT(trace.X);
end.Y = FIXED2FLOAT(trace.Y);
end.Z = FIXED2FLOAT(trace.Z);
P_DrawRailTrail (source, start, end, color1, color2, maxdiff, silent);
}
@ -3508,7 +3512,7 @@ int bombdistance;
float bombdistancefloat;
bool DamageSource;
FName bombmod;
vec3_t bombvec;
FVector3 bombvec;
bool bombdodamage;
//=============================================================================
@ -3710,7 +3714,9 @@ void P_RadiusAttack (AActor *spot, AActor *source, int damage, int distance, FNa
bombdamagefloat = (float)damage;
bombmod = damageType;
bombdodamage = dodamage;
VectorPosition (spot, bombvec);
bombvec.X = FIXED2FLOAT(spot->x);
bombvec.Y = FIXED2FLOAT(spot->y);
bombvec.Z = FIXED2FLOAT(spot->z);
radbt.Clear();

View file

@ -4402,7 +4402,6 @@ AActor *P_SpawnMissileXYZ (fixed_t x, fixed_t y, fixed_t z,
P_PlaySpawnSound(th, source);
th->target = source; // record missile's originator
vec3_t velocity;
float speed = (float)(th->Speed);
// [RH]
@ -4411,23 +4410,21 @@ AActor *P_SpawnMissileXYZ (fixed_t x, fixed_t y, fixed_t z,
// missile? I'll leave it like this for now.
// Answer. No, because this way, you can set up sets of parallel missiles.
velocity[0] = (float)(dest->x - source->x);
velocity[1] = (float)(dest->y - source->y);
velocity[2] = (float)(dest->z - source->z);
FVector3 velocity(dest->x - source->x, dest->y - source->y, dest->z - source->z);
// Floor and ceiling huggers should never have a vertical component to their velocity
if (defflags3 & (MF3_FLOORHUGGER|MF3_CEILINGHUGGER))
{
velocity[2] = 0.f;
velocity.Z = 0;
}
// [RH] Adjust the trajectory if the missile will go over the player's head.
else if (z - source->z >= dest->height)
{
velocity[2] += (float)(dest->height - z + source->z);
velocity.Z += dest->height - z + source->z;
}
VectorNormalize (velocity);
th->momx = (fixed_t)(velocity[0] * speed);
th->momy = (fixed_t)(velocity[1] * speed);
th->momz = (fixed_t)(velocity[2] * speed);
velocity.Resize (speed);
th->momx = (fixed_t)(velocity.X);
th->momy = (fixed_t)(velocity.Y);
th->momz = (fixed_t)(velocity.Z);
// invisible target: rotate velocity vector in 2D
if (dest->flags & MF_SHADOW)

View file

@ -1299,7 +1299,7 @@ static void P_SlopeLineToPoint (int lineid, fixed_t x, fixed_t y, fixed_t z, boo
plane = &sec->floorplane;
}
vec3_t p, v1, v2, cross;
FVector3 p, v1, v2, cross;
p[0] = FIXED2FLOAT (line->v1->x);
p[1] = FIXED2FLOAT (line->v1->y);
@ -1311,19 +1311,18 @@ static void P_SlopeLineToPoint (int lineid, fixed_t x, fixed_t y, fixed_t z, boo
v2[1] = FIXED2FLOAT (y - line->v1->y);
v2[2] = FIXED2FLOAT (z) - p[2];
CrossProduct (v1, v2, cross);
if (VectorLength (cross) == 0)
cross = v1 ^ v2;
double len = cross.Length();
if (len == 0)
{
Printf ("Slope thing at (%d,%d) lies directly on its target line.\n", int(x>>16), int(y>>16));
return;
}
VectorNormalize (cross);
cross /= len;
// Fix backward normals
if ((cross[2] < 0 && !slopeCeil) || (cross[2] > 0 && slopeCeil))
if ((cross.Z < 0 && !slopeCeil) || (cross.Z > 0 && slopeCeil))
{
cross[0] = -cross[0];
cross[1] = -cross[1];
cross[2] = -cross[2];
cross = -cross;
}
plane->a = FLOAT2FIXED (cross[0]);
@ -1401,12 +1400,12 @@ void P_SetSlope (secplane_t *plane, bool setCeil, int xyangi, int zangi,
xyang = (angle_t)Scale (xyangi, ANGLE_90, 90 << ANGLETOFINESHIFT);
vec3_t norm;
FVector3 norm;
norm[0] = float(finecosine[zang]) * float(finecosine[xyang]);
norm[1] = float(finecosine[zang]) * float(finesine[xyang]);
norm[2] = float(finesine[zang]) * 65536.f;
VectorNormalize (norm);
norm.MakeUnit();
plane->a = (int)(norm[0] * 65536.f);
plane->b = (int)(norm[1] * 65536.f);
plane->c = (int)(norm[2] * 65536.f);
@ -1432,7 +1431,7 @@ void P_VavoomSlope(sector_t * sec, int id, fixed_t x, fixed_t y, fixed_t z, int
if (l->args[0]==id)
{
vec3_t v1, v2, cross;
FVector3 v1, v2, cross;
secplane_t *srcplane = (which == 0) ? &sec->floorplane : &sec->ceilingplane;
fixed_t srcheight = (which == 0) ? sec->floortexz : sec->ceilingtexz;
@ -1444,15 +1443,19 @@ void P_VavoomSlope(sector_t * sec, int id, fixed_t x, fixed_t y, fixed_t z, int
v2[1] = FIXED2FLOAT (y - l->v1->y);
v2[2] = FIXED2FLOAT (z - srcheight);
CrossProduct (v1, v2, cross);
VectorNormalize (cross);
cross = v1 ^ v2;
double len = cross.Length();
if (len == 0)
{
Printf ("Slope thing at (%d,%d) lies directly on its target line.\n", int(x>>16), int(y>>16));
return;
}
cross /= len;
// Fix backward normals
if ((cross[2] < 0 && which == 0) || (cross[2] > 0 && which == 1))
if ((cross.Z < 0 && which == 0) || (cross.Z > 0 && which == 1))
{
cross[0] = -cross[0];
cross[1] = -cross[1];
cross[2] = -cross[2];
cross = -cross;
}
@ -2322,14 +2325,7 @@ static void P_AlignPlane (sector_t *sec, line_t *line, int which)
refsec = line->frontsector == sec ? line->backsector : line->frontsector;
vec3_t p, v1, v2, cross;
p[0] = FIXED2FLOAT (line->v1->x);
p[1] = FIXED2FLOAT (line->v1->y);
v1[0] = FIXED2FLOAT (line->dx);
v1[1] = FIXED2FLOAT (line->dy);
v2[0] = FIXED2FLOAT (refvert->x - line->v1->x);
v2[1] = FIXED2FLOAT (refvert->y - line->v1->y);
FVector3 p, v1, v2, cross;
const secplane_t *refplane;
secplane_t *srcplane;
@ -2340,19 +2336,22 @@ static void P_AlignPlane (sector_t *sec, line_t *line, int which)
srcheight = (which == 0) ? sec->floortexz : sec->ceilingtexz;
destheight = (which == 0) ? refsec->floortexz : refsec->ceilingtexz;
p[0] = FIXED2FLOAT (line->v1->x);
p[1] = FIXED2FLOAT (line->v1->y);
p[2] = FIXED2FLOAT (destheight);
v1[0] = FIXED2FLOAT (line->dx);
v1[1] = FIXED2FLOAT (line->dy);
v1[2] = 0;
v2[0] = FIXED2FLOAT (refvert->x - line->v1->x);
v2[1] = FIXED2FLOAT (refvert->y - line->v1->y);
v2[2] = FIXED2FLOAT (srcheight - destheight);
CrossProduct (v1, v2, cross);
VectorNormalize (cross);
cross = (v1 ^ v2).Unit();
// Fix backward normals
if ((cross[2] < 0 && which == 0) || (cross[2] > 0 && which == 1))
if ((cross.Z < 0 && which == 0) || (cross.Z > 0 && which == 1))
{
cross[0] = -cross[0];
cross[1] = -cross[1];
cross[2] = -cross[2];
cross = -cross;
}
srcplane->a = FLOAT2FIXED (cross[0]);

View file

@ -259,12 +259,7 @@ bool P_Thing_Projectile (int tid, AActor *source, int type, const char * type_na
if (targ != NULL)
{
fixed_t spot[3] = { targ->x, targ->y, targ->z+targ->height/2 };
vec3_t aim =
{
float(spot[0] - mobj->x),
float(spot[1] - mobj->y),
float(spot[2] - mobj->z)
};
FVector3 aim(float(spot[0] - mobj->x), float(spot[1] - mobj->y), float(spot[2] - mobj->z));
if (leadTarget && speed > 0 && (targ->momx | targ->momy | targ->momz))
{
@ -275,55 +270,35 @@ bool P_Thing_Projectile (int tid, AActor *source, int type, const char * type_na
// with the math. I don't think I would have thought of using
// trig alone had I been left to solve it by myself.
double tvel[3] = { double(targ->momx), double(targ->momy), double(targ->momz) };
FVector3 tvel(targ->momx, targ->momy, targ->momz);
if (!(targ->flags & MF_NOGRAVITY) && targ->waterlevel < 3)
{ // If the target is subject to gravity and not underwater,
// assume that it isn't moving vertically. Thanks to gravity,
// even if we did consider the vertical component of the target's
// velocity, we would still miss more often than not.
tvel[2] = 0.0;
tvel.Z = 0.0;
if ((targ->momx | targ->momy) == 0)
{
goto nolead;
}
}
double dist = sqrt (aim[0]*aim[0] + aim[1]*aim[1] + aim[2]*aim[2]);
double targspeed = sqrt (tvel[0]*tvel[0] + tvel[1]*tvel[1] + tvel[2]*tvel[2]);
double ydotx = -aim[0]*tvel[0] - aim[1]*tvel[1] - aim[2]*tvel[2];
double dist = aim | aim;
double targspeed = tvel.Length();
double ydotx = -aim | tvel;
double a = acos (clamp (ydotx / targspeed / dist, -1.0, 1.0));
double multiplier = double(pr_leadtarget.Random2())*0.1/255+1.1;
double sinb = clamp (targspeed*multiplier * sin(a) / fspeed, -1.0, 1.0);
double cosb = cos (asin (sinb));
// Use the cross product of two of the triangle's sides to get a
// rotation vector.
double rv[3] =
{
tvel[1]*aim[2] - tvel[2]*aim[1],
tvel[2]*aim[0] - tvel[0]*aim[2],
tvel[0]*aim[1] - tvel[1]*aim[0]
};
FVector3 rv(tvel ^ aim);
// The vector must be normalized.
double irvlen = 1.0 / sqrt(rv[0]*rv[0] + rv[1]*rv[1] + rv[2]*rv[2]);
rv[0] *= irvlen;
rv[1] *= irvlen;
rv[2] *= irvlen;
rv.MakeUnit();
// Now combine the rotation vector with angle b to get a rotation matrix.
double t = 1.0 - cosb;
double rm[3][3] =
{
{t*rv[0]*rv[0]+cosb, t*rv[0]*rv[1]-sinb*rv[2], t*rv[0]*rv[2]+sinb*rv[1]},
{t*rv[0]*rv[1]+sinb*rv[2], t*rv[1]*rv[1]+cosb, t*rv[1]*rv[2]-sinb*rv[0]},
{t*rv[0]*rv[2]-sinb*rv[1], t*rv[1]*rv[2]+sinb*rv[0], t*rv[2]*rv[2]+cosb}
};
FMatrix3x3 rm(rv, cos(asin(sinb)), sinb);
// And multiply the original aim vector with the matrix to get a
// new aim vector that leads the target.
double aimvec[3] =
{
rm[0][0]*aim[0] + rm[1][0]*aim[1] + rm[2][0]*aim[2],
rm[0][1]*aim[0] + rm[1][1]*aim[1] + rm[2][1]*aim[2],
rm[0][2]*aim[0] + rm[1][2]*aim[1] + rm[2][2]*aim[2]
};
FVector3 aimvec = rm * aim;
// And make the projectile follow that vector at the desired speed.
double aimscale = fspeed / dist;
mobj->momx = fixed_t (aimvec[0] * aimscale);
@ -335,10 +310,10 @@ bool P_Thing_Projectile (int tid, AActor *source, int type, const char * type_na
{
nolead:
mobj->angle = R_PointToAngle2 (mobj->x, mobj->y, targ->x, targ->y);
VectorNormalize (aim);
mobj->momx = fixed_t(aim[0] * fspeed);
mobj->momy = fixed_t(aim[1] * fspeed);
mobj->momz = fixed_t(aim[2] * fspeed);
aim.Resize (fspeed);
mobj->momx = fixed_t(aim[0]);
mobj->momy = fixed_t(aim[1]);
mobj->momz = fixed_t(aim[2]);
}
if (mobj->flags2 & MF2_SEEKERMISSILE)
{

View file

@ -121,7 +121,7 @@ short spanend[MAXHEIGHT];
BYTE *tiltlighting[MAXWIDTH];
int planeshade;
vec3_t plane_sz, plane_su, plane_sv;
FVector3 plane_sz, plane_su, plane_sv;
float planelightfloat;
bool plane_shade;
fixed_t pviewx, pviewy;
@ -1446,7 +1446,7 @@ void R_DrawTiltedPlane (visplane_t *pl, fixed_t alpha, bool masked)
float xscale, yscale;
fixed_t ixscale, iyscale;
angle_t ang;
vec3_t p, m, n;
FVector3 p, m, n;
fixed_t zeroheight;
if (alpha <= 0)
@ -1503,21 +1503,21 @@ void R_DrawTiltedPlane (visplane_t *pl, fixed_t alpha, bool masked)
viewx + MulScale16 (ixscale, finesine[ang]),
viewy + MulScale16 (ixscale, finecosine[ang])) - zeroheight);
CrossProduct (p, m, plane_su);
CrossProduct (p, n, plane_sv);
CrossProduct (m, n, plane_sz);
plane_su = p ^ m;
plane_sv = p ^ n;
plane_sz = m ^ n;
plane_su[2] *= FocalLengthXfloat;
plane_sv[2] *= FocalLengthXfloat;
plane_sz[2] *= FocalLengthXfloat;
plane_su.Z *= FocalLengthXfloat;
plane_sv.Z *= FocalLengthXfloat;
plane_sz.Z *= FocalLengthXfloat;
plane_su[1] *= iyaspectmulfloat;
plane_sv[1] *= iyaspectmulfloat;
plane_sz[1] *= iyaspectmulfloat;
plane_su.Y *= iyaspectmulfloat;
plane_sv.Y *= iyaspectmulfloat;
plane_sz.Y *= iyaspectmulfloat;
// Premultiply the texture vectors with the scale factors
VectorScale2 (plane_su, 4294967296.f);
VectorScale2 (plane_sv, 4294967296.f);
plane_su *= 4294967296.f;
plane_sv *= 4294967296.f;
if (MirrorFlags & RF_XFLIP)
{

View file

@ -736,9 +736,9 @@ void A_CustomMissile(AActor * self)
// Use the actual momentum instead of the missile's Speed property
// so that this can handle missiles with a high vertical velocity
// component properly.
vec3_t velocity = { missile->momx, missile->momy, 0 };
FVector3 velocity (missile->momx, missile->momy, 0);
fixed_t missilespeed=(fixed_t)VectorLength(velocity);
fixed_t missilespeed = (fixed_t)velocity.Length();
missile->angle += Angle;
ang = missile->angle >> ANGLETOFINESHIFT;
@ -1044,8 +1044,8 @@ void A_FireCustomMissile (AActor * self)
{
// This original implementation is to aim straight ahead and then offset
// the angle from the resulting direction.
vec3_t velocity = { misl->momx, misl->momy, 0 };
fixed_t missilespeed=(fixed_t)VectorLength(velocity);
FVector3 velocity(misl->momx, misl->momy, 0);
fixed_t missilespeed = (fixed_t)velocity.Length();
misl->angle += Angle;
angle_t an = misl->angle >> ANGLETOFINESHIFT;
misl->momx = FixedMul (missilespeed, finecosine[an]);

View file

@ -1,253 +0,0 @@
#include "vectors.h"
#include "actor.h"
#include "tables.h"
#define DEG2RAD( a ) ( a * M_PI ) / 180.0F
// [RH] Convert a thing's position into a vec3_t
void VectorPosition (const AActor *thing, vec3_t out)
{
out[0] = (float)thing->x / 65536.0f;
out[1] = (float)thing->y / 65536.0f;
out[2] = (float)thing->z / 65536.0f;
}
void FixedAngleToVector (angle_t an, int pitch, vec3_t v)
{
an >>= ANGLETOFINESHIFT;
v[0] = ((float)finecosine[an]) / 65536.0f;
v[1] = ((float)finesine[an]) / 65536.0f;
v[2] = ((float)finetangent[FINEANGLES/4-(pitch>>ANGLETOFINESHIFT)]) / 65536.0f;
VectorNormalize (v);
}
// Taken from Q2
vec_t VectorLength (const vec3_t v)
{
float length;
length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
length = sqrtf (length);
return length;
}
void VectorMA (const vec3_t a, float scale, const vec3_t b, vec3_t out)
{
out[0] = a[0] + scale * b[0];
out[1] = a[1] + scale * b[1];
out[2] = a[2] + scale * b[2];
}
void VectorScale (const vec3_t v, float scale, vec3_t out)
{
out[0] = v[0] * scale;
out[1] = v[1] * scale;
out[2] = v[2] * scale;
}
void VectorScale2 (vec3_t v, float scale)
{
v[0] = v[0] * scale;
v[1] = v[1] * scale;
v[2] = v[2] * scale;
}
int VectorCompare (const vec3_t v1, const vec3_t v2)
{
if (v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2])
return 0;
return 1;
}
vec_t VectorNormalize (vec3_t v)
{
double length, ilength;
length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
length = sqrt (length);
if (length)
{
ilength = 1/length;
v[0] = vec_t(v[0] * ilength);
v[1] = vec_t(v[1] * ilength);
v[2] = vec_t(v[2] * ilength);
}
return vec_t(length);
}
vec_t VectorNormalize2 (const vec3_t v, vec3_t out)
{
double length, ilength;
length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
length = sqrt (length);
if (length)
{
ilength = 1/length;
out[0] = vec_t(v[0] * ilength);
out[1] = vec_t(v[1] * ilength);
out[2] = vec_t(v[2] * ilength);
}
return vec_t(length);
}
void CrossProduct (const vec3_t v1, const vec3_t v2, vec3_t cross)
{
cross[0] = v1[1]*v2[2] - v1[2]*v2[1];
cross[1] = v1[2]*v2[0] - v1[0]*v2[2];
cross[2] = v1[0]*v2[1] - v1[1]*v2[0];
}
#ifdef _MSC_VER
#pragma optimize( "", off )
#endif
void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees )
{
float m[3][3];
float im[3][3];
float zrot[3][3];
float tmpmat[3][3];
float rot[3][3];
int i;
vec3_t vr, vup, vf;
vf[0] = dir[0];
vf[1] = dir[1];
vf[2] = dir[2];
PerpendicularVector( vr, dir );
CrossProduct( vr, vf, vup );
m[0][0] = vr[0];
m[1][0] = vr[1];
m[2][0] = vr[2];
m[0][1] = vup[0];
m[1][1] = vup[1];
m[2][1] = vup[2];
m[0][2] = vf[0];
m[1][2] = vf[1];
m[2][2] = vf[2];
memcpy( im, m, sizeof( im ) );
im[0][1] = m[1][0];
im[0][2] = m[2][0];
im[1][0] = m[0][1];
im[1][2] = m[2][1];
im[2][0] = m[0][2];
im[2][1] = m[1][2];
memset( zrot, 0, sizeof( zrot ) );
zrot[0][0] = zrot[1][1] = zrot[2][2] = 1.0F;
zrot[0][0] = (float)cos( DEG2RAD( degrees ) );
zrot[0][1] = (float)sin( DEG2RAD( degrees ) );
zrot[1][0] = (float)-sin( DEG2RAD( degrees ) );
zrot[1][1] = (float)cos( DEG2RAD( degrees ) );
R_ConcatRotations( m, zrot, tmpmat );
R_ConcatRotations( tmpmat, im, rot );
for ( i = 0; i < 3; i++ )
{
dst[i] = rot[i][0] * point[0] + rot[i][1] * point[1] + rot[i][2] * point[2];
}
}
#ifdef _MSC_VER
#pragma optimize( "", on )
#endif
void ProjectPointOnPlane (vec3_t dst, const vec3_t p, const vec3_t normal)
{
float d;
vec3_t n;
float inv_denom;
inv_denom = 1.0F / DotProduct( normal, normal );
d = DotProduct( normal, p ) * inv_denom;
n[0] = normal[0] * inv_denom;
n[1] = normal[1] * inv_denom;
n[2] = normal[2] * inv_denom;
dst[0] = p[0] - d * n[0];
dst[1] = p[1] - d * n[1];
dst[2] = p[2] - d * n[2];
}
/*
** assumes "src" is normalized
*/
void PerpendicularVector (vec3_t dst, const vec3_t src)
{
int pos;
int i;
float minelem = 1.0F;
vec3_t tempvec;
/*
** find the smallest magnitude axially aligned vector
*/
for ( pos = 0, i = 0; i < 3; i++ )
{
if ( fabs( src[i] ) < minelem )
{
pos = i;
minelem = (float)fabs( src[i] );
}
}
tempvec[0] = tempvec[1] = tempvec[2] = 0.0F;
tempvec[pos] = 1.0F;
/*
** project the point onto the plane defined by src
*/
ProjectPointOnPlane( dst, tempvec, src );
/*
** normalize the result
*/
VectorNormalize( dst );
}
/*
================
R_ConcatRotations
================
*/
void R_ConcatRotations (const float in1[3][3], const float in2[3][3], float out[3][3])
{
out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] +
in1[0][2] * in2[2][0];
out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] +
in1[0][2] * in2[2][1];
out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] +
in1[0][2] * in2[2][2];
out[1][0] = in1[1][0] * in2[0][0] + in1[1][1] * in2[1][0] +
in1[1][2] * in2[2][0];
out[1][1] = in1[1][0] * in2[0][1] + in1[1][1] * in2[1][1] +
in1[1][2] * in2[2][1];
out[1][2] = in1[1][0] * in2[0][2] + in1[1][1] * in2[1][2] +
in1[1][2] * in2[2][2];
out[2][0] = in1[2][0] * in2[0][0] + in1[2][1] * in2[1][0] +
in1[2][2] * in2[2][0];
out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] +
in1[2][2] * in2[2][1];
out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] +
in1[2][2] * in2[2][2];
}

File diff suppressed because it is too large Load diff

View file

@ -683,7 +683,7 @@ void ShowErrorPane(const char *text)
{
SetWindowLong (ErrorIcon, GWL_ID, IDC_ICONPIC);
}
ErrorPane = CreateDialogParam (g_hInst, MAKEINTRESOURCE(IDD_ERRORPANE), Window, ErrorPaneProc, NULL);
ErrorPane = CreateDialogParam (g_hInst, MAKEINTRESOURCE(IDD_ERRORPANE), Window, ErrorPaneProc, (LONG_PTR)NULL);
CHARRANGE end;
CHARFORMAT2 oldformat, newformat;

File diff suppressed because it is too large Load diff