Added viewer-relative directions

Former-commit-id: 9d80744bd227689426b76df7e3c273de13424041
This commit is contained in:
Lynix
2015-01-03 22:39:51 +01:00
parent 596f407a79
commit ed1cc7a092
11 changed files with 223 additions and 9 deletions

View File

@@ -80,6 +80,21 @@ const NzFrustumf& NzCamera::GetFrustum() const
return m_frustum;
}
NzVector3f NzCamera::GetGlobalForward() const
{
return NzVector3f::Forward();
}
NzVector3f NzCamera::GetGlobalRight() const
{
return NzVector3f::Right();
}
NzVector3f NzCamera::GetGlobalUp() const
{
return NzVector3f::Up();
}
const NzMatrix4f& NzCamera::GetProjectionMatrix() const
{
if (!m_projectionMatrixUpdated)

View File

@@ -134,6 +134,58 @@ NzAbstractBackground* NzScene::GetBackground() const
return m_impl->background.get();
}
NzVector3f NzScene::GetBackward() const
{
#if NAZARA_GRAPHICS_SAFE
if (!m_impl->viewer)
{
NazaraError("No viewer");
return NzVector3f::Backward();
}
#endif
return -m_impl->viewer->GetGlobalForward();
}
NzVector3f NzScene::GetDown() const
{
#if NAZARA_GRAPHICS_SAFE
if (!m_impl->viewer)
{
NazaraError("No viewer");
return NzVector3f::Down();
}
#endif
return -m_impl->viewer->GetGlobalUp();
}
NzVector3f NzScene::GetForward() const
{
#if NAZARA_GRAPHICS_SAFE
if (!m_impl->viewer)
{
NazaraError("No viewer");
return NzVector3f::Forward();
}
#endif
return m_impl->viewer->GetGlobalForward();
}
NzVector3f NzScene::GetLeft() const
{
#if NAZARA_GRAPHICS_SAFE
if (!m_impl->viewer)
{
NazaraError("No viewer");
return NzVector3f::Left();
}
#endif
return -m_impl->viewer->GetGlobalRight();
}
NzAbstractRenderTechnique* NzScene::GetRenderTechnique() const
{
if (!m_impl->renderTechnique)
@@ -142,6 +194,19 @@ NzAbstractRenderTechnique* NzScene::GetRenderTechnique() const
return m_impl->renderTechnique.get();
}
NzVector3f NzScene::GetRight() const
{
#if NAZARA_GRAPHICS_SAFE
if (!m_impl->viewer)
{
NazaraError("No viewer");
return NzVector3f::Right();
}
#endif
return m_impl->viewer->GetGlobalRight();
}
NzSceneNode& NzScene::GetRoot() const
{
return m_impl->root;
@@ -152,6 +217,19 @@ NzAbstractViewer* NzScene::GetViewer() const
return m_impl->viewer;
}
NzVector3f NzScene::GetUp() const
{
#if NAZARA_GRAPHICS_SAFE
if (!m_impl->viewer)
{
NazaraError("No viewer");
return NzVector3f::Up();
}
#endif
return m_impl->viewer->GetGlobalUp();
}
float NzScene::GetUpdateTime() const
{
return m_impl->updateTime;
@@ -197,7 +275,13 @@ void NzScene::SetRenderTechnique(NzAbstractRenderTechnique* renderTechnique)
void NzScene::SetViewer(NzAbstractViewer* viewer)
{
m_impl->viewer = viewer;
if (m_impl->viewer != viewer)
{
m_impl->viewer = viewer;
// Invalidation de tous les nodes de la scène (utile pour la régénération des sommets dépendant du viewer)
m_impl->root.InvalidateNode();
}
}
void NzScene::SetViewer(NzAbstractViewer& viewer)

View File

@@ -31,16 +31,94 @@ void NzSceneNode::EnableDrawing(bool drawingEnabled)
m_drawingEnabled = drawingEnabled;
}
NzVector3f NzSceneNode::GetBackward() const
{
if (m_scene)
{
if (!m_derivedUpdated)
UpdateDerived();
return m_derivedRotation * m_scene->GetBackward();
}
else
return NzNode::GetBackward();
}
NzVector3f NzSceneNode::GetDown() const
{
if (m_scene)
{
if (!m_derivedUpdated)
UpdateDerived();
return m_derivedRotation * m_scene->GetDown();
}
else
return NzNode::GetDown();
}
NzVector3f NzSceneNode::GetForward() const
{
if (m_scene)
{
if (!m_derivedUpdated)
UpdateDerived();
return m_derivedRotation * m_scene->GetForward();
}
else
return NzNode::GetForward();
}
NzVector3f NzSceneNode::GetLeft() const
{
if (m_scene)
{
if (!m_derivedUpdated)
UpdateDerived();
return m_derivedRotation * m_scene->GetLeft();
}
else
return NzNode::GetLeft();
}
nzNodeType NzSceneNode::GetNodeType() const
{
return nzNodeType_Scene;
}
NzVector3f NzSceneNode::GetRight() const
{
if (m_scene)
{
if (!m_derivedUpdated)
UpdateDerived();
return m_derivedRotation * m_scene->GetRight();
}
else
return NzNode::GetRight();
}
NzScene* NzSceneNode::GetScene() const
{
return m_scene;
}
NzVector3f NzSceneNode::GetUp() const
{
if (m_scene)
{
if (!m_derivedUpdated)
UpdateDerived();
return m_derivedRotation * m_scene->GetUp();
}
else
return NzNode::GetUp();
}
bool NzSceneNode::IsDrawingEnabled() const
{
return m_drawingEnabled;
@@ -82,6 +160,7 @@ void NzSceneNode::OnParenting(const NzNode* parent)
{
if (parent)
{
///FIXME: Remonter jusqu'au premier parent de type SceneNode plutôt que de s'arrêter au premier venu
if (parent->GetNodeType() == nzNodeType_Scene)
SetScene(static_cast<const NzSceneNode*>(parent)->m_scene);
}

View File

@@ -80,6 +80,21 @@ const NzFrustumf& NzView::GetFrustum() const
return m_frustum;
}
NzVector3f NzView::GetGlobalForward() const
{
return NzVector3f::UnitZ();
}
NzVector3f NzView::GetGlobalRight() const
{
return NzVector3f::UnitX();
}
NzVector3f NzView::GetGlobalUp() const
{
return -NzVector3f::UnitY();
}
const NzMatrix4f& NzView::GetProjectionMatrix() const
{
if (!m_projectionMatrixUpdated)

View File

@@ -685,7 +685,7 @@ void NzNode::UpdateDerived() const
m_derivedRotation.Normalize();
}
else
m_derivedRotation = m_initialRotation * m_rotation; ///FIXME: Besoin d'une normalisation ?
m_derivedRotation = m_initialRotation * m_rotation;
m_derivedScale = m_initialScale * m_scale;
if (m_inheritScale)