mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-12 20:24:47 +00:00
Added: Option to set radar to follow camera
This commit is contained in:
parent
fb6af14b28
commit
9450f9bba4
5 changed files with 92 additions and 4 deletions
|
@ -1415,6 +1415,14 @@
|
||||||
posparent="show_clock_12h"
|
posparent="show_clock_12h"
|
||||||
x="0"
|
x="0"
|
||||||
y="-12" />
|
y="-12" />
|
||||||
|
<instance template="tgcw_checkbox"
|
||||||
|
id="radar_use_camera"
|
||||||
|
text="uiRadarUseCamera"
|
||||||
|
tooltip="uittRadarUseCamera"
|
||||||
|
posref="BL TL"
|
||||||
|
posparent="show_reticle"
|
||||||
|
x="0"
|
||||||
|
y="-12" />
|
||||||
</group>
|
</group>
|
||||||
<ctrl style="skin_scroll"
|
<ctrl style="skin_scroll"
|
||||||
id="sb_hud"
|
id="sb_hud"
|
||||||
|
@ -3273,6 +3281,11 @@
|
||||||
widget="boolbut"
|
widget="boolbut"
|
||||||
link="UI:SAVE:SHOW_RETICLE"
|
link="UI:SAVE:SHOW_RETICLE"
|
||||||
realtime="true" />
|
realtime="true" />
|
||||||
|
<param ui="hud:radar_use_camera:c"
|
||||||
|
type="db"
|
||||||
|
widget="boolbut"
|
||||||
|
link="UI:SAVE:RADAR:USE_CAMERA"
|
||||||
|
realtime="true" />
|
||||||
<param ui="alpha_colors:col_day:c"
|
<param ui="alpha_colors:col_day:c"
|
||||||
type="db"
|
type="db"
|
||||||
widget="colbut"
|
widget="colbut"
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "game_share/inventories.h"
|
#include "game_share/inventories.h"
|
||||||
#include "game_share/animal_type.h"
|
#include "game_share/animal_type.h"
|
||||||
|
|
||||||
|
extern NL3D::UCamera MainCam;
|
||||||
extern CEntityManager EntitiesMngr;
|
extern CEntityManager EntitiesMngr;
|
||||||
extern CContinentManager ContinentMngr;
|
extern CContinentManager ContinentMngr;
|
||||||
CCompassDialogsManager * CCompassDialogsManager::_Instance = NULL;
|
CCompassDialogsManager * CCompassDialogsManager::_Instance = NULL;
|
||||||
|
@ -129,11 +130,24 @@ CGroupCompas::CGroupCompas(const TCtorParam ¶m)
|
||||||
_LastDynamicTargetPos = 0xFFFFFFFF;
|
_LastDynamicTargetPos = 0xFFFFFFFF;
|
||||||
_SavedTargetValid = false;
|
_SavedTargetValid = false;
|
||||||
_TargetSetOnce = false;
|
_TargetSetOnce = false;
|
||||||
|
|
||||||
|
CCDBNodeLeaf *pRC = CDBManager::getInstance()->getDbProp("UI:SAVE:RADAR:USE_CAMERA");
|
||||||
|
if (pRC)
|
||||||
|
{
|
||||||
|
ICDBNode::CTextId textId;
|
||||||
|
pRC->addObserver( &_UseCameraObs, textId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
CGroupCompas::~CGroupCompas()
|
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;
|
if ((uint) _Target.getType() >= CCompassTarget::NumTypes) return;
|
||||||
CInterfaceManager *im = CInterfaceManager::getInstance();
|
CInterfaceManager *im = CInterfaceManager::getInstance();
|
||||||
|
|
||||||
|
if (_RadarView && _UseCameraObs._changed)
|
||||||
|
{
|
||||||
|
_UseCameraObs._changed = false;
|
||||||
|
_RadarView->setUseCamera(_UseCameraObs._useCamera);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
const NLMISC::CVectorD &userPosD = UserEntity->pos();
|
const NLMISC::CVectorD &userPosD = UserEntity->pos();
|
||||||
NLMISC::CVector userPos((float) userPosD.x, (float) userPosD.y, (float) userPosD.z);
|
NLMISC::CVector userPos((float) userPosD.x, (float) userPosD.y, (float) userPosD.z);
|
||||||
NLMISC::CVector2f targetPos(0.f, 0.f);
|
NLMISC::CVector2f targetPos(0.f, 0.f);
|
||||||
// if a position tracker is provided, use it
|
// if a position tracker is provided, use it
|
||||||
CCompassTarget displayedTarget = _Target;
|
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())
|
switch(_Target.getType())
|
||||||
{
|
{
|
||||||
|
@ -332,8 +371,6 @@ void CGroupCompas::draw()
|
||||||
_ArrowShape->getShape().getMaterial(0).setDiffuse(color);
|
_ArrowShape->getShape().getMaterial(0).setDiffuse(color);
|
||||||
|
|
||||||
// Set angle
|
// Set angle
|
||||||
const CVector &front = UserEntity->front();
|
|
||||||
float myAngle = (float)atan2 (front.y, front.x);
|
|
||||||
float deltaX = targetPos.x - userPos.x;
|
float deltaX = targetPos.x - userPos.x;
|
||||||
float deltaY = targetPos.y - userPos.y;
|
float deltaY = targetPos.y - userPos.y;
|
||||||
float targetAngle = (float)atan2 (deltaY, deltaX);
|
float targetAngle = (float)atan2 (deltaY, deltaX);
|
||||||
|
@ -496,6 +533,13 @@ bool CGroupCompas::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ***************************************************************************
|
||||||
|
void CGroupCompas::CDBUseCameraObs::update( NLMISC::ICDBNode *node)
|
||||||
|
{
|
||||||
|
_changed = true;
|
||||||
|
_useCamera = ((CCDBNodeLeaf*)node)->getValueBool();
|
||||||
|
}
|
||||||
|
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
bool buildCompassTargetFromTeamMember(CCompassTarget &ct, uint teamMemberId)
|
bool buildCompassTargetFromTeamMember(CCompassTarget &ct, uint teamMemberId)
|
||||||
{
|
{
|
||||||
|
|
|
@ -132,6 +132,17 @@ private:
|
||||||
uint32 _RadarPos;
|
uint32 _RadarPos;
|
||||||
|
|
||||||
NLMISC::CVector2f getNorthPos(const NLMISC::CVector2f &userPos) const;
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -35,6 +35,8 @@ using namespace std;
|
||||||
using namespace NLMISC;
|
using namespace NLMISC;
|
||||||
using namespace NL3D;
|
using namespace NL3D;
|
||||||
|
|
||||||
|
extern NL3D::UCamera MainCam;
|
||||||
|
|
||||||
NLMISC_REGISTER_OBJECT(CViewBase, CViewRadar, std::string, "radar");
|
NLMISC_REGISTER_OBJECT(CViewBase, CViewRadar, std::string, "radar");
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -127,10 +129,25 @@ void CViewRadar::draw ()
|
||||||
CEntityCL *user = EntitiesMngr.entity(0);
|
CEntityCL *user = EntitiesMngr.entity(0);
|
||||||
if (user == NULL) return;
|
if (user == NULL) return;
|
||||||
|
|
||||||
|
float angle;
|
||||||
CVectorD xyzRef = user->pos();
|
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;
|
CMatrix mat;
|
||||||
mat.identity();
|
mat.identity();
|
||||||
// Scale to transform from world to interface screen
|
// Scale to transform from world to interface screen
|
||||||
|
|
|
@ -62,9 +62,12 @@ public:
|
||||||
void setWorldSize(float f) { _WorldSize = f; }
|
void setWorldSize(float f) { _WorldSize = f; }
|
||||||
float getWorldSize() const { return (float)_WorldSize; }
|
float getWorldSize() const { return (float)_WorldSize; }
|
||||||
|
|
||||||
|
void setUseCamera(bool b) { _UseCamera = b; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
double _WorldSize;
|
double _WorldSize;
|
||||||
|
bool _UseCamera;
|
||||||
|
|
||||||
struct CRadarSpotDesc
|
struct CRadarSpotDesc
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue