[8319] | 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 | |
---|
| 14 | */ |
---|
| 15 | #ifndef _TERRAIN_QUAD_TREE_H |
---|
| 16 | #define _TERRAIN_QUAD_TREE_H |
---|
| 17 | |
---|
| 18 | #include "types.h" |
---|
| 19 | #include "frustum.h" |
---|
| 20 | #include <stdio.h> |
---|
| 21 | class Terrain; |
---|
| 22 | class TerrainQuad; |
---|
| 23 | typedef TerrainQuad *pTerrainQuad; |
---|
| 24 | |
---|
| 25 | typedef enum { TL_CHILD = 0, TR_CHILD = 1, BL_CHILD = 2, BR_CHILD = 3 } TerrainQuadChild; |
---|
| 26 | |
---|
| 27 | class TerrainQuad { |
---|
| 28 | public: |
---|
| 29 | TerrainQuad( Terrain *_owner, int _xOffset, int _zOffset ); |
---|
| 30 | TerrainQuad( Terrain *_owner, int _x0, int _z0, int _x1, int _z1 ); |
---|
| 31 | |
---|
| 32 | virtual ~TerrainQuad( ) |
---|
| 33 | { |
---|
[8775] | 34 | for ( int i = 0; i < 4; ++i ) { |
---|
| 35 | if ( !children[i]->isChildless() ) |
---|
| 36 | SAVE_DELETE( children[i] ); |
---|
| 37 | } |
---|
[8319] | 38 | } |
---|
| 39 | int cull( ); |
---|
| 40 | |
---|
| 41 | /** |
---|
| 42 | * Returns the array containing the children quad-nodes of this node in the following |
---|
| 43 | * order: top-left, top-right, bottom-left, bottom-right |
---|
| 44 | */ |
---|
| 45 | inline pTerrainQuad* getChildren( ) |
---|
| 46 | { |
---|
| 47 | return children; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | /** |
---|
| 51 | * Sets the child-nodes to the specified _children elements. |
---|
| 52 | */ |
---|
| 53 | void setChildren( pTerrainQuad _children[] ) |
---|
| 54 | { |
---|
| 55 | for ( int i = 0; i < 4; ++i ) |
---|
| 56 | children[i] = _children[i]; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | inline bool isChildless() { return ( children[0] == NULL ); } |
---|
| 60 | |
---|
| 61 | /** |
---|
| 62 | * Returns the child node given by _child. The returned node may be null. |
---|
| 63 | */ |
---|
| 64 | inline pTerrainQuad getChild( TerrainQuadChild _child ) |
---|
| 65 | { |
---|
| 66 | return children[_child]; |
---|
| 67 | } |
---|
[9147] | 68 | inline void setScale( Vector _scale ) |
---|
[8319] | 69 | { |
---|
| 70 | scale = _scale; |
---|
| 71 | } |
---|
| 72 | inline const ABox getBounds() { return bounds; } |
---|
| 73 | inline void setChildren( pTerrainQuad _bl, pTerrainQuad _br, pTerrainQuad _tl, |
---|
| 74 | pTerrainQuad _tr ) |
---|
| 75 | { |
---|
| 76 | children[TL_CHILD] = _tl; |
---|
| 77 | children[TR_CHILD] = _tr; |
---|
| 78 | children[BR_CHILD] = _br; |
---|
| 79 | children[BL_CHILD] = _bl; |
---|
| 80 | } |
---|
| 81 | /** |
---|
| 82 | * Calculates the mininum and maximum value of this box based on the size |
---|
| 83 | * and position of its children. |
---|
| 84 | */ |
---|
| 85 | virtual void calculateBounds( ); |
---|
| 86 | inline int getXOffset() { return xOffset; } |
---|
| 87 | inline int getZOffset() { return zOffset; } |
---|
| 88 | inline int getWidth() { return width; } |
---|
| 89 | inline int getHeight() { return height; } |
---|
| 90 | |
---|
| 91 | protected: |
---|
| 92 | TerrainQuad( ) {} |
---|
| 93 | Terrain *owner; |
---|
| 94 | int xOffset, zOffset; |
---|
| 95 | int width, height; |
---|
[9147] | 96 | Vector scale; |
---|
[8319] | 97 | pTerrainQuad children[4]; |
---|
| 98 | ABox bounds; |
---|
| 99 | }; |
---|
| 100 | |
---|
| 101 | #endif |
---|