7 f32 hitX, hitY, hitZ, hitDepth, nX, nY, nZ;
11 zoneID =
test_ray_zones(posX, posY, posZ, 0.0f, -1.0f, 0.0f, &hitX, &hitY, &hitZ, &hitDepth, &nX, &nY, &nZ);
22s32
calculate_segment_intersection(f32 A1x, f32 A1z, f32 A2x, f32 A2z, f32 B1x, f32 B1z, f32 B2x, f32 B2z, f32* interX, f32* interZ, f32* squared_dist) {
41 if (dx12 == 0.0f && dz12 == 0.0f) {
45 if (dx34 == 0.0f && dz34 == 0.0f) {
49 disc = -dz12 * dx13 + dx12 * dz13;
52 }
else if (disc > 0.0f) {
58 disc = -dz12 * dx14 + dx12 * dz14;
61 }
else if (disc > 0.0f) {
68 if (B1_side == B2_side) {
81 alpha = A1x * dz12 - A1z * dx12 + dx12 * B1z - dz12 * B1x;
83 alpha /= dz12 * dx34 - dx12 * dz34;
93 alpha = (B1x + dx34 * alpha - A1x) / dx12;
94 Px = A1x + dx12 * alpha;
95 Pz = A1z + dz12 * alpha;
102 alpha = B1z * dx34 + A1x * dz34 - B1z * dz34 - A1z * dx34;
104 alpha /= dz12 * dx34 - dx12 * dz34;
106 alpha = (A1x + dx12 * alpha - B1x) / dx34;
107 Px = B1x + dx34 * alpha;
108 Pz = B1z + dz34 * alpha;
111 if ((Px - A1x) * (Px - A2x) + (Pz - A1z) * (Pz - A2z) > 0.0f) {
118 *squared_dist =
SQ(Px - B1x) +
SQ(Pz - B1z);
122s32
calculate_line_segment_intersection(f32 A1x, f32 A1z, f32 A2x, f32 A2z, f32 B1x, f32 B1z, f32 B2x, f32 B2z, f32* interX, f32* interZ, f32* squared_dist) {
131 f32 dx12 = A2x - A1x;
132 f32 dz12 = A2z - A1z;
133 f32 dx13 = B1x - A1x;
134 f32 dz13 = B1z - A1z;
135 f32 dx14 = B2x - A1x;
136 f32 dz14 = B2z - A1z;
137 f32 dx34 = B2x - B1x;
138 f32 dz34 = B2z - B1z;
140 if (dx12 == 0.0f && dz12 == 0.0f) {
143 if (dx34 == 0.0f && dz34 == 0.0f) {
147 disc = -dz12 * dx13 + dx12 * dz13;
150 }
else if (disc > 0.0f) {
156 disc = -dz12 * dx14 + dx12 * dz14;
159 }
else if (disc > 0.0f) {
165 if (B1_side == B2_side) {
170 alpha = A1x * dz12 - A1z * dx12 + dx12 * B1z - dz12 * B1x;
171 alpha /= dz12 * dx34 - dx12 * dz34;
172 alpha = (B1x + dx34 * alpha - A1x) / dx12;
173 Px = A1x + dx12 * alpha;
174 Pz = A1z + dz12 * alpha;
176 alpha = B1z * dx34 + A1x * dz34 - B1z * dz34 - A1z * dx34;
177 alpha /= dz12 * dx34 - dx12 * dz34;
178 alpha = (A1x + dx12 * alpha - B1x) / dx34;
179 Px = B1x + dx34 * alpha;
180 Pz = B1z + dz34 * alpha;
185 *squared_dist =
SQ(Px - B1x) +
SQ(Pz - B1z);
190 f32 product1, product2;
191 f32 dot1x, dot1z, dot2x, dot2z;
193 if (camSettings == NULL) {
200 f32 Ax = camSettings->
points.two.Ax;
201 f32 Az = camSettings->
points.two.Az;
202 f32 Bx = camSettings->
points.two.Bx;
203 f32 Bz = camSettings->
points.two.Bz;
206 dot1x = (Bx - Ax) * (Px - Ax);
207 dot1z = (Bz - Az) * (Pz - Az);
208 product1 = dot1x + dot1z;
211 dot2x = (Bx - Ax) * (Px - Bx);
212 dot2z = (Bz - Az) * (Pz - Bz);
213 product2 = dot2x + dot2z;
215 if (product1 < 0 && product2 < 0) {
218 if (product1 > 0 && product2 > 0) {
230 ignoreStickInput = TRUE;
233 if (ignoreStickInput) {
252 if (stickX != 0.0f) {
308 if (deltaLeadAmount > 3.0f) {
309 deltaLeadAmount = 3.0f;
317 if (deltaLeadAmount < -3.0f) {
318 deltaLeadAmount = -3.0f;
322 if (stickX != 0.0f || ignoreStickInput) {
341 if (settings != NULL) {
353 1.0f, &X, &Y, &Z, &W);
364 if (leadSettings == NULL
369 if (leadSettings != NULL && s2 != 0) {
376 f32 product = dx * cosYaw + dz * sinYaw;
382 if (leadAmount > 0.0f && camera->
leadConstrainDir > 0 || leadAmount < 0.0f && camera->leadConstrainDir < 0) {
405 if (settings == NULL) {
413 f32 intX, intZ, intDistSq;
414 f32 minDistSq =
SQ(1000.0f);
415 b32 constrainToZoneTriangles = TRUE;
420 constrainToZoneTriangles = FALSE;
422 f32 ABx = settings->
points.two.Bx - settings->
points.two.Ax;
423 f32 ABz = settings->
points.two.Bz - settings->
points.two.Az;
426 settings->
points.two.Ax - ABz, settings->
points.two.Az + ABx,
428 && intDistSq < minDistSq
430 minDistSq = intDistSq;
433 settings->
points.two.Bx - ABz, settings->
points.two.Bz + ABx,
435 && intDistSq < minDistSq
437 minDistSq = intDistSq;
441 if (constrainToZoneTriangles) {
446 && intDistSq < minDistSq
448 minDistSq = intDistSq;
453 && intDistSq < minDistSq
455 minDistSq = intDistSq;
460 && intDistSq < minDistSq
462 minDistSq = intDistSq;
467 if (minDistSq ==
SQ(1000.0f) || minDistSq == 0.0f) {
481 f32 theta = ((camera->
vfov * 0.5f) / 180.0f) *
PI;
s32 calculate_segment_intersection(f32 A1x, f32 A1z, f32 A2x, f32 A2z, f32 B1x, f32 B1z, f32 B2x, f32 B2z, f32 *interX, f32 *interZ, f32 *squared_dist)
void apply_constraints_to_lead_amount(Camera *camera)
void update_camera_lead_amount(Camera *camera, f32 candidateLeadAmount)
CameraControlSettings * test_ray_zone(f32 posX, f32 posY, f32 posZ, Collider **zone)
void create_camera_leadplayer_matrix(Camera *camera)
s32 func_800328A4(CameraControlSettings *camSettings, f32 Px, f32 Pz)
s32 calculate_line_segment_intersection(f32 A1x, f32 A1z, f32 A2x, f32 A2z, f32 B1x, f32 B1z, f32 B2x, f32 B2z, f32 *interX, f32 *interZ, f32 *squared_dist)
struct ColliderTriangle * triangleTable
union CameraControlSettings::@14 points
@ CAM_CONTROL_FIXED_POS_AND_ORIENTATION
@ CAM_CONTROL_CONSTRAIN_TO_LINE
@ CAM_CONTROL_CONSTAIN_BETWEEN_POINTS
@ CAM_CONTROL_LOOK_AT_POINT_CONSTAIN_TO_LINE
@ CAMERA_FLAG_SUPRESS_LEADING
s32 test_ray_zones(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 dirZ, f32 *hitX, f32 *hitY, f32 *hitZ, f32 *hitDepth, f32 *nx, f32 *ny, f32 *nz)
CameraControlSettings * curSettings
b32 needsInitialConstrainDir
CameraControlSettings * prevLeadSettings
PlayerStatus * gPlayerStatusPtr
CollisionData gZoneCollisionData
PartnerStatus gPartnerStatus