13#ifndef DTTR_UTIL_WORLDVIEW_H
14#define DTTR_UTIL_WORLDVIEW_H
21#ifndef DTTR_SDK_ENABLE_UNSTABLE
22#error "Define DTTR_SDK_ENABLE_UNSTABLE before including dttr_util_worldview.h"
32#define DTTR_UTIL_WORLDVIEW_FIXED_ONE 4096
36#define DTTR_UTIL_WORLDVIEW_MAX_POLYGON_POINTS 8u
61 uint64_t bit = (uint64_t)1 << 62;
68 if (value >= result + bit) {
69 value -= result + bit;
70 result = (result >> 1) + bit;
78 return (uint32_t)result;
126 const int64_t fx_raw = (int64_t)look_at.
x - eye.
x;
127 const int64_t fy_raw = (int64_t)look_at.
y - eye.
y;
128 const int64_t fz_raw = (int64_t)look_at.
z - eye.
z;
129 const uint64_t fx2 = (uint64_t)(fx_raw * fx_raw);
130 const uint64_t fy2 = (uint64_t)(fy_raw * fy_raw);
131 const uint64_t fz2 = (uint64_t)(fz_raw * fz_raw);
135 if (f_len == 0 || h_len == 0) {
154 .y = (int16_t)(((int32_t)forward.
z * right.
x - (int32_t)forward.
x * right.
z)
170 double focal_x = (double)focal;
171 double focal_y = (double)focal;
174 if (cam_ref_w >= 64 && cam_ref_w <= 4096) {
175 focal_x = (double)focal * (
double)
target->width / (double)cam_ref_w;
178 if (cam_ref_h >= 64 && cam_ref_h <= 4096) {
179 focal_y = (double)focal * (
double)
target->height / (double)cam_ref_h;
209 if (!view || !view->
valid || !world || !out) {
213 const int64_t dx = (int64_t)world->
x - view->
eye.
x;
214 const int64_t dy = (int64_t)world->
y - view->
eye.
y;
215 const int64_t dz = (int64_t)world->
z - view->
eye.
z;
219 out->
y = (int32_t)((dx * view->
up.
x + dy * view->
up.
y + dz * view->
up.
z)
236 if (!view || !view->
valid || !p || !out || p->
z <= 0) {
240 const double max_screen_coord = 1.0e9;
243 const double inv_z = 1.0 / depth;
244 const double sx = view->
center.
x + (double)p->
x * view->
focal.
x * inv_z;
245 const double sy = view->
center.
y + (double)p->
y * view->
focal.
y * inv_z;
246 if (sx < -max_screen_coord || sx > max_screen_coord || sy < -max_screen_coord
247 || sy > max_screen_coord) {
283 const int64_t dz = (int64_t)b->
z - a->
z;
288 const int64_t t_num = (int64_t)near_z - a->
z;
290 .x = (int32_t)(a->
x + (((int64_t)b->
x - a->
x) * t_num) / dz),
291 .y = (int32_t)(a->
y + (((int64_t)b->
y - a->
y) * t_num) / dz),
302 uint32_t world_count,
306 if (!view || !view->
valid || !world || !out_points || world_count < 3u
312 for (uint32_t i = 0; i < world_count; ++i) {
318 const int32_t near_z = view->
near_fp + 1;
320 uint32_t clipped_count = 0;
321 for (uint32_t i = 0; i < world_count; ++i) {
324 const bool a_in = a->
z >= near_z;
325 const bool b_in = b->
z >= near_z;
327 clipped[clipped_count++] = *a;
335 if (clipped_count < 3u) {
339 uint32_t projected = 0;
340 for (uint32_t i = 0; i < clipped_count; ++i) {
347 if (projected > 0 && s.
x == out_points[projected - 1u].
x
348 && s.
y == out_points[projected - 1u].
y) {
352 out_points[projected] = s;
354 out_view_z[projected] = (
float)clipped[i].
z;
360 if (projected >= 3u && out_points[0].
x == out_points[projected - 1u].
x
361 && out_points[0].
y == out_points[projected - 1u].
y) {
365 return projected >= 3u ? projected : 0;
DTTR_Graphics_COM_Direct3DDevice7 DWORD block DTTR_Graphics_COM_Direct3DDevice7 DWORD block DTTR_Graphics_COM_Direct3DDevice7 void void void void DWORD f DTTR_Graphics_COM_Direct3DDevice7 DWORD idx float
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
DTTR_Graphics_COM_DirectDrawSurface7 DWORD DWORD void void DWORD flags DTTR_Graphics_COM_DirectDrawSurface7 void void *cb void * target
DTTR_PCDOGS_API const struct DTTR_PCDOGS_D_Graphics_AdjustLevelScale_ListState_type *const DTTR_PCDOGS_D_Graphics_AdjustLevelScale_ListState
bool DTTR_StatusOK(DTTR_Status status)
static bool DTTR_Util_MemReadable(const void *ptr, size_t size)
#define DTTR_UTIL_WORLDVIEW_MAX_POLYGON_POINTS
static bool DTTR_Util_WorldView_ToView(const DTTR_Util_WorldView *view, const DTTR_PCDOGS_T_Math_Vec3I32 *world, DTTR_PCDOGS_T_Math_Vec3I32 *out)
static int16_t dttr_util_worldview_norm_q12(int64_t component, uint32_t length)
static bool DTTR_Util_WorldView_ViewToScreen(const DTTR_Util_WorldView *view, const DTTR_PCDOGS_T_Math_Vec3I32 *p, DTTR_PCDOGS_T_Math_Vec2F *out)
static bool DTTR_Util_WorldView_ProjectPoint(const DTTR_Util_WorldView *view, const DTTR_PCDOGS_T_Math_Vec3I32 *world, DTTR_PCDOGS_T_Math_Vec2F *out, float *out_view_z)
static uint32_t DTTR_Util_WorldView_ProjectPolygon(const DTTR_Util_WorldView *view, const DTTR_PCDOGS_T_Math_Vec3I32 *world, uint32_t world_count, DTTR_PCDOGS_T_Math_Vec2F *out_points, float *out_view_z)
static DTTR_PCDOGS_T_Math_Vec3I32 dttr_util_worldview_clip_segment(const DTTR_PCDOGS_T_Math_Vec3I32 *a, const DTTR_PCDOGS_T_Math_Vec3I32 *b, int32_t near_z)
static bool DTTR_Util_WorldView_Refresh(DTTR_Util_WorldView *view, const DTTR_PCDOGS_T_Math_RectI32 *target)
#define DTTR_UTIL_WORLDVIEW_FIXED_ONE
One logical unit spans this many world fixed-point units.
static uint32_t dttr_util_worldview_isqrt(uint64_t value)
DTTR_PCDOGS_T_Math_Vec3I32XZY eye_pos
Offset 0x10.
int32_t focal_distance
Offset 0xC.
DTTR_PCDOGS_T_Math_Vec3I32XZY target_pos
Offset 0x1C.
DTTR_PCDOGS_T_Math_SizeI16 screen_half
This holds the full display-mode size (640x480). Offset 0x2C.
int32_t projection_near_fp
Fixed-point near-plane threshold. Offset 0xB4.
This rect is an origin plus unsigned size.
int16_t height
Offset 0x2.
DTTR_PCDOGS_T_Math_Vec3I32 eye
The camera eye is logical world XYZ, already converted from XZY storage.
int32_t near_fp
The near plane in world fixed point.
DTTR_PCDOGS_T_Math_Vec3I16 forward
The view basis vectors (Q12).
DTTR_PCDOGS_T_Math_Vec2F center
The screen center and per-axis focal lengths are in draw-space pixels.
DTTR_PCDOGS_T_Math_Vec2F focal
DTTR_PCDOGS_T_Math_Vec3I16 up
DTTR_PCDOGS_T_Math_Vec3I16 right