Made char rotate
This commit is contained in:
@ -84,6 +84,8 @@ void RenderPipeline::renderSceneCamera(
|
||||
auto rp = renderable->getPasses(ctx);
|
||||
renderPasses.insert(renderPasses.end(), rp.begin(), rp.end());
|
||||
}
|
||||
|
||||
// TODO: Sort the render passes by priority and z-index
|
||||
|
||||
// TODO: Make clearing the buffers editable!
|
||||
renderTarget->bind();
|
||||
|
@ -22,20 +22,13 @@ void QuadMesh::buffer(
|
||||
glm::vec3(positions.z, positions.w, depth)
|
||||
};
|
||||
|
||||
glm::vec2 coords[QUAD_VERTICE_COUNT] = {
|
||||
glm::vec2(coordinates.x, coordinates.y),
|
||||
glm::vec2(coordinates.z, coordinates.y),
|
||||
glm::vec2(coordinates.x, coordinates.w),
|
||||
glm::vec2(coordinates.z, coordinates.w)
|
||||
};
|
||||
|
||||
int32_t indices[QUAD_INDICE_COUNT] = {
|
||||
verticeStart, verticeStart + 1, verticeStart + 3,
|
||||
verticeStart, verticeStart + 2, verticeStart + 3
|
||||
};
|
||||
|
||||
mesh->bufferPositions(verticeStart, vertices, QUAD_VERTICE_COUNT);
|
||||
mesh->bufferCoordinates(verticeStart, coords, QUAD_VERTICE_COUNT);
|
||||
QuadMesh::bufferCoordinates(mesh, coordinates, verticeStart);
|
||||
mesh->bufferIndices(indiceStart, indices, QUAD_INDICE_COUNT);
|
||||
}
|
||||
|
||||
@ -54,6 +47,21 @@ void QuadMesh::bufferWithIndex(
|
||||
glm::vec3(positions.z, positions.w, indexOffset + 3)
|
||||
};
|
||||
|
||||
int32_t indices[QUAD_INDICE_COUNT] = {
|
||||
verticeStart, verticeStart + 1, verticeStart + 3,
|
||||
verticeStart, verticeStart + 2, verticeStart + 3
|
||||
};
|
||||
|
||||
mesh->bufferPositions(verticeStart, vertices, QUAD_VERTICE_COUNT);
|
||||
QuadMesh::bufferCoordinates(mesh, coordinates, verticeStart);
|
||||
mesh->bufferIndices(indiceStart, indices, QUAD_INDICE_COUNT);
|
||||
}
|
||||
|
||||
void QuadMesh::bufferCoordinates(
|
||||
const std::shared_ptr<Mesh> mesh,
|
||||
const glm::vec4 coordinates,
|
||||
const int32_t verticeStart
|
||||
) {
|
||||
glm::vec2 coords[QUAD_VERTICE_COUNT] = {
|
||||
glm::vec2(coordinates.x, coordinates.y),
|
||||
glm::vec2(coordinates.z, coordinates.y),
|
||||
@ -61,12 +69,5 @@ void QuadMesh::bufferWithIndex(
|
||||
glm::vec2(coordinates.z, coordinates.w)
|
||||
};
|
||||
|
||||
int32_t indices[QUAD_INDICE_COUNT] = {
|
||||
verticeStart, verticeStart + 1, verticeStart + 3,
|
||||
verticeStart, verticeStart + 2, verticeStart + 3
|
||||
};
|
||||
|
||||
mesh->bufferPositions(verticeStart, vertices, QUAD_VERTICE_COUNT);
|
||||
mesh->bufferCoordinates(verticeStart, coords, QUAD_VERTICE_COUNT);
|
||||
mesh->bufferIndices(indiceStart, indices, QUAD_INDICE_COUNT);
|
||||
}
|
@ -26,8 +26,8 @@ namespace Dawn {
|
||||
const std::shared_ptr<Mesh> mesh,
|
||||
const glm::vec4 positions,
|
||||
const glm::vec4 coordinates,
|
||||
const int32_t verticeStart,
|
||||
const int32_t indiceStart,
|
||||
const int32_t verticeStart = 0,
|
||||
const int32_t indiceStart = 0,
|
||||
const float_t depth = 0.0f
|
||||
);
|
||||
|
||||
@ -47,9 +47,22 @@ namespace Dawn {
|
||||
const std::shared_ptr<Mesh> mesh,
|
||||
const glm::vec4 positions,
|
||||
const glm::vec4 coordinates,
|
||||
const int32_t verticeStart,
|
||||
const int32_t indiceStart,
|
||||
const int32_t verticeStart = 0,
|
||||
const int32_t indiceStart = 0,
|
||||
const int32_t indexOffset = 0
|
||||
);
|
||||
|
||||
/**
|
||||
* Buffers quad texture coordinates to an existing mesh.
|
||||
*
|
||||
* @param mesh The mesh to buffer into.
|
||||
* @param coordinates The coordinates to buffer.
|
||||
* @param verticeStart The starting index of the vertices.
|
||||
*/
|
||||
static void bufferCoordinates(
|
||||
const std::shared_ptr<Mesh> mesh,
|
||||
const glm::vec4 coordinates,
|
||||
const int32_t verticeStart = 0
|
||||
);
|
||||
};
|
||||
}
|
@ -48,9 +48,13 @@ void InputManager::init(const std::shared_ptr<Game> game) {
|
||||
|
||||
// Default bindings
|
||||
this->bind(InputBind::UP, GLFW_KEY_W);
|
||||
this->bind(InputBind::UP, GLFW_KEY_UP);
|
||||
this->bind(InputBind::DOWN, GLFW_KEY_S);
|
||||
this->bind(InputBind::DOWN, GLFW_KEY_DOWN);
|
||||
this->bind(InputBind::LEFT, GLFW_KEY_A);
|
||||
this->bind(InputBind::LEFT, GLFW_KEY_LEFT);
|
||||
this->bind(InputBind::RIGHT, GLFW_KEY_D);
|
||||
this->bind(InputBind::RIGHT, GLFW_KEY_RIGHT);
|
||||
}
|
||||
|
||||
float_t InputManager::getInputValue(int32_t axis) {
|
||||
|
@ -21,35 +21,39 @@ void SimpleTexturedShader::getStages(
|
||||
switch(variant) {
|
||||
case ShaderOpenGLVariant::GLSL_330_CORE:
|
||||
vertex = std::make_shared<ShaderStage>(
|
||||
ShaderStageType::VERTEX,
|
||||
"#version 330 core\n"
|
||||
"layout (location = 0) in vec3 aPos;\n"
|
||||
"layout (location = 1) in vec2 aTexCoord;\n"
|
||||
"uniform mat4 u_Projection;\n"
|
||||
"uniform mat4 u_View;\n"
|
||||
"uniform mat4 u_Model;\n"
|
||||
"out vec2 o_TextCoord;\n"
|
||||
"void main() {\n"
|
||||
"gl_Position = u_Projection * u_View * u_Model * vec4(aPos, 1.0);\n"
|
||||
"o_TextCoord = vec2(aTexCoord.x, aTexCoord.y);\n"
|
||||
"}"
|
||||
ShaderStageType::VERTEX,R"(
|
||||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec2 aTexCoord;
|
||||
uniform mat4 u_Projection;
|
||||
uniform mat4 u_View;
|
||||
uniform mat4 u_Model;
|
||||
out vec2 o_TextCoord;
|
||||
void main() {
|
||||
gl_Position = u_Projection * u_View * u_Model * vec4(aPos, 1.0);
|
||||
o_TextCoord = vec2(aTexCoord.x, aTexCoord.y);
|
||||
}
|
||||
)"
|
||||
);
|
||||
|
||||
fragment = std::make_shared<ShaderStage>(
|
||||
ShaderStageType::FRAGMENT,
|
||||
"#version 330 core\n"
|
||||
"in vec2 o_TextCoord;\n"
|
||||
"out vec4 o_Color;\n"
|
||||
"uniform vec4 u_Color;\n"
|
||||
"uniform bool u_HasTexture;\n"
|
||||
"uniform sampler2D u_Texture;\n"
|
||||
"void main() {\n"
|
||||
"if(u_HasTexture) {\n"
|
||||
"o_Color = texture(u_Texture, o_TextCoord);\n"
|
||||
"} else {\n"
|
||||
"o_Color = u_Color;"
|
||||
"}\n"
|
||||
"}\n"
|
||||
ShaderStageType::FRAGMENT,R"(
|
||||
#version 330 core
|
||||
in vec2 o_TextCoord;
|
||||
out vec4 o_Color;
|
||||
uniform vec4 u_Color;
|
||||
uniform bool u_HasTexture;
|
||||
uniform sampler2D u_Texture;
|
||||
void main() {
|
||||
if(u_HasTexture) {
|
||||
o_Color = texture(u_Texture, o_TextCoord);
|
||||
} else {
|
||||
o_Color = u_Color;
|
||||
}
|
||||
|
||||
if(o_Color.a == 0) discard;
|
||||
}
|
||||
)"
|
||||
);
|
||||
break;
|
||||
|
||||
|
@ -30,10 +30,55 @@ void RPGEntity::onInit() {
|
||||
material = getItem()->addComponent<SimpleTexturedMaterial>();
|
||||
material->setColor(COLOR_WHITE);
|
||||
material->setTexture(sprites->getTexture());
|
||||
|
||||
updateSprite();
|
||||
}
|
||||
|
||||
void RPGEntity::onDispose() {
|
||||
meshRenderer = nullptr;
|
||||
mesh = nullptr;
|
||||
material = nullptr;
|
||||
}
|
||||
|
||||
enum RPGEntityDirection RPGEntity::getFacingDirection() {
|
||||
return facingDirection;
|
||||
}
|
||||
|
||||
void RPGEntity::setFacingDirection(const enum RPGEntityDirection dir) {
|
||||
if(facingDirection == dir) return;
|
||||
facingDirection = dir;
|
||||
updateSprite();
|
||||
}
|
||||
|
||||
void RPGEntity::updateSprite() {
|
||||
int32_t row, col;
|
||||
row = col = 0;
|
||||
|
||||
switch(this->facingDirection) {
|
||||
case RPGEntityDirection::NORTH:
|
||||
row = 0;
|
||||
break;
|
||||
|
||||
case RPGEntityDirection::SOUTH:
|
||||
row = 1;
|
||||
break;
|
||||
|
||||
case RPGEntityDirection::WEST:
|
||||
row = 2;
|
||||
break;
|
||||
|
||||
case RPGEntityDirection::EAST:
|
||||
row = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
// Convert row/col to UV coordinates.
|
||||
glm::vec4 uvs = {
|
||||
(float_t)col,
|
||||
(float_t)(row+1) / 4.0f,
|
||||
(float_t)(col+1),
|
||||
(float_t)row / 4.0f
|
||||
};
|
||||
|
||||
QuadMesh::bufferCoordinates(mesh, uvs, 0);
|
||||
}
|
@ -9,6 +9,13 @@
|
||||
#define RPG_ENTITY_SIZE 32.0f
|
||||
|
||||
namespace Dawn {
|
||||
enum class RPGEntityDirection {
|
||||
NORTH,
|
||||
SOUTH,
|
||||
EAST,
|
||||
WEST
|
||||
};
|
||||
|
||||
class RPGEntity final : public SceneComponent {
|
||||
private:
|
||||
|
||||
@ -17,9 +24,27 @@ namespace Dawn {
|
||||
std::shared_ptr<Mesh> mesh;
|
||||
std::shared_ptr<SimpleTexturedMaterial> material;
|
||||
|
||||
public:
|
||||
enum RPGEntityDirection facingDirection = RPGEntityDirection::SOUTH;
|
||||
|
||||
void updateSprite();
|
||||
|
||||
public:
|
||||
void onInit() override;
|
||||
void onDispose() override;
|
||||
|
||||
/**
|
||||
* Returns the facing direction of this entity.
|
||||
*
|
||||
* @return The facing direction of this entity.
|
||||
*/
|
||||
enum RPGEntityDirection getFacingDirection();
|
||||
|
||||
/**
|
||||
* Sets the facing direction of this entity.
|
||||
*
|
||||
* @param dir The direction to face.
|
||||
*/
|
||||
void setFacingDirection(const enum RPGEntityDirection dir);
|
||||
|
||||
};
|
||||
}
|
@ -5,11 +5,13 @@
|
||||
|
||||
#include "RPGPlayer.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
#include "RPGEntity.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
void RPGPlayer::onInit() {
|
||||
rpgEntity = getItem()->getComponent<RPGEntity>();
|
||||
assertNotNull(rpgEntity, "RPGPlayer requires an RPGEntity component!");
|
||||
|
||||
events.push_back(getScene()->onUnpausedUpdate.listen([&](
|
||||
float_t d
|
||||
) {
|
||||
@ -19,6 +21,29 @@ void RPGPlayer::onInit() {
|
||||
);
|
||||
|
||||
if(movement.x != 0 || movement.y != 0) {
|
||||
enum RPGEntityDirection dir = rpgEntity->getFacingDirection();
|
||||
if(movement.x > 0) {
|
||||
if(
|
||||
movement.y == 0 ||
|
||||
(movement.y < 0 && dir == RPGEntityDirection::SOUTH) ||
|
||||
(movement.y > 0 && dir == RPGEntityDirection::NORTH)
|
||||
) {
|
||||
rpgEntity->setFacingDirection(RPGEntityDirection::EAST);
|
||||
}
|
||||
} else if(movement.x < 0) {
|
||||
if(
|
||||
movement.y == 0 ||
|
||||
(movement.y < 0 && dir == RPGEntityDirection::SOUTH) ||
|
||||
(movement.y > 0 && dir == RPGEntityDirection::NORTH)
|
||||
) {
|
||||
rpgEntity->setFacingDirection(RPGEntityDirection::WEST);
|
||||
}
|
||||
} else if(movement.y > 0) {
|
||||
rpgEntity->setFacingDirection(RPGEntityDirection::SOUTH);
|
||||
} else if(movement.y < 0) {
|
||||
rpgEntity->setFacingDirection(RPGEntityDirection::NORTH);
|
||||
}
|
||||
|
||||
// Normalize angle.
|
||||
float_t angle = atan2(movement.x, movement.y);
|
||||
angle -= Math::deg2rad(90.0f);
|
||||
@ -35,12 +60,12 @@ void RPGPlayer::onInit() {
|
||||
this->camera->lookAtPixelPerfect(
|
||||
getItem()->getLocalPosition() + glm::vec3(0, -(RPG_ENTITY_SIZE*2), 0),
|
||||
getItem()->getLocalPosition(),
|
||||
1.0f
|
||||
2.0f
|
||||
);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
void RPGPlayer::onDispose() {
|
||||
|
||||
this->rpgEntity = nullptr;
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "component/display/Camera.hpp"
|
||||
#include "RPGEntity.hpp"
|
||||
|
||||
#define PLAYER_SPEED 128.0f
|
||||
|
||||
@ -14,6 +14,7 @@ namespace Dawn {
|
||||
|
||||
public:
|
||||
std::shared_ptr<Camera> camera;
|
||||
std::shared_ptr<RPGEntity> rpgEntity;
|
||||
|
||||
void onInit() override;
|
||||
void onDispose() override;
|
||||
|
@ -30,6 +30,7 @@ void Dawn::helloWorldScene(Scene &s) {
|
||||
// Player:
|
||||
{
|
||||
auto ent = s.createSceneItem();
|
||||
ent->setLocalPosition(glm::vec3(0, 0, 0.00f));
|
||||
auto eEnt = ent->addComponent<RPGEntity>();
|
||||
auto ePlyr = ent->addComponent<RPGPlayer>();
|
||||
ePlyr->camera = camera;
|
||||
@ -38,7 +39,7 @@ void Dawn::helloWorldScene(Scene &s) {
|
||||
// Test Entity
|
||||
{
|
||||
auto ent = s.createSceneItem();
|
||||
ent->setLocalPosition(glm::vec3(-128, -32, 0));
|
||||
ent->setLocalPosition(glm::vec3(-128, -32, -0.01f));
|
||||
auto eEnt = ent->addComponent<RPGEntity>();
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,8 @@ if not os.path.exists(args.input):
|
||||
img = Image.open(args.input)
|
||||
|
||||
# Normalize the image
|
||||
hasAlpha = img.mode == 'RGBA' or img.mode == 'LA'
|
||||
# output img.info
|
||||
hasAlpha = 'transparency' in img.info
|
||||
|
||||
# Convert the image to RGB or RGBA mode based on alpha channel
|
||||
if hasAlpha:
|
||||
|
Reference in New Issue
Block a user