diff --git a/CMakeLists.txt b/CMakeLists.txt index eb5ded2..23a0a16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,19 +27,20 @@ target_include_directories(Prog3B PRIVATE ${CMAKE_CURRENT_LIST_DIR}/includes ${CMAKE_CURRENT_LIST_DIR}/raylib ) - target_link_libraries(${EXECUTABLE_NAME} PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/mac_x86/libgamematrix.a - raylib + #${CMAKE_CURRENT_LIST_DIR}/windows/libgamematrix.a + ${CMAKE_CURRENT_LIST_DIR}/windows/libraylib.a + opengl32 + gdi32 + m + winmm ) - # Checks if OSX and links appropriate frameworks (Only required on MacOS) if (APPLE) - target_link_libraries(Prog3B PRIVATE "-framework IOKit" - "-framework Cocoa" - "-framework OpenGL" - ) + target_link_libraries(Prog3B "-framework IOKit") + target_link_libraries(Prog3B "-framework Cocoa") + target_link_libraries(Prog3B "-framework OpenGL") endif() add_executable(tests @@ -48,12 +49,15 @@ add_executable(tests ) target_include_directories(tests PRIVATE ${INCLUDE_DIRS}) -target_link_libraries(tests PRIVATE) +target_link_libraries(tests PRIVATE + opengl32 + gdi32 + winmm +) -#if (APPLE) - #target_link_libraries(Prog3B PRIVATE "-framework IOKit") - #target_link_libraries(Prog3B PRIVATE "-framework Cocoa") - #target_link_libraries(Prog3B PRIVATE "-framework OpenGL") - -#endif() +if (APPLE) + target_link_libraries(Prog3B PRIVATE "-framework IOKit") + target_link_libraries(Prog3B PRIVATE "-framework Cocoa") + target_link_libraries(Prog3B PRIVATE "-framework OpenGL") +endif() diff --git a/src/gamecube.cpp b/src/gamecube.cpp index 0ab2dae..0e03c65 100644 --- a/src/gamecube.cpp +++ b/src/gamecube.cpp @@ -1,15 +1,14 @@ -#include "gamecube.h" #include "raylib.h" +#include "gamecube.h" +gamecube::gamecube(const Vec3& pos, Color col) + : position(pos), color(col) {} void gamecube::Update(float flipSpeed) { - float dt = GetFrameTime(); - if (flippingForward) { - rotation += flipSpeed * dt; - + rotation += flipSpeed; if (rotation >= 180.0f) { rotation = 180.0f; @@ -19,8 +18,7 @@ void gamecube::Update(float flipSpeed) } else if (flippingBackward) { - rotation -= flipSpeed * dt; - + rotation -= flipSpeed; if (rotation <= 0.0f) { rotation = 0.0f; @@ -29,3 +27,40 @@ void gamecube::Update(float flipSpeed) } } } + +void gamecube::FlipForward() { flippingForward = true; } +void gamecube::FlipBackward() { flippingBackward = true; } + +bool gamecube::IsFlipped() const { return flipped; } +bool gamecube::IsMatched() const { return matched; } +void gamecube::SetMatched(bool m) { matched = m; } + +void gamecube::Draw() const +{ + rlPushMatrix(); + + auto matrix_a = Matrix3D::gameMatrix::translate( + { position.x, position.y, position.z } + ); + auto matrix_b = Matrix3D::gameMatrix::rot3D(rotation, 'y'); + auto model = Matrix3D::gameMatrix::matmul(matrix_a, matrix_b); + + float f[16]; + for (int i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) + f[j * 4 + i] = model[i][j]; + + rlMultMatrixf(f); + + if (rotation < 90.0f) + DrawCube({ 0, 0, 0 }, 1, 1, 1, GRAY); + else + DrawCube({ 0, 0, 0 }, 1, 1, 1, color); + + DrawCubeWires({ 0, 0, 0 }, 1, 1, 1, BLACK); + + rlPopMatrix(); +} + +Vec3 gamecube::GetPosition() const { return position; } +float gamecube::GetRotationY() const { return rotation; } diff --git a/src/gamematrix.cpp b/src/gamematrix.cpp index 3971e61..e8eb7a8 100644 --- a/src/gamematrix.cpp +++ b/src/gamematrix.cpp @@ -1,3 +1,4 @@ +// // Created by bakee on 03.11.2025. // #include "gamematrix.h" @@ -55,16 +56,16 @@ namespace Matrix3D switch (axis) { case 'x': - result[1][1] = c; result[1][2] = -s; - result[2][1] = s; result[2][2] = c; + result[1][1] = c; result[1][2] = -s; + result[2][1] = s; result[2][2] = c; break; case 'y': - result[0][0] = c; result[0][2] = s; + result[0][0] = c; result[0][2] = s; result[2][0] = -s; result[2][2] = c; break; case 'z': - result[0][0] = c; result[0][1] = -s; - result[1][0] = s; result[1][1] = c; + result[0][0] = c; result[0][1] = -s; + result[1][0] = s; result[1][1] = c; break; default: break; @@ -79,7 +80,7 @@ namespace Matrix3D Vec3 operator*(const Mat4& m, const Vec3& v) { - Vec4 v_hom = {v[0], v[1], v[2], 1.0}; + Vec4 v_hom = { v[0], v[1], v[2], 1.0 }; Vec4 res_hom = {}; for (int i = 0; i < 4; ++i) @@ -90,6 +91,6 @@ namespace Matrix3D } } - return {res_hom[0], res_hom[1], res_hom[2]}; + return { res_hom[0], res_hom[1], res_hom[2] }; } }