00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00047 #include "../include/IPSA/SoPhysicsTriMesh.h"
00048 #include "../include/IPSA/SoCollisionShapeTriMesh.h"
00049 #include <Inventor/nodes/SoRotation.h>
00050
00051 SO_KIT_SOURCE(SoPhysicsTriMesh);
00052
00055 void SoPhysicsTriMesh::initClass()
00056 {
00057 SO_KIT_INIT_CLASS(SoPhysicsTriMesh, SoPhysics, "Physics");
00058 }
00059
00060
00065 SoPhysicsTriMesh::SoPhysicsTriMesh(const SbString& nodeName )
00066 : SoPhysics(nodeName),
00067 matrixbuf0(false),
00068 dblbfilled(false)
00069 {
00070 SO_KIT_CONSTRUCTOR(SoPhysicsTriMesh);
00071 isBuiltIn = TRUE;
00072
00073 SO_KIT_INIT_INSTANCE();
00074
00075
00076 }
00077
00078
00082 SoBaseKit* SoPhysicsTriMesh::copy(SbBool copyConnections) const
00083 {
00084
00085
00086 SoPhysicsTriMesh *newSoPhysicsTriMesh = (SoPhysicsTriMesh *) SoPhysics::copy(copyConnections);
00087
00088 for(unsigned int i = 0; i < sizeof(matrix_dblbuff); i++)
00089 {
00090 newSoPhysicsTriMesh->matrix_dblbuff[i] = matrix_dblbuff[i];
00091 }
00092 newSoPhysicsTriMesh->matrixbuf0 = matrixbuf0;
00093 newSoPhysicsTriMesh->dblbfilled = dblbfilled;
00094
00095 return newSoPhysicsTriMesh;
00096 }
00097
00098
00103 void SoPhysicsTriMesh::updateOIPosition()
00104 {
00105 SoPhysics::updateOIPosition();
00106
00107
00108 const dReal* TRANSLATION = dBodyGetPosition (body);
00109 const dReal* ROTATION = dBodyGetQuaternion (body);
00110
00111
00112
00113 dReal* p_matrix = matrix_dblbuff + ((matrixbuf0==false) ? 0 : 16);
00114
00115 p_matrix[ 0 ] = ROTATION[ 0 ]; p_matrix[ 1 ] = ROTATION[ 1 ]; p_matrix[ 2 ] = ROTATION[ 2 ]; p_matrix[ 3 ] = 0;
00116 p_matrix[ 4 ] = ROTATION[ 4 ]; p_matrix[ 5 ] = ROTATION[ 5 ]; p_matrix[ 6 ] = ROTATION[ 6 ]; p_matrix[ 7 ] = 0;
00117 p_matrix[ 8 ] = ROTATION[ 8 ]; p_matrix[ 9 ] = ROTATION[ 9 ]; p_matrix[10 ] = ROTATION[10 ]; p_matrix[11 ] = 0;
00118 p_matrix[12 ] = TRANSLATION[ 0 ]; p_matrix[13 ] = TRANSLATION[ 1 ]; p_matrix[14 ] = TRANSLATION[ 2 ]; p_matrix[15 ] = 1;
00119
00120
00121 matrixbuf0 = !matrixbuf0;
00122 assert( geom != NULL );
00123
00124 if (dblbfilled)
00125 dGeomTriMeshSetLastTransform( geom, *(dMatrix4*)( matrix_dblbuff + ((matrixbuf0==false) ? 0 : 16) ) );
00126
00127 dblbfilled = true;
00128 }
00129
00130
00138 dMass SoPhysicsTriMesh::getInitialMass()
00139 {
00140 assert( geom != NULL );
00141
00142
00143 dMass triMeshMass;
00144 dMassSetTrimeshTotal( &triMeshMass, this->mass.getValue(), geom );
00145 printf("getInitialMass(Tri): COG before shift is [%f,%f,%f], mass %2.2f\n",triMeshMass.c[0],triMeshMass.c[1],triMeshMass.c[2],triMeshMass.mass);
00146
00147
00148 dGeomSetPosition(geom, triMeshMass.c[0], triMeshMass.c[1], triMeshMass.c[2]);
00149 dMassTranslate(&triMeshMass, -triMeshMass.c[0], -triMeshMass.c[1], -triMeshMass.c[2]);
00150
00151 assert( dMassCheck(&triMeshMass) );
00152
00153 return triMeshMass;
00154 }