-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranslation Algorithm.cpp
More file actions
48 lines (38 loc) · 1.2 KB
/
Translation Algorithm.cpp
File metadata and controls
48 lines (38 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <SFML/Graphics.hpp>
int main()
{
// Window size
const int WIDTH = 800;
const int HEIGHT = 600;
// Translation values
float translateX = 100.0f;
float translateY = 100.0f;
// Create the window
sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT), "Translation Example");
// Game loop
while (window.isOpen())
{
// Handle events
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
// Clear the window
window.clear(sf::Color::Black);
// Draw a rectangle before translation
sf::RectangleShape rectangle(sf::Vector2f(100.0f, 100.0f));
rectangle.setPosition(100.0f, 100.0f);
rectangle.setFillColor(sf::Color::Red);
window.draw(rectangle);
// Perform translation
sf::RectangleShape translatedRect(sf::Vector2f(100.0f, 100.0f));
translatedRect.setPosition(100.0f + translateX, 100.0f + translateY);
translatedRect.setFillColor(sf::Color::Green);
window.draw(translatedRect);
// Update the window
window.display();
}
return 0;
}