Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/GameView.cpp
Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | float Update(float time) | ||||
if (fabs(m_Target - m_Current) < m_MinDelta) | if (fabs(m_Target - m_Current) < m_MinDelta) | ||||
return 0.0f; | return 0.0f; | ||||
double p = pow(static_cast<double>(m_Smoothness), 10.0 * static_cast<double>(time)); | double p = pow(static_cast<double>(m_Smoothness), 10.0 * static_cast<double>(time)); | ||||
// (add the factor of 10 so that smoothnesses don't have to be tiny numbers) | // (add the factor of 10 so that smoothnesses don't have to be tiny numbers) | ||||
double delta = (m_Target - m_Current) * (1.0 - p); | double delta = (m_Target - m_Current) * (1.0 - p); | ||||
m_Current += delta; | m_Current += delta; | ||||
return (float)delta; | return static_cast<float>(delta); | ||||
} | } | ||||
void ClampSmoothly(float min, float max) | void ClampSmoothly(float min, float max) | ||||
{ | { | ||||
m_Target = Clamp(m_Target, static_cast<double>(min), static_cast<double>(max)); | m_Target = Clamp(m_Target, static_cast<double>(min), static_cast<double>(max)); | ||||
} | } | ||||
// Wrap so 'target' is in the range [min, max] | // Wrap so 'target' is in the range [min, max] | ||||
void Wrap(float min, float max) | void Wrap(float min, float max) | ||||
{ | { | ||||
double t = fmod(m_Target - min, static_cast<double>(max - min)); | double t = fmod(m_Target - min, static_cast<double>(max - min)); | ||||
if (t < 0) | if (t < 0) | ||||
t += max - min; | t += max - min; | ||||
t += min; | t += min; | ||||
m_Current += t - m_Target; | m_Current += t - m_Target; | ||||
m_Target = t; | m_Target = t; | ||||
} | } | ||||
float m_Smoothness; | float GetSmoothness() const | ||||
{ | |||||
return m_Smoothness; | |||||
} | |||||
void SetSmoothness(float smoothness) | |||||
{ | |||||
m_Smoothness = smoothness; | |||||
} | |||||
private: | private: | ||||
float m_Smoothness; | |||||
double m_Target; // the value which m_Current is tending towards | double m_Target; // the value which m_Current is tending towards | ||||
double m_Current; | double m_Current; | ||||
// (We use double because the extra precision is worthwhile here) | // (We use double because the extra precision is worthwhile here) | ||||
float m_MinDelta; // cutoff where we stop moving (to avoid ugly shimmering effects) | float m_MinDelta; // cutoff where we stop moving (to avoid ugly shimmering effects) | ||||
}; | }; | ||||
class CGameViewImpl | class CGameViewImpl | ||||
▲ Show 20 Lines • Show All 280 Lines • ▼ Show 20 Lines | int CGameView::Initialize() | ||||
CFG_GET_VAL("joystick.camera.rotate.x", m->JoystickRotateX); | CFG_GET_VAL("joystick.camera.rotate.x", m->JoystickRotateX); | ||||
CFG_GET_VAL("joystick.camera.rotate.y", m->JoystickRotateY); | CFG_GET_VAL("joystick.camera.rotate.y", m->JoystickRotateY); | ||||
CFG_GET_VAL("joystick.camera.zoom.in", m->JoystickZoomIn); | CFG_GET_VAL("joystick.camera.zoom.in", m->JoystickZoomIn); | ||||
CFG_GET_VAL("joystick.camera.zoom.out", m->JoystickZoomOut); | CFG_GET_VAL("joystick.camera.zoom.out", m->JoystickZoomOut); | ||||
CFG_GET_VAL("view.height.smoothness", m->HeightSmoothness); | CFG_GET_VAL("view.height.smoothness", m->HeightSmoothness); | ||||
CFG_GET_VAL("view.height.min", m->HeightMin); | CFG_GET_VAL("view.height.min", m->HeightMin); | ||||
CFG_GET_VAL("view.pos.smoothness", m->PosX.m_Smoothness); | #define SETUP_SMOOTHNESS(CFG_PREFIX, SMOOTHED_VALUE) \ | ||||
CFG_GET_VAL("view.pos.smoothness", m->PosY.m_Smoothness); | { \ | ||||
CFG_GET_VAL("view.pos.smoothness", m->PosZ.m_Smoothness); | float smoothness = SMOOTHED_VALUE.GetSmoothness(); \ | ||||
CFG_GET_VAL("view.zoom.smoothness", m->Zoom.m_Smoothness); | CFG_GET_VAL(CFG_PREFIX ".smoothness", smoothness); \ | ||||
CFG_GET_VAL("view.rotate.x.smoothness", m->RotateX.m_Smoothness); | SMOOTHED_VALUE.SetSmoothness(smoothness); \ | ||||
CFG_GET_VAL("view.rotate.y.smoothness", m->RotateY.m_Smoothness); | } | ||||
SETUP_SMOOTHNESS("view.pos", m->PosX); | |||||
SETUP_SMOOTHNESS("view.pos", m->PosY); | |||||
SETUP_SMOOTHNESS("view.pos", m->PosZ); | |||||
SETUP_SMOOTHNESS("view.zoom", m->Zoom); | |||||
SETUP_SMOOTHNESS("view.rotate.x", m->RotateX); | |||||
SETUP_SMOOTHNESS("view.rotate.y", m->RotateY); | |||||
#undef SETUP_SMOOTHNESS | |||||
elexis: (There are D1931, D2293, but they don't touch `GameView.cpp`) | |||||
vladislavbelovAuthorUnsubmitted Done Inline ActionsYeah, I have that in mind. First of all I want to remove the public member. vladislavbelov: Yeah, I have that in mind. First of all I want to remove the public member. | |||||
CFG_GET_VAL("view.near", m->ViewNear); | CFG_GET_VAL("view.near", m->ViewNear); | ||||
CFG_GET_VAL("view.far", m->ViewFar); | CFG_GET_VAL("view.far", m->ViewFar); | ||||
CFG_GET_VAL("view.fov", m->ViewFOV); | CFG_GET_VAL("view.fov", m->ViewFOV); | ||||
// Convert to radians | // Convert to radians | ||||
m->RotateX.SetValue(DEGTORAD(m->ViewRotateXDefault)); | m->RotateX.SetValue(DEGTORAD(m->ViewRotateXDefault)); | ||||
m->RotateY.SetValue(DEGTORAD(m->ViewRotateYDefault)); | m->RotateY.SetValue(DEGTORAD(m->ViewRotateYDefault)); | ||||
▲ Show 20 Lines • Show All 263 Lines • ▼ Show 20 Lines | if (cmpPosition && cmpPosition->IsInWorld() && | ||||
CVector3D pos = transform.GetTranslation(); | CVector3D pos = transform.GetTranslation(); | ||||
if (m->FollowFirstPerson) | if (m->FollowFirstPerson) | ||||
{ | { | ||||
float x, z, angle; | float x, z, angle; | ||||
cmpPosition->GetInterpolatedPosition2D(frameOffset, x, z, angle); | cmpPosition->GetInterpolatedPosition2D(frameOffset, x, z, angle); | ||||
float height = 4.f; | float height = 4.f; | ||||
m->ViewCamera.m_Orientation.SetIdentity(); | m->ViewCamera.m_Orientation.SetIdentity(); | ||||
m->ViewCamera.m_Orientation.RotateX((float)M_PI/24.f); | m->ViewCamera.m_Orientation.RotateX(static_cast<float>(M_PI) / 24.f); | ||||
m->ViewCamera.m_Orientation.RotateY(angle); | m->ViewCamera.m_Orientation.RotateY(angle); | ||||
m->ViewCamera.m_Orientation.Translate(pos.X, pos.Y + height, pos.Z); | m->ViewCamera.m_Orientation.Translate(pos.X, pos.Y + height, pos.Z); | ||||
m->ViewCamera.UpdateFrustum(); | m->ViewCamera.UpdateFrustum(); | ||||
return; | return; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | if (m->ConstrainCamera) | ||||
CVector3D nearPoint = target.GetTranslation() + target.GetIn() * defaultNear; | CVector3D nearPoint = target.GetTranslation() + target.GetIn() * defaultNear; | ||||
float ground = m->Game->GetWorld()->GetTerrain()->GetExactGroundLevel(nearPoint.X, nearPoint.Z); | float ground = m->Game->GetWorld()->GetTerrain()->GetExactGroundLevel(nearPoint.X, nearPoint.Z); | ||||
float limit = ground + 16.f; | float limit = ground + 16.f; | ||||
if (nearPoint.Y < limit) | if (nearPoint.Y < limit) | ||||
m->PosY.AddSmoothly(limit - nearPoint.Y); | m->PosY.AddSmoothly(limit - nearPoint.Y); | ||||
} | } | ||||
*/ | */ | ||||
m->RotateY.Wrap(-(float)M_PI, (float)M_PI); | m->RotateY.Wrap(-static_cast<float>(M_PI), static_cast<float>(M_PI)); | ||||
elexisUnsubmitted Not Done Inline ActionsWhy not float(M_PI)? elexis: Why not `float(M_PI)`? | |||||
vladislavbelovAuthorUnsubmitted Done Inline ActionsWe use cast to easily find places with an implicit type conversion and for a more strict type check. vladislavbelov: We use cast to easily find places with an implicit type conversion and for a more strict type… | |||||
elexisUnsubmitted Not Done Inline ActionsI suppose the idea is to keep the semantics, i.e. expressing that it is a conversion, not a construction of a new number (from an existing number) elexis: I suppose the idea is to keep the semantics, i.e. expressing that it is a `conversion`, not a… | |||||
// Update the camera matrix | // Update the camera matrix | ||||
SetCameraProjection(); | SetCameraProjection(); | ||||
SetupCameraMatrixSmooth(m, &m->ViewCamera.m_Orientation); | SetupCameraMatrixSmooth(m, &m->ViewCamera.m_Orientation); | ||||
m->ViewCamera.UpdateFrustum(); | m->ViewCamera.UpdateFrustum(); | ||||
} | } | ||||
CVector3D CGameView::GetCameraPivot() const | CVector3D CGameView::GetCameraPivot() const | ||||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | void CGameView::CameraFollow(entity_id_t entity, bool firstPerson) | ||||
m->FollowFirstPerson = firstPerson; | m->FollowFirstPerson = firstPerson; | ||||
} | } | ||||
entity_id_t CGameView::GetFollowedEntity() | entity_id_t CGameView::GetFollowedEntity() | ||||
{ | { | ||||
return m->FollowEntity; | return m->FollowEntity; | ||||
} | } | ||||
float CGameView::GetNear() const | |||||
{ | |||||
return m->ViewNear; | |||||
} | |||||
float CGameView::GetFar() const | |||||
{ | |||||
return m->ViewFar; | |||||
} | |||||
void CGameView::SetCameraProjection() | void CGameView::SetCameraProjection() | ||||
{ | { | ||||
m->ViewCamera.SetPerspectiveProjection(m->ViewNear, m->ViewFar, m->ViewFOV); | m->ViewCamera.SetPerspectiveProjection(m->ViewNear, m->ViewFar, m->ViewFOV); | ||||
} | } | ||||
InReaction game_view_handler(const SDL_Event_* ev) | InReaction game_view_handler(const SDL_Event_* ev) | ||||
{ | { | ||||
// put any events that must be processed even if inactive here | // put any events that must be processed even if inactive here | ||||
▲ Show 20 Lines • Show All 104 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
(There are D1931, D2293, but they don't touch GameView.cpp)