game-vector-math-primitives
Apply vector math primitives for game rendering, collision, orientation, lighting, steering, and geometry predicates. Use when working with dot products, cross products, triple products, normals, projections, signed areas, signed volumes, facing checks, or vector normalization.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 1.6k
- Forks
- 491
01 前言 Front Matter
- name
- game-vector-math-primitives
- license
- MIT
- metadata
- { "tags": "game-dev,game-geometry,vectors,rendering,collision", "version": "0.1.0", "category": "Game Development", "displayName": "Game Vector Math Primitives" }
- description
- Apply vector math primitives for game rendering, collision, orientation, lighting, steering, and geometry predicates. Use when working with dot products, cross products, triple products, normals, projections, signed areas, signed volumes, facing checks, or vector normalization.
- compatibility
- Codex, Claude Code, and other Agent Skills-compatible clients.
03 SKILL.md 正文
Game Vector Math Primitives
Use this skill when game code depends on vector operations whose geometric meaning matters. Prefer clear primitives and named intent over opaque formula paste.
Primary source: Geometry for Programmers by Oleksandr Kaleniuk (https://www.manning.com/books/geometry-for-programmers), transformed and paraphrased, especially chapters 2 and 9.
Core Workflow
- Identify the geometric question: angle, projection, side, area, normal, volume, distance, facing, or interpolation.
- Choose the primitive that answers that question directly.
- Check the input assumptions: dimensionality, coordinate space, units, handedness, normalization, and zero-length vectors.
- Preserve sign when orientation or sidedness matters. Discard sign only when the caller truly needs magnitude.
- Name intermediate values by meaning:
normal,signed_area2,light_factor,plane_distance,facing,projection_t. - Add tests that exercise orientation, reversed winding, orthogonal vectors, parallel vectors, and zero-length inputs.
Primitive Guide
Dot Product
Use dot products for:
- Projection onto a direction.
- Angle/facing tests.
- Lambert-style lighting coefficients.
- Distance along a ray or segment.
- Checking orthogonality: dot equals zero under the numeric policy.
If both vectors are normalized, the dot product is the cosine of the angle between them. Clamp before inverse cosine if a display angle is needed.
Cross Product And 2D Cross Scalar
Use cross products for:
- Surface normals from two triangle edges.
- Signed 2D orientation tests.
- Twice the signed area of a 2D triangle.
- Detecting parallel vectors through near-zero magnitude.
- Building tangent frames with a known handedness.
For 2D, use the scalar a.x * b.y - a.y * b.x instead of constructing fake 3D
vectors unless the codebase already uses a 3D type.
Triple Product
Use the scalar triple product for:
- Signed volume.
- Point side relative to an oriented plane.
- Point-to-plane distance when divided by the plane normal length.
- Tetrahedron orientation and containment-style predicates.
Keep the sign when side matters. Take absolute value only for unsigned volume or distance.
Guardrails
- Never normalize before checking vector length.
- Distinguish a direction vector from a point vector in naming and APIs.
- Keep normals in the same space as the vectors they are compared with.
- Recompute or transform normals correctly after nonuniform scale.
- Decide whether clockwise or counterclockwise winding is canonical.
- Use squared length when comparing distances and no square root is needed.
- Avoid inverse trigonometric functions in hot paths unless a real angle is required. Dot thresholds are usually cheaper.
Common Mistakes
- Treating every vector as normalized because examples used unit vectors.
- Losing useful sign information by taking absolute values too early.
- Mixing coordinate spaces in one dot or cross operation.
- Using angle calculations where a dot-product threshold would be simpler.
- Flipping triangle winding without updating normals, culling, or orientation predicates.
04 同仓库更多 Skills
worktable-review-with-annotations
Create, inspect, reply to, update, or resolve situated Worktable annotations. Use when feedback belongs to a Doc section, block, text range, or HTML Doc, or when the user asks to address existing review feedback and coordinate a requested artifact edit.
worktable-find-and-synthesize-context
Find, assess, and synthesize context from Worktable Docs and Records. Use when the user asks what a workspace contains, wants workspace-backed research, needs current facts reconciled across artifacts, or requests a cited synthesis without changing workspace state.
worktable-create-or-update-docs
Create, edit, rename, or maintain narrative Worktable Docs. Use for plans, decisions, briefs, notes, research syntheses, and other durable prose when the user requests a new artifact or a safe update to an existing one.
worktable-create-or-manage-records
Organize repeated structured information as durable Worktable Records. Use for research datasets, inventories, directories, pipelines, trackers, and other collections whose items need identity, fields, filtering, links, validation, or individual updates.
worktable-create-or-manage-interactive-html
Create or improve durable visual and interactive artifacts in Worktable. Use for dashboards, trackers, calculators, mini apps, slide presentations, and other requests that benefit from a polished HTML Doc.
worktable-collaborate-threads
Read, answer, and hand off messages through durable Worktable threads with users or other authenticated participants. Use when the user asks to check addressed messages, reply to a participant, continue a thread, request another agent's help, wait briefly for a response, or watch for comments and messages sent to the agent.