102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
state.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
11#include "pcdogs/entity/types.h"
12#include "pcdogs/game/types.h"
15#include "pcdogs/level/types.h"
17#include "pcdogs/math/types.h"
21#include <math.h>
22#include <stdarg.h>
23#include <string.h>
24
25// Original pcdogs.exe: 0x407c00
26// Interpolates camera angles, eye and target using eased transition progress while active and unpaused. Orbit mode interpolates distance relative to the already-interpolated target and reconstructs the eye position. Active transitions require a nonzero duration.
27void Camera_InterpolateTransition(struct Camera_TransitionState *state, struct Camera_Pose *target_pose, int32_t duration_frames, int32_t recompute_eye_from_angles)
28{
29 // Only interpolate if transition is active (frames remaining > 0) and not paused
30 // Camera interpolation runs only while transition counter is nonzero and the secondary transition gate is
31 // clear.
32 // CAMERA TRANSITION: Ease-in/ease-out interpolation. t=0x0000 at start, 0x1000 at end. Interpolates
33 // position, rotation (12-bit wraparound), FOV, target. angle_mode=0: position, angle_mode=1: angles
35 return;
36
37 // Calculate progress: t = ((total - remaining) * 0x1000) / total
38 // Result is 0x0000 at start, 0x1000 at end (12-bit fixed point 0.0-1.0)
39 int32_t easing_intermediate;
40
41 // Apply ease-in/ease-out curve for smooth acceleration/deceleration:
42 // If t < 0.5: result = t^2/2 (quadratic ease-in)
43 // If t >= 0.5: result = 1 - (1-t)^2/2 (quadratic ease-out)
44 *(uint8_t *)&state->flags_and_state &= (uint8_t)~CAMERA_POSE_FOLLOW_UPDATED;
45
46 int32_t remaining_frames = g_cameraTransitionCountdown - 1;
47
48 g_cameraTransitionCountdown = remaining_frames;
49
50 int32_t linear_progress_q12 = (int64_t)((duration_frames - remaining_frames) << MATH_Q12_SHIFT) / duration_frames;
51
52 easing_intermediate = linear_progress_q12;
53
54 int32_t ease_half;
55 int32_t eased_progress_q12;
56
57 if (linear_progress_q12 >= MATH_Q12_HALF)
58 {
59 int64_t remaining_progress_square_wide = (int64_t)(MATH_Q12_ONE - linear_progress_q12) * (MATH_Q12_ONE - linear_progress_q12);
60
61 easing_intermediate = (int32_t)((uint64_t)remaining_progress_square_wide >> MATH_Q12_SHIFT);
62 ease_half = ((int64_t)easing_intermediate * MATH_Q12_ONE) / MATH_Q12_HALF;
63 eased_progress_q12 = MATH_Q12_ONE - ease_half;
64 }
65 else
66 {
67 int64_t elapsed_progress_square_wide = (int64_t)easing_intermediate * easing_intermediate;
68
69 // Interpolate FOV: fov = start_fov + (end_fov - start_fov) * t
70 easing_intermediate = (int32_t)((uint64_t)elapsed_progress_square_wide >> MATH_Q12_SHIFT);
71 // Interpolate look-at target position (X, Y, Z): target = start + (end - start) * t
72 ease_half = ((int64_t)easing_intermediate * MATH_Q12_ONE) / MATH_Q12_HALF;
73 eased_progress_q12 = ease_half;
74 }
75
76 int16_t start_fov = state->pose.fov;
77
78 easing_intermediate = eased_progress_q12;
79
80 int32_t end_target_x = target_pose->target_pos.x;
81
82 // Interpolate roll angle with wraparound handling. Calculate shortest path around circle:
83 // delta = (end - start) & 0xfff (12-bit angle)
84 // If delta > 0x800 (> 180 degrees), subtract 0x1000 to go other direction (shorter path)
85 target_pose->fov = (int16_t)((((int32_t)target_pose->fov - (int32_t)start_fov) * eased_progress_q12) >> MATH_Q12_SHIFT) + (uint16_t)start_fov;
86
87 int64_t target_x_delta_wide = (int64_t)(end_target_x - state->pose.target_pos.x) * easing_intermediate;
88
89 // Apply interpolation and mask result to 12-bit angle range
90 int32_t end_target_vertical = target_pose->target_pos.z;
91
92 target_pose->target_pos.x =
93 ((int32_t)((uint64_t)target_x_delta_wide >> MATH_Q12_SHIFT)) + state->pose.target_pos.x;
94
95 int64_t target_vertical_delta_wide = (int64_t)(end_target_vertical - state->pose.target_pos.z) * easing_intermediate;
96
97 target_pose->target_pos.z =
98 // Mode 0: Interpolate camera position (X, Y, Z): pos = start + (end - start) * t
99 ((int32_t)((uint64_t)target_vertical_delta_wide >> MATH_Q12_SHIFT)) + state->pose.target_pos.z;
100
101 int64_t target_depth_delta_wide = (int64_t)(target_pose->target_pos.y - state->pose.target_pos.y) * easing_intermediate;
102
103 target_pose->target_pos.y = ((int32_t)((uint64_t)target_depth_delta_wide >> MATH_Q12_SHIFT)) + state->pose.target_pos.y;
104
105 int16_t start_roll = state->pose.view_roll;
106 int16_t wrapped_roll_delta = (target_pose->view_roll - start_roll) & MATH_ANGLE_WRAP_MASK;
107 int32_t signed_roll_delta = (int32_t)wrapped_roll_delta;
108
109 // Mode 1: Interpolate pitch and yaw angles with wraparound, then calculate position from distance
110 if (wrapped_roll_delta > MATH_Q12_HALF)
111 signed_roll_delta -= MATH_Q12_ONE;
112
113 target_pose->view_roll = (int16_t)((signed_roll_delta * eased_progress_q12) >> MATH_Q12_SHIFT) + (uint16_t)start_roll;
114
115 int32_t recompute_position = recompute_eye_from_angles;
116
117 target_pose->view_roll &= MATH_ANGLE_WRAP_MASK;
118
119 if (!recompute_position)
120 {
121 int64_t eye_x_delta_wide = (int64_t)(target_pose->eye_pos.x - state->pose.eye_pos.x) * easing_intermediate;
122 int32_t end_eye_vertical = target_pose->eye_pos.z;
123
124 target_pose->eye_pos.x =
125 state->pose.eye_pos.x + ((int32_t)((uint64_t)eye_x_delta_wide >> MATH_Q12_SHIFT));
126
127 int64_t eye_vertical_delta_wide = (int64_t)(end_eye_vertical - state->pose.eye_pos.z) * easing_intermediate;
128 int32_t end_eye_depth = target_pose->eye_pos.y;
129
130 target_pose->eye_pos.z =
131 state->pose.eye_pos.z + ((int32_t)((uint64_t)eye_vertical_delta_wide >> MATH_Q12_SHIFT));
132
133 // Calculate current distance from start camera to target: sqrt((target - pos)^2)
134 int64_t eye_depth_delta_wide = (int64_t)(end_eye_depth - state->pose.eye_pos.y) * easing_intermediate;
135
136 target_pose->eye_pos.y =
137 state->pose.eye_pos.y + ((int32_t)((uint64_t)eye_depth_delta_wide >> MATH_Q12_SHIFT));
138
139 return;
140 }
141
142 int16_t start_pitch = state->pose.angle_vertical;
143 // Calculate end distance from end camera to target: sqrt((target - pos)^2)
144 int16_t wrapped_pitch_delta = (target_pose->angle_vertical - start_pitch) & MATH_ANGLE_WRAP_MASK;
145 int32_t signed_pitch_delta = (int32_t)wrapped_pitch_delta;
146
147 if (wrapped_pitch_delta > MATH_Q12_HALF)
148 signed_pitch_delta -= MATH_Q12_ONE;
149
150 target_pose->angle_vertical = (int16_t)((signed_pitch_delta * eased_progress_q12) >> MATH_Q12_SHIFT) + (uint16_t)start_pitch;
151 target_pose->angle_vertical &= MATH_ANGLE_WRAP_MASK;
152
153 // Interpolate distance: dist = start_dist + (end_dist - start_dist) * t
154 int16_t start_yaw = state->pose.angle_horizontal;
155 int16_t wrapped_yaw_delta = (target_pose->angle_horizontal - (uint16_t)start_yaw) & MATH_ANGLE_WRAP_MASK;
156 int32_t signed_yaw_delta = (int32_t)wrapped_yaw_delta;
157
158 if (wrapped_yaw_delta > MATH_Q12_HALF)
159 signed_yaw_delta -= MATH_Q12_ONE;
160
161 target_pose->angle_horizontal = (int16_t)((signed_yaw_delta * eased_progress_q12) >> MATH_Q12_SHIFT) + (uint16_t)start_yaw;
163
164 int32_t start_vertical_offset = state->pose.eye_pos.z - state->pose.target_pos.z;
165 int32_t start_depth_offset = state->pose.eye_pos.y - state->pose.target_pos.y;
166 int32_t lateral_offset = state->pose.eye_pos.x - state->pose.target_pos.x;
167 int64_t start_lateral_square_wide = (int64_t)lateral_offset * lateral_offset;
168 int64_t start_vertical_square_wide = (int64_t)start_vertical_offset * start_vertical_offset;
169 int64_t start_depth_square_wide = (int64_t)start_depth_offset * start_depth_offset;
170 int32_t start_distance = Math_SqrtFP12(((int32_t)((int64_t)((uint64_t)start_depth_square_wide + (uint64_t)start_lateral_square_wide + (uint64_t)start_vertical_square_wide) >> MATH_Q12_SHIFT)));
171 int32_t end_vertical_offset = target_pose->eye_pos.z - target_pose->target_pos.z;
172
173 lateral_offset = target_pose->eye_pos.x - target_pose->target_pos.x;
174
175 int32_t end_depth_offset = target_pose->eye_pos.y - target_pose->target_pos.y;
176 int64_t end_lateral_square_wide = (int64_t)lateral_offset * lateral_offset;
177 int64_t end_vertical_square_wide = (int64_t)end_vertical_offset * end_vertical_offset;
178 int64_t end_depth_square_wide = (int64_t)end_depth_offset * end_depth_offset;
179 int32_t end_distance = Math_SqrtFP12((uint32_t)(((uint64_t)end_depth_square_wide + (uint64_t)end_lateral_square_wide + (uint64_t)end_vertical_square_wide) >> MATH_Q12_SHIFT));
180 int64_t distance_delta_product = (int64_t)(end_distance - start_distance) * easing_intermediate;
181
182 Camera_CalculatePosition(target_pose, (int32_t)((uint64_t)distance_delta_product >> MATH_Q12_SHIFT) + start_distance);
183}
184
185// Original pcdogs.exe: 0x407f80
186// Builds a camera pose from the selected entity or default definition, applies definition overrides and follow-angle updates, and starts or advances transitions.
187void Camera_UpdateFromDefinition(struct Camera_Runtime *camera, struct Entity *entity, struct Camera_Pose *pose)
188{
189 struct Entity *tracked_entity = entity;
190 struct Pkg_CameraDef *active_definition = pkg_resource_current_level_data->cam_default;
191 struct Actor *tracked_actor = tracked_entity->runtime_actor;
192 struct Camera_DefinitionOverrideNodeView *camera_override_node = NULL;
193 struct Pkg_CameraDef *selected_definition = active_definition;
194
195 if (tracked_actor)
196 {
197 struct Player_ControllerRecordView *controller_record = (struct Player_ControllerRecordView *)(tracked_actor->record_ptr);
198
200
201 if (camera_override_node)
202 {
203 uint32_t camera_definition_index = camera_override_node->camera_definition_index;
204
205 selected_definition = &active_definition[camera_definition_index];
206
207 if (!(active_definition[camera_definition_index].flags & CAMERA_DEFINITION_PERSIST_OVERRIDE))
208 controller_record->camera_override_node = NULL;
209
210 active_definition = selected_definition;
211 }
212 }
213
214 struct Camera_Pose *output_pose = pose;
215
216 output_pose->fov = active_definition->fov_distance;
217
218 uint8_t definition_flags = active_definition->flags;
219 int32_t camera_mode = active_definition->camera_type & CAMERA_DEFINITION_MODE_MASK;
220 struct Camera_Runtime *transition_camera;
221
222 if (camera_mode == CAMERA_DEFINITION_ENTITY_RELATIVE)
223 {
224 output_pose->target_pos.x = active_definition->target_offset.x + tracked_entity->position_ptr->x;
225 output_pose->target_pos.z = tracked_entity->position_ptr->y + active_definition->target_offset.y;
226 output_pose->target_pos.y = tracked_entity->position_ptr->z + active_definition->target_offset.z;
227
228 if (!(definition_flags & CAMERA_DEFINITION_ORBIT))
229 {
230 char use_child_offset = definition_flags & CAMERA_DEFINITION_FOLLOW_CHILD;
231 struct Actor *child_actor = (use_child_offset && tracked_actor) ? tracked_actor->child_actor : NULL;
232 struct Math_Vec3I32 *position_ptr;
233
234 if (!use_child_offset || !tracked_actor || !child_actor)
235 position_ptr = tracked_entity->position_ptr;
236 else
237 position_ptr = &child_actor->position;
238
239 output_pose->eye_pos.x = active_definition->cam_offset.x + position_ptr->x;
240
241 char child_offset_flag = use_child_offset;
242 struct Actor *vertical_offset_child = (child_offset_flag && tracked_actor) ? tracked_actor->child_actor : NULL;
243 struct Math_Vec3I32 *vertical_offset_position;
244
245 if (!child_offset_flag || !tracked_actor || !vertical_offset_child)
246 vertical_offset_position = tracked_entity->position_ptr;
247 else
248 vertical_offset_position = &vertical_offset_child->position;
249
250 output_pose->eye_pos.z = vertical_offset_position->y + active_definition->cam_offset.y;
251
252 struct Actor *depth_offset_child = (child_offset_flag && tracked_actor) ? tracked_actor->child_actor : NULL;
253
254 if (!child_offset_flag || !tracked_actor || !depth_offset_child)
255 output_pose->eye_pos.y = tracked_entity->position_ptr->z + active_definition->cam_offset.z;
256 else
257 output_pose->eye_pos.y = depth_offset_child->position.z + active_definition->cam_offset.z;
258
259 transition_camera = camera;
260 }
261 else if (definition_flags & CAMERA_DEFINITION_FIXED_EYE || !tracked_actor ||
262 !(transition_camera = camera, Camera_CalculateFollowAngles(transition_camera, (struct Actor_State *)(tracked_actor), output_pose, active_definition)))
263 {
264 int32_t offset_x = active_definition->cam_offset.x;
265 int32_t offset_y = active_definition->cam_offset.y;
266 /* x, y_1 and z_2 are consumed as scalar coordinates below. */
267 int32_t offset_z = active_definition->cam_offset.z;
268 int64_t offset_x_square_wide = (int64_t)offset_x * offset_x;
269 int64_t offset_y_square_wide = (int64_t)offset_y * offset_y;
270 int64_t offset_z_square_wide = (int64_t)offset_z * offset_z;
271 int32_t camera_distance =
272 Math_SqrtFP12((int32_t)(((uint64_t)offset_x_square_wide + (uint64_t)offset_y_square_wide + (uint64_t)offset_z_square_wide) >> MATH_Q12_SHIFT));
273 int16_t facing_yaw;
274
275 if (!tracked_actor)
276 facing_yaw = 0;
277 else
278 {
279 facing_yaw = (tracked_actor->facing_blend + tracked_actor->facing_current) & MATH_ANGLE_WRAP_MASK;
280 }
281
282 pose->angle_horizontal = facing_yaw;
283
284 int32_t offset_pitch;
285
286 offset_pitch = Math_AsinRatioFP12(offset_y, camera_distance);
287
288 int32_t wrapped_pitch = offset_pitch & MATH_ANGLE_WRAP_MASK;
289
290 pose->angle_vertical = (uint16_t)wrapped_pitch;
291
292 if (tracked_actor)
293 {
294 struct Actor *pitch_follow_child = tracked_actor->child_actor;
295
296 if (pitch_follow_child)
297 {
298 if (definition_flags & CAMERA_DEFINITION_FOLLOW_CHILD)
299 {
300 int64_t pitch_height_product_wide = (int64_t)camera_distance * (Math_SinQ14(wrapped_pitch) >> 2);
301 int32_t child_relative_pitch;
302
303 child_relative_pitch = Math_AsinRatioFP12(
304 pose->target_pos.z - tracked_actor->child_actor->position.y - selected_definition->target_offset.y - ((int32_t)((uint64_t)pitch_height_product_wide >> MATH_Q12_SHIFT)),
305 camera_distance);
306 pose->angle_vertical = (int16_t)-(child_relative_pitch)&MATH_ANGLE_WRAP_MASK;
307 }
308
309 if (!(tracked_actor->behavior_flags & ACTOR_BEHAVIOR_AIRBORNE))
310 {
311 int32_t yaw_sine_q14 = Math_SinQ14(pose->angle_horizontal);
312 int16_t complement_yaw = MATH_ANGLE_QUARTER_TURN - pose->angle_horizontal;
313 int32_t yaw_cosine_q14 = Math_SinQ14(complement_yaw);
314 struct Actor *orientation_child = tracked_actor->child_actor;
315 int32_t m01 = (int32_t)orientation_child->contact_basis.m01;
316 int32_t m10 = (int32_t)orientation_child->contact_basis.m10;
317 int16_t follow_cosine = (int16_t)(yaw_cosine_q14 >> 2);
318 int32_t m02 = (int32_t)orientation_child->contact_basis.m02;
319 int32_t m00 = (int32_t)orientation_child->contact_basis.m00;
320 int32_t tilted_forward_product = (int32_t)(int16_t)((m00 * m01 + m10 * m02) >> 0xf) * (int32_t)follow_cosine + (int32_t)(int16_t)((m01 * m02 - m00 * m10) >> 0xf) * (int32_t)(int16_t)(yaw_sine_q14 >> 2);
321
322 pose->angle_vertical = (Math_AsinRatioFP12(-((int32_t)(int16_t)(tilted_forward_product >> MATH_Q12_SHIFT)), MATH_Q12_ONE) + pose->angle_vertical) & MATH_ANGLE_WRAP_MASK;
323 }
324 else
325 {
326 struct Collision_Node *ground_collision_node =
327 tracked_actor->ground_collision_node;
328
329 if (ground_collision_node)
330 {
331 struct Pkg_CollisionFacePlane *face_plane =
332 tracked_actor->ground_contact_polygon->face_plane;
333 int32_t normal_x_product = (int32_t)face_plane->normal.x * (int32_t)tracked_actor->ground_collision_node->transform_matrix.m10;
334 int32_t transformed_normal_y = ((int32_t)face_plane->normal.z * (int32_t)ground_collision_node->transform_matrix.m12 + (int32_t)face_plane->normal.y * (int32_t)ground_collision_node->transform_matrix.m11 + normal_x_product) & 0xfffff000;
335
336 if (transformed_normal_y > CAMERA_GROUND_ALIGNMENT_THRESHOLD_Q24)
337 {
338 int32_t yaw_sine_q14 = Math_SinQ14(pose->angle_horizontal);
339 int16_t complement_yaw = MATH_ANGLE_QUARTER_TURN - pose->angle_horizontal;
340 int32_t yaw_cosine_q14 = Math_SinQ14(complement_yaw);
341 struct Actor *orientation_child = tracked_actor->child_actor;
342 int32_t m01 = (int32_t)orientation_child->contact_basis.m01;
343 int32_t m10 = (int32_t)orientation_child->contact_basis.m10;
344 int16_t follow_cosine = (int16_t)(yaw_cosine_q14 >> 2);
345 int32_t m02 = (int32_t)orientation_child->contact_basis.m02;
346 int32_t m00 = (int32_t)orientation_child->contact_basis.m00;
347 int32_t tilted_forward_product = (int32_t)(int16_t)((m00 * m01 + m10 * m02) >> 0xf) * (int32_t)follow_cosine + (int32_t)(int16_t)((m01 * m02 - m00 * m10) >> 0xf) * (int32_t)(int16_t)(yaw_sine_q14 >> 2);
348
349 pose->angle_vertical = (Math_AsinRatioFP12(-((int32_t)(int16_t)(tilted_forward_product >> MATH_Q12_SHIFT)), MATH_Q12_ONE) + pose->angle_vertical) & MATH_ANGLE_WRAP_MASK;
350 }
351 }
352 }
353 }
354 }
355
356 Camera_CalculatePosition(pose, camera_distance);
357 active_definition = selected_definition;
358 transition_camera = camera;
359 output_pose = pose;
360 }
361 else
362 {
363 int16_t angle_vertical = output_pose->angle_vertical;
364
365 transition_camera->look_pitch = angle_vertical;
366
367 int8_t attachment_ticks = ((struct Player_ControllerRecordView *)tracked_actor->record_ptr)->attachment_ticks;
368
370 {
371 transition_camera->look_yaw = output_pose->angle_horizontal;
372
373 int32_t previous_target_vertical = transition_camera->target_pos.z;
374
375 transition_camera->target_pos.x += tracked_actor->sub_pos.x;
376
377 int32_t previous_target_depth = transition_camera->target_pos.y;
378
379 transition_camera->target_pos.z = previous_target_vertical + tracked_actor->sub_pos.y;
380
381 int32_t previous_eye_x = transition_camera->eye_pos.x;
382
383 transition_camera->target_pos.y = previous_target_depth + tracked_actor->sub_pos.z;
384
385 int32_t previous_eye_vertical = transition_camera->eye_pos.z;
386
387 transition_camera->eye_pos.x = previous_eye_x + tracked_actor->sub_pos.x;
388 transition_camera->eye_pos.z = previous_eye_vertical + tracked_actor->sub_pos.y;
389 transition_camera->eye_pos.y += tracked_actor->sub_pos.z;
390 }
391 }
392 }
393 else
394 {
395 if (camera_mode == CAMERA_DEFINITION_ABSOLUTE)
396 {
397 if (definition_flags & CAMERA_DEFINITION_FIXED_EYE)
398 {
399 output_pose->eye_pos.x = active_definition->cam_offset.x;
400 output_pose->eye_pos.z = active_definition->cam_offset.y;
401 output_pose->eye_pos.y = active_definition->cam_offset.z;
402
404 {
405 int32_t absolute_eye_vertical = output_pose->eye_pos.z;
406
407 output_pose->eye_pos.x += camera_override_node->world_pos.x;
408
409 int32_t absolute_eye_depth = output_pose->eye_pos.y;
410
411 output_pose->eye_pos.z = absolute_eye_vertical + camera_override_node->world_pos.y;
412 output_pose->eye_pos.y = absolute_eye_depth + camera_override_node->world_pos.z;
413 }
414
415 tracked_entity = entity;
416 }
417
418 if (!(definition_flags & CAMERA_DEFINITION_TARGET_ENTITY_RELATIVE))
419 {
420 output_pose->target_pos.x = active_definition->target_offset.x;
421 output_pose->target_pos.z = active_definition->target_offset.y;
422 output_pose->target_pos.y = active_definition->target_offset.z;
423
425 {
426 int32_t absolute_target_vertical = output_pose->target_pos.z;
427 int32_t absolute_target_depth = output_pose->target_pos.y;
428
430 output_pose->target_pos.z = absolute_target_vertical + camera_override_node->world_pos.y;
431 output_pose->target_pos.y = absolute_target_depth + camera_override_node->world_pos.z;
432 }
433 }
434 else
435 {
436 output_pose->target_pos.x = active_definition->target_offset.x + tracked_entity->position_ptr->x;
437 output_pose->target_pos.z = tracked_entity->position_ptr->y + active_definition->target_offset.y;
438 output_pose->target_pos.y = tracked_entity->position_ptr->z + active_definition->target_offset.z;
439 }
440 }
441
442 transition_camera = camera;
443 }
444
445 struct Level_Data *definition_level = pkg_resource_current_level_data;
446
447 if (active_definition != definition_level->cam_current)
448 {
450 {
451 int32_t transition_countdown = (uint16_t)(active_definition->transition_speed);
452
453 g_cameraTransitionCountdown = transition_countdown;
454 }
455
456 definition_level->cam_current = active_definition;
457 }
458
459 int32_t duration_frames = (uint16_t)(active_definition->transition_speed);
460
461 Camera_InterpolateTransition((struct Camera_TransitionState *)(transition_camera), output_pose, duration_frames,
462 definition_flags & CAMERA_DEFINITION_ORBIT);
463}
464
465// Original pcdogs.exe: 0x444b80
466// Initializes the camera's distance limit, default field of view and 640-by-480 viewport, then clears shake and roll countdowns.
468{
470 // FastAtan2: Fast arctangent calculation for 2D angle from Y,X components.
471 // Returns 12-bit angle (0-0xFFF). Uses lookup table DAT_00452a3c for interpolation.
472 // Returns 0x1000 (sentinel) if both inputs are zero. Handles all four quadrants correctly.
473 Camera_SetDefaultFOV((struct Camera_Runtime *)(render_state));
474 // Set maximum view distance to very large value (0x7ffff000 in fixed point)
475 // If Y is zero, check X. Return sentinel 0x1000 if both zero (undefined angle)
476 // Set default field of view angle
477 // Make Y absolute for calculation. Sign will be handled later for quadrant
478 // Set viewport to full screen: (0,0) to (640,480), flag=1
480 // Make X absolute for calculation. Sign will be handled later for quadrant
481 render_state->shake_countdown = 0;
482 // Clear screen shake timer (camera+0x100d4)
483 // Determine which component is larger. This decides if we use atan or cotan formula.
484 // If |Y| > |X|: use complementary angle (90 degrees - atan(X/Y))
485 render_state->roll_effect_countdown = 0;
486}
#define ACTOR_BEHAVIOR_AIRBORNE
Definition constants.h:13
#define CAMERA_DEFAULT_DISTANCE_LIMIT_Q12
Definition constants.h:24
#define CAMERA_DEFINITION_ORBIT
Definition constants.h:11
#define CAMERA_GROUND_ALIGNMENT_THRESHOLD_Q24
Definition constants.h:53
#define CAMERA_DEFINITION_TARGET_ENTITY_RELATIVE
Definition constants.h:10
#define CAMERA_DEFINITION_PERSIST_OVERRIDE
Definition constants.h:15
#define CAMERA_DEFINITION_MODE_MASK
Definition constants.h:17
@ CAMERA_DEFINITION_ENTITY_RELATIVE
Definition constants.h:6
@ CAMERA_DEFINITION_ABSOLUTE
Definition constants.h:7
#define CAMERA_DEFINITION_FOLLOW_CHILD
Definition constants.h:14
#define CAMERA_DEFAULT_VIEWPORT_WIDTH
Definition constants.h:56
#define CAMERA_DEFINITION_FIXED_EYE
Definition constants.h:16
#define CAMERA_POSE_FOLLOW_UPDATED
Definition constants.h:18
#define CAMERA_DEFAULT_VIEWPORT_HEIGHT
Definition constants.h:57
int32_t Camera_SetDefaultFOV(struct Camera_Runtime *camera)
Definition projection.c:232
bool Camera_CalculateFollowAngles(struct Camera_Runtime *camera, struct Actor_State *target_actor, struct Camera_Pose *pose, struct Pkg_CameraDef *cam_def)
Definition follow.c:95
void Camera_SetViewport(int16_t viewport_x, int16_t viewport_y, int16_t viewport_w, int16_t viewport_h, int32_t apply_projection)
Definition projection.c:243
void Camera_CalculatePosition(struct Camera_Pose *camera_pose, int32_t target_distance)
Definition follow.c:75
#define g_cameraTransitionCountdown
Definition globals.h:36
#define g_cameraTransitionPaused
Definition globals.h:45
void Camera_UpdateFromDefinition(struct Camera_Runtime *camera, struct Entity *entity, struct Camera_Pose *pose)
Definition state.c:187
void Camera_Initialize(struct Graphics_Render_ListState *render_state)
Definition state.c:467
void Camera_InterpolateTransition(struct Camera_TransitionState *state, struct Camera_Pose *target_pose, int32_t duration_frames, int32_t recompute_eye_from_angles)
Definition state.c:27
#define MATH_Q12_SHIFT
Definition constants.h:8
#define MATH_ANGLE_QUARTER_TURN
Definition constants.h:15
#define MATH_ANGLE_WRAP_MASK
Definition constants.h:16
#define MATH_Q12_ONE
Definition constants.h:9
#define MATH_Q12_HALF
Definition constants.h:10
int32_t Math_SinQ14(int32_t angle)
int32_t Math_SqrtFP12(uint32_t value)
int32_t Math_AsinRatioFP12(int32_t numerator, int32_t denominator)
#define pkg_resource_current_level_data
Definition globals.h:117
Definition types.h:118
int16_t facing_current
Definition types.h:200
struct Pkg_ActorRecord * record_ptr
Definition types.h:207
struct Math_Vec3I32 sub_pos
Definition types.h:133
int16_t facing_blend
Definition types.h:202
struct Math_Vec3I32 position
Definition types.h:132
int32_t behavior_flags
Definition types.h:160
struct Actor * child_actor
Definition types.h:208
struct Collision_Polygon * ground_contact_polygon
Definition types.h:205
struct Collision_Node * ground_collision_node
Definition types.h:204
struct Math_Matrix3x3I16 contact_basis
Definition types.h:127
int16_t angle_vertical
Definition types.h:159
struct Math_Vec3I32XZY eye_pos
Definition types.h:164
int16_t fov
Definition types.h:162
int16_t angle_horizontal
Definition types.h:160
struct Math_Vec3I32XZY target_pos
Definition types.h:165
int16_t view_roll
Definition types.h:161
struct Math_Vec3I32XZY target_pos
Definition types.h:263
int16_t look_pitch
Definition types.h:257
struct Math_Vec3I32XZY eye_pos
Definition types.h:262
int16_t look_yaw
Definition types.h:258
uint32_t flags_and_state
Definition types.h:218
struct Camera_Pose pose
Definition types.h:219
struct Math_Matrix3x3I16 transform_matrix
Definition types.h:281
struct Pkg_CollisionFacePlane * face_plane
Definition types.h:62
Definition types.h:22
struct Math_Vec3I32 * position_ptr
Definition types.h:78
struct Actor * runtime_actor
Definition types.h:107
uint16_t roll_effect_countdown
Definition types.h:702
int32_t dynamic_level_scale
Definition types.h:681
struct Pkg_CameraDef * cam_current
Definition types.h:42
int16_t m00
Definition types.h:162
int16_t m01
Definition types.h:163
int16_t m12
Definition types.h:167
int16_t m11
Definition types.h:166
int16_t m02
Definition types.h:164
int16_t m10
Definition types.h:165
int16_t z
Definition types.h:460
int16_t x
Definition types.h:458
int16_t y
Definition types.h:459
int32_t x
Definition types.h:482
int32_t z
Definition types.h:483
int32_t y
Definition types.h:484
int32_t y
Definition types.h:471
int32_t x
Definition types.h:470
int32_t z
Definition types.h:472
struct Pkg_CameraDef::@025200157226127377100327225206264140320351074277 target_offset
int32_t z
Definition types.h:190
uint8_t flags
Definition types.h:180
int32_t x
Definition types.h:188
int16_t transition_speed
Definition types.h:181
int16_t fov_distance
Definition types.h:182
int32_t y
Definition types.h:189
uint8_t camera_type
Definition types.h:179
struct Pkg_CameraDef::@210005072027223003043342324112202256330206330217 cam_offset
struct Math_Vec3I16 normal
Definition types.h:1135
struct Scene_Node * camera_override_node
Definition types.h:185
struct Math_Vec3I32 world_pos
Definition types.h:120
#define g_frameCounter
Definition values.h:501