celestia/src/celengine/nebula.cpp

127 lines
2.7 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.
#include "celestia.h"
#include "vecgl.h"
#include "render.h"
#include "astro.h"
#include "nebula.h"
#include "meshmanager.h"
#include "rendcontext.h"
#include <celmath/mathlib.h>
#include <celutil/util.h>
#include <celutil/debug.h>
#include <algorithm>
#include <cstdio>
2009-07-24 18:28:19 -06:00
using namespace Eigen;
using namespace std;
const char* Nebula::getType() const
{
return "Nebula";
}
void Nebula::setType(const string& /*typeStr*/)
{
}
size_t Nebula::getDescription(char* buf, size_t bufLength) const
{
return snprintf(buf, bufLength, _("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 Ray3d& 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);
}
bool Nebula::load(AssociativeArray* params, const string& resPath)
{
string geometryFileName;
if (params->getString("Mesh", geometryFileName))
{
ResourceHandle geometryHandle =
GetGeometryManager()->getHandle(GeometryInfo(geometryFileName, resPath));
setGeometry(geometryHandle);
}
return DeepSkyObject::load(params, resPath);
}
void Nebula::render(const GLContext& glcontext,
const Vector3f& /*unused*/,
const Quaternionf& /*unused*/,
float /*unused*/,
float pixelSize)
{
Geometry* g = nullptr;
if (geometry != InvalidResource)
g = GetGeometryManager()->find(geometry);
if (g == nullptr)
return;
glDisable(GL_BLEND);
glScalef(getRadius(), getRadius(), getRadius());
glRotate(getOrientation());
if (glcontext.getRenderPath() == GLContext::GLPath_GLSL)
{
GLSLUnlit_RenderContext rc(getRadius());
rc.setPointScale(2.0f * getRadius() / pixelSize);
g->render(rc);
glUseProgram(0);
}
else
{
2018-09-25 15:15:57 -06:00
assert(glcontext.getRenderPath() != GLContext::GLPath_GLSL);
}
glEnable(GL_BLEND);
}
unsigned int Nebula::getRenderMask() const
{
return Renderer::ShowNebulae;
}
unsigned int Nebula::getLabelMask() const
{
return Renderer::NebulaLabels;
}