void eae6320::Graphics::MovePlayer(eae6320::Math::cVector &i_Position)
{
	i_Position.y -= 5.0f;
	Math::cVector Zero;
	Math::cMatrix_transformation nonTranslationMatrix(s_Camera->getCameraOrientation(), Zero);
	Math::cVector movementVector = i_Position * nonTranslationMatrix;

	Math::cVector end = s_Player[1].m_position + Math::cVector(movementVector.x, 0 - 10, 0);
	Graphics::Mesh::sVertex intersectionPoint;
	if (Physics::CheckCollisions(s_Player[1].m_position, end, intersectionPoint))
	{
		Math::cVector collisionNormal(intersectionPoint.nx, intersectionPoint.ny, intersectionPoint.nz);
		movementVector -= collisionNormal * Math::Dot(collisionNormal, movementVector);
	}

	end = s_Player[1].m_position + Math::cVector(0, movementVector.y - 10, 0);
	if (Physics::CheckCollisions(s_Player[1].m_position, end, intersectionPoint))
	{
		Math::cVector collisionNormal(intersectionPoint.nx, intersectionPoint.ny, intersectionPoint.nz);
		movementVector -= collisionNormal * Math::Dot(collisionNormal, movementVector);
	}

	end = s_Player[1].m_position + Math::cVector(0, 0 - 10, movementVector.z);
	if (Physics::CheckCollisions(s_Player[1].m_position, end, intersectionPoint))
	{
		Math::cVector collisionNormal(intersectionPoint.nx, intersectionPoint.ny, intersectionPoint.nz);
		movementVector -= collisionNormal * Math::Dot(collisionNormal, movementVector);
	}

	for (int i = 0; i < 11; i++)
	{
		s_Player[i].m_position += movementVector;
	}
}
Exemple #2
0
/*
	Checks the position of every point of the vertex, if
	any of them are outside of the window and still heading
	there changes their direction

	momentOfInertia = mass * r^2
*/
void Convex::borderCollision(sf::RenderWindow* window)
{
	float impulse;
	float Px, Py;

	for (int i = 0; i < getPointCount(); i++)
	{
		
		if (getPoint(i).x < 0 && _velocity.x < 0)
		{
			sf::Vector2f collisionNormal(1, 0);
			applyChanges(i, &collisionNormal);
		}

		if (getPoint(i).x > window->getSize().x && _velocity.x > 0)
		{
			sf::Vector2f collisionNormal(-1, 0);
			applyChanges(i, &collisionNormal);
		}

		if (getPoint(i).y < 0 && _velocity.y < 0)
		{
			sf::Vector2f collisionNormal(0, 1);
			applyChanges(i, &collisionNormal);
		}

		if (getPoint(i).y > window->getSize().y && _velocity.y > 0)
		{
			sf::Vector2f collisionNormal(0, -1);
			applyChanges(i, &collisionNormal);
		}

		_momentOfInertia = _mass;
	}
}
Exemple #3
0
bool Maze::mazeCollision(SceneNode& node)
{
	bool isInContact = false;
	sf::FloatRect intersect;	 
	sf::Vector2u position = static_cast<sf::Vector2u>(node.worldPosition());
	int curRow = static_cast<int>(position.y / tileSize);
	int curCol = static_cast<int>(position.x / tileSize);

	contactNormals_.clear();
	for(int i = curRow - 1; i <= curRow + 1; ++i)
	{
		unsigned int ui = static_cast<unsigned int>(i);
		for(int j = curCol - 1; j <= curCol + 1; ++j)
		{
			unsigned int uj = static_cast<unsigned int>(j);
			if(i >= 0 && j >= 0 && ui < mazeSize_.y && uj < mazeSize_.x)
			{
				TileId id = mazeMap_[ui][uj];
				for(sf::FloatRect v: tileHitBoxesById_[id])
				{
					v.top  += static_cast<float>(ui*tileSize);
					v.left += static_cast<float>(uj*tileSize);
					hitBox_ = v;
					if(collision(*this, node))
					{
						contactNormals_.push_back(collisionNormal(node));
						isInContact = true;
					}
				}
			}
		}
	}

	hitBox_ = sf::FloatRect(); //Back to zero so collision from others to maze is null;

	return isInContact;
}