Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
[location] location_camera: configurable perspective
Browse files Browse the repository at this point in the history
 - introduced msg MSG_CAMERA_SET_PERSPECTIVE
  • Loading branch information
espkk committed Jan 16, 2022
1 parent 6bf5eb9 commit 88a4aae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/libs/location/src/location_camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#define LOCATIONCAMERA_DISTALPHA_MAX 1.6f // Distance from the character at which it is necessary to fade out alpha
#define LOCATIONCAMERA_DISTALPHA_MIN 0.8f // Distance from the character at which it is necessary to fade out alpha

#define LOCATIONCAMERA_PERSPECTIVE (1.57f + 1.0f) * 0.5f
#define LOCATIONCAMERA_DEFAULT_PERSPECTIVE (1.57f + 1.0f) * 0.5f

// ============================================================================================
// Construction, destruction
Expand Down Expand Up @@ -71,6 +71,8 @@ LocationCamera::LocationCamera()
dynamic_fog.isOn = false;

m_bTrackMode = false;

cameraPerspective = LOCATIONCAMERA_DEFAULT_PERSPECTIVE;
}

LocationCamera::~LocationCamera()
Expand Down Expand Up @@ -100,7 +102,7 @@ bool LocationCamera::Init()
// try to get the location
loc = EntityManager::GetEntityId("location");

rs->SetPerspective(LOCATIONCAMERA_PERSPECTIVE);
rs->SetPerspective(cameraPerspective);
// rs->SetPerspective(1.0f);

StoreRestoreDynamicFov(false);
Expand Down Expand Up @@ -404,7 +406,9 @@ uint64_t LocationCamera::ProcessMessage(MESSAGE &message)
case MSG_CAMERA_SET_RADIUS:
radius = message.Float();
return 1;

case MSG_CAMERA_SET_PERSPECTIVE:
cameraPerspective = message.Float();
return 1;
// internal
case -1: {
const auto fSpeed = message.Float();
Expand Down Expand Up @@ -611,17 +615,17 @@ void LocationCamera::Clip(PLANE *p, int32_t numPlanes, CVECTOR &cnt, float rad,
void LocationCamera::TurnOnDynamicFov(float fSpeed, float fTime, float fRelationMin, float fRelationMax,
float fAngSpeed, float fAngMax)
{
dynamic_fog.fMinFov = LOCATIONCAMERA_PERSPECTIVE * fRelationMin;
dynamic_fog.fMaxFov = LOCATIONCAMERA_PERSPECTIVE * fRelationMax;
dynamic_fog.fMinFov = cameraPerspective * fRelationMin;
dynamic_fog.fMaxFov = cameraPerspective * fRelationMax;
if (!dynamic_fog.isOn)
{
dynamic_fog.fCurFov = LOCATIONCAMERA_PERSPECTIVE;
dynamic_fog.fCurFov = cameraPerspective;
dynamic_fog.bFogUp = true;
dynamic_fog.fCurAngle = 0.f;
dynamic_fog.bAngleUp = true;
}
dynamic_fog.isOn = true;
dynamic_fog.fFogChangeSpeed = fSpeed * LOCATIONCAMERA_PERSPECTIVE;
dynamic_fog.fFogChangeSpeed = fSpeed * cameraPerspective;
dynamic_fog.fFogTimeCur = 0;
dynamic_fog.fFogTimeMax = fTime;

Expand All @@ -635,7 +639,7 @@ void LocationCamera::ProcessDynamicFov(float fDeltaTime, const CVECTOR &vFrom, c
dynamic_fog.fFogTimeCur += fDeltaTime;
if (dynamic_fog.fFogTimeMax > 0.f && dynamic_fog.fFogTimeCur >= dynamic_fog.fFogTimeMax)
{
rs->SetPerspective(LOCATIONCAMERA_PERSPECTIVE);
rs->SetPerspective(cameraPerspective);
dynamic_fog.isOn = false;
}
else
Expand Down Expand Up @@ -723,9 +727,9 @@ void LocationCamera::StoreRestoreDynamicFov(bool bStore)
dynamic_fog.isOn = pA->GetAttributeAsDword("ison", false) != 0;
if (dynamic_fog.isOn)
{
dynamic_fog.fMinFov = pA->GetAttributeAsFloat("minfov", LOCATIONCAMERA_PERSPECTIVE);
dynamic_fog.fMaxFov = pA->GetAttributeAsFloat("maxfov", LOCATIONCAMERA_PERSPECTIVE);
dynamic_fog.fCurFov = pA->GetAttributeAsFloat("curfov", LOCATIONCAMERA_PERSPECTIVE);
dynamic_fog.fMinFov = pA->GetAttributeAsFloat("minfov", cameraPerspective);
dynamic_fog.fMaxFov = pA->GetAttributeAsFloat("maxfov", cameraPerspective);
dynamic_fog.fCurFov = pA->GetAttributeAsFloat("curfov", cameraPerspective);
dynamic_fog.bFogUp = pA->GetAttributeAsDword("fogup", true) != 0;
dynamic_fog.fFogChangeSpeed = pA->GetAttributeAsFloat("speed", 0.1f);
dynamic_fog.fFogTimeCur = pA->GetAttributeAsFloat("timecur", 0.f);
Expand Down Expand Up @@ -764,7 +768,7 @@ bool LocationCamera::LoadCameraTrack(const char *pcTrackFile, float fTrackTime)
view.Inverse();
view.pos = view * -pos;
rs->SetView(*(CMatrix *)&view);
rs->SetPerspective(LOCATIONCAMERA_PERSPECTIVE);
rs->SetPerspective(cameraPerspective);

return true;
}
Expand Down Expand Up @@ -811,7 +815,7 @@ void LocationCamera::ProcessTrackCamera()
view.Inverse();
view.pos = view * -pos;
rs->SetView(*(CMatrix *)&view);
rs->SetPerspective(LOCATIONCAMERA_PERSPECTIVE);
rs->SetPerspective(cameraPerspective);
}

float LocationCamera::TrackPauseProcess()
Expand Down
2 changes: 2 additions & 0 deletions src/libs/location/src/location_camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ class LocationCamera : public Entity
PathTracks m_track;

bool forcedPos = false;

float cameraPerspective;
};

inline void LocationCamera::LockFPMode(bool isLock)
Expand Down
2 changes: 2 additions & 0 deletions src/libs/shared_headers/include/shared/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@
#define MSG_CAMERA_SLEEP 30520 // "ll" stop the camera (1) or resume (0)
#define MSG_CAMERA_SET_RADIUS 30521 // "lf" set radius

#define MSG_CAMERA_SET_PERSPECTIVE 30530 // "lf" set perspective

// Blots on the ship
#define MSG_BLOTS_SETMODEL 30600 // "li" set the model, model_id
#define MSG_BLOTS_HIT 30601 // "lffffff" set point x, y, z, nx, ny, nz
Expand Down

0 comments on commit 88a4aae

Please sign in to comment.