void SampleSubmarine::onSubstep(float dtime) { // user input -> forces handleInput(); // change current every 0.01s static PxReal sElapsedTime = 0.0f; sElapsedTime += mPause ? 0 : dtime; if(sElapsedTime > 0.01f) { static PxReal angle = 0; angle += sElapsedTime*0.01f; angle = angle < (PxTwoPi) ? angle : angle - PxTwoPi; sElapsedTime = 0; gBuoyancy.z = 0.15f * PxSin(angle * 50); PxQuat yRot = PxQuat(angle, PxVec3(0,1,0)); gBuoyancy = yRot.rotate(gBuoyancy); // apply external forces to seamines const size_t nbSeamines = mSeamines.size(); for(PxU32 i = 0; i < nbSeamines; i++) { Seamine* mine = mSeamines[i]; mine->mMineHead->addForce(gBuoyancy, PxForceMode::eACCELERATION); const size_t nbLinks = mine->mLinks.size(); for(PxU32 j = 0; j < nbLinks; j++) { mine->mLinks[j]->addForce(gBuoyancy, PxForceMode::eACCELERATION); } } } if(mSubmarineActor) { //convert forces from submarine the submarine's body local space to global space PxQuat submarineOrientation = mSubmarineActor->getGlobalPose().q; gForce = submarineOrientation.rotate(gForce); gTorque = submarineOrientation.rotate(gTorque); // add also current forces to submarine gForce.z += gBuoyancy.z * 5.0f; // apply forces in global space and reset mSubmarineActor->addForce(gForce); mSubmarineActor->addTorque(gTorque); gForce = PxVec3(0); gTorque = PxVec3(0); } }
static PxTransform computeBoneTransform(PxTransform &rootTransform, Acclaim::Bone &bone, PxVec3* boneFrameData) { using namespace Acclaim; //PxTransform rootTransform(PxVec3(0.0f), PxQuat(PxIdentity)); PxTransform parentTransform = (bone.mParent) ? computeBoneTransform(rootTransform, *bone.mParent, boneFrameData) : rootTransform; PxQuat qWorld = EulerAngleToQuat(bone.mAxis); PxVec3 offset = bone.mLength * bone.mDirection; PxQuat qDelta = PxQuat(PxIdentity); PxVec3 boneData = boneFrameData[bone.mID-1]; if (bone.mDOF & BoneDOFFlag::eRX) qDelta = PxQuat(Ps::degToRad(boneData.x), PxVec3(1.0f, 0.0f, 0.0f)) * qDelta; if (bone.mDOF & BoneDOFFlag::eRY) qDelta = PxQuat(Ps::degToRad(boneData.y), PxVec3(0.0f, 1.0f, 0.0f)) * qDelta; if (bone.mDOF & BoneDOFFlag::eRZ) qDelta = PxQuat(Ps::degToRad(boneData.z), PxVec3(0.0f, 0.0f, 1.0f)) * qDelta; PxQuat boneOrientation = qWorld * qDelta * qWorld.getConjugate(); PxTransform boneTransform(boneOrientation.rotate(offset), boneOrientation); return parentTransform.transform(boneTransform); }
/** @brief update vertex position @date 2014-02-26 */ void RendererBezierShape::SetBezierCurve(const vector<PxVec3> &points, const PxVec3 &color)//color=PxVec(0,0,0) { const PxU32 numVerts = (NODE_COUNT-1)*CONER_COUNT + 1; // +1 is head vertex point const PxVec3 diffuse = color * 255; const PxU32 diffuseColor = m_renderer.convertColor(RendererColor(diffuse.x, diffuse.y, diffuse.z)); RENDERER_ASSERT(m_vertexBuffer, "Failed to create Vertex Buffer."); if (m_vertexBuffer) { PxU32 stride = 0; void* vertPositions = m_vertexBuffer->lockSemantic(RendererVertexBuffer::SEMANTIC_POSITION, stride); //void *colors = m_vertexBuffer->lockSemantic(RendererVertexBuffer::SEMANTIC_COLOR, stride); void *normals = m_vertexBuffer->lockSemantic(RendererVertexBuffer::SEMANTIC_NORMAL, stride); PxVec3 oldPos; int vtxOffset = 0; for (int i=0; i < NODE_COUNT-1; ++i) { PxVec3 pos; utility::bezier(pos, points, (float)i/(float)(NODE_COUNT-1)); PxQuat q; if (i > 0) { PxVec3 curve = pos - oldPos; curve.normalize(); utility::quatRotationArc(q, PxVec3(1,0,0), curve); } float DEPTH = .03f; if (i == NODE_COUNT-2) DEPTH += DEPTH*3; // arrow head for (int k=0; k < CONER_COUNT; ++k) { const float rad = -PxPi * 2.f * ((float)k/(float)CONER_COUNT); PxVec3 dir = PxQuat(rad, PxVec3(1,0,0)).rotate(PxVec3(0,1,0)); if (i > 0) dir = q.rotate(dir); *(PxVec3*)(((PxU8*)vertPositions) + vtxOffset) = pos + dir*DEPTH; *(PxVec3*)(((PxU8*)normals) + vtxOffset) = PxVec3(0,1,0); //*(PxU32*)(((PxU8*)colors) + vtxOffset) = diffuseColor; vtxOffset += stride; } // arrow head DEPTH += DEPTH; // head length if (i == NODE_COUNT-2) { utility::bezier(pos, points, 1); if ((pos-oldPos).magnitude() < 0.2f) { PxVec3 v0 = pos-oldPos; if (!v0.isZero()) { v0.normalize(); pos = oldPos + v0*0.2f; } } PxVec3 dir = q.rotate(PxVec3(1,0,0)); *(PxVec3*)(((PxU8*)vertPositions) + vtxOffset) = pos; *(PxVec3*)(((PxU8*)normals) + vtxOffset) = PxVec3(0,1,0); //*(PxU32*)(((PxU8*)colors) + vtxOffset) = diffuseColor; } oldPos = pos; } m_vertexBuffer->unlockSemantic(RendererVertexBuffer::SEMANTIC_POSITION); //m_vertexBuffer->unlockSemantic(RendererVertexBuffer::SEMANTIC_COLOR); m_vertexBuffer->unlockSemantic(RendererVertexBuffer::SEMANTIC_NORMAL); } }