Skip to content

Instantly share code, notes, and snippets.

@nothke
Created December 14, 2021 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nothke/a244bfd5bb43cd35abf3470b41c4f7d7 to your computer and use it in GitHub Desktop.
Save nothke/a244bfd5bb43cd35abf3470b41c4f7d7 to your computer and use it in GitHub Desktop.
//#include <iostream>
#include "raylib.h"
#include "rlgl.h"
#include "raymath.h"
Vector3 GetForwardFromMatrix(const Matrix m)
{
return { m.m0, m.m1, m.m2 };
}
Font font;
void ShowText(const char* text, const Vector2 pos = { 50, 50 })
{
DrawTextEx(font, text, pos, 20, 1, WHITE);
}
int main(int argc, char* argv[]) {
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
InitWindow(800, 600, "My first raylib game");
font = LoadFont("res/Inconsolata-SemiBold.ttf");
//rlglInit(800, 600);
Model model = LoadModel("res/testcube.gltf");
Camera3D camera;
camera.position = { 0.0f, 10.0f, 10.0f };
camera.target = { 0,0,0 };
camera.up = { 0,1,0 };
camera.fovy = 45.0f;
camera.projection = CAMERA_PERSPECTIVE; // Camera mode type
Vector3 position = { 0, 0, 0 };
Vector3 forward = GetForwardFromMatrix(model.transform);
TraceLog(TraceLogLevel::LOG_WARNING, "Something something!");
//
while (!WindowShouldClose())
{
float dt = GetFrameTime();
float spd = dt * 10;
if (IsKeyDown(KEY_W)) position.z += spd;
if (IsKeyDown(KEY_S)) position.z -= spd;
if (IsKeyDown(KEY_D)) position.x += spd;
if (IsKeyDown(KEY_A)) position.x -= spd;
//if (IsKeyPressed(KEY_ENTER))
//SetConfigFlags(100, 100);
float _time = static_cast<float>(GetTime());
//position = { 0, sinf(static_cast<float>(_time)), 0 };
Vector3 cameraUp = { 0, 4, 0 };
Vector3 target = Vector3Add(Vector3Add(position, Vector3Scale(forward, 3)), cameraUp);
camera.position = Vector3Lerp(camera.position, target, dt * 5);
camera.target = position;
BeginDrawing();
{
ClearBackground(RED);
BeginMode3D(camera);
{
DrawModel(model, position, 1.0f, WHITE);
DrawModel(model, { 1, 0, 1 }, 1.0f, WHITE);
//DrawLine3D({ 0,0,0 }, { 0, 1, 0 }, RED);
}
EndMode3D();
ShowText("Yo");
ShowText("Fuck, it works", { 190, 100 });
ShowText("Compiles so fast!!", { 190, 120 });
ShowText("This font is disgusting tho", { 190, 140 });
}
EndDrawing();
}
//rlglClose();
return 0;
//return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment