How to rock object on the waves?
How to rock object on the waves?
How to realize rocking object on the waves?
You mean to give an object buoyancy? If so, I would point you in the direction of Newton. Its a great physics engine that has buoyancy functions, never experimented with them yet, but I have saw demos and pics of them working, give the newton forums a search if you are interested: www.newtondynamics.com/forum/
http://newtondynamics.com/forum/viewtop ... y+irrlicht
http://newtondynamics.com/forum/viewtop ... y+irrlicht
-
- Posts: 22
- Joined: Fri Dec 30, 2005 2:00 am
- Location: Singapore
- Contact:
Hope this helps:
This code is taken from the mini demo in the obj+mtl loader available here:
http://gdlib.net/index.php?name=Downloa ... ails&id=72
Code: Select all
/**
File: WaterFloatingAnimator.h
Purpose: This WaterFloatingAnimator animates a scene node as though it is floating on water
created using Irrlicht's water scene node.
*/
#ifndef WATER_FLOATING_ANIMATOR_H
#define WATER_FLOATING_ANIMATOR_H
#include "../../include/irrlicht.h"
using namespace irr;
using namespace core;
using namespace video;
using namespace scene;
#define RAD2DEG (f32) 57.29578
class WaterFloatingAnimator : public ISceneNodeAnimator
{
private:
f32 sceneNodeHeight_, waveHeight_, waveSpeed_, oneOverWaveLength_;
public:
WaterFloatingAnimator( f32 sceneNodeHeight, f32 waveHeight, f32 waveSpeed, f32 waveLength ) :
sceneNodeHeight_( sceneNodeHeight ), waveHeight_( waveHeight ),
waveSpeed_( waveSpeed ), oneOverWaveLength_( 1.0f / waveLength ) {}
virtual void animateNode( ISceneNode * pSceneNode, u32 timeMs )
{
f32 cyclePhase = timeMs / waveSpeed_;
vector3df nodePos = pSceneNode->getPosition();
// rotation
vector3df rotation = vector3df( 0, 0, 0 );
// partial derivative of scene node animator's equation with respect to X axis
rotation.X = (f32) cos( nodePos.X * oneOverWaveLength_ + cyclePhase ) * oneOverWaveLength_ * RAD2DEG;
// partial derivative of scene node animator's equation with respect to Z axis
rotation.Z = (f32) -sin( nodePos.Z * oneOverWaveLength_ + cyclePhase ) * oneOverWaveLength_ * RAD2DEG;
// Note: no rotation about Y axis
pSceneNode->setRotation( rotation );
// displacement (only along Y axis to simulate up-down motion)
nodePos.Y = sceneNodeHeight_ +
( (f32) sin( ( ( nodePos.X * oneOverWaveLength_ ) + cyclePhase ) ) * waveHeight_ ) +
( (f32) cos( ( ( nodePos.Z * oneOverWaveLength_ ) + cyclePhase ) ) * waveHeight_ );
pSceneNode->setPosition( nodePos );
}
};
#endif
http://gdlib.net/index.php?name=Downloa ... ails&id=72
I made a waves simulator a few months ago (not irrlicht) and i did what chewy did except i moved the object on the x and z coords using the normal of the nearest wave this way the waves pusshed objects too.
"Irrlicht is obese"
If you want modern rendering techniques learn how to make them or go to the engine next door =p
If you want modern rendering techniques learn how to make them or go to the engine next door =p