Skip to content

Commit

Permalink
Rotate Works But No SetRotation
Browse files Browse the repository at this point in the history
  • Loading branch information
eUltrabyte committed May 13, 2023
1 parent f343f8f commit 67f805d
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ output/
cmake-build-debug/
cmake-build-release/

compile_commands.json
.clangd
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ file(COPY Resource/ DESTINATION Resource/)
if(UVKE_EXAMPLES)
add_subdirectory(Examples/App)
file(COPY Resource/ DESTINATION Examples/App/Resource/)
endif()
endif()
2 changes: 1 addition & 1 deletion Examples/App/ExampleApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ExampleApp : public uvke::App {

uvke::Sprite sprite({ 0.2f, 0.15f });
sprite.SetPosition({ 0.0f, 0.0f });
// sprite.SetRotation(90.0f);
sprite.SetRotation(45.0f);
sprite.Create(m_renderer);
m_renderer->Push(std::make_shared<uvke::Sprite>(sprite));

Expand Down
4 changes: 4 additions & 0 deletions Source/uvke/Graphics/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace uvke {
m_ubo.projection = Perspective<float>(Radians(45.0f), size.x / size.y, 0.1f, 1000.0f);
m_ubo.projection.data[1][1] *= -1;
} break;

case Projection::Frustumic: {
m_ubo.projection = Frustum<float>(-size.x, size.x, size.y, -size.y, -150.0f, 100.0f);
} break;
}
}

Expand Down
1 change: 1 addition & 0 deletions Source/uvke/Graphics/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace uvke {
enum UVKE_API Projection {
Orthographic = 0,
Perspectivic = 1,
Frustumic = 2,
};

class UVKE_API Camera {
Expand Down
8 changes: 6 additions & 2 deletions Source/uvke/Graphics/Sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace uvke {
Sprite::Sprite(const vec2f& size)
: m_position({ 0.0f, 0.0f }), m_scale({ 1.0f, 1.0f }) {
: m_position({ 0.0f, 0.0f }), m_scale({ 1.0f, 1.0f }), m_debug(false) {
m_vertices = std::vector<Vertex> {
{ { -size.x, -size.y, 0.0f }, { 1.0f, 1.0f, 1.0f }, { 1.0f, 0.0f } },
{ { size.x, -size.y, 0.0f }, { 1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f } },
Expand Down Expand Up @@ -47,7 +47,11 @@ namespace uvke {
mat4x4f model = camera->GetModel();
model = Scale<float>(model, vec3f(m_scale.x, m_scale.y, 1.0f));
model = Translate<float>(model, vec3f(m_position.x, m_position.y, 0.0f));
// model = Rotate<float>(model, vec3f(0.0f, 0.0f, 1.0f), Radians<float>(m_angle));

if(!m_debug) {
model = Rotate<float>(model, vec3f(1.0f, 0.0f, 0.0f), Radians<float>(m_angle));
m_debug = true;
}

camera->SetModel(model);
camera->Update(m_uniformBuffer);
Expand Down
1 change: 1 addition & 0 deletions Source/uvke/Graphics/Sprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace uvke {
vec2f m_position;
vec2f m_scale;
float m_angle;
bool m_debug;
std::vector<Vertex> m_vertices;
std::vector<unsigned int> m_indices;
std::shared_ptr<VertexBuffer> m_vertexBuffer;
Expand Down
54 changes: 35 additions & 19 deletions Source/uvke/Utils/Mat4x4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#define UVKE_MAT4X4_HEADER

#include "../uvkepch.hpp"
#include "../Core/Core.hpp"
#include "Vec3.hpp"

namespace uvke {
template<typename T>
Expand Down Expand Up @@ -401,6 +403,20 @@ namespace uvke {
return result;
}

template<typename T>
inline constexpr mat4x4<T> Frustum(const T& left, const T& right, const T& bottom, const T& top, const T& zNear, const T& zFar) {
mat4x4<T> result;
result.data[0][0] = (2 * zNear) / (right - left);
result.data[1][1] = (2 * zNear) / (bottom - top);
result.data[2][0] = -(right + left) / (right - left);
result.data[2][0] = -(bottom + top) / (bottom - top);
result.data[2][2] = zNear / (zNear - zFar);
result.data[2][3] = 1;
result.data[3][2] = zNear * zFar / (zNear - zFar);

return result;
}

template<typename T>
inline constexpr mat4x4<T> LookAt(const vec3<T>& eye, const vec3<T>& center, const vec3<T>& up) {
vec3<T> normalized = Normalize<T>(vec3<T>(center.x - eye.x, center.y - eye.y, center.z - eye.z));
Expand Down Expand Up @@ -440,27 +456,27 @@ namespace uvke {
T cosinus = Cos<T>(angle);
T sinus = Sin<T>(angle);
vec3<T> axis = Normalize<T>(direction);
float calculation = 1.0f - cosinus;
vec3<T> calculation = vec3<T>(1.0f - cosinus * direction.x, 1.0f - cosinus * direction.y, 1.0f - cosinus * direction.z);

mat4x4<T> result;
result.data[0][0] = cosinus + calculation * axis.x * axis.x;
result.data[0][1] = calculation * axis.x * axis.y + sinus * axis.z;
result.data[0][2] = calculation * axis.x * axis.z - sinus * axis.y;
result.data[0][3] = 0.0f;

result.data[1][0] = calculation * axis.y * axis.x - sinus * axis.z;
result.data[1][1] = cosinus + calculation * axis.y * axis.y;
result.data[1][2] = calculation * axis.y * axis.z + sinus * axis.x;
result.data[1][3] = 0.0f;

result.data[2][0] = calculation * axis.z * axis.x + sinus * axis.y;
result.data[2][1] = calculation * axis.z * axis.y - sinus * axis.x;
result.data[2][2] = cosinus + calculation * axis.z * axis.z;
result.data[2][3] = 0.0f;

result.data[3][0] = 0.0f;
result.data[3][1] = 0.0f;
result.data[3][2] = 0.0f;
result.data[0][0] = cosinus + calculation.x * axis.x;
result.data[0][1] = calculation.x * axis.y + sinus * axis.z;
result.data[0][2] = calculation.x * axis.z - sinus * axis.y;
result.data[0][3] = 1.0f;

result.data[1][0] = calculation.y * axis.x - sinus * axis.z;
result.data[1][1] = cosinus + calculation.y * axis.y;
result.data[1][2] = calculation.y * axis.z + sinus * axis.x;
result.data[1][3] = 1.0f;

result.data[2][0] = calculation.z * axis.x + sinus * axis.y;
result.data[2][1] = calculation.z * axis.y - sinus * axis.x;
result.data[2][2] = cosinus + calculation.z * axis.z;
result.data[2][3] = 1.0f;

result.data[3][0] = 1.0f;
result.data[3][1] = 1.0f;
result.data[3][2] = 1.0f;
result.data[3][3] = 1.0f;

result *= matrix;
Expand Down
2 changes: 2 additions & 0 deletions Source/uvke/Utils/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#ifndef UVKE_UTILS_HEADER
#define UVKE_UTILS_HEADER

#include "../uvkepch.hpp"

namespace uvke {
namespace priv {
inline static const float PI = 3.141592653f;
Expand Down
1 change: 1 addition & 0 deletions Source/uvke/Utils/Vec2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define UVKE_VEC2_HEADER

#include "../uvkepch.hpp"
#include "../Core/Core.hpp"

namespace uvke {
template<typename T>
Expand Down
1 change: 1 addition & 0 deletions Source/uvke/Utils/Vec3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define UVKE_VEC3_HEADER

#include "../uvkepch.hpp"
#include "../Core/Core.hpp"

namespace uvke {
template<typename T>
Expand Down
1 change: 1 addition & 0 deletions Source/uvke/Utils/Vec4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define UVKE_VEC4_HEADER

#include "../uvkepch.hpp"
#include "../Core/Core.hpp"

namespace uvke {
template<typename T>
Expand Down
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- add multi threading support
- add audio support
- asset manager class
- add smid and avx support in math lib
- own file format for textures, audio, etc
- reimplement stb_image with own library
- reimplement audio with own library
Expand Down

0 comments on commit 67f805d

Please sign in to comment.