00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00043 #include "../include/IPSA/SoPhysicsCylinder.h"
00044 #include "../include/IPSA/SoCollisionShapeCylinder.h"
00045
00046 #include <Inventor/nodes/SoCylinder.h>
00047 #include <Inventor/SbLinear.h>
00048
00049 SO_KIT_SOURCE(SoPhysicsCylinder);
00050
00053 void SoPhysicsCylinder::initClass()
00054 {
00055 SO_KIT_INIT_CLASS(SoPhysicsCylinder, SoPhysics, "Physics");
00056 }
00057
00058
00063 SoPhysicsCylinder::SoPhysicsCylinder(const SbString& nodeName )
00064 : SoPhysics(nodeName)
00065 {
00066 SO_KIT_CONSTRUCTOR(SoPhysicsCylinder);
00067 isBuiltIn = TRUE;
00068
00069 SO_KIT_ADD_FIELD(radius,(1.0f));
00070 SO_KIT_ADD_FIELD(height,(1.0f));
00071
00072 SO_KIT_CHANGE_ENTRY_TYPE(visualisationShape, SoNode, SoCylinder);
00073 SO_KIT_CHANGE_ENTRY_TYPE(collisionShape, SoCollisionShape, SoCollisionShapeCylinder);
00074
00075 SO_KIT_CHANGE_NULL_BY_DEFAULT(visualisationShape, FALSE);
00076 SO_KIT_CHANGE_NULL_BY_DEFAULT(collisionShape, FALSE);
00077
00078 SO_KIT_INIT_INSTANCE();
00079
00080 updateDependentObjectsTrigger.appendConnection(&radius);
00081 updateDependentObjectsTrigger.appendConnection(&height);
00082
00089 CoinRefTransform.setRotate(SbRotation(SbVec3f(1,0,0),(float)(M_PI/2)));
00090 }
00091
00097 dMass SoPhysicsCylinder::getInitialMass() {
00098
00099
00100 float m = this->mass.getValue();
00101 float r = this->radius.getValue();
00102 float l = this->height.getValue();
00103 SbVec3f scaling = this->scale.getValue();
00104
00105 float x = scaling[0] * r;
00106 float y = scaling[1] * r;
00107 float h = scaling[2] * l;
00108
00109 inertia.enableNotify(false);
00110 float a = (m/6.0f) * (3*(y*y) + 4*(h*h));
00111 float b = (m/6.0f) * (3*(x*x) + 4*(h*h));
00112 float c = 0.5f * m * ((y*y) + (x*x));
00113 this->inertia.set1Value(0,a,0,0);
00114 this->inertia.set1Value(1,0,b,0);
00115 this->inertia.set1Value(2,0,0,c);
00116 inertia.enableNotify(true);
00117 SbVec3f i0 = this->inertia[0];
00118 SbVec3f i1 = this->inertia[1];
00119 SbVec3f i2 = this->inertia[2];
00120
00121 dMass mass;
00122 dMassSetParameters(&mass, m, 0,0,0, i0[0],i1[1],i2[2], i0[1],i0[2],i1[2]);
00123
00124 return mass;
00125 }
00126
00127
00133 void SoPhysicsCylinder::updateDependentObjects()
00134 {
00135
00136 SoCylinder* visShape = dynamic_cast<SoCylinder*>(this->getPart("visualisationShape", FALSE));
00137 if (NULL != visShape)
00138 {
00139 visShape->radius.setValue(radius.getValue());
00140 visShape->height.setValue(height.getValue());
00141 }
00142
00143 if (FALSE == AUTO_UPDATE_COLLISION_SHAPE.getValue())
00144 return;
00145
00146
00147 SoCollisionShapeCylinder* cShape = dynamic_cast<SoCollisionShapeCylinder*> (this->getPart("collisionShape", FALSE));
00148 if (NULL != cShape)
00149 {
00150 cShape->radius.setValue(radius.getValue());
00151 cShape->height.setValue(height.getValue());
00152 }
00153 }