I wanted to implement the newton physics engine, and I wasn't having any problems until I tried to create a camera that is linked to Newton using a Newton Body. Can someone please point me to a code snippet with a camera containing one?
Thanks in advance.
Newton + Irrlicht Question
Code: Select all
class CNewtonianNode;
class CNewtonNodeManager
{
private:
list<CNewtonianNode *> nodes;
static u32 id_counter;
unsigned long lastTime;
bool firstRun;
public:
void Update(u32 timeMS);
CNewtonianNode * addMeshSceneNode(IMesh * mesh,NewtonCollision * collision,vector3df pos,vector3df rot,vector3df sca,float mass,float max_vel,float I[3]);
CNewtonianNode * addAnimatedMeshSceneNode(IAnimatedMesh * mesh,NewtonCollision * collision,vector3df pos,vector3df rot,vector3df sca,float mass,float max_vel,float I[3])
CNewtonianNode * addCameraSceneNode(vector3df position,vector3df target,float mass,float max_vel);
void clearAll();
void clear(u32 id);
CNewtonianNodeManager();
~CNewtonianNodeManager();
};
class CNewtonianNode : public IReferenceCounted
{
private:
ISceneNode * node;
NewtonBody * body;
float max_velocity;
vector3df velocity;
u32 id;
CNewtonianNodeManager * manager;
friend class CNewtonianManager;
public:
void setMatrix(matrix4 &mat);
matrix4 getMatrix();
ISceneNode * getNode();
NewtonBody * getBody();
void setMassMatrix(float mass,float Ixx,float Iyy,float Izz);
float * getMassMatrix();
void Update(u32 timeMS);
CNewtonianNode();
~CNewtonianNode();
void setDestructorCallback(NewtonBodyDestructor callback);
void setForceAndTorqueCallback(NewtonApplyForceAndTorque callback);
void setTransformationCallback(NewtonSetTransform callback);
float getForce();
unsigned int getID();
void setPosition(vector3df pos);
void setRotation(vector3df rot);
void remove();
void setMaxVelocity(float vel);
vector3df getVelocity();
void setVelocity(vector3df velocity);
};
class ICameraNewtonSceneNode : public ICameraSceneNode
{
public::
CCameraSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
const vector3df& position = vector3df(0,0,0),
const vector3df& lookat = vector3df(0,0,100),float mass,float max_vel);
virtual ~CCameraSceneNode();
virtual void setProjectionMatrix(const matrix4& projection);
virtual const matrix4& getProjectionMatrix() const;
virtual const matrix4& getViewMatrix() const;
virtual bool OnEvent(const SEvent& event);
virtual void setTarget(const vector3df& pos);
virtual vector3df getTarget() const;
virtual void setUpVector(const vector3df& pos);
virtual vector3df getUpVector() const;
virtual f32 getNearValue() const;
virtual f32 getFarValue() const;
virtual f32 getAspectRatio() const;
virtual f32 getFOV() const;
virtual void setNearValue(f32 zn);
virtual void setFarValue(f32 zf);
virtual void setAspectRatio(f32 aspect);
virtual void setFOV(f32 fovy);
virtual void OnRegisterSceneNode();
void animate(u32 ms);
virtual void render();
virtual const aabbox3d<f32>& getBoundingBox() const;
virtual const SViewFrustum* getViewFrustum() const;
virtual void setInputReceiverEnabled(bool enabled);
virtual bool isInputReceiverEnabled() const;
virtual void serializeAttributes(IAttributes* out, SAttributeReadWriteOptions* options=0) const;
virtual void deserializeAttributes(IAttributes* in, SAttributeReadWriteOptions* options=0);
virtual ESCENE_NODE_TYPE getType() const { return ESNT_CAMERA; }
virtual vector3df getAbsolutePosition() const;
NewtonBody * body;
private:
void recalculateProjectionMatrix();
void recalculateViewArea();
vector3df Target;
vector3df UpVector;
f32 Fovy; // Field of view, in radians.
f32 Aspect; // Aspect ratio.
f32 ZNear; // value of the near view-plane.
f32 ZFar; // Z-value of the far view-plane.
SViewFrustum ViewArea;
ICursorControl * cursor;
bool InputReceiverEnabled;
float max_velocity;
};
(Yes, I stole some of that from the base ICameraSceneNode. I understand the transformations involved, but have problems making these things work with the Newton physics engine.)
Thanks in advance, and sorry if it sounds confusing.