Exemplo n.º 1
0
bool Animation::NextSheet()
{
    if ((curr_sheetnum + 1) != sheets.size())
    {
        curr_sheetnum++;
        RefreshSheet();
        CheckCollisions();
    }
    else
    {
        if (curr_beat >= sheets.at(curr_sheetnum).GetNumBeats())
        {
            if (sheets.at(curr_sheetnum).GetNumBeats() == 0)
            {
                curr_beat = 0;
            }
            else
            {
                curr_beat = sheets.at(curr_sheetnum).GetNumBeats()-1;
            }
        }
        return false;
    }
    return true;
}
void GameplayState::Update(StateEngine* state, double dt)
{
	characters[DAVE]->Update(dt);
	characters[MANDY]->Update(dt);
	if (!m_isThrowing)
		characters[NIGEL]->Update(dt);

	ScrollCranes(dt);

	CheckInterations(state);

	for (int i = 0; i <3; i++)
	{
		CheckObjects(i);
		CheckCollisions(i);	
	}

	m_Cam->SetPosition(
		CIwSVec2(static_cast<int16>(-characters[m_CharacterIndex]->GetPosition().x + (screenWidth /2)),
		static_cast<int16>(-characters[m_CharacterIndex]->GetPosition().y + (screenHeight - characters[m_CharacterIndex]->GetHeight() - 32))));

	if (s3eKeyboardGetState(s3eKeySpace) == 4)
		m_SpacePressed = false;

	if (s3ePointerGetState(S3E_POINTER_BUTTON_LEFTMOUSE) == 4)
	{
		m_MouseClicked = false;
		m_ClickLocation = CIwFVec2(0,0);
		m_TerminalSound->ResetCounter();
	}
}
Exemplo n.º 3
0
vec3 Player::MoveAbsolute(vec3 direction, const float speed, bool shouldChangeForward)
{
	if (shouldChangeForward)
	{
		m_forward = normalize(direction);
	}

	m_targetForward = m_forward;
	m_targetForward.y = 0.0f;
	m_targetForward = normalize(m_targetForward);

	vec3 totalAmountMoved;

	vec3 movement = direction;
	vec3 movementAmount = direction*speed;
	vec3 pNormal;
	int numberDivision = 1;
	while (length(movementAmount) >= 1.0f)
	{
		numberDivision++;
		movementAmount = direction*(speed / numberDivision);
	}
	for (int i = 0; i < numberDivision; i++)
	{
		float speedToUse = (speed / numberDivision) + ((speed / numberDivision) * i);
		vec3 posToCheck = GetCenter() + movement*speedToUse;

		if (m_bDoStepUpAnimation == false)
		{
			bool stepUp = false;
			if (CheckCollisions(posToCheck, m_previousPosition, &pNormal, &movement, &stepUp))
			{
				if (stepUp)
				{
					if (m_bDoStepUpAnimation == false)
					{
						m_bDoStepUpAnimation = true;

						m_stepUpAnimationYAmount = 0.0f;
						m_stepUpAnimationPrevious = 0.0f;
						m_stepUpAnimationYOffset = 0.0f;
						Interpolator::GetInstance()->AddFloatInterpolation(&m_stepUpAnimationYAmount, 0.0f, (Chunk::BLOCK_RENDER_SIZE*2.2f), 0.1f, 0.0f, NULL, _StepUpAnimationFinished, this);
						Interpolator::GetInstance()->AddFloatInterpolation(&m_stepUpAnimationYOffset, (Chunk::BLOCK_RENDER_SIZE*2.2f), 0.0f, 0.2f, -100.0f);
					}
				}
			}
		}

		m_position += (movement * speedToUse);

		totalAmountMoved += (movement * speedToUse);
	}

	// Change to run animation
	m_pVoxelCharacter->BlendIntoAnimation(AnimationSections_FullBody, true, AnimationSections_FullBody, "Run", 0.01f);

	m_bIsIdle = false;

	return totalAmountMoved;
}
/**
 * @brief CollisionSystem::Update checks for collisions between entities that have moved and all other entities
 * @param dt frame time
 */
void CollisionSystem::Update(sf::Time dt)
{
    PositionComponent* p1 = nullptr;
    sf::Vector2f norm;
    std::list<unsigned int> movedEntities = _MovedEntities;
    _MovedEntities.clear();
    std::list<unsigned int>::iterator mit;

    FillBins();

    for(mit = movedEntities.begin(); mit != movedEntities.end(); mit++)
    {
        p1 = this->GetEntity(*mit)->GetComponent<PositionComponent>("Position");

        if(CheckCollisions(*mit, norm))
        {
            MoveEntityMessage msg;
            msg.ID = *mit;
            msg.newPosition.x = p1->GetPosition().x - norm.x;
            msg.newPosition.y = p1->GetPosition().y - norm.y;
            Emit<MoveEntityMessage>(msg);
        }
    }

    ClearBins();
}
Exemplo n.º 5
0
void CStuff::Update()
{
	m_pPlayer->Update();
	camera->x = m_pPlayer->GetX() - ((float)camera->w / 2);
	camera->y = m_pPlayer->GetY() - ((float)camera->h / 2);
	

	if (camera->x < 0)
		camera->x = 0;
	if (camera->y < 0)
		camera->y = 0;

	if (camera->x > level_width - camera->w)
		camera->x = level_width - camera->w;
	if (camera->y > level_height - camera->h)
		camera->y = level_height - camera->h;

	g_pDebugscreen->Set("cameraX:", camera->x);
	g_pDebugscreen->Set("cameraY:", camera->y);

	m_pPlayer->Render(camera->x, camera->y);
	m_pPlayer->LifeRender();

	list<CExplosion>::iterator ItEx = m_ExplosionList.begin();
	while (ItEx != m_ExplosionList.end())
		if (ItEx->IsAlive())
			ItEx++;
		else ItEx = m_ExplosionList.erase(ItEx);

	CommandSpawns();
	CheckCollisions();
	RenderMonsters();

}
Exemplo n.º 6
0
bool Animation::PrevBeat()
{
    unsigned i;

    if (curr_beat == 0)
    {
        if (curr_sheetnum == 0) return false;
        curr_sheetnum--;
        for (i = 0; i < numpts; i++)
        {
            curr_cmds[i] = sheets.at(curr_sheetnum).commands[i].end() - 1;
            EndCmd(i);
        }
        curr_beat = sheets.at(curr_sheetnum).GetNumBeats();
    }
    for (i = 0; i < numpts; i++)
    {
        if (!(*curr_cmds.at(i))->PrevBeat(pts[i]))
        {
// Advance to prev command, skipping zero beat commands
            if (curr_cmds[i] != sheets.at(curr_sheetnum).commands[i].begin())
            {
                --curr_cmds[i];
                EndCmd(i);
// Set to next-to-last beat of this command
// Should always return true
                (*curr_cmds[i])->PrevBeat(pts[i]);
            }
        }
    }
    if (curr_beat > 0)
        curr_beat--;
    CheckCollisions();
    return true;
}
Exemplo n.º 7
0
void Brick::Update(Ball* ball)
{
	if (!bDestroyed)
	{
		CheckCollisions(ball);
	}
}
Exemplo n.º 8
0
void MyBOManager::Update(void)
{
	for (uint nObject = 0; nObject < m_nObjectCount; nObject++)
	{
		m_llCollidingIndices[nObject].clear();
	}
	CheckCollisions();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Update():		
//
// Returns:			Void
//
// Mod. Name:		Ethan Pendergraft
// Mod. Date:		6/2/2012
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CComponent_IntakePipeCollision::Update( float fDT )
{
	// We only need to check collisions if
	// the pipe is corkable
	

	if( m_pParent )
	{		
		// Set the collision object 
		// to the parent's collision object 
		if( !m_pCollisionObject )
		{
			m_pCollisionObject = (AABB*)m_pParent->GetCollidableObject();
		}
	}

	// only move the plug
	// if we aren't plugged yet
	if( m_bIsGettingCorked )
	{
		MoveCork( fDT );
	}

	vec3f NewCenter = m_pParent->GetWorldMat()->axis_pos;
	m_abTarget.SetWorldPoint (NewCenter);
	((AABB*)m_pParent->GetCollidableObject())->SetWorldPoint (NewCenter);

	CheckCollisions( fDT );
	
	// don't check for the cork
	// if you can't cork this pipe
	if( !m_bCorkable )
	{
		return;
	}

	CheckCorkableAABB( fDT );

	//D3DXMATRIX mat;

	//D3DXMatrixIdentity (&mat);

	//mat._41 = m_abTarget.GetMax2DTransformed().x;
	//mat._42 = m_abTarget.GetMax2DTransformed().y;
	//mat._43 = -300.0f;

	//DebugShapes::RenderSphere (mat);

	//mat._41 = m_abTarget.GetMin2DTransformed().x;
	//mat._42 = m_abTarget.GetMin2DTransformed().y;
	//mat._43 = -300.0f;

	//DebugShapes::RenderSphere (mat);

	// We only need to check collisions if
	// the pipe is corkable
}
Exemplo n.º 10
0
  bool CKinematics2DEngine::CollisionsDetection( const CKinematics2DCollisionRectangle* pc_rectangle ) {
    if(!m_bDetectCollisions)
      return false;
    
    bool enabled = pc_rectangle->IsEnabled();
    
    for( TKinematics2DEntityMap::const_iterator it = m_tPhysicsEntities.begin(); it != m_tPhysicsEntities.end(); ++it ) {
      /* don't ckeck if it's the same entity */
      if( pc_rectangle == it->second ) continue;

      bool it_enabled = it->second->IsEnabled();
      TKinematics2DCollisionType it_type = it->second->GetCollisionType();
      
      // skip collision detection if both entities are disabled or if
      // one of them has no collision model
      if( (!it_enabled && !enabled) ||
	  (it_type == KINEMATICS2D_COLLISION_NONE) ) {
	continue;
      }
      
      // check intersection between bounding boxes
      if( !pc_rectangle->GetEmbodiedEntity().GetBoundingBox().Intersects( it->second->GetEmbodiedEntity().GetBoundingBox() ) ) {
	continue;
      }
      
      bool collision_detected = false;
      if( it_type == KINEMATICS2D_COLLISION_CIRCLE ) {
	collision_detected = CheckCollisions(dynamic_cast<CKinematics2DCollisionCircle*>(it->second), pc_rectangle);
      }
      else if( it_type == KINEMATICS2D_COLLISION_RECTANGLE ) {
	collision_detected = CheckCollisions(pc_rectangle, dynamic_cast<CKinematics2DCollisionRectangle*>(it->second));
      }
      else  {
	continue;
      }
      
      /* reset to previous positions if collision is detected */
      if( collision_detected ) {
	return true;
      }
    }
    
    return false;
  }
Exemplo n.º 11
0
bool Animation::PrevSheet()
{
    if (curr_beat == 0)
    {
        if (curr_sheetnum > 0)
        {
            curr_sheetnum--;
        }
    }
    RefreshSheet();
    CheckCollisions();
    return true;
}
Exemplo n.º 12
0
	/**
	*Advances our block to the next rotation state
	*/
	void BlockEntity::AdvanceState()
	{
		mState = (mState + 1) % STATES;
		lastDirection = "Rotate";
		if (!CheckCollisions().empty())
		{
			GetSector()->As<SectorTetromino>()->mUndoRotate = true;
		}
		else
		{
			GetSector()->As<SectorTetromino>()->mPlayRotate = true;
		}
	}
Exemplo n.º 13
0
void Player::Update(const Camera& camera, float dt)
{
	Applyforces(dt);
	Move(dt);
	mSelf->Update(camera, dt);
	
	//triming the AABB
	mSelf->mMeshBox.Extents.z = 5.0f; // Makes the Dude a bit wider then 0 to prevent Z fighting ..
	mSelf->mMeshBox.Extents.x -= 23.0f; 
	//mSelf->mMeshBox.Extents.y -= 1.0f; 
	
	CheckCollisions();

	if (mItemDescription){ mItemDescription->Update(camera, dt); if (mItemDescription->mDead){ mItemDescription = nullptr; } }
}
/**
 * @brief CollisionSystem::ValidateEntity validates an entity to update
 * @param ID the entity to validate
 */
bool CollisionSystem::ValidateEntity(unsigned int ID)
{
    Entity* e = this->GetEntity(ID);

    sf::Vector2f norm;
    if(CheckCollisions(ID, norm))
    {
        DestroyEntityMessage dmsg;
        dmsg.ID = ID;
        Emit<DestroyEntityMessage>(dmsg);
        return false;
    }

    return e->HasComponent("Collider") && e->HasComponent("Position");
}
Exemplo n.º 15
0
// Movement
void Player::MoveAbsolute(vec3 direction, const float speed, bool shouldChangeForward)
{
	if (dot(direction, m_movementVelocity) > -0.9f)
	{
		direction = normalize(direction + (m_movementVelocity*0.4f));
	}

	if (shouldChangeForward)
	{
		m_forward = (length(m_movementVelocity) > 0.01f) ? m_movementVelocity : direction;
		m_forward = normalize(m_forward);
	}

	m_targetForward = m_forward;
	m_targetForward.y = 0.0f;
	m_targetForward = normalize(m_targetForward);

	vec3 movement = direction;
	vec3 movementAmount = direction*speed;
	vec3 pNormal;
	int numberDivision = 1;
	while (length(movementAmount) >= 1.0f)
	{
		numberDivision++;
		movementAmount = direction*(speed / numberDivision);
	}
	for (int i = 0; i < numberDivision; i++)
	{
		float speedToUse = (speed / numberDivision) + ((speed / numberDivision) * i);
		vec3 posToCheck = GetCenter() + movement*speedToUse;
		if (CheckCollisions(posToCheck, m_previousPosition, &pNormal, &movement))
		{
		}

		m_position += (movement * speedToUse)*0.95f;
	}

	m_movementVelocity += (direction * speed) * 0.85f;

	// Change to run animation
	if (m_pVoxelCharacter->HasAnimationFinished(AnimationSections_FullBody))
	{
		m_pVoxelCharacter->BlendIntoAnimation(AnimationSections_FullBody, false, AnimationSections_FullBody, "Run", 0.01f);
	}

	m_bIsIdle = false;
}
Exemplo n.º 16
0
void MyBOManager::CheckCollisions(MyOctant &octant)
{
	if (useOctree)
	{
		uint numChildren = octant.GetNumChildren();
		if (numChildren > 0)
		{
			for (int i = 0; i < numChildren; i++)
				CheckCollisions(octant.m_pChildren[i]);
		}
		else
		{
			std::vector<int> octantObjList = octant.GetObjIndexList();
			if (octantObjList.size() < 2)
				return;
			for (uint i = 0; i < octantObjList.size() - 1; i++)
			{
				for (uint c = i + 1; c < octantObjList.size(); c++)
				{
					int obj1 = octantObjList[i];
					int obj2 = octantObjList[c];
					if (m_lObject[obj1]->IsColliding(m_lObject[obj2]))
					{

						m_llCollidingIndices[obj1].push_back(obj2);
						m_llCollidingIndices[obj2].push_back(obj1);
					}
				}
			}
		}
	}
	else {
		for (uint i = 0; i < m_nObjectCount - 1; i++)
		{
			for (uint c = i + 1; c < m_nObjectCount; c++)
			{
				if (m_lObject[i]->IsColliding(m_lObject[c]))
				{

					m_llCollidingIndices[i].push_back(c);
					m_llCollidingIndices[c].push_back(i);
				}
			}
		}
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function Name: Update()
// Purpose: Update all data members
// Original Author: Rueben Massey
// Creation Date: 6/4/2012
// Last Modification By: 
// Last Modification Date: 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CComponent_OutletCollision::Update( float fDT )
{
	if( m_pParent )
	{
		// Set the collision object 
		// to the parent's collision object 
		if( !m_pCollisionObject )
		{
			m_pCollisionObject = (AABB*)m_pParent->GetCollidableObject();
		}
	}
	// only move the plug
	// if we aren't plugged yet
	if( m_bIsGettingPlugged )
	{
		MovePlug( fDT );
	}

	vec3f NewCenter = m_pParent->GetWorldMat()->axis_pos;
	m_OutletAABB.SetWorldPoint (NewCenter);
	((AABB*)m_pParent->GetCollidableObject())->SetWorldPoint (NewCenter);

	/*D3DXMATRIX mat;
	mat._41 = m_OutletAABB.GetMax2DTransformed().x;
	mat._42 = m_OutletAABB.GetMax2DTransformed().y;
	mat._43 = -600.0f;
	DebugShapes::RenderSphere (mat);

	mat._41 = m_OutletAABB.GetMin2DTransformed().x;
	mat._42 = m_OutletAABB.GetMin2DTransformed().y;
	mat._43 = -600.0f;
	DebugShapes::RenderSphere (mat);

	mat._41 = m_OutletAABB.GetMin2DTransformed().x;
	mat._42 = m_OutletAABB.GetMax2DTransformed().y;
	mat._43 = -600.0f;
	DebugShapes::RenderSphere (mat);

	mat._41 = m_OutletAABB.GetMax2DTransformed().x;
	mat._42 = m_OutletAABB.GetMin2DTransformed().y;
	mat._43 = -600.0f;
	DebugShapes::RenderSphere (mat);*/

	CheckPlugCollisions( fDT );
	CheckCollisions( fDT );	
}
Exemplo n.º 18
0
void Agent::Update(float a_deltaTime)
{
	// Update the velocity with the current acceleration
	m_movementInfo.m_velocityX += m_movementInfo.m_accelerationX;
	m_movementInfo.m_velocityY += m_movementInfo.m_accelerationY;

	// constrain the velocity
	if (m_movementInfo.m_velocityX > m_movementInfo.m_maxSpeed)
	{
		m_movementInfo.m_velocityX = m_movementInfo.m_maxSpeed;
	}
	else if (m_movementInfo.m_velocityX < -m_movementInfo.m_maxSpeed)
	{
		m_movementInfo.m_velocityX = -m_movementInfo.m_maxSpeed;
	}
	if (m_movementInfo.m_velocityY > m_movementInfo.m_maxSpeed)
	{
		m_movementInfo.m_velocityY = m_movementInfo.m_maxSpeed;
	}
	else if (m_movementInfo.m_velocityY < -m_movementInfo.m_maxSpeed)
	{
		m_movementInfo.m_velocityY = -m_movementInfo.m_maxSpeed;
	}
	
	// set rotation
	m_movementInfo.m_rotation = atan2(m_movementInfo.m_velocityY, m_movementInfo.m_velocityX) + (float)M_PI / 2.0f;

	// reset the acceleration for the next frame
	m_movementInfo.m_accelerationX = 0.0f;
	m_movementInfo.m_accelerationY = 0.0f;

	// add the velocity to the position
	m_movementInfo.m_positionX += m_movementInfo.m_velocityX;
	m_movementInfo.m_positionY += m_movementInfo.m_velocityY;

	CheckCollisions();
	switch (GetColour())
	{
	case Colour::Green: Patrol(); break;
	case Colour::Blue: Health(); break;
	case Colour::Red: Attack(); break;
	case Colour::Orange: Search(); break;
	}
	
}
Exemplo n.º 19
0
void Player::UpdatePhysics(float dt)
{
	// Integrate velocity
	vec3 acceleration = m_force + (m_gravityDirection * 9.81f)*4.0f;
	m_velocity += acceleration * dt;

	// Check collision
	{
		vec3 velocityToUse = m_velocity + m_movementVelocity;
		vec3 velAmount = velocityToUse*dt;
		vec3 pNormal;
		int numberDivision = 1;
		while (length(velAmount) >= 1.0f)
		{
			numberDivision++;
			velAmount = velocityToUse*(dt / numberDivision);
		}
		for (int i = 0; i < numberDivision; i++)
		{
			float dtToUse = (dt / numberDivision) + ((dt / numberDivision) * i);
			vec3 posToCheck = GetCenter() + velocityToUse*dtToUse;
			if (CheckCollisions(posToCheck, m_previousPosition, &pNormal, &velAmount))
			{
				// Reset velocity, we don't have any bounce
				m_velocity = vec3(0.0f, 0.0f, 0.0f);
				velocityToUse = vec3(0.0f, 0.0f, 0.0f);

				if (m_bCanJump == false)
				{
					m_bCanJump = true;
				}
			}
		}

		// Integrate position
		m_position += velocityToUse * dt;

		m_movementVelocity -= (m_movementVelocity * (7.5f * dt));
	}

	// Store previous position
	m_previousPosition = m_position;
}
Exemplo n.º 20
0
void MyBOManager::Update(void)
{
	for (uint nObject = 0; nObject < m_nObjectCount; nObject++)
	{
		m_llCollidingIndices[nObject].clear();
	}
	static MyOctant head = MyOctant(true);

	if (buildOctree)
	{
		head.CheckForObjs();
		buildOctree = false;
	}

	if (octreeVisible)
		head.Display();

	CheckCollisions(head);
}
Exemplo n.º 21
0
    void PhysicsWorld::ExecFrame()
    {
        LockThread();
    //
    //  [disabled] Lock timestep to improve collision prediction
        //m_QueuedTime += (GFloat)rsk::gClock->GetFrameTimeSeconds();
    //
    //  [enabled] Try to normalize the timestep to improve collision prediction
        m_FrameTime += (GFloat)rsk::gClock->GetFrameTimeSeconds();
        m_FrameTime *= 0.5f;
//        if( m_QueuedTime >= m_FrameTime )
        {
            CheckCollisions();
            HandleCollisions();
            ApplyGravity();

            RSKMAP_ITERATE( m_Entities )
                iter->second->ExecFrame( m_FrameTime );

//            m_QueuedTime = 0.f;
        }
    }
Exemplo n.º 22
0
bool Animation::NextBeat()
{
    unsigned i;

    curr_beat++;
    if (curr_beat >= sheets.at(curr_sheetnum).GetNumBeats())
    {
        return NextSheet();
    }
    for (i = 0; i < numpts; i++)
    {
        if (!(*curr_cmds.at(i))->NextBeat(pts[i]))
        {
// Advance to next command, skipping zero beat commands
            if ((curr_cmds[i] + 1) != sheets.at(curr_sheetnum).commands.at(i).end())
            {
                ++curr_cmds[i];
                BeginCmd(i);
            }
        }
    }
    CheckCollisions();
    return true;
}
Exemplo n.º 23
0
void Combat::PlayerAttack()
{
	CheckCollisions(PLAYER);

	list<Enemy*>::iterator It;
	eList = g_pGame->getEnemyList();
	
	for(It = eList.begin(); It != eList.end(); ++It)
	{
		if((*It)->getHit())
		{
			float hp = (*It)->getCurrentHP();
			hp-=g_pPlayer->getDMG();
			(*It)->setCurrentHP(hp);
			(*It)->setHit(false);

			cout << "Enemy-HP: " << (*It)->getCurrentHP() << endl;
		}
	}

	// return the list to original enemy-list
	//
	g_pGame->setEnemyList(eList);
}
Exemplo n.º 24
0
void Animation::GotoSheet(unsigned i)
{
    curr_sheetnum = i;
    RefreshSheet();
    CheckCollisions();
}
Exemplo n.º 25
0
void PointSetWithCollisions::AfterStep(double deltaTime)
{
	CheckCollisions(deltaTime);
}
Exemplo n.º 26
0
void Ball::Update(sf::Time& deltaTime)
{
	position = gameBall.getPosition();
	gameBall.move(velocity.x * deltaTime.asSeconds(), velocity.y * deltaTime.asSeconds());
	CheckCollisions();
}
Exemplo n.º 27
0
/*
    Returns true if node state is within bounds and obstacle-free
*/
bool Pendulum::Feasible(Node* n) {
    return (CheckBounds(n) && CheckCollisions(n));  
}
Exemplo n.º 28
0
  void CKinematics2DEngine::CollisionsDetection( void ) {
    if(!m_bDetectCollisions)
      return;

    for( TKinematics2DEntityMap::const_iterator it1 = m_tPhysicsEntities.begin(); it1 != m_tPhysicsEntities.end(); ++it1 ) {
      bool it1_enabled = it1->second->IsEnabled();
      TKinematics2DCollisionType it1_type = it1->second->GetCollisionType();

      TKinematics2DEntityMap::const_iterator it2 = it1;
      for( ++it2; it2 != m_tPhysicsEntities.end(); ++it2 ) {
	bool it2_enabled = it2->second->IsEnabled();
	TKinematics2DCollisionType it2_type = it2->second->GetCollisionType();

	// skip collision detection if both entity are disabled or if
	// one of them has no collision model
	if( (!it1_enabled && !it2_enabled) ||
	    (it1_type == KINEMATICS2D_COLLISION_NONE) || 
	    (it2_type == KINEMATICS2D_COLLISION_NONE) ) {
	  continue;
	}
	
	// check intersection between bounding boxes
	if( !it1->second->GetEmbodiedEntity().GetBoundingBox().Intersects( it2->second->GetEmbodiedEntity().GetBoundingBox() ) ) {
	  continue;
	}

	bool collision_detected = false;
	if( (it1_type == KINEMATICS2D_COLLISION_CIRCLE) &&
	    (it2_type == KINEMATICS2D_COLLISION_CIRCLE) ) {
	  collision_detected = CheckCollisions(dynamic_cast<CKinematics2DCollisionCircle*>(it1->second), 
					       dynamic_cast<CKinematics2DCollisionCircle*>(it2->second));
	}
	else if( (it1_type == KINEMATICS2D_COLLISION_RECTANGLE) &&
		 (it2_type == KINEMATICS2D_COLLISION_CIRCLE) ) {
	  collision_detected = CheckCollisions(dynamic_cast<CKinematics2DCollisionCircle*>(it2->second),
					       dynamic_cast<CKinematics2DCollisionRectangle*>(it1->second));
	}
	else if( (it1_type == KINEMATICS2D_COLLISION_CIRCLE) &&
		 (it2_type == KINEMATICS2D_COLLISION_RECTANGLE) ) {
	  collision_detected = CheckCollisions(dynamic_cast<CKinematics2DCollisionCircle*>(it1->second),
					       dynamic_cast<CKinematics2DCollisionRectangle*>(it2->second));
	}
	else if( (it1_type == KINEMATICS2D_COLLISION_RECTANGLE) &&
		 (it2_type == KINEMATICS2D_COLLISION_RECTANGLE) ) {
	  collision_detected = CheckCollisions(dynamic_cast<CKinematics2DCollisionRectangle*>(it1->second),
					       dynamic_cast<CKinematics2DCollisionRectangle*>(it2->second));
	}
	else {
	  continue;
	}
	
	/* reset to previous positions if collision is detected */
	if( collision_detected ) {
	  it1->second->RevertPositionAndOrientation();
	  it1->second->GetEmbodiedEntity().SetCollisionDetected();
	  
	  it2->second->RevertPositionAndOrientation();
	  it2->second->GetEmbodiedEntity().SetCollisionDetected();
 	}
      }
    }
  }
Exemplo n.º 29
0
void Player::UpdatePhysics(float dt)
{
	m_positionMovementAmount = vec3(0.0f, 0.0f, 0.0f);

	// Step up animation
	float stepUpAddition = 0.0f;	
	if (m_bDoStepUpAnimation)
	{
		stepUpAddition = m_stepUpAnimationYAmount - m_stepUpAnimationPrevious;
		m_position.y += stepUpAddition;

		m_stepUpAnimationPrevious = m_stepUpAnimationYAmount;
	}

	// Integrate velocity
	vec3 acceleration = m_force + (m_gravityDirection * 9.81f)*4.0f;
	m_velocity += acceleration * dt;

	// Check collision
	{
		vec3 velocityToUse = m_velocity;
		vec3 velAmount = velocityToUse*dt;
		vec3 pNormal;
		int numberDivision = 1;
		while (length(velAmount) >= 1.0f)
		{
			numberDivision++;
			velAmount = velocityToUse*(dt / numberDivision);
		}
		for (int i = 0; i < numberDivision; i++)
		{
			float dtToUse = (dt / numberDivision) + ((dt / numberDivision) * i);
			vec3 posToCheck = GetCenter() + velocityToUse*dtToUse;
			bool stepUp = false;
			if (CheckCollisions(posToCheck, m_previousPosition, &pNormal, &velAmount, &stepUp))
			{
				// Reset velocity, we don't have any bounce
				m_velocity = vec3(0.0f, 0.0f, 0.0f);
				velocityToUse = vec3(0.0f, 0.0f, 0.0f);

				if (velocityToUse.y <= 0.0f)
				{
					if (m_bCanJump == false)
					{
						m_bCanJump = true;
					}
				}
			}
		}

		// Integrate position
		m_position += velocityToUse * dt;

		m_positionMovementAmount += vec3(0.0f, stepUpAddition + m_stepUpAdditionYAmountChangedCache, 0.0f);
		m_positionMovementAmount += velocityToUse * dt;
	}

	m_stepUpAdditionYAmountChangedCache = 0.0f;

	// Store previous position
	m_previousPosition = GetCenter();
}
Exemplo n.º 30
0
void CollisionSystem::Update(float dt)
{
    // Avoid warnings for not using dt.
    LOG_D("[CollisionSystem] Update: " << dt);
    CheckCollisions();
}