Testing textures
This commit is contained in:
@ -8,84 +8,36 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
TiledSprite::TiledSprite(SceneItem *item) : SceneItemComponent(item) {
|
||||
TiledSprite::TiledSprite(SceneItem *item) :
|
||||
SceneItemComponent(item),
|
||||
tile(-1),
|
||||
tileset(nullptr),
|
||||
meshHost(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
glm::vec2 TiledSprite::getUV0() {
|
||||
assertNotNull(this->tileset);
|
||||
auto tile = this->tileset->getTile(tileIndex);
|
||||
return glm::vec2(
|
||||
(this->flipState & TILED_SPRITE_FLIP_X) == 0 ? tile.uv0.x : tile.uv1.x,
|
||||
(this->flipState & TILED_SPRITE_FLIP_Y) == 0 ? tile.uv0.y : tile.uv1.y
|
||||
);
|
||||
}
|
||||
|
||||
glm::vec2 TiledSprite::getUV1() {
|
||||
assertNotNull(this->tileset);
|
||||
auto tile = this->tileset->getTile(tileIndex);
|
||||
return glm::vec2(
|
||||
(this->flipState & TILED_SPRITE_FLIP_X) == 0 ? tile.uv1.x : tile.uv0.x,
|
||||
(this->flipState & TILED_SPRITE_FLIP_Y) == 0 ? tile.uv1.y : tile.uv0.y
|
||||
);
|
||||
}
|
||||
|
||||
void TiledSprite::setTileset(Tileset *tileset) {
|
||||
assertNotNull(tileset);
|
||||
this->tileset = tileset;
|
||||
this->setTile(0);
|
||||
}
|
||||
|
||||
void TiledSprite::setTilesetAndSize(TilesetGrid *tileset, glm::vec2 center) {
|
||||
this->setTileset(tileset);
|
||||
this->setSize(glm::vec2(tileset->divX, tileset->divY), center);
|
||||
}
|
||||
|
||||
void TiledSprite::setTilesetAndSize(TilesetGrid *tileset) {
|
||||
this->setTileset(tileset);
|
||||
this->setSize(glm::vec2(tileset->divX, tileset->divY));
|
||||
}
|
||||
|
||||
void TiledSprite::setTile(int32_t tileIndex) {
|
||||
if(tileIndex == this->tileIndex) return;
|
||||
this->tileIndex = tileIndex;
|
||||
if(this->host != nullptr) {
|
||||
QuadMesh::bufferCoordinates(
|
||||
&this->host->mesh, this->getUV0(), this->getUV1(), 0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void TiledSprite::setSize(glm::vec2 size, glm::vec2 center) {
|
||||
this->xy0 = -center;
|
||||
this->xy1 = size - center;
|
||||
if(this->host != nullptr) {
|
||||
QuadMesh::bufferPositions(
|
||||
&this->host->mesh, this->xy0, this->xy1, 0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void TiledSprite::setSize(glm::vec2 size) {
|
||||
this->setSize(size, size / 2.0f);
|
||||
}
|
||||
|
||||
std::vector<SceneItemComponent*> TiledSprite::getDependencies() {
|
||||
this->host = this->item->getComponent<MeshHost>();
|
||||
if(this->meshHost == nullptr) {
|
||||
this->meshHost = this->item->getComponent<QuadMeshHost>();
|
||||
}
|
||||
|
||||
return std::vector<SceneItemComponent*>{
|
||||
this->host
|
||||
return {
|
||||
this->meshHost
|
||||
};
|
||||
}
|
||||
|
||||
void TiledSprite::onStart() {
|
||||
SceneItemComponent::onStart();
|
||||
assertNotNull(this->host);
|
||||
assertNotNull(this->tileset);
|
||||
|
||||
QuadMesh::initQuadMesh(&this->host->mesh,
|
||||
this->xy0, this->getUV0(),
|
||||
this->xy1, this->getUV1(),
|
||||
0
|
||||
);
|
||||
useEffect([&]{
|
||||
if(this->meshHost == nullptr || this->tileset == nullptr) return;
|
||||
auto tile = this->tileset->getTile(this->tile);
|
||||
this->meshHost->uv0 = tile.uv0;
|
||||
this->meshHost->uv1 = tile.uv1;
|
||||
}, {
|
||||
&this->tile,
|
||||
&this->meshHost,
|
||||
&this->tileset
|
||||
})();
|
||||
}
|
Reference in New Issue
Block a user