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
IMesh* mesh, ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position, const core::vector3df& rotation,
const core::vector3df& scale)
: CMeshSceneNode(mesh, parent, mgr, id, position, rotation, scale), WaveLength(waveLength),
WaveSpeed(waveSpeed), WaveHeight(waveHeight), OriginalMesh(0)
: CMeshSceneNode(mesh, parent, mgr, id, position, rotation, scale),
WaveLength(waveLength), WaveSpeed(waveSpeed), WaveHeight(waveHeight),
OriginalMesh(0)
{
#ifdef _DEBUG
setDebugName("CWaterSurfaceSceneNode");
......@@ -38,7 +39,6 @@ CWaterSurfaceSceneNode::CWaterSurfaceSceneNode(f32 waveHeight, f32 waveSpeed, f3
}
//! destructor
CWaterSurfaceSceneNode::~CWaterSurfaceSceneNode()
{
......@@ -48,29 +48,19 @@ CWaterSurfaceSceneNode::~CWaterSurfaceSceneNode()
}
//! frame
void CWaterSurfaceSceneNode::OnRegisterSceneNode()
{
if (IsVisible)
{
SceneManager->registerNodeForRendering(this);
animateWaterSurface();
CMeshSceneNode::OnRegisterSceneNode();
}
}
void CWaterSurfaceSceneNode::animateWaterSurface()
void CWaterSurfaceSceneNode::OnAnimate(u32 timeMs)
{
if (!Mesh)
return;
u32 meshBufferCount = Mesh->getMeshBufferCount();
f32 time = os::Timer::getTime() / WaveSpeed;
if (Mesh && IsVisible)
{
const u32 meshBufferCount = Mesh->getMeshBufferCount();
const f32 time = timeMs / WaveSpeed;
for (u32 b=0; b<meshBufferCount; ++b)
{
......@@ -83,9 +73,23 @@ void CWaterSurfaceSceneNode::animateWaterSurface()
}// end for all mesh buffers
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.
void CWaterSurfaceSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
......@@ -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 irr
......@@ -12,8 +12,6 @@ namespace irr
namespace scene
{
// TODO: It seems that we have to overwrite setMesh as it should replace
// OriginalMesh
class CWaterSurfaceSceneNode : public CMeshSceneNode
{
public:
......@@ -28,9 +26,15 @@ namespace scene
//! destructor
virtual ~CWaterSurfaceSceneNode();
//! frame
//! frame registration
virtual void OnRegisterSceneNode();
//! animated update
virtual void OnAnimate(u32 timeMs);
//! Update mesh
virtual void setMesh(IMesh* mesh);
//! Returns type of the scene node
virtual ESCENE_NODE_TYPE getType() const { return ESNT_WATER_SURFACE; }
......@@ -42,13 +46,7 @@ namespace scene
private:
void animateWaterSurface();
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);
}
inline void addWave(core::vector3df& dest, const core::vector3df &source, f32 time) const;
f32 WaveLength;
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