Skip to content

Commit

Permalink
Fixes for GetAltitudeRelTo, GetGroundPosition and frameBody
Browse files Browse the repository at this point in the history
Fixes for this issues:
1. GetAltitudeRelTo using player pos no matter what first argument is passed;
2. GetGroundPosition returns nil when not in the rotating frame of ref;
3. Access violation for all three functions when body doesn't have frame of ref (ex. when ship is hyperspacing).
  • Loading branch information
Max5377 committed Oct 10, 2023
1 parent 86153e7 commit 3730917
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/lua/LuaBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,9 @@ static int l_body_get_position_rel_to(lua_State *l)

static int l_body_get_altitude_rel_to(lua_State *l)
{
Body* b = LuaObject<Body>::CheckFromLua(1);
const Body *other = LuaObject<Body>::CheckFromLua(2);
vector3d pos = Pi::player->GetPositionRelTo(other);
vector3d pos = b->GetPositionRelTo(other);
double center_dist = pos.Length();
if (other && other->IsType(ObjectType::TERRAINBODY)) {
const TerrainBody *terrain = static_cast<const TerrainBody *>(other);
Expand Down Expand Up @@ -493,6 +494,11 @@ static int l_body_attr_frame_body(lua_State *l)
}

Frame *f = Frame::GetFrame(b->GetFrame());
if (f == nullptr)
{
lua_pushnil(l);
return 1;
}
LuaObject<Body>::PushToLua(f->GetBody());
return 1;
}
Expand Down Expand Up @@ -636,8 +642,11 @@ static int l_body_get_ground_position(lua_State *l)
}

Frame *f = Frame::GetFrame(b->GetFrame());
if (!f->IsRotFrame())
return 0;
if (f == nullptr)
{
lua_pushnil(l);
return 1;
}

vector3d pos = b->GetPosition();
double latitude = atan2(pos.y, sqrt(pos.x * pos.x + pos.z * pos.z));
Expand Down

0 comments on commit 3730917

Please sign in to comment.