forge-camera-and-input
Set up a first-person camera with quaternion orientation, keyboard/mouse input, and delta time. Use when someone needs to fly through a 3D scene, handle WASD…
от Nebulavenus★ 51 звезда на GitHub
Установить forge-camera-and-input в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Camera & Input — First-Person Camera, Keyboard/Mouse, Delta Time
This skill teaches how to add interactive camera controls to a 3D scene.
It builds on the depth-and-3d skill (MVP pipeline, depth testing) and
uses quaternion math from common/math/forge_math.h.
When to use
- Adding a first-person camera to a 3D scene
- Handling keyboard input for smooth movement (WASD)
- Adding mouse look with relative mouse mode
- Making movement frame-rate independent with delta time
- Drawing multiple objects with different model transforms
- Transitioning from a fixed camera (
mat4_look_at) to a player-controlled one
Key API calls (ordered)
SDL_SetWindowRelativeMouseMode— capture mouse for FPS-style lookSDL_GetKeyboardState— poll which keys are currently heldSDL_EVENT_MOUSE_MOTION— read relative mouse deltas (xrel, yrel)quat_from_euler— convert yaw+pitch to quaternion orientationquat_forward/quat_right— extract movement directionsmat4_view_from_quat— build view matrix from position + quaternionSDL_PushGPUVertexUniformData— push per-object MVP matrixSDL_DrawGPUIndexedPrimitives— draw each object (one call per object)
Code template
Camera state
#include "math/forge_math.h"
typedef struct app_state {
/* ... GPU resources from depth-and-3d skill ... */
/* Camera */
vec3 cam_position; /* world-space position */
float cam_yaw; /* radians, rotation around Y */
float cam_pitch; /* radians, rotation around X */
/* Timing */
Uint64 last_ticks; /* previous frame timestamp (ms) */
/* Input */
bool mouse_captured;
} app_state;
Initialize camera
/* In SDL_AppInit: */
state->cam_position = vec3_create(0.0f, 1.6f, 6.0f);
state->cam_yaw = 0.0f;
state->cam_pitch = 0.0f;
state->last_ticks = SDL_GetTicks();
/* Capture mouse for FPS-style look */
if (!SDL_SetWindowRelativeMouseMode(window, true)) {
SDL_Log("SDL_SetWindowRelativeMouseMode failed: %s", SDL_GetError());
}
state->mouse_captured = true;
Mouse look (in SDL_AppEvent)
/* Escape: release mouse first, quit on second press */
if (event->type == SDL_EVENT_KEY_DOWN && event->key.key == SDLK_ESCAPE) {
if (state->mouse_captured) {
SDL_SetWindowRelativeMouseMode(state->window, false);
state->mouse_captured = false;
} else {
return SDL_APP_SUCCESS;
}
}
/* Click to recapture */
if (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN && !state->mouse_captured) {
SDL_SetWindowRelativeMouseMode(state->window, true);
state->mouse_captured = true;
}
/* Mouse motion -> yaw/pitch */
if (event->type == SDL_EVENT_MOUSE_MOTION && state->mouse_captured) {
#define MOUSE_SENSITIVITY 0.002f
state->cam_yaw -= event->motion.xrel * MOUSE_SENSITIVITY;
state->cam_pitch -= event->motion.yrel * MOUSE_SENSITIVITY;
/* Clamp pitch to avoid gimbal lock (see Math Lesson 08) */
float max_pitch = 89.0f * FORGE_DEG2RAD;
if (state->cam_pitch > max_pitch) state->cam_pitch = max_pitch;
if (state->cam_pitch < -max_pitch) state->cam_pitch = -max_pitch;
}
Delta time and keyboard movement (in SDL_AppIterate)
/* Delta time — frame-rate independent movement */
Uint64 now_ms = SDL_GetTicks();
float dt = (float)(now_ms - state->last_ticks) / 1000.0f;
state->last_ticks = now_ms;
if (dt > 0.1f) dt = 0.1f; /* clamp to prevent teleportation */
/* Build orientation quaternion from euler angles */
quat cam_orientation = quat_from_euler(
state->cam_yaw, state->cam_pitch, 0.0f);
/* Extract movement directions from quaternion */
vec3 forward = quat_forward(cam_orientation);
vec3 right = quat_right(cam_orientation);
/* Poll keyboard for continuous movement */
#define MOVE_SPEED 3.0f
const bool *keys = SDL_GetKeyboardState(NULL);
if (keys[SDL_SCANCODE_W] || keys[SDL_SCANCODE_UP]) {
state->cam_position = vec3_add(state->cam_position,
vec3_scale(forward, MOVE_SPEED * dt));
}
if (keys[SDL_SCANCODE_S] || keys[SDL_SCANCODE_DOWN]) {
state->cam_position = vec3_add(state->cam_position,
vec3_scale(forward, -MOVE_SPEED * dt));
}
if (keys[SDL_SCANCODE_D] || keys[SDL_SCANCODE_RIGHT]) {
state->cam_position = vec3_add(state->cam_position,
vec3_scale(right, MOVE_SPEED * dt));
}
if (keys[SDL_SCANCODE_A] || keys[SDL_SCANCODE_LEFT]) {
state->cam_position = vec3_add(state->cam_position,
vec3_scale(right, -MOVE_SPEED * dt));
}
if (keys[SDL_SCANCODE_SPACE]) {
state->cam_position.y += MOVE_SPEED * dt;
}
if (keys[SDL_SCANCODE_LSHIFT]) {
state->cam_position.y -= MOVE_SPEED * dt;
}
View matrix (replaces mat4_look_at)
/* Build view matrix from camera position + quaternion orientation.
* This replaces the fixed mat4_look_at from the depth-and-3d skill. */
mat4 view = mat4_view_from_quat(state->cam_position, cam_orientation);
float aspect = (float)window_w / (float)window_h;
mat4 proj = mat4_perspective(60.0f * FO
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл forge-camera-and-input?
Set up a first-person camera with quaternion orientation, keyboard/mouse input, and delta time. Use when someone needs to fly through a 3D scene, handle WASD movement, mouse look, or frame-rate-independent motion in SDL3 GPU.
Как установить скилл forge-camera-and-input?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл forge-camera-and-input запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…