]> git.mxchange.org Git - simgear.git/blob - simgear/math/vector.hxx
Fix a build order problem.
[simgear.git] / simgear / math / vector.hxx
1 // vector.hxx -- additional vector routines
2 //
3 // Written by Curtis Olson, started December 1997.
4 //
5 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
6 //
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.
11 //
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.
16 //
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.
21 //
22 // $Id$
23
24
25 #ifndef _VECTOR_HXX
26 #define _VECTOR_HXX
27
28
29 #ifndef __cplusplus                                                          
30 # error This library requires C++
31 #endif                                   
32
33 #ifdef HAVE_CONFIG_H
34 #  include <config.h>
35 #endif
36
37 #include <simgear/compiler.h>
38
39 #include <plib/sg.h>
40
41
42 inline void sgmap_vec_onto_cur_surface_plane( sgVec3 normal, 
43                                               sgVec3 v0, 
44                                               sgVec3 vec,
45                                               sgVec3 result )
46 {
47     sgVec3 u1, v, tmp;
48
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.
53
54     // u1 = ( (normal <dot> vec) / (normal <dot> normal) ) * normal
55
56     sgScaleVec3( u1,
57                  normal,
58                  ( sgScalarProductVec3(normal, vec) /
59                    sgScalarProductVec3(normal, normal)
60                    )
61                  );
62
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]);
66    
67     // calculate the vector "v" which is the vector "vec" mapped onto
68     // the plane specified by "normal" and "v0".
69
70     // v = v0 + vec - u1
71
72     sgAddVec3(tmp, v0, vec);
73     sgSubVec3(v, tmp, u1);
74     // printf("  v = %.2f, %.2f, %.2f\n", v[0], v[1], v[2]);
75
76     // Calculate the vector "result" which is "v" - "v0" which is a
77     // directional vector pointing from v0 towards v
78
79     // result = v - v0
80
81     sgSubVec3(result, v, v0);
82     // printf("  result = %.2f, %.2f, %.2f\n", 
83     // result[0], result[1], result[2]);
84 }
85
86
87 inline void sgCopyNegateVec4( sgVec4 dst, sgVec4 src )
88 {
89         dst [ 0 ] = -src [ 0 ] ;
90         dst [ 1 ] = -src [ 1 ] ;
91         dst [ 2 ] = -src [ 2 ] ;
92         dst [ 3 ] = -src [ 3 ] ;
93 }
94
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,
98                            const sgVec3 d );
99
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,
103                             const sgdVec3 d );
104
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,
108                                         const sgVec3 d );
109
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,
113                                          const sgdVec3 d );
114
115 // This is same as
116 // sgMakeMatTrans4( sgMat4 sgTrans, sgVec3 trans )
117 // sgPostMultMat4( sgMat, sgTRANS );
118 void sgPostMultMat4ByTransMat4( sgMat4 src, const sgVec3 trans );
119
120 #endif // _VECTOR_HXX
121
122