3 * Additional vector routines.
6 // Written by Curtis Olson, started December 1997.
8 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Library General Public
12 // License as published by the Free Software Foundation; either
13 // version 2 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Library General Public License for more details.
20 // You should have received a copy of the GNU Library General Public
21 // License along with this library; if not, write to the
22 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 // Boston, MA 02111-1307, USA.
33 # error This library requires C++
36 #include <simgear/compiler.h>
42 * Map a vector onto a plane.
43 * @param normal (in) normal vector for the plane
44 * @param v0 (in) a point on the plane
45 * @param vec (in) the vector to map onto the plane
46 * @param result (out) the result vector
48 inline void sgmap_vec_onto_cur_surface_plane( sgVec3 normal,
55 // calculate a vector "u1" representing the shortest distance from
56 // the plane specified by normal and v0 to a point specified by
57 // "vec". "u1" represents both the direction and magnitude of
58 // this desired distance.
60 // u1 = ( (normal <dot> vec) / (normal <dot> normal) ) * normal
64 ( sgScalarProductVec3(normal, vec) /
65 sgScalarProductVec3(normal, normal)
69 // printf(" vec = %.2f, %.2f, %.2f\n", vec[0], vec[1], vec[2]);
70 // printf(" v0 = %.2f, %.2f, %.2f\n", v0[0], v0[1], v0[2]);
71 // printf(" u1 = %.2f, %.2f, %.2f\n", u1[0], u1[1], u1[2]);
73 // calculate the vector "v" which is the vector "vec" mapped onto
74 // the plane specified by "normal" and "v0".
78 sgAddVec3(tmp, v0, vec);
79 sgSubVec3(v, tmp, u1);
80 // printf(" v = %.2f, %.2f, %.2f\n", v[0], v[1], v[2]);
82 // Calculate the vector "result" which is "v" - "v0" which is a
83 // directional vector pointing from v0 towards v
87 sgSubVec3(result, v, v0);
88 // printf(" result = %.2f, %.2f, %.2f\n",
89 // result[0], result[1], result[2]);
94 * Copy and negate a vector.
95 * @param dst (out) result vector
96 * @param src (in) input vector
98 inline void sgCopyNegateVec4( sgVec4 dst, sgVec4 src )
100 dst [ 0 ] = -src [ 0 ] ;
101 dst [ 1 ] = -src [ 1 ] ;
102 dst [ 2 ] = -src [ 2 ] ;
103 dst [ 3 ] = -src [ 3 ] ;
107 * Given a point p, and a line through p0 with direction vector d,
108 * find the closest point (p1) on the line (float version).
109 * @param p1 (out) closest point to p on the line
110 * @param p (in) original point
111 * @param p0 (in) point on the line
112 * @param d (in) vector defining line direction
114 void sgClosestPointToLine( sgVec3 p1, const sgVec3 p, const sgVec3 p0,
118 * Given a point p, and a line through p0 with direction vector d,
119 * find the closest point (p1) on the line (double version).
120 * @param p1 (out) closest point to p on the line
121 * @param p (in) original point
122 * @param p0 (in) point on the line
123 * @param d (in) vector defining line direction
125 void sgdClosestPointToLine( sgdVec3 p1, const sgdVec3 p, const sgdVec3 p0,
129 * Given a point p, and a line through p0 with direction vector d,
130 * find the shortest distance (squared) from the point to the line (float
132 * @param p (in) original point
133 * @param p0 (in) point on the line
134 * @param d (in) vector defining line direction
135 * @return shortest distance (squared) from p to line
137 double sgClosestPointToLineDistSquared( const sgVec3 p, const sgVec3 p0,
141 * Given a point p, and a line through p0 with direction vector d,
142 * find the shortest distance (squared) from the point to the line (double
144 * @param p (in) original point
145 * @param p0 (in) point on the line
146 * @param d (in) vector defining line direction
147 * @return shortest distance (squared) from p to line
149 double sgdClosestPointToLineDistSquared( const sgdVec3 p, const sgdVec3 p0,
155 * <li> sgMakeMatTrans4( sgMat4 sgTrans, sgVec3 trans )
156 * <li> sgPostMultMat4( sgMat4 src, sgTRANS );
158 * @param src starting sgMat4 matrix
159 * @param trans translation vector
161 void sgPostMultMat4ByTransMat4( sgMat4 src, const sgVec3 trans );
164 #endif // _VECTOR_HXX