Add Simple GTE_Sprite type

This commit is contained in:
jaby 2024-04-21 16:31:17 +02:00
parent 3ef946ad4b
commit 6d2e1a7f8b
2 changed files with 23 additions and 15 deletions

View File

@ -22,9 +22,10 @@ namespace GTETest {
GPU::Color24::Grey() GPU::Color24::Grey()
)); ));
static auto rotation = 0.0_deg; static auto gbl_rotation = 0.0_deg;
static void setup() { static void setup() {
doener_fish.area.position = GPU::PositionI16::create(100, 100);
Shared::back_menu.reset(); Shared::back_menu.reset();
GTE::set_geom_offset(0, 0); GTE::set_geom_offset(0, 0);
@ -37,12 +38,10 @@ namespace GTETest {
return true; return true;
} }
const auto matrix = GTE::MATRIX{ auto matrix = GTE::MATRIX::rotated(-gbl_rotation, gbl_rotation, -gbl_rotation);
GTE::ROTMATRIX::rotated(-rotation, rotation, -rotation),
GTE::TRANSFERVECTOR::translated((Assets::Main::DoenerFishInfo.size.width/2), (Assets::Main::DoenerFishInfo.size.height/2))
};
doener_fish.apply(matrix); doener_fish.apply(matrix);
rotation += 5.0_deg; doener_fish.angle += 25.0_deg;
gbl_rotation += 2.5_deg;
return false; return false;
} }

View File

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