本文整理汇总了C++中PhysicsWorld::castRay方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsWorld::castRay方法的具体用法?C++ PhysicsWorld::castRay怎么用?C++ PhysicsWorld::castRay使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicsWorld
的用法示例。
在下文中一共展示了PhysicsWorld::castRay方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processTick
void Projectile::processTick(const Move* move)
{
Parent::processTick(move);
mCurrTick++;
if(mSourceObject && mCurrTick > SourceIdTimeoutTicks)
{
mSourceObject = 0;
mSourceObjectId = 0;
}
// See if we can get out of here the easy way ...
if (isServerObject() && mCurrTick >= mDataBlock->lifetime)
{
deleteObject();
return;
}
else if (mHidden == true)
return;
// ... otherwise, we have to do some simulation work.
RayInfo rInfo;
Point3F oldPosition;
Point3F newPosition;
oldPosition = mCurrPosition;
if(mDataBlock->isBallistic)
mCurrVelocity.z -= 9.81 * mDataBlock->gravityMod * (F32(TickMs) / 1000.0f);
newPosition = oldPosition + mCurrVelocity * (F32(TickMs) / 1000.0f);
// disable the source objects collision reponse while we determine
// if the projectile is capable of moving from the old position
// to the new position, otherwise we'll hit ourself
if (mSourceObject.isValid())
mSourceObject->disableCollision();
disableCollision();
// Determine if the projectile is going to hit any object between the previous
// position and the new position. This code is executed both on the server
// and on the client (for prediction purposes). It is possible that the server
// will have registered a collision while the client prediction has not. If this
// happens the client will be corrected in the next packet update.
// Raycast the abstract PhysicsWorld if a PhysicsPlugin exists.
bool hit = false;
if ( gPhysicsPlugin )
{
// TODO: hacked for single player... fix me!
PhysicsWorld *world = gPhysicsPlugin->getWorld( "Server"/*isServerObject() ? "Server" : "Client"*/ );
if ( world )
hit = world->castRay( oldPosition, newPosition, &rInfo, Point3F( newPosition - oldPosition) * mDataBlock->impactForce );
}
else
hit = getContainer()->castRay(oldPosition, newPosition, csmDynamicCollisionMask | csmStaticCollisionMask, &rInfo);
if ( hit )
{
// make sure the client knows to bounce
if(isServerObject() && (rInfo.object->getType() & csmStaticCollisionMask) == 0)
setMaskBits(BounceMask);
// Next order of business: do we explode on this hit?
if(mCurrTick > mDataBlock->armingDelay)
{
MatrixF xform(true);
xform.setColumn(3, rInfo.point);
setTransform(xform);
mCurrPosition = rInfo.point;
mCurrVelocity = Point3F(0, 0, 0);
// Get the object type before the onCollision call, in case
// the object is destroyed.
U32 objectType = rInfo.object->getType();
// re-enable the collision response on the source object since
// we need to process the onCollision and explode calls
if(mSourceObject)
mSourceObject->enableCollision();
// Ok, here is how this works:
// onCollision is called to notify the server scripts that a collision has occurred, then
// a call to explode is made to start the explosion process. The call to explode is made
// twice, once on the server and once on the client.
// The server process is responsible for two things:
// 1) setting the ExplosionMask network bit to guarantee that the client calls explode
// 2) initiate the explosion process on the server scripts
// The client process is responsible for only one thing:
// 1) drawing the appropriate explosion
// It is possible that during the processTick the server may have decided that a hit
// has occurred while the client prediction has decided that a hit has not occurred.
// In this particular scenario the client will have failed to call onCollision and
// explode during the processTick. However, the explode function will be called
// during the next packet update, due to the ExplosionMask network bit being set.
// onCollision will remain uncalled on the client however, therefore no client
// specific code should be placed inside the function!
onCollision(rInfo.point, rInfo.normal, rInfo.object);
//.........这里部分代码省略.........