8#ifndef DTTR_UTIL_COLLISION_H
9#define DTTR_UTIL_COLLISION_H
16#ifndef DTTR_SDK_ENABLE_UNSTABLE
17#error "Define DTTR_SDK_ENABLE_UNSTABLE before including dttr_util_collision.h"
27#define DTTR_UTIL_COLLISION_Q12_ONE 4096
32#define DTTR_UTIL_COLLISION_VERTEX_WORLD_SCALE 64
36#define DTTR_UTIL_COLLISION_MAX_VERTICES 4096u
37#define DTTR_UTIL_COLLISION_MAX_POLYGONS 8192u
41#define DTTR_UTIL_COLLISION_ADJ_FACE_MIN_SIZE 0x14u
45#define DTTR_UTIL_COLLISION_VERTEX_WALL_TAG_OFFSET 0x0bu
52 return (polygon->
flags & 0x1u) != 0u ? 3u : 4u;
67 if (!node || !vertex || !out_world) {
71 int32_t
x = (int32_t)vertex->
x;
72 int32_t
y = (int32_t)vertex->
y;
73 int32_t
z = (int32_t)vertex->
z;
74 if ((node->
flags & 0x22u) != 0u) {
79 x = (int32_t)(((int64_t)rx * m->
m00 + (int64_t)ry * m->
m01 + (int64_t)rz * m->
m02)
81 y = (int32_t)(((int64_t)rx * m->
m10 + (int64_t)ry * m->
m11 + (int64_t)rz * m->
m12)
83 z = (int32_t)(((int64_t)rx * m->
m20 + (int64_t)ry * m->
m21 + (int64_t)rz * m->
m22)
87 const int64_t wx = (int64_t)node->
origin.
x
89 const int64_t wy = (int64_t)node->
origin.
y
91 const int64_t wz = (int64_t)node->
origin.
z
93 if (wx < INT32_MIN || wx > INT32_MAX || wy < INT32_MIN || wy > INT32_MAX
94 || wz < INT32_MIN || wz > INT32_MAX) {
127 sizeof(node->
polygons[0]) * polygon_count
136 const uintptr_t polygon_addr = (uintptr_t)polygon;
137 const uintptr_t polygons_begin = (uintptr_t)node->
polygons;
138 const uintptr_t polygons_end = polygons_begin
139 +
sizeof(node->
polygons[0]) * polygon_count;
140 if (polygon_addr < polygons_begin || polygon_addr >= polygons_end) {
144 if ((polygon_addr - polygons_begin) %
sizeof(node->
polygons[0]) != 0u) {
149 for (uint32_t i = 0; i < 4u; ++i) {
168 int32_t *out_neighbor_edge
170 if (!node || !polygon || edge_index >= 4u || !polygon->
adj_face_ptr
178 const uint16_t *adj_edges = (
const uint16_t *)((
const uint8_t *)polygon->
adj_face_ptr
180 const uint16_t encoded = adj_edges[edge_index];
181 const uint32_t one_based_index = (uint32_t)encoded >> 2;
182 if (one_based_index == 0u || !node->
polygons
192 if (out_neighbor_edge) {
193 *out_neighbor_edge = (int32_t)(encoded & 0x3u);
207 if (edge_index >= 4u) {
212 const uint16_t i1 = polygon->
vertex_indices[(edge_index + 1u) & 3u];
245 if (!node || !polygon || !node->
vertices
247 || (polygon->
flags & 0x4000u) == 0u) {
253 && (((
const uint8_t *)polygon->
plane_data)[0] & 0x1u) != 0u) {
266 if (tag0 == 0u && tag1 == 0u) {
272 return neighbor ==
NULL || (neighbor->
flags & 0x4u) == 0u;
284 if (!node || !polygon || !out_world
302 const int64_t top0 = (int64_t)base0.
y + height_fp;
303 const int64_t top1 = (int64_t)base1.
y + height_fp;
304 if (top0 < INT32_MIN || top0 > INT32_MAX || top1 < INT32_MIN || top1 > INT32_MAX) {
308 out_world[0] = base0;
309 out_world[1] = base1;
DTTR_Graphics_COM_Direct3DDevice7 void DWORD flags DWORD void DWORD DWORD float z
DTTR_Graphics_COM_DirectDrawSurface7 DWORD x
DTTR_Graphics_COM_DirectDrawSurface7 DWORD DWORD y
DTTR_Graphics_COM_DirectDrawSurface7 DWORD flags void NULL
#define DTTR_UTIL_COLLISION_VERTEX_WORLD_SCALE
#define DTTR_UTIL_COLLISION_ADJ_FACE_MIN_SIZE
static bool DTTR_Util_CollisionEdgeIsWall(const DTTR_PCDOGS_T_Collision_Node *node, const DTTR_PCDOGS_T_Collision_Polygon *polygon, uint32_t edge_index)
#define DTTR_UTIL_COLLISION_Q12_ONE
Collision node transform matrices use this Q12 fixed-point unit.
static DTTR_PCDOGS_T_Collision_Polygon * DTTR_Util_CollisionAdjacentPolygon(const DTTR_PCDOGS_T_Collision_Node *node, const DTTR_PCDOGS_T_Collision_Polygon *polygon, uint32_t edge_index, int32_t *out_neighbor_edge)
static bool dttr_util_collision_edge_vertices(const DTTR_PCDOGS_T_Collision_Node *node, const DTTR_PCDOGS_T_Collision_Polygon *polygon, uint32_t edge_index, uint16_t *out_i0, uint16_t *out_i1)
static uint32_t DTTR_Util_CollisionPolygonEdgeCount(const DTTR_PCDOGS_T_Collision_Polygon *polygon)
static uint8_t dttr_util_collision_vertex_wall_tag(const DTTR_PCDOGS_T_Collision_Vertex *vertex)
static bool DTTR_Util_CollisionPolygonInNode(const DTTR_PCDOGS_T_Collision_Node *node, const DTTR_PCDOGS_T_Collision_Polygon *polygon)
#define DTTR_UTIL_COLLISION_MAX_POLYGONS
static bool DTTR_Util_CollisionVertexWorld(const DTTR_PCDOGS_T_Collision_Node *node, const DTTR_PCDOGS_T_Collision_Vertex *vertex, DTTR_PCDOGS_T_Math_Vec3I32 *out_world)
#define DTTR_UTIL_COLLISION_VERTEX_WALL_TAG_OFFSET
#define DTTR_UTIL_COLLISION_MAX_VERTICES
static bool DTTR_Util_CollisionWallEdgeQuad(const DTTR_PCDOGS_T_Collision_Node *node, const DTTR_PCDOGS_T_Collision_Polygon *polygon, uint32_t edge_index, int32_t height_fp, DTTR_PCDOGS_T_Math_Vec3I32 out_world[4])
static bool DTTR_Util_MemReadable(const void *ptr, size_t size)
DTTR_PCDOGS_T_Math_Matrix3x3I16 transform_matrix
DTTR_PCDOGS_T_Math_Vec3I32 origin
Offset 0x40.
DTTR_PCDOGS_T_Collision_Polygon * polygons
DTTR_PCDOGS_T_Collision_Vertex * vertices
uint16_t vertex_indices[4]
Offset 0x4.
DTTR_PCDOGS_T_Collision_Plane * plane_data
Offset 0x0.