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.
|
|
|
|
|
2020-06-14 10:06:05 -06:00
|
|
|
#include <algorithm>
|
2009-10-04 08:12:59 -06:00
|
|
|
#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"
|
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;
|
2019-05-16 15:51:11 -06:00
|
|
|
using namespace celmath;
|
2020-05-12 09:51:25 -06:00
|
|
|
using namespace celestia;
|
2003-01-26 19:04:46 -07:00
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-14 06:56:04 -06:00
|
|
|
string Nebula::getDescription() const
|
2005-11-21 03:22:52 -07:00
|
|
|
{
|
2018-10-14 06:56:04 -06:00
|
|
|
return _("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
|
|
|
|
2021-11-13 14:42:26 -07:00
|
|
|
bool Nebula::pick(const Eigen::ParametrizedLine<double, 3>& ray,
|
2006-12-08 12:19:29 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-15 13:21:22 -06:00
|
|
|
bool Nebula::load(AssociativeArray* params, const fs::path& resPath)
|
2003-01-26 19:04:46 -07:00
|
|
|
{
|
2019-08-15 13:21:22 -06:00
|
|
|
string t;
|
|
|
|
if (params->getString("Mesh", t))
|
2003-01-26 19:04:46 -07:00
|
|
|
{
|
2019-08-15 13:21:22 -06:00
|
|
|
fs::path geometryFileName(t);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-29 01:35:03 -06:00
|
|
|
void Nebula::render(const Vector3f& /*offset*/,
|
2018-09-22 07:13:49 -06:00
|
|
|
const Quaternionf& /*unused*/,
|
|
|
|
float /*unused*/,
|
2018-12-04 13:00:36 -07:00
|
|
|
float pixelSize,
|
2020-05-12 09:51:25 -06:00
|
|
|
const Matrices& m,
|
2020-06-14 10:06:05 -06:00
|
|
|
Renderer* renderer)
|
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;
|
|
|
|
|
2020-06-14 10:06:05 -06:00
|
|
|
renderer->disableBlending();
|
2007-04-21 22:53:43 -06:00
|
|
|
|
2020-05-12 09:51:25 -06:00
|
|
|
Matrix4f mv = vecgl::rotate(vecgl::scale(*m.modelview, getRadius()),
|
|
|
|
getOrientation());
|
2003-01-26 19:04:46 -07:00
|
|
|
|
2021-11-28 12:21:51 -07:00
|
|
|
GLSLUnlit_RenderContext rc(renderer, getRadius(), &mv, m.projection);
|
2022-04-01 20:45:15 -06:00
|
|
|
rc.setPointScale(2.0f * getRadius() / pixelSize);
|
2018-10-27 10:40:32 -06:00
|
|
|
g->render(rc);
|
2004-03-09 11:57:41 -07:00
|
|
|
|
2020-06-14 10:06:05 -06:00
|
|
|
renderer->enableBlending();
|
2003-01-26 19:04:46 -07:00
|
|
|
}
|
2005-02-10 23:09:37 -07:00
|
|
|
|
|
|
|
|
2019-07-06 06:37:18 -06:00
|
|
|
uint64_t 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;
|
|
|
|
}
|