#include "classes.h" // 00945190 void Capsule::constructor(Vector *position, Vector *multiplier, float rotation, float size) { float axisX; float cosRotation; Capsule CVar1; float scaledY; float fVar2; this[1] = (Capsule)0x0; *this = (Capsule)0x0; this[3] = (Capsule)0x0; this[2] = (Capsule)0x0; this[5] = (Capsule)0x0; this[4] = (Capsule)0x0; this[7] = (Capsule)0x0; this[6] = (Capsule)0x0; *this = (Capsule)position->x; this[1] = (Capsule)position->y; CVar1 = (Capsule)(size * multiplier->x); scaledY = size * multiplier->y; axisX = sin(rotation * 0.017453292); cosRotation = cos(rotation * 0.017453292); if ((float)CVar1 <= scaledY) { this[8] = CVar1; this[9] = (Capsule)(scaledY - (float)CVar1); this[6] = (Capsule)axisX; this[7] = (Capsule)cosRotation; fVar2 = cosRotation; cosRotation = axisX; } else { this[8] = (Capsule)scaledY; this[9] = (Capsule)((float)CVar1 - scaledY); this[6] = (Capsule)cosRotation; this[7] = (Capsule)axisX; fVar2 = axisX; } this[2] = (Capsule)((float)*this - (float)this[9] * cosRotation); this[3] = (Capsule)((float)this[1] - (float)this[9] * fVar2); this[5] = (Capsule)((float)this[9] * (float)this[7] + (float)this[1]); this[4] = (Capsule)((float)this[9] * (float)this[6] + (float)*this); return; } // 009452e0 void Capsule::constructor2(Vector *Position, Vector *TargetPosition, float size) { float length; float dirX; float dy; float dirY; float dx; this[3] = (Capsule)0x0; this[2] = (Capsule)0x0; this[5] = (Capsule)0x0; this[4] = (Capsule)0x0; this[1] = (Capsule)0x0; *this = (Capsule)0x0; this[7] = (Capsule)0x0; this[6] = (Capsule)0x0; this[2] = (Capsule)Position->x; this[3] = (Capsule)Position->y; this[4] = (Capsule)TargetPosition->x; this[5] = (Capsule)TargetPosition->y; dy = TargetPosition->y - Position->y; dx = TargetPosition->x - Position->x; length = sqrtf(dy * dy + dx * dx); if (length <= 0.0) { dirX = g_vectorZero.x; dirY = g_vectorZero.y; } else { dirY = dy / length; dirX = dx / length; } this[6] = (Capsule)dirX; this[7] = (Capsule)dirY; this[8] = (Capsule)size; this[9] = (Capsule)(length * 0.5); *this = (Capsule)(((float)this[4] + (float)this[2]) * 0.5); this[1] = (Capsule)(((float)this[3] + (float)this[5]) * 0.5); return; } // 00945400 void Capsule::get_bounding_box(Vector *outMin, Vector *outMax) { float extentY; float extentX; Capsule centerY; extentX = ABS((float)this[6]) * (float)this[9] + (float)this[8]; extentY = ABS((float)this[7]) * (float)this[9] + (float)this[8]; centerY = this[1]; outMin->x = (float)*this - extentX; outMin->y = (float)centerY - extentY; centerY = this[1]; outMax->x = extentX + (float)*this; outMax->y = extentY + (float)centerY; return; } // 00945470 byte Capsule::Collide(Capsule *a, Capsule *b, Vector *outHit) { Capsule *closestToA; float *closestToB; float fVar1; float fVar2; float fVar3; double dVar4; float fVar5; float fVar6; Capsule CVar7; float fVar8; float separationY; float separationX; float aStartY; float aEndX; float bStartY; float aEndY; float bEndY; float bEndX; Capsule local_3c; float bStartToAY; float aStartX; Capsule local_30; float local_2c; float aLengthSq; Capsule local_24; float bEndToAY; Capsule *local_1c; float aEndToBX; float aEndToBY; float aStartToBX; float aStartToBY; separationY = g_vectorZero.y; separationX = g_vectorZero.x; aEndX = *GHIDRA_CAST((a + 4)); aStartX = *GHIDRA_CAST((a + 2)); aStartY = *GHIDRA_CAST((a + 3)); fVar1 = aEndX - aStartX; bEndX = *GHIDRA_CAST((b + 4)); local_3c = b[2]; aEndY = *GHIDRA_CAST((a + 5)); fVar2 = aEndY - aStartY; bEndY = *GHIDRA_CAST((b + 5)); bStartY = *GHIDRA_CAST((b + 3)); fVar8 = (bEndX - (float)local_3c) * fVar2 - ((float)b[5] - bStartY) * fVar1; local_1c = a; if (fVar8 != 0.0) { fVar3 = ((aStartX - (float)local_3c) * fVar2 + ((float)b[3] - aStartY) * fVar1) / fVar8; local_2c = ((aStartY - (float)b[3]) * (bEndX - (float)local_3c) + ((float)local_3c - aStartX) * ((float)b[5] - bStartY)) / -fVar8; bEndX = *GHIDRA_CAST((b + 4)); if ((((0.0 <= fVar3) && (fVar3 <= 1.0)) && (aEndX = *GHIDRA_CAST((a + 4)), 0.0 <= local_2c)) && (local_2c <= 1.0)) { fVar5 = fVar2 * fVar3 + aStartY; fVar3 = fVar1 * fVar3 + aStartX; separationX = fVar3 - aStartX; separationY = fVar5 - aStartY; fVar8 = fVar3 - aEndX; fVar1 = separationY * separationY + separationX * separationX; local_30 = a[8]; local_24 = (Capsule)(fVar5 - (float)a[5]); fVar2 = (float)local_24 * (float)local_24 + fVar8 * fVar8; if (fVar2 < fVar1) { fVar1 = fVar2; separationY = (float)local_24; separationX = fVar8; } fVar6 = (float)local_3c - fVar3; fVar8 = (float)b[3] - fVar5; fVar2 = fVar8 * fVar8 + fVar6 * fVar6; if (fVar2 < fVar1) { local_30 = b[8]; fVar1 = fVar2; separationY = fVar8; separationX = fVar6; } fVar3 = bEndX - fVar3; fVar5 = (float)b[5] - fVar5; fVar2 = fVar5 * fVar5 + fVar3 * fVar3; if (fVar2 < fVar1) { local_30 = b[8]; fVar1 = fVar2; separationY = fVar5; separationX = fVar3; } dVar4 = (double)fVar1; if (dVar4 < 0.0) { libm_sse2_sqrt_precise(); } else { dVar4 = SQRT(dVar4); } local_24 = (Capsule)((float)dVar4 + (float)local_30); fVar1 = sqrtf(separationY * separationY + separationX * separationX); if (0.0 < fVar1) { separationX = separationX * (1.0 / fVar1); separationY = separationY * (1.0 / fVar1); } separationX = separationX * (float)local_24; separationY = separationY * (float)local_24; aStartX = *GHIDRA_CAST((a + 2)); aEndX = *GHIDRA_CAST((a + 4)); local_3c = b[2]; bEndX = *GHIDRA_CAST((b + 4)); } } if ((separationX != g_vectorZero.x) || (separationY != g_vectorZero.y)) { aEndY = (float)a[5] + separationY; aEndX = aEndX + separationX; local_3c = (Capsule)((float)local_3c + separationX); bEndX = bEndX + separationX; aStartY = aStartY + separationY; aStartX = aStartX + separationX; bEndY = (float)b[5] + separationY; bStartY = (float)b[3] + separationY; } local_30 = (Capsule)(bEndX - (float)local_3c); aStartToBY = aStartY - bStartY; fVar2 = bEndY - bStartY; fVar1 = fVar2 * fVar2 + (float)local_30 * (float)local_30; aStartToBX = aStartX - (float)local_3c; if ((0.0001 <= ABS(fVar1)) && (fVar8 = (fVar2 * aStartToBY + (float)local_30 * aStartToBX) / fVar1, 0.0 <= fVar8)) { if (fVar8 < 1.0) { aStartToBX = aStartX - ((float)local_30 * fVar8 + (float)local_3c); aStartToBY = aStartY - (fVar2 * fVar8 + bStartY); } else { aStartToBY = aStartY - bEndY; aStartToBX = aStartX - bEndX; } } aStartToBX = -aStartToBX; aEndToBX = aEndX - (float)local_3c; aEndToBY = aEndY - bStartY; aStartToBY = -aStartToBY; if ((0.0001 <= ABS(fVar1)) && (fVar1 = (fVar2 * aEndToBY + (float)local_30 * aEndToBX) / fVar1, 0.0 <= fVar1)) { if (fVar1 < 1.0) { aEndToBX = aEndX - ((float)local_30 * fVar1 + (float)local_3c); aEndToBY = aEndY - (fVar2 * fVar1 + bStartY); } else { aEndToBX = aEndX - bEndX; aEndToBY = aEndY - bEndY; } } aEndToBX = -aEndToBX; fVar1 = aEndY - aStartY; aEndToBY = -aEndToBY; fVar2 = aEndX - aStartX; aLengthSq = fVar1 * fVar1 + fVar2 * fVar2; local_2c = ABS(aLengthSq); CVar7 = (Capsule)((float)local_3c - aStartX); bStartToAY = bStartY - aStartY; if ((0.0001 <= local_2c) && (fVar8 = ((float)CVar7 * fVar2 + fVar1 * bStartToAY) / aLengthSq, 0.0 <= fVar8)) { if (fVar8 < 1.0) { CVar7 = (Capsule)((float)local_3c - (fVar2 * fVar8 + aStartX)); bStartToAY = bStartY - (fVar1 * fVar8 + aStartY); } else { CVar7 = (Capsule)((float)local_3c - aEndX); bStartToAY = bStartY - aEndY; } } local_24 = (Capsule)(bEndX - aStartX); bEndToAY = bEndY - aStartY; local_3c = CVar7; if (0.0001 <= local_2c) { local_30 = (Capsule)(fVar2 * (float)local_24 + fVar1 * bEndToAY); fVar8 = (float)local_30 / aLengthSq; if (0.0 <= fVar8) { if (fVar8 < 1.0) { local_24 = (Capsule)(bEndX - (fVar2 * fVar8 + aStartX)); bEndToAY = bEndY - (fVar1 * fVar8 + aStartY); } else { local_24 = (Capsule)(bEndX - aEndX); bEndToAY = bEndY - aEndY; } } } fVar1 = aStartToBY * aStartToBY + aStartToBX * aStartToBX; fVar3 = aEndToBY * aEndToBY + aEndToBX * aEndToBX; fVar8 = bStartToAY * bStartToAY + (float)CVar7 * (float)CVar7; fVar2 = bEndToAY * bEndToAY + (float)local_24 * (float)local_24; closestToB = &aStartToBX; if (fVar3 <= fVar1) { closestToB = &aEndToBX; fVar1 = fVar3; } closestToA = &local_24; if (fVar8 < fVar2) { closestToA = &local_3c; fVar2 = fVar8; } if (fVar2 <= fVar1) { if (outHit == GHIDRA_CAST(0x0)) goto LAB_00945cf6; outHit->x = (float)*closestToA; CVar7 = closestToA[1]; } else { fVar2 = fVar1; if (outHit == GHIDRA_CAST(0x0)) goto LAB_00945cf6; outHit->x = *closestToB; CVar7 = *GHIDRA_CAST((closestToB + 1)); } outHit->y = (float)CVar7; LAB_00945cf6: local_1c = GHIDRA_CAST(((float)local_1c[8] + (float)b[8])); if ((float)local_1c * (float)local_1c <= fVar2) { return 0; } if (fVar2 == 0.0) { if (outHit != GHIDRA_CAST(0x0)) { outHit->x = separationX; outHit->y = separationY; return 1; } } else { dVar4 = (double)fVar2; if (dVar4 < 0.0) { libm_sse2_sqrt_precise(); } else { dVar4 = SQRT(dVar4); } fVar1 = (float)dVar4; if (outHit != GHIDRA_CAST(0x0)) { outHit->x = (outHit->x / fVar1) * ((float)local_1c - fVar1) + separationX; outHit->y = (outHit->y / fVar1) * ((float)local_1c - fVar1) + separationY; } } return 1; }