Skip to content

Commit

Permalink
- removed the implicit fixedvec -> TVector conversions because they c…
Browse files Browse the repository at this point in the history
…aused too many problems. Also reviewed all uses of these and made the necessary adjustments. Problems were present in P_SpawnMissileXYZ and P_Thing_Projectile.

- replaced some single precision float math with doubles.
  • Loading branch information
Christoph Oelckers committed Jan 23, 2016
1 parent f860a34 commit c4377b7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 35 deletions.
20 changes: 0 additions & 20 deletions src/actor.h
Expand Up @@ -591,31 +591,11 @@ enum
struct fixedvec3
{
fixed_t x, y, z;

operator FVector3()
{
return FVector3(FIXED2FLOAT(x), FIXED2FLOAT(y), FIXED2FLOAT(z));
}

operator TVector3<double>()
{
return TVector3<double>(FIXED2DBL(x), FIXED2DBL(y), FIXED2DBL(z));
}
};

struct fixedvec2
{
fixed_t x, y;

operator FVector2()
{
return FVector2(FIXED2FLOAT(x), FIXED2FLOAT(y));
}

operator TVector2<double>()
{
return TVector2<double>(FIXED2DBL(x), FIXED2DBL(y));
}
};

struct FDropItem
Expand Down
3 changes: 2 additions & 1 deletion src/b_func.cpp
Expand Up @@ -465,7 +465,8 @@ fixed_t FCajunMaster::FakeFire (AActor *source, AActor *dest, ticcmd_t *cmd)

float speed = (float)th->Speed;

TVector3<double> velocity = source->Vec3To(dest);
fixedvec3 fixvel = source->Vec3To(dest);
TVector3<double> velocity(fixvel.x, fixvel.y, fixvel.z);
velocity.MakeUnit();
th->velx = FLOAT2FIXED(velocity[0] * speed);
th->vely = FLOAT2FIXED(velocity[1] * speed);
Expand Down
5 changes: 3 additions & 2 deletions src/g_shared/a_camera.cpp
Expand Up @@ -176,8 +176,9 @@ void AAimingCamera::Tick ()
}
if (MaxPitchChange)
{ // Aim camera's pitch; use floats for precision
TVector2<double> vect = tracer->Vec2To(this);
double dz = FIXED2DBL(Z() - tracer->Z() - tracer->height/2);
fixedvec2 fv3 = tracer->Vec2To(this);
TVector2<double> vect(fv3.x, fv3.y);
double dz = Z() - tracer->Z() - tracer->height/2;
double dist = vect.Length();
double ang = dist != 0.f ? atan2 (dz, dist) : 0;
int desiredpitch = (angle_t)(ang * 2147483648.f / PI);
Expand Down
10 changes: 6 additions & 4 deletions src/p_enemy.cpp
Expand Up @@ -2777,7 +2777,8 @@ void A_Face (AActor *self, AActor *other, angle_t max_turn, angle_t max_pitch, a
// disabled and is so by default.
if (max_pitch <= ANGLE_180)
{
TVector2<double> dist = self->Vec2To(other);
fixedvec2 pos = self->Vec2To(other);
TVector2<double> dist(pos.x, pos.y);

// Positioning ala missile spawning, 32 units above foot level
fixed_t source_z = self->Z() + 32*FRACUNIT + self->GetBobOffset();
Expand All @@ -2801,7 +2802,7 @@ void A_Face (AActor *self, AActor *other, angle_t max_turn, angle_t max_pitch, a
if (!(flags & FAF_NODISTFACTOR))
target_z += pitch_offset;

double dist_z = FIXED2DBL(target_z - source_z);
double dist_z = target_z - source_z;
double ddist = sqrt(dist.X*dist.X + dist.Y*dist.Y + dist_z*dist_z);
int other_pitch = (int)rad2bam(asin(dist_z / ddist));

Expand Down Expand Up @@ -2915,8 +2916,9 @@ DEFINE_ACTION_FUNCTION(AActor, A_MonsterRail)
if (linetarget == NULL)
{
// We probably won't hit the target, but aim at it anyway so we don't look stupid.
TVector2<double> xydiff = self->Vec2To(self->target);
double zdiff = FIXED2DBL((self->target->Z() + (self->target->height>>1)) - (self->Z() + (self->height>>1) - self->floorclip));
fixedvec2 pos = self->Vec2To(self->target);
TVector2<double> xydiff(pos.x, pos.y);
double zdiff = (self->target->Z() + (self->target->height>>1)) - (self->Z() + (self->height>>1) - self->floorclip);
self->pitch = int(atan2(zdiff, xydiff.Length()) * ANGLE_180 / -M_PI);
}

Expand Down
7 changes: 4 additions & 3 deletions src/p_mobj.cpp
Expand Up @@ -2037,7 +2037,7 @@ fixed_t P_XYMovement (AActor *mo, fixed_t scrollx, fixed_t scrolly)
//dest->x - source->x
fixedvec3 vect = mo->Vec3To(origin);
vect.z += origin->height / 2;
FVector3 velocity(vect);
TVector3<double> velocity(vect.x, vect.y, vect.z);
velocity.Resize(speed);
mo->velx = (fixed_t)(velocity.X);
mo->vely = (fixed_t)(velocity.Y);
Expand Down Expand Up @@ -5733,7 +5733,8 @@ AActor *P_SpawnMissileXYZ (fixed_t x, fixed_t y, fixed_t z,
// missile?
// Answer: No, because this way, you can set up sets of parallel missiles.

FVector3 velocity = source->Vec3To(dest);
fixedvec3 fixvel = source->Vec3To(dest);
FVector3 velocity(fixvel.x, fixvel.y, fixvel.z);
// Floor and ceiling huggers should never have a vertical component to their velocity
if (th->flags3 & (MF3_FLOORHUGGER|MF3_CEILINGHUGGER))
{
Expand All @@ -5742,7 +5743,7 @@ AActor *P_SpawnMissileXYZ (fixed_t x, fixed_t y, fixed_t z,
// [RH] Adjust the trajectory if the missile will go over the target's head.
else if (z - source->Z() >= dest->height)
{
velocity.Z += dest->height - z + source->Z();
velocity.Z += (dest->height - z + source->Z());
}
velocity.Resize (speed);
th->velx = (fixed_t)(velocity.X);
Expand Down
10 changes: 5 additions & 5 deletions src/p_things.cpp
Expand Up @@ -256,7 +256,7 @@ bool P_Thing_Projectile (int tid, AActor *source, int type, const char *type_nam
{
fixedvec3 vect = mobj->Vec3To(targ);
vect.z += targ->height / 2;
FVector3 aim = vect;
TVector3<double> aim(vect.x, vect.y, vect.z);

if (leadTarget && speed > 0 && (targ->velx | targ->vely | targ->velz))
{
Expand All @@ -267,7 +267,7 @@ bool P_Thing_Projectile (int tid, AActor *source, int type, const char *type_nam
// with the math. I don't think I would have thought of using
// trig alone had I been left to solve it by myself.

FVector3 tvel(targ->velx, targ->vely, targ->velz);
TVector3<double> tvel(targ->velx, targ->vely, targ->velz);
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,
Expand All @@ -288,14 +288,14 @@ bool P_Thing_Projectile (int tid, AActor *source, int type, const char *type_nam

// Use the cross product of two of the triangle's sides to get a
// rotation vector.
FVector3 rv(tvel ^ aim);
TVector3<double> rv(tvel ^ aim);
// The vector must be normalized.
rv.MakeUnit();
// Now combine the rotation vector with angle b to get a rotation matrix.
FMatrix3x3 rm(rv, cos(asin(sinb)), sinb);
TMatrix3x3<double> 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.
FVector3 aimvec = rm * aim;
TVector3<double> aimvec = rm * aim;
// And make the projectile follow that vector at the desired speed.
double aimscale = fspeed / dist;
mobj->velx = fixed_t (aimvec[0] * aimscale);
Expand Down

0 comments on commit c4377b7

Please sign in to comment.