hinge callback

PJani

17-02-2009 23:47:05

hy i hope someone does know how to solve this, i have frustrations with this for almost 2days and i dont get enywhere.
I created class for creating hinges and holding up data about limits of hinges and motors but i can't figoure out how to get pointer of method for hinge call back here is source code of hinge creator and header

///////////////////////////
// RE JOINTS
// 170209
///////////////////////////

#include "newton\ReJoints.h"

void ReHingeJoint::joint_callback(OgreNewt::BasicJoints::Hinge* me){
if(enablemotor){

me->setCallbackAccel(me->calculateStopAlpha(Ogre::Radian(ang)));
}
}
ReHingeJoint::ReHingeJoint(OgreNewt::World* world,OgreNewt::Body* child,OgreNewt::Body* parent,Ogre::Vector3 pos, Ogre::Vector3 pin){
jnt = new OgreNewt::BasicJoints::Hinge(world,child,parent ,pos, pin);
OgreNewt::BasicJoints::Hinge::HingeCallback f = ReHingeJoint::joint_callback;
jnt->setCallback(f);

ang = Ogre::Degree(0);

}
void ReHingeJoint::RotateTo(Ogre::Degree deg){
ang = deg;
//angle2 = ang.valueDegrees();
}
void ReHingeJoint::updateHinge(){
//angle2 = ang.valueDegrees();

}

void ReHingeJoint::setMotor(bool motor){
enablemotor = motor;
//enableengine = enablemotor;
}

ReHingeJoint::~ReHingeJoint(){

delete jnt;
}




header

#ifndef REJOINTS_H_INCLUDED
#define REJOINTS_H_INCLUDED

#include <OgreNewt.h>
#include <Ogre.h>

class ReHingeJoint{
public:
ReHingeJoint(OgreNewt::World* world,OgreNewt::Body* child,OgreNewt::Body* parent,Ogre::Vector3 pos, Ogre::Vector3 pin);
void RotateTo(Ogre::Degree deg);
void setMotor(bool motor);
void deltaMove(float delta){ang = Ogre::Degree(ang.valueDegrees() + delta);}
void updateHinge();
OgreNewt::BasicJoints::Hinge* getHinge(){ return jnt; }

~ReHingeJoint();
//void ReHingeJoint::joint_callback(OgreNewt::BasicJoints::Hinge* me);
//void *joint_callback(OgreNewt::BasicJoints::Hinge* me);
private:
void ReHingeJoint::joint_callback(OgreNewt::BasicJoints::Hinge* me);
bool enablemotor;
float acell;
Ogre::Degree ang;
OgreNewt::BasicJoints::Hinge* jnt;
};


#endif // REJOINTS_H_INCLUDED

PJani

19-02-2009 13:47:06

i solved this problem by adding two functions and one varble to OgreNewt lib...and it works i declared callback as extern "C"

this part makes this posible to access functions in that class
ReHingeJoint* rhj = (ReHingeJoint*)(me->getExternalClass());
///////////////////////////
// RE JOINTS
// 170209
///////////////////////////

#include "ReJoints.h"

#include <map>
#include <iostream>

//map<OgreNewt::BasicJoints::Hinge*,ReHingeJoint*> hinge_callbacks;

extern "C" void joint_callback(OgreNewt::BasicJoints::Hinge* me){
ReHingeJoint* rhj = (ReHingeJoint*)(me->getExternalClass());
//printf("ANGLE: %f\n", me->getJointAngle().valueDegrees());
if(rhj->getMotorStatus()){

me->setCallbackAccel(me->calculateStopAlpha(Ogre::Degree(me->getJointAngle().valueDegrees()+rhj->getDelta())));

}

}

ReHingeJoint::ReHingeJoint(OgreNewt::World* world,OgreNewt::Body* child,OgreNewt::Body* parent,Ogre::Vector3 pos, Ogre::Vector3 pin){
jnt = new OgreNewt::BasicJoints::Hinge(world,child,parent ,pos, pin);
//hinge_callback[jnt]=this;
jnt->setExternalClass(this);
//printf("ANGLE %p\n",rhj);
OgreNewt::BasicJoints::Hinge::HingeCallback f = joint_callback;

jnt->setCallback(f);

ang = Ogre::Degree(0);

}
void ReHingeJoint::RotateTo(Ogre::Degree deg){
ang = deg;
}
void ReHingeJoint::setMotor(bool motor){
enablemotor = motor;
}

ReHingeJoint::~ReHingeJoint(){

//hinge_callbacks.erase(jnt);
delete jnt;
}


PJani

19-02-2009 15:19:06

Does somebody knows how is calculateStopAlpha(Angle) calculated? on hinge joints