void RigidBody::_copyFrom(const ComponentBase *model) { init(); auto m = (RigidBody*)model; #ifdef EDITOR_ENABLED editorUpdate(); if (editorStruct) { editorStruct->copyDatas(m); editorStruct->refreshDatas(this); Link *link = entity.getLinkPtr(); if (isKinematic()) { auto p = posFromMat4(link->getGlobalTransform()); setPosition(posFromMat4(link->getGlobalTransform())); setRotation(link->getOrientation()); // global orientation not supported } } #else setAngularDrag(m->getAngularDrag()); setAngularVelocity(m->getAngularVelocity()); setCenterOfMass(m->getCenterOfMass()); setLinearDrag(m->getLinearDrag()); setLinearVelocity(m->getLinearVelocity()); setMass(m->getMass()); setDiagonalInertiaTensor(m->getDiagonalInertiaTensor()); setMaxAngularVelocity(m->getMaxAngularVelocity()); setMaxDepenetrationVelocity(m->getMaxDepenetrationVelocity()); affectByGravity(m->isAffectedByGravity()); setPosition(m->getPosition()); setRotation(m->getRotation()); setAsKinematic(m->isKinematic()); setCollisionDetectionMode(m->getCollisionDetectionMode()); #endif }
//------------------------------ void MolState::align() { // Shift center of mass to the origin: shiftCoordinates( getCenterOfMass() ); // Aligh moment of inertia principal axes: KMatrix MOI_tensor(3,3), MOI_eigenValues(3,1), MOI_eigenVectors(3,3); MOI_tensor = getMomentOfInertiaTensor(); //MOI_tensor.Print("Moment of inertia tensor"); MOI_eigenVectors=MOI_tensor.Herm_Diag(MOI_eigenValues, true); // true=>eigen vals in the descending order; eigen vectors in ROWS. // MOI_eigenVectors.Print("MOI eigen vectors"); // MOI_eigenValues.Print("MOI eigen values"); // compute the determinant of MOI matrix: double det_tmp = MOI_eigenVectors.Determinant(); // if determinant is = 1 than it is a proper rotation; // if it is = -1 than it is rotation+reflection (switch from left handed to the right handed coord.system); swap x&y axes: if (det_tmp < 0) MOI_eigenVectors.SwapRows(0,1); transformCoordinates(MOI_eigenVectors); // rotate coordinates using matrix of the MOI eigen vectors std::cout << "Coordinate axes were aligned with MOI principal axes; center mass was shifted to the origin.\n"; }
Ogre::Vector3 OctreeSDF::getCenterOfMass() { float mass = 0.0f; return getCenterOfMass(mass); }
void CX3DOpenHRPSegmentNode::print(int indent) { FILE *fp = CX3DParser::getDebugLogFp(); int nMax = CX3DParser::getMaxPrintElemsForMFField(); bool bPartialPrint = false; char *nodeName = getNodeName(); if (nodeName) { float x, y, z; MFNode *nodes; int i, n; CX3DParser::printIndent(indent); fprintf(fp, "%s (%s)\n", nodeName, CX3DNode::getNodeTypeString(getNodeType())); CX3DParser::printIndent(indent+1); fprintf(fp, "children\n"); nodes = getChildren(); n = nodes->count(); for (i=0; i<n; i++) { CX3DNode *child = nodes->getNode(i); if (child) { child->print(indent+2); } } CX3DParser::printIndent(indent+1); fprintf(fp, "name (%s)\n", m_name.getValue()); CX3DParser::printIndent(indent+1); fprintf(fp, "coord\n"); CX3DNode *pCoord = getCoord()->getNode(); if (pCoord) pCoord->print(indent+2); CX3DParser::printIndent(indent+1); getCenterOfMass()->getValue(x, y, z); fprintf(fp, "centerOfMass : (%f %f %f)\n", x, y, z); CX3DParser::printIndent(indent+1); fprintf(fp, "displacers\n"); nodes = getDisplacers(); n = nodes->count(); for (i=0; i<n; i++) { CX3DNode *child = nodes->getNode(i); if (child) { child->print(indent+2); } } CX3DParser::printIndent(indent+1); fprintf(fp, "mass (%f)\n", getMass()->getValue()); CX3DParser::printIndent(indent+1); n = m_momentsOfInertia.count(); fprintf(fp, "momentsOfInertia [%d]\n", n); if ((nMax > 0) && (n > nMax)) { n = nMax; bPartialPrint = true; } else { bPartialPrint = false; } CX3DParser::printIndent(indent+2); fprintf(fp, "("); for (i=0; i<n; i++) { fprintf(fp, "%f ", m_momentsOfInertia.getValue(i)); } if (bPartialPrint) fprintf(fp, "..."); fprintf(fp, ")\n"); } }