本文整理汇总了C++中NxShape类的典型用法代码示例。如果您正苦于以下问题:C++ NxShape类的具体用法?C++ NxShape怎么用?C++ NxShape使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NxShape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
CPhysicUserData* CPhysicsManager::RaycastClosestActor( const Vect3f _vPosRay, const Vect3f& _vDirRay, uint32 _uiImpactMask, SCollisionInfo& _Info, float _uiMaxDistance )
{
//NxUserRaycastReport::ALL_SHAPES
assert(m_pScene != NULL);
NxRay ray;
ray.dir = NxVec3 ( _vDirRay.x, _vDirRay.y, _vDirRay.z );
ray.orig = NxVec3 ( _vPosRay.x, _vPosRay.y, _vPosRay.z );
NxRaycastHit hit;
NxShape* closestShape = NULL;
//closestShape = m_pScene->raycastClosestShape ( ray, NX_ALL_SHAPES, hit, _uiImpactMask, NX_MAX_F32, _uiImpactMask );
//closestShape = m_pScene->raycastClosestShape( ray, NX_ALL_SHAPES, hit, 0xffffffff, NX_MAX_F32, 0xffffffff, NULL, NULL );
NxReal l_Distance = (NxReal) _uiMaxDistance;
// --- Jordi : Provisional. Cal deixar aquesta linia i modificar la col·lisió de càmera
closestShape = m_pScene->raycastClosestShape( ray, NX_ALL_SHAPES, hit, _uiImpactMask, l_Distance );
if (!closestShape)
{
//No hemos tocado a ningún objeto físico de la escena.
return NULL;
}
NxActor* actor = &closestShape->getActor();
CPhysicUserData* impactObject =(CPhysicUserData*)actor->userData;
//Si está petando aquí quiere decir que se ha registrado un objeto físico sin proporcionarle UserData
assert(impactObject);
_Info.m_fDistance = hit.distance;
_Info.m_Normal = Vect3f(hit.worldNormal.x, hit.worldNormal.y, hit.worldNormal.z );
_Info.m_CollisionPoint = Vect3f(hit.worldImpact.x, hit.worldImpact.y, hit.worldImpact.z );
return impactObject;
}
示例2: assert
CPhysicUserData* CPhysicsManager::RaycastClosestActor (const Vect3f posRay, const Vect3f& dirRay, uint32 impactMask, SCollisionInfo& info )
{
//NxUserRaycastReport::ALL_SHAPES
assert(m_pScene != NULL);
NxRay ray;
ray.dir = NxVec3(dirRay.x, dirRay.y, dirRay.z);
ray.orig = NxVec3(posRay.x, posRay.y, posRay.z);
NxRaycastHit hit;
NxShape* closestShape = NULL;
closestShape = m_pScene->raycastClosestShape(ray, NX_ALL_SHAPES, hit, impactMask);
if (!closestShape)
{
//No hemos tocado a ningún objeto físico de la escena.
return NULL;
}
NxActor* actor = &closestShape->getActor();
CPhysicUserData* impactObject =(CPhysicUserData*)actor->userData;
//Si está petando aquí quiere decir que se ha registrado un objeto físico sin proporcionarle UserData
assert(impactObject);
info.m_fDistance = hit.distance;
info.m_Normal = Vect3f(hit.worldNormal.x, hit.worldNormal.y, hit.worldNormal.z );
info.m_CollisionPoint = Vect3f(hit.worldImpact.x, hit.worldImpact.y, hit.worldImpact.z );
return impactObject;
}
示例3: OverlapWithController
bool plPXPhysical::OverlapWithController(const plPXPhysicalControllerCore* controller)
{
NxCapsule cap;
controller->GetWorldSpaceCapsule(cap);
NxShape* shape = fActor->getShapes()[0];
return shape->checkOverlapCapsule(cap);
}
示例4: ReleaseRandomShape
// Release one of the shapes from our compound. At the moment
// we are just releasing the first object in the array.
// As long as the index is below the number of shapes (uiNumShapes)
// it should work, but be careful about releasing an object inside
// other objects (for performance reasons)
void ReleaseRandomShape()
{
// Get the array of pointers to shapes
NxShape*const* ppShapeArray = mainBox->getShapes();
// Find out how many shapes there are left
NxU32 uiNumShapes = mainBox->getNbShapes();
// Don't remove the last shape (or we'll have a shapeless actor)
if (uiNumShapes < 2)
return;
// Record the pose of the shape we intend to release, for later
NxShape* pShapeToRelease = ppShapeArray[0];
NxMat34 mNewBoxPose = pShapeToRelease->getGlobalPose();
// Release the object, and make a note of the new total number of objects
mainBox->releaseShape(*pShapeToRelease);
--iNumberObjects;
// We need to update the mass and intertial tensors. We choose to base it
// on the density of the objects, which are all fBoxDensity
mainBox->updateMassFromShapes(fBoxDensity, 0.0f);
// Create the new box, in the pose we recorded earlier
CreateBoxPiece(mNewBoxPose);
}
示例5: onTrigger
//-----------------------------------------------------------------------------
// onTrigger
//-----------------------------------------------------------------------------
//!!
void CPhysicScene::onTrigger (NxShape &triggerShape, NxShape &otherShape, NxTriggerFlag status)
{
if (!m_pCollisionMng)
return;
TActorInfo *triggerInfo = (TActorInfo*) triggerShape.getActor().userData;
TActorInfo *otherInfo = (TActorInfo*) otherShape.getActor().userData;
m_pCollisionMng->onTrigger(*triggerInfo, *otherInfo, status);
}
示例6: GetCollisionGroup
int CPhysicsActor::GetCollisionGroup()
{
NxShape*const* shapes = m_Actor->getShapes();
NxShape* shape;
shape = shapes[0];
return shape->getGroup();
}
示例7: SpamMsg
plPXPhysical::~plPXPhysical()
{
SpamMsg(plSimulationMgr::Log("Destroying physical %s", GetKeyName().c_str()));
if (fActor)
{
// Grab any mesh we may have (they need to be released manually)
NxConvexMesh* convexMesh = nil;
NxTriangleMesh* triMesh = nil;
NxShape* shape = fActor->getShapes()[0];
if (NxConvexShape* convexShape = shape->isConvexMesh())
convexMesh = &convexShape->getConvexMesh();
else if (NxTriangleMeshShape* trimeshShape = shape->isTriangleMesh())
triMesh = &trimeshShape->getTriangleMesh();
if (!fActor->isDynamic())
plPXPhysicalControllerCore::RebuildCache();
if (fActor->isDynamic() && fActor->readBodyFlag(NX_BF_KINEMATIC))
{
if (fGroup == plSimDefs::kGroupDynamic)
fNumberAnimatedPhysicals--;
else
fNumberAnimatedActivators--;
}
// Release the actor
NxScene* scene = plSimulationMgr::GetInstance()->GetScene(fWorldKey);
scene->releaseActor(*fActor);
fActor = nil;
// Now that the actor is freed, release the mesh
if (convexMesh)
plSimulationMgr::GetInstance()->GetSDK()->releaseConvexMesh(*convexMesh);
if (triMesh)
plSimulationMgr::GetInstance()->GetSDK()->releaseTriangleMesh(*triMesh);
// Release the scene, so it can be cleaned up if no one else is using it
plSimulationMgr::GetInstance()->ReleaseScene(fWorldKey);
}
if (fWorldHull)
delete [] fWorldHull;
if (fSaveTriangles)
delete [] fSaveTriangles;
delete fProxyGen;
// remove sdl modifier
plSceneObject* sceneObj = plSceneObject::ConvertNoRef(fObjectKey->ObjectIsLoaded());
if (sceneObj && fSDLMod)
{
sceneObj->RemoveModifier(fSDLMod);
}
delete fSDLMod;
}
示例8: getWheelShape
pWheelContactData* pWheel2::getContact()
{
NxWheelShape *wShape = getWheelShape();
if (!wShape)
{
return new pWheelContactData();
}
NxWheelContactData wcd;
NxShape* contactShape = wShape->getContact(wcd);
pWheelContactData result;
result.contactEntity = NULL;
if (contactShape)
{
result.contactForce = wcd.contactForce;
result.contactNormal = getFrom(wcd.contactNormal);
result.contactPoint= getFrom(wcd.contactPoint);
result.contactPosition= wcd.contactPosition;
result.lateralDirection= getFrom(wcd.lateralDirection);
result.lateralImpulse= wcd.lateralImpulse;
result.lateralSlip = wcd.lateralSlip;
result.longitudalDirection = getFrom(wcd.longitudalDirection);
result.longitudalImpulse = wcd.longitudalImpulse;
result.longitudalSlip= wcd.longitudalSlip;
pSubMeshInfo *sInfo = static_cast<pSubMeshInfo*>(contactShape->userData);
if (sInfo->entID)
{
CKObject *obj = (CKObject*)GetPMan()->m_Context->GetObject(sInfo->entID);
if (obj)
{
result.contactEntity = (CK3dEntity*)obj;
}else
{
result.contactEntity = NULL;
}
}
result.otherShapeMaterialIndex = contactShape->getMaterial();
NxMaterial* otherMaterial = contactShape->getActor().getScene().getMaterialFromIndex(contactShape->getMaterial());
if (otherMaterial)
{
pFactory::Instance()->copyTo(result.otherMaterial,otherMaterial);
}
}
return &result;
}
示例9: onTrigger
void pTriggerReport::onTrigger(NxShape& triggerShape, NxShape& otherShape, NxTriggerFlag status)
{
NxActor *triggerActor = &triggerShape.getActor();
NxActor *otherActor = &otherShape.getActor();
pRigidBody *triggerBody = NULL;
pRigidBody *otherBody = NULL;
if (triggerActor)
{
triggerBody = static_cast<pRigidBody*>(triggerActor->userData);
triggerBody->getTriggers().Clear();
}
if (otherActor)
{
otherBody = static_cast<pRigidBody*>(otherActor->userData);
otherBody->getTriggers().Clear();
}
pTriggerEntry entry;
entry.shapeA = &triggerShape;
entry.shapeB = &otherShape;
entry.triggerEvent = status;
if (triggerBody)
{
triggerBody->getTriggers().PushBack(entry);
}
/*if(status & NX_TRIGGER_ON_ENTER)
{
}
if(status & NX_TRIGGER_ON_LEAVE)
{
}
if(status & NX_TRIGGER_ON_STAY)
{
// A body entered the trigger area for the first time
}*/
}
示例10: _processParticle
//-----------------------------------------------------------------------
void PhysXActorExtern::_processParticle(
ParticleTechnique* particleTechnique,
Particle* particle,
Ogre::Real timeElapsed,
bool firstParticle)
{
// Only update after a PhysX simulation step
if (mSynchronize)
{
if (particle->particleType != Particle::PT_VISUAL)
return;
if (!particle->physicsActor)
return;
VisualParticle* visualParticle = static_cast<VisualParticle*>(particle);
PhysXActor* physXActor = static_cast<PhysXActor*>(particle->physicsActor);
NxActor* nxActor = physXActor->nxActor;
if (nxActor)
{
// Synchronize both the particle and the pysicsActor with the nxActor
particle->position = PhysXMath::convert(nxActor->getGlobalPosition());
particle->direction = PhysXMath::convert(nxActor->getLinearVelocity());
visualParticle->orientation = PhysXMath::convert(nxActor->getGlobalOrientationQuat());
physXActor->position = particle->position;
physXActor->direction = particle->direction;
physXActor->orientation = visualParticle->orientation;
if (nxActor->getNbShapes())
{
NxShape *shape = nxActor->getShapes()[0]; // Max one.
switch(shape->getType())
{
case NX_SHAPE_BOX:
(static_cast<NxBoxShape*>(shape))->setDimensions(
PhysXMath::convert(0.5 * Ogre::Vector3(
visualParticle->width, visualParticle->height, visualParticle->depth)));
break;
case NX_SHAPE_SPHERE:
(static_cast<NxSphereShape*>(shape))->setRadius(0.5f * visualParticle->width);
break;
case NX_SHAPE_CAPSULE:
{
(static_cast<NxCapsuleShape*>(shape))->setRadius(0.5f * visualParticle->width);
(static_cast<NxCapsuleShape*>(shape))->setHeight(0.5f * visualParticle->height);
}
break;
}
}
}
}
}
示例11: onContactNotify
virtual void onContactNotify(NxContactPair& pair, NxU32 events)
{
NxU32 carIndex = 0;
if (isCar(pair.actors[0]))
carIndex = 0;
else if (isCar(pair.actors[1]))
carIndex = 1;
else
return;
//ignore the 'both are cars' case for now.
// Iterate through contact points
NxContactStreamIterator i(pair.stream);
//user can call getNumPairs() here
while (i.goNextPair())
{
//user can also call getShape() and getNumPatches() here
NxShape * s = i.getShape(carIndex);
while (i.goNextPatch())
{
//user can also call getPatchNormal() and getNumPoints() here
const NxVec3& contactNormal = i.getPatchNormal();
while (i.goNextPoint())
{
//user can also call getPoint() and getSeparation() here
const NxVec3& contactPoint = i.getPoint();
NxVec3 contactNormalForce = pair.sumNormalForce;
NxVec3 contactFrictionForce = pair.sumFrictionForce;
//add forces:
//assuming front wheel drive we need to apply a force at the wheels.
if (s->is(NX_SHAPE_CAPSULE)) //assuming only the wheels of the car are capsules, otherwise we need more checks.
//this branch can't be pulled out of loops because we have to do a full iteration through the stream
{
CarWheelContact cwc;
cwc.car = pair.actors[carIndex];
cwc.wheel = s;
cwc.contactPoint = contactPoint;
cwc.contactNormalForce = contactNormalForce;
cwc.contactFrictionForce = contactFrictionForce;
wheelContactPoints.pushBack(cwc);
//#error too bad this is illegal (reentry) and also technically busted because the accumulators get zeroed after this returns.
//pair.actors[carIndex]->addForceAtPos(NxVec3(100,0,0),contactPoint);
}
}
}
}
}
示例12: ExcludeRegionHack
void plPXPhysical::ExcludeRegionHack(bool cleared)
{
NxShape* shape = fActor->getShapes()[0];
shape->setFlag(NX_TRIGGER_ON_ENTER, !cleared);
shape->setFlag(NX_TRIGGER_ON_LEAVE, !cleared);
fGroup = cleared ? plSimDefs::kGroupExcludeRegion : plSimDefs::kGroupDetector;
shape->setGroup(fGroup);
/*if switching a static need to inform the controller that it needs to rebuild
the collision cache otherwise will still think that the detector is still static or that
the static is still a detector*/
plPXPhysicalControllerCore::RebuildCache();
}
示例13: PBSetTriggerMask
//************************************
// Method: PBSetTriggerMask
// FullName: PBSetTriggerMask
// Access: public
// Returns: int
// Qualifier:
// Parameter: const CKBehaviorContext& behcontext
//************************************
int PBSetTriggerMask(const CKBehaviorContext& behcontext)
{
CKBehavior* beh = behcontext.Behavior;
CKContext* ctx = behcontext.Context;
PhysicManager *pm = GetPMan();
pFactory *pf = pFactory::Instance();
using namespace vtTools::BehaviorTools;
if( beh->IsInputActive(0) )
{
beh->ActivateInput(0,FALSE);
//////////////////////////////////////////////////////////////////////////
//the object :
CK3dEntity *target = (CK3dEntity *) beh->GetTarget();
if( !target ) return CKBR_OWNERERROR;
//////////////////////////////////////////////////////////////////////////
// the world :
pWorld *world = GetPMan()->getWorldByShapeReference(target);
if (!world)
{
beh->ActivateOutput(0);
return 0;
}
if (world)
{
NxShape *shape = world->getShapeByEntityID(target->GetID());
if (shape)
{
int onEnter = GetInputParameterValue<int>(beh,bbI_OnEnter);
int onStay = GetInputParameterValue<int>(beh,bbI_OnStay);
int onLeave = GetInputParameterValue<int>(beh,bbI_OnLeave);
shape->setFlag(NX_TRIGGER_ON_ENTER,onEnter);
shape->setFlag(NX_TRIGGER_ON_STAY,onStay);
shape->setFlag(NX_TRIGGER_ON_LEAVE,onLeave);
}
}
beh->ActivateOutput(0);
}
return 0;
}
示例14: castRayGetClosest
//NX_STATIC_SHAPES,NX_DYNAMIC_SHAPES,NX_ALL_SHAPES
GameObject* PhysicsManager::castRayGetClosest(Vector3 startPosition, Vector3 direction, bool omitTriggers,bool omitActors, bool omitStatic, bool omitDynamic, bool omitCharacters)
{
NxRay worldRay;
worldRay.orig = NxTools::convert(startPosition);
worldRay.dir = NxTools::convert(direction);
NxShapesType flags = NX_ALL_SHAPES; // NxShapeType::;
NxRaycastHit hit;
NxShape* shape = mScene->raycastClosestShape(worldRay, flags, hit);
if(shape) {
NxActor& actor = shape->getActor();
if(!omitTriggers) {
CPhysicsTrigger* trigger = static_cast<CPhysicsTrigger*>(actor.userData);
if(trigger)
return trigger->getOwnerObject();
}
if(!omitActors) {
CPhysicsActor* physicsActor = static_cast<CPhysicsActor*>(actor.userData);
if(physicsActor) {
//if(!omitDynamic) {
// if(physicsActor->isDynamic()) {
return physicsActor->getOwnerObject();
// }
//} else {
//}
}
}
if(!omitCharacters) {
CCharacterController* character = static_cast<CCharacterController*>(actor.userData);
if(character)
return character->getOwnerObject();
}
}
//if(shape)
// return hit.distance;
//else
// return 0;
return NULL;
}
示例15: onTrigger
void myTrigger::onTrigger(NxShape& triggerShape, NxShape& otherShape, NxTriggerFlag status){
if ( ! triggerShape.getActor().userData && ! otherShape.getActor().userData )
{
return;
}
if (status & NX_TRIGGER_ON_ENTER)
{
// A body just entered the trigger area
NxActor* triggerActor = &triggerShape.getActor();
String name = triggerActor->getName();
int thisTarget = StringConverter::parseInt(name);
creditTarget(thisTarget);
}
}