00001 00006 // Written by Curtis Olson, started December 1997. 00007 // 00008 // Copyright (C) 1997 Curtis L. Olson - http://www.flightgear.org/~curt 00009 // 00010 // This library is free software; you can redistribute it and/or 00011 // modify it under the terms of the GNU Library General Public 00012 // License as published by the Free Software Foundation; either 00013 // version 2 of the License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Library General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU General Public License 00021 // along with this program; if not, write to the Free Software 00022 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00023 // 00024 // $Id: vector_8hxx-source.html,v 1.17 2008/12/18 22:33:10 curt Exp $ 00025 00026 00027 #ifndef _VECTOR_HXX 00028 #define _VECTOR_HXX 00029 00030 00031 #ifndef __cplusplus 00032 # error This library requires C++ 00033 #endif 00034 00035 #include <simgear/compiler.h> 00036 00037 #include <plib/sg.h> 00038 00039 00047 inline void sgmap_vec_onto_cur_surface_plane( sgVec3 normal, 00048 sgVec3 v0, 00049 sgVec3 vec, 00050 sgVec3 result ) 00051 { 00052 sgVec3 u1, v, tmp; 00053 00054 // calculate a vector "u1" representing the shortest distance from 00055 // the plane specified by normal and v0 to a point specified by 00056 // "vec". "u1" represents both the direction and magnitude of 00057 // this desired distance. 00058 00059 // u1 = ( (normal <dot> vec) / (normal <dot> normal) ) * normal 00060 00061 sgScaleVec3( u1, 00062 normal, 00063 ( sgScalarProductVec3(normal, vec) / 00064 sgScalarProductVec3(normal, normal) 00065 ) 00066 ); 00067 00068 // printf(" vec = %.2f, %.2f, %.2f\n", vec[0], vec[1], vec[2]); 00069 // printf(" v0 = %.2f, %.2f, %.2f\n", v0[0], v0[1], v0[2]); 00070 // printf(" u1 = %.2f, %.2f, %.2f\n", u1[0], u1[1], u1[2]); 00071 00072 // calculate the vector "v" which is the vector "vec" mapped onto 00073 // the plane specified by "normal" and "v0". 00074 00075 // v = v0 + vec - u1 00076 00077 sgAddVec3(tmp, v0, vec); 00078 sgSubVec3(v, tmp, u1); 00079 // printf(" v = %.2f, %.2f, %.2f\n", v[0], v[1], v[2]); 00080 00081 // Calculate the vector "result" which is "v" - "v0" which is a 00082 // directional vector pointing from v0 towards v 00083 00084 // result = v - v0 00085 00086 sgSubVec3(result, v, v0); 00087 // printf(" result = %.2f, %.2f, %.2f\n", 00088 // result[0], result[1], result[2]); 00089 } 00090 00091 00097 inline void sgCopyNegateVec4( sgVec4 dst, sgVec4 src ) 00098 { 00099 dst [ 0 ] = -src [ 0 ] ; 00100 dst [ 1 ] = -src [ 1 ] ; 00101 dst [ 2 ] = -src [ 2 ] ; 00102 dst [ 3 ] = -src [ 3 ] ; 00103 } 00104 00113 void sgClosestPointToLine( sgVec3 p1, const sgVec3 p, const sgVec3 p0, 00114 const sgVec3 d ); 00115 00124 void sgdClosestPointToLine( sgdVec3 p1, const sgdVec3 p, const sgdVec3 p0, 00125 const sgdVec3 d ); 00126 00136 double sgClosestPointToLineDistSquared( const sgVec3 p, const sgVec3 p0, 00137 const sgVec3 d ); 00138 00148 double sgdClosestPointToLineDistSquared( const sgdVec3 p, const sgdVec3 p0, 00149 const sgdVec3 d ); 00150 00160 void sgPostMultMat4ByTransMat4( sgMat4 src, const sgVec3 trans ); 00161 00162 00163 #endif // _VECTOR_HXX 00164 00165
1.5.6