Compare commits
2 Commits
d9e5da49f2
...
979a7b6179
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
979a7b6179 | ||
|
|
d7e51c73f1 |
@ -1,39 +1,23 @@
|
||||
cmake_minimum_required(VERSION 3.28)
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
project(Prog3B)
|
||||
set(EXECUTABLE_NAME Prog3B)
|
||||
set(OS_NAME windows)
|
||||
|
||||
# Generate compile_commands.json
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# Set the default build type if not specified
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
|
||||
endif()
|
||||
include(FetchContent)
|
||||
|
||||
set(SRC_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/main.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/gamecube.cpp
|
||||
FetchContent_Declare(
|
||||
raylib
|
||||
GIT_REPOSITORY https://github.com/raysan5/raylib.git
|
||||
GIT_TAG 5.0
|
||||
)
|
||||
|
||||
set(INCLUDE_DIRS
|
||||
${CMAKE_CURRENT_LIST_DIR}/linux
|
||||
FetchContent_MakeAvailable(raylib)
|
||||
|
||||
add_executable(Prog3B
|
||||
main.cpp
|
||||
gamecube.cpp
|
||||
gamematrix.cpp
|
||||
)
|
||||
|
||||
add_executable(${EXECUTABLE_NAME} ${SRC_FILES})
|
||||
target_include_directories(${EXECUTABLE_NAME} PRIVATE ${INCLUDE_DIRS})
|
||||
target_link_libraries(${EXECUTABLE_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}/${OS_NAME}/libgamematrix.a
|
||||
${CMAKE_CURRENT_LIST_DIR}/${OS_NAME}/libraylib.a
|
||||
)
|
||||
if (WIN32)
|
||||
target_link_libraries(Prog3B PRIVATE winmm)
|
||||
endif()
|
||||
|
||||
# Checks if OSX and links appropriate frameworks (Only required on MacOS)
|
||||
if (APPLE)
|
||||
target_link_libraries(Prog3B "-framework IOKit")
|
||||
target_link_libraries(Prog3B "-framework Cocoa")
|
||||
target_link_libraries(Prog3B "-framework OpenGL")
|
||||
endif()
|
||||
target_include_directories(Prog3B PRIVATE .)
|
||||
target_link_libraries(Prog3B raylib)
|
||||
13
gamecube.cpp
13
gamecube.cpp
@ -27,8 +27,8 @@ void gamecube::Update(float flipSpeed)
|
||||
}
|
||||
}
|
||||
|
||||
void gamecube::FlipForward() { flippingForward = true; }
|
||||
void gamecube::FlipBackward() { flippingBackward = true; }
|
||||
void gamecube::FlipForward() { flippingForward = true; }
|
||||
void gamecube::FlipBackward() { flippingBackward = true; }
|
||||
|
||||
bool gamecube::IsFlipped() const { return flipped; }
|
||||
bool gamecube::IsMatched() const { return matched; }
|
||||
@ -38,18 +38,15 @@ void gamecube::Draw() const
|
||||
{
|
||||
rlPushMatrix();
|
||||
|
||||
// Matrizen für Rotation und Translation erzeugen
|
||||
auto matrix_a = gameMatrix::translate({ position.x, position.y, position.z});
|
||||
auto matrix_b = gameMatrix::rot3D(rotation, 'y');
|
||||
|
||||
// Matrizen multiplizieren (Translation * Rotation)
|
||||
auto model = gameMatrix::matmul(matrix_a, matrix_b);
|
||||
|
||||
// transform for raylib matrix
|
||||
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)
|
||||
@ -62,5 +59,5 @@ void gamecube::Draw() const
|
||||
rlPopMatrix();
|
||||
}
|
||||
|
||||
Vec3 gamecube::GetPosition() const { return position; }
|
||||
float gamecube::GetRotationY() const { return rotation; }
|
||||
Vec3 gamecube::GetPosition() const { return position; }
|
||||
float gamecube::GetRotationY() const { return rotation; }
|
||||
|
||||
15
gamecube.h
15
gamecube.h
@ -3,22 +3,24 @@
|
||||
#include "raylib.h"
|
||||
#include <rlgl.h>
|
||||
|
||||
struct Vec3
|
||||
{
|
||||
struct Vec3 {
|
||||
float x, y, z;
|
||||
};
|
||||
|
||||
class gamecube
|
||||
{
|
||||
class gamecube {
|
||||
public:
|
||||
gamecube(const Vec3 &pos, Color col);
|
||||
|
||||
void Update(float flipSpeed);
|
||||
void FlipForward();
|
||||
void FlipBackward();
|
||||
|
||||
bool IsFlipped() const;
|
||||
bool IsMatched() const;
|
||||
void SetMatched(bool m);
|
||||
|
||||
void Draw() const;
|
||||
|
||||
Vec3 GetPosition() const;
|
||||
float GetRotationY() const;
|
||||
Color GetColor() const { return color; }
|
||||
@ -26,9 +28,12 @@ public:
|
||||
private:
|
||||
Vec3 position;
|
||||
Color color;
|
||||
|
||||
bool flipped = false;
|
||||
bool matched = false;
|
||||
|
||||
bool flippingForward = false;
|
||||
bool flippingBackward = false;
|
||||
|
||||
float rotation = 0.0f;
|
||||
};
|
||||
};
|
||||
|
||||
43
gamematrix.cpp
Normal file
43
gamematrix.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include "gamematrix.h"
|
||||
|
||||
std::array<std::array<double,4>,4> gameMatrix::matmul(
|
||||
const std::array<std::array<double,4>,4>& A,
|
||||
const std::array<std::array<double,4>,4>& B)
|
||||
{
|
||||
std::array<std::array<double,4>,4> R = {};
|
||||
|
||||
for(int i=0;i<4;i++)
|
||||
for(int j=0;j<4;j++)
|
||||
for(int k=0;k<4;k++)
|
||||
R[i][j] += A[i][k] * B[k][j];
|
||||
|
||||
return R;
|
||||
}
|
||||
|
||||
std::array<std::array<double,4>,4> gameMatrix::rot3D(double angle_deg, char axis)
|
||||
{
|
||||
double a = angle_deg * M_PI / 180.0;
|
||||
double c = cos(a);
|
||||
double s = sin(a);
|
||||
|
||||
std::array<std::array<double,4>,4> M = {0};
|
||||
|
||||
M[3][3] = 1;
|
||||
M[axis == 'x'][axis == 'y'] = 1; // init identity axis
|
||||
|
||||
if(axis == 'x') M = {{{1,0,0,0},{0,c,-s,0},{0,s,c,0},{0,0,0,1}}};
|
||||
if(axis == 'y') M = {{{c,0,s,0},{0,1,0,0},{-s,0,c,0},{0,0,0,1}}};
|
||||
if(axis == 'z') M = {{{c,-s,0,0},{s,c,0,0},{0,0,1,0},{0,0,0,1}}};
|
||||
|
||||
return M;
|
||||
}
|
||||
|
||||
std::array<std::array<double,4>,4> gameMatrix::translate(const std::array<double,3>& p)
|
||||
{
|
||||
return {{
|
||||
{1,0,0,p[0]},
|
||||
{0,1,0,p[1]},
|
||||
{0,0,1,p[2]},
|
||||
{0,0,0,1}
|
||||
}};
|
||||
}
|
||||
22
tests.cpp
Normal file
22
tests.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include <iostream>
|
||||
#include "gamematrix.h"
|
||||
using namespace Matrix3D;
|
||||
|
||||
void test_rotation_z() {
|
||||
Vec3 v{1,0,0};
|
||||
auto R = rot3D(90,'z');
|
||||
Vec3 res = apply(R,v);
|
||||
std::cout << "Rotate Z 90° -> (" << res.x << "," << res.y << "," << res.z << ")\n";
|
||||
}
|
||||
|
||||
void test_translate() {
|
||||
Vec3 v{0,0,0};
|
||||
auto T = translate({1,2,3});
|
||||
Vec3 res = apply(T,v);
|
||||
std::cout << "Translate -> (" << res.x << "," << res.y << "," << res.z << ")\n";
|
||||
}
|
||||
|
||||
int main() {
|
||||
test_rotation_z();
|
||||
test_translate();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user