mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-12-02 17:02:25 +00:00
25f1407228
All CVars, mapinfo variables, and playerinfo/playerpawn variables are gone. A Camera actor named 'SpectatorCamera' is defined in warsrc/static/zscript/actors/shared/camera.zs The following new flag bits were defined in the 'DViewPosition' struct for use with actor->ViewPos in src/playsim/actor.h: VPSF_ALLOWOUTOFBOUNDS = 1 << 3, // Allow viewpoint to go out of bounds (hardware renderer only). VPSF_ORTHOGRAPHIC = 1 << 4, // Use orthographic projection. VPSF_ISOMETRICSPRITES = 1 << 5, // Displace sprites towards camera and don't billboard (drawn from isometric perspective). Basically, spawn a SpectatorCamera actor with the appropriate flags and set it to player.camera. See example template: https://www.mediafire.com/file/fv8rytayjt9l6g1/isometric_actor_wads.zip/file Has been tested with multiplayer death and disconnection (and respawns). Not tested with portals. Still only works with hardware renderer (mostly). But should be compatible with older mods and libraries.
171 lines
3.1 KiB
Text
171 lines
3.1 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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
class SpectatorCamera : Actor
|
|
{
|
|
|
|
default
|
|
{
|
|
+NOBLOCKMAP
|
|
+NOGRAVITY
|
|
+NOSECTOR
|
|
+NOINTERACTION
|
|
RenderStyle "None";
|
|
CameraHeight 0;
|
|
}
|
|
|
|
void Init(double dist, double yaw, double inpitch, int inflags)
|
|
{
|
|
if((inflags & VPSF_ORTHOGRAPHIC) || ((inflags == -1) && (ViewPos.Flags & VPSF_ORTHOGRAPHIC))) dist *= 3.0;
|
|
SetViewPos((-dist*Cos(yaw), -dist*Sin(yaw), dist*Tan(inpitch)-0.5*players[consoleplayer].mo.height), inflags);
|
|
// CameraHeight = players[consoleplayer].mo.viewheight; // Not used
|
|
LookAtSelf(inpitch);
|
|
}
|
|
|
|
void LookAtSelf(double inpitch)
|
|
{
|
|
if(ViewPos.Offset != (0., 0., 0.))
|
|
{
|
|
Vector3 negviewpos = (-1.0) * ViewPos.Offset;
|
|
angle = negviewpos.Angle();
|
|
pitch = inpitch;
|
|
}
|
|
}
|
|
|
|
override void Tick()
|
|
{
|
|
if(player != NULL)
|
|
{
|
|
cameraFOV = player.FOV;
|
|
SetOrigin(player.mo.pos, true);
|
|
}
|
|
}
|
|
}
|