Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

vector.h

Go to the documentation of this file.
00001 // OMICRON ENGINE HEADER FILE
00002 //
00003 // --------------------------------------------------------------------------
00004 // Copyright (C) 2001-2002 by Bjoern Paetzel <kolrabi@gmx.de>
00005 //
00006 // This file is part of the Omicron Engine.
00007 //
00008 // The Omicron Engine is free software; you can redistribute it and/or modify
00009 // it under the terms of the  GNU General Public License  as published by the
00010 // Free Software Foundation;  either version  2  of the License,  or (at your
00011 // option) any later version.
00012 //
00013 // The Omicron Engine  is distributed in the hope that it will be useful, but
00014 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00015 // or  FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License
00016 // for more details.
00017 //
00018 // You should have  received a copy of the  GNU General Public License  along
00019 // with The Omicron Engine;  if not,  write to the  Free Software Foundation,
00020 // Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
00021 //
00022 // --------------------------------------------------------------------------
00023 // Last modified:       $Date: 2002/12/07 19:02:18 $
00024 // By           :       $Author: kolrabi $
00025 // $Id: vector.h,v 1.1.1.1 2002/12/07 19:02:18 kolrabi Exp $ 
00026 
00027 /*
00028 
00029   $Log: vector.h,v $
00030   Revision 1.1.1.1  2002/12/07 19:02:18  kolrabi
00031   initial release
00032 
00033 
00034 */
00035 
00042 /**************************************************************************** 
00043  **************************************************************************** 
00044  * DEFINES ****************************************************************** 
00045  **************************************************************************** 
00046  ****************************************************************************/ 
00047  
00048 /* VECTOR ELEMENTS **********************************************************/ 
00049  
00050 #define         VECT_X                  0       
00051 #define         VECT_Y                  1       
00052 #define         VECT_Z                  2       
00053 #define         VECT_W                  3       
00054  
00055 #define         ANGLE_YAW               0       
00056 #define         ANGLE_PITCH             1       
00057 #define         ANGLE_ROLL              2       
00058  
00059 
00060 #define         V2TOFS(a)               (float)a[0], (float)a[1] 
00061 #define         V3TOFS(a)               V2TOFS(a), (float)a[2] 
00062 #define         V4TOFS(a)               V3TOFS(a), (float)a[3] 
00063 
00064 /**************************************************************************** 
00065  **************************************************************************** 
00066  * TYPEDEFS ***************************************************************** 
00067  **************************************************************************** 
00068  ****************************************************************************/ 
00069  
00070 #ifndef OMICRON_VECTOR_TYPES_DEFINED 
00071 #define OMICRON_VECTOR_TYPES_DEFINED
00072 
00073 typedef float       vec_t;              
00074 typedef vec_t       vec2_t[2];          
00075 typedef vec_t       vec3_t[3];          
00076 typedef vec_t       vec4_t[4];          
00077 typedef vec_t       vec5_t[5];          
00078 
00079 typedef vec3_t      edge_t[2];          
00080 
00081 typedef class vec3_c spline_t[3];       
00082 typedef spline_t    patch_t[3];         
00083 
00084 typedef struct collision_s              
00085 {
00086     float           t;                  
00087     vec3_t          pos, normal;        
00088 } collision_t;
00089 
00090 typedef struct bbox_s                   
00091 {
00092     vec3_t          pos1, pos2;         
00093     vec3_t          size[2];            
00094 } bbox_t;
00095  
00096 typedef float       matrix3_t[4][4];    
00097 typedef float       matrix4_t[4][4];    
00098  
00099 typedef struct plane_s                  
00100 { 
00101     vec3_t          n;                  
00102     vec_t           d;                  
00103 } plane_t; 
00104  
00112 typedef struct vertex_s                 
00113 { 
00114     vec3_t          xyz;                
00115     vec2_t          uv[2];              
00116     vec3_t          normal;             
00117     long            diffuse;            
00118 } vertex_t; 
00119 
00125 typedef struct intersection_s
00126 {
00127     float           t;                  
00128     vec3_t          pos;                
00129     plane_t         plane;              
00130 } intersection_t;
00131 
00132 
00133 #ifndef ushort
00134 typedef unsigned short ushort;
00135 typedef unsigned long ulong;
00136 #endif
00137 
00138 class vec3_c
00140 {
00141 protected:
00142 
00143     vec3_t          vec;                
00144 
00145 public:
00146 
00147     static const vec3_t          vec3x;
00148     static const vec3_t          vec3y;
00149     static const vec3_t          vec3z;
00150     static const vec3_t          vec30;
00151 
00152     vec3_c();                           
00153     vec3_c(const vec3_c &);             
00154     vec3_c(const vec3_t);               
00155     vec3_c(float, float, float);        
00156 
00157     virtual ~vec3_c();                  
00158 
00159     operator const float *();           
00160 
00162     void
00163     set
00164     ( 
00165         float               x,
00166         float               y,
00167         float               z
00168         );
00169 
00171     void
00172     set_component
00173     (
00174         int                 n,
00175         float               x
00176     );
00177 
00179     void
00180     clear
00181     ();
00182 
00187     float 
00188     length
00189     ();
00190 
00195     float
00196     length_squared             
00197     ();
00198 
00199     // ******************************************************************* //
00200     // OPERATIONS (OPERATORS, CROSSPRODUCT ETC)
00201 
00202     vec3_c                              
00203     operator -(const vec3_t);
00204 
00205 //    vec3_c
00206 //    operator +(const vec3_t);           /// add vectors
00207 
00208         friend vec3_c
00209         operator +(const vec3_t, const vec3_c);
00210 
00211     vec3_c
00212     operator *(float);                  
00213 
00214     vec3_c                              
00215     operator *(const vec3_t);
00216 
00217     vec3_c                              
00218     operator =(const vec3_t);
00219 
00220     bool                                
00221     operator ==(const vec3_t);
00222 
00223     vec3_c
00224     normalize();
00225 
00226     vec3_c
00227     cross                    
00229     ( 
00230         const vec3_t        v
00231     );
00232 
00233     float
00234     dot
00236     ( 
00237         const vec3_t        v
00238     );
00239 
00240     // ******************************************************************* //
00241     // PROJECTION
00242 
00243     vec3_c
00244     project();
00245 
00246     vec3_c
00247     project_ex(ulong w, ulong h);
00248 
00249     vec3_c
00250     unproject();
00251 
00252     vec3_c
00253     unproject_ex(ulong w, ulong h);
00254 
00255     vec3_c
00256     rotate
00258     ( 
00259         const vec3_t        angles          
00260     );
00261 
00262     vec3_c
00263     project_on_plane
00266     ( 
00267         const vec3_t        normal          
00268     );
00269 
00270     vec3_c
00271     perpendicular               
00274     ( 
00275     );
00276 
00277     vec3_c
00278     rotate_vec
00281     ( 
00282         const float         degrees,        
00283         const vec3_t        dir             
00284     );
00285 
00286     void
00287     get_view_from_angles
00290     ( 
00291         vec3_c              &forward,       
00292         vec3_c              &right,         
00293         vec3_c              &up             
00294     );
00295 
00300     ushort
00301     pack_normal
00302     ( 
00303     );
00304 
00305     /* experimental -->
00306     float
00307     vector_intersect_bbox
00310     (
00311         const vec3_t        v,              
00312         const bbox_t        *bbox,          
00313         collision_t         *out            
00314     );
00315     */
00316 
00317     void copy(vec3_t out)
00318     {
00319         out[0] = vec[0];
00320         out[1] = vec[1];
00321         out[2] = vec[2];
00322     }
00323 
00324     // ******************************************************************* //
00325     // STATIC
00326 
00331     static vec3_c
00332     unpack_normal
00333     ( 
00334         ushort      in                  
00335     );
00336 
00337     static vec3_c
00338     bezier_patch
00340     (
00341         const patch_t       patch,
00342         float               u,
00343         float               v
00344     );
00345 
00346     static vec3_c
00347     bezier_spline
00350     ( 
00351         const spline_t      spline,
00352         const float         frac            
00353     );
00354 
00355     static vec3_c
00356     hermite
00359     ( 
00360         const vec3_t        p1,             
00361         const vec3_t        t1,             
00362         const vec3_t        p2,             
00363         const vec3_t        t2,             
00364         const float         frac            
00365     );
00366 
00367     static vec3_c
00368     linear
00371     ( 
00372         const vec3_t        p1,             
00373         const vec3_t        p2,             
00374         const float         frac            
00375     );
00376 };
00377 
00378 #endif  // OMICRON_VECTOR_TYPES_DEFINED
00379 
00380 // include 2 and 4 dimensional stuff too..
00381  
00382 #include            "vector2.h"
00383 #include            "vector4.h"
00384  
00385 /**************************************************************************** 
00386  **************************************************************************** 
00387  * FUNCTIONS **************************************************************** 
00388  **************************************************************************** 
00389  ****************************************************************************/ 
00390  
00391 
00393 // plane stuff
00394 
00395 plane_t
00396 plane_frompoints
00398 // Creates a plane from three points that lie in that plane.
00399 ( 
00400     const vec3_t        a,              
00401     const vec3_t        b, 
00402     const vec3_t        c 
00403 );
00404 
00405 float
00406 plane_line_intersect
00411 ( 
00412     const vec3_t        a,              
00413     const vec3_t        b,              
00414     const plane_t       *p,             
00415     vec3_t              out             
00416 );
00417 
00418 float
00419 plane_pointdist
00422 (
00423     const vec3_t        v,              
00424     const plane_t       *p              
00425 );
00426 
00427 int
00428 plane_pointside
00431 (
00432     const vec3_t        v,              
00433     const plane_t       *p              
00434 );
00435 
00436 int
00437 plane_clip_box
00441 (
00442     const plane_t       *p,             
00443     const bbox_t        *bbox           
00444 );
00445 
00447 // vertex stuff
00448 
00449 void
00450 vertex_set_ex
00453 (
00454     vertex_t            *vert,          
00455     float               x,              
00456     float               y, 
00457     float               z, 
00458     float               u,              
00459     float               v, 
00460     float               lu,             
00461     float               lv 
00462 );
00463 
00464 void
00465 vertex_set
00468 ( 
00469     vertex_t            *vert,          
00470     float               x,              
00471     float               y, 
00472     float               z, 
00473     float               u,              
00474     float               v
00475 );
00476 
00477 void
00478 vertex_copy
00481 ( 
00482     vertex_t            *in,            
00483     vertex_t            *out            
00484 );
00485 
00487 // matrix stuff
00488 
00489 void
00490 matrix3_mult
00493 ( 
00494     const matrix3_t     a,              
00495     const matrix3_t     b,              
00496     matrix3_t           out             
00497 );
00498 
00499 vec3_c
00500 operator +(const vec3_t, vec3_c);

Generated on Wed Dec 18 15:48:48 2002 for omicron engine by doxygen1.2.18