1 // vector.hxx -- additional vector routines
3 // Written by Curtis Olson, started December 1997.
5 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Library General Public License for more details.
17 // You should have received a copy of the GNU Library General Public
18 // License along with this library; if not, write to the
19 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 // Boston, MA 02111-1307, USA.
30 # error This library requires C++
37 #include <simgear/compiler.h>
42 inline void sgmap_vec_onto_cur_surface_plane( sgVec3 normal,
49 // calculate a vector "u1" representing the shortest distance from
50 // the plane specified by normal and v0 to a point specified by
51 // "vec". "u1" represents both the direction and magnitude of
52 // this desired distance.
54 // u1 = ( (normal <dot> vec) / (normal <dot> normal) ) * normal
58 ( sgScalarProductVec3(normal, vec) /
59 sgScalarProductVec3(normal, normal)
63 // printf(" vec = %.2f, %.2f, %.2f\n", vec[0], vec[1], vec[2]);
64 // printf(" v0 = %.2f, %.2f, %.2f\n", v0[0], v0[1], v0[2]);
65 // printf(" u1 = %.2f, %.2f, %.2f\n", u1[0], u1[1], u1[2]);
67 // calculate the vector "v" which is the vector "vec" mapped onto
68 // the plane specified by "normal" and "v0".
72 sgAddVec3(tmp, v0, vec);
73 sgSubVec3(v, tmp, u1);
74 // printf(" v = %.2f, %.2f, %.2f\n", v[0], v[1], v[2]);
76 // Calculate the vector "result" which is "v" - "v0" which is a
77 // directional vector pointing from v0 towards v
81 sgSubVec3(result, v, v0);
82 // printf(" result = %.2f, %.2f, %.2f\n",
83 // result[0], result[1], result[2]);
87 inline void sgCopyNegateVec4( sgVec4 dst, sgVec4 src )
89 dst [ 0 ] = -src [ 0 ] ;
90 dst [ 1 ] = -src [ 1 ] ;
91 dst [ 2 ] = -src [ 2 ] ;
92 dst [ 3 ] = -src [ 3 ] ;
95 // Given a point p, and a line through p0 with direction vector d,
96 // find the closest point (p1) on the line
97 void sgClosestPointToLine( sgVec3 p1, const sgVec3 p, const sgVec3 p0,
100 // Given a point p, and a line through p0 with direction vector d,
101 // find the closest point (p1) on the line
102 void sgdClosestPointToLine( sgdVec3 p1, const sgdVec3 p, const sgdVec3 p0,
105 // Given a point p, and a line through p0 with direction vector d,
106 // find the shortest distance (squared) from the point to the line
107 double sgClosestPointToLineDistSquared( const sgVec3 p, const sgVec3 p0,
110 // Given a point p, and a line through p0 with direction vector d,
111 // find the shortest distance (squared) from the point to the line
112 double sgdClosestPointToLineDistSquared( const sgdVec3 p, const sgdVec3 p0,
116 // sgMakeMatTrans4( sgMat4 sgTrans, sgVec3 trans )
117 // sgPostMultMat4( sgMat, sgTRANS );
118 void sgPostMultMat4ByTransMat4( sgMat4 src, const sgVec3 trans );
120 #endif // _VECTOR_HXX