2003-01-26 19:04:46 -07:00
|
|
|
// 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"
|
2009-10-04 08:12:59 -06:00
|
|
|
#include "vecgl.h"
|
|
|
|
#include "render.h"
|
2003-01-26 19:04:46 -07:00
|
|
|
#include "astro.h"
|
|
|
|
#include "nebula.h"
|
|
|
|
#include "meshmanager.h"
|
2004-02-21 18:44:38 -07:00
|
|
|
#include "rendcontext.h"
|
2009-10-04 08:12:59 -06:00
|
|
|
#include <celmath/mathlib.h>
|
|
|
|
#include <celutil/util.h>
|
|
|
|
#include <celutil/debug.h>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cstdio>
|
2003-01-26 19:04:46 -07:00
|
|
|
|
2009-07-24 18:28:19 -06:00
|
|
|
using namespace Eigen;
|
2003-01-26 19:04:46 -07:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
2005-11-18 02:00:39 -07:00
|
|
|
const char* Nebula::getType() const
|
|
|
|
{
|
|
|
|
return "Nebula";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 12:25:32 -06:00
|
|
|
void Nebula::setType(const string& /*typeStr*/)
|
2005-11-18 02:00:39 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-21 03:22:52 -07:00
|
|
|
size_t Nebula::getDescription(char* buf, size_t bufLength) const
|
|
|
|
{
|
2009-12-12 03:06:28 -07:00
|
|
|
return snprintf(buf, bufLength, _("Nebula"));
|
2005-11-21 03:22:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-23 15:54:53 -06:00
|
|
|
ResourceHandle Nebula::getGeometry() const
|
2003-01-26 19:04:46 -07:00
|
|
|
{
|
2008-07-23 15:54:53 -06:00
|
|
|
return geometry;
|
2003-01-26 19:04:46 -07:00
|
|
|
}
|
|
|
|
|
2006-12-08 12:19:29 -07:00
|
|
|
|
2008-07-23 15:54:53 -06:00
|
|
|
void Nebula::setGeometry(ResourceHandle _geometry)
|
2003-01-26 19:04:46 -07:00
|
|
|
{
|
2008-07-23 15:54:53 -06:00
|
|
|
geometry = _geometry;
|
2003-01-26 19:04:46 -07:00
|
|
|
}
|
|
|
|
|
2007-04-02 01:55:49 -06:00
|
|
|
const char* Nebula::getObjTypeName() const
|
|
|
|
{
|
|
|
|
return "nebula";
|
|
|
|
}
|
|
|
|
|
2003-01-26 19:04:46 -07:00
|
|
|
|
2006-12-08 12:19:29 -07:00
|
|
|
bool Nebula::pick(const Ray3d& ray,
|
|
|
|
double& distanceToPicker,
|
2007-01-07 17:03:07 -07:00
|
|
|
double& cosAngleToBoundCenter) const
|
2006-12-08 12:19:29 -07:00
|
|
|
{
|
|
|
|
// The preconditional sphere-ray intersection test is enough for now:
|
2007-01-07 17:03:07 -07:00
|
|
|
return DeepSkyObject::pick(ray, distanceToPicker, cosAngleToBoundCenter);
|
2006-12-08 12:19:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-24 01:55:54 -07:00
|
|
|
bool Nebula::load(AssociativeArray* params, const string& resPath)
|
2003-01-26 19:04:46 -07:00
|
|
|
{
|
2008-07-23 15:54:53 -06:00
|
|
|
string geometryFileName;
|
|
|
|
if (params->getString("Mesh", geometryFileName))
|
2003-01-26 19:04:46 -07:00
|
|
|
{
|
2008-07-23 15:54:53 -06:00
|
|
|
ResourceHandle geometryHandle =
|
|
|
|
GetGeometryManager()->getHandle(GeometryInfo(geometryFileName, resPath));
|
|
|
|
setGeometry(geometryHandle);
|
2003-01-26 19:04:46 -07:00
|
|
|
}
|
2006-09-16 12:25:32 -06:00
|
|
|
|
2003-03-24 01:55:54 -07:00
|
|
|
return DeepSkyObject::load(params, resPath);
|
2003-01-26 19:04:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-20 11:56:18 -06:00
|
|
|
void Nebula::render(const GLContext& glcontext,
|
2018-09-22 07:13:49 -06:00
|
|
|
const Vector3f& /*unused*/,
|
|
|
|
const Quaternionf& /*unused*/,
|
|
|
|
float /*unused*/,
|
2007-04-20 11:56:18 -06:00
|
|
|
float pixelSize)
|
2003-01-26 19:04:46 -07:00
|
|
|
{
|
2018-09-22 07:13:49 -06:00
|
|
|
Geometry* g = nullptr;
|
2008-07-23 15:54:53 -06:00
|
|
|
if (geometry != InvalidResource)
|
|
|
|
g = GetGeometryManager()->find(geometry);
|
2018-09-22 07:13:49 -06:00
|
|
|
if (g == nullptr)
|
2003-01-26 19:04:46 -07:00
|
|
|
return;
|
|
|
|
|
2007-04-21 22:53:43 -06:00
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
2003-01-26 19:04:46 -07:00
|
|
|
glScalef(getRadius(), getRadius(), getRadius());
|
2003-02-26 01:12:53 -07:00
|
|
|
glRotate(getOrientation());
|
2003-01-26 19:04:46 -07:00
|
|
|
|
2007-04-20 11:56:18 -06:00
|
|
|
if (glcontext.getRenderPath() == GLContext::GLPath_GLSL)
|
|
|
|
{
|
|
|
|
GLSLUnlit_RenderContext rc(getRadius());
|
2008-02-20 12:39:26 -07:00
|
|
|
rc.setPointScale(2.0f * getRadius() / pixelSize);
|
2008-07-23 15:54:53 -06:00
|
|
|
g->render(rc);
|
2018-09-26 15:19:35 -06:00
|
|
|
glUseProgram(0);
|
2007-04-20 11:56:18 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-25 15:15:57 -06:00
|
|
|
assert(glcontext.getRenderPath() != GLContext::GLPath_GLSL);
|
2007-04-20 11:56:18 -06:00
|
|
|
}
|
2004-03-09 11:57:41 -07:00
|
|
|
|
2004-02-20 03:24:44 -07:00
|
|
|
glEnable(GL_BLEND);
|
2003-01-26 19:04:46 -07:00
|
|
|
}
|
2005-02-10 23:09:37 -07:00
|
|
|
|
|
|
|
|
2005-11-18 02:00:39 -07:00
|
|
|
unsigned int Nebula::getRenderMask() const
|
2005-02-10 23:09:37 -07:00
|
|
|
{
|
|
|
|
return Renderer::ShowNebulae;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-18 02:00:39 -07:00
|
|
|
unsigned int Nebula::getLabelMask() const
|
2005-02-10 23:09:37 -07:00
|
|
|
{
|
|
|
|
return Renderer::NebulaLabels;
|
|
|
|
}
|