1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
4#include "collisionmdt.hpp"
14static void vu_maxmin3(
float *max,
float *min,
float *a,
float *b,
float *c) {
15 register float *out_max = max;
16 register float *out_min = min;
17 register float *p0 = a;
18 register float *p1 = b;
19 register float *p2 = c;
26 vmini vf20, vf15, vf16
28 vmini vf21, vf20, vf17
35static void vu_normal(
float *normal,
float *a,
float *b,
float *c) {
36 register float *out = normal;
37 register float *p0 = a;
38 register float *p1 = b;
39 register float *p2 = c;
47 vopmula ACC, vf10, vf11
48 vopmsub vf12, vf11, vf10
55static inline void vu_hold_box(
float *max,
float *min) {
56 register float *p0 = max;
57 register float *p1 = min;
69static inline int vu_box_missed(
float *max,
float *min) {
70 register float *p0 = max;
71 register float *p1 = min;
81 vsub.xyz vf25, vf10, vf13
82 vsub.xyz vf25, vf12, vf11
96void CCollision::CreateBBox() {
99 sceVu0FVECTOR *vertex;
101 vertex = GetVertexAddress(&vertex_count);
110 max[0] = vertex[0][0];
111 max[1] = vertex[0][1];
112 max[2] = vertex[0][2];
113 min[0] = vertex[0][0];
114 min[1] = vertex[0][1];
115 min[2] = vertex[0][2];
117 for (i = 0; i < vertex_count; i++) {
118 if (
max[0] < vertex[0][0]) {
119 max[0] = vertex[0][0];
122 if (
max[1] < vertex[0][1]) {
123 max[1] = vertex[0][1];
126 if (
max[2] < vertex[0][2]) {
127 max[2] = vertex[0][2];
130 if (
min[0] > vertex[0][0]) {
131 min[0] = vertex[0][0];
134 if (
min[1] > vertex[0][1]) {
135 min[1] = vertex[0][1];
138 if (
min[2] > vertex[0][2]) {
139 min[2] = vertex[0][2];
146sceVu0FVECTOR *CCollision::GetVertexAddress(
int *count) {
150int CCollisionMDT::GetPolygon(
int index, sceVu0FMATRIX v0, sceVu0FMATRIX v1, sceVu0FMATRIX v2) {
159 if (index >= collision->
set.
num) {
169int CCollisionMDT::GetMaxY(
float *position) {
176 sceVu0FVECTOR normal;
177 sceVu0FVECTOR tri_max;
178 sceVu0FVECTOR tri_min;
181 sceVu0FVECTOR *vertex;
196 from[0] = to[0] = position[0];
197 from[2] = to[2] = position[2];
205 for (i = 0; i < set->
num; i++) {
206 *(u_long128 *) v0 = *(u_long128 *) vertex[poly->
vertex[0]];
207 *(u_long128 *) v1 = *(u_long128 *) vertex[poly->
vertex[1]];
208 *(u_long128 *) v2 = *(u_long128 *) vertex[poly->
vertex[2]];
211 vu_maxmin3(tri_max, tri_min, v0, v1, v2);
213 if (position[0] < tri_min[0] || position[0] > tri_max[0]) {
217 if (position[2] < tri_min[2] || position[2] > tri_max[2]) {
221 vu_normal(normal, v0, v1, v2);
223 if (IntersectionPoint_line_poly3(from, to, v0, v1, v2, normal, hit) == 0) {
243int CCollisionMDT::Intersection(
float *from,
float *to,
float *hit) {
250 sceVu0FVECTOR normal;
251 sceVu0FVECTOR tri_max;
252 sceVu0FVECTOR tri_min;
255 sceVu0FVECTOR *vertex;
273 for (i = 0; i < set->
num; i++) {
274 *(u_long128 *) v0 = *(u_long128 *) vertex[poly->
vertex[0]];
275 *(u_long128 *) v1 = *(u_long128 *) vertex[poly->
vertex[1]];
276 *(u_long128 *) v2 = *(u_long128 *) vertex[poly->
vertex[2]];
279 vu_maxmin3(tri_max, tri_min, v0, v1, v2);
281 if (from[0] < tri_min[0] && to[0] < tri_min[0]) {
285 if (from[0] > tri_max[0] && to[0] > tri_max[0]) {
292 if (from[1] < tri_min[1] && to[1] < tri_min[0]) {
296 if (from[1] > tri_max[1] && to[1] > tri_max[0]) {
300 if (from[2] < tri_min[2] && to[2] < tri_min[2]) {
304 if (from[2] > tri_max[2] && to[2] > tri_max[2]) {
308 edge0[0] = v1[0] - v0[0];
309 edge0[1] = v1[1] - v0[1];
310 edge0[2] = v1[2] - v0[2];
312 edge1[0] = v2[0] - v0[0];
313 edge1[1] = v2[1] - v0[1];
314 edge1[2] = v2[2] - v0[2];
317 sceVu0OuterProduct(normal, edge0, edge1);
320 plane_dist = sceVu0InnerProduct(normal, v0);
321 from_dist = sceVu0InnerProduct(normal, from);
322 to_dist = sceVu0InnerProduct(normal, to);
324 if (plane_dist - from_dist > 0.0f && plane_dist - to_dist > 0.0f) {
328 if (plane_dist - from_dist < 0.0f && plane_dist - to_dist < 0.0f) {
332 if (IntersectionPoint_line_poly3(from, to, v0, v1, v2, normal, point) == 0) {
336 dx = point[0] - from[0];
337 dy = point[1] - from[1];
338 dz = point[2] - from[2];
339 distance = dx * dx + dy * dy + dz * dz;
342 best_distance = distance;
343 sceVu0CopyVector(hit, point);
346 if (distance < best_distance) {
347 best_distance = distance;
348 sceVu0CopyVector(hit, point);
358sceVu0FVECTOR *CCollisionMDT::GetVertexAddress(
int *count) {
373int CCollisionMDT::PickUpNearPoly(
CCPoly *poly,
float *position,
float radius) {
374 sceVu0FVECTOR tri_max;
375 sceVu0FVECTOR tri_min;
378 sceVu0FVECTOR *vertex;
392 max_x = position[0] + radius;
393 max_y = position[1] + radius;
394 max_z = position[2] + radius;
395 min_x = position[0] - radius;
396 min_y = position[1] - radius;
397 min_z = position[2] - radius;
403 for (i = 0; i < set->
num; i++) {
404 *(u_long128 *) out->
vertex[0] = *(u_long128 *) vertex[cpoly->
vertex[0]];
405 *(u_long128 *) out->
vertex[1] = *(u_long128 *) vertex[cpoly->
vertex[1]];
406 *(u_long128 *) out->
vertex[2] = *(u_long128 *) vertex[cpoly->
vertex[2]];
411 if (min_x > tri_max[0] || min_y > tri_max[1] || min_z > tri_max[2]) {
415 if (max_x < tri_min[0] || max_y < tri_min[1] || max_z < tri_min[2]) {
429int CCollisionMDT::PickUpNearPoly(
CCPoly *poly,
const CBoxVu0 &box) {
435 if (box.
min[0] >
max[0]) {
439 if (box.
min[1] >
max[1]) {
443 if (box.
min[2] >
max[2]) {
447 if (box.
max[0] <
min[0]) {
451 if (box.
max[1] <
min[1]) {
455 if (box.
max[2] <
min[2]) {
461 bound.
max[0] = box.
max[0];
462 bound.
max[1] = box.
max[1];
463 bound.
max[2] = box.
max[2];
464 bound.
min[0] = box.
min[0];
465 bound.
min[1] = box.
min[1];
466 bound.
min[2] = box.
min[2];
468 vu_hold_box(bound.
max, bound.
min);
472 for (i = 0; i < this->
mesh_count; i++, box_poly++) {
473 if (vu_box_missed(box_poly->
box.
max, box_poly->
box.
min) == 0) {
488int CCollisionMDT::PickUpNearPoly(
CCPoly *poly) {
491 sceVu0FVECTOR *vertex;
501 for (i = 0; i < set->
num; i++) {
502 *(u_long128 *) poly->
vertex[0] = *(u_long128 *) vertex[cpoly->
vertex[0]];
503 *(u_long128 *) poly->
vertex[1] = *(u_long128 *) vertex[cpoly->
vertex[1]];
504 *(u_long128 *) poly->
vertex[2] = *(u_long128 *) vertex[cpoly->
vertex[2]];