void SpaceStation::Render(Graphics::Renderer *r, const Camera *camera, const vector3d &viewCoords, const matrix4x4d &viewTransform) { Body *b = GetFrame()->GetBody(); assert(b); if (!b->IsType(Object::PLANET)) { // orbital spaceport -- don't make city turds or change lighting based on atmosphere RenderModel(r, camera, viewCoords, viewTransform); r->GetStats().AddToStatCount(Graphics::Stats::STAT_SPACESTATIONS, 1); } else { // don't render city if too far away if (viewCoords.LengthSqr() >= SQRMAXCITYDIST) { return; } std::vector<Graphics::Light> oldLights; Color oldAmbient; SetLighting(r, camera, oldLights, oldAmbient); if (!m_adjacentCity) { m_adjacentCity = new CityOnPlanet(static_cast<Planet*>(b), this, m_sbody->GetSeed()); } m_adjacentCity->Render(r, camera->GetContext()->GetFrustum(), this, viewCoords, viewTransform); RenderModel(r, camera, viewCoords, viewTransform, false); ResetLighting(r, oldLights, oldAmbient); r->GetStats().AddToStatCount(Graphics::Stats::STAT_GROUNDSTATIONS, 1); } }
void CollisionSpace::CollideRaySphere(const vector3d &start, const vector3d &dir, isect_t *isect) { if (sphere.radius > 0.0) { /* Collide with lovely sphere! */ const vector3d v = start - sphere.pos; const double b = -v.Dot(dir); double det = (b * b) - v.LengthSqr() + (sphere.radius*sphere.radius); if (det > 0) { det = sqrt(det); const double i1 = b - det; const double i2 = b + det; if (i2 > 0) { /*if (i1 < 0) { if (i2 < *dist) { *dist = i2; //retval = INPRIM; retval = true; } }*/ if (i1 > 0) { if (i1 < isect->dist) { isect->dist = float(i1); isect->triIdx = 0; } } } } } }
// returns acceleration due to gravity at that point static double GetGravityAtPos(Frame *targframe, const vector3d &posoff) { Body *body = targframe->GetBodyFor(); if (!body || body->IsType(Object::SPACESTATION)) return 0; double rsqr = posoff.LengthSqr(); return G * body->GetMass() / rsqr; // inverse is: sqrt(G * m1m2 / thrust) }
/// Calculates acceleration due to gravity at given position static double GetGravityAtPos(Frame *target_frame, const vector3d &position) { Body *body = target_frame->GetBody(); if (!body || body->IsType(Object::SPACESTATION)) { return 0.0; } return G * body->GetMass() / position.LengthSqr(); // inverse is: sqrt(G * m1m2 / thrust) }