Commit 188ce8b5 authored by hybrid's avatar hybrid

Ouch, rendered twice, now fixed. Moreover, we use the standard interfaces for all updates now.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2357 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 99a92fc3
...@@ -20,8 +20,9 @@ CWaterSurfaceSceneNode::CWaterSurfaceSceneNode(f32 waveHeight, f32 waveSpeed, f3 ...@@ -20,8 +20,9 @@ CWaterSurfaceSceneNode::CWaterSurfaceSceneNode(f32 waveHeight, f32 waveSpeed, f3
IMesh* mesh, ISceneNode* parent, ISceneManager* mgr, s32 id, IMesh* mesh, ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position, const core::vector3df& rotation, const core::vector3df& position, const core::vector3df& rotation,
const core::vector3df& scale) const core::vector3df& scale)
: CMeshSceneNode(mesh, parent, mgr, id, position, rotation, scale), WaveLength(waveLength), : CMeshSceneNode(mesh, parent, mgr, id, position, rotation, scale),
WaveSpeed(waveSpeed), WaveHeight(waveHeight), OriginalMesh(0) WaveLength(waveLength), WaveSpeed(waveSpeed), WaveHeight(waveHeight),
OriginalMesh(0)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CWaterSurfaceSceneNode"); setDebugName("CWaterSurfaceSceneNode");
...@@ -38,7 +39,6 @@ CWaterSurfaceSceneNode::CWaterSurfaceSceneNode(f32 waveHeight, f32 waveSpeed, f3 ...@@ -38,7 +39,6 @@ CWaterSurfaceSceneNode::CWaterSurfaceSceneNode(f32 waveHeight, f32 waveSpeed, f3
} }
//! destructor //! destructor
CWaterSurfaceSceneNode::~CWaterSurfaceSceneNode() CWaterSurfaceSceneNode::~CWaterSurfaceSceneNode()
{ {
...@@ -48,29 +48,19 @@ CWaterSurfaceSceneNode::~CWaterSurfaceSceneNode() ...@@ -48,29 +48,19 @@ CWaterSurfaceSceneNode::~CWaterSurfaceSceneNode()
} }
//! frame //! frame
void CWaterSurfaceSceneNode::OnRegisterSceneNode() void CWaterSurfaceSceneNode::OnRegisterSceneNode()
{ {
if (IsVisible)
{
SceneManager->registerNodeForRendering(this);
animateWaterSurface();
CMeshSceneNode::OnRegisterSceneNode(); CMeshSceneNode::OnRegisterSceneNode();
}
} }
void CWaterSurfaceSceneNode::OnAnimate(u32 timeMs)
void CWaterSurfaceSceneNode::animateWaterSurface()
{ {
if (!Mesh) if (Mesh && IsVisible)
return; {
const u32 meshBufferCount = Mesh->getMeshBufferCount();
u32 meshBufferCount = Mesh->getMeshBufferCount(); const f32 time = timeMs / WaveSpeed;
f32 time = os::Timer::getTime() / WaveSpeed;
for (u32 b=0; b<meshBufferCount; ++b) for (u32 b=0; b<meshBufferCount; ++b)
{ {
...@@ -83,9 +73,23 @@ void CWaterSurfaceSceneNode::animateWaterSurface() ...@@ -83,9 +73,23 @@ void CWaterSurfaceSceneNode::animateWaterSurface()
}// end for all mesh buffers }// end for all mesh buffers
SceneManager->getMeshManipulator()->recalculateNormals(Mesh); SceneManager->getMeshManipulator()->recalculateNormals(Mesh);
}
CMeshSceneNode::OnAnimate(timeMs);
} }
void CWaterSurfaceSceneNode::setMesh(IMesh* mesh)
{
CMeshSceneNode::setMesh(mesh);
if (!mesh)
return;
if (OriginalMesh)
OriginalMesh->drop();
IMesh* clone = SceneManager->getMeshManipulator()->createMeshCopy(mesh);
OriginalMesh = mesh;
Mesh = clone;
}
//! Writes attributes of the scene node. //! Writes attributes of the scene node.
void CWaterSurfaceSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const void CWaterSurfaceSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
...@@ -124,6 +128,14 @@ void CWaterSurfaceSceneNode::deserializeAttributes(io::IAttributes* in, io::SAtt ...@@ -124,6 +128,14 @@ void CWaterSurfaceSceneNode::deserializeAttributes(io::IAttributes* in, io::SAtt
} }
} }
void CWaterSurfaceSceneNode::addWave(core::vector3df& dest, const core::vector3df &source, f32 time) const
{
dest.Y = source.Y +
(sinf(((source.X/WaveLength) + time)) * WaveHeight) +
(cosf(((source.Z/WaveLength) + time)) * WaveHeight);
}
} // end namespace scene } // end namespace scene
} // end namespace irr } // end namespace irr
...@@ -12,8 +12,6 @@ namespace irr ...@@ -12,8 +12,6 @@ namespace irr
namespace scene namespace scene
{ {
// TODO: It seems that we have to overwrite setMesh as it should replace
// OriginalMesh
class CWaterSurfaceSceneNode : public CMeshSceneNode class CWaterSurfaceSceneNode : public CMeshSceneNode
{ {
public: public:
...@@ -28,9 +26,15 @@ namespace scene ...@@ -28,9 +26,15 @@ namespace scene
//! destructor //! destructor
virtual ~CWaterSurfaceSceneNode(); virtual ~CWaterSurfaceSceneNode();
//! frame //! frame registration
virtual void OnRegisterSceneNode(); virtual void OnRegisterSceneNode();
//! animated update
virtual void OnAnimate(u32 timeMs);
//! Update mesh
virtual void setMesh(IMesh* mesh);
//! Returns type of the scene node //! Returns type of the scene node
virtual ESCENE_NODE_TYPE getType() const { return ESNT_WATER_SURFACE; } virtual ESCENE_NODE_TYPE getType() const { return ESNT_WATER_SURFACE; }
...@@ -42,13 +46,7 @@ namespace scene ...@@ -42,13 +46,7 @@ namespace scene
private: private:
void animateWaterSurface(); inline void addWave(core::vector3df& dest, const core::vector3df &source, f32 time) const;
void addWave(core::vector3df& dest, const core::vector3df &source, f32 time) const
{
dest.Y = source.Y +
(sinf(((source.X/WaveLength) + time)) * WaveHeight) +
(cosf(((source.Z/WaveLength) + time)) * WaveHeight);
}
f32 WaveLength; f32 WaveLength;
f32 WaveSpeed; f32 WaveSpeed;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment