Пример #1
0
void SingleEvent ()
{
  real vvSum;
  int n;

  NextEvent ();
  if (evIdB < MOL_LIMIT) {
    ProcessCollision ();
    EvalFreePath ();
    ++ collCount;
  } else if (evIdB >= MOL_LIMIT + 100) {
    ProcessCellCrossing ();
    ++ crossCount;
  } else if (evIdB == MOL_LIMIT + 6) {
    UpdateSystem ();
    nextSumTime += intervalSum;
    ScheduleEvent (0, MOL_LIMIT + 6, nextSumTime);
    VZero (vSum);
    vvSum = 0.;
    DO_MOL {
      VVAdd (vSum, mol[n].rv);
      vvSum += VLenSq (mol[n].rv);
    }
    kinEnVal = vvSum * 0.5 / nMol;
    PrintSummary (stdout);
  }
Пример #2
0
void Physics::IterateCollisions() {
	for( int I = 0; I < Iterations; I++ ) { //Repeat this a few times to give more exact results

		//A small 'hack' that keeps the vertices inside the screen. You could of course implement static objects and create
		//four to serve as screen boundaries, but the max/min method is faster
		for( int T = 0; T < VertexCount; T++ ) {
			Vec2& Pos = Vertices[ T ]->Position;
	
			Pos.X = MAX( MIN( Pos.X, (float)GWidth  ), 0.0f );
			Pos.Y = MAX( MIN( Pos.Y, (float)GHeight ), 0.0f );
		}

		UpdateEdges(); //Edge correction step

		for( int I = 0; I < BodyCount; I++ ) {
			Bodies[ I ]->CalculateCenter(); //Recalculate the center
		}

		for( int B1 = 0; B1 < BodyCount; B1++ ) { //Iterate trough all bodies
			for( int B2 = 0; B2 < BodyCount; B2++ ) {
				if( B1 != B2 )
					if( BodiesOverlap( Bodies[ B1 ], Bodies[ B2 ] ) ) //Test the bounding boxes
						if( DetectCollision( Bodies[ B1 ], Bodies[ B2 ] ) ) //If there is a collision, respond to it
							ProcessCollision();
			}
		}
	}
}
Пример #3
0
void SingleEvent ()
{
  real vvSum;
  real sp;
  int n;

  NextEvent ();
  if (evIdB < MOL_LIMIT) {
    ProcessCollision ();
    ++ collCount;
  } else if (evIdB < MOL_LIMIT + NDIM * 2 || evIdB >= MOL_LIMIT + 100) {
    ProcessCellCrossing ();
    ++ crossCount;
  } else if (evIdB == MOL_LIMIT + 6) {
    UpdateSystem ();
    nextSumTime += intervalSum;
    ScheduleEvent (0, MOL_LIMIT + 6, nextSumTime);
    VZero (vSum);
    vvSum = 0.;
    sp = 0.;
    DO_MOL {
      VVAdd (vSum, mol[n].rv);
      vvSum += VLenSq (mol[n].rv);
      sp += VDot (mol[n].r, gravField);
    }
    kinEnVal = vvSum * 0.5 / nMol;
    totEnVal = kinEnVal - sp / nMol;
    PrintSummary (stdout);
  } else if (evIdB == MOL_LIMIT + 7) {
Пример #4
0
void CW::PhysicsEngine::Iterate(void)
{
	for(int i = 0; i < m_Iterations; ++i) 
	{
		// Apply edge constraints
		UpdateEdges();

		for (PhysicsBody* b : m_Bodies)
		{
			b->CalculateCenter();
		}

		for (PhysicsBody* b1 : m_Bodies) 
		{ 
			for(PhysicsBody* b2 : m_Bodies) 
			{
				if(b1 != b2)
				{
					if (BoundingBox::CheckIntersection(&(b1->BoundingBox), &(b2->BoundingBox)))
					{
						if (DetectCollision(b1, b2))
						{
							// Process collision info with CollisionInfo data
							ProcessCollision();
						}
					}
				}
			}
		}
	}
}
Пример #5
0
void GameObject::ProcessCollision( GameObject* obj )
{
	//to be considered
	/*if (((obj->pos3D - pos3D).Length() <= (obj->size + size)) &&
		(obj != ((GameObject*)this)))
	{
		OnCollision(obj);		// perform this object's collision with obj

		// test child collisions with obj
		if (HasChild())
			((GameObject*)GetChild())->ProcessCollision(obj);

		// test sibling collisions with obj
		if (HasParent() && !IsLastChild())
			((GameObject*)GetFollowing())->ProcessCollision(obj);
	}

	// if obj has children, check collisions with these children
	if (obj->HasChild())
		ProcessCollision((GameObject*)(obj->GetChild()));*/

	// if obj has siblings, check collisions with these siblings
	if (obj->HasParent() && !obj->IsLastChild())
		ProcessCollision((GameObject*)(obj->GetFollowing()));
}
Пример #6
0
void CDeflectorShield::HandleEvent(const SGameObjectEvent& event)
{
	if (event.event == eGFE_OnCollision)
	{
		EventPhysCollision* pCollision = (EventPhysCollision*)event.ptr;
		ProcessCollision(*pCollision);
	}
}
Пример #7
0
void Paddle::Update(float deltaTime)
{
  InputManager* pInputManager = InputManager::GetInstance();

  ProcessCollision();

  // Respond to controlls based on which player this paddle is
  if (m_player == 0)
  {
    if (pInputManager->KeyDown(sf::Keyboard::W))
    {
      m_velocity.y = -200;
    }
    else if (pInputManager->KeyDown(sf::Keyboard::S))
    {
      m_velocity.y = 200;
    }
    else
    {
      m_velocity.y = 0;
    }
  }
  else if (m_player == 1)
  {
    if (pInputManager->KeyDown(sf::Keyboard::Up))
    {
      m_velocity.y = -200;
    }
    else if (pInputManager->KeyDown(sf::Keyboard::Down))
    {
      m_velocity.y = 200;
    }
    else
    {
      m_velocity.y = 0;
    }
  }
  else
  {
    if (m_pBall->GetPosition().y + (m_pBall->GetRect().height / 2) > m_position.y + (m_rect.height - 20))
    {
      m_velocity.y = 250;
    }
    else if (m_pBall->GetPosition().y + (m_pBall->GetRect().height / 2) < m_position.y+20)
    {
      m_velocity.y = -250;
    }
    else
    {
      m_velocity.y = 0;
    }
  }

  m_position += m_velocity*deltaTime;

  m_rect = sf::FloatRect(m_position, sf::Vector2f(15, 100));
}
void hhProjectileFreezer::Event_Collision_Bounce( const trace_t* collision, const idVec3 &velocity ) {
	idEntity *entityHit = gameLocal.entities[ collision->c.entityNum ];
	if ( entityHit->IsType(idAI::Type) || entityHit->IsType(idAFEntity_Base::Type) ) {
		Event_Collision_Explode(collision, velocity);
		return;
	}

	ProcessCollision(collision, velocity);
	collided=true;
	idThread::ReturnInt( 1 );
}
Пример #9
0
void TWorld::ProcessShips() {
    QVector<TShip> newShips;
    newShips.reserve(Ships.size());
    for (size_t i = 0; i < (size_t)Ships.size(); ++i) {
        TShip& ship = Ships[i];
        ship.Position.setX(ship.Position.x() + ship.Speed.x());
        if (!ProcessCollision(ship)) {
            newShips.push_back(ship);
        }
    }
    Ships.swap(newShips);
}
void hhProjectileStickyCrawlerGrenade::Event_Collision_Stick( const trace_t* collision, const idVec3 &velocity ) {
	if (proximityDetonateTrigger.GetEntity()) { //rww - don't allow this to be called more than once in a crawler grenade's lifetime
		return;
	}
	ProcessCollision( collision, velocity );

	BindToCollisionObject( collision );
	
	fl.ignoreGravityZones = true;
	SetGravity( idVec3(0.f, 0.f, 0.f) );
	spawnArgs.SetVector("gravity", idVec3(0.f, 0.f, 0.f) );

	BounceSplat( GetOrigin(), -collision->c.normal );

	idDict dict;

	dict.SetVector( "origin", GetOrigin() );
	//dict.SetMatrix( "rotation", GetAxis() );
	dict.Set( "target", name.c_str() );

	dict.SetVector( "mins", spawnArgs.GetVector("detonationMins", "-10 -10 -10") );
	dict.SetVector( "maxs", spawnArgs.GetVector("detonationMaxs", "10 10 10") );
	if (!gameLocal.isClient) {
		proximityDetonateTrigger = gameLocal.SpawnObject( spawnArgs.GetString("def_trigger"), &dict );
		proximityDetonateTrigger->Bind( this, true );
		if ( proximityDetonateTrigger->IsType( hhTrigger::Type ) ) {
			hhTrigger *trigger = static_cast<hhTrigger*>(proximityDetonateTrigger.GetEntity());
			if ( trigger && trigger->IsEncroached() ) {
				proximityDetonateTrigger->PostEventMS( &EV_Activate, 0, this );
			}
		}
	}

	if( modelProxy.IsValid() ) {
		modelProxy->CycleAnim( "idle", ANIMCHANNEL_ALL );
	}

	// CJR:  Added this from the normal crawler collision bounce code
	SIMDProcessor->Memcpy( &collisionInfo, collision, sizeof(trace_t) );
	collisionInfo.fraction = 0.0f;//Sometimes fraction == 1.0f

	idThread::ReturnInt( 1 );
}
Пример #11
0
void GameObject::OnPrepare()
{
	ProcessCollision(FindRoot());
}