Setting Up Box3D and Raylib in CLion with CMake and MinGW Настройка Box3D и Raylib в CLion с использованием CMake и MinGW

Setting up tools using these guides: Установите инструменты по инструкциям:

Create a C or C++ project in CLion Создайте C или C++ проект в CLion

Click a new project button

You can select a Locaton (1) and a type of project (2) - C or C++: Вы можете выбрать расположение проекта - Locaton (1) и тип проекта (2) - C или C++:

Create a project

Let's select a C project and click the Create button: Давайте выберем проект на C и нажмем кнопку Create:

C-project

You can click the Run (1) or Debug (2) button to test the project launch and ensure that everything is working: Вы можете нажать кнопку Run (1) или Debug (2), чтобы протестировать запуск проекта и убедиться, что всё работает:

Run and Debug buttons

Setting up Box3D and Raylib in the CMakeLists.txt file Настройка Box3D и Raylib в файле CMakeLists.txt

Replace the contents of the CMakeLists.txt file with the following code: Замените содержимое файла CMakeLists.txt следующим кодом:

set(CMAKE_BUILD_TYPE "Debug")

cmake_minimum_required(VERSION 3.21)
project(show-gravity-box3d-raylib-c)

add_executable(app)

target_include_directories(app PRIVATE C:/libs/raylib-6.0_win64_mingw-w64/include)
target_link_directories(app PRIVATE C:/libs/raylib-6.0_win64_mingw-w64/lib)

target_include_directories(app PRIVATE C:/libs/box3d-0.1.0-mingw/include)
target_link_directories(app PRIVATE C:/libs/box3d-0.1.0-mingw/lib)

target_sources(app
    PRIVATE
    main.c
)

target_link_libraries(app PRIVATE box3d raylib winmm)
target_link_options(app PRIVATE -static)

Replace the contents of the main.c file with the following code: Замените содержимое файла main.c следующим кодом:

#include <box3d/box3d.h>
#include <raylib.h>

// Global or persistent data
b3WorldId worldId;

void InitGame()
{
    InitWindow(800, 450, "Raylib and Box3D");
    SetTargetFPS(60);

    b3WorldDef worldDef = b3DefaultWorldDef();
    worldDef.gravity = (b3Vec3){ 0.0f, -9.8f, 0.0f };
    worldId = b3CreateWorld(&worldDef);
}

void UpdateGame()
{
    // Handle game logic updates here
}

void DrawGame()
{
    b3Vec3 g = b3World_GetGravity(worldId);

    BeginDrawing();
    ClearBackground(RAYWHITE);

    DrawText(TextFormat("Gravity is: (%0.1f, %0.1f, %0.1f)", g.x, g.y, g.z), 190, 200, 20, DARKGRAY);

    EndDrawing();
}

void ShutdownGame()
{
    b3DestroyWorld(worldId);
    CloseWindow();
}

int main()
{
    InitGame();

    while (!WindowShouldClose())
    {
        UpdateGame();
        DrawGame();
    }

    ShutdownGame();

    return 0;
}

When you run the example above, you will see the following result: Когда вы запустите пример выше, вы увидите следующий результат:

Result

Support My Work Поддержать проект

If these tutorials helped you, consider buying me a coffee! Если эти туториалы вам помогли, вы можете поддержать автора.

Sberbank (Russia only) Сбербанк (только для РФ)

Sberbank SBP QR Code

Direct transfer via phone number (Russia only) Перевод по номеру телефона (только для РФ)

+7 (917) 212-29-59

USDT TRC20

USDT TRC20 QR Code

Support via Cryptocurrency Поддержка криптовалютой

TMtY1YifNf6FKvgeFmqKGQR4NStKr3csGp