mirror of
https://github.com/pmret/papermario.git
synced 2024-11-18 17:02:46 +01:00
parent
3746411d89
commit
f0bdf8ee09
296
src/collision.c
296
src/collision.c
@ -113,8 +113,8 @@ void load_map_hit_asset(void) {
|
|||||||
map->hitAssetCollisionOffset = uncompressedData->collisionOffset;
|
map->hitAssetCollisionOffset = uncompressedData->collisionOffset;
|
||||||
map->hitAssetZoneOffset = uncompressedData->zoneOffset;
|
map->hitAssetZoneOffset = uncompressedData->zoneOffset;
|
||||||
|
|
||||||
load_hit_data(0, uncompressedData);
|
load_hit_data(0, uncompressedData); // Colliders
|
||||||
load_hit_data(1, uncompressedData);
|
load_hit_data(1, uncompressedData); // Zones
|
||||||
|
|
||||||
heap_free(uncompressedData);
|
heap_free(uncompressedData);
|
||||||
}
|
}
|
||||||
@ -193,19 +193,20 @@ void load_hit_data(s32 idx, HitFile* hit) {
|
|||||||
map = get_current_map_header();
|
map = get_current_map_header();
|
||||||
|
|
||||||
switch (idx) {
|
switch (idx) {
|
||||||
case 0:
|
case 0: // Colliders
|
||||||
collisionOffset = map->hitAssetCollisionOffset;
|
collisionOffset = map->hitAssetCollisionOffset;
|
||||||
if (collisionOffset == 0)
|
if (collisionOffset == 0) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
assetCollisionData = (HitFileHeader*)((void*)hit + collisionOffset);
|
assetCollisionData = (HitFileHeader*)((void*)hit + collisionOffset);
|
||||||
collisionData = &gCollisionData;
|
collisionData = &gCollisionData;
|
||||||
break;
|
break;
|
||||||
|
case 1: // Zones
|
||||||
case 1:
|
|
||||||
collisionOffset = map->hitAssetZoneOffset;
|
collisionOffset = map->hitAssetZoneOffset;
|
||||||
if (collisionOffset == 0)
|
if (collisionOffset == 0) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
assetCollisionData = (HitFileHeader*)((void*)hit + collisionOffset);
|
assetCollisionData = (HitFileHeader*)((void*)hit + collisionOffset);
|
||||||
collisionData = &gZoneCollisionData;
|
collisionData = &gZoneCollisionData;
|
||||||
@ -287,12 +288,13 @@ void load_hit_data(s32 idx, HitFile* hit) {
|
|||||||
normalX = e13_y * e21_z - e13_z * e21_y;
|
normalX = e13_y * e21_z - e13_z * e21_y;
|
||||||
normalY = e13_z * e21_x - e13_x * e21_z;
|
normalY = e13_z * e21_x - e13_x * e21_z;
|
||||||
normalZ = e13_x * e21_y - e13_y * e21_x;
|
normalZ = e13_x * e21_y - e13_y * e21_x;
|
||||||
coeff = SQ(normalX) + SQ(normalY) + SQ(normalZ);
|
coeff = SQ(normalX) + SQ(normalY) + SQ(normalZ);
|
||||||
|
|
||||||
if (coeff != 0)
|
if (coeff != 0) {
|
||||||
coeff = 1.0f / sqrtf(coeff);
|
coeff = 1.0f / sqrtf(coeff);
|
||||||
else
|
} else {
|
||||||
coeff = 0.0f;
|
coeff = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
triangle->normal.x = normalX * coeff;
|
triangle->normal.x = normalX * coeff;
|
||||||
triangle->normal.y = normalY * coeff;
|
triangle->normal.y = normalY * coeff;
|
||||||
@ -330,9 +332,9 @@ void parent_collider_to_model(s16 colliderID, s16 modelIndex) {
|
|||||||
collider->vertexTable = collision_heap_malloc(vertexBufferSize * 0x18);
|
collider->vertexTable = collision_heap_malloc(vertexBufferSize * 0x18);
|
||||||
for (i = 0, vertexTable = collider->vertexTable; i < vertexBufferSize; vertexPtr++, vertexTable += 2, i++) {
|
for (i = 0, vertexTable = collider->vertexTable; i < vertexBufferSize; vertexPtr++, vertexTable += 2, i++) {
|
||||||
vertex = *vertexPtr;
|
vertex = *vertexPtr;
|
||||||
vertexTable->x = vertexTable[1].x = vertex->x;
|
vertexTable[0].x = vertexTable[1].x = vertex->x;
|
||||||
vertexTable->y = vertexTable[1].y = vertex->y;
|
vertexTable[0].y = vertexTable[1].y = vertex->y;
|
||||||
vertexTable->z = vertexTable[1].z = vertex->z;
|
vertexTable[0].z = vertexTable[1].z = vertex->z;
|
||||||
}
|
}
|
||||||
|
|
||||||
vertexTable = collider->vertexTable;
|
vertexTable = collider->vertexTable;
|
||||||
@ -348,9 +350,11 @@ void parent_collider_to_model(s16 colliderID, s16 modelIndex) {
|
|||||||
void _add_hit_vert_to_buffer(Vec3f** buf, Vec3f* vert, s32* bufSize) {
|
void _add_hit_vert_to_buffer(Vec3f** buf, Vec3f* vert, s32* bufSize) {
|
||||||
s32 i;
|
s32 i;
|
||||||
|
|
||||||
for (i = 0; i < *bufSize; i++)
|
for (i = 0; i < *bufSize; i++) {
|
||||||
if (buf[i] == vert)
|
if (buf[i] == vert) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (i == *bufSize) {
|
if (i == *bufSize) {
|
||||||
buf[i] = vert;
|
buf[i] = vert;
|
||||||
@ -449,10 +453,11 @@ void update_collider_transform(s16 colliderID) {
|
|||||||
normalZ = e13_x * e21_y - e13_y * e21_x;
|
normalZ = e13_x * e21_y - e13_y * e21_x;
|
||||||
coeff = SQ(normalX) + SQ(normalY) + SQ(normalZ);
|
coeff = SQ(normalX) + SQ(normalY) + SQ(normalZ);
|
||||||
|
|
||||||
if (coeff != 0)
|
if (coeff != 0) {
|
||||||
coeff = 1.0f / sqrtf(coeff);
|
coeff = 1.0f / sqrtf(coeff);
|
||||||
else
|
} else {
|
||||||
coeff = 0.0f;
|
coeff = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
triangle->normal.x = normalX * coeff;
|
triangle->normal.x = normalX * coeff;
|
||||||
triangle->normal.y = normalY * coeff;
|
triangle->normal.y = normalY * coeff;
|
||||||
@ -505,49 +510,68 @@ s32 test_ray_triangle_general(ColliderTriangle* triangle, Vec3f* vertices) {
|
|||||||
triangle->normal.z * (gCollisionRayStartZ - v1->z);
|
triangle->normal.z * (gCollisionRayStartZ - v1->z);
|
||||||
|
|
||||||
if (triangle->oneSided) {
|
if (triangle->oneSided) {
|
||||||
if (distToTrianglePlane < 0)
|
if (distToTrianglePlane < 0) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (triangle->normal.x * gCollisionRayDirX + triangle->normal.y * gCollisionRayDirY + triangle->normal.z * gCollisionRayDirZ >= 0)
|
if (triangle->normal.x * gCollisionRayDirX + triangle->normal.y * gCollisionRayDirY + triangle->normal.z * gCollisionRayDirZ >= 0) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if ((gCollisionRayStartX - v1->x) * (triangle->e13.z * gCollisionRayDirY - triangle->e13.y * gCollisionRayDirZ) +
|
if ((gCollisionRayStartX - v1->x) * (triangle->e13.z * gCollisionRayDirY - triangle->e13.y * gCollisionRayDirZ) +
|
||||||
(gCollisionRayStartY - v1->y) * (triangle->e13.x * gCollisionRayDirZ - triangle->e13.z * gCollisionRayDirX) +
|
(gCollisionRayStartY - v1->y) * (triangle->e13.x * gCollisionRayDirZ - triangle->e13.z * gCollisionRayDirX) +
|
||||||
(gCollisionRayStartZ - v1->z) * (triangle->e13.y * gCollisionRayDirX - triangle->e13.x * gCollisionRayDirY) < 0)
|
(gCollisionRayStartZ - v1->z) * (triangle->e13.y * gCollisionRayDirX - triangle->e13.x * gCollisionRayDirY) < 0)
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if ((gCollisionRayStartX - v2->x) * (triangle->e21.z * gCollisionRayDirY - triangle->e21.y * gCollisionRayDirZ) +
|
if ((gCollisionRayStartX - v2->x) * (triangle->e21.z * gCollisionRayDirY - triangle->e21.y * gCollisionRayDirZ) +
|
||||||
(gCollisionRayStartY - v2->y) * (triangle->e21.x * gCollisionRayDirZ - triangle->e21.z * gCollisionRayDirX) +
|
(gCollisionRayStartY - v2->y) * (triangle->e21.x * gCollisionRayDirZ - triangle->e21.z * gCollisionRayDirX) +
|
||||||
(gCollisionRayStartZ - v2->z) * (triangle->e21.y * gCollisionRayDirX - triangle->e21.x * gCollisionRayDirY) < 0)
|
(gCollisionRayStartZ - v2->z) * (triangle->e21.y * gCollisionRayDirX - triangle->e21.x * gCollisionRayDirY) < 0)
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if ((gCollisionRayStartX - v3->x) * (triangle->e32.z * gCollisionRayDirY - triangle->e32.y * gCollisionRayDirZ) +
|
if ((gCollisionRayStartX - v3->x) * (triangle->e32.z * gCollisionRayDirY - triangle->e32.y * gCollisionRayDirZ) +
|
||||||
(gCollisionRayStartY - v3->y) * (triangle->e32.x * gCollisionRayDirZ - triangle->e32.z * gCollisionRayDirX) +
|
(gCollisionRayStartY - v3->y) * (triangle->e32.x * gCollisionRayDirZ - triangle->e32.z * gCollisionRayDirX) +
|
||||||
(gCollisionRayStartZ - v3->z) * (triangle->e32.y * gCollisionRayDirX - triangle->e32.x * gCollisionRayDirY) < 0)
|
(gCollisionRayStartZ - v3->z) * (triangle->e32.y * gCollisionRayDirX - triangle->e32.x * gCollisionRayDirY) < 0)
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((triangle->normal.x * gCollisionRayDirX + triangle->normal.y * gCollisionRayDirY + triangle->normal.z * gCollisionRayDirZ) * distToTrianglePlane >= 0)
|
if ((triangle->normal.x * gCollisionRayDirX + triangle->normal.y * gCollisionRayDirY + triangle->normal.z * gCollisionRayDirZ) * distToTrianglePlane >= 0) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (((gCollisionRayStartX - v1->x) * (triangle->e13.z * gCollisionRayDirY - triangle->e13.y * gCollisionRayDirZ) +
|
if (((gCollisionRayStartX - v1->x) * (triangle->e13.z * gCollisionRayDirY - triangle->e13.y * gCollisionRayDirZ) +
|
||||||
(gCollisionRayStartY - v1->y) * (triangle->e13.x * gCollisionRayDirZ - triangle->e13.z * gCollisionRayDirX) +
|
(gCollisionRayStartY - v1->y) * (triangle->e13.x * gCollisionRayDirZ - triangle->e13.z * gCollisionRayDirX) +
|
||||||
(gCollisionRayStartZ - v1->z) * (triangle->e13.y * gCollisionRayDirX - triangle->e13.x * gCollisionRayDirY)) * distToTrianglePlane < 0)
|
(gCollisionRayStartZ - v1->z) * (triangle->e13.y * gCollisionRayDirX - triangle->e13.x * gCollisionRayDirY)
|
||||||
|
) * distToTrianglePlane < 0)
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (((gCollisionRayStartX - v2->x) * (triangle->e21.z * gCollisionRayDirY - triangle->e21.y * gCollisionRayDirZ) +
|
if (((gCollisionRayStartX - v2->x) * (triangle->e21.z * gCollisionRayDirY - triangle->e21.y * gCollisionRayDirZ) +
|
||||||
(gCollisionRayStartY - v2->y) * (triangle->e21.x * gCollisionRayDirZ - triangle->e21.z * gCollisionRayDirX) +
|
(gCollisionRayStartY - v2->y) * (triangle->e21.x * gCollisionRayDirZ - triangle->e21.z * gCollisionRayDirX) +
|
||||||
(gCollisionRayStartZ - v2->z) * (triangle->e21.y * gCollisionRayDirX - triangle->e21.x * gCollisionRayDirY)) * distToTrianglePlane < 0)
|
(gCollisionRayStartZ - v2->z) * (triangle->e21.y * gCollisionRayDirX - triangle->e21.x * gCollisionRayDirY)
|
||||||
|
) * distToTrianglePlane < 0)
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (((gCollisionRayStartX - v3->x) * (triangle->e32.z * gCollisionRayDirY - triangle->e32.y * gCollisionRayDirZ) +
|
if (((gCollisionRayStartX - v3->x) * (triangle->e32.z * gCollisionRayDirY - triangle->e32.y * gCollisionRayDirZ) +
|
||||||
(gCollisionRayStartY - v3->y) * (triangle->e32.x * gCollisionRayDirZ - triangle->e32.z * gCollisionRayDirX) +
|
(gCollisionRayStartY - v3->y) * (triangle->e32.x * gCollisionRayDirZ - triangle->e32.z * gCollisionRayDirX) +
|
||||||
(gCollisionRayStartZ - v3->z) * (triangle->e32.y * gCollisionRayDirX - triangle->e32.x * gCollisionRayDirY)) * distToTrianglePlane < 0)
|
(gCollisionRayStartZ - v3->z) * (triangle->e32.y * gCollisionRayDirX - triangle->e32.x * gCollisionRayDirY)
|
||||||
|
) * distToTrianglePlane < 0)
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cosAngle = triangle->normal.x * gCollisionRayDirX + triangle->normal.y * gCollisionRayDirY + triangle->normal.z * gCollisionRayDirZ;
|
cosAngle = triangle->normal.x * gCollisionRayDirX + triangle->normal.y * gCollisionRayDirY + triangle->normal.z * gCollisionRayDirZ;
|
||||||
if (gCollisionRayLength >= 0 && gCollisionRayLength <= -distToTrianglePlane / cosAngle)
|
if (gCollisionRayLength >= 0 && gCollisionRayLength <= -distToTrianglePlane / cosAngle) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
gCollisionRayLength = -distToTrianglePlane / cosAngle;
|
gCollisionRayLength = -distToTrianglePlane / cosAngle;
|
||||||
|
|
||||||
@ -568,10 +592,9 @@ s32 test_ray_triangle_down(ColliderTriangle* triangle, Vec3f* vertices) {
|
|||||||
Vec3f* v2;
|
Vec3f* v2;
|
||||||
Vec3f* v3;
|
Vec3f* v3;
|
||||||
|
|
||||||
if (triangle->normal.x == 0 &&
|
if (triangle->normal.x == 0 && triangle->normal.y == 0 && triangle->normal.z == 0) {
|
||||||
triangle->normal.y == 0 &&
|
|
||||||
triangle->normal.z == 0)
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
v1 = triangle->v1;
|
v1 = triangle->v1;
|
||||||
v2 = triangle->v2;
|
v2 = triangle->v2;
|
||||||
@ -582,37 +605,46 @@ s32 test_ray_triangle_down(ColliderTriangle* triangle, Vec3f* vertices) {
|
|||||||
triangle->normal.z * (gCollisionRayStartZ - v1->z);
|
triangle->normal.z * (gCollisionRayStartZ - v1->z);
|
||||||
|
|
||||||
if (triangle->oneSided) {
|
if (triangle->oneSided) {
|
||||||
if (distToTrianglePlane < 0)
|
if (distToTrianglePlane < 0) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (triangle->normal.y <= 0)
|
if (triangle->normal.y <= 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if ((gCollisionRayStartZ - v1->z) * triangle->e13.x - (gCollisionRayStartX - v1->x) * triangle->e13.z < 0)
|
if ((gCollisionRayStartZ - v1->z) * triangle->e13.x - (gCollisionRayStartX - v1->x) * triangle->e13.z < 0) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if ((gCollisionRayStartZ - v2->z) * triangle->e21.x - (gCollisionRayStartX - v2->x) * triangle->e21.z < 0)
|
if ((gCollisionRayStartZ - v2->z) * triangle->e21.x - (gCollisionRayStartX - v2->x) * triangle->e21.z < 0) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if ((gCollisionRayStartZ - v3->z) * triangle->e32.x - (gCollisionRayStartX - v3->x) * triangle->e32.z < 0)
|
if ((gCollisionRayStartZ - v3->z) * triangle->e32.x - (gCollisionRayStartX - v3->x) * triangle->e32.z < 0) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (triangle->normal.y * distToTrianglePlane <= 0)
|
if (triangle->normal.y * distToTrianglePlane <= 0) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (((gCollisionRayStartZ - v1->z) * triangle->e13.x - (gCollisionRayStartX - v1->x) * triangle->e13.z) * distToTrianglePlane < 0)
|
if (((gCollisionRayStartZ - v1->z) * triangle->e13.x - (gCollisionRayStartX - v1->x) * triangle->e13.z) * distToTrianglePlane < 0) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (((gCollisionRayStartZ - v2->z) * triangle->e21.x - (gCollisionRayStartX - v2->x) * triangle->e21.z) * distToTrianglePlane < 0)
|
if (((gCollisionRayStartZ - v2->z) * triangle->e21.x - (gCollisionRayStartX - v2->x) * triangle->e21.z) * distToTrianglePlane < 0) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (((gCollisionRayStartZ - v3->z) * triangle->e32.x - (gCollisionRayStartX - v3->x) * triangle->e32.z) * distToTrianglePlane < 0)
|
if (((gCollisionRayStartZ - v3->z) * triangle->e32.x - (gCollisionRayStartX - v3->x) * triangle->e32.z) * distToTrianglePlane < 0) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cosAngle = -triangle->normal.y;
|
cosAngle = -triangle->normal.y;
|
||||||
if (gCollisionRayLength >= 0 && gCollisionRayLength <= -distToTrianglePlane / cosAngle)
|
if (gCollisionRayLength >= 0 && gCollisionRayLength <= -distToTrianglePlane / cosAngle) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
gCollisionRayLength = -distToTrianglePlane / cosAngle;
|
gCollisionRayLength = -distToTrianglePlane / cosAngle;
|
||||||
|
|
||||||
@ -633,10 +665,9 @@ s32 test_ray_triangle_horizontal(ColliderTriangle* triangle, Vec3f *vertices) {
|
|||||||
Vec3f* v2;
|
Vec3f* v2;
|
||||||
Vec3f* v3;
|
Vec3f* v3;
|
||||||
|
|
||||||
if (triangle->normal.x == 0 &&
|
if (triangle->normal.x == 0 && triangle->normal.y == 0 && triangle->normal.z == 0) {
|
||||||
triangle->normal.y == 0 &&
|
|
||||||
triangle->normal.z == 0)
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
v1 = triangle->v1;
|
v1 = triangle->v1;
|
||||||
v2 = triangle->v2;
|
v2 = triangle->v2;
|
||||||
@ -647,49 +678,66 @@ s32 test_ray_triangle_horizontal(ColliderTriangle* triangle, Vec3f *vertices) {
|
|||||||
triangle->normal.z * (gCollisionRayStartZ - v1->z);
|
triangle->normal.z * (gCollisionRayStartZ - v1->z);
|
||||||
|
|
||||||
if (triangle->oneSided) {
|
if (triangle->oneSided) {
|
||||||
if (distToTrianglePlane < 0)
|
if (distToTrianglePlane < 0) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (triangle->normal.x * gCollisionRayDirX + triangle->normal.z * gCollisionRayDirZ >= 0)
|
if (triangle->normal.x * gCollisionRayDirX + triangle->normal.z * gCollisionRayDirZ >= 0) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if ((gCollisionRayStartX - v1->x) * (-triangle->e13.y * gCollisionRayDirZ) +
|
if ((gCollisionRayStartX - v1->x) * (-triangle->e13.y * gCollisionRayDirZ) +
|
||||||
(gCollisionRayStartY - v1->y) * (triangle->e13.x * gCollisionRayDirZ - triangle->e13.z * gCollisionRayDirX) +
|
(gCollisionRayStartY - v1->y) * (triangle->e13.x * gCollisionRayDirZ - triangle->e13.z * gCollisionRayDirX) +
|
||||||
(gCollisionRayStartZ - v1->z) * (triangle->e13.y * gCollisionRayDirX) < 0)
|
(gCollisionRayStartZ - v1->z) * (triangle->e13.y * gCollisionRayDirX) < 0)
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if ((gCollisionRayStartX - v2->x) * (-triangle->e21.y * gCollisionRayDirZ) +
|
if ((gCollisionRayStartX - v2->x) * (-triangle->e21.y * gCollisionRayDirZ) +
|
||||||
(gCollisionRayStartY - v2->y) * (triangle->e21.x * gCollisionRayDirZ - triangle->e21.z * gCollisionRayDirX) +
|
(gCollisionRayStartY - v2->y) * (triangle->e21.x * gCollisionRayDirZ - triangle->e21.z * gCollisionRayDirX) +
|
||||||
(gCollisionRayStartZ - v2->z) * (triangle->e21.y * gCollisionRayDirX) < 0)
|
(gCollisionRayStartZ - v2->z) * (triangle->e21.y * gCollisionRayDirX) < 0)
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if ((gCollisionRayStartX - v3->x) * (-triangle->e32.y * gCollisionRayDirZ) +
|
if ((gCollisionRayStartX - v3->x) * (-triangle->e32.y * gCollisionRayDirZ) +
|
||||||
(gCollisionRayStartY - v3->y) * (triangle->e32.x * gCollisionRayDirZ - triangle->e32.z * gCollisionRayDirX) +
|
(gCollisionRayStartY - v3->y) * (triangle->e32.x * gCollisionRayDirZ - triangle->e32.z * gCollisionRayDirX) +
|
||||||
(gCollisionRayStartZ - v3->z) * (triangle->e32.y * gCollisionRayDirX) < 0)
|
(gCollisionRayStartZ - v3->z) * (triangle->e32.y * gCollisionRayDirX) < 0)
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((triangle->normal.x * gCollisionRayDirX + triangle->normal.z * gCollisionRayDirZ) * distToTrianglePlane >= 0)
|
if ((triangle->normal.x * gCollisionRayDirX + triangle->normal.z * gCollisionRayDirZ) * distToTrianglePlane >= 0)
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (((gCollisionRayStartX - v1->x) * (-triangle->e13.y * gCollisionRayDirZ) +
|
if (((gCollisionRayStartX - v1->x) * (-triangle->e13.y * gCollisionRayDirZ) +
|
||||||
(gCollisionRayStartY - v1->y) * (triangle->e13.x * gCollisionRayDirZ - triangle->e13.z * gCollisionRayDirX) +
|
(gCollisionRayStartY - v1->y) * (triangle->e13.x * gCollisionRayDirZ - triangle->e13.z * gCollisionRayDirX) +
|
||||||
(gCollisionRayStartZ - v1->z) * (triangle->e13.y * gCollisionRayDirX)) * distToTrianglePlane < 0)
|
(gCollisionRayStartZ - v1->z) * (triangle->e13.y * gCollisionRayDirX)) * distToTrianglePlane < 0)
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (((gCollisionRayStartX - v2->x) * (-triangle->e21.y * gCollisionRayDirZ) +
|
if (((gCollisionRayStartX - v2->x) * (-triangle->e21.y * gCollisionRayDirZ) +
|
||||||
(gCollisionRayStartY - v2->y) * (triangle->e21.x * gCollisionRayDirZ - triangle->e21.z * gCollisionRayDirX) +
|
(gCollisionRayStartY - v2->y) * (triangle->e21.x * gCollisionRayDirZ - triangle->e21.z * gCollisionRayDirX) +
|
||||||
(gCollisionRayStartZ - v2->z) * (triangle->e21.y * gCollisionRayDirX)) * distToTrianglePlane < 0)
|
(gCollisionRayStartZ - v2->z) * (triangle->e21.y * gCollisionRayDirX)) * distToTrianglePlane < 0)
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (((gCollisionRayStartX - v3->x) * (-triangle->e32.y * gCollisionRayDirZ) +
|
if (((gCollisionRayStartX - v3->x) * (-triangle->e32.y * gCollisionRayDirZ) +
|
||||||
(gCollisionRayStartY - v3->y) * (triangle->e32.x * gCollisionRayDirZ - triangle->e32.z * gCollisionRayDirX) +
|
(gCollisionRayStartY - v3->y) * (triangle->e32.x * gCollisionRayDirZ - triangle->e32.z * gCollisionRayDirX) +
|
||||||
(gCollisionRayStartZ - v3->z) * (triangle->e32.y * gCollisionRayDirX)) * distToTrianglePlane < 0)
|
(gCollisionRayStartZ - v3->z) * (triangle->e32.y * gCollisionRayDirX)) * distToTrianglePlane < 0)
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cosAngle = triangle->normal.x * gCollisionRayDirX + triangle->normal.z * gCollisionRayDirZ;
|
cosAngle = triangle->normal.x * gCollisionRayDirX + triangle->normal.z * gCollisionRayDirZ;
|
||||||
if (gCollisionRayLength >= 0 && gCollisionRayLength <= -distToTrianglePlane / cosAngle)
|
if (gCollisionRayLength >= 0 && gCollisionRayLength <= -distToTrianglePlane / cosAngle) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
gCollisionRayLength = -distToTrianglePlane / cosAngle;
|
gCollisionRayLength = -distToTrianglePlane / cosAngle;
|
||||||
|
|
||||||
@ -713,8 +761,9 @@ s32 test_ray_colliders(s32 ignoreFlags, f32 startX, f32 startY, f32 startZ, f32
|
|||||||
s32 colliderID;
|
s32 colliderID;
|
||||||
f32 min_x, min_y, min_z, max_x, max_y, max_z;
|
f32 min_x, min_y, min_z, max_x, max_y, max_z;
|
||||||
|
|
||||||
if (dirX == 0 && dirY == 0 && dirZ == 0)
|
if (dirX == 0 && dirY == 0 && dirZ == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
collisionData = &gCollisionData;
|
collisionData = &gCollisionData;
|
||||||
gCollisionRayDirX = dirX;
|
gCollisionRayDirX = dirX;
|
||||||
@ -761,21 +810,29 @@ s32 test_ray_colliders(s32 ignoreFlags, f32 startX, f32 startY, f32 startZ, f32
|
|||||||
min_z > collider->aabb->max.z ||
|
min_z > collider->aabb->max.z ||
|
||||||
max_y < collider->aabb->min.y ||
|
max_y < collider->aabb->min.y ||
|
||||||
min_y > collider->aabb->max.y)
|
min_y > collider->aabb->max.y)
|
||||||
continue;
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
triangle = collider->triangleTable;
|
triangle = collider->triangleTable;
|
||||||
if (gCollisionRayDirX == 0 && gCollisionRayDirZ == 0 && gCollisionRayDirY == -1.0) {
|
if (gCollisionRayDirX == 0 && gCollisionRayDirZ == 0 && gCollisionRayDirY == -1.0) {
|
||||||
for (j = 0; j < collider->numTriangles; j++)
|
for (j = 0; j < collider->numTriangles; j++) {
|
||||||
if (test_ray_triangle_down(triangle++, collisionData->vertices))
|
if (test_ray_triangle_down(triangle++, collisionData->vertices)) {
|
||||||
colliderID = i;
|
colliderID = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (gCollisionRayDirY == 0) {
|
} else if (gCollisionRayDirY == 0) {
|
||||||
for (j = 0; j < collider->numTriangles; j++)
|
for (j = 0; j < collider->numTriangles; j++) {
|
||||||
if (test_ray_triangle_horizontal(triangle++, collisionData->vertices))
|
if (test_ray_triangle_horizontal(triangle++, collisionData->vertices)) {
|
||||||
colliderID = i;
|
colliderID = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for (j = 0; j < collider->numTriangles; j++)
|
for (j = 0; j < collider->numTriangles; j++) {
|
||||||
if (test_ray_triangle_general(triangle++, collisionData->vertices))
|
if (test_ray_triangle_general(triangle++, collisionData->vertices)) {
|
||||||
colliderID = i;
|
colliderID = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -788,8 +845,9 @@ s32 test_ray_colliders(s32 ignoreFlags, f32 startX, f32 startY, f32 startZ, f32
|
|||||||
*hitNy = gCollisionNormalY;
|
*hitNy = gCollisionNormalY;
|
||||||
*hitNz = gCollisionNormalZ;
|
*hitNz = gCollisionNormalZ;
|
||||||
return colliderID;
|
return colliderID;
|
||||||
} else
|
} else {
|
||||||
return colliderID;
|
return colliderID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s32 test_ray_zones(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 dirZ,
|
s32 test_ray_zones(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 dirZ,
|
||||||
@ -820,9 +878,11 @@ s32 test_ray_zones(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 d
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
triangle = collider->triangleTable;
|
triangle = collider->triangleTable;
|
||||||
for (j = 0; j < collider->numTriangles; j++)
|
for (j = 0; j < collider->numTriangles; j++) {
|
||||||
if (test_ray_triangle_down(triangle++, collisionData->vertices))
|
if (test_ray_triangle_down(triangle++, collisionData->vertices)) {
|
||||||
colliderID = i;
|
colliderID = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colliderID >= 0) {
|
if (colliderID >= 0) {
|
||||||
@ -834,8 +894,9 @@ s32 test_ray_zones(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 d
|
|||||||
*hitNy = gCollisionNormalY;
|
*hitNy = gCollisionNormalY;
|
||||||
*hitNz = gCollisionNormalZ;
|
*hitNz = gCollisionNormalZ;
|
||||||
return colliderID;
|
return colliderID;
|
||||||
} else
|
} else {
|
||||||
return colliderID;
|
return colliderID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
f32 test_ray_collider_horizontal(s32 ignoreFlags, s32 colliderID, f32 x, f32 y, f32 z, f32 length, f32 yaw) {
|
f32 test_ray_collider_horizontal(s32 ignoreFlags, s32 colliderID, f32 x, f32 y, f32 z, f32 length, f32 yaw) {
|
||||||
@ -904,32 +965,35 @@ s32 test_ray_entities(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f3
|
|||||||
for (i = 0; i < MAX_ENTITIES; i++) {
|
for (i = 0; i < MAX_ENTITIES; i++) {
|
||||||
entity = get_entity_by_index(i);
|
entity = get_entity_by_index(i);
|
||||||
|
|
||||||
if (entity == NULL || (entity->flags & 0x40000020))
|
if (entity == NULL || (entity->flags & 0x40000020)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
dist = hitDepthHoriz + entity->effectiveSize;
|
dist = hitDepthHoriz + entity->effectiveSize;
|
||||||
if (startX > entity->position.x + dist ||
|
if (startX > entity->position.x + dist || startX < entity->position.x - dist) {
|
||||||
startX < entity->position.x - dist)
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (startZ > entity->position.z + dist ||
|
if (startZ > entity->position.z + dist || startZ < entity->position.z - dist) {
|
||||||
startZ < entity->position.z - dist)
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
dist = entity->position.y;
|
dist = entity->position.y;
|
||||||
dist2 = hitDepthDown + entity->effectiveSize * 2;
|
dist2 = hitDepthDown + entity->effectiveSize * 2;
|
||||||
if (dist + dist2 < startY || startY < dist - dist2)
|
if (dist + dist2 < startY || startY < dist - dist2) {
|
||||||
continue;
|
continue;
|
||||||
break;
|
}
|
||||||
case 2:
|
break;
|
||||||
dist = entity->position.y;
|
case 2:
|
||||||
dist2 = entity->effectiveSize * 2;
|
dist = entity->position.y;
|
||||||
if (dist + dist2 < startY || startY < dist - dist2)
|
dist2 = entity->effectiveSize * 2;
|
||||||
continue;
|
if (dist + dist2 < startY || startY < dist - dist2) {
|
||||||
break;
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
aabbX = entity->aabb.x / 2;
|
aabbX = entity->aabb.x / 2;
|
||||||
@ -963,8 +1027,9 @@ s32 test_ray_entities(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f3
|
|||||||
triangle->normal.y = gEntityColliderNormals[j].y;
|
triangle->normal.y = gEntityColliderNormals[j].y;
|
||||||
triangle->normal.z = gEntityColliderNormals[j].z;
|
triangle->normal.z = gEntityColliderNormals[j].z;
|
||||||
|
|
||||||
if (hasCollision = test_ray_triangle_general(&entityTriangle, boxVertices))
|
if (hasCollision = test_ray_triangle_general(&entityTriangle, boxVertices)) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasCollision && gCollisionRayLength < *hitDepth) {
|
if (hasCollision && gCollisionRayLength < *hitDepth) {
|
||||||
@ -972,16 +1037,16 @@ s32 test_ray_entities(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f3
|
|||||||
*hitDepth = gCollisionRayLength;
|
*hitDepth = gCollisionRayLength;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 0:
|
case 0:
|
||||||
hitDepthDown = gCollisionRayLength;
|
hitDepthDown = gCollisionRayLength;
|
||||||
hitDepthHoriz = gCollisionRayLength;
|
hitDepthHoriz = gCollisionRayLength;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
hitDepthDown = gCollisionRayLength;
|
hitDepthDown = gCollisionRayLength;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
hitDepthHoriz = gCollisionRayLength;
|
hitDepthHoriz = gCollisionRayLength;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
guRotateF(tempMatrix1, entity->rotation.x, 1.0f, 0.0f, 0.0f);
|
guRotateF(tempMatrix1, entity->rotation.x, 1.0f, 0.0f, 0.0f);
|
||||||
@ -1013,48 +1078,49 @@ ApiStatus func_8005DB00(Evt* script, s32 isInitialCall) {
|
|||||||
playerStatus = &gPlayerStatus;
|
playerStatus = &gPlayerStatus;
|
||||||
partnerStatus = &gPartnerActionStatus;
|
partnerStatus = &gPartnerActionStatus;
|
||||||
|
|
||||||
if (isInitialCall)
|
if (isInitialCall) {
|
||||||
script->functionTemp[0] = 0;
|
script->functionTemp[0] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
switch(script->functionTemp[0]) {
|
switch(script->functionTemp[0]) {
|
||||||
case 0:
|
case 0:
|
||||||
npc->planarFlyDist = evt_get_float_variable(script, LW(0));
|
npc->planarFlyDist = evt_get_float_variable(script, LW(0));
|
||||||
npc->duration = evt_get_variable(script, LW(1));
|
npc->duration = evt_get_variable(script, LW(1));
|
||||||
script->functionTemp[1] = evt_get_variable(script, LW(2));
|
script->functionTemp[1] = evt_get_variable(script, LW(2));
|
||||||
script->functionTemp[2] = evt_get_variable(script, LW(3)) / 2;
|
script->functionTemp[2] = evt_get_variable(script, LW(3)) / 2;
|
||||||
npc->currentAnim.w = script->varTable[10];
|
npc->currentAnim.w = script->varTable[10];
|
||||||
script->functionTemp[0] = 1;
|
script->functionTemp[0] = 1;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (partnerStatus->actingPartner != PARTNER_BOW) {
|
if (partnerStatus->actingPartner != PARTNER_BOW) {
|
||||||
if (npc->duration != 0 && npc->duration != script->functionTemp[0])
|
if (npc->duration != 0 && npc->duration != script->functionTemp[0])
|
||||||
return ApiStatus_BLOCK;
|
return ApiStatus_BLOCK;
|
||||||
|
|
||||||
if (npc->duration == 0) {
|
if (npc->duration == 0) {
|
||||||
if (sqrtf(SQ((playerStatus->position.x - npc->pos.x)) +
|
if (sqrtf(SQ((playerStatus->position.x - npc->pos.x)) +
|
||||||
SQ((playerStatus->position.y - npc->pos.y)) +
|
SQ((playerStatus->position.y - npc->pos.y)) +
|
||||||
SQ((playerStatus->position.z - npc->pos.z))) <= npc->planarFlyDist) {
|
SQ((playerStatus->position.z - npc->pos.z))) <= npc->planarFlyDist) {
|
||||||
targetDir = atan2(npc->pos.x, npc->pos.z, playerStatus->position.x, playerStatus->position.z);
|
targetDir = atan2(npc->pos.x, npc->pos.z, playerStatus->position.x, playerStatus->position.z);
|
||||||
npcYaw = script->functionTemp[1] == -1 ? npc->yaw : script->functionTemp[1];
|
npcYaw = script->functionTemp[1] == -1 ? npc->yaw : script->functionTemp[1];
|
||||||
|
|
||||||
if (fabsf(get_clamped_angle_diff(npcYaw, targetDir)) < script->functionTemp[2]) {
|
if (fabsf(get_clamped_angle_diff(npcYaw, targetDir)) < script->functionTemp[2]) {
|
||||||
script->varTable[0] = 1;
|
script->varTable[0] = 1;
|
||||||
return ApiStatus_DONE2;
|
return ApiStatus_DONE2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
if (dist2D(npc->pos.x, npc->pos.z, playerStatus->position.x, playerStatus->position.z) <= npc->planarFlyDist) {
|
||||||
if (dist2D(npc->pos.x, npc->pos.z, playerStatus->position.x, playerStatus->position.z) <= npc->planarFlyDist) {
|
targetDir = atan2(npc->pos.x, npc->pos.z, playerStatus->position.x, playerStatus->position.z);
|
||||||
targetDir = atan2(npc->pos.x, npc->pos.z, playerStatus->position.x, playerStatus->position.z);
|
npcYaw = script->functionTemp[1] == -1 ? npc->yaw : script->functionTemp[1];
|
||||||
npcYaw = script->functionTemp[1] == -1 ? npc->yaw : script->functionTemp[1];
|
|
||||||
|
|
||||||
if (fabsf(get_clamped_angle_diff(npcYaw, targetDir)) < script->functionTemp[2]) {
|
if (fabsf(get_clamped_angle_diff(npcYaw, targetDir)) < script->functionTemp[2]) {
|
||||||
script->varTable[0] = 1;
|
script->varTable[0] = 1;
|
||||||
return ApiStatus_DONE2;
|
return ApiStatus_DONE2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ApiStatus_BLOCK;
|
return ApiStatus_BLOCK;
|
||||||
|
Loading…
Reference in New Issue
Block a user