//Note: models get some ambient colour added when dark as the camera moves closer void CityOnPlanet::Render(Graphics::Renderer *r, const Camera *camera, const SpaceStation *station, const vector3d &viewCoords, const matrix4x4d &viewTransform, double illumination, double minIllumination) { matrix4x4d rot[4]; station->GetRotMatrix(rot[0]); // change detail level if necessary if (m_detailLevel != Pi::detail.cities) { RemoveStaticGeomsFromCollisionSpace(); AddStaticGeomsToCollisionSpace(); } rot[0] = viewTransform * rot[0]; for (int i=1; i<4; i++) { rot[i] = rot[0] * matrix4x4d::RotateYMatrix(M_PI*0.5*double(i)); } const Graphics::Frustum frustum = Graphics::Frustum::FromGLState(); //modelview seems to be always identity memset(&cityobj_params, 0, sizeof(LmrObjParams)); cityobj_params.time = Pi::game->GetTime(); for (std::vector<BuildingDef>::const_iterator i = m_buildings.begin(); i != m_buildings.end(); ++i) { if (!(*i).isEnabled) continue; vector3d pos = viewTransform * (*i).pos; if (!frustum.TestPoint(pos, (*i).clipRadius)) continue; const Color oldSceneAmbientColor = r->GetAmbientColor(); // fade conditions for models double fadeInEnd, fadeInLength; if (Graphics::AreShadersEnabled()) { fadeInEnd = 10.0; fadeInLength = 500.0; } else { fadeInEnd = 2000.0; fadeInLength = 6000.0; } FadeInModelIfDark(r, (*i).clipRadius, pos.Length(), fadeInEnd, fadeInLength, illumination, minIllumination); matrix4x4f _rot; for (int e=0; e<16; e++) _rot[e] = float(rot[(*i).rotation][e]); _rot[12] = float(pos.x); _rot[13] = float(pos.y); _rot[14] = float(pos.z); (*i).model->Render(_rot, &cityobj_params); // restore old ambient colour if (illumination <= minIllumination) r->SetAmbientColor(oldSceneAmbientColor); } }
void CityOnPlanet::Render(const SpaceStation *station, const vector3d &viewCoords, const matrix4x4d &viewTransform) { matrix4x4d rot[4]; station->GetRotMatrix(rot[0]); // change detail level if necessary if (m_detailLevel != Pi::detail.cities) { RemoveStaticGeomsFromCollisionSpace(); AddStaticGeomsToCollisionSpace(); } rot[0] = viewTransform * rot[0]; for (int i=1; i<4; i++) { rot[i] = rot[0] * matrix4x4d::RotateYMatrix(M_PI*0.5*double(i)); } GetFrustum(planes); memset(&cityobj_params, 0, sizeof(LmrObjParams)); // this f*****g rubbish needs to be moved into a function cityobj_params.argDoubles[1] = Pi::GetGameTime(); cityobj_params.argDoubles[2] = Pi::GetGameTime() / 60.0; cityobj_params.argDoubles[3] = Pi::GetGameTime() / 3600.0; cityobj_params.argDoubles[4] = Pi::GetGameTime() / (24*3600.0); for (std::vector<BuildingDef>::const_iterator i = m_buildings.begin(); i != m_buildings.end(); ++i) { if (!(*i).isEnabled) continue; vector3d pos = viewTransform * (*i).pos; /* frustum cull */ bool cull = false; for (int j=0; j<6; j++) { if (planes[j].DistanceToPoint(pos)+(*i).clipRadius < 0) { cull = true; break; } } if (cull) continue; matrix4x4f _rot; for (int e=0; e<16; e++) _rot[e] = float(rot[(*i).rotation][e]); _rot[12] = float(pos.x); _rot[13] = float(pos.y); _rot[14] = float(pos.z); (*i).model->Render(_rot, &cityobj_params); } }
void CityOnPlanet::Render(Graphics::Renderer *r, const SpaceStation *station, const vector3d &viewCoords, const matrix4x4d &viewTransform) { matrix4x4d rot[4]; station->GetRotMatrix(rot[0]); // change detail level if necessary if (m_detailLevel != Pi::detail.cities) { RemoveStaticGeomsFromCollisionSpace(); AddStaticGeomsToCollisionSpace(); } rot[0] = viewTransform * rot[0]; for (int i=1; i<4; i++) { rot[i] = rot[0] * matrix4x4d::RotateYMatrix(M_PI*0.5*double(i)); } Graphics::Frustum frustum = Graphics::Frustum::FromGLState(); //modelview seems to be always identity memset(&cityobj_params, 0, sizeof(LmrObjParams)); cityobj_params.time = Pi::game->GetTime(); for (std::vector<BuildingDef>::const_iterator i = m_buildings.begin(); i != m_buildings.end(); ++i) { if (!(*i).isEnabled) continue; vector3d pos = viewTransform * (*i).pos; if (!frustum.TestPoint(pos, (*i).clipRadius)) continue; matrix4x4f _rot; for (int e=0; e<16; e++) _rot[e] = float(rot[(*i).rotation][e]); _rot[12] = float(pos.x); _rot[13] = float(pos.y); _rot[14] = float(pos.z); (*i).model->Render(_rot, &cityobj_params); } }