added 2d png support

This commit is contained in:
h4570
2020-12-01 17:26:10 +01:00
parent 3841487388
commit 510199164c
17 changed files with 317 additions and 80 deletions
+16
View File
@@ -9,6 +9,7 @@
*/
#include "../../include/models/math/point.hpp"
#include "../../include/utils/math.hpp"
#include <stdio.h>
@@ -55,6 +56,21 @@ void Point::set(const Point &v)
y = v.y;
}
void Point::rotate(const float &t_angle, const float &t_x, const float &t_y)
{
float s = Math::sin(t_angle);
float c = Math::cos(t_angle);
x -= t_x;
y -= t_y;
float xnew = x * c - y * s;
float ynew = x * s + y * c;
x = xnew + t_x;
y = ynew + t_y;
}
const void Point::print() const
{
printf("Point(%f, %f)\n", x, y);
+12 -1
View File
@@ -39,15 +39,18 @@ MeshTexture::~MeshTexture()
// Methods
// ----
void MeshTexture::setSize(const u8 &t_width, const u8 &t_height)
void MeshTexture::setSize(const u8 &t_width, const u8 &t_height, const TextureType &t_type)
{
if (_isSizeSet)
{
PRINT_ERR("Can't set size, because was already set!");
return;
}
if (t_width > 256 || t_height > 256)
PRINT_ERR("Given texture can be too big for PS2. Please strict to 256x256 max. Prefer 128x128.");
width = t_width;
height = t_height;
_type = t_type;
data = new unsigned char[getDataSize()];
_isSizeSet = true;
}
@@ -86,3 +89,11 @@ void MeshTexture::addLink(const u32 &t_meshId, const u32 &t_materialId)
link.meshId = t_meshId;
texLinks.push_back(link);
}
void MeshTexture::addLink(const u32 &t_spriteId)
{
TextureLink link;
link.materialId = 0;
link.meshId = t_spriteId;
texLinks.push_back(link);
}
+55
View File
@@ -0,0 +1,55 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2020, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#include "../include/models/sprite.hpp"
#include "../include/utils/debug.hpp"
#include "../include/utils/string.hpp"
#include <cstdlib>
// ----
// Constructors/Destructors
// ----
Sprite::Sprite()
{
id = rand() % 1000000;
_isSizeSet = false;
_flipH = false;
_flipV = false;
scale = 1.0F;
setDefaultColor();
setDefaultLODAndClut();
}
Sprite::~Sprite() {}
// ----
// Methods
// ----
/** Set's default object color + no transparency */
void Sprite::setDefaultColor()
{
color.r = 0x80;
color.g = 0x80;
color.b = 0x80;
color.a = 0x80;
color.q = 0.0F;
}
/** Sets texture level of details settings and CLUT settings */
void Sprite::setDefaultLODAndClut()
{
clut.storage_mode = CLUT_STORAGE_MODE1;
clut.start = 0;
clut.psm = 0;
clut.load_method = CLUT_NO_LOAD;
clut.address = 0;
}