IrrNewton animator

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
schick
Posts: 230
Joined: Tue Oct 07, 2003 3:55 pm
Location: Germany
Contact:

IrrNewton animator

Post by schick »

Here we go again,

I wrote a physic animator as a wrapper over newton. Its easy to use but if you want you may gain full control over newton.

A very basic example looks like that, using a level and two boxes. Its documented so there is no need to tell more about it.

It is aplha software. That means its not even tested :-(, so dont expect to much from it.

What is done:

- core design is ready
- animator works
- world works
- materials work
- an example material in the extra namespace
- working on msvc++6 and gcc3.3

ToDo:

- testing :-) well, thats up to you, too
- add joint support
- add ragdoll support?
- add some tutorials (materials)
- did i mentioned testing

Code: Select all

#include <irrlicht.h>
#include <newton.h>

#include "IrrNewton\IrrNewton.hpp"

using namespace irr;
using namespace irr::video;
using namespace irr::scene;
using namespace irr::core;
using namespace irr::gui;

// The IrrNewton physic animator uses those namespaces.
// All basic stuff can be found here in IrrNewton
using namespace IrrNewton;
// Some extras and examples can be found here.
using namespace IrrNewton::Extra;

ISceneManager* IrrScene = NULL;
IVideoDriver* IrrDriver = NULL;
IrrlichtDevice* IrrDevice = NULL;

irr::s32 main( irr::s32 argc, irr::c8* argv[])
{
	
	IrrlichtDevice *IrrDevice = createDevice( video::EDT_OPENGL,
		core::dimension2d<s32>(800,600), false);	
	video::IVideoDriver* IrrDriver = IrrDevice->getVideoDriver();
	scene::ISceneManager* IrrScene = IrrDevice->getSceneManager();
	
	IAnimatedMesh* BoxMesh = IrrScene->getMesh( "../../data/smallcube.3ds");
	IAnimatedMesh* LevelMesh = IrrScene->getMesh( "../../data/castle.x");
	
	IAnimatedMeshSceneNode* BoxNode0 = IrrScene->addAnimatedMeshSceneNode( BoxMesh);
	BoxNode0->setPosition( core::vector3df(0,200,-200)); 
	
	IAnimatedMeshSceneNode* BoxNode1 = IrrScene->addAnimatedMeshSceneNode( BoxMesh);
	BoxNode1->setPosition( core::vector3df(0,200,-100)); 
	
	ISceneNode* LevelNode = IrrScene->addOctTreeSceneNode( LevelMesh);
	
	IrrScene->addLightSceneNode(0, core::vector3df(0,1000,-500), 
		video::SColorf(1.0f, 0.6f, 0.7f, 1.0f), 600.0f);
	
	irr::scene::ICameraSceneNode* Camera = IrrScene->addCameraSceneNodeFPS();
	Camera->setPosition( core::vector3df(0,200,-500)); 
	
	// Lets create the physic world.
	IrrNewtonWorld* PhysicWorld = new IrrNewtonWorld( IrrDevice);
	// Set the world size in which all the physics will be calculated.
	// We use the bounding box from the LevelNode scenenode.
	PhysicWorld->SetSize( LevelNode->getBoundingBox());
	
	// Create our sample material
	// You can have a look it in the IrrNewton::Extra namespace.
	SampleMaterial* Material0 = new SampleMaterial( PhysicWorld);
	// Register the material in the world.
	PhysicWorld->RegisterMaterial( Material0);
	// drop it we dont need it anymore (the world takes care about it).
	Material0->drop();
	
	// Set up all materials in the world
	PhysicWorld->SetupAllMaterial();
	
	// Create one animator using the mesh rigid body (useful for maps etc, but 
	// dont forget it will always have a infinit mass (cannot react on physics just like bouncing).
	// Attach the animator to LevelNode and finally let the animator create the rigidbody using 
	// the mesh of the LevelNode. 
	IrrNewtonAnimator* LevelAnim0 = PhysicWorld->CreateIrrNewtonAnimator( ERigidBodyMesh, 
		LevelNode, 
		// Use the default material.
		MaterialDefault, 
		LevelMesh);
	
	// Create one animator using the box rigid body.
	// Attach the animator to BoxNode0.
	IrrNewtonAnimator* BoxAnim0 = PhysicWorld->CreateIrrNewtonAnimator( ERigidBodyBox, 
		BoxNode0);
	
	// Create one animator using the box rigid body.
	// Attach the animator to BoxNode1.
	IrrNewtonAnimator* BoxAnim1 = PhysicWorld->CreateIrrNewtonAnimator( ERigidBodyBox, 
		BoxNode1);
	
	/*
	// Lets use the SampleMaterial.
	// The material will print "Autsch" to the console on any contact with another
	// animator using the SampleMaterial. Furthermore it will call the event handler
	// of each animator. Have a look at the documentation or sources.
	
	  IrrNewtonAnimator* LevelAnim0 = PhysicWorld->CreateIrrNewtonAnimator( ERigidBodyMesh, 
	  LevelNode, 
	  MaterialSample, 
	  LevelMesh);
 
	  IrrNewtonAnimator* BoxAnim1 = PhysicWorld->CreateIrrNewtonAnimator( ERigidBodyBox, 
		BoxNode1,
		MaterialSample);
	*/
	
	irr::s32 lastFPS = -1;
	while( IrrDevice->run())
	{
		IrrDriver->beginScene( true, true, video::SColor(0,200,200,200));
		IrrScene->drawAll();
		IrrDriver->endScene();
		
		// Update the world using a hard frame rate
		// Have a look at the documentation or sources.
		PhysicWorld->UpdateWorld();
		
		irr::s32 fps = IrrDriver->getFPS();
		
		if (lastFPS != fps)
		{
			core::stringw str = L"IrrNewton Demo [";
			str += IrrDriver->getName();
			str += "]  FPS: ";
			str += fps;
			str += " | ";
			str += static_cast<irr::s32>( IrrDevice->getVideoDriver()->getPrimitiveCountDrawn());
			str += " Primitives",
				IrrDevice->setWindowCaption( str.c_str());
			lastFPS = fps;
		}
	}

	// drop the physic world
	PhysicWorld->drop();

	IrrDevice->drop();
	
	return 0;
}  

The good stuff comes last.

(Compressed using the z7 engine)
Download here:
http://www.bluffel.de.vu/IrrNewton/Files/IrrNewton.exe

And the documentation here:
http://www.bluffel.de.vu/IrrNewton/Docu/index.html

If a link does not work browse here:
http://www.bluffel.de.vu/IrrNewton/

I have no internet during the week so dont exspect any answers to that thread before next weekend, except tomorrow.

Please use it and post all bugs into that thread. I want to make it as stable as possible. Thanks.

Happy using,

schick
Please send me an e-mail instead of a private message.
brcolow
Posts: 56
Joined: Mon Jul 19, 2004 6:15 am
Location: Arizona

Post by brcolow »

Nice work! Except, unfortunatley, I will not be using it because I am using ODE. A physics engine that works with mac, linux, and windows. Newton is closed-source and only works with Windows. Not my kind of engine.

Nevertheless, nice work!
G'Day.
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

Looks very nice. I kinda regret that I've already started using pure Newton in my game, or I'd certainly take a very long look at this, which looks as though it makes integrating newton and irr easy.
A couple comments and questions:
1) I saw no interface for setting material properties (friction, etc). Did I miss it, or is that feature still to be implemented?

2) As Mercior did in his demos, you use a scale factor between Newton and Irr. There must be some reason for that, but it escapes me. I'm currently using no scale between Newton and Irr in my project, and it's working fine. It's all simply numbers, not some specific unit like meters or feet or whatever.
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

Good work Schick, like ever.
Don't give up!
schick
Posts: 230
Joined: Tue Oct 07, 2003 3:55 pm
Location: Germany
Contact:

Post by schick »

Electron wrote:Looks very nice. I kinda regret that I've already started using pure Newton in my game, or I'd certainly take a very long look at this, which looks as though it makes integrating newton and irr easy.
A couple comments and questions:
1) I saw no interface for setting material properties (friction, etc). Did I miss it, or is that feature still to be implemented?

2) As Mercior did in his demos, you use a scale factor between Newton and Irr. There must be some reason for that, but it escapes me. I'm currently using no scale between Newton and Irr in my project, and it's working fine. It's all simply numbers, not some specific unit like meters or feet or whatever.
1. Have a look at the SampleMaterial. All the material properties are set in the SetupMaterial() function. There is no need to write a wrapper for this.

2. Newton uses a different scale system then irrlicht does. Well, it worked fine without the scale factor but as the newton developers do so, i do so :-). Maybe something about accuracy.

greetings,

schick
Please send me an e-mail instead of a private message.
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Hmm. I was going to use Newton for my project, but because of the Windows-only I would maybe try ODE. Do most Linux-gamers have a Windows-install for gaming purposes. Because Newton is imo way better...
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

@schick thanks for your answer

@ everyone
about Newton being Windows only, please do note that the developers do plan to port it to linux. As the Newton developers seem to be quite dedicated, I think there's probably at least a 90% chance that Newton will work with linux by the time a project being started now is finished. I do realize some people may not want to take that chance, but Newton for linux is not hopeless. Since no graphics or anything is involved, I do not think porting to linux would be that hard for the developers.
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
buhatkj
Posts: 444
Joined: Fri Dec 12, 2003 4:53 am
Contact:

best physics wrapper so far....

Post by buhatkj »

dude, this is about the most useful physics wrapper i have seen so far, it really integrates well with irrlicht, and has a relatively uncluttered structure. NICE man....I especially like the irrnewton material idea, you just derive a new material from that class and set up how it should act...splendid idea. I need to read through so that I can understand everything you did here, but it looks really good so far, hopefully you will have a chance to lkeep working on it and adding some more of the stuff in your todo. :-)
My irrlicht-based projects have gone underground for now, but if you want, check out my webcomic instead! http://brokenboomerang.net
ZDimitor
Posts: 202
Joined: Fri Jul 16, 2004 3:27 am
Location: Russia

Post by ZDimitor »

All need to say - Newton is not open source project!!!

Thats why there is no altrnative to the ODE.

ODE fastest, open sourced and multiplatform.
Guest

Post by Guest »

I thinks Tokamak, Meqon, Novodex, Havok, aren’t open source and not one hold that against then.
It has not been proven ODE to be faster than Newton. Do you have some comparison demo shown both side by side I have never seen any? All I read are rumors, but when I worked with ODE, with all the solvers it has, all I got was explosions, jitter, collision bugs, you name if it is bad I have it. Since I switched to Newton all does bug when away.
Newton is more stable, have more features, and hell of a lot easier to work with.
I stay with Newton and save myself lot of cursing while setting my physics;
I am using Merciors’s tutorial but I think this wrapper is awesome. I cannot wait to see it working with the new feature of the next SDK
http://www.newtondynamics.com/forum/viewtopic.php?t=642

Roberto
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

I don't know whether newton is better physics engine, but Schick found very fine solution to implement newton physics in irrlicht. Congratulation, we will waiting for feature development of this project.
schick
Posts: 230
Joined: Tue Oct 07, 2003 3:55 pm
Location: Germany
Contact:

New demo

Post by schick »

The demo IrrNewton 0.2:

A box, a sphere and a fps player. The demo shows what can done
by IrrNewton in a few function calls.

Download here:
SFX archive 7z:
http://www.bluffel.de.vu/IrrNewton/File ... onDemo.exe

or browse here (docu and sources aint being updated yet):
http://www.bluffel.de.vu/

Changelog:

for 0.5
- first release

for 0.4
- few tutorials

for 0.3:
- add all missing joints supported by newton
- make it stable
- more docu

IrrNewton 0.2

- fixed lots of bugs
- added some new :-)
- joint design ready (UpVector is done)

Extra:
- camera class
- keymap class (managing keys and actions)
- a fps animator

IrrNewton 0.1:

- core design is ready
- animator works
- world works
- materials work
- working on msvc++6 and gcc3.3

Extra:
- sample material
Please send me an e-mail instead of a private message.
schick
Posts: 230
Joined: Tue Oct 07, 2003 3:55 pm
Location: Germany
Contact:

Post by schick »

http://www.bluffel.de.vu/

Sources and docu are updated. Its still in heavy development so dont exspect it to be stable.
Please send me an e-mail instead of a private message.
schick
Posts: 230
Joined: Tue Oct 07, 2003 3:55 pm
Location: Germany
Contact:

Uppps

Post by schick »

The version ive uploaded was out of date sorry. The new version is up in the next 10 mins.

Get it here:

http://www.bluffel.de.vu/

I've added some pseudo shooting, its much more fun. Check out the demo and your left mouse key :-).
Please send me an e-mail instead of a private message.
Guest

Post by Guest »

ZDimitor wrote:All need to say - Newton is not open source project!!!

Thats why there is no altrnative to the ODE.

ODE fastest, open sourced and multiplatform.
yes, ODE is open source... (the source isn't of much use though because to do something with it you have to be very experienced and ODE is flawed from the ground up.) ...but ODE is not fast. faststep and quickstep are unusable and ODE's big matrix solver is much slower than newton. don't get me wrong. i like open source and i hope ODE gets better in the future. :) but at the moment you can avoid a lot of cursing by using closed source physics engines like newton.
Post Reply