示例#1
0
void Graphics::draw(sf::Vector2f position, sf::Vector2f hitbox, sf::Color color)
{
    sf::RectangleShape rectangle = sf::RectangleShape(hitbox);
    rectangle.setOrigin(0, rectangle.getSize().y);
    rectangle.setFillColor(color);

    //Translate position
    translatePosition(position, window_);

    rectangle.setPosition(position);

    window_->draw(rectangle);
    return;
}
示例#2
0
void Graphics::draw(sf::Vector2f position, sf::Vector2f hitbox, sf::Sprite sprite)
{
    sprite.setOrigin(0, hitbox.y);
    sf::Vector2f roundedPosition = sf::Vector2f(position.x - 0.5, position.y - 0.5);

    //Translate position
    translatePosition(roundedPosition, window_);

    //Set Position
    sprite.setPosition(roundedPosition);

    //Scale if necessary
    sprite.scale(hitbox.x / sprite.getTextureRect().width, hitbox.y / sprite.getTextureRect().height);

    window_->draw(sprite);
    return;
}
示例#3
0
void Camera::moveRight(float units){
	//Translate to origin
	translateOrigin();

	//Calculate right vector
	glm::vec3 right = getRight();

	//Normalize right vector
	right = glm::normalize(right);
	glm::mat4 transMat = glm::translate(right*units);

	//Translate back
	translatePosition();

	//move both position and lookAt
	setLookAt(glm::vec3(transMat*glm::vec4(lookAt, 1)));
	setPosition(glm::vec3(transMat*glm::vec4(position, 1)));

}
示例#4
0
void Camera::turn (float const x, float const y, float const speed){
	glm::vec3 newVec3;
	glm::vec3 right;

	//Translate to the origin
	translateOrigin();

	//calculate right vector

	//Rotate about x
	setLookAt(glm::mat3(glm::rotate(speed * y, getRight()))*lookAt);

	//Rotate about y
	glm::vec3 currentUp = getCurrentUp();
	setLookAt(glm::mat3(glm::rotate(speed * x, currentUp))*lookAt);

	//Translate back to previous position
	translatePosition();
}