Skip to content

Commit

Permalink
Fix Vector2/Vector3 order (#1272)
Browse files Browse the repository at this point in the history
* Fix Vector2/Vector3 order

* Refactor vector classes to be const and reference param consistent

* Add BETA10 annotations and fixes
  • Loading branch information
foxtacles authored Dec 24, 2024
1 parent 7c41ff4 commit c2c9c75
Show file tree
Hide file tree
Showing 26 changed files with 220 additions and 214 deletions.
2 changes: 2 additions & 0 deletions LEGO1/lego/legoomni/include/legoentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class LegoEntity : public MxEntity {
MxBool GetUnknown0x10IsSet(MxU8 p_flag) { return m_unk0x10 & p_flag; }
MxBool GetFlagsIsSet(MxU8 p_flag) { return m_flags & p_flag; }
MxU8 GetFlags() { return m_flags; }

// FUNCTION: BETA10 0x10049db0
MxFloat GetWorldSpeed() { return m_worldSpeed; }

// FUNCTION: BETA10 0x1000f2f0
Expand Down
6 changes: 3 additions & 3 deletions LEGO1/lego/legoomni/src/actors/act2actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ void Act2Actor::Animate(float p_time)
local30 -= local60;
local30.Unitize();

MxFloat dotproduct = local18.Dot(&local30, &local18);
MxFloat dotproduct = local18.Dot(local30, local18);

if (dotproduct >= 0.0) {
const MxFloat* pepperWorldPosition = roiPepper->GetWorldPosition();
Expand Down Expand Up @@ -613,9 +613,9 @@ MxU32 Act2Actor::FUN_10019700(MxFloat p_param)
col2 = col3;
col2 -= m_unk0x4c->GetROI()->GetWorldPosition();
col2.Unitize();
col0.EqualsCross(&col1, &col2);
col0.EqualsCross(col1, col2);
col0.Unitize();
col1.EqualsCross(&col2, &col0);
col1.EqualsCross(col2, col0);

assert(!m_cameraFlag);

Expand Down
24 changes: 12 additions & 12 deletions LEGO1/lego/legoomni/src/actors/act3actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,16 @@ void Act3Cop::ParseAction(char* p_extra)

for (MxS32 j = 0; j < boundary->GetNumEdges(); j++) {
Mx4DPointFloat* edgeNormal = boundary->GetEdgeNormal(j);
if (point.Dot(edgeNormal, &point) + edgeNormal->index_operator(3) < -0.001) {
if (point.Dot(*edgeNormal, point) + edgeNormal->index_operator(3) < -0.001) {
MxTrace("Bad Act3 cop destination %d\n", i);
break;
}
}

Mx4DPointFloat* boundary0x14 = boundary->GetUnknown0x14();

if (point.Dot(&point, boundary0x14) + boundary0x14->index_operator(3) <= 0.001 &&
point.Dot(&point, boundary0x14) + boundary0x14->index_operator(3) >= -0.001) {
if (point.Dot(point, *boundary0x14) + boundary0x14->index_operator(3) <= 0.001 &&
point.Dot(point, *boundary0x14) + boundary0x14->index_operator(3) >= -0.001) {
continue;
}

Expand Down Expand Up @@ -496,9 +496,9 @@ MxResult Act3Cop::FUN_10040360()
v3 = v4;
v3 -= vecUnk;
v3.Unitize();
v1.EqualsCross(&v2, &v3);
v1.EqualsCross(v2, v3);
v1.Unitize();
v2.EqualsCross(&v3, &v1);
v2.EqualsCross(v3, v1);

VTable0x9c();
}
Expand Down Expand Up @@ -628,9 +628,9 @@ void Act3Brickster::Animate(float p_time)
localc = local20;
localc -= m_pInfo->m_position;
localc.Unitize();
local14.EqualsCross(&local28, &localc);
local14.EqualsCross(local28, localc);
local14.Unitize();
local28.EqualsCross(&localc, &local14);
local28.EqualsCross(localc, local14);

assert(!m_cameraFlag);

Expand Down Expand Up @@ -675,9 +675,9 @@ void Act3Brickster::Animate(float p_time)

local80 -= m_unk0x3c;
local80.Unitize();
local88.EqualsCross(&local9c, &local80);
local88.EqualsCross(local9c, local80);
local88.Unitize();
local9c.EqualsCross(&local80, &local88);
local9c.EqualsCross(local80, local88);

assert(!m_cameraFlag);

Expand Down Expand Up @@ -991,9 +991,9 @@ MxResult Act3Brickster::FUN_100417c0()
v3 = v4;
v3 -= vecUnk;
v3.Unitize();
v1.EqualsCross(&v2, &v3);
v1.EqualsCross(v2, v3);
v1.Unitize();
v2.EqualsCross(&v3, &v1);
v2.EqualsCross(v3, v1);

VTable0x9c();

Expand Down Expand Up @@ -1087,7 +1087,7 @@ MxS32 Act3Brickster::FUN_10042300()
local18 = local64[local1c];
local18 -= local38;

if (maxE == NULL || (local18.Dot(&local94, &local18) < 0.0f && local78 < local98)) {
if (maxE == NULL || (local18.Dot(local94, local18) < 0.0f && local78 < local98)) {
maxE = e;
m_boundary = boundaries[i];
local78 = local98;
Expand Down
14 changes: 7 additions & 7 deletions LEGO1/lego/legoomni/src/actors/act3ammo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,20 +227,20 @@ MxResult Act3Ammo::FUN_10053db0(float p_param1, const Matrix4& p_param2)

local14[1] = local14[2] = 0.0f;
local14[0] = 1.0f;
local3c.EqualsCross(&localc, &local14);
local3c.EqualsCross(localc, local14);

if (local3c.Unitize() != 0) {
local14[0] = local14[1] = 0.0f;
local14[2] = 1.0f;
local3c.EqualsCross(&localc, &local14);
local3c.EqualsCross(localc, local14);

if (local3c.Unitize() != 0) {
assert(0);
return FAILURE;
}
}

local14.EqualsCross(&local3c, &localc);
local14.EqualsCross(local3c, localc);
return SUCCESS;
}

Expand Down Expand Up @@ -340,17 +340,17 @@ void Act3Ammo::Animate(float p_time)
local184 = *m_boundary->GetUnknown0x14();
local17c[0] = 1.0f;
local17c[1] = local17c[2] = 0.0f;
local174.EqualsCross(&local17c, &local184);
local174.EqualsCross(local17c, local184);
local174.Unitize();
local17c.EqualsCross(&local184, &local174);
local17c.EqualsCross(local184, local174);
}
else {
local17c = *m_boundary->GetUnknown0x14();
local184[0] = 1.0f;
local184[1] = local184[2] = 0.0f;
local174.EqualsCross(&local17c, &local184);
local174.EqualsCross(local17c, local184);
local174.Unitize();
local184.EqualsCross(&local174, &local17c);
local184.EqualsCross(local174, local17c);
}
}

Expand Down
8 changes: 4 additions & 4 deletions LEGO1/lego/legoomni/src/actors/helicopter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ MxLong Helicopter::HandleControl(LegoControlManagerNotificationParam& p_param)
Mx3DPointFloat v68, va4, up;
Mx3DPointFloat v90(0, 1, 0);
v68 = m_world->GetCamera()->GetWorldUp();
va4.EqualsCross(&v68, &direction);
up.EqualsCross(&va4, &v90);
va4.EqualsCross(v68, direction);
up.EqualsCross(va4, v90);

if (isPizza) {
if (((Act3*) m_world)->ShootPizza(m_pathController, location, direction, up) != SUCCESS) {
Expand Down Expand Up @@ -457,9 +457,9 @@ void Helicopter::FUN_100042a0(const Matrix4& p_matrix)
vec5[0] = vec5[2] = 0.0f;
vec5[1] = -1.0f;

vec3.EqualsCross(&vec4, &vec5);
vec3.EqualsCross(vec4, vec5);
vec3.Unitize();
vec4.EqualsCross(&vec5, &vec3);
vec4.EqualsCross(vec5, vec3);
vec6 = vec2;

local90 = m_unk0x1a8;
Expand Down
4 changes: 2 additions & 2 deletions LEGO1/lego/legoomni/src/actors/islepathactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void IslePathActor::Exit()
for (j = 0; j < m_boundary->GetNumEdges(); j++) {
Mx4DPointFloat& normal = *m_boundary->GetEdgeNormal(j);

if (local20.Dot(&normal, &local20) + normal[3] < -0.001) {
if (local20.Dot(normal, local20) + normal[3] < -0.001) {
break;
}
}
Expand Down Expand Up @@ -645,7 +645,7 @@ void IslePathActor::FUN_1001b660()
Vector3 up(transform[2]);

up *= -1.0f;
position.EqualsCross(&direction, &up);
position.EqualsCross(direction, up);
m_roi->FUN_100a58f0(transform);
m_roi->VTable0x14();
}
2 changes: 1 addition & 1 deletion LEGO1/lego/legoomni/src/build/legocarbuildpresenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ void LegoCarBuildAnimPresenter::RotateAroundYAxis(MxFloat p_angle)
Mx4DPointFloat newRotation;

additionalRotation.NormalizeQuaternion();
newRotation.EqualsHamiltonProduct(&currentRotation, &additionalRotation);
newRotation.EqualsHamiltonProduct(currentRotation, additionalRotation);

if (newRotation[3] < 0.9999) {
rotationKey->FUN_100739a0(TRUE);
Expand Down
4 changes: 2 additions & 2 deletions LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,7 @@ MxU16 LegoAnimationManager::FUN_10062110(
if (GetViewManager()->IsBoundingBoxInFrustum(p_roi->GetWorldBoundingBox())) {
Mx3DPointFloat direction(p_roi->GetWorldDirection());

if (direction.Dot(&direction, &p_direction) > 0.707) {
if (direction.Dot(direction, p_direction) > 0.707) {
Mx3DPointFloat position(p_roi->GetWorldPosition());

position -= p_position;
Expand Down Expand Up @@ -2525,7 +2525,7 @@ MxBool LegoAnimationManager::FUN_10064120(LegoLocation::Boundary* p_boundary, Mx
for (i = 0; i < numEdges; i++) {
e = (LegoUnknown100db7f4*) boundary->GetEdges()[i];
e->FUN_1002ddc0(*boundary, vec);
float dot = vec.Dot(&direction, &vec);
float dot = vec.Dot(direction, vec);

if (dot > local4c) {
local50 = e;
Expand Down
6 changes: 3 additions & 3 deletions LEGO1/lego/legoomni/src/common/legobuildingmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ MxResult LegoBuildingManager::FUN_10030630()
for (MxS32 j = 0; j < boundary->GetNumEdges(); j++) {
Mx4DPointFloat* normal = boundary->GetEdgeNormal(j);

if (position.Dot(normal, &position) + (*normal).index_operator(3) < -0.001) {
if (position.Dot(*normal, position) + (*normal).index_operator(3) < -0.001) {
MxTrace(
"Building %d shot location (%g, %g, %g) is not in boundary %s.\n",
i,
Expand All @@ -826,8 +826,8 @@ MxResult LegoBuildingManager::FUN_10030630()
if (g_buildingInfo[i].m_boundary != NULL) {
Mx4DPointFloat& unk0x14 = *g_buildingInfo[i].m_boundary->GetUnknown0x14();

if (position.Dot(&position, &unk0x14) + unk0x14.index_operator(3) > 0.001 ||
position.Dot(&position, &unk0x14) + unk0x14.index_operator(3) < -0.001) {
if (position.Dot(position, unk0x14) + unk0x14.index_operator(3) > 0.001 ||
position.Dot(position, unk0x14) + unk0x14.index_operator(3) < -0.001) {

g_buildingInfo[i].m_y =
-((position[0] * unk0x14.index_operator(0) + unk0x14.index_operator(3) +
Expand Down
6 changes: 3 additions & 3 deletions LEGO1/lego/legoomni/src/common/legoplantmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ MxResult LegoPlantManager::FUN_10026410()
for (MxS32 j = 0; j < boundary->GetNumEdges(); j++) {
Mx4DPointFloat* normal = boundary->GetEdgeNormal(j);

if (position.Dot(normal, &position) + (*normal).index_operator(3) < -0.001) {
if (position.Dot(*normal, position) + (*normal).index_operator(3) < -0.001) {
MxTrace(
"Plant %d shot location (%g, %g, %g) is not in boundary %s.\n",
i,
Expand All @@ -162,8 +162,8 @@ MxResult LegoPlantManager::FUN_10026410()
if (g_plantInfo[i].m_boundary != NULL) {
Mx4DPointFloat& unk0x14 = *g_plantInfo[i].m_boundary->GetUnknown0x14();

if (position.Dot(&position, &unk0x14) + unk0x14.index_operator(3) > 0.001 ||
position.Dot(&position, &unk0x14) + unk0x14.index_operator(3) < -0.001) {
if (position.Dot(position, unk0x14) + unk0x14.index_operator(3) > 0.001 ||
position.Dot(position, unk0x14) + unk0x14.index_operator(3) < -0.001) {

g_plantInfo[i].m_y =
-((position[0] * unk0x14.index_operator(0) + unk0x14.index_operator(3) +
Expand Down
2 changes: 1 addition & 1 deletion LEGO1/lego/legoomni/src/entity/legojetskiraceactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ MxS32 LegoJetskiRaceActor::VTable0x1c(LegoPathBoundary* p_boundary, LegoEdge* p_
LERP3(a, *v1, *v2, m_unk0xe4);

m_destEdge->FUN_1002ddc0(*m_boundary, bbb);
c.EqualsCross(&bbb, m_boundary->GetUnknown0x14());
c.EqualsCross(bbb, *m_boundary->GetUnknown0x14());
c.Unitize();

Mx3DPointFloat worldDirection(m_roi->GetWorldDirection());
Expand Down
40 changes: 17 additions & 23 deletions LEGO1/lego/legoomni/src/paths/legoextraactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ MxResult LegoExtraActor::FUN_1002aae0()
Vector3 positionRef(m_unk0xec[3]);

dirRef *= -1.0f;
rightRef.EqualsCross(&upRef, &dirRef);
rightRef.EqualsCross(upRef, dirRef);

if (m_boundary == m_destEdge->m_faceA) {
m_boundary = (LegoPathBoundary*) m_destEdge->m_faceB;
Expand Down Expand Up @@ -191,9 +191,10 @@ inline void LegoExtraActor::FUN_1002ad8a()
}

// FUNCTION: LEGO1 0x1002aba0
// FUNCTION: BETA10 0x1008114a
MxResult LegoExtraActor::HitActor(LegoPathActor* p_actor, MxBool p_bool)
{
if (p_actor->GetActorState() != c_initial || m_actorState != c_initial) {
if (p_actor->GetActorState() != c_initial || GetActorState() != c_initial) {
return FAILURE;
}

Expand Down Expand Up @@ -222,7 +223,7 @@ MxResult LegoExtraActor::HitActor(LegoPathActor* p_actor, MxBool p_bool)
for (MxS32 i = 0; i < m_boundary->GetNumEdges(); i++) {
Mx4DPointFloat* normal = m_boundary->GetEdgeNormal(i);

if (positionRef.Dot(normal, &positionRef) + (*normal)[3] < -0.001) {
if (positionRef.Dot(*normal, positionRef) + normal->index_operator(3) < -0.001) {
b = TRUE;
break;
}
Expand All @@ -232,41 +233,34 @@ MxResult LegoExtraActor::HitActor(LegoPathActor* p_actor, MxBool p_bool)
m_roi->FUN_100a58f0(matrix2);
m_roi->VTable0x14();
FUN_1002ad8a();
assert(m_roi);
assert(SoundManager()->GetCacheSoundManager());
SoundManager()->GetCacheSoundManager()->Play("crash5", m_roi->GetName(), FALSE);
m_scheduledTime = Timer()->GetTime() + m_disAnim->GetDuration();
m_prevWorldSpeed = m_worldSpeed;
m_prevWorldSpeed = GetWorldSpeed();
VTable0xc4();
SetWorldSpeed(0);
m_whichAnim = 1;
m_actorState = c_one | c_noCollide;
SetActorState(c_one | c_noCollide);
}
}

if (b) {
LegoROI* roi = m_roi;
LegoROI* roi = GetROI();
assert(roi);
SoundManager()->GetCacheSoundManager()->Play("crash5", m_roi->GetName(), FALSE);
VTable0xc4();
m_actorState = c_two | c_noCollide;
SetActorState(c_two | c_noCollide);
Mx3DPointFloat dir = p_actor->GetWorldDirection();
MxMatrix matrix3 = MxMatrix(roi->GetLocal2World());
Vector3 positionRef(matrix3[3]);
positionRef += g_unk0x10104c18;
roi->FUN_100a58f0(matrix3);

#ifdef COMPAT_MODE
float dotX, dotZ;
{
Mx3DPointFloat tmp(1.0f, 0, 0);
dotX = dir.Dot(&dir, &tmp);
Mx3DPointFloat tmp2(0, 0, 1.0f);
dotZ = dir.Dot(&dir, &tmp2);
}
#else
float dotX = dir.Dot(&dir, &Mx3DPointFloat(1.0f, 0, 0));
float dotZ = dir.Dot(&dir, &Mx3DPointFloat(0, 0, 1.0f));
#endif
float dotX = dir.Dot(dir, Mx3DPointFloat(1.0f, 0, 0));
float dotZ = dir.Dot(dir, Mx3DPointFloat(0, 0, 1.0f));

if (abs(dotZ) < abs(dotX)) {
if (fabs(dotZ) < fabs(dotX)) {
m_axis = dotX > 0.0 ? e_posz : e_negz;
}
else {
Expand Down Expand Up @@ -463,9 +457,9 @@ MxU32 LegoExtraActor::VTable0x6c(
Mx3DPointFloat local54(p_v1);

local54 -= local60;
float local1c = p_v2.Dot(&p_v2, &p_v2);
float local24 = p_v2.Dot(&p_v2, &local54) * 2.0f;
float local20 = local54.Dot(&local54, &local54);
float local1c = p_v2.Dot(p_v2, p_v2);
float local24 = p_v2.Dot(p_v2, local54) * 2.0f;
float local20 = local54.Dot(local54, local54);

if (m_unk0x15 != 0 && local20 < 10.0f) {
return 0;
Expand Down
Loading

0 comments on commit c2c9c75

Please sign in to comment.