gzdoom/wadsrc/static/zscript/actors/shared/camera.zs
Rachael Alexanderson d8ef27e0ed
Squashed commit of the following:
commit ad25b50089b6e01b8e4291e34cfe3a008af9128d
Author: Rachael Alexanderson <madame-rachelle@users.noreply.github.com>
Date:   Fri Feb 9 12:12:46 2024 -0500

    Revert "Adding isometric camera mode with orthographic projection to current state of master branch of GZDoom."

    This reverts commit d2c2c93cf1.

commit 8537f0d8db804f0076b90daa66b750e44dccf44c
Author: Rachael Alexanderson <madame-rachelle@users.noreply.github.com>
Date:   Fri Feb 9 12:12:41 2024 -0500

    Revert "Changed all of the isometric functionality to mapinfo and playerinfo variables. Retained function of most of the CVars."

    This reverts commit dc897eacc0.

commit d45f6ebf11f31d246f2de4f3bbd11f7970783125
Author: Rachael Alexanderson <madame-rachelle@users.noreply.github.com>
Date:   Fri Feb 9 12:10:21 2024 -0500

    Revert "Restored r_orthographic behavior."

    This reverts commit 26908f5bc5.

commit be0836feef9b95f12828eeed4319c726ef13780d
Author: Rachael Alexanderson <madame-rachelle@users.noreply.github.com>
Date:   Fri Feb 9 12:09:15 2024 -0500

    Revert "Adding isometric camera mode with orthographic projection to current state of master branch of GZDoom."

    This reverts commit 08b03e6b19.

commit 688288a9199b912203022cb4db37503f6270e0c3
Author: Rachael Alexanderson <madame-rachelle@users.noreply.github.com>
Date:   Fri Feb 9 12:09:06 2024 -0500

    Revert "Changed all of the isometric functionality to mapinfo and playerinfo variables. Retained function of most of the CVars."

    This reverts commit d3405837ce.

commit 72b7df9fa1841d665c2846dd31a89c6f48123e55
Author: Rachael Alexanderson <madame-rachelle@users.noreply.github.com>
Date:   Fri Feb 9 12:08:59 2024 -0500

    Revert "Restored r_orthographic behavior."

    This reverts commit e171f4eb6a.

commit aa954132bf29f2f8a51bf09dae127e5ffe2c5670
Author: Rachael Alexanderson <madame-rachelle@users.noreply.github.com>
Date:   Fri Feb 9 12:08:48 2024 -0500

    Revert "Merged with latest master and made small change (zcenter -> center.Z) to hw_sprites.cpp. Now compiles and works."

    This reverts commit c8a7507e8e.

commit 3ce90e87a3a9956b615995b57b90619e89bbcff4
Author: Rachael Alexanderson <madame-rachelle@users.noreply.github.com>
Date:   Fri Feb 9 12:00:46 2024 -0500

    Revert "Cleaning up implementation of isometric camera with optional orthographic projection."

    This reverts commit 25f1407228.

commit 3aafd363e40c8d1d2ebbe3c61aeb2b80a74e565a
Author: Rachael Alexanderson <madame-rachelle@users.noreply.github.com>
Date:   Fri Feb 9 11:59:25 2024 -0500

    Revert "Small change to SpectatorCamera actor."

    This reverts commit 2b555d7556.

commit a41911f8907731c098de71ca3e14261ac432ec8c
Author: Rachael Alexanderson <madame-rachelle@users.noreply.github.com>
Date:   Fri Feb 9 11:59:16 2024 -0500

    Revert "SpectatorCamera can now follow the 'tracer' actor. Also added a 'lagdistance' property for lazy follow."

    This reverts commit 7fbb4cd06c.

commit 19398edd065b7b483b8c7be42cb16026695e241a
Author: Rachael Alexanderson <madame-rachelle@users.noreply.github.com>
Date:   Fri Feb 9 11:59:05 2024 -0500

    Revert "Minor addition toe SpectatorCamera. Added three chase modes to lazy follow. 0: Catch up until tracer is centered again. 1: Same but don't move if tracer isn't moving (camera moving when character is not is jarring). 2: Stop chasing if tracer is closer than lagdistance. Game modes benefit from a 'center camera' button but that doesn't have to be hard-baked into the engine."

    This reverts commit c3ca564cfc.
2024-02-09 12:15:17 -05:00

130 lines
2.2 KiB
Text

class DoomBuilderCamera : Actor
{
States
{
Spawn:
TNT1 A 1;
Stop;
}
}
class SecurityCamera : Actor
{
default
{
+NOBLOCKMAP
+NOGRAVITY
+DONTSPLASH
RenderStyle "None";
CameraHeight 0;
}
double Center;
double Acc;
double Delta;
double Range;
override void PostBeginPlay ()
{
Super.PostBeginPlay ();
Center = Angle;
if (args[2])
Delta = 360. / (args[2] * TICRATE / 8);
else
Delta = 0.;
if (args[1])
Delta /= 2;
Acc = 0.;
int arg = (args[0] << 24) >> 24; // make sure the value has the intended sign.
Pitch = clamp(arg, -89, 89);
Range = args[1];
}
override void Tick ()
{
Acc += Delta;
if (Range != 0)
Angle = Center + Range * sin(Acc);
else if (Delta != 0)
Angle = Acc;
}
}
class AimingCamera : SecurityCamera
{
double MaxPitchChange;
override void PostBeginPlay ()
{
int changepitch = args[2];
args[2] = 0;
Super.PostBeginPlay ();
MaxPitchChange = double(changepitch) / TICRATE;
Range /= TICRATE;
ActorIterator it = Level.CreateActorIterator(args[3]);
tracer = it.Next ();
if (tracer == NULL)
{
if (args[3] != 0)
{
console.Printf ("AimingCamera %d: Can't find TID %d\n", tid, args[3]);
}
}
else
{ // Don't try for a new target upon losing this one.
args[3] = 0;
}
}
override void Tick ()
{
if (tracer == NULL && args[3] != 0)
{ // Recheck, in case something with this TID was created since the last time.
ActorIterator it = Level.CreateActorIterator(args[3]);
tracer = it.Next ();
}
if (tracer != NULL)
{
double dir = deltaangle(angle, AngleTo(tracer));
double delta = abs(dir);
if (delta > Range)
{
delta = Range;
}
if (dir > 0)
{
Angle += delta;
}
else
{
Angle -= delta;
}
if (MaxPitchChange != 0)
{ // Aim camera's pitch; use floats for precision
Vector2 vect = tracer.Vec2To(self);
double dz = pos.z - tracer.pos.z - tracer.Height/2;
double dist = vect.Length();
double desiredPitch = dist != 0.f ? VectorAngle(dist, dz) : 0.;
double diff = deltaangle(pitch, desiredPitch);
if (abs (diff) < MaxPitchChange)
{
pitch = desiredPitch;
}
else if (diff < 0)
{
pitch -= MaxPitchChange;
}
else
{
pitch += MaxPitchChange;
}
}
}
}
}