Made bounding volume handing part of SceneNodes
Former-commit-id: d09d06ac4515ce09aa16fd92dd045c2a06730a99
This commit is contained in:
parent
bce3cadfd5
commit
8a3c410d60
|
|
@ -225,6 +225,11 @@ int main()
|
|||
bool smoothMovement = true;
|
||||
NzVector3f targetPos = camera.GetPosition();
|
||||
|
||||
NzTextSprite text;
|
||||
text.SetParent(scene);
|
||||
text.Update(NzSimpleTextDrawer::Draw("Hello world !", 72));
|
||||
text.Scale(0.1f);
|
||||
|
||||
// Début de la boucle de rendu du programme
|
||||
while (window.IsOpen())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@
|
|||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||
#include <Nazara/Graphics/SceneNode.hpp>
|
||||
#include <Nazara/Math/Frustum.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
|
||||
class NAZARA_API NzCamera : public NzAbstractViewer, public NzNode, NzRenderTarget::Listener
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ class NAZARA_API NzLight : public NzSceneNode
|
|||
|
||||
float GetAmbientFactor() const;
|
||||
float GetAttenuation() const;
|
||||
const NzBoundingVolumef& GetBoundingVolume() const;
|
||||
NzColor GetColor() const;
|
||||
float GetDiffuseFactor() const;
|
||||
float GetInnerAngle() const;
|
||||
|
|
@ -54,15 +53,13 @@ class NAZARA_API NzLight : public NzSceneNode
|
|||
|
||||
private:
|
||||
bool FrustumCull(const NzFrustumf& frustum) const override;
|
||||
void InvalidateNode() override;
|
||||
void MakeBoundingVolume() const override;
|
||||
void Register() override;
|
||||
void Unregister() override;
|
||||
void UpdateBoundingVolume() const;
|
||||
|
||||
nzLightType m_type;
|
||||
mutable NzBoundingVolumef m_boundingVolume;
|
||||
NzColor m_color;
|
||||
mutable bool m_boundingVolumeUpdated;
|
||||
float m_ambientFactor;
|
||||
float m_attenuation;
|
||||
float m_diffuseFactor;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ class NAZARA_API NzModel : public NzSceneNode
|
|||
void EnableAnimation(bool animation);
|
||||
|
||||
NzAnimation* GetAnimation() const;
|
||||
const NzBoundingVolumef& GetBoundingVolume() const;
|
||||
NzMaterial* GetMaterial(const NzString& subMeshName) const;
|
||||
NzMaterial* GetMaterial(unsigned int matIndex) const;
|
||||
NzMaterial* GetMaterial(unsigned int skinIndex, const NzString& subMeshName) const;
|
||||
|
|
@ -84,13 +83,10 @@ class NAZARA_API NzModel : public NzSceneNode
|
|||
NzModel& operator=(const NzModel& node);
|
||||
|
||||
protected:
|
||||
void InvalidateNode() override;
|
||||
virtual void UpdateBoundingVolume() const;
|
||||
void MakeBoundingVolume() const override;
|
||||
|
||||
std::vector<NzMaterialRef> m_materials;
|
||||
mutable NzBoundingVolumef m_boundingVolume;
|
||||
NzMeshRef m_mesh;
|
||||
mutable bool m_boundingVolumeUpdated;
|
||||
unsigned int m_matCount;
|
||||
unsigned int m_skin;
|
||||
unsigned int m_skinCount;
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ class NAZARA_API NzParticleSystem : public NzSceneNode, NzUpdatable
|
|||
void* GenerateParticle();
|
||||
void* GenerateParticles(unsigned int count);
|
||||
|
||||
const NzBoundingVolumef& GetBoundingVolume() const override;
|
||||
const NzParticleDeclaration* GetDeclaration() const;
|
||||
float GetFixedStepSize() const;
|
||||
unsigned int GetMaxParticleCount() const;
|
||||
|
|
@ -67,22 +66,19 @@ class NAZARA_API NzParticleSystem : public NzSceneNode, NzUpdatable
|
|||
NzParticleSystem& operator=(const NzParticleSystem& emitter);
|
||||
|
||||
private:
|
||||
void GenerateAABB() const;
|
||||
void MakeBoundingVolume() const override;
|
||||
void Register() override;
|
||||
void ResizeBuffer();
|
||||
void Unregister() override;
|
||||
void Update() override;
|
||||
void UpdateBoundingVolume() const;
|
||||
|
||||
std::set<unsigned int, std::greater<unsigned int>> m_dyingParticles;
|
||||
mutable std::vector<nzUInt8> m_buffer;
|
||||
std::vector<NzParticleControllerRef> m_controllers;
|
||||
std::vector<NzParticleEmitter*> m_emitters;
|
||||
std::vector<NzParticleGeneratorRef> m_generators;
|
||||
mutable NzBoundingVolumef m_boundingVolume;
|
||||
NzParticleDeclarationConstRef m_declaration;
|
||||
NzParticleRendererRef m_renderer;
|
||||
mutable bool m_boundingVolumeUpdated;
|
||||
bool m_fixedStepEnabled;
|
||||
bool m_processing;
|
||||
float m_stepAccumulator;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@
|
|||
#include <Nazara/Math/Frustum.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
|
||||
class NzScene;
|
||||
|
||||
class NAZARA_API NzSceneNode : public NzNode
|
||||
{
|
||||
friend class NzScene;
|
||||
|
|
@ -29,7 +31,7 @@ class NAZARA_API NzSceneNode : public NzNode
|
|||
void EnableDrawing(bool drawingEnabled);
|
||||
|
||||
NzVector3f GetBackward() const;
|
||||
virtual const NzBoundingVolumef& GetBoundingVolume() const = 0;
|
||||
virtual const NzBoundingVolumef& GetBoundingVolume() const;
|
||||
NzVector3f GetDown() const;
|
||||
NzVector3f GetForward() const;
|
||||
NzVector3f GetLeft() const;
|
||||
|
|
@ -39,6 +41,8 @@ class NAZARA_API NzSceneNode : public NzNode
|
|||
virtual nzSceneNodeType GetSceneNodeType() const = 0;
|
||||
NzVector3f GetUp() const;
|
||||
|
||||
void InvalidateAABB();
|
||||
|
||||
virtual bool IsDrawable() const = 0;
|
||||
bool IsDrawingEnabled() const;
|
||||
bool IsVisible() const;
|
||||
|
|
@ -48,6 +52,8 @@ class NAZARA_API NzSceneNode : public NzNode
|
|||
|
||||
protected:
|
||||
virtual bool FrustumCull(const NzFrustumf& frustum) const;
|
||||
virtual void InvalidateNode() override;
|
||||
virtual void MakeBoundingVolume() const = 0;
|
||||
virtual void OnParenting(const NzNode* parent) override;
|
||||
virtual void OnVisibilityChange(bool visibility);
|
||||
void RecursiveSetScene(NzScene* scene, NzNode* node);
|
||||
|
|
@ -55,8 +61,11 @@ class NAZARA_API NzSceneNode : public NzNode
|
|||
void SetScene(NzScene* scene);
|
||||
virtual void Unregister();
|
||||
virtual void Update();
|
||||
virtual void UpdateBoundingVolume() const;
|
||||
|
||||
mutable NzBoundingVolumef m_boundingVolume;
|
||||
NzScene* m_scene;
|
||||
mutable bool m_boundingVolumeUpdated;
|
||||
bool m_drawingEnabled;
|
||||
bool m_visible;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ class NAZARA_API NzSceneRoot : public NzSceneNode
|
|||
public:
|
||||
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
|
||||
|
||||
const NzBoundingVolumef& GetBoundingVolume() const override;
|
||||
nzSceneNodeType GetSceneNodeType() const override;
|
||||
|
||||
bool IsDrawable() const;
|
||||
|
|
@ -26,6 +25,7 @@ class NAZARA_API NzSceneRoot : public NzSceneNode
|
|||
NzSceneRoot(NzScene* scene);
|
||||
virtual ~NzSceneRoot();
|
||||
|
||||
void MakeBoundingVolume() const override;
|
||||
void Register();
|
||||
void Unregister();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -69,10 +69,10 @@ class NAZARA_API NzSkeletalModel : public NzModel, NzUpdatable
|
|||
NzSkeletalModel& operator=(NzSkeletalModel&& node);
|
||||
|
||||
private:
|
||||
void MakeBoundingVolume() const override;
|
||||
void Register() override;
|
||||
void Unregister() override;
|
||||
void Update() override;
|
||||
void UpdateBoundingVolume() const;
|
||||
|
||||
NzAnimationRef m_animation;
|
||||
NzSkeleton m_skeleton;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ class NAZARA_API NzSprite : public NzSceneNode
|
|||
|
||||
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
|
||||
|
||||
const NzBoundingVolumef& GetBoundingVolume() const override;
|
||||
const NzColor& GetColor() const;
|
||||
NzMaterial* GetMaterial() const;
|
||||
nzSceneNodeType GetSceneNodeType() const override;
|
||||
|
|
@ -44,18 +43,16 @@ class NAZARA_API NzSprite : public NzSceneNode
|
|||
|
||||
private:
|
||||
void InvalidateNode() override;
|
||||
void MakeBoundingVolume() const override;
|
||||
void Register() override;
|
||||
void Unregister() override;
|
||||
void UpdateBoundingVolume() const;
|
||||
void UpdateVertices() const;
|
||||
|
||||
mutable NzBoundingVolumef m_boundingVolume;
|
||||
NzColor m_color;
|
||||
NzMaterialRef m_material;
|
||||
NzRectf m_textureCoords;
|
||||
NzVector2f m_size;
|
||||
mutable NzVertexStruct_XYZ_Color_UV m_vertices[4];
|
||||
mutable bool m_boundingVolumeUpdated;
|
||||
mutable bool m_verticesUpdated;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ class NAZARA_API NzTextSprite : public NzSceneNode, NzAbstractAtlas::Listener
|
|||
|
||||
void Clear();
|
||||
|
||||
const NzBoundingVolumef& GetBoundingVolume() const override;
|
||||
const NzColor& GetColor() const;
|
||||
NzMaterial* GetMaterial() const;
|
||||
nzSceneNodeType GetSceneNodeType() const override;
|
||||
|
|
@ -47,12 +46,12 @@ class NAZARA_API NzTextSprite : public NzSceneNode, NzAbstractAtlas::Listener
|
|||
private:
|
||||
void ClearAtlases();
|
||||
void InvalidateNode() override;
|
||||
void MakeBoundingVolume() const override;
|
||||
bool OnAtlasCleared(const NzAbstractAtlas* atlas, void* userdata) override;
|
||||
bool OnAtlasLayerChange(const NzAbstractAtlas* atlas, NzAbstractImage* oldLayer, NzAbstractImage* newLayer, void* userdata) override;
|
||||
void OnAtlasReleased(const NzAbstractAtlas* atlas, void* userdata) override;
|
||||
void Register() override;
|
||||
void Unregister() override;
|
||||
void UpdateBoundingVolume() const;
|
||||
void UpdateVertices() const;
|
||||
|
||||
struct RenderIndices
|
||||
|
|
@ -65,11 +64,9 @@ class NAZARA_API NzTextSprite : public NzSceneNode, NzAbstractAtlas::Listener
|
|||
mutable std::unordered_map<NzTexture*, RenderIndices> m_renderInfos;
|
||||
mutable std::vector<NzVertexStruct_XY_Color> m_localVertices;
|
||||
mutable std::vector<NzVertexStruct_XYZ_Color_UV> m_vertices;
|
||||
mutable NzBoundingVolumef m_boundingVolume;
|
||||
NzColor m_color;
|
||||
NzMaterialRef m_material;
|
||||
NzRectui m_localBounds;
|
||||
mutable bool m_boundingVolumeUpdated;
|
||||
mutable bool m_verticesUpdated;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@
|
|||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||
#include <Nazara/Graphics/SceneNode.hpp>
|
||||
#include <Nazara/Math/Frustum.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
|
||||
class NAZARA_API NzView : public NzAbstractViewer, public NzNode, NzRenderTarget::Listener
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,11 +14,11 @@
|
|||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
///TODO: Utilisation des UBOs
|
||||
///TODO: Scale ?
|
||||
|
||||
NzLight::NzLight(nzLightType type) :
|
||||
m_type(type),
|
||||
m_color(NzColor::White),
|
||||
m_boundingVolumeUpdated(false),
|
||||
m_ambientFactor((type == nzLightType_Directional) ? 0.2f : 0.f),
|
||||
m_attenuation(0.9f),
|
||||
m_diffuseFactor(1.f),
|
||||
|
|
@ -31,9 +31,7 @@ m_radius(5.f)
|
|||
NzLight::NzLight(const NzLight& light) :
|
||||
NzSceneNode(light),
|
||||
m_type(light.m_type),
|
||||
m_boundingVolume(light.m_boundingVolume),
|
||||
m_color(light.m_color),
|
||||
m_boundingVolumeUpdated(light.m_boundingVolumeUpdated),
|
||||
m_ambientFactor(light.m_ambientFactor),
|
||||
m_attenuation(light.m_attenuation),
|
||||
m_diffuseFactor(light.m_diffuseFactor),
|
||||
|
|
@ -112,14 +110,6 @@ float NzLight::GetAttenuation() const
|
|||
return m_attenuation;
|
||||
}
|
||||
|
||||
const NzBoundingVolumef& NzLight::GetBoundingVolume() const
|
||||
{
|
||||
if (!m_boundingVolumeUpdated)
|
||||
UpdateBoundingVolume();
|
||||
|
||||
return m_boundingVolume;
|
||||
}
|
||||
|
||||
NzColor NzLight::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
|
|
@ -251,31 +241,13 @@ bool NzLight::FrustumCull(const NzFrustumf& frustum) const
|
|||
return false;
|
||||
}
|
||||
|
||||
void NzLight::InvalidateNode()
|
||||
{
|
||||
NzSceneNode::InvalidateNode();
|
||||
|
||||
m_boundingVolumeUpdated = false;
|
||||
}
|
||||
|
||||
void NzLight::Register()
|
||||
{
|
||||
}
|
||||
|
||||
void NzLight::Unregister()
|
||||
{
|
||||
}
|
||||
|
||||
void NzLight::UpdateBoundingVolume() const
|
||||
{
|
||||
if (m_boundingVolume.IsNull())
|
||||
void NzLight::MakeBoundingVolume() const
|
||||
{
|
||||
switch (m_type)
|
||||
{
|
||||
case nzLightType_Directional:
|
||||
m_boundingVolume.MakeInfinite();
|
||||
m_boundingVolumeUpdated = true;
|
||||
return; // Rien d'autre à faire
|
||||
break;
|
||||
|
||||
case nzLightType_Point:
|
||||
{
|
||||
|
|
@ -310,6 +282,19 @@ void NzLight::UpdateBoundingVolume() const
|
|||
}
|
||||
}
|
||||
|
||||
void NzLight::Register()
|
||||
{
|
||||
}
|
||||
|
||||
void NzLight::Unregister()
|
||||
{
|
||||
}
|
||||
|
||||
void NzLight::UpdateBoundingVolume() const
|
||||
{
|
||||
if (m_boundingVolume.IsNull())
|
||||
MakeBoundingVolume();
|
||||
|
||||
switch (m_type)
|
||||
{
|
||||
case nzLightType_Directional:
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ bool NzModelParameters::IsValid() const
|
|||
}
|
||||
|
||||
NzModel::NzModel() :
|
||||
m_boundingVolumeUpdated(true),
|
||||
m_matCount(0),
|
||||
m_skin(0),
|
||||
m_skinCount(1)
|
||||
|
|
@ -35,9 +34,7 @@ m_skinCount(1)
|
|||
NzModel::NzModel(const NzModel& model) :
|
||||
NzSceneNode(model),
|
||||
m_materials(model.m_materials),
|
||||
m_boundingVolume(model.m_boundingVolume),
|
||||
m_mesh(model.m_mesh),
|
||||
m_boundingVolumeUpdated(model.m_boundingVolumeUpdated),
|
||||
m_matCount(model.m_matCount),
|
||||
m_skin(model.m_skin),
|
||||
m_skinCount(model.m_skinCount)
|
||||
|
|
@ -69,24 +66,6 @@ void NzModel::AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const
|
|||
}
|
||||
}
|
||||
|
||||
const NzBoundingVolumef& NzModel::GetBoundingVolume() const
|
||||
{
|
||||
#if NAZARA_GRAPHICS_SAFE
|
||||
if (!m_mesh)
|
||||
{
|
||||
NazaraError("Model has no mesh");
|
||||
|
||||
static NzBoundingVolumef dummy(nzExtend_Null);
|
||||
return dummy;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!m_boundingVolumeUpdated)
|
||||
UpdateBoundingVolume();
|
||||
|
||||
return m_boundingVolume;
|
||||
}
|
||||
|
||||
NzMaterial* NzModel::GetMaterial(const NzString& subMeshName) const
|
||||
{
|
||||
#if NAZARA_GRAPHICS_SAFE
|
||||
|
|
@ -414,23 +393,12 @@ NzModel& NzModel::operator=(const NzModel& node)
|
|||
return *this;
|
||||
}
|
||||
|
||||
void NzModel::InvalidateNode()
|
||||
void NzModel::MakeBoundingVolume() const
|
||||
{
|
||||
NzSceneNode::InvalidateNode();
|
||||
|
||||
m_boundingVolumeUpdated = false;
|
||||
}
|
||||
|
||||
void NzModel::UpdateBoundingVolume() const
|
||||
{
|
||||
if (m_boundingVolume.IsNull())
|
||||
if (m_mesh)
|
||||
m_boundingVolume.Set(m_mesh->GetAABB());
|
||||
|
||||
if (!m_transformMatrixUpdated)
|
||||
UpdateTransformMatrix();
|
||||
|
||||
m_boundingVolume.Update(m_transformMatrix);
|
||||
m_boundingVolumeUpdated = true;
|
||||
else
|
||||
m_boundingVolume.MakeNull();
|
||||
}
|
||||
|
||||
NzModelLoader::LoaderList NzModel::s_loaders;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ NzParticleSystem(maxParticleCount, NzParticleDeclaration::Get(layout))
|
|||
|
||||
NzParticleSystem::NzParticleSystem(unsigned int maxParticleCount, const NzParticleDeclaration* declaration) :
|
||||
m_declaration(declaration),
|
||||
m_boundingVolumeUpdated(false),
|
||||
m_fixedStepEnabled(false),
|
||||
m_processing(false),
|
||||
m_stepAccumulator(0.f),
|
||||
|
|
@ -38,10 +37,8 @@ NzParticleSystem::NzParticleSystem(const NzParticleSystem& system) :
|
|||
NzSceneNode(system),
|
||||
m_controllers(system.m_controllers),
|
||||
m_generators(system.m_generators),
|
||||
m_boundingVolume(system.m_boundingVolume),
|
||||
m_declaration(system.m_declaration),
|
||||
m_renderer(system.m_renderer),
|
||||
m_boundingVolumeUpdated(system.m_boundingVolumeUpdated),
|
||||
m_fixedStepEnabled(system.m_fixedStepEnabled),
|
||||
m_processing(false),
|
||||
m_stepAccumulator(0.f),
|
||||
|
|
@ -132,14 +129,6 @@ void* NzParticleSystem::GenerateParticles(unsigned int count)
|
|||
return ptr;
|
||||
}
|
||||
|
||||
const NzBoundingVolumef& NzParticleSystem::GetBoundingVolume() const
|
||||
{
|
||||
if (!m_boundingVolumeUpdated)
|
||||
UpdateBoundingVolume();
|
||||
|
||||
return m_boundingVolume;
|
||||
}
|
||||
|
||||
const NzParticleDeclaration* NzParticleSystem::GetDeclaration() const
|
||||
{
|
||||
return m_declaration;
|
||||
|
|
@ -238,8 +227,6 @@ NzParticleSystem& NzParticleSystem::operator=(const NzParticleSystem& system)
|
|||
|
||||
NzSceneNode::operator=(system);
|
||||
|
||||
m_boundingVolume = system.m_boundingVolume;
|
||||
m_boundingVolumeUpdated = system.m_boundingVolumeUpdated;
|
||||
m_controllers = system.m_controllers;
|
||||
m_declaration = system.m_declaration;
|
||||
m_fixedStepEnabled = system.m_fixedStepEnabled;
|
||||
|
|
@ -308,7 +295,7 @@ void NzParticleSystem::ApplyControllers(NzParticleMapper& mapper, unsigned int p
|
|||
m_dyingParticles.clear();
|
||||
}
|
||||
|
||||
void NzParticleSystem::GenerateAABB() const
|
||||
void NzParticleSystem::MakeBoundingVolume() const
|
||||
{
|
||||
///TODO: Calculer l'AABB (prendre la taille des particules en compte s'il y a)
|
||||
m_boundingVolume.MakeInfinite();
|
||||
|
|
@ -356,16 +343,3 @@ void NzParticleSystem::Update()
|
|||
ApplyControllers(mapper, m_particleCount, elapsedTime, m_stepAccumulator);
|
||||
}
|
||||
}
|
||||
|
||||
void NzParticleSystem::UpdateBoundingVolume() const
|
||||
{
|
||||
if (m_boundingVolume.IsNull())
|
||||
GenerateAABB();
|
||||
|
||||
if (!m_transformMatrixUpdated)
|
||||
UpdateTransformMatrix();
|
||||
|
||||
///FIXME: Pourquoi est-ce que le particle system est un node ? Il serait trop coûteux de calculer les particules relativement
|
||||
m_boundingVolume.Update(m_transformMatrix);
|
||||
m_boundingVolumeUpdated = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
NzSceneNode::NzSceneNode() :
|
||||
m_scene(nullptr),
|
||||
m_boundingVolumeUpdated(false),
|
||||
m_drawingEnabled(true),
|
||||
m_visible(false)
|
||||
{
|
||||
|
|
@ -19,6 +20,7 @@ m_visible(false)
|
|||
NzSceneNode::NzSceneNode(const NzSceneNode& sceneNode) :
|
||||
NzNode(sceneNode),
|
||||
m_scene(nullptr),
|
||||
m_boundingVolumeUpdated(false),
|
||||
m_drawingEnabled(sceneNode.m_drawingEnabled),
|
||||
m_visible(false)
|
||||
{
|
||||
|
|
@ -44,6 +46,14 @@ NzVector3f NzSceneNode::GetBackward() const
|
|||
return NzNode::GetBackward();
|
||||
}
|
||||
|
||||
const NzBoundingVolumef& NzSceneNode::GetBoundingVolume() const
|
||||
{
|
||||
if (!m_boundingVolumeUpdated)
|
||||
UpdateBoundingVolume();
|
||||
|
||||
return m_boundingVolume;
|
||||
}
|
||||
|
||||
NzVector3f NzSceneNode::GetDown() const
|
||||
{
|
||||
if (m_scene)
|
||||
|
|
@ -145,6 +155,13 @@ bool NzSceneNode::FrustumCull(const NzFrustumf& frustum) const
|
|||
return frustum.Contains(GetBoundingVolume());
|
||||
}
|
||||
|
||||
void NzSceneNode::InvalidateNode()
|
||||
{
|
||||
NzNode::InvalidateNode();
|
||||
|
||||
m_boundingVolumeUpdated = false;
|
||||
}
|
||||
|
||||
void NzSceneNode::OnParenting(const NzNode* parent)
|
||||
{
|
||||
if (parent)
|
||||
|
|
@ -207,6 +224,18 @@ void NzSceneNode::Update()
|
|||
{
|
||||
}
|
||||
|
||||
void NzSceneNode::UpdateBoundingVolume() const
|
||||
{
|
||||
if (m_boundingVolume.IsNull())
|
||||
MakeBoundingVolume();
|
||||
|
||||
if (!m_transformMatrixUpdated)
|
||||
UpdateTransformMatrix();
|
||||
|
||||
m_boundingVolume.Update(m_transformMatrix);
|
||||
m_boundingVolumeUpdated = true;
|
||||
}
|
||||
|
||||
void NzSceneNode::UpdateVisibility(const NzFrustumf& frustum)
|
||||
{
|
||||
bool wasVisible = m_visible;
|
||||
|
|
|
|||
|
|
@ -20,12 +20,6 @@ void NzSceneRoot::AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const
|
|||
NazaraInternalError("SceneNode::AddToRenderQueue() called on SceneRoot");
|
||||
}
|
||||
|
||||
const NzBoundingVolumef& NzSceneRoot::GetBoundingVolume() const
|
||||
{
|
||||
static NzBoundingVolumef infinite(nzExtend_Infinite);
|
||||
return infinite;
|
||||
}
|
||||
|
||||
nzSceneNodeType NzSceneRoot::GetSceneNodeType() const
|
||||
{
|
||||
return nzSceneNodeType_Root;
|
||||
|
|
@ -36,6 +30,11 @@ bool NzSceneRoot::IsDrawable() const
|
|||
return true;
|
||||
}
|
||||
|
||||
void NzSceneRoot::MakeBoundingVolume() const
|
||||
{
|
||||
m_boundingVolume.MakeInfinite();
|
||||
}
|
||||
|
||||
void NzSceneRoot::Register()
|
||||
{
|
||||
NazaraInternalError("SceneNode::Register() called on SceneRoot");
|
||||
|
|
|
|||
|
|
@ -325,6 +325,11 @@ NzSkeletalModel& NzSkeletalModel::operator=(NzSkeletalModel&& node)
|
|||
return *this;
|
||||
}
|
||||
|
||||
void NzSkeletalModel::MakeBoundingVolume() const
|
||||
{
|
||||
m_boundingVolume.Set(m_skeleton.GetAABB());
|
||||
}
|
||||
|
||||
void NzSkeletalModel::Register()
|
||||
{
|
||||
if (m_animation)
|
||||
|
|
@ -342,16 +347,4 @@ void NzSkeletalModel::Update()
|
|||
AdvanceAnimation(m_scene->GetUpdateTime());
|
||||
}
|
||||
|
||||
void NzSkeletalModel::UpdateBoundingVolume() const
|
||||
{
|
||||
if (m_boundingVolume.IsNull())
|
||||
m_boundingVolume.Set(m_skeleton.GetAABB());
|
||||
|
||||
if (!m_transformMatrixUpdated)
|
||||
UpdateTransformMatrix();
|
||||
|
||||
m_boundingVolume.Update(m_transformMatrix);
|
||||
m_boundingVolumeUpdated = true;
|
||||
}
|
||||
|
||||
NzSkeletalModelLoader::LoaderList NzSkeletalModel::s_loaders;
|
||||
|
|
|
|||
|
|
@ -9,22 +9,18 @@
|
|||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
NzSprite::NzSprite() :
|
||||
m_boundingVolume(NzBoundingVolumef::Null()),
|
||||
m_color(NzColor::White),
|
||||
m_textureCoords(0.f, 0.f, 1.f, 1.f),
|
||||
m_size(64.f, 64.f),
|
||||
m_boundingVolumeUpdated(true),
|
||||
m_verticesUpdated(false)
|
||||
{
|
||||
SetDefaultMaterial();
|
||||
}
|
||||
|
||||
NzSprite::NzSprite(NzTexture* texture) :
|
||||
m_boundingVolume(NzBoundingVolumef::Null()),
|
||||
m_color(NzColor::White),
|
||||
m_textureCoords(0.f, 0.f, 1.f, 1.f),
|
||||
m_size(64.f, 64.f),
|
||||
m_boundingVolumeUpdated(false),
|
||||
m_verticesUpdated(false)
|
||||
{
|
||||
SetTexture(texture, true);
|
||||
|
|
@ -32,13 +28,11 @@ m_verticesUpdated(false)
|
|||
|
||||
NzSprite::NzSprite(const NzSprite& sprite) :
|
||||
NzSceneNode(sprite),
|
||||
m_boundingVolume(sprite.m_boundingVolume),
|
||||
m_color(sprite.m_color),
|
||||
m_material(sprite.m_material),
|
||||
m_textureCoords(sprite.m_textureCoords),
|
||||
m_size(sprite.m_size),
|
||||
m_vertices(sprite.m_vertices),
|
||||
m_boundingVolumeUpdated(sprite.m_boundingVolumeUpdated),
|
||||
m_verticesUpdated(sprite.m_verticesUpdated)
|
||||
{
|
||||
SetParent(sprite.GetParent());
|
||||
|
|
@ -52,14 +46,6 @@ void NzSprite::AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const
|
|||
renderQueue->AddSprites(m_material, m_vertices, 1);
|
||||
}
|
||||
|
||||
const NzBoundingVolumef& NzSprite::GetBoundingVolume() const
|
||||
{
|
||||
if (!m_boundingVolumeUpdated)
|
||||
UpdateBoundingVolume();
|
||||
|
||||
return m_boundingVolume;
|
||||
}
|
||||
|
||||
const NzColor& NzSprite::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
|
|
@ -189,7 +175,6 @@ NzSprite& NzSprite::operator=(const NzSprite& sprite)
|
|||
m_size = sprite.m_size;
|
||||
|
||||
// On ne copie pas les sommets finaux car il est très probable que nos paramètres soient modifiés et qu'ils doivent être régénérés de toute façon
|
||||
m_boundingVolumeUpdated = false;
|
||||
m_verticesUpdated = false;
|
||||
|
||||
return *this;
|
||||
|
|
@ -199,7 +184,6 @@ void NzSprite::InvalidateNode()
|
|||
{
|
||||
NzSceneNode::InvalidateNode();
|
||||
|
||||
m_boundingVolumeUpdated = false;
|
||||
m_verticesUpdated = false;
|
||||
}
|
||||
|
||||
|
|
@ -213,30 +197,21 @@ void NzSprite::Unregister()
|
|||
{
|
||||
}
|
||||
|
||||
void NzSprite::UpdateBoundingVolume() const
|
||||
void NzSprite::MakeBoundingVolume() const
|
||||
{
|
||||
if (m_boundingVolume.IsNull())
|
||||
{
|
||||
NzVector3f down = m_scene->GetDown();
|
||||
NzVector3f right = m_scene->GetRight();
|
||||
NzVector3f down = (m_scene) ? m_scene->GetDown() : NzVector3f::Down();
|
||||
NzVector3f right = (m_scene) ? m_scene->GetRight() : NzVector3f::Right();
|
||||
|
||||
m_boundingVolume.Set(NzVector3f(0.f), m_size.x*right + m_size.y*down);
|
||||
}
|
||||
|
||||
if (!m_transformMatrixUpdated)
|
||||
UpdateTransformMatrix();
|
||||
|
||||
m_boundingVolume.Update(m_transformMatrix);
|
||||
m_boundingVolumeUpdated = true;
|
||||
}
|
||||
|
||||
void NzSprite::UpdateVertices() const
|
||||
{
|
||||
if (!m_transformMatrixUpdated)
|
||||
UpdateTransformMatrix();
|
||||
|
||||
NzVector3f down = m_scene->GetDown();
|
||||
NzVector3f right = m_scene->GetRight();
|
||||
NzVector3f down = (m_scene) ? m_scene->GetDown() : NzVector3f::Down();
|
||||
NzVector3f right = (m_scene) ? m_scene->GetRight() : NzVector3f::Right();
|
||||
|
||||
m_vertices[0].color = m_color;
|
||||
m_vertices[0].position = m_transformMatrix.Transform(NzVector3f(0.f));
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
NzTextSprite::NzTextSprite() :
|
||||
m_boundingVolume(NzBoundingVolumef::Null()),
|
||||
m_color(NzColor::White),
|
||||
m_verticesUpdated(false)
|
||||
{
|
||||
|
|
@ -24,11 +23,9 @@ m_atlases(sprite.m_atlases),
|
|||
m_renderInfos(sprite.m_renderInfos),
|
||||
m_localVertices(sprite.m_localVertices),
|
||||
m_vertices(sprite.m_vertices),
|
||||
m_boundingVolume(sprite.m_boundingVolume),
|
||||
m_color(sprite.m_color),
|
||||
m_material(sprite.m_material),
|
||||
m_localBounds(sprite.m_localBounds),
|
||||
m_boundingVolumeUpdated(sprite.m_boundingVolumeUpdated),
|
||||
m_verticesUpdated(sprite.m_verticesUpdated)
|
||||
{
|
||||
SetParent(sprite.GetParent());
|
||||
|
|
@ -66,14 +63,6 @@ void NzTextSprite::Clear()
|
|||
m_vertices.clear();
|
||||
}
|
||||
|
||||
const NzBoundingVolumef& NzTextSprite::GetBoundingVolume() const
|
||||
{
|
||||
if (!m_boundingVolumeUpdated)
|
||||
UpdateBoundingVolume();
|
||||
|
||||
return m_boundingVolume;
|
||||
}
|
||||
|
||||
const NzColor& NzTextSprite::GetColor() const
|
||||
{
|
||||
return m_color;
|
||||
|
|
@ -266,7 +255,6 @@ NzTextSprite& NzTextSprite::operator=(const NzTextSprite& text)
|
|||
m_localVertices = text.m_localVertices;
|
||||
|
||||
// On ne copie pas les sommets finaux car il est très probable que nos paramètres soient modifiés et qu'ils doivent être régénérés de toute façon
|
||||
m_boundingVolumeUpdated = false;
|
||||
m_verticesUpdated = false;
|
||||
|
||||
return *this;
|
||||
|
|
@ -284,10 +272,21 @@ void NzTextSprite::InvalidateNode()
|
|||
{
|
||||
NzSceneNode::InvalidateNode();
|
||||
|
||||
m_boundingVolumeUpdated = false;
|
||||
m_verticesUpdated = false;
|
||||
}
|
||||
|
||||
void NzTextSprite::MakeBoundingVolume() const
|
||||
{
|
||||
NzVector3f down = (m_scene) ? m_scene->GetDown() : NzVector3f::Down();
|
||||
NzVector3f right = (m_scene) ? m_scene->GetRight() : NzVector3f::Right();
|
||||
|
||||
NzRectf bounds(m_localBounds);
|
||||
NzVector2f max = bounds.GetMaximum();
|
||||
NzVector2f min = bounds.GetMinimum();
|
||||
|
||||
m_boundingVolume.Set(min.x*right + min.y*down, max.x*right + max.y*down);
|
||||
}
|
||||
|
||||
bool NzTextSprite::OnAtlasCleared(const NzAbstractAtlas* atlas, void* userdata)
|
||||
{
|
||||
NazaraUnused(userdata);
|
||||
|
|
@ -373,34 +372,13 @@ void NzTextSprite::Unregister()
|
|||
{
|
||||
}
|
||||
|
||||
void NzTextSprite::UpdateBoundingVolume() const
|
||||
{
|
||||
if (m_boundingVolume.IsNull())
|
||||
{
|
||||
NzVector3f down = m_scene->GetDown();
|
||||
NzVector3f right = m_scene->GetRight();
|
||||
|
||||
NzRectf bounds(m_localBounds);
|
||||
NzVector2f max = bounds.GetMaximum();
|
||||
NzVector2f min = bounds.GetMinimum();
|
||||
|
||||
m_boundingVolume.Set(min.x*right + min.y*down, max.x*right + max.y*down);
|
||||
}
|
||||
|
||||
if (!m_transformMatrixUpdated)
|
||||
UpdateTransformMatrix();
|
||||
|
||||
m_boundingVolume.Update(m_transformMatrix);
|
||||
m_boundingVolumeUpdated = true;
|
||||
}
|
||||
|
||||
void NzTextSprite::UpdateVertices() const
|
||||
{
|
||||
if (!m_transformMatrixUpdated)
|
||||
UpdateTransformMatrix();
|
||||
|
||||
NzVector3f down = m_scene->GetDown();
|
||||
NzVector3f right = m_scene->GetRight();
|
||||
NzVector3f down = (m_scene) ? m_scene->GetDown() : NzVector3f::Down();
|
||||
NzVector3f right = (m_scene) ? m_scene->GetRight() : NzVector3f::Right();
|
||||
|
||||
NzSparsePtr<NzColor> colorPtr(&m_vertices[0].color, sizeof(NzVertexStruct_XYZ_Color_UV));
|
||||
NzSparsePtr<NzVector3f> posPtr(&m_vertices[0].position, sizeof(NzVertexStruct_XYZ_Color_UV));
|
||||
|
|
|
|||
Loading…
Reference in New Issue