2001-11-27 18:50:04 -07:00
|
|
|
// render.h
|
|
|
|
//
|
|
|
|
// Copyright (C) 2001, 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.
|
|
|
|
|
|
|
|
#ifndef _RENDER_H_
|
|
|
|
#define _RENDER_H_
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <celengine/observer.h>
|
2002-01-07 15:48:32 -07:00
|
|
|
#include <celengine/universe.h>
|
2001-11-27 18:50:04 -07:00
|
|
|
#include <celengine/selection.h>
|
2003-02-19 10:48:25 -07:00
|
|
|
#include <celengine/glcontext.h>
|
2001-11-27 18:50:04 -07:00
|
|
|
#include <celtxf/texturefont.h>
|
|
|
|
|
|
|
|
|
2002-11-03 21:14:07 -07:00
|
|
|
struct RenderListEntry
|
|
|
|
{
|
|
|
|
const Star* star;
|
|
|
|
Body* body;
|
|
|
|
Point3f position;
|
|
|
|
Vec3f sun;
|
|
|
|
float distance;
|
|
|
|
float radius;
|
|
|
|
float nearZ;
|
|
|
|
float farZ;
|
|
|
|
float discSizeInPixels;
|
|
|
|
float appMag;
|
|
|
|
bool isCometTail;
|
|
|
|
};
|
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
class Renderer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Renderer();
|
|
|
|
~Renderer();
|
|
|
|
|
2003-02-19 10:48:25 -07:00
|
|
|
bool init(GLContext*, int, int);
|
2001-11-27 18:50:04 -07:00
|
|
|
void shutdown() {};
|
|
|
|
void resize(int, int);
|
|
|
|
|
2003-01-01 16:48:15 -07:00
|
|
|
float calcPixelSize(float fov, float windowHeight);
|
2002-12-11 13:27:35 -07:00
|
|
|
void setFaintestAM45deg(float);
|
|
|
|
float getFaintestAM45deg();
|
2001-11-27 18:50:04 -07:00
|
|
|
|
|
|
|
void setRenderMode(int);
|
2002-09-22 08:51:35 -06:00
|
|
|
void autoMag(float& faintestMag);
|
2001-11-27 18:50:04 -07:00
|
|
|
void render(const Observer&,
|
2002-01-07 15:48:32 -07:00
|
|
|
const Universe&,
|
2001-11-27 18:50:04 -07:00
|
|
|
float faintestVisible,
|
|
|
|
const Selection& sel,
|
|
|
|
double now);
|
|
|
|
|
|
|
|
enum {
|
2002-02-17 21:00:07 -07:00
|
|
|
NoLabels = 0x00,
|
|
|
|
StarLabels = 0x01,
|
2002-03-14 14:48:51 -07:00
|
|
|
PlanetLabels = 0x02,
|
|
|
|
MoonLabels = 0x04,
|
2002-02-17 21:00:07 -07:00
|
|
|
ConstellationLabels = 0x08,
|
|
|
|
GalaxyLabels = 0x10,
|
2002-03-14 14:48:51 -07:00
|
|
|
AsteroidLabels = 0x20,
|
|
|
|
SpacecraftLabels = 0x40,
|
2002-03-18 14:54:54 -07:00
|
|
|
BodyLabelMask = (PlanetLabels | MoonLabels | AsteroidLabels | SpacecraftLabels),
|
2001-11-27 18:50:04 -07:00
|
|
|
};
|
2002-02-17 21:00:07 -07:00
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
enum {
|
2002-02-17 21:00:07 -07:00
|
|
|
ShowNothing = 0x0000,
|
|
|
|
ShowStars = 0x0001,
|
|
|
|
ShowPlanets = 0x0002,
|
|
|
|
ShowGalaxies = 0x0004,
|
|
|
|
ShowDiagrams = 0x0008,
|
|
|
|
ShowCloudMaps = 0x0010,
|
|
|
|
ShowOrbits = 0x0020,
|
|
|
|
ShowCelestialSphere = 0x0040,
|
|
|
|
ShowNightMaps = 0x0080,
|
|
|
|
ShowAtmospheres = 0x0100,
|
|
|
|
ShowSmoothLines = 0x0200,
|
|
|
|
ShowEclipseShadows = 0x0400,
|
2002-02-28 15:12:26 -07:00
|
|
|
ShowStarsAsPoints = 0x0800,
|
2002-04-16 03:32:55 -06:00
|
|
|
ShowRingShadows = 0x1000,
|
2002-06-04 23:27:53 -06:00
|
|
|
ShowBoundaries = 0x2000,
|
2002-06-22 09:16:27 -06:00
|
|
|
ShowAutoMag = 0x4000,
|
2002-09-08 21:50:37 -06:00
|
|
|
ShowCometTails = 0x8000,
|
2003-01-31 21:42:21 -07:00
|
|
|
ShowMarkers = 0x10000,
|
2001-11-27 18:50:04 -07:00
|
|
|
};
|
2002-02-17 21:00:07 -07:00
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
int getRenderFlags() const;
|
|
|
|
void setRenderFlags(int);
|
|
|
|
int getLabelMode() const;
|
|
|
|
void setLabelMode(int);
|
|
|
|
void addLabelledStar(Star*);
|
|
|
|
void clearLabelledStars();
|
|
|
|
float getAmbientLightLevel() const;
|
|
|
|
void setAmbientLightLevel(float);
|
2002-04-25 21:49:43 -06:00
|
|
|
void setMinimumOrbitSize(float);
|
2002-09-08 21:50:37 -06:00
|
|
|
float getDistanceLimit() const;
|
|
|
|
void setDistanceLimit(float);
|
2001-11-27 18:50:04 -07:00
|
|
|
|
|
|
|
bool getFragmentShaderEnabled() const;
|
|
|
|
void setFragmentShaderEnabled(bool);
|
|
|
|
bool fragmentShaderSupported() const;
|
|
|
|
bool getVertexShaderEnabled() const;
|
|
|
|
void setVertexShaderEnabled(bool);
|
|
|
|
bool vertexShaderSupported() const;
|
|
|
|
|
|
|
|
float getSaturationMagnitude() const;
|
|
|
|
void setSaturationMagnitude(float);
|
|
|
|
float getBrightnessBias() const;
|
|
|
|
void setBrightnessBias(float);
|
2002-02-13 13:38:49 -07:00
|
|
|
void setResolution(unsigned int resolution);
|
|
|
|
unsigned int getResolution();
|
2001-11-27 18:50:04 -07:00
|
|
|
|
2002-05-02 01:57:38 -06:00
|
|
|
void loadTextures(Body*);
|
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
typedef struct {
|
|
|
|
std::string text;
|
|
|
|
Color color;
|
|
|
|
Point3f position;
|
|
|
|
} Label;
|
|
|
|
|
|
|
|
void addLabel(std::string, Color, Point3f, float depth = -1);
|
|
|
|
void clearLabels();
|
|
|
|
|
|
|
|
void setFont(TextureFont*);
|
|
|
|
TextureFont* getFont() const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Internal types
|
|
|
|
// TODO: Figure out how to make these private. Even with a friend
|
|
|
|
//
|
|
|
|
struct Particle
|
|
|
|
{
|
|
|
|
Point3f center;
|
|
|
|
float size;
|
|
|
|
Color color;
|
|
|
|
float pad0, pad1, pad2;
|
|
|
|
};
|
|
|
|
|
2002-02-17 21:00:07 -07:00
|
|
|
struct EclipseShadow
|
|
|
|
{
|
|
|
|
Point3f origin;
|
|
|
|
Vec3f direction;
|
|
|
|
float penumbraRadius;
|
|
|
|
float umbraRadius;
|
|
|
|
};
|
|
|
|
|
2002-02-08 14:55:26 -07:00
|
|
|
struct RenderProperties
|
|
|
|
{
|
|
|
|
RenderProperties() :
|
|
|
|
surface(NULL),
|
|
|
|
atmosphere(NULL),
|
|
|
|
rings(NULL),
|
|
|
|
radius(1.0f),
|
|
|
|
oblateness(0.0f),
|
|
|
|
mesh(InvalidResource),
|
2002-02-17 21:00:07 -07:00
|
|
|
orientation(1.0f),
|
|
|
|
eclipseShadows(NULL)
|
2002-02-08 14:55:26 -07:00
|
|
|
{};
|
|
|
|
|
2002-02-13 13:38:49 -07:00
|
|
|
Surface* surface;
|
2002-02-08 14:55:26 -07:00
|
|
|
const Atmosphere* atmosphere;
|
|
|
|
RingSystem* rings;
|
|
|
|
float radius;
|
|
|
|
float oblateness;
|
|
|
|
ResourceHandle mesh;
|
|
|
|
Quatf orientation;
|
2002-02-17 21:00:07 -07:00
|
|
|
std::vector<EclipseShadow>* eclipseShadows;
|
2002-02-08 14:55:26 -07:00
|
|
|
};
|
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
class StarVertexBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
StarVertexBuffer(unsigned int _capacity);
|
|
|
|
~StarVertexBuffer();
|
2002-02-28 15:12:26 -07:00
|
|
|
void start(bool _usePoints);
|
2001-11-27 18:50:04 -07:00
|
|
|
void render();
|
2002-02-25 13:29:32 -07:00
|
|
|
void finish();
|
2001-11-27 18:50:04 -07:00
|
|
|
void addStar(const Point3f&, const Color&, float);
|
|
|
|
void setBillboardOrientation(const Quatf&);
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned int capacity;
|
|
|
|
unsigned int nStars;
|
|
|
|
float* vertices;
|
|
|
|
float* texCoords;
|
|
|
|
unsigned char* colors;
|
|
|
|
Vec3f v0, v1, v2, v3;
|
2002-02-28 15:12:26 -07:00
|
|
|
bool usePoints;
|
2001-11-27 18:50:04 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2003-02-14 11:07:47 -07:00
|
|
|
void setFieldOfView(float);
|
2001-11-27 18:50:04 -07:00
|
|
|
void renderStars(const StarDatabase& starDB,
|
|
|
|
float faintestVisible,
|
|
|
|
const Observer& observer);
|
2003-01-28 22:47:50 -07:00
|
|
|
void renderDeepSkyObjects(const DeepSkyCatalog& catalog,
|
|
|
|
const Observer& observer);
|
2001-11-27 18:50:04 -07:00
|
|
|
void renderCelestialSphere(const Observer& observer);
|
|
|
|
void renderPlanetarySystem(const Star& sun,
|
|
|
|
const PlanetarySystem& solSystem,
|
|
|
|
const Observer& observer,
|
|
|
|
double now,
|
|
|
|
bool showLabels = false);
|
2002-02-08 14:55:26 -07:00
|
|
|
|
|
|
|
void renderObject(Point3f pos,
|
|
|
|
float distance,
|
|
|
|
double now,
|
|
|
|
Quatf cameraOrientation,
|
|
|
|
float nearPlaneDistance,
|
|
|
|
float farPlaneDistance,
|
|
|
|
Vec3f sunDirection,
|
|
|
|
Color sunColor,
|
|
|
|
RenderProperties& obj);
|
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
void renderPlanet(const Body& body,
|
|
|
|
Point3f pos,
|
|
|
|
Vec3f sunDirection,
|
|
|
|
float distance,
|
|
|
|
float appMag,
|
|
|
|
double now,
|
|
|
|
Quatf orientation,
|
|
|
|
float, float);
|
2002-02-08 14:55:26 -07:00
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
void renderStar(const Star& star,
|
|
|
|
Point3f pos,
|
|
|
|
float distance,
|
|
|
|
float appMag,
|
|
|
|
Quatf orientation,
|
|
|
|
double now,
|
|
|
|
float, float);
|
2002-02-08 14:55:26 -07:00
|
|
|
|
2002-06-16 20:41:11 -06:00
|
|
|
void renderCometTail(const Body& body,
|
|
|
|
Point3f pos,
|
|
|
|
Vec3f sunDirection,
|
|
|
|
float distance,
|
|
|
|
float appMag,
|
|
|
|
double now,
|
|
|
|
Quatf orientation,
|
|
|
|
float, float);
|
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
void renderBodyAsParticle(Point3f center,
|
|
|
|
float appMag,
|
2002-01-23 18:21:53 -07:00
|
|
|
float _faintestMag,
|
2001-11-27 18:50:04 -07:00
|
|
|
float discSizeInPixels,
|
|
|
|
Color color,
|
|
|
|
const Quatf& orientation,
|
|
|
|
float renderDistance,
|
|
|
|
bool useHaloes);
|
2002-02-17 21:00:07 -07:00
|
|
|
|
|
|
|
bool testEclipse(const Body&, const Body&, double now);
|
|
|
|
|
2003-01-28 22:47:50 -07:00
|
|
|
void labelGalaxies(const DeepSkyCatalog& catalog,
|
|
|
|
const Observer& observer);
|
2001-11-27 18:50:04 -07:00
|
|
|
void labelStars(const std::vector<Star*>& stars,
|
|
|
|
const StarDatabase& starDB,
|
|
|
|
const Observer& observer);
|
|
|
|
void labelConstellations(const AsterismList& asterisms,
|
|
|
|
const Observer& observer);
|
|
|
|
void renderParticles(const std::vector<Particle>& particles,
|
|
|
|
Quatf orientation);
|
|
|
|
void renderLabels();
|
2003-01-31 21:42:21 -07:00
|
|
|
void renderMarkers(const MarkerList&,
|
|
|
|
const UniversalCoord& position,
|
|
|
|
const Quatf& orientation,
|
|
|
|
double jd);
|
2001-11-27 18:50:04 -07:00
|
|
|
|
2002-03-19 17:28:43 -07:00
|
|
|
void renderOrbit(Body*, double);
|
2002-03-21 15:38:35 -07:00
|
|
|
void renderOrbits(PlanetarySystem*, const Selection&, double,
|
|
|
|
const Point3d&, const Point3d&);
|
2001-11-27 18:50:04 -07:00
|
|
|
|
|
|
|
private:
|
2003-02-19 10:48:25 -07:00
|
|
|
GLContext* context;
|
|
|
|
|
2001-11-27 18:50:04 -07:00
|
|
|
int windowWidth;
|
|
|
|
int windowHeight;
|
|
|
|
float fov;
|
2002-09-22 08:51:35 -06:00
|
|
|
float corrFac;
|
2001-11-27 18:50:04 -07:00
|
|
|
float pixelSize;
|
2002-12-11 13:27:35 -07:00
|
|
|
float faintestAutoMag45deg;
|
2001-11-27 18:50:04 -07:00
|
|
|
TextureFont* font;
|
|
|
|
|
|
|
|
int renderMode;
|
|
|
|
int labelMode;
|
|
|
|
int renderFlags;
|
|
|
|
float ambientLightLevel;
|
|
|
|
bool fragmentShaderEnabled;
|
|
|
|
bool vertexShaderEnabled;
|
|
|
|
float brightnessBias;
|
|
|
|
|
|
|
|
float brightnessScale;
|
|
|
|
float faintestMag;
|
2002-01-23 18:21:53 -07:00
|
|
|
float faintestPlanetMag;
|
2001-12-11 00:40:53 -07:00
|
|
|
float saturationMagNight;
|
|
|
|
float saturationMag;
|
2001-11-27 18:50:04 -07:00
|
|
|
|
|
|
|
Color ambientColor;
|
|
|
|
|
|
|
|
StarVertexBuffer* starVertexBuffer;
|
|
|
|
std::vector<RenderListEntry> renderList;
|
|
|
|
std::vector<Particle> glareParticles;
|
|
|
|
std::vector<Label> labels;
|
2002-02-17 21:00:07 -07:00
|
|
|
std::vector<EclipseShadow> eclipseShadows;
|
2001-11-27 18:50:04 -07:00
|
|
|
|
|
|
|
std::vector<Star*> labelledStars;
|
|
|
|
|
|
|
|
double modelMatrix[16];
|
|
|
|
double projMatrix[16];
|
|
|
|
|
|
|
|
bool useCompressedTextures;
|
|
|
|
bool useVertexPrograms;
|
|
|
|
bool useRescaleNormal;
|
2002-05-14 11:02:04 -06:00
|
|
|
bool useMinMaxBlending;
|
2002-09-22 19:59:15 -06:00
|
|
|
bool useClampToBorder;
|
2002-02-13 13:38:49 -07:00
|
|
|
unsigned int textureResolution;
|
2002-03-19 17:28:43 -07:00
|
|
|
|
|
|
|
struct CachedOrbit
|
|
|
|
{
|
|
|
|
Body* body;
|
|
|
|
std::vector<Point3f> trajectory;
|
|
|
|
bool keep;
|
|
|
|
};
|
|
|
|
std::vector<CachedOrbit*> orbitCache;
|
2002-04-25 21:49:43 -06:00
|
|
|
|
|
|
|
float minOrbitSize;
|
2002-09-08 21:50:37 -06:00
|
|
|
float distanceLimit;
|
2001-11-27 18:50:04 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _RENDER_H_
|