celestia/src/celengine/nebula.cpp

120 lines
2.6 KiB
C++
Raw Normal View History

// nebula.cpp
//
// Copyright (C) 2003, Chris Laurel <claurel@shatters.net>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
2020-06-14 10:06:05 -06:00
#include <algorithm>
#include <celmath/mathlib.h>
2020-02-13 09:21:42 -07:00
#include <celutil/gettext.h>
2020-06-14 10:06:05 -06:00
#include "astro.h"
#include "meshmanager.h"
#include "nebula.h"
#include "rendcontext.h"
#include "render.h"
#include "vecgl.h"
2009-07-24 18:28:19 -06:00
using namespace Eigen;
using namespace std;
2019-05-16 15:51:11 -06:00
using namespace celmath;
2020-05-12 09:51:25 -06:00
using namespace celestia;
const char* Nebula::getType() const
{
return "Nebula";
}
void Nebula::setType(const string& /*typeStr*/)
{
}
string Nebula::getDescription() const
{
return _("Nebula");
}
ResourceHandle Nebula::getGeometry() const
{
return geometry;
}
void Nebula::setGeometry(ResourceHandle _geometry)
{
geometry = _geometry;
}
const char* Nebula::getObjTypeName() const
{
return "nebula";
}
bool Nebula::pick(const Eigen::ParametrizedLine<double, 3>& ray,
double& distanceToPicker,
2007-01-07 17:03:07 -07:00
double& cosAngleToBoundCenter) const
{
// The preconditional sphere-ray intersection test is enough for now:
2007-01-07 17:03:07 -07:00
return DeepSkyObject::pick(ray, distanceToPicker, cosAngleToBoundCenter);
}
2019-08-15 13:21:22 -06:00
bool Nebula::load(AssociativeArray* params, const fs::path& resPath)
{
2019-08-15 13:21:22 -06:00
string t;
if (params->getString("Mesh", t))
{
2019-08-15 13:21:22 -06:00
fs::path geometryFileName(t);
ResourceHandle geometryHandle =
GetGeometryManager()->getHandle(GeometryInfo(geometryFileName, resPath));
setGeometry(geometryHandle);
}
return DeepSkyObject::load(params, resPath);
}
2020-03-29 01:35:03 -06:00
void Nebula::render(const Vector3f& /*offset*/,
const Quaternionf& /*unused*/,
float /*unused*/,
float pixelSize,
2020-05-12 09:51:25 -06:00
const Matrices& m,
2020-06-14 10:06:05 -06:00
Renderer* renderer)
{
Geometry* g = nullptr;
if (geometry != InvalidResource)
g = GetGeometryManager()->find(geometry);
if (g == nullptr)
return;
2020-06-14 10:06:05 -06:00
renderer->disableBlending();
2020-05-12 09:51:25 -06:00
Matrix4f mv = vecgl::rotate(vecgl::scale(*m.modelview, getRadius()),
getOrientation());
GLSLUnlit_RenderContext rc(renderer, getRadius(), &mv, m.projection);
rc.setPointScale(2.0f * getRadius() / pixelSize);
g->render(rc);
2020-06-14 10:06:05 -06:00
renderer->enableBlending();
}
uint64_t Nebula::getRenderMask() const
{
return Renderer::ShowNebulae;
}
unsigned int Nebula::getLabelMask() const
{
return Renderer::NebulaLabels;
}