How to rock object on the waves?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Magnet
Posts: 101
Joined: Wed Sep 27, 2006 7:32 pm

How to rock object on the waves?

Post by Magnet »

How to realize rocking object on the waves?
zeno60
Posts: 342
Joined: Sun May 21, 2006 2:48 am
Location: NC, USA
Contact:

Post by zeno60 »

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
Magnet
Posts: 101
Joined: Wed Sep 27, 2006 7:32 pm

Post by Magnet »

I am using standart water SceneNode.
And no need to using newton to water.

I need to get Y cordinate on water node in any position and apply it to object.
Also get rotation matrix for some wave and apply it to object.
loonychewy
Posts: 22
Joined: Fri Dec 30, 2005 2:00 am
Location: Singapore
Contact:

Post by loonychewy »

Hope this helps:

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
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
Magnet
Posts: 101
Joined: Wed Sep 27, 2006 7:32 pm

Post by Magnet »

You not undestand me.
I am create water!! And need to realize floating object on the water.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Looks to me as thought that's what loonychewy's code does for you. It's an animator which you add to your node to make it look like it's floating on the irrlicht water.
Image Image Image
ssexton
Posts: 54
Joined: Wed Oct 25, 2006 7:46 am
Location: South Florida
Contact:

Post by ssexton »

*drool* more eye candy ;)

Thanks loonychewy. Can't wait to try this out.
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

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
Magnet
Posts: 101
Joined: Wed Sep 27, 2006 7:32 pm

Post by Magnet »

Can you publish your code of the water and moving object?
Or help me please :wink:
Please :cry:
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Use loonychewy's code that has been provided, check the download link so you can see that it is in fact what you're after, and then if you need the object to be pushed along by the waves then just listen to what omaremad said! Everything's been laid out for you ;)
Image Image Image
Post Reply