udword Havok::BatchRaycasts(PintSQThreadContext context, udword nb, PintRaycastHit* dest, const PintRaycastData* raycasts) { ASSERT(mPhysicsWorld); hkpWorldRayCastOutput output; udword NbHits = 0; while(nb--) { hkpWorldRayCastInput input; input.m_from = ToHkVector4(raycasts->mOrigin); input.m_to = ToHkVector4(raycasts->mOrigin + raycasts->mDir*raycasts->mMaxDist); output.reset(); mPhysicsWorld->castRay(input, output); if(output.m_rootCollidable) { NbHits++; FillResultStruct(*dest, output, raycasts->mOrigin, raycasts->mDir, raycasts->mMaxDist); } else { dest->mObject = null; } raycasts++; dest++; } return NbHits; }
udword Havok::BatchRaycastsPhantom(udword nb, PintRaycastHit* dest, const PintRaycastData* raycasts, void** phantoms) { ASSERT(phantoms); hkpAabbPhantom** ph = (hkpAabbPhantom**)phantoms; udword NbHits = 0; while(nb--) { hkpWorldRayCastInput input; input.m_from = ToHkVector4(raycasts->mOrigin); input.m_to = ToHkVector4(raycasts->mOrigin + raycasts->mDir*raycasts->mMaxDist); hkpAabbPhantom* phantom = *ph++; hkpWorldRayCastOutput output; phantom->castRay(input, output); if(output.m_rootCollidable) { NbHits++; FillResultStruct(*dest, output, raycasts->mOrigin, raycasts->mDir, raycasts->mMaxDist); } else { dest->mObject = null; } raycasts++; dest++; } return NbHits; }
void Havok::ApplyActionAtPoint(PintObjectHandle handle, PintActionType action_type, const Point& action, const Point& pos) { hkpRigidBody* RB = (hkpRigidBody*)handle; if(action_type==PINT_ACTION_FORCE) { RB->applyForce(1.0f/60.0f, ToHkVector4(action), ToHkVector4(pos)); } else if(action_type==PINT_ACTION_IMPULSE) { RB->applyPointImpulseAsCriticalOperation(ToHkVector4(action), ToHkVector4(pos)); } else ASSERT(0); }
udword Havok::BatchSphereSweeps(PintSQThreadContext context, udword nb, PintRaycastHit* dest, const PintSphereSweepData* sweeps) { ASSERT(mPhysicsWorld); hkpClosestCdPointCollector castCollector; udword NbHits = 0; while(nb--) { hkpLinearCastInput input; input.m_to = ToHkVector4(sweeps->mSphere.mCenter + sweeps->mDir*sweeps->mMaxDist); HAVOK_COLLIDABLE_FROM_SPHERE(sweeps->mSphere) castCollector.reset(); mPhysicsWorld->linearCast(&Collidable, input, castCollector); if(castCollector.hasHit()) { NbHits++; FillResultStruct(*dest, castCollector, sweeps->mMaxDist); } else { dest->mObject = null; } sweeps++; dest++; } return NbHits; }
hkpBoxShape* FindBoxShape(bool share_shapes, std::vector<hkpBoxShape*>& shapes, const PINT_BOX_CREATE& box_create) { const hkVector4 halfExtents = ToHkVector4(box_create.mExtents); if(share_shapes) { const int size = shapes.size(); for(int i=0;i<size;i++) { hkpBoxShape* CurrentShape = shapes[i]; const hkVector4& CurrentExtents = CurrentShape->getHalfExtents(); if( CurrentExtents(0)==halfExtents(0) && CurrentExtents(1)==halfExtents(1) && CurrentExtents(2)==halfExtents(2)) { CurrentShape->addReference(); return CurrentShape; } } } hkpBoxShape* shape = new hkpBoxShape(halfExtents, 0); ASSERT(shape); shapes.push_back(shape); if(box_create.mRenderer) shape->setUserData(hkUlong(box_create.mRenderer)); return shape; }
bool Havok::SetKinematicPose(PintObjectHandle handle, const Point& pos) { hkpRigidBody* RB = (hkpRigidBody*)handle; hkpKeyFrameUtility::applyHardKeyFrame(ToHkVector4(pos), hkQuaternion::getIdentity(), 60.0f, RB); return true; }
void* Havok::CreatePhantom(const AABB& box) { Point Min, Max; box.GetMin(Min); box.GetMax(Max); hkAabb info; info.m_min = ToHkVector4(Min); info.m_max = ToHkVector4(Max); hkpAabbPhantom* phantom = new hkpAabbPhantom(info); mPhysicsWorld->lock(); mPhysicsWorld->addPhantom(phantom); mPhysicsWorld->unlock(); mPhantoms.Add(udword(phantom)); return phantom; }
udword Havok::BatchBoxSweeps(PintSQThreadContext context, udword nb, PintRaycastHit* dest, const PintBoxSweepData* sweeps) { ASSERT(mPhysicsWorld); // Since we're not too concerned with perfect accuracy, we can set the early out // distance to give the algorithm a chance to exit more quickly: // mPhysicsWorld->getCollisionInput()->m_config->m_iterativeLinearCastEarlyOutDistance = 0.1f; hkpClosestCdPointCollector castCollector; udword NbHits = 0; while(nb--) { hkpLinearCastInput input; input.m_to = ToHkVector4(sweeps->mBox.mCenter + sweeps->mDir*sweeps->mMaxDist); const hkpBoxShape BoxShape(ToHkVector4(sweeps->mBox.mExtents), 0.0f); const hkTransform Pose(ToHkQuaternion(Quat(sweeps->mBox.mRot)), ToHkVector4(sweeps->mBox.mCenter)); hkpCollidable Collidable(&BoxShape, &Pose); castCollector.reset(); mPhysicsWorld->linearCast(&Collidable, input, castCollector); if(castCollector.hasHit()) { NbHits++; FillResultStruct(*dest, castCollector, sweeps->mMaxDist); } else { dest->mObject = null; } sweeps++; dest++; } return NbHits; }
udword Havok::BatchConvexSweeps(PintSQThreadContext context, udword nb, PintRaycastHit* dest, const PintConvexSweepData* sweeps) { ASSERT(mPhysicsWorld); hkpClosestCdPointCollector castCollector; udword NbHits = 0; while(nb--) { hkpConvexVerticesShape* ConvexShape = mConvexObjects[sweeps->mConvexObjectIndex]; const Point& center = sweeps->mTransform.mPos; const Quat& q = sweeps->mTransform.mRot; // const Point Center = (sweeps->mCapsule.mP0 + sweeps->mCapsule.mP1)*0.5f; hkpLinearCastInput input; input.m_to = ToHkVector4(center + sweeps->mDir*sweeps->mMaxDist); // HAVOK_COLLIDABLE_FROM_CAPSULE(sweeps->mCapsule, Center) // const hkpConvexShape CapsuleShape(ToHkVector4(capsule.mP0 - center), ToHkVector4(capsule.mP1 - center), capsule.mRadius); const hkTransform Pose(ToHkQuaternion(q), ToHkVector4(center)); const hkpCollidable Collidable(ConvexShape, &Pose); castCollector.reset(); mPhysicsWorld->linearCast(&Collidable, input, castCollector); if(castCollector.hasHit()) { NbHits++; FillResultStruct(*dest, castCollector, sweeps->mMaxDist); } else { dest->mObject = null; } sweeps++; dest++; } return NbHits; }
void Havok::SetGravity(const Point& gravity) { ASSERT(mPhysicsWorld); mPhysicsWorld->setGravity(ToHkVector4(gravity)); }