alberts
29-08-2006 12:58:14
Hi
I'm having problems with the setUserData method. I've defined a class to store a set of values. It works well with simple values (int, float, vector3...). I can recover them using the getUserData method. The problem is that the values of an array of floats are lost. Here are the code involved:
In AerodynamicProperties constructor:
Later, in callback
But inside CalculateAirfoilForce method of AerodynamicProperties, the arrays have strange values. The rest of variables of AerodynamicProperties, like "name" are kept well.
What could be the problem?
Thanks in advance and I apologize for my english
Edit: It was my fault.
I was not reserving memory in the constructor for the arrays. I thought it was ref counted or something (It's my first projects in c++ for years )
Thanks!
I'm having problems with the setUserData method. I've defined a class to store a set of values. It works well with simple values (int, float, vector3...). I can recover them using the getUserData method. The problem is that the values of an array of floats are lost. Here are the code involved:
float liftCoefficient[9] = {-0.54f, -0.2f, 0.2f, 0.57f, 0.92f, 1.21f, 1.43f, 1.4f, 1.0f};
float dragCoefficient[9] = {0.01f, 0.0074f, 0.004f, 0.009f, 0.013f, 0.023f, 0.05f, 0.12f, 0.21f};
float angleCoefficient[9] = {-8.0f, -4.0f, 0.0f, 4.0f, 8.0f, 12.0f, 16.0f, 20.0f, 24.0f};
mWing = makeSimpleBox(*mWingSize,5,Ogre::Vector3(1.5,0.8,0),orient,"wing");
mWing->setCustomForceAndTorqueCallback<Airplane>( &Airplane::AerodynamicForceCallback, this );
AerodynamicProperties* ap = new AerodynamicProperties("WING",mWing,mSceneManager,&Ogre::Vector3(mWingSize->x,0,0),&Ogre::Vector3(0,0,mWingSize->z),&Ogre::Vector3(0,1,0)
,liftCoefficient,dragCoefficient,angleCoefficient,coefficientCount);
mWing->setUserData(ap);
In AerodynamicProperties constructor:
...
mName = name;
mBody = body;
mCoefficientCount = CoefficientCount;
mLiftCoefficient = LiftCoefficient;
for(int i=0;i<CoefficientCount;i++)
{
mLiftCoefficient[i] = LiftCoefficient[i];
}
...
Later, in callback
AerodynamicProperties* ap = (AerodynamicProperties*)me->getUserData();
netForce = ap->CalculateAirfoilForce(relWindVeloc);
But inside CalculateAirfoilForce method of AerodynamicProperties, the arrays have strange values. The rest of variables of AerodynamicProperties, like "name" are kept well.
What could be the problem?
Thanks in advance and I apologize for my english
Edit: It was my fault.
I was not reserving memory in the constructor for the arrays. I thought it was ref counted or something (It's my first projects in c++ for years )
Thanks!