本文整理汇总了C++中sf::Sprite::TransformToGlobal方法的典型用法代码示例。如果您正苦于以下问题:C++ Sprite::TransformToGlobal方法的具体用法?C++ Sprite::TransformToGlobal怎么用?C++ Sprite::TransformToGlobal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Sprite
的用法示例。
在下文中一共展示了Sprite::TransformToGlobal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetAABB
sf::IntRect Collision::GetAABB(const sf::Sprite& Object) {
//Get the top left corner of the sprite regardless of the sprite's center
//This is in Global Coordinates so we can put the rectangle back into the right place
sf::Vector2f pos = Object.TransformToGlobal(sf::Vector2f(0, 0));
//Store the size so we can calculate the other corners
sf::Vector2f size = Object.GetSize();
float Angle = Object.GetRotation();
//Bail out early if the sprite isn't rotated
if (Angle == 0.0f) {
return sf::IntRect(static_cast<int> (pos.x),
static_cast<int> (pos.y),
static_cast<int> (pos.x + size.x),
static_cast<int> (pos.y + size.y));
}
//Calculate the other points as vectors from (0,0)
//Imagine sf::Vector2f A(0,0); but its not necessary
//as rotation is around this point.
sf::Vector2f B(size.x, 0);
sf::Vector2f C(size.x, size.y);
sf::Vector2f D(0, size.y);
//Rotate the points to match the sprite rotation
B = RotatePoint(B, Angle);
C = RotatePoint(C, Angle);
D = RotatePoint(D, Angle);
//Round off to int and set the four corners of our Rect
int Left = static_cast<int> (MinValue(0.0f, B.x, C.x, D.x));
int Top = static_cast<int> (MinValue(0.0f, B.y, C.y, D.y));
int Right = static_cast<int> (MaxValue(0.0f, B.x, C.x, D.x));
int Bottom = static_cast<int> (MaxValue(0.0f, B.y, C.y, D.y));
//Create a Rect from out points and move it back to the correct position on the screen
sf::IntRect AABB = sf::IntRect(Left, Top, Right, Bottom);
AABB.Offset(static_cast<int> (pos.x), static_cast<int> (pos.y));
return AABB;
}