ok I have finaly been able to get 1 node to fall but the problem is now to create more than 1 and how would i get it to colide with another node
Code: Select all
#include "Irrlicht.h"
#include "newton.h"
#include <iostream>
#include <Irrlicht.h>
#include <memory.h>
#include <iostream>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
//Now we create a pointer to a Newton "World" object
#define NEWTON_GRAVITY 900.0f
static NewtonWorld* nWorld;
void* _cdecl
NewtonAlloc (int sizeInBytes)
{
return new char[sizeInBytes];
}
// destruction of memory from Newton
void _cdecl
NewtonFree (void *ptr, int sizeInBytes)
{
char *tmp;
tmp = (char*) ptr;
delete[] tmp;
}
//the is the main newton object. Next we add a pointer for a rigid body object
static NewtonBody* body;
static NewtonBody* Floor;
IVideoDriver* driver = 0;
IrrlichtDevice *device = 0;
ISceneManager* smgr = 0;
scene::ISceneNode* boxNode = 0;
scene::ISceneNode* FloorNode = 0;
ISceneNode *cam = 0;
unsigned int lasttick;
void InitScene();
void DrawScene();
void InitScene()
{
device = createDevice(EDT_OPENGL,
dimension2d<s32>(640,480),
false);
driver = device->getVideoDriver();
smgr = device->getSceneManager();
nWorld = NewtonCreate (NewtonAlloc, NewtonFree);
int i = NewtonMaterialGetDefaultGroupID(nWorld);
NewtonMaterialSetDefaultFriction (nWorld, i, i, 0.8f, 0.4f);
NewtonMaterialSetDefaultElasticity (nWorld, i, i, 0.3f);
NewtonMaterialSetDefaultSoftness (nWorld, i, i, 0.05f);
NewtonMaterialSetCollisionCallback (nWorld, i, i, NULL, NULL, NULL, NULL);
boxNode = smgr->addTestSceneNode();
FloorNode = smgr->addTestSceneNode();
FloorNode->setPosition(core::vector3df(64,0, 8));
FloorNode->setScale(core::vector3df(2,32,32));
boxNode->setScale(core::vector3df(2,16,8));
NewtonCollision *collision;
collision = NewtonCreateBox(nWorld, 0, 0, 0, NULL);
body = NewtonCreateBody (nWorld, collision);
Floor = NewtonCreateBody (nWorld, collision);
NewtonReleaseCollision (nWorld, collision);
NewtonBodySetUserData(body, boxNode);
NewtonBodySetUserData(Floor, FloorNode);
NewtonBodySetMassMatrix (body, 100.0f, 1.0f, 1.0f, 1.0f);
NewtonBodySetMassMatrix (Floor, 100.0f, 1.0f, 1.0f, 1.0f);
matrix4 mat;
mat.setTranslation(vector3df(0,0,0));
NewtonBodySetMatrix(body, &mat.M[0]);
NewtonBodySetMatrix(Floor, &mat.M[0]);
// float omega[3] = {0.0f, 1.0f, 0.0f};
// NewtonBodySetVelocity (body, &omega[0]);
// NewtonBodyAddForce (body, &omega[0]);
cam = smgr->addCameraSceneNodeMaya(0,-1500.0f,200.0f,500.0f,0);
cam->setPosition(vector3df(0, 300, 0));
}
// Newton callback
void applyForceAndTorqueEvent(const NewtonBody* body)
{
float mass;
float Ixx;
float Iyy;
float Izz;
NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
vector3df force (NEWTON_GRAVITY * mass , 0.0f , 0.0f);
vector3df torque (0.0f, 0.0f, 0.0f);
NewtonBodySetForce(body, &force.X);
}
void applyForceAndTorque(const NewtonBody* Floor)
{
float massF;
float IxxF;
float IyyF;
float IzzF;
NewtonBodyGetMassMatrix (Floor, &massF, &IxxF, &IyyF, &IzzF);
vector3df force (NEWTON_GRAVITY * massF , 0.0f , 0.0f);
vector3df torque (0.0f, 0.0f, 0.0f);
NewtonBodySetForce(Floor, &force.X);
}
void DrawScene()
{
NewtonBodySetForceAndTorqueCallback(body, applyForceAndTorqueEvent);
NewtonBodySetForceAndTorqueCallback(Floor, applyForceAndTorque);
if (device->getTimer()->getTime() > lasttick + 10) {
lasttick = device->getTimer()->getTime();
NewtonUpdate(nWorld, 0.01f);
}
float matrix[4][4];
NewtonBodyGetMatrix(body, &matrix[0][0]);
float matrixF[4][4];
NewtonBodyGetMatrix(Floor, &matrixF[0][0]);
matrix4 mat;
memcpy(mat.M, 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;
}
Why will the body not colide with the floor it just seems to pass right through it, i have created them both as individual bodies and applied 2 different callbacks but it just does not seem to work