Vec3D<> CVX_Sim::GetCM(void) { vfloat TotalMass = 0; Vec3D<> Sum(0,0,0); int nVox = NumVox(); for (int i=0; i<nVox; i++){ if (i==InputVoxSInd) continue; CVXS_Voxel* it = &VoxArray[i]; vfloat ThisMass = it->GetMass(); Sum += it->GetCurPos()*ThisMass; TotalMass += ThisMass; } return Sum/TotalMass; }
void CVXS_SimGLView::DrawForce(void) { CVXS_Voxel* pVox; float PrevLineWidth; glGetFloatv(GL_LINE_WIDTH, &PrevLineWidth); glLineWidth(1.0); glDisable(GL_LIGHTING); vfloat MaxForce = 0; int iT = pSim->NumBond(); int NumVox = pSim->NumVox(); if (NumVox <=0) return; vfloat VSize = pSim->VoxArray[0].GetNominalSize(); for (int i = 0; i<iT; i++){ //go through all the bonds... vfloat ThisMag = pSim->BondArrayInternal[i].GetForce1().Length(); if (ThisMag > MaxForce) MaxForce = ThisMag; } vfloat ForceScale = 0.3*VSize/MaxForce; //Vox size / max Force // int x, y, z; glBegin(GL_LINES); glLoadName (-1); //to disable picking for (int i = 0; i<NumVox; i++) //go through all the voxels... { //pSim->pEnv->pObj->GetXYZNom(&x, &y, &z, pSim->StoXIndexMap[i]); //if (ViewSection && z>SectionLayer) continue; //exit if obscured in a section view! pVox = &pSim->VoxArray[i]; Vec3D<> Center = pVox->GetCurPos(); CQuat<> Angle = pVox->GetCurAngle(); Vec3D<> PointToDrawFrom; for (int i=0; i<6; i++) //for each potential bond { switch (i){ case BD_PX: PointToDrawFrom = Center + Angle.RotateVec3D(Vec3D<>(0.2*VSize, 0, 0)); break; case BD_NX: PointToDrawFrom = Center + Angle.RotateVec3D(Vec3D<>(-0.2*VSize, 0, 0)); break; case BD_PY: PointToDrawFrom = Center + Angle.RotateVec3D(Vec3D<>(0, 0.2*VSize, 0)); break; case BD_NY: PointToDrawFrom = Center + Angle.RotateVec3D(Vec3D<>(0, -0.2*VSize, 0)); break; case BD_PZ: PointToDrawFrom = Center + Angle.RotateVec3D(Vec3D<>(0, 0, 0.2*VSize)); break; case BD_NZ: PointToDrawFrom = Center + Angle.RotateVec3D(Vec3D<>(0, 0, -0.2*VSize)); break; }; CVXS_BondInternal* pBond = pVox->GetpInternalBond((BondDir)i); if (pBond){ glColor4d(1.0, 0.0, 0.0, 1.0); //red Vec3D<> PointToDrawTo; //Total Force if (pVox->IAmInternalVox2(i)) PointToDrawTo = PointToDrawFrom+ForceScale*pBond->GetForce2(); else PointToDrawTo = PointToDrawFrom+ForceScale*pBond->GetForce1(); CGL_Utils::DrawLineArrowD(PointToDrawFrom, PointToDrawTo, 1.0, CColor(1, 0, 0)); //Red //Axial Force if (pVox->IAmInternalVox2(i)) PointToDrawTo = PointToDrawFrom+ForceScale*pBond->AxialForce2; else PointToDrawTo = PointToDrawFrom+ForceScale*pBond->AxialForce1; CGL_Utils::DrawLineArrowD(PointToDrawFrom, PointToDrawTo, 1.0, CColor(0.2, 0.2, 0.7)); //Blue //Bending Force if (pVox->IAmInternalVox2(i)) PointToDrawTo = PointToDrawFrom+ForceScale*pBond->BendingForce2; else PointToDrawTo = PointToDrawFrom+ForceScale*pBond->BendingForce1; CGL_Utils::DrawLineArrowD(PointToDrawFrom, PointToDrawTo, 1.0, CColor(0.2, 0.7, 0.2)); //Green //Shear Force if (pVox->IAmInternalVox2(i)) PointToDrawTo = PointToDrawFrom+ForceScale*pBond->ShearForce2; else PointToDrawTo = PointToDrawFrom+ForceScale*pBond->ShearForce1; CGL_Utils::DrawLineArrowD(PointToDrawFrom, PointToDrawTo, 1.0, CColor(0.7, 0.2, 0.7)); //Purple } } } glEnd(); glLineWidth(PrevLineWidth); glEnable(GL_LIGHTING); }