void SpaceStation::Render(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; } RenderLmrModel(viewCoords, viewTransform); /* don't render city if too far away */ if (viewCoords.Length() > 1000000.0) return; // find planet Body* Planet *planet; { Body *_planet = GetFrame()->m_astroBody; if ((!_planet) || !_planet->IsType(Object::PLANET)) { // orbital spaceport -- don't make city turds } else { planet = static_cast<Planet*>(_planet); if (!m_adjacentCity) { m_adjacentCity = new CityOnPlanet(planet, this, m_sbody->seed); } m_adjacentCity->Render(this, viewCoords, viewTransform); } } }
void SpaceStation::Render(const vector3d &viewCoords, const matrix4x4d &viewTransform) { /* Well this is nice... */ static int poo=0; if (!poo) { poo = 1; LmrGetModelsWithTag("advert", s_advertModels); } // it is silly to do this every render call // // random advert models in pFlag[16 .. 19] // station name in pText[0] // docking port in pText[1] MTRand rand; rand.seed(m_sbody->seed); LmrObjParams ¶ms = GetLmrObjParams(); /* random advert models */ params.argStrings[4] = s_advertModels[rand.Int32(s_advertModels.size())]->GetName(); params.argStrings[5] = s_advertModels[rand.Int32(s_advertModels.size())]->GetName(); params.argStrings[6] = s_advertModels[rand.Int32(s_advertModels.size())]->GetName(); params.argStrings[7] = s_advertModels[rand.Int32(s_advertModels.size())]->GetName(); params.argStrings[0] = GetLabel().c_str(); SetLmrTimeParams(); for (int i=0; i<MAX_DOCKING_PORTS; i++) { params.argDoubles[ARG_STATION_BAY1_STAGE + i] = double(m_shipDocking[i].stage); params.argDoubles[ARG_STATION_BAY1_POS + i] = m_shipDocking[i].stagePos; } RenderLmrModel(viewCoords, viewTransform); /* don't render city if too far away */ if (viewCoords.Length() > 1000000.0) return; // find planet Body* Planet *planet; { Body *_planet = GetFrame()->m_astroBody; if ((!_planet) || !_planet->IsType(Object::PLANET)) { // orbital spaceport -- don't make city turds } else { planet = static_cast<Planet*>(_planet); if (!m_adjacentCity) { m_adjacentCity = new CityOnPlanet(planet, this, m_sbody->seed); } m_adjacentCity->Render(this, viewCoords, viewTransform); } } }
// 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(r, 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, GetCollMesh()->GetBoundingRadius(), viewCoords.Length(), fadeInEnd, fadeInLength, overallLighting, minIllumination); RenderLmrModel(r, 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 */ }
void Ship::Render(Graphics::Renderer *renderer, const Camera *camera, const vector3d &viewCoords, const matrix4x4d &viewTransform) { if (IsDead()) return; LmrObjParams ¶ms = GetLmrObjParams(); 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.animValues[ANIM_WHEEL_STATE] = m_wheelState; params.flightState = m_flightState; if (m_landingGearAnimation) m_landingGearAnimation->SetProgress(m_wheelState); //strncpy(params.pText[0], GetLabel().c_str(), sizeof(params.pText)); RenderLmrModel(renderer, viewCoords, viewTransform); // draw shield recharge bubble if (m_stats.shield_mass_left < m_stats.shield_mass) { const float shield = 0.01f*GetPercentShields(); renderer->SetBlendMode(Graphics::BLEND_ADDITIVE); glPushMatrix(); matrix4x4f trans = matrix4x4f::Identity(); trans.Translate(viewCoords.x, viewCoords.y, viewCoords.z); trans.Scale(GetPhysRadius()); renderer->SetTransform(trans); //fade based on strength Sfx::shieldEffect->GetMaterial()->diffuse = Color((1.0f-shield),shield,0.0,0.33f*(1.0f-shield)); Sfx::shieldEffect->Draw(renderer); glPopMatrix(); renderer->SetBlendMode(Graphics::BLEND_SOLID); } if (m_ecmRecharge > 0.0f) { // ECM effect: a cloud of particles for a sparkly 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] = vector3f(viewTransform * ( GetPosition() + GetPhysRadius() * 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; } Sfx::ecmParticle->diffuse = c; renderer->SetBlendMode(Graphics::BLEND_ALPHA_ONE); renderer->DrawPointSprites(100, v, Sfx::ecmParticle, 50.f); } }