Removed more code that used the old vector classes.

sensor-dev
Chris Laurel 2009-08-05 21:13:29 +00:00
parent 1f47ed60e8
commit 157b720854
12 changed files with 60 additions and 100 deletions

View File

@ -11,7 +11,6 @@
#define _DISPMAP_H_
#include <string>
#include <celmath/vecmath.h>
typedef float (*DisplacementMapFunc)(float, float, void*);

View File

@ -108,23 +108,6 @@ Vec3ShaderParameter::operator=(const Eigen::Vector3f& v)
return *this;
}
Vec3ShaderParameter&
Vec3ShaderParameter::operator=(const Vec3f& v)
{
if (slot != -1)
glx::glUniform3fARB(slot, v.x, v.y, v.z);
return *this;
}
Vec3ShaderParameter&
Vec3ShaderParameter::operator=(const Point3f& p)
{
if (slot != -1)
glx::glUniform3fARB(slot, p.x, p.y, p.z);
return *this;
}
Vec4ShaderParameter::Vec4ShaderParameter() :
slot(-1)
{
@ -143,14 +126,6 @@ Vec4ShaderParameter::operator=(const Eigen::Vector4f& v)
return *this;
}
Vec4ShaderParameter&
Vec4ShaderParameter::operator=(const Vec4f& v)
{
if (slot != -1)
glx::glUniform4fARB(slot, v.x, v.y, v.z, v.w);
return *this;
}
//************* GLProgram **************

View File

@ -10,7 +10,6 @@
#ifndef _CELENGINE_GLSHADER_H_
#define _CELENGINE_GLSHADER_H_
#include <celmath/vecmath.h>
#include <Eigen/Core>
#include <string>
#include <vector>
@ -108,10 +107,6 @@ class Vec3ShaderParameter
Vec3ShaderParameter& operator=(const Eigen::Vector3f&);
// Compatibility
Vec3ShaderParameter& operator=(const Vec3f&);
Vec3ShaderParameter& operator=(const Point3f&);
private:
int slot;
};
@ -125,9 +120,6 @@ class Vec4ShaderParameter
Vec4ShaderParameter& operator=(const Eigen::Vector4f&);
// Compatibility
Vec4ShaderParameter& operator=(const Vec4f&);
private:
int slot;
};

View File

@ -13,7 +13,6 @@
#include <cmath>
#include <iostream>
#include <celmath/mathlib.h>
#include <celmath/vecmath.h>
#include "precession.h"
using namespace std;

View File

@ -682,8 +682,9 @@ GLSL_RenderContext::makeCurrent(const Mesh::Material& m)
prog->setLightParameters(lightingState, diffuse, m.specular, m.emissive);
Matrix4f xform_e = Map<Matrix4f>(&xform[0][0]);
if (shaderProps.shadowCounts != 0)
prog->setEclipseShadowParameters(lightingState, objRadius, xform);
prog->setEclipseShadowParameters(lightingState, objRadius, xform_e);
// TODO: handle emissive color
prog->shininess = m.specularPower;
@ -865,13 +866,9 @@ GLSLUnlit_RenderContext::makeCurrent(const Mesh::Material& m)
}
#ifdef HDR_COMPRESS
prog->lights[0].diffuse = Vec3f(m.diffuse.red() * 0.5f,
m.diffuse.green() * 0.5f,
m.diffuse.blue() * 0.5f);
prog->lights[0].diffuse = m.diffuse.toVector3() * 0.5f;
#else
prog->lights[0].diffuse = Vec3f(m.diffuse.red(),
m.diffuse.green(),
m.diffuse.blue());
prog->lights[0].diffuse = m.diffuse.toVector3();
#endif
prog->opacity = m.opacity;

View File

@ -5097,20 +5097,13 @@ void Renderer::renderEllipsoidAtmosphere(const Atmosphere& atmosphere,
}
Vector3f botColor(atmosphere.lowerColor.red(),
atmosphere.lowerColor.green(),
atmosphere.lowerColor.blue());
Vector3f topColor(atmosphere.upperColor.red(),
atmosphere.upperColor.green(),
atmosphere.upperColor.blue());
Vector3f sunsetColor(atmosphere.sunsetColor.red(),
atmosphere.sunsetColor.green(),
atmosphere.sunsetColor.blue());
Vector3f botColor = atmosphere.lowerColor.toVector3();
Vector3f topColor = atmosphere.upperColor.toVector3();
Vector3f sunsetColor = atmosphere.sunsetColor.toVector3();
if (within)
{
Vector3f skyColor(atmosphere.skyColor.red(),
atmosphere.skyColor.green(),
atmosphere.skyColor.blue());
Vector3f skyColor = atmosphere.skyColor.toVector3();
if (ellipDist < 0.0f)
topColor = skyColor;
else
@ -5321,19 +5314,13 @@ static void setupBumpTexenvAmbient(Color ambientColor)
static void setupTexenvAmbient(Color ambientColor)
{
float texenvConst[4];
texenvConst[0] = ambientColor.red();
texenvConst[1] = ambientColor.green();
texenvConst[2] = ambientColor.blue();
texenvConst[3] = ambientColor.alpha();
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
// The primary color contains the light direction in surface
// space, and texture0 is a normal map. The lighting is
// calculated by computing the dot product.
glx::glActiveTextureARB(GL_TEXTURE0_ARB);
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, texenvConst);
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, ambientColor.toVector4().data());
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
@ -5361,25 +5348,17 @@ static void setLightParameters_VP(VertexProcessor& vproc,
Color materialDiffuse,
Color materialSpecular)
{
Vector3f diffuseColor(materialDiffuse.red(),
materialDiffuse.green(),
materialDiffuse.blue());
Vector3f diffuseColor = materialDiffuse.toVector3();
#ifdef HDR_COMPRESS
Vector3f specularColor(materialSpecular.red() * 0.5f,
materialSpecular.green() * 0.5f,
materialSpecular.blue() * 0.5f);
Vector3f specularColor = materialSpecular.toVector3() * 0.5f;
#else
Vector3f specularColor(materialSpecular.red(),
materialSpecular.green(),
materialSpecular.blue());
Vector3f specularColor = materialSpecular.toVector3();
#endif
for (unsigned int i = 0; i < ls.nLights; i++)
{
const DirectionalLight& light = ls.lights[i];
Vector3f lightColor = Vector3f(light.color.red(),
light.color.green(),
light.color.blue()) * light.irradiance;
Vector3f lightColor = light.color.toVector3() * light.irradiance;
Vector3f diffuse = diffuseColor.cwise() * lightColor;
Vector3f specular = specularColor.cwise() * lightColor;
@ -6473,11 +6452,9 @@ static void renderRings(RingSystem& rings,
if (vpath == GLContext::VPath_Basic)
{
glDisable(GL_LIGHTING);
Vec3f litColor(rings.color.red(), rings.color.green(), rings.color.blue());
litColor = litColor * ringIllumination +
Vec3f(ri.ambientColor.red(), ri.ambientColor.green(),
ri.ambientColor.blue());
glColor4f(litColor.x, litColor.y, litColor.z, 1.0f);
Vector3f litColor = rings.color.toVector3();
litColor = litColor * ringIllumination + ri.ambientColor.toVector3();
glColor4f(litColor.x(), litColor.y(), litColor.z(), 1.0f);
}
// This gets tricky . . . we render the rings in two parts. One
@ -7345,9 +7322,7 @@ void Renderer::renderObject(const Vector3f& pos,
// Addendum: Unsurprisingly, using color values outside [0, 1] produces
// problems on Savage4 cards.
Vec3f lightColor = Vec3f(light.color.red(),
light.color.green(),
light.color.blue()) * light.irradiance;
Vector3f lightColor = light.color.toVector3() * light.irradiance;
if (useRescaleNormal)
{
glLightColor(GL_LIGHT0 + i, GL_DIFFUSE, lightColor);

View File

@ -242,8 +242,9 @@ void renderSphere_GLSL(const RenderInfo& ri,
prog->setAtmosphereParameters(*atmosphere, radius, radius);
}
Matrix4f planetMat_e = Map<Matrix4f>(&planetMat[0][0]);
if (shadprop.shadowCounts != 0)
prog->setEclipseShadowParameters(ls, radius, planetMat);
prog->setEclipseShadowParameters(ls, radius, planetMat_e);
glColor(ri.color);
@ -462,8 +463,9 @@ void renderClouds_GLSL(const RenderInfo& ri,
prog->ringWidth = 1.0f / (ringWidth / cloudRadius);
}
Matrix4f planetMat_e = Map<Matrix4f>(&planetMat[0][0]);
if (shadprop.shadowCounts != 0)
prog->setEclipseShadowParameters(ls, cloudRadius, planetMat);
prog->setEclipseShadowParameters(ls, cloudRadius, planetMat_e);
unsigned int attributes = LODSphereMesh::Normals;
if (cloudNormalMap != NULL)

View File

@ -1,6 +1,7 @@
// selection.cpp
//
// Copyright (C) 2001-2008, Chris Laurel <claurel@shatters.net>
// Copyright (C) 2001-2009, the Celestia Development Team
// Original version by Chris Laurel <claurel@gmail.com>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
@ -57,10 +58,6 @@ UniversalCoord Selection::getPosition(double t) const
// Celestia 1.6.0.
Vector3f p = deepsky()->getPosition().cast<float>();
return UniversalCoord::CreateLy(p.cast<double>());
#if CELVEC
return astro::universalPosition(Point3d(0.0, 0.0, 0.0),
Point3f((float) p.x, (float) p.y, (float) p.z));
#endif
}
case Type_Location:
@ -68,11 +65,6 @@ UniversalCoord Selection::getPosition(double t) const
Body* body = location()->getParentBody();
if (body != NULL)
{
#if CELVEC
Point3d planetocentricPos = location()->getPlanetocentricPosition(t) *
astro::kilometersToMicroLightYears(1.0);
return body->getPosition(t) + planetocentricPos;
#endif
return body->getPosition(t).offsetKm(location()->getPlanetocentricPosition(t));
}
else
@ -105,10 +97,6 @@ Vector3d Selection::getVelocity(double t) const
case Type_Location:
{
// For now, just use differentiation for location velocities.
#if CELVEC
Vec3d ulyPerJD = (getPosition(t) - getPosition(t - VELOCITY_DIFF_DELTA)) * (1.0 / VELOCITY_DIFF_DELTA);
return ulyPerJD * astro::microLightYearsToKilometers(1.0);
#endif
return getPosition(t).offsetFromKm(getPosition(t - VELOCITY_DIFF_DELTA)) / VELOCITY_DIFF_DELTA;
}

View File

@ -2538,10 +2538,10 @@ CelestiaGLProgram::setLightParameters(const LightingState& ls,
void
CelestiaGLProgram::setEclipseShadowParameters(const LightingState& ls,
float planetRadius,
const Mat4f& planetMat)
const Eigen::Matrix4f& planetMat)
{
Transform3f planetTransform;
planetTransform.matrix() = Map<Matrix4f>(&planetMat[0][0]);
planetTransform.matrix() = planetMat;
for (unsigned int li = 0;
li < min(ls.nLights, MaxShaderLights);

View File

@ -124,7 +124,7 @@ class CelestiaGLProgram
);
void setEclipseShadowParameters(const LightingState& ls,
float planetRadius,
const Mat4f& planetMat);
const Eigen::Matrix4f& planetMat);
void setAtmosphereParameters(const Atmosphere& atmosphere,
float atmPlanetRadius,
float objRadius);

View File

@ -186,5 +186,16 @@ inline void glLightPosition(GLenum light, const Eigen::Vector3f& pos)
glLightfv(light, GL_POSITION, Eigen::Vector4f(pos.x(), pos.y(), pos.z(), 1.0f).data());
}
template<typename DERIVED>
void glLightColor(GLenum light, GLenum which, const Eigen::MatrixBase<DERIVED>& color)
{
glLightfv(light, which, Eigen::Vector4f(color.x(), color.y(), color.z(), 1.0f).data());
}
inline void glLightColor(GLenum light, GLenum which, const Eigen::Vector4f& color)
{
glLightfv(light, which, color.data());
}
#endif // _CELENGINE_VECGL_H_

View File

@ -12,6 +12,7 @@
#include <map>
#include <string>
#include <Eigen/Core>
class Color
@ -35,6 +36,9 @@ class Color
inline float blue() const;
inline float alpha() const;
inline void get(unsigned char*) const;
inline Eigen::Vector3f toVector3() const;
inline Eigen::Vector4f toVector4() const;
friend bool operator==(Color, Color);
friend bool operator!=(Color, Color);
@ -84,6 +88,24 @@ void Color::get(unsigned char* rgba) const
rgba[3] = c[Alpha];
}
/** Return the color as a vector, with red, green, and blue in the
* the x, y, and z components of the vector. Each component is a
* floating point value between 0 and 1, inclusive.
*/
Eigen::Vector3f Color::toVector3() const
{
return Eigen::Vector3f(red(), green(), blue());
}
/** Return the color as a vector, with red, green, blue, and alpha in the
* the x, y, z, and w components of the vector. Each component is a
* floating point value between 0 and 1, inclusive.
*/
Eigen::Vector4f Color::toVector4() const
{
return Eigen::Vector4f(red(), green(), blue(), alpha());
}
inline bool operator==(Color a, Color b)
{
return (a.c[0] == b.c[2] && a.c[1] == b.c[1] &&