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