void CPlayerController::Tick(float deltaTime) {
	if (!m_enable && !IsInContact())
		return;

	m_ticksSinceUpdate++;

	btRigidBody *body = m_pObject->GetObject();
	btMassCenterMotionState *motionState = (btMassCenterMotionState *)body->getMotionState();

	// Don't let the player controller travel too far away from the target position.
	btTransform transform;
	motionState->getGraphicTransform(transform);
	btVector3 delta_position = m_targetPosition - transform.getOrigin();

	btScalar qdist = delta_position.length2();
	if (qdist > m_maxDeltaPosition * m_maxDeltaPosition && TryTeleportObject()) {
		return;
	}

	m_linVelocity.setZero();
	CalculateVelocity(deltaTime);

	// Integrate the velocity into our world transform
	btVector3 deltaPos = m_linVelocity * deltaTime;

	if (!deltaPos.fuzzyZero()) {
		btTransform trans;
		motionState->getGraphicTransform(trans);
		trans.setOrigin(trans.getOrigin() + deltaPos);
		motionState->setGraphicTransform(trans);
	}
}
Example #2
0
void CPartSnowFlake::Think( float flTime )
{
	if( m_flBrightness < 130.0 && !m_bTouched )
		m_flBrightness += 4.5;

	Fade( flTime );
	Spin( flTime );

	if( m_flSpiralTime <= gEngfuncs.GetClientTime() )
	{
		m_bSpiral = !m_bSpiral;

		m_flSpiralTime = gEngfuncs.GetClientTime() + UTIL_RandomLong( 2, 4 );
	}
	else
	{
	}

	if( m_bSpiral && !m_bTouched )
	{
		const float flDelta = flTime - g_Environment.GetOldTime();

		const float flSpin = sin( flTime * 5.0 + reinterpret_cast<int>( this ) );
	
		m_vOrigin = m_vOrigin + m_vVelocity * flDelta;

		m_vOrigin.x += ( flSpin * flSpin ) * 0.3;
	}
	else
	{
		CalculateVelocity( flTime );
	}

	CheckCollision( flTime );
}
void ClientSideGame::PredictMovement(int prevFrame, int curFrame)
{
	if(!localClient)
		return;

	float frametime = inputClient.frame[curFrame].msec / 1000.0f;

	localClient->frame[curFrame].key = inputClient.frame[curFrame].key;

	// Process commands
	CalculateVelocity(&localClient->frame[curFrame], frametime);

	// Calculate new predicted origin
	localClient->frame[curFrame].predictedOrigin.x =
		localClient->frame[prevFrame].predictedOrigin.x + localClient->frame[curFrame].vel.x;

	localClient->frame[curFrame].predictedOrigin.y =
		localClient->frame[prevFrame].predictedOrigin.y + localClient->frame[curFrame].vel.y;

	// Copy values to "current" values
	localClient->command.predictedOrigin.x	= localClient->frame[curFrame].predictedOrigin.x;
	localClient->command.predictedOrigin.y	= localClient->frame[curFrame].predictedOrigin.y;
	localClient->command.vel.x				= localClient->frame[curFrame].vel.x;
	localClient->command.vel.y      		= localClient->frame[curFrame].vel.y;
}
Example #4
0
//-----------------------------------------------------------------------------
// Name: empty()
// Desc: 
//-----------------------------------------------------------------------------
void CArmyWar::MoveObjects(void)
{
	if(!localClient)
		return;

	clientData *client = clientList;

	Ogre::Vector3 transVector = Ogre::Vector3::ZERO;

	for( ; client != NULL; client = client->next)
	{
		// Remote players
		if(client != localClient)
		{
			CalculateVelocity(&client->command, frametime);

			client->command.origin.x += client->command.vel.x;
			client->command.origin.y += client->command.vel.y;

            transVector.x = client->command.origin.x;
            transVector.y = client->command.origin.y;

			client->myNode->setPosition(transVector);


		}

		//Local player
		else
		{
			/*
			client->command.origin.x = client->command.predictedOrigin.x;
			client->command.origin.y = client->command.predictedOrigin.y;

			//memcpy(&client->command, &inputClient.command, sizeof(command_t));
			//CalculateVelocity(&inputClient.command, frametime);

			//client->command.origin.x += client->command.vel.x;
			//client->command.origin.y += client->command.vel.y;

            transVector.x = client->command.predictedOrigin.x;
            transVector.y = client->command.predictedOrigin.y;

			//transVector.x = client->command.vel.x;
            //transVector.y = client->command.vel.y;

			//client->myNode->translate(transVector, Ogre::Node::TS_LOCAL);
            client->myNode->setPosition(transVector);


            //LogString("transVector.x %f: ", transVector.x);
			//LogString("transVector.y %f: ", transVector.y);
			//LogString("predictedOrigin.x %f: ", client->command.predictedOrigin.x);
			//LogString("predictedOrigin.y %f: ", client->command.predictedOrigin.y);
*/
		}
		
	}
}
void ServerSideNetworkedGame::MovePlayer(ServerSideNetworkedClient *client)
{
	float clientFrametime;

	float multiplier = 17.0f;

	clientFrametime = client->command.msec / 1000.0f;;

	CalculateVelocity(&client->command, clientFrametime);

	// Move the client based on the commands
	client->command.origin.x += client->command.vel.x;
	client->command.origin.y += client->command.vel.y;


	int f = client->netClient->GetIncomingSequence() & (COMMAND_HISTORY_SIZE-1);
	client->processedFrame = f;
}
Example #6
0
  virtual void AdvanceFrame(MotiveTime delta_time) {
    Defragment();

    // Loop through every motivator one at a time.
    // TODO: change this to a closed-form equation.
    // TODO OPT: reorder data and then optimize with SIMD to process in groups
    // of 4 floating-point or 8 fixed-point values.
    for (auto d = data_.begin(); d < data_.end(); ++d) {
      for (MotiveTime time_remaining = delta_time; time_remaining > 0;) {
        MotiveTime dt = std::min(time_remaining, d->init.max_delta_time());

        d->velocity = CalculateVelocity(dt, *d);
        d->value = CalculateValue(dt, *d);

        time_remaining -= dt;
      }
    }
  }
void CParticleManager::SetProperties(int cont, int i)
{
    CParticleEmitter* l_pE = new CParticleEmitter();
    l_pE->SetMinLife(m_vInfo[cont].fLifeMin);
    l_pE->SetMaxLife(m_vInfo[cont].fLifeMax);
    l_pE->SetTexture(m_vInfo[cont].pTexture);
    l_pE->SetMaxEmitRate(m_vInfo[cont].fEmitRate2);
    l_pE->SetMinEmitRate(m_vInfo[cont].fEmitRate1);
    l_pE->SetGravity(m_vInfo[cont].bGravity);
    l_pE->SetName(m_vInfo[cont].sName);

    //calcular posiciones del emisor
    l_pE->SetPos1(CalculatePos1(cont, i));
    l_pE->SetPos2(CalculatePos2(cont, i));

    //calcular color, dirección, tamaño, velocidad y ángulo de rotación
    CalculateColor(cont);
    CalculateDir(cont);
    CalculateSize(cont);
    CalculateVelocity(cont);
    CalculateAngle(cont);

    //fijar color, dirección, tamaño, velocidad y ángulo de rotación
    l_pE->SetColorTime(m_vTimeColor);
    l_pE->SetColorV(m_vColor);
    l_pE->SetDirTime(m_vTimeDir);
    l_pE->SetDirV(m_vDir);
    l_pE->SetSizeTime(m_vTimeSize);
    l_pE->SetSizeV(m_vSize);
    l_pE->SetVelocityTime(m_vTimeVel);
    l_pE->SetVelocityV(m_vVelocity);
    l_pE->SetAngleTime(m_vTimeAngle);
    l_pE->SetAngleV(m_vAngle);

    //borrar memoria
    m_vInfo[cont].vColor.clear();
    m_vInfo[cont].vDir.clear();
    m_vInfo[cont].vSize.clear();
    m_vInfo[cont].vVelocity.clear();
    m_vInfo[cont].vAngle.clear();

    m_vParticleEmitter.push_back(l_pE);
}
Example #8
0
MachineGun::MachineGun(sf::Vector2f pPosition, float pRotation, sf::Vector2f pVelocity)
{
	Damage = 20;
	Cooldown = 0.1;
	Speed = 500;


	Velocity = pVelocity;
	Position = pPosition;

	Direction = pRotation;
	Sprite.setRotation(pRotation);

	CalculateVelocity();
	
	Sprite.setFillColor(sf::Color::White);
	Sprite.setSize(sf::Vector2f(2, 10));
	Sprite.setOrigin(Sprite.getSize().x / 2, Sprite.getSize().y / 2);
}
//-----------------------------------------------------------------------------
// Name: empty()
// Desc:
//-----------------------------------------------------------------------------
void ClientSideGame::MoveObjects(void)
{
	if(!localClient)
		return;

	clientData *client = clientList;

	Ogre::Vector3 transVector = Ogre::Vector3::ZERO;

	for( ; client != NULL; client = client->next)
	{
		// Remote players
		if(client != localClient)
		{
			CalculateVelocity(&client->command, frametime);

			client->command.origin.x += client->command.vel.x;
			client->command.origin.y += client->command.vel.y;

            transVector.x = client->command.origin.x;
            transVector.y = client->command.origin.y;

			client->mClientSideShape->getSceneNode()->setPosition(transVector);
		}

		//Local player
		else
		{
			client->command.origin.x = client->command.predictedOrigin.x;
			client->command.origin.y = client->command.predictedOrigin.y;

            transVector.x = client->command.predictedOrigin.x;
            transVector.y = client->command.predictedOrigin.y;

            client->mClientSideShape->getSceneNode()->setPosition(transVector);
		}

	}

	}