Skip to content

Commit

Permalink
Clean up matrix3x3
Browse files Browse the repository at this point in the history
  • Loading branch information
John Jordan committed Dec 16, 2012
1 parent 059e280 commit 18f14a4
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 104 deletions.
2 changes: 1 addition & 1 deletion src/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void Body::OrientOnSurface(double radius, double latitude, double longitude)
SetPosition(radius * up);

vector3d right = up.Cross(vector3d(0,0,1)).Normalized();
SetOrient(matrix3x3d::BuildFromVectors(right, up));
SetOrient(matrix3x3d::FromVectors(right, up));
}

void Body::SwitchToFrame(Frame *newFrame)
Expand Down
4 changes: 2 additions & 2 deletions src/DynamicBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void DynamicBody::TimeStepUpdate(const float timeStep)
double len = m_angVel.Length();
if (len > 1e-16) {
vector3d axis = m_angVel * (1.0 / len);
matrix3x3d r = matrix3x3d::BuildRotate(len * timeStep, axis);
matrix3x3d r = matrix3x3d::Rotate(len * timeStep, axis);
SetOrient(r * GetOrient());
}
m_oldAngDisplacement = m_angVel * timeStep;
Expand Down Expand Up @@ -187,7 +187,7 @@ void DynamicBody::UpdateInterpTransform(double alpha)
double len = m_oldAngDisplacement.Length() * (1.0-alpha);
if (len > 1e-16) {
vector3d axis = m_oldAngDisplacement.Normalized();
matrix3x3d rot = matrix3x3d::BuildRotate(-len, axis); // rotate backwards
matrix3x3d rot = matrix3x3d::Rotate(-len, axis); // rotate backwards
m_interpOrient = rot * GetOrient();
}
else m_interpOrient = GetOrient();
Expand Down
4 changes: 2 additions & 2 deletions src/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void Frame::UpdateInterpTransform(double alpha)
double len = m_oldAngDisplacement * (1.0-alpha);
if (!is_zero_exact(len)) { // very small values are normal here
vector3d axis = vector3d(0,1,0);
matrix3x3d rot = matrix3x3d::BuildRotate(-len, axis);
matrix3x3d rot = matrix3x3d::Rotate(-len, axis);
m_interpOrient = m_orient * rot;
}
else m_interpOrient = m_orient;
Expand Down Expand Up @@ -233,7 +233,7 @@ void Frame::UpdateOrbitRails(double time, double timestep)
double ang = m_angSpeed * timestep; // hmm. cumulative inaccuracy? worse!
if (!is_zero_exact(ang)) { // frequently used with e^-10 etc
vector3d axis = vector3d(0,1,0);
matrix3x3d rot = matrix3x3d::BuildRotate(ang, axis);
matrix3x3d rot = matrix3x3d::Rotate(ang, axis);
m_orient = m_orient * rot; // angvel always +y
}
UpdateRootRelativeVars(); // update root-relative pos/vel/orient
Expand Down
2 changes: 1 addition & 1 deletion src/LuaSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ static int l_space_spawn_ship_parked(lua_State *l)
parkPos = station->GetPosition() + station->GetOrient() * parkPos;

matrix3x3d rot = station->GetOrient();
if (station->IsGroundStation()) matrix3x3d::RotateXMatrix(M_PI/2) * rot;
if (station->IsGroundStation()) matrix3x3d::RotateX(M_PI/2) * rot;

ship->SetFrame(station->GetFrame());
ship->SetVelocity(vector3d(0.0));
Expand Down
2 changes: 1 addition & 1 deletion src/Ship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ void Ship::TestLanded()

// position facing in roughly the same direction
vector3d right = up.Cross(GetOrient().VectorZ()).Normalized();
SetOrient(matrix3x3d::BuildFromVectors(right, up));
SetOrient(matrix3x3d::FromVectors(right, up));

SetVelocity(vector3d(0, 0, 0));
SetAngVelocity(vector3d(0, 0, 0));
Expand Down
2 changes: 1 addition & 1 deletion src/ShipAICmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ bool AICmdDock::TimeStepUpdate()
double ang = av * Pi::game->GetTimeStep();
if (ang > 1e-16) {
vector3d axis = m_target->GetAngVelocity().Normalized();
trot = trot * matrix3x3d::BuildRotate(ang, axis);
trot = trot * matrix3x3d::Rotate(ang, axis);
}
double af;
if (m_target->GetStationType()->dockMethod == SpaceStationType::ORBITAL)
Expand Down
2 changes: 1 addition & 1 deletion src/ShipController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void PlayerShipController::PollControls(const float timeStep, const bool manualR
m_mouseY -= mody;

if(!is_zero_general(modx) || !is_zero_general(mody)) {
matrix3x3d mrot = matrix3x3d::RotateYMatrix(modx); mrot.RotateX(mody);
matrix3x3d mrot = matrix3x3d::RotateY(modx) * matrix3x3d::RotateX(mody);
m_mouseDir = (rot * (mrot * objDir)).Normalized();
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ static void RelocateStarportIfUnderwaterOrBuried(SystemBody *sbody, Frame *frame
// try new random position
const double r2 = r.Double(); // function parameter evaluation order is implementation-dependent
const double r1 = r.Double(); // can't put two rands in the same expression
rot_ = matrix3x3d::RotateZMatrix(2*M_PI*r1)
* matrix3x3d::RotateYMatrix(2*M_PI*r2);
rot_ = matrix3x3d::RotateZ(2*M_PI*r1)
* matrix3x3d::RotateY(2*M_PI*r2);
pos_ = rot_ * vector3d(0,1,0);
}

Expand Down Expand Up @@ -487,12 +487,12 @@ static Frame *MakeFrameFor(SystemBody *sbody, Body *b, Frame *f)
// rotating frame has atmosphere radius or feature height, whichever is larger
rotFrame->SetRadius(b->GetPhysRadius());

matrix3x3d rotMatrix = matrix3x3d::RotateXMatrix(sbody->axialTilt.ToDouble());
matrix3x3d rotMatrix = matrix3x3d::RotateX(sbody->axialTilt.ToDouble());
double angSpeed = 2.0*M_PI/sbody->GetRotationPeriod();
rotFrame->SetAngSpeed(angSpeed);

if (sbody->rotationalPhaseAtStart != fixed(0))
rotMatrix = rotMatrix * matrix3x3d::RotateYMatrix(sbody->rotationalPhaseAtStart.ToDouble());
rotMatrix = rotMatrix * matrix3x3d::RotateY(sbody->rotationalPhaseAtStart.ToDouble());
rotFrame->SetOrient(rotMatrix);

b->SetFrame(rotFrame);
Expand Down
10 changes: 5 additions & 5 deletions src/SpaceStation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ void SpaceStation::PositionDockedShip(Ship *ship, int port) const
// Still in docking animation process?
if (dt.stage <= m_type->numDockingStages) {
ship->SetPosition(GetPosition() + GetOrient()*dport.pos);
matrix3x3d wantRot = matrix3x3d::BuildFromVectors(dport.xaxis, dport.yaxis);
matrix3x3d wantRot = matrix3x3d::FromVectors(dport.xaxis, dport.yaxis);
// use quaternion spherical linear interpolation to do
// rotation smoothly
Quaterniond wantQuat = Quaterniond::FromMatrix3x3(wantRot);
Expand All @@ -603,10 +603,10 @@ void SpaceStation::PositionDockedShip(Ship *ship, int port) const
if (m_type->dockMethod == SpaceStationType::ORBITAL) {
ship->SetPosition(GetPosition() + GetOrient()*dport.pos);
vector3d zaxis = dport.xaxis.Cross(dport.yaxis);
ship->SetOrient(GetOrient() * matrix3x3d::BuildFromVectors(dport.xaxis, dport.yaxis));
ship->SetOrient(GetOrient() * matrix3x3d::FromVectors(dport.xaxis, dport.yaxis));
} else {
ship->SetPosition(GetPosition() + GetOrient()*dport.pos); // + dport.yaxis));
ship->SetOrient(GetOrient() * matrix3x3d::BuildFromVectors(dport.xaxis, dport.yaxis));
ship->SetOrient(GetOrient() * matrix3x3d::FromVectors(dport.xaxis, dport.yaxis));
}
}

Expand Down Expand Up @@ -643,7 +643,7 @@ void SpaceStation::TimeStepUpdate(const float timeStep)
double len = m_type->angVel * timeStep;
if (!is_zero_exact(len)) {
vector3d axis = vector3d(0,1,0);
matrix3x3d r = matrix3x3d::BuildRotate(len, axis);
matrix3x3d r = matrix3x3d::Rotate(len, axis);
SetOrient(r * GetOrient());
}
m_oldAngDisplacement = len;
Expand All @@ -662,7 +662,7 @@ void SpaceStation::UpdateInterpTransform(double alpha)
double len = m_oldAngDisplacement * (1.0-alpha);
if (!is_zero_exact(len)) {
vector3d axis = vector3d(0,1,0);
matrix3x3d rot = matrix3x3d::BuildRotate(-len, axis); // rotate backwards
matrix3x3d rot = matrix3x3d::Rotate(-len, axis); // rotate backwards
m_interpOrient = rot * GetOrient();
}
else m_interpOrient = GetOrient();
Expand Down
32 changes: 16 additions & 16 deletions src/WorldViewCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,27 @@ void InternalCamera::SetMode(Mode m)
switch (m_mode) {
case MODE_FRONT:
m_name = Lang::CAMERA_FRONT_VIEW;
SetOrient(matrix3x3d::RotateYMatrix(M_PI*2));
SetOrient(matrix3x3d::RotateY(M_PI*2));
break;
case MODE_REAR:
m_name = Lang::CAMERA_REAR_VIEW;
SetOrient(matrix3x3d::RotateYMatrix(M_PI));
SetOrient(matrix3x3d::RotateY(M_PI));
break;
case MODE_LEFT:
m_name = Lang::CAMERA_LEFT_VIEW;
SetOrient(matrix3x3d::RotateYMatrix((M_PI/2)*3));
SetOrient(matrix3x3d::RotateY((M_PI/2)*3));
break;
case MODE_RIGHT:
m_name = Lang::CAMERA_RIGHT_VIEW;
SetOrient(matrix3x3d::RotateYMatrix(M_PI/2));
SetOrient(matrix3x3d::RotateY(M_PI/2));
break;
case MODE_TOP:
m_name = Lang::CAMERA_TOP_VIEW;
SetOrient(matrix3x3d::RotateXMatrix((M_PI/2)*3));
SetOrient(matrix3x3d::RotateX((M_PI/2)*3));
break;
case MODE_BOTTOM:
m_name = Lang::CAMERA_BOTTOM_VIEW;
SetOrient(matrix3x3d::RotateXMatrix(M_PI/2));
SetOrient(matrix3x3d::RotateX(M_PI/2));
break;
}
}
Expand Down Expand Up @@ -140,10 +140,10 @@ void ExternalCamera::UpdateTransform()
}
}
vector3d p = vector3d(0, 0, m_dist);
p = matrix3x3d::RotateXMatrix(-DEG2RAD(m_rotX)) * p;
p = matrix3x3d::RotateYMatrix(-DEG2RAD(m_rotY)) * p;
m_extOrient = matrix3x3d::RotateYMatrix(-DEG2RAD(m_rotY)) *
matrix3x3d::RotateXMatrix(-DEG2RAD(m_rotX));
p = matrix3x3d::RotateX(-DEG2RAD(m_rotX)) * p;
p = matrix3x3d::RotateY(-DEG2RAD(m_rotY)) * p;
m_extOrient = matrix3x3d::RotateY(-DEG2RAD(m_rotY)) *
matrix3x3d::RotateX(-DEG2RAD(m_rotX));
SetPosition(p);
SetOrient(m_extOrient);
}
Expand Down Expand Up @@ -173,25 +173,25 @@ SiderealCamera::SiderealCamera(const Ship *s, const vector2f &size, float fovY,
void SiderealCamera::RotateUp(float frameTime)
{
const vector3d rotAxis = m_sidOrient.VectorX();
m_sidOrient = matrix3x3d::BuildRotate(-M_PI/4 * frameTime, rotAxis) * m_sidOrient;
m_sidOrient = matrix3x3d::Rotate(-M_PI/4 * frameTime, rotAxis) * m_sidOrient;
}

void SiderealCamera::RotateDown(float frameTime)
{
const vector3d rotAxis = m_sidOrient.VectorX();
m_sidOrient = matrix3x3d::BuildRotate(M_PI/4 * frameTime, rotAxis) * m_sidOrient;
m_sidOrient = matrix3x3d::Rotate(M_PI/4 * frameTime, rotAxis) * m_sidOrient;
}

void SiderealCamera::RotateLeft(float frameTime)
{
const vector3d rotAxis = m_sidOrient.VectorY();
m_sidOrient = matrix3x3d::BuildRotate(-M_PI/4 * frameTime, rotAxis) * m_sidOrient;
m_sidOrient = matrix3x3d::Rotate(-M_PI/4 * frameTime, rotAxis) * m_sidOrient;
}

void SiderealCamera::RotateRight(float frameTime)
{
const vector3d rotAxis = m_sidOrient.VectorY();
m_sidOrient = matrix3x3d::BuildRotate(M_PI/4 * frameTime, rotAxis) * m_sidOrient;
m_sidOrient = matrix3x3d::Rotate(M_PI/4 * frameTime, rotAxis) * m_sidOrient;
}

void SiderealCamera::ZoomIn(float frameTime)
Expand Down Expand Up @@ -221,13 +221,13 @@ void SiderealCamera::ZoomEventUpdate(float frameTime)
void SiderealCamera::RollLeft(float frameTime)
{
const vector3d rotAxis = m_sidOrient.VectorZ();
m_sidOrient = matrix3x3d::BuildRotate(M_PI/4 * frameTime, rotAxis) * m_sidOrient;
m_sidOrient = matrix3x3d::Rotate(M_PI/4 * frameTime, rotAxis) * m_sidOrient;
}

void SiderealCamera::RollRight(float frameTime)
{
const vector3d rotAxis = m_sidOrient.VectorZ();
m_sidOrient = matrix3x3d::BuildRotate(-M_PI/4 * frameTime, rotAxis) * m_sidOrient;
m_sidOrient = matrix3x3d::Rotate(-M_PI/4 * frameTime, rotAxis) * m_sidOrient;
}

void SiderealCamera::Reset()
Expand Down
20 changes: 10 additions & 10 deletions src/galaxy/StarSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,8 @@ static void position_settlement_on_planet(SystemBody *b)
// used for orientation on planet surface
double r2 = r.Double(); // function parameter evaluation order is implementation-dependent
double r1 = r.Double(); // can't put two rands in the same expression
b->orbit.rotMatrix = matrix3x3d::RotateZMatrix(2*M_PI*r1) *
matrix3x3d::RotateYMatrix(2*M_PI*r2);
b->orbit.rotMatrix = matrix3x3d::RotateZ(2*M_PI*r1) *
matrix3x3d::RotateY(2*M_PI*r2);
}

double SystemBody::GetMaxChildOrbitalDistance() const
Expand Down Expand Up @@ -959,14 +959,14 @@ void StarSystem::CustomGetKidsOf(SystemBody *parent, const std::vector<CustomSys
kid->heightMapFractal = csbody->heightMapFractal;
}
if (kid->type == SystemBody::TYPE_STARPORT_SURFACE) {
kid->orbit.rotMatrix = matrix3x3d::RotateYMatrix(csbody->longitude) *
matrix3x3d::RotateXMatrix(-0.5*M_PI + csbody->latitude);
kid->orbit.rotMatrix = matrix3x3d::RotateY(csbody->longitude) *
matrix3x3d::RotateX(-0.5*M_PI + csbody->latitude);
} else {
if (kid->orbit.semiMajorAxis < 1.2 * parent->GetRadius()) {
Error("%s's orbit is too close to its parent", csbody->name.c_str());
}
double offset = csbody->want_rand_offset ? rand.Double(2*M_PI) : (csbody->orbitalOffset.ToDouble()*M_PI);
kid->orbit.rotMatrix = matrix3x3d::RotateYMatrix(offset) * matrix3x3d::RotateXMatrix(-0.5*M_PI + csbody->latitude);
kid->orbit.rotMatrix = matrix3x3d::RotateY(offset) * matrix3x3d::RotateX(-0.5*M_PI + csbody->latitude);
}
if (kid->GetSuperType() == SystemBody::SUPERTYPE_STARPORT) {
(*outHumanInfestedness)++;
Expand Down Expand Up @@ -1079,8 +1079,8 @@ void StarSystem::MakeBinaryPair(SystemBody *a, SystemBody *b, fixed minDist, MTR

const float rotX = -0.5f*float(M_PI);//(float)(rand.Double()*M_PI/2.0);
const float rotY = static_cast<float>(rand.Double(M_PI));
a->orbit.rotMatrix = matrix3x3d::RotateYMatrix(rotY) * matrix3x3d::RotateXMatrix(rotX);
b->orbit.rotMatrix = matrix3x3d::RotateYMatrix(rotY-M_PI) * matrix3x3d::RotateXMatrix(rotX);
a->orbit.rotMatrix = matrix3x3d::RotateY(rotY) * matrix3x3d::RotateX(rotX);
b->orbit.rotMatrix = matrix3x3d::RotateY(rotY-M_PI) * matrix3x3d::RotateX(rotX);

b->orbit.eccentricity = a->eccentricity.ToDouble();
b->orbit.semiMajorAxis = AU * (a->semiMajorAxis * a1).ToDouble();
Expand Down Expand Up @@ -1683,8 +1683,8 @@ void StarSystem::MakePlanetsAround(SystemBody *primary, MTRand &rand)

double r1 = rand.Double(2*M_PI); // function parameter evaluation order is implementation-dependent
double r2 = rand.NDouble(5); // can't put two rands in the same expression
planet->orbit.rotMatrix = matrix3x3d::RotateYMatrix(r1) *
matrix3x3d::RotateXMatrix(-0.5*M_PI + r2*M_PI/2.0);
planet->orbit.rotMatrix = matrix3x3d::RotateY(r1) *
matrix3x3d::RotateX(-0.5*M_PI + r2*M_PI/2.0);

planet->orbMin = periapsis;
planet->orbMax = apoapsis;
Expand Down Expand Up @@ -2133,7 +2133,7 @@ void SystemBody::PopulateAddStations(StarSystem *system)
SystemPath path2 = sp2->path;
*sp2 = *sp;
sp2->path = path2;
sp2->orbit.rotMatrix = matrix3x3d::RotateZMatrix(M_PI);
sp2->orbit.rotMatrix = matrix3x3d::RotateZ(M_PI);
sp2->name = Pi::luaNameGen->BodyName(sp2, namerand);
children.insert(children.begin(), sp2);
system->m_spaceStations.push_back(sp2);
Expand Down
Loading

0 comments on commit 18f14a4

Please sign in to comment.