Code: Select all
mesh = Sys.smgr->getMesh("data/plate.3ds");
node = Sys.smgr->addAnimatedMeshSceneNode(mesh);
physicsman.createCube(node);
Code: Select all
NewtonCube *physicsman::createCube(ISceneNode *node)
{
NewtonCube *tmp = new NewtonCube;
//tmp->mesh = smgr->getMesh("data/smallcube.3ds");
//tmp->node = smgr->addAnimatedMeshSceneNode(tmp->mesh);
//tmp->node->setMaterialTexture(0, driver->getTexture("data/crate.jpg"));
// Create a box primitive. 38 is just an estimated value of the size of the model,
tmp->collision = NewtonCreateBox(nWorld, 50, 50, 50, NULL);
tmp->body = NewtonCreateBody(nWorld, tmp->collision);
// Set user data pointer to the scene node
NewtonBodySetUserData(tmp->body, tmp->node);
// Set body mass & inertia matrix
NewtonBodySetMassMatrix (tmp->body, 10.0f, 150.0f, 150.0f, 150.0f);
// Set the freeze threshhold to 1 unit (default is 0.01 but irrlight uses a large unit scale)
NewtonBodySetFreezeTreshold(tmp->body, 1.0, 1.0, 1.0);
NewtonBodySetAutoFreeze(tmp->body,0);
// Set callback functions for the body
NewtonBodySetForceAndTorqueCallback(tmp->body, EnemyApplyForceAndTorqueEvent);
NewtonBodySetMaterialGroupID (tmp->body, metalID);
if (currentCube == 512)
{
printf("* Too many cubes!");
return NULL;
}
cubes[currentCube] = tmp;
currentCube ++;
printf("\n\nPlayer physics object created\n");
return tmp;
}
physicsman.cpp(110): error C2065: 'node' : undeclared identifier
physicsman.cpp(110): error C2761: 'NewtonCube *physicsman::createCube(void)' : member function redeclaration not allowed
And here is the header for the physics manager class. The above function is defined here. As you can see from the lines
// Set user data pointer to the scene node
NewtonBodySetUserData(tmp->body, tmp->node);
the function needs to know which node to attach the body to.
Code: Select all
#include "StdAfx.h"
#include <Newton.h>
#if !defined(PHYSICSMAN_H)
#define PHYSICSMAN_H
struct NewtonCube {
ISceneNode *node;
NewtonBody *body;
NewtonCollision *collision;
};
class physicsman
{
// misc
int lastFPS;
unsigned int lasttick;
public:
// Newton vars
NewtonWorld *nWorld;
NewtonCollision* collisionMap;
NewtonBody* collisionMapbody;
//////////////////////////////////////////////////////////////////////////
// Newton Callbacks
static void _cdecl ApplyForceAndTorqueEvent (const NewtonBody* body);
static void _cdecl EnemyApplyForceAndTorqueEvent (const NewtonBody* body);
void Init();
NewtonCube *createPlayerBody();
NewtonCube *createCube(ISceneNode *node);
void Finish();
void SetPlayerPos(float PositionX, float PositionY, float PositionZ);
void SetEnemyPos(float PositionX, float PositionY, float PositionZ);
void Update();
NewtonCube *cubes[512];
int currentCube;
};
#endif
physicsman.h( 8 ): error C2143: syntax error : missing ';' before '*'
physicsman.h( 8 ): error C2501: 'NewtonCube::ISceneNode' : missing storage-class or type specifiers
physicsman.h( 8 ): error C2501: 'NewtonCube::node' : missing storage-class or type specifiers
I'm not sure if this is the right way to do this. Please help me out!
Thanks for your time.