I have a sf::RectangleShape 2D cube and want to create functionality to draw sides "like 3D" for that cube.
This is my solution:
//X. Y
//gonyometric latters for clearity
sf::Vector2f A(300, 500);
sf::Vector2f B(500, 500);
sf::Vector2f E(300, 300);
sf::Vector2f F(500, 300);
sf::RectangleShape cube;
cube.setPosition(300, 300);
cube.setSize(sf::Vector2f(200,200));
cube.setTexture(&brick_texture);
// convex shape
sf::ConvexShape rightSide;
rightSide.setPointCount(4);
rightSide.setPosition(B);
rightSide.rotate(-45);
rightSide.setPoint(0 ,sf::Vector2f(0, 0));
sf::Vector2f C(100,0);
rightSide.setPoint(1, C);
sf::Vector2f D(100+(200 * getSin(45)), (0-200* getCos(45)));
rightSide.setPoint(2, D);
rightSide.setPoint(3, sf::Vector2f(0 + (200 * getSin(45)), (0 - 200 * getCos(45))));
rightSide.setTexture(&brick_texture);
This is how it looks:
![drawed cube](https://i.stack.imgur.com/HT8Je.png)
I can't figure out how to edit shape of texture to shape of rightSide to make it really like 3D.
Solution:
I used custome matrix of sf::Transform to manage shape deformation. And replaced convex by rectangleShape.
Fastest and easiest way to make it is create whole matrix with default parameters and change values you want. Other more comlex soution is to take matrix from your shape, convert it to float array inside 4x4 loop(here you can edit its elements with cute switch) and bind parts of that array properly to new 3x3 matrix.
This is result:
![solved](https://i.stack.imgur.com/INPSw.png)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…