Add Simple GTE_Sprite type

This commit is contained in:
Jaby
2024-04-21 16:31:17 +02:00
committed by Jaby
parent 4f80a6e25e
commit 08c673f745
2 changed files with 23 additions and 15 deletions

View File

@@ -7,24 +7,33 @@ namespace GTETest {
using namespace JabyEngine;
struct GTE_Sprite {
GPU::AreaI16 area;
GPU::POLY_FT4 display;
GPU::AreaI16 area;
GPU::PositionI16 pivot;
deg_t angle;
GPU::POLY_FT4 display;
static constexpr GTE_Sprite create(const GPU::POLY_FT4& base) {
return GTE_Sprite{
.area = GPU::AreaI16::create(base.get_rect_pos(), base.get_rect_size()),
.pivot = GPU::PositionI16::create(base.get_rect_size().width/2, base.get_rect_size().height/2),
.angle = 0.0_deg,
.display = base
};
}
void apply(const GTE::MATRIX& matrix) {
const auto move_back = GTE::MATRIX::comp(GTE::MATRIX::translated(-matrix.transfer.x, -matrix.transfer.y, -matrix.transfer.z), matrix);
const auto& area = this->area;
void apply(const GTE::MATRIX& gbl_matrix) {
auto matrix = GTE::MATRIX::translated(-this->pivot.x, -this->pivot.y, 0).comp(
GTE::MATRIX::rotated(0.0_deg, 0.0_deg, this->angle)
).comp(
GTE::MATRIX::translated(this->pivot.x, this->pivot.y, 0)
).comp(
GTE::MATRIX::translated(this->area.position.x, this->area.position.y)
).comp(gbl_matrix);
this->display.vertex0 = move_back.apply_to(area.get_top_left());
this->display.vertex1 = move_back.apply_to(area.get_top_right());
this->display.vertex2 = move_back.apply_to(area.get_bottom_left());
this->display.vertex3 = move_back.apply_to(area.get_bottom_right());
this->display.vertex0 = matrix.apply_to(GPU::Vertex::create(0, 0));
this->display.vertex1 = matrix.apply_to(GPU::Vertex::create(this->area.size.width, 0));
this->display.vertex2 = matrix.apply_to(GPU::Vertex::create(0, this->area.size.height));
this->display.vertex3 = matrix.apply_to(GPU::Vertex::create(this->area.size.width, this->area.size.height));
}
void render() {