Added orbit camera mode, set up orbit in World Editor and Model Editor
This commit is contained in:
parent
373426a98f
commit
2e5678e863
190
Core/CCamera.cpp
190
Core/CCamera.cpp
|
@ -12,81 +12,63 @@ CCamera::CCamera()
|
||||||
|
|
||||||
mYaw = -Math::skHalfPi;
|
mYaw = -Math::skHalfPi;
|
||||||
mPitch = 0.0f;
|
mPitch = 0.0f;
|
||||||
CalculateDirection();
|
SetOrbit(CVector3f(0), 5.f);
|
||||||
|
Update();
|
||||||
|
|
||||||
mMoveSpeed = 1.f; // Old: 0.01f
|
mMoveSpeed = 1.f;
|
||||||
mLookSpeed = 1.f; // Old: 0.003f
|
mLookSpeed = 1.f;
|
||||||
mViewOutdated = true;
|
mViewOutdated = true;
|
||||||
mProjectionOutdated = true;
|
mProjectionOutdated = true;
|
||||||
mFrustumPlanesOutdated = true;
|
mFrustumPlanesOutdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCamera::CCamera(CVector3f Position, CVector3f)
|
CCamera::CCamera(CVector3f Position, CVector3f /*Target*/)
|
||||||
{
|
{
|
||||||
// todo: make it actually look at the target!
|
// todo: make it actually look at the target!
|
||||||
// Not using parameter 2 (CVector3f - Target)
|
|
||||||
mMode = eFreeCamera;
|
mMode = eFreeCamera;
|
||||||
mMoveSpeed = 1.f; // Old: 0.01f
|
mMoveSpeed = 1.f;
|
||||||
mLookSpeed = 1.f; // Old: 0.003f
|
mLookSpeed = 1.f;
|
||||||
mPosition = Position;
|
mPosition = Position;
|
||||||
mYaw = -Math::skHalfPi;
|
mYaw = -Math::skHalfPi;
|
||||||
mPitch = 0.0f;
|
mPitch = 0.0f;
|
||||||
CalculateDirection();
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCamera::Pan(float XAmount, float YAmount)
|
void CCamera::Pan(float XAmount, float YAmount)
|
||||||
{
|
{
|
||||||
switch (mMode)
|
if (mMode == eFreeCamera)
|
||||||
{
|
{
|
||||||
|
Update();
|
||||||
case eFreeCamera:
|
mPosition += mRightVector * (XAmount * mMoveSpeed);
|
||||||
{
|
mPosition += mUpVector * (YAmount * mMoveSpeed);
|
||||||
CVector3f Right(
|
|
||||||
cos(mYaw - Math::skHalfPi),
|
|
||||||
sin(mYaw - Math::skHalfPi),
|
|
||||||
0
|
|
||||||
);
|
|
||||||
CVector3f Up = Right.Cross(mDirection);
|
|
||||||
|
|
||||||
mPosition += Right * (XAmount * mMoveSpeed);
|
|
||||||
mPosition += Up * (YAmount * mMoveSpeed);
|
|
||||||
mViewOutdated = true;
|
mViewOutdated = true;
|
||||||
mFrustumPlanesOutdated = true;
|
mFrustumPlanesOutdated = true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unfinished
|
else
|
||||||
case eOrbitCamera:
|
Rotate(-XAmount * 0.3f, YAmount * 0.3f);
|
||||||
{
|
|
||||||
CVector3f Right(
|
|
||||||
cos(mYaw - Math::skHalfPi),
|
|
||||||
sin(mYaw - Math::skHalfPi),
|
|
||||||
0
|
|
||||||
);
|
|
||||||
CVector3f Up = Right.Cross(mDirection);
|
|
||||||
|
|
||||||
CVector3f TargetDirection = mPosition - mOrbitTarget;
|
|
||||||
//CMatrix4f YawRotation = CQuaternion::F
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCamera::Rotate(float XAmount, float YAmount)
|
void CCamera::Rotate(float XAmount, float YAmount)
|
||||||
{
|
{
|
||||||
switch (mMode)
|
mYaw -= (XAmount * mLookSpeed * 0.3f);
|
||||||
{
|
mPitch -= (YAmount * mLookSpeed * 0.3f);
|
||||||
case eFreeCamera:
|
|
||||||
mYaw -= (XAmount * mLookSpeed * 0.3f);
|
mViewOutdated = true;
|
||||||
mPitch -= (YAmount * mLookSpeed * 0.3f);
|
mFrustumPlanesOutdated = true;
|
||||||
mViewOutdated = true;
|
|
||||||
mFrustumPlanesOutdated = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCamera::Zoom(float Amount)
|
void CCamera::Zoom(float Amount)
|
||||||
{
|
{
|
||||||
mPosition += (mDirection * Amount) * (mMoveSpeed * 25.f);
|
if (mMode == eFreeCamera)
|
||||||
|
{
|
||||||
|
Update();
|
||||||
|
mPosition += (mDirection * Amount) * (mMoveSpeed * 25.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
mOrbitDistance -= Amount * mMoveSpeed * 25.f;
|
||||||
|
|
||||||
mViewOutdated = true;
|
mViewOutdated = true;
|
||||||
mFrustumPlanesOutdated = true;
|
mFrustumPlanesOutdated = true;
|
||||||
}
|
}
|
||||||
|
@ -98,21 +80,19 @@ void CCamera::Snap(CVector3f Position)
|
||||||
mPitch = 0.0f;
|
mPitch = 0.0f;
|
||||||
mViewOutdated = true;
|
mViewOutdated = true;
|
||||||
mFrustumPlanesOutdated = true;
|
mFrustumPlanesOutdated = true;
|
||||||
CalculateDirection();
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCamera::ProcessKeyInput(EKeyInputs KeyFlags, double DeltaTime)
|
void CCamera::ProcessKeyInput(EKeyInputs KeyFlags, double DeltaTime)
|
||||||
{
|
{
|
||||||
float FDeltaTime = (float) DeltaTime;
|
float FDeltaTime = (float) DeltaTime;
|
||||||
if (mMode == eFreeCamera)
|
|
||||||
{
|
if (KeyFlags & eWKey) Zoom(FDeltaTime);
|
||||||
if (KeyFlags & eWKey) Zoom(FDeltaTime);
|
if (KeyFlags & eSKey) Zoom(-FDeltaTime);
|
||||||
if (KeyFlags & eSKey) Zoom(-FDeltaTime);
|
if (KeyFlags & eQKey) Pan(0, -FDeltaTime * 25.f);
|
||||||
if (KeyFlags & eQKey) Pan(0, -FDeltaTime * 25.f);
|
if (KeyFlags & eEKey) Pan(0, FDeltaTime * 25.f);
|
||||||
if (KeyFlags & eEKey) Pan(0, FDeltaTime * 25.f);
|
if (KeyFlags & eAKey) Pan(-FDeltaTime * 25.f, 0);
|
||||||
if (KeyFlags & eAKey) Pan(-FDeltaTime * 25.f, 0);
|
if (KeyFlags & eDKey) Pan(FDeltaTime * 25.f, 0);
|
||||||
if (KeyFlags & eDKey) Pan(FDeltaTime * 25.f, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCamera::ProcessMouseInput(EKeyInputs KeyFlags, EMouseInputs MouseFlags, float XMovement, float YMovement)
|
void CCamera::ProcessMouseInput(EKeyInputs KeyFlags, EMouseInputs MouseFlags, float XMovement, float YMovement)
|
||||||
|
@ -132,14 +112,9 @@ void CCamera::ProcessMouseInput(EKeyInputs KeyFlags, EMouseInputs MouseFlags, fl
|
||||||
// Orbit Camera
|
// Orbit Camera
|
||||||
else if (mMode == eOrbitCamera)
|
else if (mMode == eOrbitCamera)
|
||||||
{
|
{
|
||||||
if ((MouseFlags & eMiddleButton) && (KeyFlags & eCtrlKey))
|
if ((MouseFlags & eMiddleButton) || (MouseFlags & eRightButton))
|
||||||
Zoom(-YMovement * 0.2f);
|
Pan(-XMovement, YMovement);
|
||||||
|
|
||||||
else if ((MouseFlags & eMiddleButton) || (MouseFlags & eRightButton))
|
|
||||||
Pan(XMovement, YMovement);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CalculateDirection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CRay CCamera::CastRay(CVector2f DeviceCoords)
|
CRay CCamera::CastRay(CVector2f DeviceCoords)
|
||||||
|
@ -156,6 +131,52 @@ CRay CCamera::CastRay(CVector2f DeviceCoords)
|
||||||
return Ray;
|
return Ray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCamera::SetMoveMode(ECameraMoveMode Mode)
|
||||||
|
{
|
||||||
|
mMode = Mode;
|
||||||
|
mViewOutdated = true;
|
||||||
|
mFrustumPlanesOutdated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCamera::SetOrbit(const CVector3f& OrbitTarget, float Distance)
|
||||||
|
{
|
||||||
|
mOrbitTarget = OrbitTarget;
|
||||||
|
mOrbitDistance = Distance;
|
||||||
|
|
||||||
|
if (mMode == eOrbitCamera)
|
||||||
|
{
|
||||||
|
mViewOutdated = true;
|
||||||
|
mFrustumPlanesOutdated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCamera::SetOrbit(const CAABox& OrbitTarget, float DistScale /*= 2.5f*/)
|
||||||
|
{
|
||||||
|
CVector3f Min = OrbitTarget.Min();
|
||||||
|
CVector3f Max = OrbitTarget.Max();
|
||||||
|
|
||||||
|
mOrbitTarget = OrbitTarget.Center();
|
||||||
|
mOrbitDistance = ((Max.x - Min.x) + (Max.y - Min.y) + (Max.z - Min.z)) / 3.f;
|
||||||
|
mOrbitDistance *= DistScale;
|
||||||
|
|
||||||
|
if (mMode == eOrbitCamera)
|
||||||
|
{
|
||||||
|
mViewOutdated = true;
|
||||||
|
mFrustumPlanesOutdated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCamera::SetOrbitDistance(float Distance)
|
||||||
|
{
|
||||||
|
mOrbitDistance = Distance;
|
||||||
|
|
||||||
|
if (mMode == eOrbitCamera)
|
||||||
|
{
|
||||||
|
mViewOutdated = true;
|
||||||
|
mFrustumPlanesOutdated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CCamera::LoadMatrices()
|
void CCamera::LoadMatrices()
|
||||||
{
|
{
|
||||||
CGraphics::sMVPBlock.ViewMatrix = ViewMatrix();
|
CGraphics::sMVPBlock.ViewMatrix = ViewMatrix();
|
||||||
|
@ -199,10 +220,15 @@ float CCamera::FieldOfView() const
|
||||||
return 55.f;
|
return 55.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ECameraMoveMode CCamera::MoveMode() const
|
||||||
|
{
|
||||||
|
return mMode;
|
||||||
|
}
|
||||||
|
|
||||||
const CMatrix4f& CCamera::ViewMatrix()
|
const CMatrix4f& CCamera::ViewMatrix()
|
||||||
{
|
{
|
||||||
if (mViewOutdated)
|
if (mViewOutdated)
|
||||||
CalculateView();
|
UpdateView();
|
||||||
|
|
||||||
return mCachedViewMatrix;
|
return mCachedViewMatrix;
|
||||||
}
|
}
|
||||||
|
@ -210,7 +236,7 @@ const CMatrix4f& CCamera::ViewMatrix()
|
||||||
const CMatrix4f& CCamera::ProjectionMatrix()
|
const CMatrix4f& CCamera::ProjectionMatrix()
|
||||||
{
|
{
|
||||||
if (mProjectionOutdated)
|
if (mProjectionOutdated)
|
||||||
CalculateProjection();
|
UpdateProjection();
|
||||||
|
|
||||||
return mCachedProjectionMatrix;
|
return mCachedProjectionMatrix;
|
||||||
}
|
}
|
||||||
|
@ -218,7 +244,7 @@ const CMatrix4f& CCamera::ProjectionMatrix()
|
||||||
const CFrustumPlanes& CCamera::FrustumPlanes()
|
const CFrustumPlanes& CCamera::FrustumPlanes()
|
||||||
{
|
{
|
||||||
if (mFrustumPlanesOutdated)
|
if (mFrustumPlanesOutdated)
|
||||||
CalculateFrustumPlanes();
|
UpdateFrustum();
|
||||||
|
|
||||||
return mCachedFrustumPlanes;
|
return mCachedFrustumPlanes;
|
||||||
}
|
}
|
||||||
|
@ -258,17 +284,6 @@ void CCamera::SetLookSpeed(float LookSpeed)
|
||||||
mLookSpeed = LookSpeed;
|
mLookSpeed = LookSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCamera::SetFree()
|
|
||||||
{
|
|
||||||
mMode = eFreeCamera;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCamera::SetOrbit(const CVector3f& OrbitTarget)
|
|
||||||
{
|
|
||||||
mMode = eOrbitCamera;
|
|
||||||
mOrbitTarget = OrbitTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCamera::SetAspectRatio(float AspectRatio)
|
void CCamera::SetAspectRatio(float AspectRatio)
|
||||||
{
|
{
|
||||||
mAspectRatio = AspectRatio;
|
mAspectRatio = AspectRatio;
|
||||||
|
@ -277,8 +292,9 @@ void CCamera::SetAspectRatio(float AspectRatio)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ************ PRIVATE ************
|
// ************ PRIVATE ************
|
||||||
void CCamera::CalculateDirection()
|
void CCamera::Update()
|
||||||
{
|
{
|
||||||
|
// Update direction
|
||||||
if (mPitch > Math::skHalfPi) mPitch = Math::skHalfPi;
|
if (mPitch > Math::skHalfPi) mPitch = Math::skHalfPi;
|
||||||
if (mPitch < -Math::skHalfPi) mPitch = -Math::skHalfPi;
|
if (mPitch < -Math::skHalfPi) mPitch = -Math::skHalfPi;
|
||||||
|
|
||||||
|
@ -295,12 +311,22 @@ void CCamera::CalculateDirection()
|
||||||
);
|
);
|
||||||
|
|
||||||
mUpVector = mRightVector.Cross(mDirection);
|
mUpVector = mRightVector.Cross(mDirection);
|
||||||
|
|
||||||
|
// Update position
|
||||||
|
if (mMode == eOrbitCamera)
|
||||||
|
{
|
||||||
|
if (mOrbitDistance < 1.f) mOrbitDistance = 1.f;
|
||||||
|
mPosition = mOrbitTarget + (mDirection * -mOrbitDistance);
|
||||||
|
}
|
||||||
|
|
||||||
|
mViewOutdated = true;
|
||||||
|
mFrustumPlanesOutdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCamera::CalculateView()
|
void CCamera::UpdateView()
|
||||||
{
|
{
|
||||||
// todo: don't use glm
|
// todo: don't use glm
|
||||||
CalculateDirection();
|
Update();
|
||||||
|
|
||||||
glm::vec3 glmpos(mPosition.x, mPosition.y, mPosition.z);
|
glm::vec3 glmpos(mPosition.x, mPosition.y, mPosition.z);
|
||||||
glm::vec3 glmdir(mDirection.x, mDirection.y, mDirection.z);
|
glm::vec3 glmdir(mDirection.x, mDirection.y, mDirection.z);
|
||||||
|
@ -309,13 +335,13 @@ void CCamera::CalculateView()
|
||||||
mViewOutdated = false;
|
mViewOutdated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCamera::CalculateProjection()
|
void CCamera::UpdateProjection()
|
||||||
{
|
{
|
||||||
mCachedProjectionMatrix = Math::PerspectiveMatrix(55.f, mAspectRatio, 0.1f, 4096.f);
|
mCachedProjectionMatrix = Math::PerspectiveMatrix(55.f, mAspectRatio, 0.1f, 4096.f);
|
||||||
mProjectionOutdated = false;
|
mProjectionOutdated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCamera::CalculateFrustumPlanes()
|
void CCamera::UpdateFrustum()
|
||||||
{
|
{
|
||||||
mCachedFrustumPlanes.SetPlanes(mPosition, mDirection, 55.f, mAspectRatio, 0.1f, 4096.f);
|
mCachedFrustumPlanes.SetPlanes(mPosition, mDirection, 55.f, mAspectRatio, 0.1f, 4096.f);
|
||||||
mFrustumPlanesOutdated = false;
|
mFrustumPlanesOutdated = false;
|
||||||
|
|
|
@ -28,6 +28,7 @@ class CCamera
|
||||||
float mYaw;
|
float mYaw;
|
||||||
float mPitch;
|
float mPitch;
|
||||||
CVector3f mOrbitTarget;
|
CVector3f mOrbitTarget;
|
||||||
|
float mOrbitDistance;
|
||||||
float mMoveSpeed;
|
float mMoveSpeed;
|
||||||
float mLookSpeed;
|
float mLookSpeed;
|
||||||
|
|
||||||
|
@ -51,6 +52,11 @@ public:
|
||||||
CRay CastRay(CVector2f DeviceCoords);
|
CRay CastRay(CVector2f DeviceCoords);
|
||||||
void LoadMatrices();
|
void LoadMatrices();
|
||||||
|
|
||||||
|
void SetMoveMode(ECameraMoveMode Mode);
|
||||||
|
void SetOrbit(const CVector3f& OrbitTarget, float Distance);
|
||||||
|
void SetOrbit(const CAABox& OrbitTarget, float DistScale = 2.5f);
|
||||||
|
void SetOrbitDistance(float Distance);
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
CVector3f Position() const;
|
CVector3f Position() const;
|
||||||
CVector3f Direction() const;
|
CVector3f Direction() const;
|
||||||
|
@ -59,6 +65,7 @@ public:
|
||||||
float Yaw() const;
|
float Yaw() const;
|
||||||
float Pitch() const;
|
float Pitch() const;
|
||||||
float FieldOfView() const;
|
float FieldOfView() const;
|
||||||
|
ECameraMoveMode MoveMode() const;
|
||||||
const CMatrix4f& ViewMatrix();
|
const CMatrix4f& ViewMatrix();
|
||||||
const CMatrix4f& ProjectionMatrix();
|
const CMatrix4f& ProjectionMatrix();
|
||||||
const CFrustumPlanes& FrustumPlanes();
|
const CFrustumPlanes& FrustumPlanes();
|
||||||
|
@ -70,17 +77,14 @@ public:
|
||||||
void SetPitch(float Pitch);
|
void SetPitch(float Pitch);
|
||||||
void SetMoveSpeed(float MoveSpeed);
|
void SetMoveSpeed(float MoveSpeed);
|
||||||
void SetLookSpeed(float LookSpeed);
|
void SetLookSpeed(float LookSpeed);
|
||||||
void SetFree();
|
|
||||||
void SetOrbit(const CVector3f& OrbitTarget);
|
|
||||||
void SetOrbit(const CAABox& OrbitTarget);
|
|
||||||
void SetAspectRatio(float AspectRatio);
|
void SetAspectRatio(float AspectRatio);
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
private:
|
private:
|
||||||
void CalculateDirection();
|
void Update();
|
||||||
void CalculateView();
|
void UpdateView();
|
||||||
void CalculateProjection();
|
void UpdateProjection();
|
||||||
void CalculateFrustumPlanes();
|
void UpdateFrustum();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CCAMERA_H
|
#endif // CCAMERA_H
|
||||||
|
|
|
@ -47,8 +47,8 @@ public:
|
||||||
void mouseReleaseEvent(QMouseEvent *pEvent);
|
void mouseReleaseEvent(QMouseEvent *pEvent);
|
||||||
void mouseMoveEvent(QMouseEvent *pEvent);
|
void mouseMoveEvent(QMouseEvent *pEvent);
|
||||||
void wheelEvent(QWheelEvent *pEvent);
|
void wheelEvent(QWheelEvent *pEvent);
|
||||||
void keyPressEvent(QKeyEvent *pEvent);
|
virtual void keyPressEvent(QKeyEvent *pEvent);
|
||||||
void keyReleaseEvent(QKeyEvent *pEvent);
|
virtual void keyReleaseEvent(QKeyEvent *pEvent);
|
||||||
void focusOutEvent(QFocusEvent *pEvent);
|
void focusOutEvent(QFocusEvent *pEvent);
|
||||||
void contextMenuEvent(QContextMenuEvent *pEvent);
|
void contextMenuEvent(QContextMenuEvent *pEvent);
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,8 @@ CModelEditorWindow::CModelEditorWindow(QWidget *parent) :
|
||||||
|
|
||||||
CCamera& camera = ui->Viewport->Camera();
|
CCamera& camera = ui->Viewport->Camera();
|
||||||
camera.Snap(CVector3f(0, 3, 1));
|
camera.Snap(CVector3f(0, 3, 1));
|
||||||
camera.SetFree();
|
camera.SetMoveMode(eOrbitCamera);
|
||||||
|
camera.SetOrbit(CVector3f(0, 0, 1), 3.f);
|
||||||
camera.SetMoveSpeed(0.5f);
|
camera.SetMoveSpeed(0.5f);
|
||||||
|
|
||||||
// UI initialization
|
// UI initialization
|
||||||
|
@ -153,6 +154,7 @@ void CModelEditorWindow::SetActiveModel(CModel *pModel)
|
||||||
mpCurrentModelNode->MarkTransformChanged();
|
mpCurrentModelNode->MarkTransformChanged();
|
||||||
mpCurrentModel = pModel;
|
mpCurrentModel = pModel;
|
||||||
mModelToken = CToken(pModel);
|
mModelToken = CToken(pModel);
|
||||||
|
ui->Viewport->Camera().SetOrbit(pModel->AABox());
|
||||||
|
|
||||||
u32 numVertices = (pModel ? pModel->GetVertexCount() : 0);
|
u32 numVertices = (pModel ? pModel->GetVertexCount() : 0);
|
||||||
u32 numTriangles = (pModel ? pModel->GetTriangleCount() : 0);
|
u32 numTriangles = (pModel ? pModel->GetTriangleCount() : 0);
|
||||||
|
@ -807,3 +809,26 @@ void CModelEditorWindow::on_actionSave_as_triggered()
|
||||||
TString name = TString(filename.toStdString());
|
TString name = TString(filename.toStdString());
|
||||||
setWindowTitle("Prime World Editor - Model Editor: " + TO_QSTRING(name));
|
setWindowTitle("Prime World Editor - Model Editor: " + TO_QSTRING(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CModelEditorWindow::on_CameraModeButton_clicked()
|
||||||
|
{
|
||||||
|
CCamera *pCam = &ui->Viewport->Camera();
|
||||||
|
|
||||||
|
if (pCam->MoveMode() == eOrbitCamera)
|
||||||
|
{
|
||||||
|
pCam->SetMoveMode(eFreeCamera);
|
||||||
|
ui->CameraModeButton->setIcon(QIcon(":/icons/EditorAssets/Free Camera.png"));
|
||||||
|
ui->CameraModeButton->setToolTip(QString("Free Camera"));
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (pCam->MoveMode() == eFreeCamera)
|
||||||
|
{
|
||||||
|
pCam->SetMoveMode(eOrbitCamera);
|
||||||
|
ui->CameraModeButton->setIcon(QIcon(":/icons/EditorAssets/Orbit Camera v2.png"));
|
||||||
|
ui->CameraModeButton->setToolTip(QString("Orbit Camera"));
|
||||||
|
|
||||||
|
CVector3f Pos = pCam->Position();
|
||||||
|
CVector3f Target = mpCurrentModelNode->AABox().Center();
|
||||||
|
pCam->SetOrbitDistance(Pos.Distance(Target));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -115,6 +115,8 @@ private slots:
|
||||||
|
|
||||||
void on_actionSave_as_triggered();
|
void on_actionSave_as_triggered();
|
||||||
|
|
||||||
|
void on_CameraModeButton_clicked();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void Closed();
|
void Closed();
|
||||||
};
|
};
|
||||||
|
|
|
@ -2140,7 +2140,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,0,0,0,0,0,0,0">
|
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,0,0,0,0,0,0,0,0">
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
<number>50</number>
|
<number>50</number>
|
||||||
</property>
|
</property>
|
||||||
|
@ -2227,6 +2227,32 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="CameraModeButton">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Orbit Camera</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../Icons.qrc">
|
||||||
|
<normaloff>:/icons/EditorAssets/Orbit Camera.png</normaloff>:/icons/EditorAssets/Orbit Camera.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="iconSize">
|
||||||
|
<size>
|
||||||
|
<width>32</width>
|
||||||
|
<height>32</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="flat">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="Line" name="line">
|
<widget class="Line" name="line">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|
|
@ -109,6 +109,26 @@ bool CSceneViewport::IsHoveringGizmo()
|
||||||
return mGizmoHovering;
|
return mGizmoHovering;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSceneViewport::keyPressEvent(QKeyEvent* pEvent)
|
||||||
|
{
|
||||||
|
CBasicViewport::keyPressEvent(pEvent);
|
||||||
|
|
||||||
|
if (pEvent->key() == Qt::Key_Z)
|
||||||
|
{
|
||||||
|
mCamera.SetMoveMode(eOrbitCamera);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSceneViewport::keyReleaseEvent(QKeyEvent* pEvent)
|
||||||
|
{
|
||||||
|
CBasicViewport::keyReleaseEvent(pEvent);
|
||||||
|
|
||||||
|
if (pEvent->key() == Qt::Key_Z)
|
||||||
|
{
|
||||||
|
mCamera.SetMoveMode(eFreeCamera);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ************ PROTECTED SLOTS ************
|
// ************ PROTECTED SLOTS ************
|
||||||
void CSceneViewport::CheckUserInput()
|
void CSceneViewport::CheckUserInput()
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,6 +34,9 @@ public:
|
||||||
void ResetHover();
|
void ResetHover();
|
||||||
bool IsHoveringGizmo();
|
bool IsHoveringGizmo();
|
||||||
|
|
||||||
|
void keyPressEvent(QKeyEvent* pEvent);
|
||||||
|
void keyReleaseEvent(QKeyEvent* pEvent);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void GizmoMoved();
|
void GizmoMoved();
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,7 @@ void CWorldEditor::SetArea(CWorld *pWorld, CGameArea *pArea)
|
||||||
ui->ModifyTabContents->ClearCachedEditors();
|
ui->ModifyTabContents->ClearCachedEditors();
|
||||||
ui->InstancesTabContents->SetMaster(nullptr);
|
ui->InstancesTabContents->SetMaster(nullptr);
|
||||||
ui->InstancesTabContents->SetArea(pArea);
|
ui->InstancesTabContents->SetArea(pArea);
|
||||||
|
mUndoStack.clear();
|
||||||
|
|
||||||
// Clear old area - hack until better world/area loader is implemented
|
// Clear old area - hack until better world/area loader is implemented
|
||||||
if ((mpArea) && (pArea != mpArea))
|
if ((mpArea) && (pArea != mpArea))
|
||||||
|
@ -109,10 +110,17 @@ void CWorldEditor::SetArea(CWorld *pWorld, CGameArea *pArea)
|
||||||
mScene.SetActiveWorld(pWorld);
|
mScene.SetActiveWorld(pWorld);
|
||||||
mScene.SetActiveArea(pArea);
|
mScene.SetActiveArea(pArea);
|
||||||
|
|
||||||
// Snap camera to location of area
|
// Snap camera to new area
|
||||||
CTransform4f AreaTransform = pArea->GetTransform();
|
CCamera *pCamera = &ui->MainViewport->Camera();
|
||||||
CVector3f AreaPosition(AreaTransform[0][3], AreaTransform[1][3], AreaTransform[2][3]);
|
|
||||||
ui->MainViewport->Camera().Snap(AreaPosition);
|
if (pCamera->MoveMode() == eFreeCamera)
|
||||||
|
{
|
||||||
|
CTransform4f AreaTransform = pArea->GetTransform();
|
||||||
|
CVector3f AreaPosition(AreaTransform[0][3], AreaTransform[1][3], AreaTransform[2][3]);
|
||||||
|
pCamera->Snap(AreaPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateCameraOrbit();
|
||||||
|
|
||||||
// Default bloom to Fake Bloom for Metroid Prime 3; disable for other games
|
// Default bloom to Fake Bloom for Metroid Prime 3; disable for other games
|
||||||
if (mpWorld->Version() == eCorruption)
|
if (mpWorld->Version() == eCorruption)
|
||||||
|
@ -137,63 +145,7 @@ CGameArea* CWorldEditor::ActiveArea()
|
||||||
return mpArea;
|
return mpArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ************ SLOTS ************
|
// ************ UPDATE UI ************
|
||||||
void CWorldEditor::UpdateCursor()
|
|
||||||
{
|
|
||||||
if (ui->MainViewport->IsCursorVisible())
|
|
||||||
{
|
|
||||||
CSceneNode *pHoverNode = ui->MainViewport->HoverNode();
|
|
||||||
|
|
||||||
if (ui->MainViewport->IsHoveringGizmo())
|
|
||||||
ui->MainViewport->SetCursorState(Qt::SizeAllCursor);
|
|
||||||
else if ((pHoverNode) && (pHoverNode->NodeType() != eStaticNode))
|
|
||||||
ui->MainViewport->SetCursorState(Qt::PointingHandCursor);
|
|
||||||
else
|
|
||||||
ui->MainViewport->SetCursorState(Qt::ArrowCursor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CWorldEditor::UpdateStatusBar()
|
|
||||||
{
|
|
||||||
// Would be cool to do more frequent status bar updates with more info. Unfortunately, this causes lag.
|
|
||||||
QString StatusText = "";
|
|
||||||
|
|
||||||
if (!mGizmoHovering)
|
|
||||||
{
|
|
||||||
if (ui->MainViewport->underMouse())
|
|
||||||
{
|
|
||||||
CSceneNode *pHoverNode = ui->MainViewport->HoverNode();
|
|
||||||
|
|
||||||
if (pHoverNode && (pHoverNode->NodeType() != eStaticNode))
|
|
||||||
StatusText = TO_QSTRING(pHoverNode->Name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ui->statusbar->currentMessage() != StatusText)
|
|
||||||
ui->statusbar->showMessage(StatusText);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CWorldEditor::UpdateSelectionUI()
|
|
||||||
{
|
|
||||||
// Update sidebar
|
|
||||||
ui->ModifyTabContents->GenerateUI(mSelection);
|
|
||||||
|
|
||||||
// Update selection info text
|
|
||||||
QString SelectionText;
|
|
||||||
|
|
||||||
if (mSelection.size() == 1)
|
|
||||||
SelectionText = TO_QSTRING(mSelection.front()->Name());
|
|
||||||
else if (mSelection.size() > 1)
|
|
||||||
SelectionText = QString("%1 objects selected").arg(mSelection.size());
|
|
||||||
|
|
||||||
QFontMetrics Metrics(ui->SelectionInfoLabel->font());
|
|
||||||
SelectionText = Metrics.elidedText(SelectionText, Qt::ElideRight, ui->SelectionInfoFrame->width() - 10);
|
|
||||||
ui->SelectionInfoLabel->setText(SelectionText);
|
|
||||||
|
|
||||||
// Update gizmo stuff
|
|
||||||
UpdateGizmoUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CWorldEditor::UpdateGizmoUI()
|
void CWorldEditor::UpdateGizmoUI()
|
||||||
{
|
{
|
||||||
// Update transform XYZ spin boxes
|
// Update transform XYZ spin boxes
|
||||||
|
@ -248,13 +200,83 @@ void CWorldEditor::UpdateGizmoUI()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CWorldEditor::UpdateSelectionUI()
|
||||||
|
{
|
||||||
|
// Update camera orbit
|
||||||
|
UpdateCameraOrbit();
|
||||||
|
|
||||||
|
// Update sidebar
|
||||||
|
ui->ModifyTabContents->GenerateUI(mSelection);
|
||||||
|
|
||||||
|
// Update selection info text
|
||||||
|
QString SelectionText;
|
||||||
|
|
||||||
|
if (mSelection.size() == 1)
|
||||||
|
SelectionText = TO_QSTRING(mSelection.front()->Name());
|
||||||
|
else if (mSelection.size() > 1)
|
||||||
|
SelectionText = QString("%1 objects selected").arg(mSelection.size());
|
||||||
|
|
||||||
|
QFontMetrics Metrics(ui->SelectionInfoLabel->font());
|
||||||
|
SelectionText = Metrics.elidedText(SelectionText, Qt::ElideRight, ui->SelectionInfoFrame->width() - 10);
|
||||||
|
ui->SelectionInfoLabel->setText(SelectionText);
|
||||||
|
|
||||||
|
// Update gizmo stuff
|
||||||
|
UpdateGizmoUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWorldEditor::UpdateStatusBar()
|
||||||
|
{
|
||||||
|
// Would be cool to do more frequent status bar updates with more info. Unfortunately, this causes lag.
|
||||||
|
QString StatusText = "";
|
||||||
|
|
||||||
|
if (!mGizmoHovering)
|
||||||
|
{
|
||||||
|
if (ui->MainViewport->underMouse())
|
||||||
|
{
|
||||||
|
CSceneNode *pHoverNode = ui->MainViewport->HoverNode();
|
||||||
|
|
||||||
|
if (pHoverNode && (pHoverNode->NodeType() != eStaticNode))
|
||||||
|
StatusText = TO_QSTRING(pHoverNode->Name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ui->statusbar->currentMessage() != StatusText)
|
||||||
|
ui->statusbar->showMessage(StatusText);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************ PROTECTED ************
|
||||||
void CWorldEditor::GizmoModeChanged(CGizmo::EGizmoMode mode)
|
void CWorldEditor::GizmoModeChanged(CGizmo::EGizmoMode mode)
|
||||||
{
|
{
|
||||||
ui->TransformSpinBox->SetSingleStep( (mode == CGizmo::eRotate ? 1.0 : 0.1) );
|
ui->TransformSpinBox->SetSingleStep( (mode == CGizmo::eRotate ? 1.0 : 0.1) );
|
||||||
ui->TransformSpinBox->SetDefaultValue( (mode == CGizmo::eScale ? 1.0 : 0.0) );
|
ui->TransformSpinBox->SetDefaultValue( (mode == CGizmo::eScale ? 1.0 : 0.0) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ************ ACTIONS ************
|
void CWorldEditor::UpdateCursor()
|
||||||
|
{
|
||||||
|
if (ui->MainViewport->IsCursorVisible())
|
||||||
|
{
|
||||||
|
CSceneNode *pHoverNode = ui->MainViewport->HoverNode();
|
||||||
|
|
||||||
|
if (ui->MainViewport->IsHoveringGizmo())
|
||||||
|
ui->MainViewport->SetCursorState(Qt::SizeAllCursor);
|
||||||
|
else if ((pHoverNode) && (pHoverNode->NodeType() != eStaticNode))
|
||||||
|
ui->MainViewport->SetCursorState(Qt::PointingHandCursor);
|
||||||
|
else
|
||||||
|
ui->MainViewport->SetCursorState(Qt::ArrowCursor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CWorldEditor::UpdateCameraOrbit()
|
||||||
|
{
|
||||||
|
CCamera *pCamera = &ui->MainViewport->Camera();
|
||||||
|
|
||||||
|
if (!mSelection.isEmpty())
|
||||||
|
pCamera->SetOrbit(mSelectionBounds);
|
||||||
|
else
|
||||||
|
pCamera->SetOrbit(mpArea->AABox(), 0.8f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************ PRIVATE SLOTS ************
|
||||||
void CWorldEditor::RefreshViewport()
|
void CWorldEditor::RefreshViewport()
|
||||||
{
|
{
|
||||||
if (!mGizmo.IsTransforming())
|
if (!mGizmo.IsTransforming())
|
||||||
|
@ -413,37 +435,6 @@ void CWorldEditor::on_ActionBloom_triggered()
|
||||||
ui->ActionBloom->setChecked(true);
|
ui->ActionBloom->setChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWorldEditor::on_ActionZoomOnSelection_triggered()
|
|
||||||
{
|
|
||||||
static const float skDistScale = 2.5f;
|
|
||||||
static const float skAreaDistScale = 0.8f;
|
|
||||||
|
|
||||||
CCamera& Camera = ui->MainViewport->Camera();
|
|
||||||
CVector3f CamDir = Camera.Direction();
|
|
||||||
CVector3f NewPos;
|
|
||||||
|
|
||||||
// Zoom on selection
|
|
||||||
if (mSelection.size() != 0)
|
|
||||||
{
|
|
||||||
CVector3f Min = mSelectionBounds.Min();
|
|
||||||
CVector3f Max = mSelectionBounds.Max();
|
|
||||||
float Dist = ((Max.x - Min.x) + (Max.y - Min.y) + (Max.z - Min.z)) / 3.f;
|
|
||||||
NewPos = mSelectionBounds.Center() + (CamDir * -(Dist * skDistScale));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Zoom on area
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CAABox AreaBox = mpArea->AABox();
|
|
||||||
CVector3f Min = AreaBox.Min();
|
|
||||||
CVector3f Max = AreaBox.Max();
|
|
||||||
float Dist = ((Max.x - Min.x) + (Max.y - Min.y) + (Max.z - Min.z)) / 3.f;
|
|
||||||
NewPos = AreaBox.Center() + (CamDir * -(Dist * skAreaDistScale));
|
|
||||||
}
|
|
||||||
|
|
||||||
Camera.SetPosition(NewPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CWorldEditor::on_ActionDisableBackfaceCull_triggered()
|
void CWorldEditor::on_ActionDisableBackfaceCull_triggered()
|
||||||
{
|
{
|
||||||
ui->MainViewport->Renderer()->ToggleBackfaceCull(!ui->ActionDisableBackfaceCull->isChecked());
|
ui->MainViewport->Renderer()->ToggleBackfaceCull(!ui->ActionDisableBackfaceCull->isChecked());
|
||||||
|
|
|
@ -50,10 +50,8 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void GizmoModeChanged(CGizmo::EGizmoMode mode);
|
void GizmoModeChanged(CGizmo::EGizmoMode mode);
|
||||||
|
|
||||||
private:
|
|
||||||
void UpdateCursor();
|
void UpdateCursor();
|
||||||
void OnSidebarResize();
|
void UpdateCameraOrbit();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void RefreshViewport();
|
void RefreshViewport();
|
||||||
|
@ -72,7 +70,6 @@ private slots:
|
||||||
void on_ActionBloomMaps_triggered();
|
void on_ActionBloomMaps_triggered();
|
||||||
void on_ActionFakeBloom_triggered();
|
void on_ActionFakeBloom_triggered();
|
||||||
void on_ActionBloom_triggered();
|
void on_ActionBloom_triggered();
|
||||||
void on_ActionZoomOnSelection_triggered();
|
|
||||||
void on_ActionDisableBackfaceCull_triggered();
|
void on_ActionDisableBackfaceCull_triggered();
|
||||||
void on_ActionDisableAlpha_triggered();
|
void on_ActionDisableAlpha_triggered();
|
||||||
void on_ActionEditLayers_triggered();
|
void on_ActionEditLayers_triggered();
|
||||||
|
|
|
@ -267,8 +267,6 @@
|
||||||
<addaction name="ActionFakeBloom"/>
|
<addaction name="ActionFakeBloom"/>
|
||||||
<addaction name="ActionBloom"/>
|
<addaction name="ActionBloom"/>
|
||||||
</widget>
|
</widget>
|
||||||
<addaction name="ActionZoomOnSelection"/>
|
|
||||||
<addaction name="separator"/>
|
|
||||||
<addaction name="ActionDrawWorld"/>
|
<addaction name="ActionDrawWorld"/>
|
||||||
<addaction name="ActionDrawObjects"/>
|
<addaction name="ActionDrawObjects"/>
|
||||||
<addaction name="ActionDrawCollision"/>
|
<addaction name="ActionDrawCollision"/>
|
||||||
|
|
Loading…
Reference in New Issue