mist ,den code vergesse ich natürlich.
Code:
#include <Irrlicht.h>
#include "newton.h"
#include <iostream>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
static NewtonWorld* nWorld;
static NewtonBody* body;
IVideoDriver* driver = 0;
IrrlichtDevice *device = 0;
ISceneManager* smgr = 0;
ISceneNode *boxNode = 0;
ISceneNode *cam = 0;
unsigned int lasttick;
void InitScene()
{
device = createDevice(EDT_OPENGL,
dimension2d<u32>(640, 480), 16,
false, false, false, 0);
driver = device->getVideoDriver();
smgr = device->getSceneManager();
nWorld = NewtonCreate (NULL, NULL);
boxNode = smgr->addAnimatedMeshSceneNode(smgr->getMesh("data/smallcube.3ds"));
boxNode->setMaterialTexture(0, driver->getTexture("data/crate.jpg"));
NewtonCollision *collision;
collision = NewtonCreateBox(nWorld, 0, 0, 0, NULL);
body = NewtonCreateBody (nWorld, collision);
NewtonReleaseCollision (nWorld, collision);
NewtonBodySetUserData(body, boxNode);
NewtonBodySetMassMatrix (body, 100.0f, 1.0f, 1.0f, 1.0f);
matrix4 mat;
mat.setTranslation(vector3df(0,0,0));
NewtonBodySetMatrix(body, &mat.pointer()[0]);
float omega[3] = {1.0f, 2.0f, 1.0f};
NewtonBodySetOmega (body, &omega[0]);
cam = smgr->addCameraSceneNodeMaya(0,-1500.0f,200.0f,500.0f,0);
cam->setPosition(vector3df(0, 300, 0));
}
void DrawScene()
{
if (device->getTimer()->getTime() > lasttick + 10) {
lasttick = device->getTimer()->getTime();
NewtonUpdate(nWorld, 0.01f);
}
float matrix[4][4];
NewtonBodyGetMatrix(body, &matrix[0][0]);
matrix4 mat;
memcpy(mat.pointer(), matrix, sizeof(float)*16);
boxNode->setPosition(mat.getTranslation());
boxNode->setRotation(mat.getRotationDegrees());
}
int main()
{
InitScene();
while(device->run())
{
DrawScene();
driver->beginScene(true, true, video::SColor(0,0,0,0));
smgr->drawAll();
driver->endScene();
}
NewtonDestroy(nWorld);
device->drop();
return 0;
}