00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00039 #include "../include/IPSA/SoPhysicsSphere.h"
00040 #include "../include/IPSA/SoCollisionShapeSphere.h"
00041
00042 #include <Inventor/nodes/SoSphere.h>
00043
00044 SO_KIT_SOURCE(SoPhysicsSphere);
00045
00046
00049 void SoPhysicsSphere::initClass()
00050 {
00051 SO_KIT_INIT_CLASS(SoPhysicsSphere, SoPhysics, "Physics");
00052 }
00053
00054
00059 SoPhysicsSphere::SoPhysicsSphere(const SbString& nodeName )
00060 : SoPhysics(nodeName)
00061 {
00062 SO_KIT_CONSTRUCTOR(SoPhysicsSphere);
00063 isBuiltIn = TRUE;
00064
00065 SO_KIT_ADD_FIELD(radius, (1.0f));
00066
00067 SO_KIT_CHANGE_ENTRY_TYPE(visualisationShape, SoNode, SoSphere);
00068 SO_KIT_CHANGE_ENTRY_TYPE(collisionShape, SoCollisionShape, SoCollisionShapeSphere);
00069
00070 SO_KIT_CHANGE_NULL_BY_DEFAULT(visualisationShape, FALSE);
00071 SO_KIT_CHANGE_NULL_BY_DEFAULT(collisionShape, FALSE);
00072
00073 SO_KIT_INIT_INSTANCE();
00074
00075 updateDependentObjectsTrigger.appendConnection(&radius);
00076 }
00077
00078
00084 dMass SoPhysicsSphere::getInitialMass() {
00085 float r = this->radius.getValue();
00086 SbVec3f scaling = this->scale.getValue();
00087
00088 float x = scaling[0] * r;
00089 float y = scaling[1] * r;
00090 float z = scaling[2] * r;
00091
00092 inertia.enableNotify(false);
00093 float m = this->mass.getValue();
00094 float a = 0.2f * m * ((y*y) + (z*z));
00095 float b = 0.2f * m * ((x*x) + (z*z));
00096 float c = 0.2f * m * ((y*y) + (x*x));
00097
00098 this->inertia.set1Value(0,a,0,0);
00099 this->inertia.set1Value(1,0,b,0);
00100 this->inertia.set1Value(2,0,0,c);
00101 inertia.enableNotify(true);
00102 SbVec3f i0 = this->inertia[0];
00103 SbVec3f i1 = this->inertia[1];
00104 SbVec3f i2 = this->inertia[2];
00105
00106 dMass mass;
00107 dMassSetParameters(&mass, m, 0,0,0, i0[0],i1[1],i2[2], i0[1],i0[2],i1[2]);
00108
00109 return mass;
00110 }
00111
00112
00118 void SoPhysicsSphere::updateDependentObjects()
00119 {
00120 const float RADIUS_VALUE = radius.getValue();
00121
00122
00123 SoSphere* visShape = dynamic_cast<SoSphere*> (this->getPart("visualisationShape", FALSE));
00124 if (NULL != visShape)
00125 {
00126 visShape->radius.setValue(RADIUS_VALUE);
00127 }
00128
00129 if (FALSE == AUTO_UPDATE_COLLISION_SHAPE.getValue())
00130 return;
00131
00132
00133 SoCollisionShapeSphere* cShape = dynamic_cast<SoCollisionShapeSphere*> (this->getPart("collisionShape", FALSE));
00134 if (NULL != cShape)
00135 {
00136 cShape->radius.setValue(RADIUS_VALUE);
00137 }
00138 }