102 Patches: Detours to the Rescue
C reference for DttR maintainers and modders.
Loading...
Searching...
No Matches
dttr_util_worldview.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <dttr_core.h>
#include <dttr_pcdogs.h>
#include <dttr_util_mem.h>

Go to the source code of this file.

Data Structures

struct  DTTR_Util_WorldView

Macros

#define DTTR_UTIL_WORLDVIEW_FIXED_ONE   4096
 One logical unit spans this many world fixed-point units.
#define DTTR_UTIL_WORLDVIEW_MAX_POLYGON_POINTS   8u

Typedefs

typedef struct DTTR_Util_WorldView DTTR_Util_WorldView

Functions

static uint32_t dttr_util_worldview_isqrt (uint64_t value)
static int16_t dttr_util_worldview_norm_q12 (int64_t component, uint32_t length)
static bool DTTR_Util_WorldView_Refresh (DTTR_Util_WorldView *view, const DTTR_PCDOGS_T_Math_RectI32 *target)
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 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 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 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)

Macro Definition Documentation

◆ DTTR_UTIL_WORLDVIEW_FIXED_ONE

#define DTTR_UTIL_WORLDVIEW_FIXED_ONE   4096

One logical unit spans this many world fixed-point units.

Helpers for extracting the camera frame and projecting world geometry to draw space with near-plane clipping and sub-pixel output.

This header is exposed through dttr_sdk.h only when DTTR_SDK_ENABLE_UNSTABLE is set. It depends on PCDOGS layouts that are still being mapped, so source and ABI details may change without notice.

World positions are int32 fixed point at 4096 units per logical unit, and draw coordinates are in the game's logical resolution. Graphics_ListState stores eye/target as Math_Vec3I32XZY, whose .z field holds logical Y and whose .y field holds logical Z.

Definition at line 32 of file dttr_util_worldview.h.

Referenced by dttr_util_worldview_norm_q12(), DTTR_Util_WorldView_Refresh(), DTTR_Util_WorldView_ToView(), and DTTR_Util_WorldView_ViewToScreen().

◆ DTTR_UTIL_WORLDVIEW_MAX_POLYGON_POINTS

#define DTTR_UTIL_WORLDVIEW_MAX_POLYGON_POINTS   8u

Polygon projection emits at most this many screen vertices. A quad clipped against one plane gains at most one vertex, so 8 leaves headroom.

Definition at line 36 of file dttr_util_worldview.h.

Referenced by DTTR_Util_WorldView_ProjectPolygon().

Typedef Documentation

◆ DTTR_Util_WorldView

typedef struct DTTR_Util_WorldView DTTR_Util_WorldView

Cached camera frame in screen-draw space. Build it once per frame with DTTR_Util_WorldView_Refresh and reuse it for each projection.

Function Documentation

◆ dttr_util_worldview_clip_segment()

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 )
inlinestatic

◆ dttr_util_worldview_isqrt()

uint32_t dttr_util_worldview_isqrt ( uint64_t value)
inlinestatic

Definition at line 59 of file dttr_util_worldview.h.

Referenced by DTTR_Util_WorldView_Refresh().

◆ dttr_util_worldview_norm_q12()

int16_t dttr_util_worldview_norm_q12 ( int64_t component,
uint32_t length )
inlinestatic

Definition at line 81 of file dttr_util_worldview.h.

References DTTR_UTIL_WORLDVIEW_FIXED_ONE.

Referenced by DTTR_Util_WorldView_Refresh().

◆ DTTR_Util_WorldView_ProjectPoint()

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 )
inlinestatic

Project a single world point to draw space, failing when the point is behind the near plane.

Definition at line 258 of file dttr_util_worldview.h.

References DTTR_Util_WorldView_ToView(), DTTR_Util_WorldView_ViewToScreen(), float, DTTR_Util_WorldView::near_fp, and DTTR_PCDOGS_T_Math_Vec3I32::z.

◆ DTTR_Util_WorldView_ProjectPolygon()

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 )
inlinestatic

Project a convex world polygon to draw space, clipping it against the near plane so camera-crossing geometry still draws its visible part. Offscreen extent is left to the rasterizer.

Definition at line 299 of file dttr_util_worldview.h.

References dttr_util_worldview_clip_segment(), DTTR_UTIL_WORLDVIEW_MAX_POLYGON_POINTS, DTTR_Util_WorldView_ToView(), DTTR_Util_WorldView_ViewToScreen(), float, DTTR_Util_WorldView::near_fp, DTTR_Util_WorldView::valid, DTTR_PCDOGS_T_Math_Vec2F::x, x, DTTR_PCDOGS_T_Math_Vec2F::y, y, DTTR_PCDOGS_T_Math_Vec3I32::z, and z.

◆ DTTR_Util_WorldView_Refresh()

◆ DTTR_Util_WorldView_ToView()

◆ DTTR_Util_WorldView_ViewToScreen()

bool DTTR_Util_WorldView_ViewToScreen ( const DTTR_Util_WorldView * view,
const DTTR_PCDOGS_T_Math_Vec3I32 * p,
DTTR_PCDOGS_T_Math_Vec2F * out )
inlinestatic

Perspective-divide a view-space point to draw-space coordinates with sub-pixel precision. The call fails for points at or behind the camera plane.

Definition at line 231 of file dttr_util_worldview.h.

References DTTR_Util_WorldView::center, DTTR_UTIL_WORLDVIEW_FIXED_ONE, float, DTTR_Util_WorldView::focal, DTTR_Util_WorldView::valid, DTTR_PCDOGS_T_Math_Vec2F::x, DTTR_PCDOGS_T_Math_Vec3I32::x, DTTR_PCDOGS_T_Math_Vec2F::y, DTTR_PCDOGS_T_Math_Vec3I32::y, and DTTR_PCDOGS_T_Math_Vec3I32::z.

Referenced by DTTR_Util_WorldView_ProjectPoint(), and DTTR_Util_WorldView_ProjectPolygon().