From 55b46c5c768a62886e5819d83649a60f79759385 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Tue, 15 Dec 2015 12:22:47 +0200 Subject: [PATCH] Added: Option to set radar to follow camera --HG-- branch : develop --- .../gamedev/interfaces_v3/game_config.xml | 13 +++++ .../client/src/interface_v3/group_compas.cpp | 48 ++++++++++++++++++- .../client/src/interface_v3/group_compas.h | 11 +++++ .../client/src/interface_v3/view_radar.cpp | 21 +++++++- .../client/src/interface_v3/view_radar.h | 3 ++ 5 files changed, 92 insertions(+), 4 deletions(-) diff --git a/code/ryzom/client/data/gamedev/interfaces_v3/game_config.xml b/code/ryzom/client/data/gamedev/interfaces_v3/game_config.xml index ca68212cf..0995c64c9 100644 --- a/code/ryzom/client/data/gamedev/interfaces_v3/game_config.xml +++ b/code/ryzom/client/data/gamedev/interfaces_v3/game_config.xml @@ -1415,6 +1415,14 @@ posparent="show_clock_12h" x="0" y="-12" /> + + getDbProp("UI:SAVE:RADAR:USE_CAMERA"); + if (pRC) + { + ICDBNode::CTextId textId; + pRC->addObserver( &_UseCameraObs, textId); + } } // *************************************************************************** CGroupCompas::~CGroupCompas() { + CCDBNodeLeaf *pRC = CDBManager::getInstance()->getDbProp("UI:SAVE:RADAR:USE_CAMERA"); + if (pRC) + { + ICDBNode::CTextId textId; + pRC->removeObserver( &_UseCameraObs, textId); + } } @@ -225,12 +239,37 @@ void CGroupCompas::draw() { if ((uint) _Target.getType() >= CCompassTarget::NumTypes) return; CInterfaceManager *im = CInterfaceManager::getInstance(); + + if (_RadarView && _UseCameraObs._changed) + { + _UseCameraObs._changed = false; + _RadarView->setUseCamera(_UseCameraObs._useCamera); + } + // const NLMISC::CVectorD &userPosD = UserEntity->pos(); NLMISC::CVector userPos((float) userPosD.x, (float) userPosD.y, (float) userPosD.z); NLMISC::CVector2f targetPos(0.f, 0.f); // if a position tracker is provided, use it CCompassTarget displayedTarget = _Target; + float myAngle; + + if (_UseCameraObs._useCamera) + { + CVector projectedFront = MainCam.getMatrix().getJ(); + if (projectedFront.norm() <= 0.01f) + { + projectedFront = MainCam.getMatrix().getK(); + projectedFront.z = 0.f; + } + CVector cam = projectedFront.normed(); + myAngle = (float)atan2(cam.y, cam.x); + } + else + { + const CVector &front = UserEntity->front(); + myAngle = (float)atan2 (front.y, front.x); + } switch(_Target.getType()) { @@ -332,8 +371,6 @@ void CGroupCompas::draw() _ArrowShape->getShape().getMaterial(0).setDiffuse(color); // Set angle - const CVector &front = UserEntity->front(); - float myAngle = (float)atan2 (front.y, front.x); float deltaX = targetPos.x - userPos.x; float deltaY = targetPos.y - userPos.y; float targetAngle = (float)atan2 (deltaY, deltaX); @@ -496,6 +533,13 @@ bool CGroupCompas::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup) return true; } +// *************************************************************************** +void CGroupCompas::CDBUseCameraObs::update( NLMISC::ICDBNode *node) +{ + _changed = true; + _useCamera = ((CCDBNodeLeaf*)node)->getValueBool(); +} + // *************************************************************************** bool buildCompassTargetFromTeamMember(CCompassTarget &ct, uint teamMemberId) { diff --git a/code/ryzom/client/src/interface_v3/group_compas.h b/code/ryzom/client/src/interface_v3/group_compas.h index 4e4830aa2..e122866c7 100644 --- a/code/ryzom/client/src/interface_v3/group_compas.h +++ b/code/ryzom/client/src/interface_v3/group_compas.h @@ -132,6 +132,17 @@ private: uint32 _RadarPos; NLMISC::CVector2f getNorthPos(const NLMISC::CVector2f &userPos) const; + + class CDBUseCameraObs : public NLMISC::ICDBNode::IPropertyObserver + { + public: + CDBUseCameraObs():_useCamera(false),_changed(false) + { } + virtual void update( NLMISC::ICDBNode *node); + bool _useCamera; + bool _changed; + }; + CDBUseCameraObs _UseCameraObs; }; /** diff --git a/code/ryzom/client/src/interface_v3/view_radar.cpp b/code/ryzom/client/src/interface_v3/view_radar.cpp index 073318ec8..718e2430a 100644 --- a/code/ryzom/client/src/interface_v3/view_radar.cpp +++ b/code/ryzom/client/src/interface_v3/view_radar.cpp @@ -35,6 +35,8 @@ using namespace std; using namespace NLMISC; using namespace NL3D; +extern NL3D::UCamera MainCam; + NLMISC_REGISTER_OBJECT(CViewBase, CViewRadar, std::string, "radar"); // ---------------------------------------------------------------------------- @@ -127,10 +129,25 @@ void CViewRadar::draw () CEntityCL *user = EntitiesMngr.entity(0); if (user == NULL) return; + float angle; CVectorD xyzRef = user->pos(); - const CVector dir = user->front(); + if (_UseCamera) + { + CVector projectedFront = MainCam.getMatrix().getJ(); + if (projectedFront.norm() <= 0.01f) + { + projectedFront = MainCam.getMatrix().getK(); + projectedFront.z = 0.f; + } + CVector cam = projectedFront.normed(); + angle = (float)(atan2(cam.y, cam.x) - (Pi / 2.0)); + } + else + { + const CVector dir = user->front(); + angle = (float)(atan2(dir.y, dir.x) - (Pi / 2.0)); + } - float angle = (float)(atan2(dir.y, dir.x) - (Pi / 2.0)); CMatrix mat; mat.identity(); // Scale to transform from world to interface screen diff --git a/code/ryzom/client/src/interface_v3/view_radar.h b/code/ryzom/client/src/interface_v3/view_radar.h index 0c45b8136..d218a4890 100644 --- a/code/ryzom/client/src/interface_v3/view_radar.h +++ b/code/ryzom/client/src/interface_v3/view_radar.h @@ -62,9 +62,12 @@ public: void setWorldSize(float f) { _WorldSize = f; } float getWorldSize() const { return (float)_WorldSize; } + void setUseCamera(bool b) { _UseCamera = b; } + protected: double _WorldSize; + bool _UseCamera; struct CRadarSpotDesc {