mirror of
https://github.com/ZDoom/qzdoom-gpl.git
synced 2024-11-16 01:02:03 +00:00
- removed the implicit fixedvec -> TVector conversions because they caused 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.
This commit is contained in:
parent
f860a344cc
commit
c4377b7039
6 changed files with 20 additions and 35 deletions
20
src/actor.h
20
src/actor.h
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
@ -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))
|
||||
{
|
||||
|
@ -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);
|
||||
|
|
|
@ -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))
|
||||
{
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue