{"id":13732007,"url":"https://github.com/nlguillemot/flythrough_camera","last_synced_at":"2025-05-08T06:31:06.390Z","repository":{"id":147131735,"uuid":"55417906","full_name":"nlguillemot/flythrough_camera","owner":"nlguillemot","description":"Single-header single-function C/C++ immediate-mode camera for your graphics demos","archived":false,"fork":false,"pushed_at":"2016-08-27T14:34:01.000Z","size":13,"stargazers_count":116,"open_issues_count":0,"forks_count":8,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-08-04T02:10:42.291Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nlguillemot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2016-04-04T14:27:54.000Z","updated_at":"2024-07-31T17:06:28.000Z","dependencies_parsed_at":"2023-05-15T06:00:44.321Z","dependency_job_id":null,"html_url":"https://github.com/nlguillemot/flythrough_camera","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlguillemot%2Fflythrough_camera","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlguillemot%2Fflythrough_camera/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlguillemot%2Fflythrough_camera/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlguillemot%2Fflythrough_camera/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nlguillemot","download_url":"https://codeload.github.com/nlguillemot/flythrough_camera/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224707586,"owners_count":17356361,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T02:01:43.608Z","updated_at":"2024-11-14T23:30:46.841Z","avatar_url":"https://github.com/nlguillemot.png","language":"Objective-C","funding_links":[],"categories":["Graphics"],"sub_categories":[],"readme":"# flythrough_camera\n\n![demonstration](https://j.gifs.com/gJMrk9.gif)\n\nSingle-header single-function C/C++ immediate-mode camera for your graphics demos\n\nJust call `flythrough_camera_update` once per frame.\n\n# Simple Example\n\nBelow is a fully-functional example program that works under command prompt.\n\nCreate a new Visual Studio project, drop this file in it, and it should just work.\n\n```\n#define FLYTHROUGH_CAMERA_IMPLEMENTATION\n#include \"flythrough_camera.h\"\n\n#include \u003cWindows.h\u003e\n#include \u003cstdio.h\u003e\n\nint main()\n{\n    printf(\"flythrough_camera test:\\n\");\n    printf(\"hold right click, then move the mouse and press WASD/space/left ctrl\\n\");\n\n    float pos[3] = { 0.0f, 0.0f, 0.0f };\n    float look[3] = { 0.0f, 0.0f, 1.0f };\n    const float up[3] = { 0.0f, 1.0f, 0.0f };\n\n    LARGE_INTEGER then, now, freq;\n    QueryPerformanceFrequency(\u0026freq);\n    QueryPerformanceCounter(\u0026then);\n\n    POINT oldcursor;\n    GetCursorPos(\u0026oldcursor);\n\n    while (!GetAsyncKeyState(VK_ESCAPE))\n    {\n        QueryPerformanceCounter(\u0026now);\n        float delta_time_sec = (float)(now.QuadPart - then.QuadPart) / freq.QuadPart;\n\n        POINT cursor;\n        GetCursorPos(\u0026cursor);\n\n        // only move and rotate camera when right mouse button is pressed\n        float activated = GetAsyncKeyState(VK_RBUTTON) ? 1.0f : 0.0f;\n\n        float view[16];\n        flythrough_camera_update(\n            pos, look, up, view,\n            delta_time_sec,\n            100.0f * (GetAsyncKeyState(VK_LSHIFT) ? 2.0f : 1.0f) * activated,\n            0.5f * activated,\n            80.0f,\n            cursor.x - oldcursor.x, cursor.y - oldcursor.y,\n            GetAsyncKeyState('W'), GetAsyncKeyState('A'), GetAsyncKeyState('S'), GetAsyncKeyState('D'),\n            GetAsyncKeyState(VK_SPACE), GetAsyncKeyState(VK_LCONTROL),\n            FLYTHROUGH_CAMERA_LEFT_HANDED_BIT);\n\n        if (activated)\n        {\n            printf(\"\\n\");\n            printf(\"pos: %f, %f, %f\\n\", pos[0], pos[1], pos[2]);\n            printf(\"look: %f, %f, %f\\n\", look[0], look[1], look[2]);\n            printf(\"view: %f %f %f %f\\n\"\n                   \"      %f %f %f %f\\n\"\n                   \"      %f %f %f %f\\n\"\n                   \"      %f %f %f %f\\n\",\n                 view[0],  view[1],  view[2],  view[3],\n                 view[4],  view[5],  view[6],  view[7],\n                 view[8],  view[9], view[10], view[11],\n                view[12], view[13], view[14], view[15]);\n            \n            Sleep(100);\n        }\n\n        then = now;\n        oldcursor = cursor;\n    }\n\n    return 0;\n}\n```\n\n# OpenGL Example\n\n![openglexample](https://j.gifs.com/gJMA3D.gif)\n\nBelow is a fully-functional example program that works using OpenGL.\n\nCreate a new Visual Studio project, drop this file in it, and it should just work.\n\n```\n#define FLYTHROUGH_CAMERA_IMPLEMENTATION\n#include \"flythrough_camera.h\"\n\n#include \u003cWindows.h\u003e\n#include \u003cGL/gl.h\u003e\n#include \u003cGL/glu.h\u003e\n#include \u003cstdio.h\u003e\n\n#pragma comment(lib, \"OpenGL32.lib\")\n#pragma comment(lib, \"glu32.lib\")\n\nLRESULT CALLBACK MyWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)\n{\n    switch (message)\n    {\n    case WM_CLOSE:\n        ExitProcess(0);\n    default:\n        return DefWindowProc(hWnd, message, wParam, lParam);\n    }\n}\n\nint CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)\n{\n    printf(\"flythrough_camera test:\\n\");\n    printf(\"hold right click, then move the mouse and press WASD/space/left ctrl\\n\");\n    \n    WNDCLASSEX wc;\n    ZeroMemory(\u0026wc, sizeof(wc));\n    wc.cbSize = sizeof(wc);\n    wc.style = CS_OWNDC;\n    wc.lpfnWndProc = MyWndProc;\n    wc.hInstance = hInstance;\n    wc.hCursor = LoadCursor(NULL, IDC_ARROW);\n    wc.hbrBackground = (HBRUSH)COLOR_BACKGROUND;\n    wc.lpszClassName = TEXT(\"WindowClass\");\n    RegisterClassEx(\u0026wc);\n\n    RECT wr = { 0, 0, 640, 480 };\n    AdjustWindowRect(\u0026wr, 0, FALSE);\n    HWND hWnd = CreateWindowEx(\n        0, TEXT(\"WindowClass\"),\n        TEXT(\"BasicGL\"),\n        WS_OVERLAPPEDWINDOW,\n        0, 0, wr.right - wr.left, wr.bottom - wr.top,\n        0, 0, hInstance, 0);\n\n    PIXELFORMATDESCRIPTOR pfd;\n    ZeroMemory(\u0026pfd, sizeof(pfd));\n    pfd.nSize = sizeof(pfd);\n    pfd.nVersion = 1;\n    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;\n    pfd.iPixelType = PFD_TYPE_RGBA;\n    pfd.cColorBits = 32;\n    pfd.cDepthBits = 24;\n    pfd.cStencilBits = 8;\n    pfd.iLayerType = PFD_MAIN_PLANE;\n\n    HDC hDC = GetDC(hWnd);\n\n    int chosenPixelFormat = ChoosePixelFormat(hDC, \u0026pfd);\n    SetPixelFormat(hDC, chosenPixelFormat, \u0026pfd);\n\n    HGLRC hGLRC = wglCreateContext(hDC);\n    wglMakeCurrent(hDC, hGLRC);\n\n    ShowWindow(hWnd, SW_SHOWNORMAL);\n\n    float pos[3] = { 0.0f, 0.0f, 0.0f };\n    float look[3] = { 0.0f, 0.0f, 1.0f };\n    const float up[3] = { 0.0f, 1.0f, 0.0f };\n\n    LARGE_INTEGER then, now, freq;\n    QueryPerformanceFrequency(\u0026freq);\n    QueryPerformanceCounter(\u0026then);\n\n    POINT oldcursor;\n    GetCursorPos(\u0026oldcursor);\n\n    while (!GetAsyncKeyState(VK_ESCAPE))\n    {\n        MSG msg;\n        while (PeekMessage(\u0026msg, NULL, 0, 0, PM_REMOVE))\n        {\n            TranslateMessage(\u0026msg);\n            DispatchMessage(\u0026msg);\n        }\n\n        QueryPerformanceCounter(\u0026now);\n        float delta_time_sec = (float)(now.QuadPart - then.QuadPart) / freq.QuadPart;\n\n        POINT cursor;\n        GetCursorPos(\u0026cursor);\n\n        // only move and rotate camera when right mouse button is pressed\n        float activated = GetAsyncKeyState(VK_RBUTTON) ? 1.0f : 0.0f;\n\n        float view[16];\n        flythrough_camera_update(\n            pos, look, up, view,\n            delta_time_sec,\n            10.0f * (GetAsyncKeyState(VK_LSHIFT) ? 2.0f : 1.0f) * activated,\n            0.5f * activated,\n            80.0f,\n            cursor.x - oldcursor.x, cursor.y - oldcursor.y,\n            GetAsyncKeyState('W'), GetAsyncKeyState('A'), GetAsyncKeyState('S'), GetAsyncKeyState('D'),\n            GetAsyncKeyState(VK_SPACE), GetAsyncKeyState(VK_LCONTROL),\n            0);\n\n        if (activated)\n        {\n            printf(\"\\n\");\n            printf(\"pos: %f, %f, %f\\n\", pos[0], pos[1], pos[2]);\n            printf(\"look: %f, %f, %f\\n\", look[0], look[1], look[2]);\n            printf(\"view: %f %f %f %f\\n\"\n                   \"      %f %f %f %f\\n\"\n                   \"      %f %f %f %f\\n\"\n                   \"      %f %f %f %f\\n\",\n                 view[0],  view[1],  view[2],  view[3],\n                 view[4],  view[5],  view[6],  view[7],\n                 view[8],  view[9], view[10], view[11],\n                view[12], view[13], view[14], view[15]);\n        }\n\n        glClear(GL_COLOR_BUFFER_BIT);\n\n        glMatrixMode(GL_PROJECTION);\n        glLoadIdentity();\n        gluPerspective(70.0, (double)(wr.right - wr.left) / (wr.bottom - wr.top), 0.001, 100.0);\n\n        glMatrixMode(GL_MODELVIEW);\n        glLoadMatrixf(view);\n\n        glBegin(GL_TRIANGLES);\n        glColor3ub(255, 0, 0);\n        glVertex3f(-1.0f, -1.0f, 10.0f);\n        glColor3ub(0, 255, 0);\n        glVertex3f(1.0f, -1.0f, 10.0f);\n        glColor3ub(0, 0, 255);\n        glVertex3f(0.0f, 1.0f, 10.0f);\n        glEnd();\n\n        SwapBuffers(hDC);\n\n        then = now;\n        oldcursor = cursor;\n    }\n\n    return 0;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnlguillemot%2Fflythrough_camera","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnlguillemot%2Fflythrough_camera","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnlguillemot%2Fflythrough_camera/lists"}