|
2 | 2 | //============================================================================= |
3 | 3 | // map_colliders.h |
4 | 4 | // |
5 | | -// Shared map collider definitions. |
| 5 | +// Shared map data definitions. |
6 | 6 | // This file is used by BOTH client and server — keep in sync! |
7 | 7 | // No DirectXMath dependency — pure C structs. |
| 8 | +// |
| 9 | +// MAP_GRID[][] defines the obstacle layout (1=block, 0=empty). |
| 10 | +// MAP_COLLIDERS[] defines merged AABBs for physics/hitscan. |
| 11 | +// The client generates individual cube draw calls from the grid; |
| 12 | +// the server only reads MAP_COLLIDERS[]. |
8 | 13 | //============================================================================= |
9 | 14 |
|
10 | | -// Object categories |
11 | | -enum MapCategory |
| 15 | +//----------------------------------------------------------------------------- |
| 16 | +// Grid-based map layout |
| 17 | +//----------------------------------------------------------------------------- |
| 18 | +static const int MAP_GRID_ROWS = 20; |
| 19 | +static const int MAP_GRID_COLS = 20; |
| 20 | +static const int MAP_BLOCK_HEIGHT = 4; // cubes stacked per obstacle cell |
| 21 | +static const float MAP_OFFSET_X = -10.0f; // world X offset (center the grid) |
| 22 | +static const float MAP_OFFSET_Z = -10.0f; // world Z offset (center the grid) |
| 23 | + |
| 24 | +static const int MAP_GRID[MAP_GRID_ROWS][MAP_GRID_COLS] = |
12 | 25 | { |
13 | | - MAP_GROUND = 0, // Ground plane — rendered as MeshField, has AABB |
14 | | - MAP_CUBE = 1, // Cube block — rendered with Cube_Draw, AABB from position |
15 | | - MAP_WALL = 2, // Invisible wall — AABB only, no rendering |
| 26 | + {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, |
| 27 | + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
| 28 | + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
| 29 | + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
| 30 | + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
| 31 | + {1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1}, |
| 32 | + {1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1}, |
| 33 | + {1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1}, |
| 34 | + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
| 35 | + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
| 36 | + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
| 37 | + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
| 38 | + {1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1}, |
| 39 | + {1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1}, |
| 40 | + {1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,1}, |
| 41 | + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
| 42 | + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
| 43 | + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
| 44 | + {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
| 45 | + {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, |
16 | 46 | }; |
17 | 47 |
|
18 | | -// Collider definition |
19 | | -// For MAP_CUBE: AABB is auto-computed from position (±0.5 unit cube) |
20 | | -// For MAP_GROUND / MAP_WALL: AABB is specified explicitly via min/max |
| 48 | +//----------------------------------------------------------------------------- |
| 49 | +// Collider definition (physics / hitscan) |
| 50 | +//----------------------------------------------------------------------------- |
21 | 51 | struct MapColliderDef |
22 | 52 | { |
23 | | - int category; |
24 | | - float posX, posY, posZ; // position (used for cube rendering & AABB center) |
25 | | - float minX, minY, minZ; // AABB min (explicit, ignored for MAP_CUBE) |
26 | | - float maxX, maxY, maxZ; // AABB max (explicit, ignored for MAP_CUBE) |
27 | | - bool isGround; // true = player can land on this surface |
| 53 | + float minX, minY, minZ; |
| 54 | + float maxX, maxY, maxZ; |
| 55 | + bool isGround; |
28 | 56 | }; |
29 | 57 |
|
30 | 58 | // ============================================================================ |
31 | | -// MAP DATA — Add new colliders here! |
| 59 | +// COLLIDERS — Manually merged AABBs for physics/hitscan. |
| 60 | +// |
| 61 | +// Grid cell (row, col) maps to world: |
| 62 | +// X = col + MAP_OFFSET_X, Z = row + MAP_OFFSET_Z |
| 63 | +// A group from (r1,c1)-(r2,c2) → AABB: |
| 64 | +// min = (c1-10, 0, r1-10) max = (c2+1-10, 4, r2+1-10) |
32 | 65 | // ============================================================================ |
33 | 66 | static const MapColliderDef MAP_COLLIDERS[] = |
34 | 67 | { |
35 | | - // === Ground === |
36 | | - // cat pos(x,y,z) AABB min AABB max ground |
37 | | - { MAP_GROUND, 0,0,0, -128.0f,-1.0f,-128.0f, 128.0f, 0.0f, 128.0f, true }, |
38 | | - |
39 | | - // === Cube Blocks (AABB auto = pos ± 0.5) === |
40 | | - // y=0.5 → AABB [0,1] (sits on ground) | y=1.5 → AABB [1,2] (second layer) |
41 | | - // cat pos(x,y,z) (min/max ignored for cubes) ground |
42 | | - { MAP_CUBE, 7.5f, 0.5f, 7.5f, 0,0,0, 0,0,0, true }, |
43 | | - { MAP_CUBE, 7.5f, 0.5f, 8.5f, 0,0,0, 0,0,0, true }, |
44 | | - { MAP_CUBE, 8.5f, 0.5f, 7.5f, 0,0,0, 0,0,0, true }, |
45 | | - { MAP_CUBE, 8.5f, 0.5f, 8.5f, 0,0,0, 0,0,0, true }, |
46 | | - { MAP_CUBE, 7.5f, 1.5f, 7.5f, 0,0,0, 0,0,0, true }, |
47 | | - { MAP_CUBE, 8.5f, 1.5f, 7.5f, 0,0,0, 0,0,0, true }, |
48 | | - |
49 | | - // === Invisible Walls (map boundary) === |
50 | | - // cat pos(unused) AABB min AABB max ground |
51 | | - // (Add map boundary walls here if needed) |
| 68 | + // AABB min AABB max ground |
| 69 | + |
| 70 | + // --- Ground plane --- |
| 71 | + { -128.0f,-1.0f,-128.0f, 128.0f, 0.0f, 128.0f, true }, |
| 72 | + |
| 73 | + // --- Border walls --- |
| 74 | + // Top wall: row 0, cols 0-19 |
| 75 | + { -10.0f, 0.0f,-10.0f, 10.0f, 4.0f, -9.0f, true }, |
| 76 | + // Bottom wall: row 19, cols 0-19 |
| 77 | + { -10.0f, 0.0f, 9.0f, 10.0f, 4.0f, 10.0f, true }, |
| 78 | + // Left wall: rows 1-18, col 0 |
| 79 | + { -10.0f, 0.0f, -9.0f, -9.0f, 4.0f, 9.0f, true }, |
| 80 | + // Right wall: rows 1-18, col 19 |
| 81 | + { 9.0f, 0.0f, -9.0f, 10.0f, 4.0f, 9.0f, true }, |
| 82 | + |
| 83 | + // --- Interior blocks (3x3 each, height 4) --- |
| 84 | + // Block A: rows 5-7, cols 5-7 |
| 85 | + { -5.0f, 0.0f, -5.0f, -2.0f, 4.0f, -2.0f, true }, |
| 86 | + // Block B: rows 5-7, cols 12-14 |
| 87 | + { 2.0f, 0.0f, -5.0f, 5.0f, 4.0f, -2.0f, true }, |
| 88 | + // Block C: rows 12-14, cols 5-7 |
| 89 | + { -5.0f, 0.0f, 2.0f, -2.0f, 4.0f, 5.0f, true }, |
| 90 | + // Block D: rows 12-14, cols 12-14 |
| 91 | + { 2.0f, 0.0f, 2.0f, 5.0f, 4.0f, 5.0f, true }, |
52 | 92 | }; |
53 | 93 |
|
54 | 94 | static const int MAP_COLLIDER_COUNT = sizeof(MAP_COLLIDERS) / sizeof(MAP_COLLIDERS[0]); |
0 commit comments