Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain/src/lib/graphics/importer/terrain/types.h @ 8321

Last change on this file since 8321 was 8319, checked in by ponder, 18 years ago

I know this is a big commit. I'm sorry about that. Anyway…

  • Added the Terrain / TerrainQuad TerrainPage and Frustum classes to the project. The rendering frustum culling is working.
  • The types.h is here only temporary. It should be removed afterwards.
File size: 2.6 KB
Line 
1/*
2        orxonox - the future of 3D-vertical-scrollers
3 
4        Copyright (C) 2006 orx
5 
6        This program is free software; you can redistribute it and/or modify
7        it under the terms of the GNU General Public License as published by
8        the Free Software Foundation; either version 2, or (at your option)
9        any later version.
10 
11        ### File Specific:
12        main programmer: Marco Biasini
13        This files needs to be removed after code-revision...
14 */
15#ifndef TYPES_H
16#define TYPES_H
17
18#ifndef NULL
19#define NULL 0
20#endif
21#include <math.h>
22
23
24struct Triple {
25        Triple( float _x, float _y, float _z ) 
26        { 
27                x = _x; y = _y; z = _z; 
28        }
29        Triple() { x = y = z = 0.0f; }
30        inline float length() const
31        { return sqrt( x*x+y*y+z*z ); } 
32        float x, y, z;
33};
34
35struct TexCoord {
36        TexCoord( float _u, float _v )
37        {
38                u = _u; v = _v;
39        }
40        TexCoord() { u = v = 0.0f; }
41        float u, v;
42};
43
44/**
45 * Defines an axis aligned box.
46 */
47struct ABox {
48       
49        ABox( Triple _min, Triple _max)
50        {
51                corner = _min;
52                x = _max.x-_min.x;
53                y = _max.y-_min.y;
54                z = _max.z-_min.z;
55        }
56       
57        ABox() 
58        {
59                corner = Triple( 0.0f, 0.0f, 0.0f );
60                x = y = z = 0.0f;
61        }
62        inline void set( const Triple& _min, const Triple& _max )
63        {
64                setMin( _min ); setMax( _max );
65        }
66        inline void setMax( const Triple& _max )
67        {
68                x = _max.x-corner.x;
69                y = _max.y-corner.y;
70                z = _max.z-corner.z;
71        }
72        inline void setMin( const Triple& _min )
73        {
74                corner = _min;
75        }
76        inline Triple vertexP( const Triple& _normal ) const 
77        {
78                Triple res = corner;
79                if ( _normal.x > 0 )
80                        res.x+= x;
81                if ( _normal.y > 0 )
82                        res.y+= y;
83                if ( _normal.z > 0 )
84                        res.z+= z;                     
85                       
86                return res;
87        }
88        inline Triple vertexN( const Triple& _normal ) const
89        {               
90                Triple res = corner;
91                if ( _normal.x < 0 )
92                        res.x+= x;
93                if ( _normal.y < 0 )
94                        res.y+= y;
95                if ( _normal.z < 0 )
96                        res.z+= z;                     
97                       
98                return res;
99       
100        }
101        inline Triple min() const { return Triple(corner); }
102        inline Triple max() const { return Triple( corner.x+x, corner.y+y, corner.z+z ); }
103        Triple corner;
104        float x, y, z;
105       
106};
107
108struct Plane {
109        Plane() { n = Triple( 0.0f, 1.0f, 0.0f ); d = 0.0f; }
110        inline void setCoefficients( float _nx, float _ny, float _nz, float _d )
111        {
112                n = Triple( _nx, _ny, _nz );
113                float l = n.length();
114                n.x /= l; n.y/=l; n.z/=l;
115                d = _d/l;
116        }
117        inline float distance( const Triple& _point ) const
118        {
119                return _point.x*n.x+_point.y*n.y+_point.z*n.z+d;
120        }
121        Triple n;
122        float d;
123};
124
125/**
126 * TODO: Replace this method with the actual matrix multiplication code!
127 */
128inline void multMat(float *res,float *a, float *b) {
129
130
131        for (int i=0;i<4;i++) {
132                for (int j = 0;j < 4;j++) {
133                        res[i*4+j] = 0.0;
134                        for (int k = 0; k < 4; k++) {
135                                res[i*4+j] += a[i*4+k] * b[k*4+j];
136                        }
137                }
138        }
139}
140typedef unsigned char UByte;
141#endif
Note: See TracBrowser for help on using the repository browser.