I tried to do something with irrlicht and newton.
I do some easy program with this->http://gpwiki.org/index.php/Irrlicht:Physics tutorial.
But i have done something bad, and nothing happend(no gravity, etc), what i do wrong?
I do you know some nice tutorials to newton, and newton with irrlicht?
Thanks a lot for any reply.
petra999
And source code:
Code: Select all
#include <Irrlicht.h>
#pragma comment(lib, "Irrlicht.lib")
#include <newton.h>
#pragma comment(lib, "Newton.h")
using namespace irr;
using namespace video;
using namespace core;
using namespace scene;
unsigned int lasttick;
int main()
{
NewtonWorld* nWorld = NewtonCreate(NULL, NULL);
NewtonBody* nCube = 0;
NewtonCollision* collision = NewtonCreateBox(nWorld, 0, 0, 0, NULL);
nCube = NewtonCreateBody(nWorld, collision);
NewtonReleaseCollision(nWorld, collision);
IrrlichtDevice* device = createDevice(EDT_OPENGL, dimension2d<s32>(1000, 680), 16, false, false, false, 0);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
ISceneNode* cube = smgr->addCubeSceneNode();
cube->setPosition(vector3df(0,1110,50));
cube->setMaterialFlag(EMF_LIGHTING, false);
cube->setMaterialTexture( 0, driver->getTexture("C:/irrlicht-1.4.1/media/irrlichtlogo.jpg"));
NewtonBodySetUserData(nCube, cube);
NewtonBodySetMassMatrix(nCube, 1000, 10, 10, 10);
matrix4 mat;
mat.setTranslation(vector3df(0, 1110, 50));
NewtonBodySetMatrix(nCube, &mat.M[0]);
float omega[3] = {1, 2, 1};
NewtonBodySetOmega(nCube, &omega[0]);
ISceneNode* cube1 = smgr->addCubeSceneNode();
cube1->setPosition(vector3df(0,1125,50));
cube1->setMaterialFlag(EMF_LIGHTING, false);
cube1->setMaterialTexture( 0, driver->getTexture("C:/irrlicht-1.4.1/media/dirlogo.jpg"));
ISceneNode* podloga = smgr->addCubeSceneNode();
podloga->setScale(vector3df(1000, 1, 1000));
podloga->setMaterialFlag(EMF_LIGHTING, false);
podloga->setMaterialTexture( 0, driver->getTexture("C:/irrlicht-1.4.1/media/wall.jpg"));
ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS();
cam->setPosition(vector3df(50, 1110, 50));
smgr->addSkyDomeSceneNode(driver->getTexture("C:/irrlicht-1.4.1/media/irrlicht2_bk.jpg"),16,16,1.3f,2.0f);
cam->setFarValue(90000);
cam->setTarget(cube->getPosition());
while (device->run())
{
if (device->isWindowActive())
{
driver->beginScene(true, true, SColor(255,255,255,255));
smgr->drawAll();
//cam->setTarget(cube->getPosition());
if (device->getTimer()->getTime() > lasttick + 10)
{
lasttick = device->getTimer()->getTime();
NewtonUpdate(nWorld, 0.01f);
}
float matrix[4][4];
NewtonBodyGetMatrix(nCube, &matrix[0][0]);
matrix4 mat;
memcpy(mat.M, matrix, sizeof(float)*16);
cube->setPosition(mat.getTranslation());
cube->setRotation(mat.getRotationDegrees());
driver->endScene();
}
}
device->drop();
NewtonDestroy(nWorld);
return 0;
}