#endif
#include <sstream>
-#include <simgear/math/vector.hxx>
+#include <simgear/math/SGGeometry.hxx>
#include <Main/viewer.hxx>
#include "HUD.hxx"
-
// FIXME
static float get__heading() { return fgGetFloat("/orientation/heading-deg") * M_PI / 180.0; }
static float get__throttleval() { return fgGetFloat("/controls/engines/engine/throttle"); }
// however the horizon line should always stay on the horizon. We
// project the alpha/beta offset onto the horizon line to get the
// result we want.
- sgdVec3 p1; // result
- sgdVec3 p; sgdSetVec3(p, vel_x, vel_y, 0.0);
- sgdVec3 p0; sgdSetVec3(p0, 0.0, 0.0, 0.0);
- sgdVec3 d; sgdSetVec3(d, cos(roll_value), sin(roll_value), 0.0);
- sgdClosestPointToLine(p1, p, p0, d);
- glTranslatef(p1[0], p1[1], 0);
+
+ SGVec3d d(cos(roll_value), sin(roll_value), 0.0);
+ SGRayd r(SGVec3d::zeros(), d);
+ SGVec3d p = r.getClosestPointTo(SGVec3d(vel_x, vel_y, 0.0));
+ glTranslatef(p[0], p[1], 0);
}
} else {
// ladder position is fixed relative to the center of the screen.
#include <simgear/sg_inlines.h>
#include <simgear/timing/sg_time.hxx>
-#include <simgear/math/vector.hxx>
#include <simgear/math/sg_random.h>
#include <simgear/misc/sg_path.hxx>
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/constants.h>
#include <simgear/scene/model/placement.hxx>
-#include <simgear/math/vector.hxx>
#include <Main/globals.hxx>
#include <Scenery/scenery.hxx>
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
-#include <simgear/math/vector.hxx>
#include <simgear/structure/exception.hxx>
#include <simgear/scene/model/modellib.hxx>
#include <simgear/scene/tgdb/SGReaderWriterBTGOptions.hxx>
#endif
#include <simgear/math/SGMath.hxx>
-#include <simgear/math/vector.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/timing/sg_time.hxx>
#include "sunsolver.hxx"
#include "tmp.hxx"
+/**
+ * Map i.e. project a vector onto a plane.
+ * @param normal (in) normal vector for the plane
+ * @param v0 (in) a point on the plane
+ * @param vec (in) the vector to map onto the plane
+ */
+static SGVec3f map_vec_onto_cur_surface_plane(const SGVec3f& normal,
+ const SGVec3f& v0,
+ const SGVec3f& vec)
+{
+ // calculate a vector "u1" representing the shortest distance from
+ // the plane specified by normal and v0 to a point specified by
+ // "vec". "u1" represents both the direction and magnitude of
+ // this desired distance.
+
+ // u1 = ( (normal <dot> vec) / (normal <dot> normal) ) * normal
+ SGVec3f u1 = (dot(normal, vec) / dot(normal, normal)) * normal;
+
+ // calculate the vector "v" which is the vector "vec" mapped onto
+ // the plane specified by "normal" and "v0".
+
+ // v = v0 + vec - u1
+ SGVec3f v = v0 + vec - u1;
+
+ // Calculate the vector "result" which is "v" - "v0" which is a
+ // directional vector pointing from v0 towards v
+
+ // result = v - v0
+ return v - v0;
+}
+
// periodic time updater wrapper
void fgUpdateLocalTime() {
// local plane representing "horizontal".
// surface direction to go to head towards sun
- SGVec3f surface_to_sun;
SGVec3f view_pos = toVec3f(v->get_view_pos());
- sgmap_vec_onto_cur_surface_plane( world_up.data(), view_pos.data(),
- to_sun.data(), surface_to_sun.data() );
+ SGVec3f surface_to_sun = map_vec_onto_cur_surface_plane(world_up, view_pos, to_sun);
+
surface_to_sun = normalize(surface_to_sun);
// cout << "(sg) Surface direction to sun is "
// << surface_to_sun[0] << ","