67 lines
1.7 KiB
C++
67 lines
1.7 KiB
C++
#include "gamecube.h"
|
|
|
|
gamecube::gamecube(const Vec3 &pos, Color col)
|
|
: position(pos), color(col) {}
|
|
|
|
void gamecube::Update(float flipSpeed)
|
|
{
|
|
if (flippingForward)
|
|
{
|
|
rotation += flipSpeed;
|
|
if (rotation >= 180.0f)
|
|
{
|
|
rotation = 180.0f;
|
|
flippingForward = false;
|
|
flipped = true;
|
|
}
|
|
}
|
|
else if (flippingBackward)
|
|
{
|
|
rotation -= flipSpeed;
|
|
if (rotation <= 0.0f)
|
|
{
|
|
rotation = 0.0f;
|
|
flippingBackward = false;
|
|
flipped = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
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();
|
|
|
|
// 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)
|
|
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; }
|