void DynamicBody::SetMassDistributionFromModel() { LmrCollMesh *m = GetLmrCollMesh(); // XXX totally arbitrarily pick to distribute mass over a half // bounding sphere area m_massRadius = m->GetBoundingRadius()*0.5f; SetMass(m_mass); }
// Renders space station and adjacent city if applicable // For orbital starports: renders as normal // For surface starports: // Lighting: Calculates available light for model and splits light between directly and ambiently lit // Lighting is done by manipulating global lights or setting uniforms in atmospheric models shader // Adds an ambient light at close ranges if dark by manipulating the global ambient level void SpaceStation::Render(Graphics::Renderer *r, const Camera *camera, const vector3d &viewCoords, const matrix4x4d &viewTransform) { LmrObjParams ¶ms = GetLmrObjParams(); params.label = GetLabel().c_str(); SetLmrTimeParams(); for (int i=0; i<MAX_DOCKING_PORTS; i++) { params.animStages[ANIM_DOCKING_BAY_1 + i] = m_shipDocking[i].stage; params.animValues[ANIM_DOCKING_BAY_1 + i] = m_shipDocking[i].stagePos; } Body *b = GetFrame()->m_astroBody; assert(b); if (!b->IsType(Object::PLANET)) { // orbital spaceport -- don't make city turds or change lighting based on atmosphere RenderLmrModel(viewCoords, viewTransform); } else { Planet *planet = static_cast<Planet*>(b); // calculate lighting // available light is calculated and split between directly (diffusely/specularly) lit and ambiently lit const std::vector<Camera::LightSource> &lightSources = camera->GetLightSources(); double ambient, intensity; CalcLighting(planet, ambient, intensity, lightSources); std::vector<Graphics::Light> origLights, newLights; for(size_t i = 0; i < lightSources.size(); i++) { Graphics::Light light(lightSources[i].GetLight()); origLights.push_back(light); Color c = light.GetDiffuse(); Color ca = light.GetAmbient(); Color cs = light.GetSpecular(); ca.r = c.r * float(ambient); ca.g = c.g * float(ambient); ca.b = c.b * float(ambient); c.r*=float(intensity); c.g*=float(intensity); c.b*=float(intensity); cs.r*=float(intensity); cs.g*=float(intensity); cs.b*=float(intensity); light.SetDiffuse(c); light.SetAmbient(ca); light.SetSpecular(cs); newLights.push_back(light); } r->SetLights(newLights.size(), &newLights[0]); double overallLighting = ambient+intensity; // turn off global ambient color const Color oldAmbient = r->GetAmbientColor(); r->SetAmbientColor(Color::BLACK); // as the camera gets close adjust scene ambient so that intensity+ambient = minIllumination double fadeInEnd, fadeInLength, minIllumination; if (Graphics::AreShadersEnabled()) { minIllumination = 0.125; fadeInEnd = 800.0; fadeInLength = 2000.0; } else { minIllumination = 0.25; fadeInEnd = 1500.0; fadeInLength = 3000.0; } /* don't render city if too far away */ if (viewCoords.Length() < 1000000.0){ r->SetAmbientColor(Color::BLACK); if (!m_adjacentCity) { m_adjacentCity = new CityOnPlanet(planet, this, m_sbody->seed); } m_adjacentCity->Render(r, camera, this, viewCoords, viewTransform, overallLighting, minIllumination); } r->SetAmbientColor(Color::BLACK); FadeInModelIfDark(r, GetLmrCollMesh()->GetBoundingRadius(), viewCoords.Length(), fadeInEnd, fadeInLength, overallLighting, minIllumination); RenderLmrModel(viewCoords, viewTransform); // restore old lights r->SetLights(origLights.size(), &origLights[0]); // restore old ambient color r->SetAmbientColor(oldAmbient); } }
void Ship::Render(const vector3d &viewCoords, const matrix4x4d &viewTransform) { if ((!IsEnabled()) && !m_flightState) return; LmrObjParams ¶ms = GetLmrObjParams(); if ( (this != reinterpret_cast<Ship*>(Pi::player)) || (Pi::worldView->GetCamType() == WorldView::CAM_EXTERNAL) ) { m_shipFlavour.ApplyTo(¶ms); SetLmrTimeParams(); params.angthrust[0] = float(-m_angThrusters.x); params.angthrust[1] = float(-m_angThrusters.y); params.angthrust[2] = float(-m_angThrusters.z); params.linthrust[0] = float(m_thrusters.x); params.linthrust[1] = float(m_thrusters.y); params.linthrust[2] = float(m_thrusters.z); params.argDoubles[0] = m_wheelState; params.argDoubles[5] = double(m_equipment.Get(Equip::SLOT_FUELSCOOP)); params.argDoubles[6] = double(m_equipment.Get(Equip::SLOT_ENGINE)); params.argDoubles[7] = double(m_equipment.Get(Equip::SLOT_ECM)); params.argDoubles[8] = double(m_equipment.Get(Equip::SLOT_SCANNER)); params.argDoubles[9] = double(m_equipment.Get(Equip::SLOT_ATMOSHIELD)); params.argDoubles[10] = double(m_equipment.Get(Equip::SLOT_LASER, 0)); params.argDoubles[11] = double(m_equipment.Get(Equip::SLOT_LASER, 1)); for (int i=0; i<8; i++) { params.argDoubles[12+i] = double(m_equipment.Get(Equip::SLOT_MISSILE, i)); } params.argDoubles[20] = m_flightState; //strncpy(params.pText[0], GetLabel().c_str(), sizeof(params.pText)); RenderLmrModel(viewCoords, viewTransform); // draw shield recharge bubble if (m_stats.shield_mass_left < m_stats.shield_mass) { float shield = 0.01f*GetPercentShields(); glDisable(GL_LIGHTING); glEnable(GL_BLEND); glColor4f((1.0f-shield),shield,0.0,0.33f*(1.0f-shield)); glPushMatrix(); glTranslatef(GLfloat(viewCoords.x), GLfloat(viewCoords.y), GLfloat(viewCoords.z)); Render::State::UseProgram(Render::simpleShader); gluSphere(Pi::gluQuadric, GetLmrCollMesh()->GetBoundingRadius(), 20, 20); Render::State::UseProgram(0); glPopMatrix(); glEnable(GL_LIGHTING); glDisable(GL_BLEND); } } if (m_ecmRecharge > 0.0f) { // pish effect vector3f v[100]; for (int i=0; i<100; i++) { const double r1 = Pi::rng.Double()-0.5; const double r2 = Pi::rng.Double()-0.5; const double r3 = Pi::rng.Double()-0.5; v[i] = viewTransform * ( GetPosition() + GetLmrCollMesh()->GetBoundingRadius() * vector3d(r1, r2, r3).Normalized() ); } Color c(0.5,0.5,1.0,1.0); float totalRechargeTime = GetECMRechargeTime(); if (totalRechargeTime >= 0.0f) { c.a = m_ecmRecharge / totalRechargeTime; } GLuint tex = util_load_tex_rgba(PIONEER_DATA_DIR"/textures/ecm.png"); glBindTexture(GL_TEXTURE_2D, tex); Render::PutPointSprites(100, v, 50.0f, c); } #if 0 if (IsFiringLasers()) { glPushMatrix(); TransformToModelCoords(camFrame); RenderLaserfire(); glPopMatrix(); } #endif /* 0 */ }