#include "SGMath.hxx"
-osg::Matrix SGGeod::makeSimulationFrameRelative()
+#ifndef NO_OPENSCENEGRAPH_INTERFACE
+
+osg::Matrix SGGeod::makeSimulationFrameRelative() const
{
SGQuatd hlOr = SGQuatd::fromLonLat(*this);
return osg::Matrix(hlOr.osg());
}
-osg::Matrix SGGeod::makeSimulationFrame()
+osg::Matrix SGGeod::makeSimulationFrame() const
{
osg::Matrix result(makeSimulationFrameRelative());
SGVec3d coord;
return result;
}
-osg::Matrix SGGeod::makeZUpFrameRelative()
+osg::Matrix SGGeod::makeZUpFrameRelative() const
{
osg::Matrix result(makeSimulationFrameRelative());
// 180 degree rotation around Y axis
return result;
}
-osg::Matrix SGGeod::makeZUpFrame()
+osg::Matrix SGGeod::makeZUpFrame() const
{
osg::Matrix result(makeZUpFrameRelative());
SGVec3d coord;
result.setTrans(coord.osg());
return result;
}
+
+#endif
#include <simgear/constants.h>
+#ifndef NO_OPENSCENEGRAPH_INTERFACE
#include <osg/Matrix>
+#endif
// #define SG_GEOD_NATIVE_DEGREE
/// Set the geodetic elevation from the argument given in feet
void setElevationFt(double elevation);
+#ifndef NO_OPENSCENEGRAPH_INTERFACE
// Create a local coordinate frame in the earth-centered frame of
// reference. X points north, Z points down.
// makeSimulationFrameRelative() only includes rotation.
-
- osg::Matrix makeSimulationFrameRelative();
- osg::Matrix makeSimulationFrame();
+ osg::Matrix makeSimulationFrameRelative() const;
+ osg::Matrix makeSimulationFrame() const;
// Create a Z-up local coordinate frame in the earth-centered frame
// of reference. This is what scenery models, etc. expect.
// makeZUpFrameRelative() only includes rotation.
- osg::Matrix makeZUpFrameRelative();
- osg::Matrix makeZUpFrame();
+ osg::Matrix makeZUpFrameRelative() const;
+ osg::Matrix makeZUpFrame() const;
+#endif
private:
/// This one is private since construction is not unique if you do
/// not know the units of the arguments. Use the factory methods for
/// that purpose
SGGeod(double lon, double lat, double elevation);
- /// The actual data, angles in degree, elevation in meters
+ //// FIXME: wrong comment!
+ /// The actual data, angles in degrees, elevation in meters
/// The rationale for storing the values in degrees is that most code places
/// in flightgear/terragear use degrees as a nativ input and output value.
/// The places where it makes sense to use radians is when we convert
-// Copyright (C) 2006 Mathias Froehlich - Mathias.Froehlich@web.de
+// Copyright (C) 2006-2009 Mathias Froehlich - Mathias.Froehlich@web.de
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
#undef max
#endif
+#ifndef NO_OPENSCENEGRAPH_INTERFACE
#include <osg/Quat>
+#endif
+/// Quaternion Class
template<typename T>
-struct SGQuatStorage {
- /// Readonly raw storage interface
- const T (&data(void) const)[4]
- { return _data; }
- /// Readonly raw storage interface
- T (&data(void))[4]
- { return _data; }
-
- void osg() const
- { }
-
-private:
- T _data[4];
-};
-
-template<>
-struct SGQuatStorage<double> : public osg::Quat {
- /// Access raw data by index, the index is unchecked
- const double (&data(void) const)[4]
- { return osg::Quat::_v; }
- /// Access raw data by index, the index is unchecked
- double (&data(void))[4]
- { return osg::Quat::_v; }
-
- const osg::Quat& osg() const
- { return *this; }
- osg::Quat& osg()
- { return *this; }
-};
-
-/// 3D Vector Class
-template<typename T>
-class SGQuat : protected SGQuatStorage<T> {
+class SGQuat {
public:
typedef T value_type;
/// make sure it has at least 4 elements
explicit SGQuat(const T* d)
{ data()[0] = d[0]; data()[1] = d[1]; data()[2] = d[2]; data()[3] = d[3]; }
+#ifndef NO_OPENSCENEGRAPH_INTERFACE
explicit SGQuat(const osg::Quat& d)
{ data()[0] = d[0]; data()[1] = d[1]; data()[2] = d[2]; data()[3] = d[3]; }
+#endif
/// Return a unit quaternion
static SGQuat unit(void)
static SGQuat fromLonLat(const SGGeod& geod)
{ return fromLonLatRad(geod.getLongitudeRad(), geod.getLatitudeRad()); }
+
/// Return a quaternion rotation from the earth centered to the
/// OpenGL/viewer horizontal local frame from given longitude and latitude.
/// This frame matches the usual OpenGL axis directions. That is the target
{ return data()[3]; }
/// Get the data pointer
- using SGQuatStorage<T>::data;
-
- /// Readonly interface function to ssg's sgQuat/sgdQuat
- const T (&sg(void) const)[4]
- { return data(); }
- /// Interface function to ssg's sgQuat/sgdQuat
- T (&sg(void))[4]
- { return data(); }
+ const T (&data(void) const)[4]
+ { return _data; }
+ /// Get the data pointer
+ T (&data(void))[4]
+ { return _data; }
- /// Interface function to osg's Quat*
- using SGQuatStorage<T>::osg;
+#ifndef NO_OPENSCENEGRAPH_INTERFACE
+ osg::Quat osg() const
+ { return osg::Quat(data()[0], data()[1], data()[2], data()[3]); }
+#endif
/// Inplace addition
SGQuat& operator+=(const SGQuat& v)
SGQuat q2 = SGQuat::fromRotateToSmaller90Deg(-cosang, -from, to);
return q1*q2;
}
+
+ T _data[4];
};
/// Unary +, do nothing ...
toQuatd(const SGQuatf& v)
{ return SGQuatd(v(0), v(1), v(2), v(3)); }
+#ifndef NO_OPENSCENEGRAPH_INTERFACE
+inline
+SGQuatd
+toSG(const osg::Quat& q)
+{ return SGQuatd(q[0], q[1], q[2], q[3]); }
+
+inline
+osg::Quat
+toOsg(const SGQuatd& q)
+{ return osg::Quat(q[0], q[1], q[2], q[3]); }
+#endif
+
#endif
-// Copyright (C) 2006 Mathias Froehlich - Mathias.Froehlich@web.de
+// Copyright (C) 2006-2009 Mathias Froehlich - Mathias.Froehlich@web.de
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
#include <ieeefp.h>
#endif
+#ifndef NO_OPENSCENEGRAPH_INTERFACE
#include <osg/Vec2f>
#include <osg/Vec2d>
-
-template<typename T>
-struct SGVec2Storage {
- /// Readonly raw storage interface
- const T (&data(void) const)[2]
- { return _data; }
- /// Readonly raw storage interface
- T (&data(void))[2]
- { return _data; }
-
- void osg() const
- { }
-
-private:
- T _data[2];
-};
-
-template<>
-struct SGVec2Storage<float> : public osg::Vec2f {
- /// Access raw data by index, the index is unchecked
- const float (&data(void) const)[2]
- { return osg::Vec2f::_v; }
- /// Access raw data by index, the index is unchecked
- float (&data(void))[2]
- { return osg::Vec2f::_v; }
-
- const osg::Vec2f& osg() const
- { return *this; }
- osg::Vec2f& osg()
- { return *this; }
-};
-
-template<>
-struct SGVec2Storage<double> : public osg::Vec2d {
- /// Access raw data by index, the index is unchecked
- const double (&data(void) const)[2]
- { return osg::Vec2d::_v; }
- /// Access raw data by index, the index is unchecked
- double (&data(void))[2]
- { return osg::Vec2d::_v; }
-
- const osg::Vec2d& osg() const
- { return *this; }
- osg::Vec2d& osg()
- { return *this; }
-};
+#endif
/// 2D Vector Class
template<typename T>
-class SGVec2 : protected SGVec2Storage<T> {
+class SGVec2 {
public:
typedef T value_type;
template<typename S>
explicit SGVec2(const SGVec2<S>& d)
{ data()[0] = d[0]; data()[1] = d[1]; }
+#ifndef NO_OPENSCENEGRAPH_INTERFACE
explicit SGVec2(const osg::Vec2f& d)
{ data()[0] = d[0]; data()[1] = d[1]; }
explicit SGVec2(const osg::Vec2d& d)
{ data()[0] = d[0]; data()[1] = d[1]; }
+#endif
/// Access by index, the index is unchecked
const T& operator()(unsigned i) const
T& y(void)
{ return data()[1]; }
- /// Get the data pointer
- using SGVec2Storage<T>::data;
-
- /// Readonly interface function to ssg's sgVec2/sgdVec2
- const T (&sg(void) const)[2]
- { return data(); }
- /// Interface function to ssg's sgVec2/sgdVec2
- T (&sg(void))[2]
- { return data(); }
+ /// Access raw data
+ const T (&data(void) const)[2]
+ { return _data; }
+ /// Access raw data
+ T (&data(void))[2]
+ { return _data; }
- /// Interface function to osg's Vec2*
- using SGVec2Storage<T>::osg;
+#ifndef NO_OPENSCENEGRAPH_INTERFACE
+ osg::Vec2d osg() const
+ { return osg::Vec2d(data()[0], data()[1]); }
+#endif
/// Inplace addition
SGVec2& operator+=(const SGVec2& v)
{ return SGVec2(1, 0); }
static SGVec2 e2(void)
{ return SGVec2(0, 1); }
+
+private:
+ T _data[2];
};
/// Unary +, do nothing ...
toVec2d(const SGVec2f& v)
{ return SGVec2d(v(0), v(1)); }
+#ifndef NO_OPENSCENEGRAPH_INTERFACE
+inline
+SGVec2d
+toSG(const osg::Vec2d& v)
+{ return SGVec2d(v[0], v[1]); }
+
+inline
+SGVec2f
+toSG(const osg::Vec2f& v)
+{ return SGVec2f(v[0], v[1]); }
+
+inline
+osg::Vec2d
+toOsg(const SGVec2d& v)
+{ return osg::Vec2d(v[0], v[1]); }
+
+inline
+osg::Vec2f
+toOsg(const SGVec2f& v)
+{ return osg::Vec2f(v[0], v[1]); }
+
+#endif
+
#endif
-// Copyright (C) 2006 Mathias Froehlich - Mathias.Froehlich@web.de
+// Copyright (C) 2006-2009 Mathias Froehlich - Mathias.Froehlich@web.de
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
#ifndef SGVec3_H
#define SGVec3_H
+#ifndef NO_OPENSCENEGRAPH_INTERFACE
#include <osg/Vec3f>
#include <osg/Vec3d>
-
-template<typename T>
-struct SGVec3Storage {
- /// Readonly raw storage interface
- const T (&data(void) const)[3]
- { return _data; }
- /// Readonly raw storage interface
- T (&data(void))[3]
- { return _data; }
-
- void osg() const
- { }
-
-private:
- T _data[3];
-};
-
-template<>
-struct SGVec3Storage<float> : public osg::Vec3f {
- /// Access raw data by index, the index is unchecked
- const float (&data(void) const)[3]
- { return osg::Vec3f::_v; }
- /// Access raw data by index, the index is unchecked
- float (&data(void))[3]
- { return osg::Vec3f::_v; }
-
- const osg::Vec3f& osg() const
- { return *this; }
- osg::Vec3f& osg()
- { return *this; }
-};
-
-template<>
-struct SGVec3Storage<double> : public osg::Vec3d {
- /// Access raw data by index, the index is unchecked
- const double (&data(void) const)[3]
- { return osg::Vec3d::_v; }
- /// Access raw data by index, the index is unchecked
- double (&data(void))[3]
- { return osg::Vec3d::_v; }
-
- const osg::Vec3d& osg() const
- { return *this; }
- osg::Vec3d& osg()
- { return *this; }
-};
+#endif
/// 3D Vector Class
template<typename T>
-class SGVec3 : protected SGVec3Storage<T> {
+class SGVec3 {
public:
typedef T value_type;
template<typename S>
explicit SGVec3(const SGVec3<S>& d)
{ data()[0] = d[0]; data()[1] = d[1]; data()[2] = d[2]; }
+ explicit SGVec3(const SGVec2<T>& v2, const T& v3 = 0)
+ { data()[0] = v2[0]; data()[1] = v2[1]; data()[2] = v3; }
+#ifndef NO_OPENSCENEGRAPH_INTERFACE
explicit SGVec3(const osg::Vec3f& d)
{ data()[0] = d[0]; data()[1] = d[1]; data()[2] = d[2]; }
explicit SGVec3(const osg::Vec3d& d)
{ data()[0] = d[0]; data()[1] = d[1]; data()[2] = d[2]; }
- explicit SGVec3(const SGVec2<T>& v2, const T& v3 = 0)
- { data()[0] = v2[0]; data()[1] = v2[1]; data()[2] = v3; }
+#endif
/// Access by index, the index is unchecked
const T& operator()(unsigned i) const
T& z(void)
{ return data()[2]; }
- /// Get the data pointer
- using SGVec3Storage<T>::data;
-
- /// Readonly interface function to ssg's sgVec3/sgdVec3
- const T (&sg(void) const)[3]
- { return data(); }
- /// Interface function to ssg's sgVec3/sgdVec3
- T (&sg(void))[3]
- { return data(); }
+ /// Readonly raw storage interface
+ const T (&data(void) const)[3]
+ { return _data; }
+ /// Readonly raw storage interface
+ T (&data(void))[3]
+ { return _data; }
- /// Interface function to osg's Vec3*
- using SGVec3Storage<T>::osg;
+#ifndef NO_OPENSCENEGRAPH_INTERFACE
+ osg::Vec3d osg() const
+ { return osg::Vec3d(data()[0], data()[1], data()[2]); }
+#endif
/// Inplace addition
SGVec3& operator+=(const SGVec3& v)
/// Constructor. Initialize by a geocentric coordinate
/// Note that this conversion is relatively expensive to compute
static SGVec3 fromGeoc(const SGGeoc& geoc);
+
+private:
+ T _data[3];
};
template<>
toVec3d(const SGVec3f& v)
{ return SGVec3d(v(0), v(1), v(2)); }
+#ifndef NO_OPENSCENEGRAPH_INTERFACE
+inline
+SGVec3d
+toSG(const osg::Vec3d& v)
+{ return SGVec3d(v[0], v[1], v[2]); }
+
+inline
+SGVec3f
+toSG(const osg::Vec3f& v)
+{ return SGVec3f(v[0], v[1], v[2]); }
+
+inline
+osg::Vec3d
+toOsg(const SGVec3d& v)
+{ return osg::Vec3d(v[0], v[1], v[2]); }
+
+inline
+osg::Vec3f
+toOsg(const SGVec3f& v)
+{ return osg::Vec3f(v[0], v[1], v[2]); }
+#endif
+
#endif
-// Copyright (C) 2006 Mathias Froehlich - Mathias.Froehlich@web.de
+// Copyright (C) 2006-2009 Mathias Froehlich - Mathias.Froehlich@web.de
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
#ifndef SGVec4_H
#define SGVec4_H
+#ifndef NO_OPENSCENEGRAPH_INTERFACE
#include <osg/Vec4f>
#include <osg/Vec4d>
-
-template<typename T>
-struct SGVec4Storage {
- /// Readonly raw storage interface
- const T (&data(void) const)[4]
- { return _data; }
- /// Readonly raw storage interface
- T (&data(void))[4]
- { return _data; }
-
- void osg() const
- { }
-
-private:
- T _data[4];
-};
-
-template<>
-struct SGVec4Storage<float> : public osg::Vec4f {
- /// Access raw data by index, the index is unchecked
- const float (&data(void) const)[4]
- { return osg::Vec4f::_v; }
- /// Access raw data by index, the index is unchecked
- float (&data(void))[4]
- { return osg::Vec4f::_v; }
-
- const osg::Vec4f& osg() const
- { return *this; }
- osg::Vec4f& osg()
- { return *this; }
-};
-
-template<>
-struct SGVec4Storage<double> : public osg::Vec4d {
- /// Access raw data by index, the index is unchecked
- const double (&data(void) const)[4]
- { return osg::Vec4d::_v; }
- /// Access raw data by index, the index is unchecked
- double (&data(void))[4]
- { return osg::Vec4d::_v; }
-
- const osg::Vec4d& osg() const
- { return *this; }
- osg::Vec4d& osg()
- { return *this; }
-};
+#endif
/// 4D Vector Class
template<typename T>
-class SGVec4 : protected SGVec4Storage<T> {
+class SGVec4 {
public:
typedef T value_type;
template<typename S>
explicit SGVec4(const SGVec4<S>& d)
{ data()[0] = d[0]; data()[1] = d[1]; data()[2] = d[2]; data()[3] = d[3]; }
+ explicit SGVec4(const SGVec3<T>& v3, const T& v4 = 0)
+ { data()[0] = v3[0]; data()[1] = v3[1]; data()[2] = v3[2]; data()[3] = v4; }
+#ifndef NO_OPENSCENEGRAPH_INTERFACE
explicit SGVec4(const osg::Vec4f& d)
{ data()[0] = d[0]; data()[1] = d[1]; data()[2] = d[2]; data()[3] = d[3]; }
explicit SGVec4(const osg::Vec4d& d)
{ data()[0] = d[0]; data()[1] = d[1]; data()[2] = d[2]; data()[3] = d[3]; }
- explicit SGVec4(const SGVec3<T>& v3, const T& v4 = 0)
- { data()[0] = v3[0]; data()[1] = v3[1]; data()[2] = v3[2]; data()[3] = v4; }
-
+#endif
/// Access by index, the index is unchecked
const T& operator()(unsigned i) const
T& w(void)
{ return data()[3]; }
- /// Get the data pointer
- using SGVec4Storage<T>::data;
-
- /// Readonly interface function to ssg's sgVec4/sgdVec4
- const T (&sg(void) const)[4]
- { return data(); }
- /// Interface function to ssg's sgVec4/sgdVec4
- T (&sg(void))[4]
- { return data(); }
+ /// Readonly raw storage interface
+ const T (&data(void) const)[4]
+ { return _data; }
+ /// Readonly raw storage interface
+ T (&data(void))[4]
+ { return _data; }
- /// Interface function to osg's Vec4*
- using SGVec4Storage<T>::osg;
+#ifndef NO_OPENSCENEGRAPH_INTERFACE
+ osg::Vec4d osg() const
+ { return osg::Vec4d(data()[0], data()[1], data()[2], data()[3]); }
+#endif
/// Inplace addition
SGVec4& operator+=(const SGVec4& v)
{ return SGVec4(0, 0, 1, 0); }
static SGVec4 e4(void)
{ return SGVec4(0, 0, 0, 1); }
+
+private:
+ T _data[4];
};
/// Unary +, do nothing ...
toVec4d(const SGVec4f& v)
{ return SGVec4d(v(0), v(1), v(2), v(3)); }
+#ifndef NO_OPENSCENEGRAPH_INTERFACE
+inline
+SGVec4d
+toSG(const osg::Vec4d& v)
+{ return SGVec4d(v[0], v[1], v[2], v[3]); }
+
+inline
+SGVec4f
+toSG(const osg::Vec4f& v)
+{ return SGVec4f(v[0], v[1], v[2], v[3]); }
+
+inline
+osg::Vec4d
+toOsg(const SGVec4d& v)
+{ return osg::Vec4d(v[0], v[1], v[2], v[3]); }
+
+inline
+osg::Vec4f
+toOsg(const SGVec4f& v)
+{ return osg::Vec4f(v[0], v[1], v[2], v[3]); }
+#endif
+
#endif
colors(2, i) = (sky_color - upperVisFactor * diff).osg();
colors(3, i) = (sky_color - middleVisFactor * diff + middle_amt).osg();
colors(4, i) = (fog_color + outer_amt).osg();
- colors(0, i) = simgear::math::lerp(sky_color.osg(), colors(2, i), .3942);
- colors(1, i) = simgear::math::lerp(sky_color.osg(), colors(2, i), .7885);
+ colors(0, i) = simgear::math::lerp(toOsg(sky_color), colors(2, i), .3942);
+ colors(1, i) = simgear::math::lerp(toOsg(sky_color), colors(2, i), .7885);
for (int j = 0; j < numRings - 1; ++j)
clampColor(colors(j, i));
outer_amt -= outer_diff;