示例#1
0
void Projectile::interpolateTick(F32 delta)
{
   Parent::interpolateTick(delta);

   if( mHasExploded )
      return;

   Point3F interpPos = mCurrDeltaBase + mCurrBackDelta * delta;
   Point3F dir = mCurrVelocity;
   if(dir.isZero())
      dir.set(0,0,1);
   else
      dir.normalize();

   MatrixF xform(true);
	xform = MathUtils::createOrientFromDir(dir);
   xform.setPosition(interpPos);
   setRenderTransform(xform);

   // fade out the projectile image
   S32 time = (S32)(mCurrTick - delta);
   if(time > mDataBlock->fadeDelay)
   {
      F32 fade = F32(time - mDataBlock->fadeDelay);
      mFadeValue = 1.0 - (fade / F32(mDataBlock->lifetime));
   }
   else
      mFadeValue = 1.0;

   updateSound();
}
示例#2
0
   virtual void process(NetConnection *con)
   {
	//   Con::printf("WebViewDataURLEvent: %s, %s, %s;", mWebViewData->getName(), mURL, mFrame);
	   if(mObject.isValid())
	   {
		   Con::printf("ShapeBaseTransformEvent::process: %f, %f, %f", mObject->getPosition().x, mObject->getPosition().y, mObject->getPosition().z);
		   Con::printf("ShapeBaseTransformEvent::process2: %f, %f, %f", mTransform.getPosition().x, mTransform.getPosition().y, mTransform.getPosition().z);
		   if(mReletive)
		   {
			   if(mScale.x!=1.0f || mScale.y!=1.0f || mScale.z!=1.0f)
			   {
				  Point3F scale = mObject->getScale() * mScale;
				  mObject->setScale(scale);
			   }
			//   if(!(mTransform.isIdentity()))
			//   {
				//  MatrixF mat = mTransform;
				//  mat.mul(mObject->getTransform());

				//  mObject->setTransform(mat);
				   mObject->setPosition(mObject->getPosition() + mTransform.getPosition());
				   if(mTransform.hasRotation())
				   {
					  MatrixF mat(true);
					  mTransform.getOrientation().setMatrix(&mat);
					  mat.mulL(mObject->getTransform());
                      mObject->setTransform(mat);
				   }
			//   }
		   }
		   else
		   {
			   if(mObject->getScale() != mScale)
                  mObject->setScale(mScale);
			//   if(!mTransform.hasRotation())
			//   {
			//      Point3F pos = mTransform.getPosition();
			//      mTransform.set(mObject->getTransform());
			//	  mTransform.mPosition = pos;
			//   }
			//   mObject->setTransform(mTransform.getMatrix());
			   if(mTransform.hasRotation())
			      mObject->setTransform(mTransform.getMatrix());
			   else
			      mObject->setPosition(mTransform.getPosition());
		   }

		   if(!mVelocity.isZero())
		   {
			//   mObject->setVelocity(mVelocity);
			   RigidShape* rigid = static_cast<RigidShape*>(mObject.getPointer());
			   if(rigid)
                  rigid->reset();
			   mObject->applyImpulse(mObject->getWorldBox().getCenter(), mVelocity);
		   }
	   }
   }
示例#3
0
void PhysicsForce::detach( const Point3F &force )
{
   if ( mBody && !force.isZero() )
   {
      Point3F cMass = mBody->getCMassPosition();      
      F32 mass = mBody->getMass();

      Point3F impulse = ( mass * force ) / TickSec;
      mBody->applyImpulse( cMass, impulse );
   }

   mBody = NULL;
}
示例#4
0
bool Px3World::castRay( const Point3F &startPnt, const Point3F &endPnt, RayInfo *ri, const Point3F &impulse )
{
    
   physx::PxVec3 orig = px3Cast<physx::PxVec3>( startPnt );
   physx::PxVec3 dir = px3Cast<physx::PxVec3>( endPnt - startPnt );
   physx::PxF32 maxDist = dir.magnitude();
   dir.normalize();

   U32 groups = 0xffffffff;
   groups &= ~( PX3_TRIGGER ); // No trigger shapes!

   physx::PxHitFlags outFlags(physx::PxHitFlag::eDISTANCE | physx::PxHitFlag::eIMPACT | physx::PxHitFlag::eNORMAL);
   physx::PxQueryFilterData filterData(physx::PxQueryFlag::eSTATIC|physx::PxQueryFlag::eDYNAMIC);
   filterData.data.word0 = groups;
   physx::PxRaycastBuffer buf;

   if(!mScene->raycast(orig,dir,maxDist,buf,outFlags,filterData))
     return false;
   if(!buf.hasBlock)
    return false;

   const physx::PxRaycastHit hit = buf.block;
   physx::PxRigidActor *actor = hit.actor;
   PhysicsUserData *userData = PhysicsUserData::cast( actor->userData );

   if ( ri )
   {
      ri->object = ( userData != NULL ) ? userData->getObject() : NULL;
      
      if ( ri->object == NULL )

      ri->distance = hit.distance;
      ri->normal = px3Cast<Point3F>( hit.normal );
      ri->point = px3Cast<Point3F>( hit.position );
      ri->t = maxDist / hit.distance;
   }

   if ( impulse.isZero() ||
        !actor->isRigidDynamic() ||
        actor->is<physx::PxRigidDynamic>()->getRigidDynamicFlags() & physx::PxRigidDynamicFlag::eKINEMATIC )
      return true;
  
   physx::PxRigidBody *body = actor->is<physx::PxRigidBody>();
   physx::PxVec3 force = px3Cast<physx::PxVec3>( impulse );
   physx::PxRigidBodyExt::addForceAtPos(*body,force,hit.position,physx::PxForceMode::eIMPULSE);

   return true;
}
示例#5
0
   virtual void write(NetConnection* con, BitStream *bstream)
   {
	   U32 gIndex = bool(mObject) ? con->getGhostIndex(mObject): -1;
	   bstream->writeInt(gIndex, NetConnection::GhostIdBitSize);

	//   if(bstream->writeFlag(!(mTransform.isIdentity())))
       mathWrite(*bstream,mTransform);

	   if(bstream->writeFlag((mScale.x == mScale.y && mScale.z == mScale.x)))
          bstream->write(mScale.x);
	   else
          mathWrite(*bstream,mScale);

	   if(bstream->writeFlag(!mVelocity.isZero()))
		   mathWrite(*bstream,mVelocity);

	   bstream->write(mReletive);
   }
示例#6
0
void Projectile::emitParticles(const Point3F& from, const Point3F& to, const Point3F& vel, const U32 ms)
{
   if ( mHasExploded )
      return;

   Point3F axis = -vel;

   if( axis.isZero() )
      axis.set( 0.0, 0.0, 1.0 );
   else
      axis.normalize();

   bool fromWater = pointInWater(from);
   bool toWater   = pointInWater(to);

   if (!fromWater && !toWater && bool(mParticleEmitter))                                        // not in water
      mParticleEmitter->emitParticles(from, to, axis, vel, ms);
   else if (fromWater && toWater && bool(mParticleWaterEmitter))                                // in water
      mParticleWaterEmitter->emitParticles(from, to, axis, vel, ms);
   else if (!fromWater && toWater && mDataBlock->splash)     // entering water
   {
      // cast the ray to get the surface point of the water
      RayInfo rInfo;
      if (gClientContainer.castRay(from, to, WaterObjectType, &rInfo))
      {
         MatrixF trans = getTransform();
         trans.setPosition(rInfo.point);

         Splash *splash = new Splash();
         splash->onNewDataBlock(mDataBlock->splash, false);
         splash->setTransform(trans);
         splash->setInitialState(trans.getPosition(), Point3F(0.0, 0.0, 1.0));
         if (!splash->registerObject())
         {
            delete splash;
            splash = NULL;
         }

         // create an emitter for the particles out of water and the particles in water
         if (mParticleEmitter)
            mParticleEmitter->emitParticles(from, rInfo.point, axis, vel, ms);

         if (mParticleWaterEmitter)
            mParticleWaterEmitter->emitParticles(rInfo.point, to, axis, vel, ms);
      }
   }
   else if (fromWater && !toWater && mDataBlock->splash)     // leaving water
   {
      // cast the ray in the opposite direction since that point is out of the water, otherwise
      //  we hit water immediately and wont get the appropriate surface point
      RayInfo rInfo;
      if (gClientContainer.castRay(to, from, WaterObjectType, &rInfo))
      {
         MatrixF trans = getTransform();
         trans.setPosition(rInfo.point);

         Splash *splash = new Splash();
         splash->onNewDataBlock(mDataBlock->splash,false);
         splash->setTransform(trans);
         splash->setInitialState(trans.getPosition(), Point3F(0.0, 0.0, 1.0));
         if (!splash->registerObject())
         {
            delete splash;
            splash = NULL;
         }

         // create an emitter for the particles out of water and the particles in water
         if (mParticleEmitter)
            mParticleEmitter->emitParticles(rInfo.point, to, axis, vel, ms);

         if (mParticleWaterEmitter)
            mParticleWaterEmitter->emitParticles(from, rInfo.point, axis, vel, ms);
      }
   }
}