Page 1 of 1

CMF_OFFSETPITCH inverts pitch in A_SpawnProjectile

Posted: Fri Feb 09, 2018 7:42 am
by Marrub
Subject says it all. Projectiles are fired downward when the player is above the monster and upward when the player is above them. Any parameter for pitch will cause this, just having the flag is enough to break it.

Re: CMF_OFFSETPITCH inverts pitch in A_SpawnProjectile

Posted: Fri Feb 09, 2018 11:18 am
by Graf Zahl
Damnit, I thought this had been fixed when deprecating the old versions of these functions.

Re: CMF_OFFSETPITCH inverts pitch in A_SpawnProjectile

Posted: Thu Mar 01, 2018 5:14 am
by Graf Zahl
To ensure that I actually test your problem case, a small demo would be appreciated. I already tried to address this last year but apparently it didn't catch all eventualities.

Re: CMF_OFFSETPITCH inverts pitch in A_SpawnProjectile

Posted: Sat Jan 19, 2019 12:36 am
by Xaser
Welp, this affects one of the enemies in Square, and we're working on updating it for 3.7.x, so time to bump I guess.

Here's a quick test wad:
BackwardsImp.wad
(1.09 KiB) Downloaded 33 times
The imp is supposed to chuck a fireball at you with very slight vertical pitch randomness; instead, the fireball goes up and clonk's the ceiling.

Any chance of taking a look at this before 3.7.2? I dunno if it's possible to handle it on Square's side without it re-breaking in the future.

Re: CMF_OFFSETPITCH inverts pitch in A_SpawnProjectile

Posted: Sat Jan 19, 2019 2:19 am
by Graf Zahl
Interesting. The last time someone encountered this bug the following happened:

Code: Select all

DEFINE_ACTION_FUNCTION(FLevelLocals, SphericalCoords)
{
	PARAM_SELF_STRUCT_PROLOGUE(FLevelLocals);
	PARAM_FLOAT(viewpointX);
	PARAM_FLOAT(viewpointY);
	PARAM_FLOAT(viewpointZ);
	PARAM_FLOAT(targetX);
	PARAM_FLOAT(targetY);
	PARAM_FLOAT(targetZ);
	PARAM_ANGLE(viewYaw);
	PARAM_ANGLE(viewPitch);
	PARAM_BOOL(absolute);

	DVector3 viewpoint(viewpointX, viewpointY, viewpointZ);
	DVector3 target(targetX, targetY, targetZ);
	auto vecTo = absolute ? target - viewpoint : VecDiff(self, viewpoint, target);

	ACTION_RETURN_VEC3(DVector3(
		deltaangle(vecTo.Angle(), viewYaw).Degrees,
		deltaangle(-vecTo.Pitch(), viewPitch).Degrees,
		vecTo.Length()
	));
See that '-' in front of vecTo.Pitch()? That's only there to compensate for the bug. The TVector::Pitch() function got the pitch's sign inverted. Fortunately there's only 3 places in the entire engine using it, and one already compensates for the inversion.

The third place is the function to check actor visibility in the renderer and apparently isn't used in sufficient quantity to have registered. CMF_OFFSETPITCH is the only really critical one.
Let's just hope that no mod depends on it, otherwise a compatibility option will be needed.

Re: CMF_OFFSETPITCH inverts pitch in A_SpawnProjectile

Posted: Sat Jan 19, 2019 2:51 am
by Apeirogon
Graf Zahl wrote:The TVector::Pitch() function got the pitch's sign inverted
Does this because (g)zdoom use strange decision to make "up" pitch (looking at the ceiling) negative and "down" pitch positive?
Because, since it use right handed coordinate system, pitch signs must be inverted, positive up - negative down.

Re: CMF_OFFSETPITCH inverts pitch in A_SpawnProjectile

Posted: Sat Jan 19, 2019 2:58 am
by Graf Zahl
Yes, to match the internal usage it needs to invert the sign here. Why was it inverse? No idea, it predates my involvement in this code. Early ZDoom had a few of these odd gotchas attached to it, unfortunately, but since this got exposed to scripting very early on there is no chance to fix the design flaw now.

Re: CMF_OFFSETPITCH inverts pitch in A_SpawnProjectile

Posted: Mon Jan 21, 2019 10:14 pm
by Xaser
Bit late I suppose, since 3.7.2 is out, but this is indeed all working in Square-land. Thanks for the fix!