Skip to content

Instantly share code, notes, and snippets.

View 8Observer8's full-sized avatar

Ivan 8Observer8

View GitHub Profile
@8Observer8
8Observer8 / .clang-format
Last active March 31, 2025 18:41
.clang-format WebKit
---
Language: Cpp
# BasedOnStyle: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignArrayOfStructures: None
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
@8Observer8
8Observer8 / hello-box2d-v2-cpp.cpp
Created February 8, 2025 20:30
Print gravity with Box2D 2.4.2
#include <box2d/box2d.h>
#include <iostream>
int main()
{
b2Vec2 gravity(0.f, -9.8f);
b2World* world = new b2World(gravity);
float gx = world->GetGravity().x;
float gy = world->GetGravity().y;
std::cout << "gravity = (" << gx << ", " << gy << ")" << std::endl;
@8Observer8
8Observer8 / debug_drawer.py
Last active December 2, 2024 11:43
PyBox2D collision detection using Pygame
import math
import pygame
from Box2D import b2Draw
class DebugDrawer(b2Draw):
def __init__(self, window, pixelsPerMeter, thickness=3):
super().__init__()
@8Observer8
8Observer8 / gist:fa980059a1bc581c6195438e4d327438
Created November 29, 2024 23:35
Errors for building Chipmunk2D with Emscripten, CMake, and MinGW
E:\libs\Chipmunk2D-Chipmunk-7.0.3>emcmake cmake -G "MinGW Makefiles" -S . -B dist -DCMAKE_INSTALL_PREFIX=E:/libs/chipmunk-7.0.3-prefix/web
configure: cmake -G "MinGW Makefiles" -S . -B dist -DCMAKE_INSTALL_PREFIX=E:/libs/chipmunk-7.0.3-prefix/web -DCMAKE_TOOLCHAIN_FILE=C:\emsdk\upstream\emscripten\cmake\Modules\Platform\Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=C:/emsdk/node/20.18.0_64bit/bin/node.exe
Configuring Chipmunk2D version 7.0.3
CMake Warning (dev) at src/CMakeLists.txt:15 (add_library):
ADD_LIBRARY called with SHARED option but the target platform does not
support dynamic linking. Building a STATIC library instead. This may lead
to problems.
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring done (4.4s)
@8Observer8
8Observer8 / main.c
Created November 23, 2024 12:52
Play sound effect my mouse click using SDL3_mixer and C
/*
* This example code $WHAT_IT_DOES.
*
* This code is public domain. Feel free to use it for any purpose!
*/
#define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <SDL3_mixer/SDL_mixer.h>
@8Observer8
8Observer8 / main.c
Created November 19, 2024 13:30
A problem with float numbers using Box2D v3.1 in C and SDL3
#define SDL_MAIN_USE_CALLBACKS 1 // Use callbacks instead of main()
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <box2d/box2d.h>
#include <math.h>
static SDL_Window *window = NULL;
static SDL_Renderer *renderer = NULL;
b2WorldId worldId; // Physical world identifier
@8Observer8
8Observer8 / log.txt
Created November 15, 2024 14:27
Log file of building Qt Creator 14.0.2 for the message: https://forum.qt.io/post/814789
E:\Temp\qt-creator-14.0.2\build>cmake --build . -j4
[ 0%] [ 0%] Automatic MOC and UIC for target QtCreatorPchGuiAutomatic MOC and UIC for target 3rd_cplusplus
[ 0%] Automatic MOC and UIC for target QtCreatorPchConsole[ 0%]
Copy data/syntax/ into build directory
[ 0%] Built target QtCreatorPchGui_autogen
[ 0%] Built target QtCreatorPchConsole_autogen
[ 0%] Built target copy_generic_highligher_to_builddir
[ 0%] Built target 3rd_cplusplus_autogen
[ 0%] Automatic MOC and UIC for target libvterm
@8Observer8
8Observer8 / debug_drawer.cpp
Created November 13, 2024 19:32
The debug drawer for Bullet Physics using the line drawer
#include "debug_drawer.h"
DebugDrawer::DebugDrawer(GLuint program, btDynamicsWorld *world,
const glm::mat4 &projViewMatrix, float thickness)
: m_world(world)
, m_thickness(thickness)
{
m_lineDrawer = new LineDrawer(program, projViewMatrix);
}
@8Observer8
8Observer8 / line_drawer.cpp
Created November 13, 2024 01:19
Line drawer in 3D to draw Bullet Physics colliders and rays using SDL3 and OpenGL for Desktop and WebAssembly
#include <cmath>
#include "line_drawer.h"
#include "math_helper.h"
#include <iostream>
LineDrawer::LineDrawer(GLuint program, const glm::mat4 &projViewMatrix)
: m_program(program)
, m_projViewMatrix(projViewMatrix)
@8Observer8
8Observer8 / CMakeLists.txt
Last active October 10, 2024 10:24
Set a background color using OpenGL, SDL3, and C++
# mkdir dist\win
# cmake -G "MinGW Makefiles" -S . -B dist/win -DSDL3_DIR=E:/libs/sdl3-desktop-prefix/lib/cmake/SDL3
# cmake -G "MinGW Makefiles" -S . -B dist/win -DSDL3_DIR=E:/libs/sdl3-libs/SDL3-devel-3.1.3-mingw/SDL3-3.1.3/x86_64-w64-mingw32/lib/cmake/SDL3
# cd dist/win
# mingw32-make
# app
cmake_minimum_required(VERSION 3.20)
project(background_color_opengl_sdl3_cpp)