Remove support for old vector math

pull/241/head
Hleb Valoshka 2019-03-16 15:36:43 +03:00
parent d1d5970b8a
commit 81aa6f43bc
42 changed files with 5 additions and 1353 deletions

View File

@ -300,12 +300,6 @@ Matrix4f readMeshMatrix(ifstream& in/*, int nBytes*/)
m30, m31, m32, 1;
return m;
#ifdef CELVEC
return Mat4f(Vec4f(m00, m01, m02, 0),
Vec4f(m10, m11, m12, 0),
Vec4f(m20, m21, m22, 0),
Vec4f(m30, m31, m32, 1));
#endif
}

View File

@ -216,16 +216,6 @@ void astro::decimalToHourMinSec(double angle, int& hours, int& minutes, double&
seconds = (B - (double) minutes) * 60.0;
}
// Compute the fraction of a sphere which is illuminated and visible
// to a viewer. The source of illumination is assumed to be at (0, 0, 0)
#ifdef __CELVEC__
float astro::sphereIlluminationFraction(Point3d /*spherePos*/,
Point3d /*viewerPos*/)
{
return 1.0f;
}
#endif
// Convert equatorial coordinates to Cartesian celestial (or ecliptical)
// coordinates.
Eigen::Vector3f

View File

@ -11,10 +11,6 @@
#ifndef _CELENGINE_ASTRO_H_
#define _CELENGINE_ASTRO_H_
#ifdef __CELVEC__
#include <celmath/vecmath.h>
#include <celmath/quaternion.h>
#endif
#include <Eigen/Core>
#include <Eigen/Geometry>
#include <iostream>
@ -211,11 +207,6 @@ namespace astro
double degMinSecToDecimal(int degrees, int minutes, double seconds);
void decimalToHourMinSec(double angle, int& hours, int& minutes, double& seconds);
#ifdef __CELVEC__
float sphereIlluminationFraction(Point3d spherePos,
Point3d viewerPos);
#endif
Eigen::Vector3f equatorialToCelestialCart(float ra, float dec, float distance);
Eigen::Vector3d equatorialToCelestialCart(double ra, double dec, double distance);

View File

@ -225,20 +225,12 @@ Command* CommandParser::parseCommand()
if (paramList->getString("upframe", frameString))
upFrame = parseCoordinateSystem(frameString);
#ifdef __CELVEC__
Vec3d up(0, 1, 0);
#else
Eigen::Vector3d up(Eigen::Vector3d::UnitY());
#endif
paramList->getVector("up", up);
cmd = new CommandGoto(t,
distance,
#ifdef __CELVEC__
Vec3f((float) up.x, (float) up.y, (float) up.z),
#else
up.cast<float>(),
#endif
upFrame);
}
else if (commandName == "gotolonglat")
@ -247,11 +239,7 @@ Command* CommandParser::parseCommand()
paramList->getNumber("time", t);
double distance = 5.0;
paramList->getNumber("distance", distance);
#ifdef __CELVEC__
Vec3d up(0, 1, 0);
#else
Eigen::Vector3d up(Eigen::Vector3d::UnitY());
#endif
paramList->getVector("up", up);
double longitude;
paramList->getNumber("longitude", longitude);
@ -262,21 +250,13 @@ Command* CommandParser::parseCommand()
distance,
(float) degToRad(longitude),
(float) degToRad(latitude),
#ifdef __CELVEC__
Vec3f((float) up.x, (float) up.y, (float) up.z));
#else
up.cast<float>());
#endif
}
else if (commandName == "gotoloc")
{
double t = 1.0;
paramList->getNumber("time", t);
#ifdef __CELVEC__
Vec3d pos(0, 1, 0);
#else
Eigen::Vector3d pos(Eigen::Vector3d::UnitY());
#endif
if (paramList->getVector("position", pos))
{
pos = pos * astro::kilometersToMicroLightYears(1.0);
@ -287,18 +267,10 @@ Command* CommandParser::parseCommand()
double zrot = 0.0;
paramList->getNumber("zrot", zrot);
zrot = degToRad(zrot);
#ifdef __CELVEC__
Quatf rotation = Quatf::xrotation((float) degToRad(xrot)) *
Quatf::yrotation((float) degToRad(yrot)) *
Quatf::zrotation((float) degToRad(zrot));
cmd = new CommandGotoLocation(t, Point3d(0.0, 0.0, 0.0) + pos,
rotation);
#else
auto rotation = Eigen::Quaterniond(Eigen::AngleAxisd(degToRad(xrot), Eigen::Vector3d::UnitX()) *
Eigen::AngleAxisd(degToRad(yrot), Eigen::Vector3d::UnitY()) *
Eigen::AngleAxisd(degToRad(zrot), Eigen::Vector3d::UnitZ()));
cmd = new CommandGotoLocation(t, pos, rotation);
#endif
}
else
{
@ -311,15 +283,9 @@ Command* CommandParser::parseCommand()
paramList->getNumber("ox", ox);
paramList->getNumber("oy", oy);
paramList->getNumber("oz", oz);
#ifdef __CELVEC__
Quatf orientation((float)ow, (float)ox, (float)oy, (float)oz);
cmd = new CommandGotoLocation(t, Point3d((double)BigFix(x), (double)BigFix(y), (double)BigFix(z)),
orientation);
#else
Eigen::Quaterniond orientation(ow, ox, oy, oz);
cmd = new CommandGotoLocation(t, Eigen::Vector3d((double)BigFix(x), (double)BigFix(y), (double)BigFix(z)),
orientation);
#endif
}
}
else if (commandName == "seturl")
@ -468,49 +434,29 @@ Command* CommandParser::parseCommand()
{
double rate = 0.0;
double duration = 1.0;
#ifdef __CELVEC__
Vec3d axis;
#else
Eigen::Vector3d axis(Eigen::Vector3d::Zero());
#endif
paramList->getNumber("duration", duration);
paramList->getNumber("rate", rate);
paramList->getVector("axis", axis);
cmd = new CommandOrbit(duration,
#ifdef __CELVEC__
Vec3f((float) axis.x, (float) axis.y, (float) axis.z),
#else
axis.cast<float>(),
#endif
(float) degToRad(rate));
}
else if (commandName == "rotate")
{
double rate = 0.0;
double duration = 1.0;
#ifdef __CELVEC__
Vec3d axis;
#else
Eigen::Vector3d axis(Eigen::Vector3d::Zero());
#endif
paramList->getNumber("duration", duration);
paramList->getNumber("rate", rate);
paramList->getVector("axis", axis);
cmd = new CommandRotate(duration,
#ifdef __CELVEC__
Vec3f((float) axis.x, (float) axis.y, (float) axis.z),
#else
axis.cast<float>(),
#endif
(float) degToRad(rate));
}
else if (commandName == "move")
{
#ifdef __CELVEC__
Vec3d velocity;
#else
Eigen::Vector3d velocity(Eigen::Vector3d::Zero());
#endif
double duration;
paramList->getNumber("duration", duration);
paramList->getVector("velocity", velocity);
@ -526,10 +472,6 @@ Command* CommandParser::parseCommand()
Eigen::Vector3f basef = base.cast<float>();
UniversalCoord basePosition = UniversalCoord::CreateLy(basef.cast<double>());
cmd = new CommandSetPosition(basePosition.offsetKm(offset));
#ifdef CELVEC
cmd = new CommandSetPosition(astro::universalPosition(Point3d(offset.x, offset.y, offset.z),
Point3f((float) base.x, (float) base.y, (float) base.z)));
#endif
}
else
{
@ -542,23 +484,14 @@ Command* CommandParser::parseCommand()
}
else if (commandName == "setorientation")
{
#ifdef __CELVEC__
Vec3d axis;
#else
Eigen::Vector3d axis(Eigen::Vector3d::Zero());
#endif
double angle;
if (paramList->getNumber("angle", angle))
{
paramList->getVector("axis", axis);
#ifdef __CELVEC__
cmd = new CommandSetOrientation(Vec3f((float) axis.x, (float) axis.y, (float) axis.z),
(float) degToRad(angle));
#else
auto orientation = Eigen::Quaternionf(Eigen::AngleAxisf((float) degToRad(angle),
axis.cast<float>().normalized()));
cmd = new CommandSetOrientation(orientation);
#endif
}
else
{
@ -567,16 +500,8 @@ Command* CommandParser::parseCommand()
paramList->getNumber("ox", ox);
paramList->getNumber("oy", oy);
paramList->getNumber("oz", oz);
#ifdef __CELVEC__
Quatf orientation((float)ow, (float)ox, (float)oy, (float)oz);
Vec3f axis;
float angle;
orientation.getAxisAngle(axis, angle);
cmd = new CommandSetOrientation(axis, angle);
#else
Eigen::Quaternionf orientation(ow, ox, oy, oz);
cmd = new CommandSetOrientation(orientation);
#endif
}
}
else if (commandName == "lookback")

View File

@ -22,9 +22,6 @@
#include <utility>
#include <algorithm>
#include <Eigen/Geometry>
#ifdef __CELVEC__
#include "eigenport.h"
#endif
using namespace std;
using namespace Eigen;
@ -62,11 +59,7 @@ void CommandSelect::process(ExecutionEnvironment& env)
CommandGoto::CommandGoto(double t,
double dist,
#ifdef __CELVEC__
Vec3f _up,
#else
Eigen::Vector3f _up,
#endif
ObserverFrame::CoordinateSystem _upFrame) :
gotoTime(t), distance(dist), up(_up), upFrame(_upFrame)
{
@ -77,11 +70,7 @@ void CommandGoto::process(ExecutionEnvironment& env)
Selection sel = env.getSimulation()->getSelection();
env.getSimulation()->gotoSelection(gotoTime,
sel.radius() * distance,
#ifdef __CELVEC__
toEigen(up), upFrame);
#else
up, upFrame);
#endif
}
@ -92,11 +81,7 @@ CommandGotoLongLat::CommandGotoLongLat(double t,
double dist,
float _longitude,
float _latitude,
#ifdef __CELVEC__
Vec3f _up) :
#else
Eigen::Vector3f _up) :
#endif
gotoTime(t),
distance(dist),
longitude(_longitude),
@ -111,11 +96,7 @@ void CommandGotoLongLat::process(ExecutionEnvironment& env)
env.getSimulation()->gotoSelectionLongLat(gotoTime,
sel.radius() * distance,
longitude, latitude,
#ifdef __CELVEC__
toEigen(up));
#else
up);
#endif
}
@ -123,27 +104,16 @@ void CommandGotoLongLat::process(ExecutionEnvironment& env)
// GotoLocation
CommandGotoLocation::CommandGotoLocation(double t,
#ifdef __CELVEC__
const Point3d& _translation,
const Quatf& _rotation) :
#else
const Eigen::Vector3d& _translation,
const Eigen::Quaterniond& _rotation) :
#endif
gotoTime(t), translation(_translation), rotation(_rotation)
{
}
void CommandGotoLocation::process(ExecutionEnvironment& env)
{
#ifdef __CELVEC__
Quatd toOrientation = Quatd(rotation.w, rotation.x, rotation.y, rotation.z);
UniversalCoord toPosition = UniversalCoord::CreateUly(toEigen(translation));
env.getSimulation()->gotoLocation(toPosition, toEigen(toOrientation), gotoTime);
#else
UniversalCoord toPosition = UniversalCoord::CreateUly(translation);
env.getSimulation()->gotoLocation(toPosition, rotation, gotoTime);
#endif
}
/////////////////////////////
@ -346,11 +316,7 @@ void CommandChangeDistance::process(ExecutionEnvironment& env, double /*unused*/
////////////////
// Orbit command: rotate about the selected object
#ifdef __CELVEC__
CommandOrbit::CommandOrbit(double _duration, const Vec3f& axis, float rate) :
#else
CommandOrbit::CommandOrbit(double _duration, const Eigen::Vector3f& axis, float rate) :
#endif
TimedCommand(_duration),
spin(axis * rate)
{
@ -358,29 +324,15 @@ CommandOrbit::CommandOrbit(double _duration, const Eigen::Vector3f& axis, float
void CommandOrbit::process(ExecutionEnvironment& env, double /*unused*/, double dt)
{
#ifdef __CELVEC__
float v = spin.length();
#else
float v = spin.norm();
#endif
if (v != 0.0f)
{
#ifdef __CELVEC__
Quatf q;
q.setAxisAngle(spin / v, (float) (v * dt));
env.getSimulation()->orbit(toEigen(q));
#else
auto q = Quaternionf(AngleAxisf((float) (v * dt), (spin / v).normalized()));
env.getSimulation()->orbit(q);
#endif
}
}
#ifdef __CELVEC__
CommandRotate::CommandRotate(double _duration, const Vec3f& axis, float rate) :
#else
CommandRotate::CommandRotate(double _duration, const Eigen::Vector3f& axis, float rate) :
#endif
TimedCommand(_duration),
spin(axis * rate)
{
@ -388,30 +340,16 @@ CommandRotate::CommandRotate(double _duration, const Eigen::Vector3f& axis, floa
void CommandRotate::process(ExecutionEnvironment& env, double /*unused*/, double dt)
{
#ifdef __CELVEC__
float v = spin.length();
#else
float v = spin.norm();
#endif
if (v != 0.0f)
{
#ifdef __CELVEC__
Quatf q;
q.setAxisAngle(spin / v, (float) (v * dt));
env.getSimulation()->rotate(toEigen(q));
#else
auto q = Quaternionf(AngleAxisf((float) (v * dt), (spin / v).normalized()));
env.getSimulation()->rotate(q);
#endif
}
}
#ifdef __CELVEC__
CommandMove::CommandMove(double _duration, const Vec3d& _velocity) :
#else
CommandMove::CommandMove(double _duration, const Eigen::Vector3d& _velocity) :
#endif
TimedCommand(_duration),
velocity(_velocity)
{
@ -419,12 +357,8 @@ CommandMove::CommandMove(double _duration, const Eigen::Vector3d& _velocity) :
void CommandMove::process(ExecutionEnvironment& env, double /*unused*/, double dt)
{
#ifdef __CELVEC__
Eigen::Vector3d velocityKm = toEigen(velocity) * dt * astro::microLightYearsToKilometers(1.0);
#else
Eigen::Vector3d velocityKm = velocity * dt * astro::microLightYearsToKilometers(1.0);
#endif
env.getSimulation()->setObserverPosition(env.getSimulation()->getObserver().getPosition().offsetKm(velocityKm));
env.getSimulation()->setObserverPosition(env.getSimulation()->getObserver().getPosition().offsetKm(velocityKm));
}
@ -444,25 +378,14 @@ void CommandSetPosition::process(ExecutionEnvironment& env)
////////////////
// Set orientation command: set the orientation of the camera
#ifdef __CELVEC__
CommandSetOrientation::CommandSetOrientation(const Vec3f& _axis, float _angle) :
axis(_axis), angle(_angle)
#else
CommandSetOrientation::CommandSetOrientation(const Quaternionf& _orientation) :
orientation(_orientation)
#endif
{
}
void CommandSetOrientation::process(ExecutionEnvironment& env)
{
#ifdef __CELVEC__
Quatf q(1);
q.setAxisAngle(axis, angle);
env.getSimulation()->setObserverOrientation(toEigen(q));
#else
env.getSimulation()->setObserverOrientation(orientation);
#endif
}
////////////////

View File

@ -81,11 +81,7 @@ class CommandGoto : public InstantaneousCommand
{
public:
CommandGoto(double t, double dist,
#ifdef __CELVEC__
Vec3f _up,
#else
Eigen::Vector3f _up,
#endif
ObserverFrame::CoordinateSystem _upFrame);
~CommandGoto() = default;
void process(ExecutionEnvironment&);
@ -93,11 +89,7 @@ class CommandGoto : public InstantaneousCommand
private:
double gotoTime;
double distance;
#ifdef __CELVEC__
Vec3f up;
#else
Eigen::Vector3f up;
#endif
ObserverFrame::CoordinateSystem upFrame;
};
@ -108,11 +100,7 @@ class CommandGotoLongLat : public InstantaneousCommand
CommandGotoLongLat(double t,
double dist,
float _longitude, float _latitude,
#ifdef __CELVEC__
Vec3f _up);
#else
Eigen::Vector3f _up);
#endif
~CommandGotoLongLat() = default;
void process(ExecutionEnvironment&);
@ -121,11 +109,7 @@ class CommandGotoLongLat : public InstantaneousCommand
double distance;
float longitude;
float latitude;
#ifdef __CELVEC__
Vec3f up;
#else
Eigen::Vector3f up;
#endif
};
@ -135,25 +119,16 @@ class CommandGotoLocation : public InstantaneousCommand
EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
CommandGotoLocation(double t,
#ifdef __CELVEC__
const Point3d& translation, const Quatf& rotation);
#else
const Eigen::Vector3d& translation,
const Eigen::Quaterniond& rotation);
#endif
~CommandGotoLocation() = default;
void process(ExecutionEnvironment&);
private:
double gotoTime;
#ifdef __CELVEC__
Point3d translation;
Quatf rotation;
#else
Eigen::Vector3d translation;
Eigen::Quaterniond rotation;
#endif
};
class CommandSetUrl : public InstantaneousCommand
@ -345,57 +320,33 @@ class CommandChangeDistance : public TimedCommand
class CommandOrbit : public TimedCommand
{
public:
#ifdef __CELVEC__
CommandOrbit(double _duration, const Vec3f& axis, float rate);
#else
CommandOrbit(double _duration, const Eigen::Vector3f& axis, float rate);
#endif
void process(ExecutionEnvironment&, double t, double dt);
private:
#ifdef __CELVEC__
Vec3f spin;
#else
Eigen::Vector3f spin;
#endif
};
class CommandRotate : public TimedCommand
{
public:
#ifdef __CELVEC__
CommandRotate(double _duration, const Vec3f& axis, float rate);
#else
CommandRotate(double _duration, const Eigen::Vector3f& axis, float rate);
#endif
void process(ExecutionEnvironment&, double t, double dt);
private:
#ifdef __CELVEC__
Vec3f spin;
#else
Eigen::Vector3f spin;
#endif
};
class CommandMove : public TimedCommand
{
public:
#ifdef __CELVEC__
CommandMove(double _duration, const Vec3d& _velocity);
#else
CommandMove(double _duration, const Eigen::Vector3d& _velocity);
#endif
void process(ExecutionEnvironment&, double t, double dt);
private:
#ifdef __CELVEC__
Vec3d velocity;
#else
Eigen::Vector3d velocity;
#endif
};
@ -415,20 +366,11 @@ class CommandSetOrientation : public InstantaneousCommand
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
#ifdef __CELVEC__
CommandSetOrientation(const Vec3f&, float);
#else
CommandSetOrientation(const Eigen::Quaternionf&);
#endif
void process(ExecutionEnvironment&);
private:
#ifdef __CELVEC__
Vec3f axis;
float angle;
#else
Eigen::Quaternionf orientation;
#endif
};
class CommandLookBack : public InstantaneousCommand

View File

@ -179,12 +179,6 @@ bool DeepSkyObject::load(AssociativeArray* params, const string& resPath)
params->getAngle("Angle", angle);
setOrientation(Quaternionf(AngleAxisf((float) degToRad(angle), axis.cast<float>().normalized())));
#ifdef CELVEC
Quatf q(1);
q.setAxisAngle(Vec3f((float) axis.x, (float) axis.y, (float) axis.z),
(float) degToRad(angle));
setOrientation(toEigen(q));
#endif
double radius = 1.0;
params->getLength("Radius", radius, KM_PER_LY);

View File

@ -33,11 +33,6 @@ bool dsoStraddlesNodesPredicate(const Vector3d& cellCenterPos, DeepSkyObject* co
float dsoRadius = _dso->getBoundingSphereRadius();
return (_dso->getPosition() - cellCenterPos).cwiseAbs().minCoeff() < dsoRadius;
#ifdef CELVEC
return abs(dsoPos.x - cellCenterPos.x) < dsoRadius ||
abs(dsoPos.y - cellCenterPos.y) < dsoRadius ||
abs(dsoPos.z - cellCenterPos.z) < dsoRadius;
#endif
}
@ -89,15 +84,6 @@ void DSOOctree::processVisibleObjects(DSOHandler& processor,
double r = scale * plane.normal().cwiseAbs().sum();
if (plane.signedDistance(cellCenterPos) < -r)
return;
#ifdef CELVEC
double r = scale * (abs(plane->normal.x) +
abs(plane->normal.y) +
abs(plane->normal.z));
if (plane->normal * cellCenterPos - plane->d < -r)
return;
#endif
}
// Compute the distance to node; this is equal to the distance to

View File

@ -178,13 +178,7 @@ ReferenceFrame::getAngularVelocity(double tjd) const
if (std::abs(dq.w()) > 0.99999999)
return Vector3d::Zero();
else
return dq.vec().normalized() * (2.0 * acos(dq.w()) / ANGULAR_VELOCITY_DIFF_DELTA);
#ifdef CELVEC
Vector3d v(dq.x, dq.y, dq.z);
v.normalize();
return v * (2.0 * acos(dq.w) / ANGULAR_VELOCITY_DIFF_DELTA);
#endif
return dq.vec().normalized() * (2.0 * acos(dq.w()) / ANGULAR_VELOCITY_DIFF_DELTA);
}
@ -624,29 +618,6 @@ TwoVectorFrame::computeOrientation(double tjd) const
rhAxis = 1;
bool rhOrder = rhAxis == abs(secondaryAxis);
#ifdef CELVEC
// Set the rotation matrix axes
Vector3d v[3];
v[abs(primaryAxis) - 1] = v0;
// Reverse the cross products if the axes are not in right
// hand order.
if (rhOrder)
{
v[abs(secondaryAxis) - 1] = v2.cross(v0);
v[abs(tertiaryAxis) - 1] = v2;
}
else
{
v[abs(secondaryAxis) - 1] = v0.cross(-v2);
v[abs(tertiaryAxis) - 1] = -v2;
}
// The axes are the rows of a rotation matrix. The getOrientation
// method must return the quaternion representation of the
// orientation, so convert the rotation matrix to a quaternion now.
Quatd q = Quatd::matrixToQuaternion(Mat3d(v[0], v[1], v[2]));
#endif
// Set the rotation matrix axes
Matrix3d m;
m.row(abs(primaryAxis) - 1) = v0;

View File

@ -658,38 +658,21 @@ void InitializeForms()
//Irregular Galaxies
unsigned int galaxySize = GALAXY_POINTS, ip = 0;
Blob b;
#ifdef __CELVEC__
Point3f p;
#else
Vector3f p;
#endif
BlobVector* irregularPoints = new BlobVector;
irregularPoints->reserve(galaxySize);
while (ip < galaxySize)
{
#ifdef __CELVEC__
p = Point3f(Mathf::sfrand(), Mathf::sfrand(), Mathf::sfrand());
float r = p.distanceFromOrigin();
#else
p = Vector3f(Mathf::sfrand(), Mathf::sfrand(), Mathf::sfrand());
float r = p.norm();
#endif
if (r < 1)
{
#ifdef __CELVEC__
float prob = (1 - r) * (fractalsum(Vector3f(p.x + 5, p.y + 5, p.z + 5), 8) + 1) * 0.5f;
#else
float prob = (1 - r) * (fractalsum(Vector3f(p.x() + 5, p.y() + 5, p.z() + 5), 8) + 1) * 0.5f;
#endif
if (Mathf::frand() < prob)
{
#ifdef __CELVEC__
b.position = Vector4f(p.x, p.y, p.z, 1.0f);
#else
b.position = Vector4f(p.x(), p.y(), p.z(), 1.0f);
#endif
b.brightness = 64u;
auto rr = (unsigned int) (r * 511);
b.colorIndex = rr < 256 ? rr : 255;

View File

@ -28,9 +28,6 @@
#include <algorithm>
#include <cassert>
#include <fmt/printf.h>
#ifdef __CELVEC__
#include "eigenport.h"
#endif
using namespace Eigen;
using namespace std;
@ -278,15 +275,9 @@ bool Globular::pick(const Ray3d& ray,
* that blobs are considered points when globulars are built, but have size
* when they are drawn.
*/
#ifdef __CELVEC__
Vec3d ellipsoidAxes(getRadius() * (form->scale.x + RADIUS_CORRECTION),
getRadius() * (form->scale.y + RADIUS_CORRECTION),
getRadius() * (form->scale.z + RADIUS_CORRECTION));
#else
Vector3d ellipsoidAxes(getRadius() * (form->scale.x() + RADIUS_CORRECTION),
getRadius() * (form->scale.y() + RADIUS_CORRECTION),
getRadius() * (form->scale.z() + RADIUS_CORRECTION));
#endif
Vector3d p = getPosition();
return testIntersection(Ray3d(ray.origin - p, ray.direction).transform(getOrientation().cast<double>().toRotationMatrix()),
@ -331,34 +322,20 @@ void Globular::render(const Vector3f& offset,
float pixelSize,
const Renderer* /* unused */)
{
#ifdef __CELVEC__
renderGlobularPointSprites(fromEigen(offset), fromEigen(viewerOrientation), brightness, pixelSize);
#else
renderGlobularPointSprites(offset, viewerOrientation, brightness, pixelSize);
#endif
}
void Globular::renderGlobularPointSprites(
#ifdef __CELVEC__
const Vec3f& offset,
const Quatf& viewerOrientation,
#else
const Vector3f& offset,
const Quaternionf& viewerOrientation,
#endif
float brightness,
float pixelSize)
{
if (form == nullptr)
return;
#ifdef __CELVEC__
float distanceToDSO = offset.length() - getRadius();
#else
float distanceToDSO = offset.norm() - getRadius();
#endif
if (distanceToDSO < 0)
distanceToDSO = 0;
@ -409,18 +386,6 @@ void Globular::renderGlobularPointSprites(
glEnable (GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
#ifdef __CELVEC__
Mat3f viewMat = viewerOrientation.toMatrix3();
Vec3f v0 = Vec3f(-1, -1, 0) * viewMat;
Vec3f v1 = Vec3f( 1, -1, 0) * viewMat;
Vec3f v2 = Vec3f( 1, 1, 0) * viewMat;
Vec3f v3 = Vec3f(-1, 1, 0) * viewMat;
float tidalSize = 2 * tidalRadius;
Mat3f m =
Mat3f::scaling(form->scale) * fromEigen(getOrientation()).toMatrix3() *
Mat3f::scaling(tidalSize);
#else
// XXX or transpose() instead of .adjoint()?
Matrix3f viewMat = viewerOrientation.toRotationMatrix();
Vector3f v0 = viewMat.adjoint() * Vector3f(-1, -1, 0);
@ -430,7 +395,6 @@ void Globular::renderGlobularPointSprites(
float tidalSize = 2 * tidalRadius;
Matrix3f m = Scaling(form->scale) * getOrientation().toRotationMatrix() * Scaling(tidalSize);
#endif
vector<GBlob>* points = form->gblobs;
unsigned int nPoints =
@ -477,11 +441,7 @@ void Globular::renderGlobularPointSprites(
for (unsigned int i = 0; i < nPoints; ++i)
{
GBlob b = (*points)[i];
#ifdef __CELVEC__
Point3f p = b.position * m;
#else
Vector3f p = m * b.position;
#endif
float eta_2d = b.radius_2d;
/*! Note that the [axis,angle] input in globulars.dsc transforms the
@ -503,11 +463,7 @@ void Globular::renderGlobularPointSprites(
break;
}
#ifdef __CELVEC__
float obsDistanceToStarRatio = (p + offset).distanceFromOrigin() / clipDistance;
#else
float obsDistanceToStarRatio = (p + offset).norm() / clipDistance;
#endif
float saveSize = starSize;
if (obsDistanceToStarRatio < 1.0f)
@ -627,11 +583,7 @@ GlobularForm* buildGlobularForms(float c)
float sthetu2 = sin(theta) * sqrt(1.0f - u * u);
// x,y,z points within -0.5..+0.5, as required for consistency:
#ifdef __CELVEC__
b.position = 0.5f * Point3f(eta * sqrt(1.0f - u * u) * cos(theta), eta * sthetu2 , eta * u);
#else
b.position = 0.5f * Vector3f(eta * sqrt(1.0f - u * u) * cos(theta), eta * sthetu2 , eta * u);
#endif
/*
* Note: 2d projection in x-z plane, according to Celestia's
@ -658,11 +610,7 @@ GlobularForm* buildGlobularForms(float c)
auto* globularForm = new GlobularForm();
globularForm->gblobs = globularPoints;
#ifdef __CELVEC__
globularForm->scale = Vec3f(1.0f, 1.0f, 1.0f);
#else
globularForm->scale = Vector3f::Ones();
#endif
return globularForm;
}

View File

@ -21,11 +21,7 @@
struct GBlob
{
#ifdef __CELVEC__
Point3f position;
#else
Eigen::Vector3f position;
#endif
unsigned int colorIndex;
float radius_2d;
};
@ -33,11 +29,7 @@ struct GBlob
struct GlobularForm
{
std::vector<GBlob>* gblobs;
#ifdef __CELVEC__
Vec3f scale;
#else
Eigen::Vector3f scale;
#endif
};
class Globular : public DeepSkyObject
@ -71,14 +63,8 @@ class Globular : public DeepSkyObject
float brightness,
float pixelSize,
const Renderer* r = nullptr);
virtual void renderGlobularPointSprites(
#ifdef __CELVEC__
const Vec3f& offset,
const Quatf& viewerOrientation,
#else
const Eigen::Vector3f& offset,
virtual void renderGlobularPointSprites(const Eigen::Vector3f& offset,
const Eigen::Quaternionf& viewerOrientation,
#endif
float brightness,
float pixelSize);
GlobularForm* getForm() const;

View File

@ -13,17 +13,12 @@
#include <iostream>
#include <algorithm>
#include <celmath/mathlib.h>
#ifdef __CELVEC__
#include <celmath/vecmath.h>
#endif
#include <GL/glew.h>
#include "vecgl.h"
#include "lodspheremesh.h"
using namespace std;
#ifndef __CELVEC__
using namespace Eigen;
#endif
//#define SHOW_PATCH_VISIBILITY
//#define SHOW_FRUSTUM
@ -51,7 +46,7 @@ static const int MaxPatchesShown = 4096;
static int visiblePatches[MaxPatchesShown];
#endif
#ifndef __CELVEC__
// TODO: figure out how to use std eigen's methods instead
static Vector3f intersect3(const Frustum::PlaneType& p0,
const Frustum::PlaneType& p1,
@ -67,8 +62,6 @@ static Vector3f intersect3(const Frustum::PlaneType& p0,
p1.offset() * p2.normal().cross(p0.normal()) +
p2.offset() * p0.normal().cross(p1.normal())) * (1.0f / d);
}
#endif
static void InitTrigArrays()
{
@ -139,21 +132,12 @@ LODSphereMesh::~LODSphereMesh()
}
#ifdef __CELVEC__
static Point3f spherePoint(int theta, int phi)
{
return Point3f(cosPhi[phi] * cosTheta[theta],
sinPhi[phi],
cosPhi[phi] * sinTheta[theta]);
}
#else
static Vector3f spherePoint(int theta, int phi)
{
return Vector3f(cosPhi[phi] * cosTheta[theta],
sinPhi[phi],
cosPhi[phi] * sinTheta[theta]);
}
#endif
void LODSphereMesh::render(const Frustum& frustum,
@ -365,32 +349,6 @@ void LODSphereMesh::render(unsigned int attributes,
// Compute the vertices of the view frustum. These will be used for
// culling patches.
#ifdef __CELVEC__
ri.fp[0] = Planef::intersection(frustum.getPlane(Frustum::Near),
frustum.getPlane(Frustum::Top),
frustum.getPlane(Frustum::Left));
ri.fp[1] = Planef::intersection(frustum.getPlane(Frustum::Near),
frustum.getPlane(Frustum::Top),
frustum.getPlane(Frustum::Right));
ri.fp[2] = Planef::intersection(frustum.getPlane(Frustum::Near),
frustum.getPlane(Frustum::Bottom),
frustum.getPlane(Frustum::Left));
ri.fp[3] = Planef::intersection(frustum.getPlane(Frustum::Near),
frustum.getPlane(Frustum::Bottom),
frustum.getPlane(Frustum::Right));
ri.fp[4] = Planef::intersection(frustum.getPlane(Frustum::Far),
frustum.getPlane(Frustum::Top),
frustum.getPlane(Frustum::Left));
ri.fp[5] = Planef::intersection(frustum.getPlane(Frustum::Far),
frustum.getPlane(Frustum::Top),
frustum.getPlane(Frustum::Right));
ri.fp[6] = Planef::intersection(frustum.getPlane(Frustum::Far),
frustum.getPlane(Frustum::Bottom),
frustum.getPlane(Frustum::Left));
ri.fp[7] = Planef::intersection(frustum.getPlane(Frustum::Far),
frustum.getPlane(Frustum::Bottom),
frustum.getPlane(Frustum::Right));
#else
ri.fp[0] = intersect3(frustum.plane(Frustum::Near),
frustum.plane(Frustum::Top),
frustum.plane(Frustum::Left));
@ -415,7 +373,6 @@ void LODSphereMesh::render(unsigned int attributes,
ri.fp[7] = intersect3(frustum.plane(Frustum::Far),
frustum.plane(Frustum::Bottom),
frustum.plane(Frustum::Right));
#endif
#ifdef SHOW_PATCH_VISIBILITY
@ -575,25 +532,6 @@ int LODSphereMesh::renderPatches(int phi0, int theta0,
// the rest of the sphere. If the view frustum lies entirely
// on the side of the plane that does not contain the sphere
// patch, we cull the patch.
#ifdef __CELVEC__
Point3f p0 = spherePoint(theta0, phi0);
Point3f p1 = spherePoint(theta0 + thetaExtent, phi0);
Point3f p2 = spherePoint(theta0 + thetaExtent,
phi0 + phiExtent);
Point3f p3 = spherePoint(theta0, phi0 + phiExtent);
Vec3f v0 = p1 - p0;
Vec3f v2 = p3 - p2;
Vec3f normal;
if (v0.lengthSquared() > v2.lengthSquared())
normal = (p0 - p3) ^ v0;
else
normal = (p2 - p1) ^ v2;
// If the normal is near zero length, something's going wrong
assert(normal.length() != 0.0f);
normal.normalize();
Planef separatingPlane(normal, p0);
#else
Vector3f p0 = spherePoint(theta0, phi0);
Vector3f p1 = spherePoint(theta0 + thetaExtent, phi0);
Vector3f p2 = spherePoint(theta0 + thetaExtent,
@ -612,17 +550,12 @@ int LODSphereMesh::renderPatches(int phi0, int theta0,
assert(normal.norm() != 0.0f);
normal.normalize();
Frustum::PlaneType separatingPlane(normal, p0);
#endif
bool outside = true;
#if 1
for (int k = 0; k < 8; k++)
{
#ifdef __CELVEC__
if (separatingPlane.distanceTo(ri.fp[k]) > 0.0f)
#else
if (separatingPlane.absDistance(ri.fp[k]) > 0.0f)
#endif
{
outside = false;
break;
@ -643,28 +576,15 @@ int LODSphereMesh::renderPatches(int phi0, int theta0,
phi0 + phiExtent / 2);
#else
// . . . or is the average of the points better?
#ifdef __CELVEC__
Point3f patchCenter = Point3f(p0.x + p1.x + p2.x + p3.x,
p0.y + p1.y + p2.y + p3.y,
p0.z + p1.z + p2.z + p3.z) * 0.25f;
#else
Vector3f patchCenter = Vector3f(p0.x() + p1.x() + p2.x() + p3.x(),
p0.y() + p1.y() + p2.y() + p3.y(),
p0.z() + p1.z() + p2.z() + p3.z()) * 0.25f;
#endif
#endif
float boundingRadius = 0.0f;
#ifdef __CELVEC__
boundingRadius = max(boundingRadius, patchCenter.distanceTo(p0));
boundingRadius = max(boundingRadius, patchCenter.distanceTo(p1));
boundingRadius = max(boundingRadius, patchCenter.distanceTo(p2));
boundingRadius = max(boundingRadius, patchCenter.distanceTo(p3));
#else
boundingRadius = max(boundingRadius, (patchCenter - p0).norm()); // patchCenter.distanceTo(p0)
boundingRadius = max(boundingRadius, (patchCenter - p1).norm());
boundingRadius = max(boundingRadius, (patchCenter - p2).norm());
boundingRadius = max(boundingRadius, (patchCenter - p3).norm());
#endif
if (ri.frustum.testSphere(patchCenter, boundingRadius) == Frustum::Outside)
outside = true;

View File

@ -13,11 +13,7 @@
#include <celengine/texture.h>
#include <celengine/glcontext.h>
#ifdef __CELVEC__
#include <celmath/vecmath.h>
#else
#include <Eigen/Geometry>
#endif
#include <celmath/frustum.h>
@ -62,11 +58,7 @@ public:
int step;
unsigned int attributes; // vertex attributes
const Frustum& frustum; // frustum, for culling
#ifdef __CELVEC__
Point3f fp[8]; // frustum points, for culling
#else
Eigen::Vector3f fp[8]; // frustum points, for culling
#endif
int texLOD[MAX_SPHERE_MESH_TEXTURES];
};

View File

@ -264,19 +264,6 @@ lookAt(Matrix<T, 3, 1> from, Matrix<T, 3, 1> to, Matrix<T, 3, 1> up)
return Quaternion<T>(m).conjugate();
}
#ifdef CELVEC
template<class T> static Quat<T>
lookAt(Point3<T> from, Point3<T> to, Vector3<T> up)
{
Vector3<T> n = to - from;
n.normalize();
Vector3<T> v = n ^ up;
v.normalize();
Vector3<T> u = v ^ n;
return Quat<T>::matrixToQuaternion(Matrix3<T>(v, u, -n));
}
#endif
double Observer::getArrivalTime() const
{
@ -310,9 +297,6 @@ void Observer::update(double dt, double timeScale)
t = (float) clamp((realTime - journey.startTime) / journey.duration);
Vector3d jv = journey.to.offsetFromKm(journey.from);
#ifdef CELVEC
Vector3d jv = journey.to - journey.from;
#endif
UniversalCoord p;
// Another interpolation method . . . accelerate exponentially,
@ -348,12 +332,6 @@ void Observer::update(double dt, double timeScale)
p = journey.from.offsetKm(v * x);
else
p = journey.to.offsetKm(-v * x);
#ifdef CELVEC
if (t < 0.5)
p = journey.from + v * astro::kilometersToMicroLightYears(x);
else
p = journey.to - v * astro::kilometersToMicroLightYears(x);
#endif
}
}
else if (journey.traj == GreatCircle)
@ -392,17 +370,6 @@ void Observer::update(double dt, double timeScale)
v = slerp(x, v1, v0);
p = frame->convertFromUniversal(origin.offsetKm(v), simTime);
#ifdef CELVEC
x = astro::kilometersToMicroLightYears(x / jv.length());
Vector3d v;
if (t < 0.5)
v = slerp(x, v0, v1);
else
v = slerp(x, v1, v0);
p = frame->convertFromUniversal(origin + v, simTime);
#endif
}
}
else if (journey.traj == CircularOrbit)
@ -451,18 +418,6 @@ void Observer::update(double dt, double timeScale)
}
q = journey.initialOrientation.slerp(v, journey.finalOrientation);
#ifdef CELVEC
// Be careful to choose the shortest path when interpolating
if ((journey.initialOrientation.coeffs() - journey.finalOrientation.coeffs()).norm() <
(journey.initialOrientation.coeffs() + journey.finalOrientation.coeffs()).norm())
{
q = journey.initialOrientation.slerp(v, journey.finalOrientation);
}
else
{
q = journey.initialOrientation.slerp(v, journey.finalOrientation * -1.0);
}
#endif
}
else if (t < journey.startInterpolation)
{
@ -512,11 +467,6 @@ void Observer::update(double dt, double timeScale)
Quaterniond dr = Quaterniond(0.0, halfAV.x(), halfAV.y(), halfAV.z()) * orientation;
orientation = Quaterniond(orientation.coeffs() + dt * dr.coeffs());
orientation.normalize();
#ifdef CELVEC
Quaterniond dr = 0.5 * (AV * orientation);
orientation += dt * dr;
orientation.normalize();
#endif
}
updateUniversal();
@ -572,11 +522,6 @@ void Observer::setLocationFilter(uint64_t _locationFilter)
void Observer::reverseOrientation()
{
setOrientation(getOrientation() * Quaterniond(AngleAxisd(PI, Vector3d::UnitY())));
#ifdef CELVEC
Quatd q = getOrientation();
q.yrotate(PI);
setOrientation(q);
#endif
reverseFlag = !reverseFlag;
}

View File

@ -393,31 +393,6 @@ bool AssociativeArray::getBoolean(const string& key, bool& val) const
return true;
}
#ifdef __CELVEC__
bool AssociativeArray::getVector(const string& key, Vec3d& val) const
{
Value* v = getValue(key);
if (v == nullptr || v->getType() != Value::ArrayType)
return false;
ValueArray* arr = v->getArray();
if (arr->size() != 3)
return false;
Value* x = (*arr)[0];
Value* y = (*arr)[1];
Value* z = (*arr)[2];
if (x->getType() != Value::NumberType ||
y->getType() != Value::NumberType ||
z->getType() != Value::NumberType)
return false;
val = Vec3d(x->getNumber(), y->getNumber(), z->getNumber());
return true;
}
#endif
bool AssociativeArray::getVector(const string& key, Vector3d& val) const
{
Value* v = getValue(key);
@ -441,19 +416,6 @@ bool AssociativeArray::getVector(const string& key, Vector3d& val) const
return true;
}
#ifdef __CELVEC__
bool AssociativeArray::getVector(const string& key, Vec3f& val) const
{
Vec3d vecVal;
if (!getVector(key, vecVal))
return false;
val = Vec3f((float) vecVal.x, (float) vecVal.y, (float) vecVal.z);
return true;
}
#endif
bool AssociativeArray::getVector(const string& key, Vector3f& val) const
{
@ -467,46 +429,6 @@ bool AssociativeArray::getVector(const string& key, Vector3f& val) const
}
#ifdef __CELVEC__
/** @copydoc AssociativeArray::getRotation() */
bool AssociativeArray::getRotation(const string& key, Quatf& val) const
{
Value* v = getValue(key);
if (v == nullptr || v->getType() != Value::ArrayType)
return false;
ValueArray* arr = v->getArray();
if (arr->size() != 4)
return false;
Value* w = (*arr)[0];
Value* x = (*arr)[1];
Value* y = (*arr)[2];
Value* z = (*arr)[3];
if (w->getType() != Value::NumberType ||
x->getType() != Value::NumberType ||
y->getType() != Value::NumberType ||
z->getType() != Value::NumberType)
return false;
Vec3f axis((float) x->getNumber(),
(float) y->getNumber(),
(float) z->getNumber());
axis.normalize();
double ang = w->getNumber();
double angScale = 1.0;
getAngleScale(key, angScale);
float angle = degToRad((float) (ang * angScale));
val.setAxisAngle(axis, angle);
return true;
}
#endif
/**
* Retrieves a quaternion, scaled to an associated angle unit.
*

View File

@ -14,10 +14,6 @@
#include <vector>
#include <map>
#include <celmath/mathlib.h>
#ifdef __CELVEC__
#include <celmath/vecmath.h>
#include <celmath/quaternion.h>
#endif
#include <celutil/color.h>
#include <celengine/tokenizer.h>
#include <Eigen/Core>
@ -44,11 +40,6 @@ class AssociativeArray
bool getBoolean(const std::string&, bool&) const;
bool getVector(const std::string&, Eigen::Vector3d&) const;
bool getVector(const std::string&, Eigen::Vector3f&) const;
#ifdef __CELVEC__
bool getVector(const std::string&, Vec3d&) const;
bool getVector(const std::string&, Vec3f&) const;
bool getRotation(const std::string&, Quatf&) const;
#endif
bool getRotation(const std::string&, Eigen::Quaternionf&) const;
bool getColor(const std::string&, Color&) const;
bool getAngle(const std::string&, double&, double = 1.0, double = 0.0) const;

View File

@ -82,9 +82,6 @@ std::ofstream hdrlog;
#include <sstream>
#include <iomanip>
#include <numeric>
#ifdef __CELVEC__
#include "eigenport.h"
#endif
using namespace cmod;
using namespace Eigen;
@ -2611,11 +2608,7 @@ void Renderer::draw(const Observer& observer,
setupSecondaryLightSources(secondaryIlluminators, lightSourceList);
#ifdef USE_HDR
#ifdef __CELVEC__
Mat3f viewMat = conjugate(observer.getOrientationf()).toMatrix3();
#else
Matrix3f viewMat = observer.getOrientationf().conjugate().toRotationMatrix();
#endif
float maxSpan = (float) sqrt(square((float) windowWidth) +
square((float) windowHeight));
float nearZcoeff = (float) cos(degToRad(fov / 2)) *
@ -2626,11 +2619,7 @@ void Renderer::draw(const Observer& observer,
auto notCulled = renderList.begin();
for (const auto& render_item : renderList)
{
#ifdef __CELVEC__
Point3f center = render_item.position * viewMat;
#else
Vector3f center = viewMat * render_item.position;
#endif
bool convex = true;
float radius = 1.0f;
@ -2674,11 +2663,7 @@ void Renderer::draw(const Observer& observer,
// Test the object's bounding sphere against the view frustum
if (frustum.testSphere(center, cullRadius) != Frustum::Outside)
{
#ifdef __CELVEC__
float nearZ = center.distanceFromOrigin() - radius;
#else
float nearZ = center.norm() - radius;
#endif
nearZ = -nearZ * nearZcoeff;
if (nearZ > -MinNearPlaneDistance)
@ -2688,22 +2673,14 @@ void Renderer::draw(const Observer& observer,
if (!convex)
{
#ifdef __CELVEC__
render_item.farZ = center.z - radius;
#else
render_item.farZ = center.z() - radius;
#endif
if (render_item.farZ / render_item.nearZ > MaxFarNearRatio * 0.5f)
render_item.nearZ = render_item.farZ / (MaxFarNearRatio * 0.5f);
}
else
{
// Make the far plane as close as possible
#ifdef __CELVEC__
float d = center.distanceFromOrigin();
#else
float d = center.norm();
#endif
// Account for ellipsoidal objects
float eradius = radius;
if (render_item.body != nullptr) // XXX: not checked before
@ -3160,27 +3137,16 @@ void Renderer::draw(const Observer& observer,
{
const Body *body = closestBody->body;
double scale = astro::microLightYearsToKilometers(1.0);
#ifdef __CELVEC__
Point3d posBody = body->getAstrocentricPosition(now);
Point3d posStar;
Point3d posEye = astrocentricPosition(observer.getPosition(), *brightestStar, now);
#else
Vector3d posBody = body->getAstrocentricPosition(now);
Vector3d posStar;
Vector3d posEye = astrocentricPosition(observer.getPosition(), *brightestStar, now);
#endif
if (body->getSystem() &&
body->getSystem()->getStar() &&
body->getSystem()->getStar() != brightestStar)
{
UniversalCoord center = body->getSystem()->getStar()->getPosition(now);
#ifdef __CELVEC__
Vec3d v = brightestStar->getPosition(now) - center;
posStar = Point3d(v.x, v.y, v.z);
#else
posStar = brightestStar->getPosition(now) - center;
#endif
}
else
{
@ -4667,32 +4633,10 @@ void Renderer::renderObject(const Vector3f& pos,
}
// Compute the inverse model/view matrix
// TODO: This code uses the old vector classes, but will be eliminated when the new planet rendering code
// is adopted. The new planet renderer doesn't require the inverse transformed view frustum.
#ifndef __CELVEC__
/*
Transform3f invModelView = cameraOrientation.conjugate() *
Translation3f(-pos) *
obj.orientation *
Scaling3f(1.0f / radius);
*/
Affine3f invModelView = obj.orientation *
Translation3f(-pos / obj.radius) *
cameraOrientation.conjugate();
Matrix4f invMV = invModelView.matrix();
#else
Matrix4f planetMat = Matrix4f::Identity();
planetMat.topLeftCorner(3, 3) = planetRotation;
Mat4f planetMat_old(Vec4f(planetMat.col(0).x(), planetMat.col(0).y(), planetMat.col(0).z(), planetMat.col(0).w()),
Vec4f(planetMat.col(1).x(), planetMat.col(1).y(), planetMat.col(1).z(), planetMat.col(1).w()),
Vec4f(planetMat.col(2).x(), planetMat.col(2).y(), planetMat.col(2).z(), planetMat.col(2).w()),
Vec4f(planetMat.col(3).x(), planetMat.col(3).y(), planetMat.col(3).z(), planetMat.col(3).w()));
Mat4f invMV = (fromEigen(cameraOrientation).toMatrix4() *
Mat4f::translation(Point3f(-pos.x() / radius, -pos.y() / radius, -pos.z() / radius)) *
planetMat_old);
#endif
// The sphere rendering code uses the view frustum to determine which
// patches are visible. In order to avoid rendering patches that can't
@ -6372,26 +6316,14 @@ void Renderer::buildLabelLists(const Frustum& viewFrustum,
// Not rejected. Compute the plane tangent to
// the primary at the viewer-to-primary
// intersection point.
#ifdef __CELVEC__
Vec3d primaryVec(primarySphere.center.x(),
primarySphere.center.y(),
primarySphere.center.z());
double distToPrimary = primaryVec.length();
Planed primaryTangentPlane(primaryVec, primaryVec * (primaryVec * (1.0 - primarySphere.radius / distToPrimary)));
#else
Vector3d primaryVec = primarySphere.center;
double distToPrimary = primaryVec.norm();
Hyperplane<double, 3> primaryTangentPlane(primaryVec,
primaryVec.dot(primaryVec * (1.0 - primarySphere.radius / distToPrimary)));
#endif
// Compute the intersection of the viewer-to-labeled
// object ray with the tangent plane.
#ifdef __CELVEC__
float u = (float) (primaryTangentPlane.d / (primaryTangentPlane.normal * Vec3d(pos.x(), pos.y(), pos.z())));
#else
float u = (float) (primaryTangentPlane.offset() / primaryTangentPlane.normal().dot(pos.cast<double>()));
#endif
// If the intersection point is closer to the viewer
// than the label, then project the label onto the

View File

@ -13,37 +13,11 @@
#ifndef _CELENGINE_VECGL_H_
#define _CELENGINE_VECGL_H_
#ifdef __CELVEC__
#include <celmath/vecmath.h>
#include <celmath/quaternion.h>
#endif
#include <celutil/color.h>
#include <GL/glew.h>
#include <Eigen/Core>
#include <Eigen/Geometry>
#ifdef __CELVEC__
inline void glVertex(const Point3f& p)
{
glVertex3fv(&p.x);
}
inline void glVertex(const Vec3f& v)
{
glVertex3fv(&v.x);
}
inline void glNormal(const Vec3f& n)
{
glNormal3fv(&n.x);
}
inline void glTexCoord(const Point2f& p)
{
glTexCoord2fv(&p.x);
}
#endif
inline void glColor(const Color& c)
{
@ -56,47 +30,6 @@ inline void glColor(const Color& c, float a)
}
#ifdef __CELVEC__
inline void glMatrix(const Mat4f& m)
{
Mat4f trans = m.transpose();
glMultMatrixf(&trans[0].x);
}
inline void glMatrix(const Mat4d& m)
{
Mat4d trans = m.transpose();
glMultMatrixd(&trans[0].x);
}
inline void glRotate(const Quatf& q)
{
glMatrix(q.toMatrix4());
}
inline void glRotate(const Quatd& q)
{
glMatrix(q.toMatrix4());
}
inline void glTranslate(const Vec3f& v)
{
glTranslatef(v.x, v.y, v.z);
}
inline void glTranslate(const Point3f& p)
{
glTranslatef(p.x, p.y, p.z);
}
inline void glScale(const Vec3f& v)
{
glScalef(v.x, v.y, v.z);
}
#endif
#if 0
inline void glLightDirection(GLenum light, const Vec3f& dir)
{

View File

@ -3111,9 +3111,6 @@ class JPLEphOrbit : public CachingOrbit
}
// Rotate from the J2000 mean equator to the ecliptic
#ifdef CELVEC
pos = pos * Mat3d::xrotation(astro::J2000Obliquity);
#endif
pos = XRotation(-astro::J2000Obliquity) * pos;
// Convert to Celestia's coordinate system

View File

@ -49,11 +49,6 @@ RotationModel::angularVelocityAtTime(double tdb) const
return Vector3d::Zero();
return dq.vec().normalized() * (2.0 * acos(dq.w()) / dt);
#ifdef CELVEC
Vector3d v(dq.x, dq.y, dq.z);
v.normalize();
return v * (2.0 * acos(dq.w) / dt);
#endif
}
@ -148,11 +143,6 @@ CachingRotationModel::computeAngularVelocity(double tjd) const
return Vector3d::Zero();
return dq.vec().normalized() * (2.0 * acos(dq.w()) / dt);
#ifdef CELVEC
Vec3d v(dq.x, dq.y, dq.z);
v.normalize();
return v * (2.0 * acos(dq.w) / dt);
#endif
}

View File

@ -174,11 +174,6 @@ ScriptedOrbit::computePosition(double tjd) const
if (lua_pcall(luaState, 2, 3, 0) == 0)
{
pos = Vector3d(lua_tonumber(luaState, -3), lua_tonumber(luaState, -2), lua_tonumber(luaState, -1));
#ifdef CELVEC
pos.x = lua_tonumber(luaState, -3);
pos.y = lua_tonumber(luaState, -2);
pos.z = lua_tonumber(luaState, -1);
#endif
lua_pop(luaState, 3);
}
else

View File

@ -155,12 +155,6 @@ ScriptedRotation::spin(double tjd) const
lua_tonumber(luaState, -3),
lua_tonumber(luaState, -2),
lua_tonumber(luaState, -1));
#ifdef CELVEC
lastOrientation.w = lua_tonumber(luaState, -4);
lastOrientation.x = lua_tonumber(luaState, -3);
lastOrientation.y = lua_tonumber(luaState, -2);
lastOrientation.z = lua_tonumber(luaState, -1);
#endif
lua_pop(luaState, 4);
lastTime = tjd;
}

View File

@ -19,9 +19,6 @@
#include <celengine/cmdparser.h>
#include <celengine/execenv.h>
#include <celengine/execution.h>
#ifdef __CELVEC__
#include <celmath/vecmath.h>
#endif
#include <celengine/timeline.h>
#include <celengine/timelinephase.h>
#include <fmt/printf.h>
@ -42,10 +39,6 @@
#include "celx_gl.h"
#include "celx_category.h"
#ifdef __CELVEC__
#include <celengine/eigenport.h>
#endif
// Older gcc versions used <strstream> instead of <sstream>.
// This has been corrected in GCC 3.2, but name clashing must
@ -1958,23 +1951,11 @@ bool CelxLua::safeGetBoolean(int index,
}
#ifdef __CELVEC__
void CelxLua::newVector(const Vec3d& v)
{
vector_new(m_lua, v);
}
void CelxLua::newVector(const Vector3d& v)
{
vector_new(m_lua, fromEigen(v));
}
#else
void CelxLua::newVector(const Vector3d& v)
{
vector_new(m_lua, v);
}
#endif
void CelxLua::newPosition(const UniversalCoord& uc)
{
@ -1982,11 +1963,7 @@ void CelxLua::newPosition(const UniversalCoord& uc)
}
#ifdef __CELVEC__
void CelxLua::newRotation(const Quatd& q)
#else
void CelxLua::newRotation(const Quaterniond& q)
#endif
{
rotation_new(m_lua, q);
}
@ -2006,20 +1983,12 @@ void CelxLua::newPhase(const TimelinePhase& phase)
phase_new(m_lua, phase);
}
#ifdef __CELVEC__
Vec3d* CelxLua::toVector(int n)
#else
Vector3d* CelxLua::toVector(int n)
#endif
{
return to_vector(m_lua, n);
}
#ifdef __CELVEC__
Quatd* CelxLua::toRotation(int n)
#else
Quaterniond* CelxLua::toRotation(int n)
#endif
{
return to_rotation(m_lua, n);
}

View File

@ -1653,11 +1653,7 @@ static int celestia_newvector(lua_State* l)
double y = Celx_SafeGetNumber(l, 3, AllErrors, "Second arg to celestia:newvector must be a number");
double z = Celx_SafeGetNumber(l, 4, AllErrors, "Third arg to celestia:newvector must be a number");
#ifdef __CELVEC__
vector_new(l, Vec3d(x,y,z));
#else
vector_new(l, Vector3d(x,y,z));
#endif
return 1;
}
@ -1704,11 +1700,7 @@ static int celestia_newrotation(lua_State* l)
double x = Celx_SafeGetNumber(l, 3, AllErrors, "arguments to celestia:newrotation must either be (vec, number) or four numbers");
double y = Celx_SafeGetNumber(l, 4, AllErrors, "arguments to celestia:newrotation must either be (vec, number) or four numbers");
double z = Celx_SafeGetNumber(l, 5, AllErrors, "arguments to celestia:newrotation must either be (vec, number) or four numbers");
#ifdef __CELVEC__
Quatd q(w, x, y, z);
#else
Quaterniond q(w, x, y, z);
#endif
rotation_new(l, q);
}
else
@ -1720,12 +1712,7 @@ static int celestia_newrotation(lua_State* l)
return 0;
}
double angle = Celx_SafeGetNumber(l, 3, AllErrors, "second argument to celestia:newrotation must be a number");
#ifdef __CELVEC__
Quatd q;
q.setAxisAngle(*v, angle);
#else
Quaterniond q(AngleAxisd(angle, v->normalized()));
#endif
rotation_new(l, q);
}
return 1;

View File

@ -15,9 +15,6 @@
#include "celestiacore.h"
#include <celengine/observer.h>
#include <Eigen/Geometry>
#ifdef __CELVEC__
#include <celengine/eigenport.h>
#endif
using namespace Eigen;
@ -69,11 +66,7 @@ static int frame_from(lua_State* l)
CelestiaCore* appCore = celx.appCore(AllErrors);
UniversalCoord* uc = nullptr;
#ifdef __CELVEC__
Quatd* q = nullptr;
#else
Quaterniond* q = nullptr;
#endif
double jd = 0.0;
if (celx.isType(2, Celx_Position))
@ -99,11 +92,7 @@ static int frame_from(lua_State* l)
}
else
{
#ifdef __CELVEC__
Quatd q1 = fromEigen(frame->convertToUniversal(toEigen(*q), jd));
#else
Quaterniond q1 = frame->convertToUniversal(*q, jd);
#endif
celx.newRotation(q1);
}
@ -121,11 +110,7 @@ static int frame_to(lua_State* l)
CelestiaCore* appCore = celx.appCore(AllErrors);
UniversalCoord* uc = nullptr;
#ifdef __CELVEC__
Quatd* q = nullptr;
#else
Quaterniond* q = nullptr;
#endif
double jd = 0.0;
if (celx.isType(2, Celx_Position))
@ -152,13 +137,8 @@ static int frame_to(lua_State* l)
}
else
{
#ifdef __CELVEC__
Quaterniond q1 = frame->convertFromUniversal(toEigen(*q), jd);
celx.newRotation(fromEigen(q1));
#else
Quaterniond q1 = frame->convertFromUniversal(*q, jd);
celx.newRotation(q1);
#endif
}
return 1;

View File

@ -256,25 +256,14 @@ public:
void setTable(const char* field, const char* value);
void newFrame(const ObserverFrame& f);
#ifdef __CELVEC__
void newVector(const Vec3d& v);
#endif
void newVector(const Eigen::Vector3d& v);
#ifdef __CELVEC__
void newRotation(const Quatd& q);
#endif
void newRotation(const Eigen::Quaterniond& q);
void newPosition(const UniversalCoord& uc);
void newObject(const Selection& sel);
void newPhase(const TimelinePhase& phase);
#ifdef __CELVEC__
Vec3d* toVector(int n);
Quatd* toRotation(int n);
#else
Eigen::Vector3d* toVector(int n);
Eigen::Quaterniond* toRotation(int n);
#endif
UniversalCoord* toPosition(int n);
Selection* toObject(int n);
ObserverFrame* toFrame(int n);

View File

@ -16,9 +16,6 @@
//#include <celengine/timelinephase.h>
#include "celestiacore.h"
#include <Eigen/Geometry>
#ifdef __CELVEC__
#include <celengine/eigenport.h>
#endif
using namespace Eigen;
@ -112,11 +109,7 @@ static int observer_setorientation(lua_State* l)
celx.doError("Argument to observer:setorientation must be a rotation");
return 0;
}
#ifdef __CELVEC__
o->setOrientation(toEigen(*q));
#else
o->setOrientation(*q);
#endif
return 0;
}
@ -126,11 +119,7 @@ static int observer_getorientation(lua_State* l)
celx.checkArgs(1, 1, "No arguments expected to observer:getorientation()");
Observer* o = this_observer(l);
#ifdef __CELVEC__
celx.newRotation(fromEigen(o->getOrientation()));
#else
celx.newRotation(o->getOrientation());
#endif
return 1;
}
@ -148,12 +137,7 @@ static int observer_rotate(lua_State* l)
celx.doError("Argument to observer:setpos must be a rotation");
return 0;
}
#ifdef __CELVEC__
Quatf qf((float) q->w, (float) q->x, (float) q->y, (float) q->z);
o->rotate(toEigen(qf));
#else
o->rotate(q->cast<float>());
#endif
return 0;
}
@ -171,12 +155,7 @@ static int observer_orbit(lua_State* l)
celx.doError("Argument for observer:orbit must be a rotation");
return 0;
}
#ifdef __CELVEC__
Quatf qf((float) q->w, (float) q->x, (float) q->y, (float) q->z);
o->orbit(Selection(), toEigen(qf));
#else
o->orbit(Selection(), q->cast<float>());
#endif
return 0;
}
@ -191,11 +170,7 @@ static int observer_lookat(lua_State* l)
UniversalCoord* from = nullptr;
UniversalCoord* to = nullptr;
#ifdef __CELVEC__
Vec3d* upd = nullptr;
#else
Vector3d* upd = nullptr;
#endif
if (argc == 3)
{
@ -237,18 +212,6 @@ static int observer_lookat(lua_State* l)
{
nd = to->offsetFromKm(*from);
}
#ifdef __CELVEC__
// need Vec3f instead:
Vec3f up = Vec3f((float) upd->x, (float) upd->y, (float) upd->z);
Vec3f n = fromEigen(nd.cast<float>());
n.normalize();
Vec3f v = n ^ up;
v.normalize();
Vec3f u = v ^ n;
Quatf qf = Quatf(Mat3f(v, u, -n));
o->setOrientation(toEigen(qf));
#else
Vector3f up = upd->cast<float>();
Vector3f n = nd.cast<float>().normalized();
@ -257,7 +220,6 @@ static int observer_lookat(lua_State* l)
Matrix3f m;
m.row(0) = v; m.row(1) = u; m.row(2) = n * (-1);
o->setOrientation(Quaternionf(m));
#endif
return 0;
}
@ -307,22 +269,14 @@ static int observer_gototable(lua_State* l)
lua_gettable(l, 2);
auto rot1 = celx.toRotation(3);
if (rot1 != nullptr)
#ifdef __CELVEC__
jparams.initialOrientation = toEigen(*rot1);
#else
jparams.initialOrientation = *rot1;
#endif
lua_settop(l, 2);
lua_pushstring(l, "finalOrientation");
lua_gettable(l, 2);
auto rot2 = celx.toRotation(3);
if (rot2 != nullptr)
#ifdef __CELVEC__
jparams.finalOrientation = toEigen(*rot2);
#else
jparams.finalOrientation = *rot2;
#endif
lua_settop(l, 2);
lua_pushstring(l, "startInterpolation");
@ -426,11 +380,7 @@ static int observer_gotolonglat(lua_State* l)
celx.doError("Sixth argument to observer:gotolonglat must be a vector");
return 0;
}
#ifdef __CELVEC__
up = toEigen(*uparg).cast<float>();
#else
up = uparg->cast<float>();
#endif
}
o->gotoSelectionLongLat(*sel, travelTime, distance, (float)longitude, (float)latitude, up);
@ -488,11 +438,7 @@ static int observer_gotodistance(lua_State* l)
return 0;
}
#ifdef __CELVEC__
up = toEigen(*up_arg).cast<float>();
#else
up = up_arg->cast<float>();
#endif
}
o->gotoSelection(*sel, travelTime, distance, up, ObserverFrame::Universal);

View File

@ -15,9 +15,6 @@
#include <celengine/timelinephase.h>
#include <celephem/orbit.h>
#include <celephem/rotation.h>
#ifdef __CELVEC__
#include <celengine/eigenport.h>
#endif
// We want to avoid copying TimelinePhase objects, so we can't make them
@ -190,11 +187,7 @@ static int phase_getorientation(lua_State* l)
tdb = phase->startTime();
else if (tdb > phase->endTime())
tdb = phase->endTime();
#ifdef __CELVEC__
celx.newRotation(fromEigen(phase->rotationModel()->orientationAtTime(tdb)));
#else
celx.newRotation(phase->rotationModel()->orientationAtTime(tdb));
#endif
return 1;
}

View File

@ -13,9 +13,6 @@
#include "celx_internal.h"
#include "celx_position.h"
#include <Eigen/Geometry>
#ifdef __CELVEC__
#include <celengine/eigenport.h>
#endif
using namespace Eigen;
@ -169,11 +166,7 @@ static int position_vectorto(lua_State* l)
return 0;
}
#ifdef __CELVEC__
celx.newVector(fromEigen(uc2->offsetFromUly(*uc)));
#else
celx.newVector(uc2->offsetFromUly(*uc));
#endif
return 1;
}
@ -201,21 +194,12 @@ static int position_orientationto(lua_State* l)
return 1;
}
#ifdef __CELVEC__
Vec3d src2target = fromEigen(target->offsetFromKm(*src));
src2target.normalize();
Vec3d v = src2target ^ *upd;
v.normalize();
Vec3d u = v ^ src2target;
Quatd qd = Quatd(Mat3d(v, u, -src2target));
#else
Vector3d src2target = target->offsetFromKm(*src).normalized();
Vector3d v = src2target.cross(*upd).normalized();
Vector3d u = v.cross(src2target);
Matrix3d m;
m.row(0) = v; m.row(1) = u; m.row(2) = src2target * (-1);
Quaterniond qd(m);
#endif
celx.newRotation(qd);
return 1;
@ -258,11 +242,7 @@ static int position_add(lua_State* l)
celx.checkArgs(2, 2, "Need two operands for addition");
UniversalCoord* p1 = nullptr;
UniversalCoord* p2 = nullptr;
#ifdef __CELVEC__
Vec3d* v2 = nullptr;
#else
Vector3d* v2 = nullptr;
#endif
if (celx.isType(1, Celx_Position) && celx.isType(2, Celx_Position))
{
@ -276,11 +256,7 @@ static int position_add(lua_State* l)
{
p1 = celx.toPosition(1);
v2 = celx.toVector(2);
#ifdef __CELVEC__
celx.newPosition(p1->offsetUly(toEigen(*v2)));
#else
celx.newPosition(p1->offsetUly(*v2));
#endif
}
else
{
@ -297,11 +273,7 @@ static int position_sub(lua_State* l)
celx.checkArgs(2, 2, "Need two operands for subtraction");
UniversalCoord* p1 = nullptr;
UniversalCoord* p2 = nullptr;
#ifdef __CELVEC__
Vec3d* v2 = nullptr;
#else
Vector3d* v2 = nullptr;
#endif
if (celx.isType(1, Celx_Position) && celx.isType(2, Celx_Position))
{
@ -314,11 +286,7 @@ static int position_sub(lua_State* l)
{
p1 = celx.toPosition(1);
v2 = celx.toVector(2);
#ifdef __CELVEC__
celx.newPosition(p1->offsetUly(toEigen(*v2)));
#else
celx.newPosition(p1->offsetUly(*v2));
#endif
}
else
{
@ -344,11 +312,7 @@ static int position_addvector(lua_State* l)
return 0;
}
#ifdef __CELVEC__
UniversalCoord ucnew = uc->offsetUly(toEigen(*v3d));
#else
UniversalCoord ucnew = uc->offsetUly(*v3d);
#endif
position_new(l, ucnew);
return 1;
}

View File

@ -13,23 +13,13 @@
#include "celx_internal.h"
#include "celx_vector.h"
#ifndef __CELVEC__
using namespace Eigen;
#endif
#ifdef __CELVEC__
int rotation_new(lua_State* l, const Quatd& qd)
#else
int rotation_new(lua_State* l, const Quaterniond& qd)
#endif
{
CelxLua celx(l);
#ifdef __CELVEC__
Quatd* q = reinterpret_cast<Quatd*>(lua_newuserdata(l, sizeof(Quatd)));
#else
auto q = reinterpret_cast<Quaterniond*>(lua_newuserdata(l, sizeof(Quaterniond)));
#endif
*q = qd;
@ -38,26 +28,14 @@ int rotation_new(lua_State* l, const Quaterniond& qd)
return 1;
}
#ifdef __CELVEC__
Quatd* to_rotation(lua_State* l, int index)
#else
Quaterniond* to_rotation(lua_State* l, int index)
#endif
{
CelxLua celx(l);
#ifdef __CELVEC__
return static_cast<Quatd*>(celx.checkUserData(index, Celx_Rotation));
#else
return static_cast<Quaterniond*>(celx.checkUserData(index, Celx_Rotation));
#endif
}
#ifdef __CELVEC__
static Quatd* this_rotation(lua_State* l)
#else
static Quaterniond* this_rotation(lua_State* l)
#endif
{
CelxLua celx(l);
@ -85,14 +63,10 @@ static int rotation_add(lua_State* l)
}
else
{
#ifdef __CELVEC__
auto result = *q1 + *q2;
#else
Quaterniond result(q1->w() + q2->w(),
q1->x() + q2->x(),
q1->y() + q2->y(),
q1->z() + q2->z());
#endif
rotation_new(l, result);
}
return 1;
@ -104,13 +78,8 @@ static int rotation_mult(lua_State* l)
CelxLua celx(l);
celx.checkArgs(2, 2, "Need two operands for multiplication");
#ifdef __CELVEC__
Quatd* r1 = nullptr;
Quatd* r2 = nullptr;
#else
Quaterniond* r1 = nullptr;
Quaterniond* r2 = nullptr;
#endif
lua_Number s = 0.0;
if (celx.isType(1, Celx_Rotation) && celx.isType(2, Celx_Rotation))
{
@ -123,24 +92,16 @@ static int rotation_mult(lua_State* l)
{
r1 = to_rotation(l, 1);
s = lua_tonumber(l, 2);
#ifdef __CELVEC__
rotation_new(l, *r1 * s);
#else
Quaterniond r(r1->w() * s, r1->x() * s, r1->y() * s, r1->x() * s);
rotation_new(l, r);
#endif
}
else
if (lua_isnumber(l, 1) && celx.isType(2, Celx_Rotation))
{
s = lua_tonumber(l, 1);
r1 = to_rotation(l, 2);
#ifdef __CELVEC__
rotation_new(l, *r1 * s);
#else
Quaterniond r(r1->w() * s, r1->x() * s, r1->y() * s, r1->x() * s);
rotation_new(l, r);
#endif
}
else
{
@ -156,11 +117,7 @@ static int rotation_imag(lua_State* l)
celx.checkArgs(1, 1, "No arguments expected for rotation_imag");
auto q = this_rotation(l);
#ifdef __CELVEC__
vector_new(l, imag(*q));
#else
vector_new(l, q->vec());
#endif
return 1;
}
@ -171,11 +128,7 @@ static int rotation_real(lua_State* l)
celx.checkArgs(1, 1, "No arguments expected for rotation_real");
auto q = this_rotation(l);
#ifdef __CELVEC__
lua_pushnumber(l, real(*q));
#else
lua_pushnumber(l, q->w());
#endif
return 1;
}
@ -192,12 +145,8 @@ static int rotation_transform(lua_State* l)
celx.doError("Argument to rotation:transform() must be a vector");
return 0;
}
#ifdef __CELVEC__
vector_new(l, *v * q->toMatrix3());
#else
// XXX or transpose() instead of .adjoint()?
vector_new(l, q->toRotationMatrix().adjoint() * (*v));
#endif
return 1;
}
@ -215,11 +164,7 @@ static int rotation_setaxisangle(lua_State* l)
return 0;
}
double angle = celx.safeGetNumber(3, AllErrors, "second argument to rotation:setaxisangle must be a number");
#ifdef __CELVEC__
q->setAxisAngle(*v, angle);
#else
*q = Quaterniond(AngleAxisd(angle, v->normalized()));
#endif
return 0;
}
@ -237,11 +182,7 @@ static int rotation_slerp(lua_State* l)
return 0;
}
double t = celx.safeGetNumber(3, AllErrors, "second argument to rotation:slerp must be a number");
#ifdef __CELVEC__
rotation_new(l, Quatd::slerp(*q1, *q2, t));
#else
rotation_new(l, q1->slerp(t, *q2));
#endif
return 1;
}
@ -255,29 +196,13 @@ static int rotation_get(lua_State* l)
string key = celx.safeGetString(2, AllErrors, "Invalid key in rotation-access");
double value = 0.0;
if (key == "x")
#ifdef __CELVEC__
value = imag(*q3).x;
#else
value = q3->x();
#endif
else if (key == "y")
#ifdef __CELVEC__
value = imag(*q3).y;
#else
value = q3->y();
#endif
else if (key == "z")
#ifdef __CELVEC__
value = imag(*q3).z;
#else
value = q3->z();
#endif
else if (key == "w")
#ifdef __CELVEC__
value = real(*q3);
#else
value = q3->w();
#endif
else
{
if (!lua_getmetatable(l, 1))
@ -303,42 +228,21 @@ static int rotation_set(lua_State* l)
auto q3 = this_rotation(l);
string key = celx.safeGetString(2, AllErrors, "Invalid key in rotation-access");
double value = celx.safeGetNumber(3, AllErrors, "Rotation components must be numbers");
#ifdef __CELVEC__
Vec3d v = imag(*q3);
double w = real(*q3);
#else
Vector3d v = q3->vec();
double w = q3->w();
#endif
if (key == "x")
#ifdef __CELVEC__
v.x = value;
#else
v.x() = value;
#endif
else if (key == "y")
#ifdef __CELVEC__
v.y = value;
#else
v.y() = value;
#endif
else if (key == "z")
#ifdef __CELVEC__
v.z = value;
#else
v.z() = value;
#endif
else if (key == "w")
w = value;
else
{
celx.doError("Invalid key in rotation-access");
}
#ifdef __CELVEC__
*q3 = Quatd(w, v);
#else
*q3 = Quaterniond(w, v.x(), v.y(), v.z());
#endif
return 0;
}

View File

@ -12,21 +12,12 @@
#ifndef _CELX_ROTATION_H_
#define _CELX_ROTATION_H_
#ifdef __CELVEC__
#include <celmath/quaternion.h>
#else
#include <Eigen/Geometry>
#endif
struct lua_State;
extern void CreateRotationMetaTable(lua_State* l);
#ifdef __CELVEC__
extern int rotation_new(lua_State* l, const Quatd& qd);
extern Quatd* to_rotation(lua_State* l, int index);
#else
extern int rotation_new(lua_State* l, const Eigen::Quaterniond& qd);
extern Eigen::Quaterniond* to_rotation(lua_State* l, int index);
#endif
#endif // _CELX_ROTATION_H_

View File

@ -12,52 +12,28 @@
#include "celx.h"
#include "celx_internal.h"
#include "celx_vector.h"
#ifdef __CELVEC__
#include <celengine/eigenport.h>
#else
#include <Eigen/Geometry>
using namespace Eigen;
#endif
#ifdef __CELVEC__
int vector_new(lua_State* l, const Vec3d& v)
#else
int vector_new(lua_State* l, const Vector3d& v)
#endif
{
CelxLua celx(l);
#ifdef __CELVEC__
Vec3d* v3 = reinterpret_cast<Vec3d*>(lua_newuserdata(l, sizeof(Vec3d)));
#else
auto v3 = reinterpret_cast<Vector3d*>(lua_newuserdata(l, sizeof(Vector3d)));
#endif
*v3 = v;
celx.setClass(Celx_Vec3);
return 1;
}
#ifdef __CELVEC__
Vec3d* to_vector(lua_State* l, int index)
#else
Vector3d* to_vector(lua_State* l, int index)
#endif
{
CelxLua celx(l);
#ifdef __CELVEC__
return static_cast<Vec3d*>(celx.checkUserData(index, Celx_Vec3));
#else
return static_cast<Vector3d*>(celx.checkUserData(index, Celx_Vec3));
#endif
}
#ifdef __CELVEC__
static Vec3d* this_vector(lua_State* l)
#else
static Vector3d* this_vector(lua_State* l)
#endif
{
CelxLua celx(l);
@ -99,23 +75,11 @@ static int vector_get(lua_State* l)
string key = celx.safeGetString(2, AllErrors, "Invalid key in vector-access");
double value = 0.0;
if (key == "x")
#ifdef __CELVEC__
value = v3->x;
#else
value = v3->x();
#endif
else if (key == "y")
#ifdef __CELVEC__
value = v3->y;
#else
value = v3->y();
#endif
else if (key == "z")
#ifdef __CELVEC__
value = v3->z;
#else
value = v3->z();
#endif
else
{
if (!lua_getmetatable(l, 1))
@ -141,23 +105,11 @@ static int vector_set(lua_State* l)
string key = celx.safeGetString(2, AllErrors, "Invalid key in vector-access");
double value = celx.safeGetNumber(3, AllErrors, "Vector components must be numbers");
if (key == "x")
#ifdef __CELVEC__
v3->x = value;
#else
v3->x() = value;
#endif
else if (key == "y")
#ifdef __CELVEC__
v3->y = value;
#else
v3->y() = value;
#endif
else if (key == "z")
#ifdef __CELVEC__
v3->z = value;
#else
v3->z() = value;
#endif
else
{
celx.doError("Invalid key in vector-access");
@ -172,11 +124,7 @@ static int vector_getx(lua_State* l)
celx.checkArgs(1, 1, "No arguments expected for vector:getx");
auto v3 = this_vector(l);
lua_Number x;
#ifdef __CELVEC__
x = static_cast<lua_Number>(v3->x);
#else
x = static_cast<lua_Number>(v3->x());
#endif
lua_pushnumber(l, x);
return 1;
@ -189,11 +137,7 @@ static int vector_gety(lua_State* l)
celx.checkArgs(1, 1, "No arguments expected for vector:gety");
auto v3 = this_vector(l);
lua_Number y;
#ifdef __CELVEC__
y = static_cast<lua_Number>(v3->y);
#else
y = static_cast<lua_Number>(v3->y());
#endif
lua_pushnumber(l, y);
return 1;
@ -206,11 +150,7 @@ static int vector_getz(lua_State* l)
celx.checkArgs(1, 1, "No arguments expected for vector:getz");
auto v3 = this_vector(l);
lua_Number z;
#ifdef __CELVEC__
z = static_cast<lua_Number>(v3->z);
#else
z = static_cast<lua_Number>(v3->z());
#endif
lua_pushnumber(l, z);
return 1;
@ -222,13 +162,7 @@ static int vector_normalize(lua_State* l)
celx.checkArgs(1, 1, "No arguments expected for vector:normalize");
auto v = this_vector(l);
#ifdef __CELVEC__
Vec3d vn(*v);
vn.normalize();
celx.newVector(vn);
#else
celx.newVector(v->normalized());
#endif
return 1;
}
@ -238,11 +172,7 @@ static int vector_length(lua_State* l)
celx.checkArgs(1, 1, "No arguments expected for vector:length");
auto v = this_vector(l);
#ifdef __CELVEC__
double length = v->length();
#else
double length = v->norm();
#endif
lua_pushnumber(l, (lua_Number)length);
return 1;
}
@ -252,13 +182,8 @@ static int vector_add(lua_State* l)
CelxLua celx(l);
celx.checkArgs(2, 2, "Need two operands for addition");
#ifdef __CELVEC__
Vec3d* v1 = nullptr;
Vec3d* v2 = nullptr;
#else
Vector3d* v1 = nullptr;
Vector3d* v2 = nullptr;
#endif
UniversalCoord* p = nullptr;
if (celx.isType(1, Celx_Vec3) && celx.isType(2, Celx_Vec3))
@ -272,11 +197,7 @@ static int vector_add(lua_State* l)
{
v1 = celx.toVector(1);
p = celx.toPosition(2);
#ifdef __CELVEC__
celx.newPosition(p->offsetUly(toEigen(*v1)));
#else
celx.newPosition(p->offsetUly(*v1));
#endif
}
else
{
@ -290,25 +211,15 @@ static int vector_mult(lua_State* l)
CelxLua celx(l);
celx.checkArgs(2, 2, "Need two operands for multiplication");
#ifdef __CELVEC__
Vec3d* v1 = nullptr;
Vec3d* v2 = nullptr;
Quatd* q = nullptr;
#else
Vector3d* v1 = nullptr;
Vector3d* v2 = nullptr;
Quaterniond* q = nullptr;
#endif
lua_Number s = 0.0;
if (celx.isType(1, Celx_Vec3) && celx.isType(2, Celx_Vec3))
{
v1 = celx.toVector(1);
v2 = celx.toVector(2);
#ifdef __CELVEC__
lua_pushnumber(l, *v1 * *v2);
#else
lua_pushnumber(l, (lua_Number)v1->dot(*v2));
#endif
}
else
if (celx.isType(1, Celx_Vec3) && lua_isnumber(l, 2))
@ -322,11 +233,7 @@ static int vector_mult(lua_State* l)
{
v1 = celx.toVector(1);
q = celx.toRotation(2);
#ifdef __CELVEC__
celx.newRotation(*v1 * *q);
#else
celx.newRotation(Quaterniond(0, v1->x(), v1->y(), v1->z()) * *q);
#endif
}
else
if (lua_isnumber(l, 1) && celx.isType(2, Celx_Vec3))
@ -347,22 +254,13 @@ static int vector_cross(lua_State* l)
CelxLua celx(l);
celx.checkArgs(2, 2, "Need two operands for multiplication");
#ifdef __CELVEC__
Vec3d* v1 = nullptr;
Vec3d* v2 = nullptr;
#else
Vector3d* v1 = nullptr;
Vector3d* v2 = nullptr;
#endif
if (celx.isType(1, Celx_Vec3) && celx.isType(2, Celx_Vec3))
{
v1 = celx.toVector(1);
v2 = celx.toVector(2);
#ifdef __CELVEC__
celx.newVector(*v1 ^ *v2);
#else
celx.newVector(v1->cross(*v2));
#endif
}
else
{

View File

@ -12,19 +12,12 @@
#ifndef _CELX_VECTOR_H_
#define _CELX_VECTOR_H_
#ifndef __CELVEC__
#include <Eigen/Geometry>
#endif
struct lua_State;
extern void CreateVectorMetaTable(lua_State* l);
#ifdef __CELVEC__
extern int vector_new(lua_State* l, const Vec3d& v);
extern Vec3d* to_vector(lua_State* l, int index);
#else
extern int vector_new(lua_State* l, const Eigen::Vector3d& v);
extern Eigen::Vector3d* to_vector(lua_State* l, int index);
#endif
#endif // _CELX_VECTOR_H_

View File

@ -72,10 +72,6 @@ FavoritesList* ReadFavoritesList(istream& in)
favParams->getVector("base", base);
favParams->getVector("offset", offset);
fav->position = UniversalCoord::CreateLy(base) + UniversalCoord::CreateLy(offset * 1.0e-6);
#ifdef CELVEC
base *= 1e6;
fav->position = UniversalCoord(Point3d(base.x, base.y, base.z)) + offset;
#endif
// Get orientation
Vector3d axis = Vector3d::UnitX();
@ -83,10 +79,6 @@ FavoritesList* ReadFavoritesList(istream& in)
favParams->getVector("axis", axis);
favParams->getNumber("angle", angle);
fav->orientation = Quaternionf(AngleAxisf((float) angle, axis.cast<float>()));
#ifdef CELVEC
fav->orientation.setAxisAngle(Vec3f((float) axis.x, (float) axis.y, (float) axis.z),
(float) angle);
#endif
// Get time
fav->jd = 0.0;
@ -131,14 +123,6 @@ void WriteFavoritesList(FavoritesList& favorites, ostream& out)
(double) (fav->position.z - (BigFix) baseUly.z()));
Vector3d base = baseUly * 1e-6; // Base is in micro-light years
// This was the old way of doing things, before the confusing operators
// and implicit casts were removed from UniversalCoord.
#ifdef CELVEC
Point3d base = (Point3d) fav->position;
Vec3d offset = fav->position - base;
base.x *= 1e-6; base.y *= 1e-6; base.z *= 1e-6;
#endif
out << '"' << fav->name << "\" {\n";
if(fav->isFolder)
out << "\tisFolder " << "true\n";

View File

@ -110,12 +110,6 @@ struct BrighterStarPredicate
d0 = ucPos.offsetFromLy(star0->getPosition()).norm();
if (d1 < 1.0f)
d1 = ucPos.offsetFromLy(star1->getPosition()).norm();
#if CELVEC
if (d0 < 1.0f)
d0 = (toMicroLY(star0->getPosition()) - toEigen((Point3f) ucPos)).norm() * 1e-6f;
if (d1 < 1.0f)
d1 = (toMicroLY(star1->getPosition()) - toEigen((Point3f) ucPos)).norm() * 1e-6f;
#endif
return (star0->getApparentMagnitude(d0) <
star1->getApparentMagnitude(d1));
@ -309,12 +303,6 @@ int CALLBACK StarBrowserCompareFunc(LPARAM lParam0, LPARAM lParam1,
d0 = sortInfo->ucPos.offsetFromLy(star0->getPosition()).norm();
if (d1 < 1.0f)
d1 = sortInfo->ucPos.offsetFromLy(star1->getPosition()).norm();
#if CELVEC
if (d0 < 1.0f)
d0 = (toMicroLY(star0->getPosition()) - toEigen((Point3f) sortInfo->ucPos)).norm() * 1e-6f;
if (d1 < 1.0f)
d1 = (toMicroLY(star1->getPosition()) - toEigen((Point3f) sortInfo->ucPos)).norm() * 1e-6f;
#endif
return (int) sign(astro::absToAppMag(star0->getAbsoluteMagnitude(), d0) -
astro::absToAppMag(star1->getAbsoluteMagnitude(), d1));
}

View File

@ -19,28 +19,6 @@
#include <Eigen/Core>
#ifdef __CELVEC__
template<class T> T distance(const Point3<T>& p, const Sphere<T>& s)
{
return abs(s.center.distanceTo(p) - s.radius);
}
template<class T> T distance(const Point3<T>& p, const Ellipsoid<T>& e)
{
return 0.0f;
}
template<class T> T distance(const Point3<T>& p, const Ray3<T>& r)
{
Eigen::Matrix<T, 3, 1> p2(p.x, p.y, p.z);
T t = ((p2 - r.origin).dot(r.direction)) / r.direction.squaredNorm();
if (t <= 0)
return (p2 - r.origin).norm();
else
return (p2 - r.point(t)).norm();
}
#endif
template<class T> T distance(const Eigen::Matrix<T, 3, 1>& p, const Ray3<T>& r)
{
T t = ((p - r.origin).dot(r.direction)) / r.direction.squaredNorm();
@ -50,21 +28,4 @@ template<class T> T distance(const Eigen::Matrix<T, 3, 1>& p, const Ray3<T>& r)
return (p - r.point(t)).norm();
}
#ifdef __CELVEC__
// Distance between a point and a segment defined by orig+dir*t, 0 <= t <= 1
template<class T> T distanceToSegment(const Point3<T>& p,
const Point3<T>& origin,
const Vector3<T>& direction)
{
T t = ((p - origin) * direction) / (direction * direction);
if (t <= 0)
return p.distanceTo(origin);
else if (t >= 1)
return p.distanceTo(origin + direction);
else
return p.distanceTo(origin + direction * t);
}
#endif
#endif // _CELMATH_DISTANCE_H_

View File

@ -10,9 +10,6 @@
#ifndef _CELMATH_ELLIPSOID_H_
#define _CELMATH_ELLIPSOID_H_
#ifdef __CELVEC__
#include "vecmath.h"
#endif
#include <Eigen/Core>
template<class T> class Ellipsoid
@ -57,37 +54,6 @@ template<class T> class Ellipsoid
}
#ifdef __CELVEC__
/**** Compatibility with old Celestia vectors ****/
/*! Created an ellipsoid with the specified semiaxes, centered
* at the origin.
*/
Ellipsoid(const Vector3<T>& _axes) :
center(0, 0, 0),
axes(_axes.x, _axes.y, _axes.z)
{
}
/*! Create an ellipsoid with the specified center and semiaxes.
*/
Ellipsoid(const Point3<T>& _center,
const Vector3<T>& _axes) :
center(_center.x, _center.y, _center.z),
axes(_axes.x, _axes.y, _axes.z)
{
}
/*! Test whether the point p lies inside the ellipsoid.
*/
bool contains(const Point3<T>& p) const
{
Vector3<T> v = p - center;
v = Vector3<T>(v.x / axes.x, v.y / axes.y, v.z / axes.z);
return v * v <= (T) 1.0;
}
#endif
public:
Eigen::Matrix<T, 3, 1> center;
Eigen::Matrix<T, 3, 1> axes;
@ -96,7 +62,4 @@ template<class T> class Ellipsoid
typedef Ellipsoid<float> Ellipsoidf;
typedef Ellipsoid<double> Ellipsoidd;
#endif // _CELMATH_ELLIPSOID_H_

View File

@ -106,25 +106,6 @@ Frustum::testSphere(const Eigen::Vector3d& center, double radius) const
}
#ifdef __CELVEC__
Frustum::Aspect Frustum::test(const Point3f& p) const
{
return testSphere(Eigen::Vector3f(p.x, p.y, p.z), 0.0f);
}
Frustum::Aspect Frustum::testSphere(const Point3f& center, float radius) const
{
return testSphere(Eigen::Vector3f(center.x, center.y, center.z), radius);
}
Frustum::Aspect Frustum::testSphere(const Point3d& center, double radius) const
{
return testSphere(Eigen::Vector3d(center.x, center.y, center.z), radius);
}
#endif
/*
Frustum::Aspect Frustum::testCapsule(const Capsulef& capsule) const
{
@ -204,21 +185,3 @@ Frustum::transform(const Matrix4f& m)
//planes[i].d *= s;
}
}
#ifdef __CELVEC__
void
Frustum::transform(const Mat3f& m)
{
Matrix3f m2 = Map<Matrix3f>(&m[0][0]);
transform(m2);
}
void
Frustum::transform(const Mat4f& m)
{
Matrix4f m2 = Map<Matrix4f>(&m[0][0]);
transform(m2);
}
#endif

View File

@ -13,11 +13,6 @@
#include <Eigen/Core>
#include <Eigen/Geometry>
// Compatibility
#ifdef __CELVEC__
#include <celmath/plane.h>
#endif
//#include <celmath/capsule.h>
@ -59,20 +54,6 @@ class Frustum
Aspect testSphere(const Eigen::Vector3d& center, double radius) const;
// Aspect testCapsule(const Capsulef&) const;
#ifdef __CELVEC__
// Compatibility
inline Planef getPlane(unsigned int which) const
{
PlaneType p = plane(which);
return Planef(Vec3f(p.coeffs().x(), p.coeffs().y(), p.coeffs().z()), p.coeffs().w());
}
void transform(const Mat3f&);
void transform(const Mat4f&);
Aspect test(const Point3f&) const;
Aspect testSphere(const Point3f& center, float radius) const;
Aspect testSphere(const Point3d& center, double radius) const;
#endif
private:
void init(float, float, float, float);

View File

@ -10,9 +10,6 @@
#ifndef _CELMATH_RAY_H_
#define _CELMATH_RAY_H_
#ifdef __CELVEC__
#include "vecmath.h"
#endif
#include <Eigen/Core>
template<class T> class Ray3
@ -22,10 +19,6 @@ template<class T> class Ray3
Ray3();
Ray3(const Eigen::Matrix<T, 3, 1>& origin, const Eigen::Matrix<T, 3, 1>& direction);
#ifdef __CELVEC__
// Compatibility
Ray3(const Point3<T>&, const Vector3<T>&);
#endif
Eigen::Matrix<T, 3, 1> point(T) const;
@ -54,36 +47,9 @@ template<class T> Ray3<T>::Ray3(const Eigen::Matrix<T, 3, 1>& _origin,
{
}
#ifdef __CELVEC__
// Compatibility
template<class T> Ray3<T>::Ray3(const Point3<T>& _origin,
const Vector3<T>& _direction) :
origin(_origin.x, _origin.y, _origin.z),
direction(_direction.x, _direction.y, _direction.z)
{
}
#endif
template<class T> Eigen::Matrix<T, 3, 1> Ray3<T>::point(T t) const
{
return origin + direction * t;
}
#ifdef __CELVEC__
// Compatibility
template<class T> Ray3<T> operator*(const Ray3<T>& r, const Matrix3<T>& m)
{
Eigen::Map<Eigen::Matrix<T, 3, 3> > m2(&m[0][0]);
return Ray3<T>(m2 * r.origin, m2 * r.direction);
}
// Compatibility
template<class T> Ray3<T> operator*(const Ray3<T>& r, const Matrix4<T>& m)
{
Eigen::Map<Eigen::Matrix<T, 4, 4> > m2(&m[0][0]);
return Ray3<T>(m2 * r.origin, m2 * r.direction);
}
#endif
#endif // _CELMATH_RAY_H_

View File

@ -10,9 +10,6 @@
#ifndef _CELMATH_SPHERE_H_
#define _CELMATH_SPHERE_H_
#ifdef __CELVEC__
#include "vecmath.h"
#endif
#include <Eigen/Core>
template<class T> class Sphere
@ -38,15 +35,6 @@ template<class T> class Sphere
{
}
#ifdef __CELVEC__
// Compatibility
Sphere(const Point3<T>& _center, T _radius) :
center(_center.x, _center.y, _center.z),
radius(_radius)
{
}
#endif
public:
Eigen::Matrix<T, 3, 1> center;
T radius;