[4790] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 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 | |
---|
[4923] | 11 | ### File Specific: |
---|
[4791] | 12 | main-programmer: Patrick Boenzli |
---|
[4790] | 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
[4808] | 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SPATIAL_SEPARATION |
---|
[4790] | 17 | |
---|
| 18 | #include "spatial_separation.h" |
---|
[5075] | 19 | |
---|
[6022] | 20 | #include "model.h" |
---|
[4819] | 21 | #include "quadtree.h" |
---|
[5075] | 22 | #include "debug.h" |
---|
[5427] | 23 | #include "compiler.h" |
---|
[4790] | 24 | |
---|
| 25 | using namespace std; |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | /** |
---|
[4836] | 29 | * standard constructor |
---|
| 30 | * @param model the model that is to be separated |
---|
| 31 | * @param overlapSize each box will overlap for a given size |
---|
[4810] | 32 | |
---|
| 33 | The boxes are overlaping because this makes collision detection a lot simpler |
---|
| 34 | |
---|
[4923] | 35 | */ |
---|
[6022] | 36 | SpatialSeparation::SpatialSeparation (Model* model, float overlapSize) |
---|
[4790] | 37 | { |
---|
[4887] | 38 | PRINT(3)("+---------Debug Information SpatialSeparation----------\n"); |
---|
| 39 | PRINT(3)("+-| (Event) Spatial Separation process kicked on\n"); |
---|
| 40 | |
---|
[4923] | 41 | this->setClassID(CL_SPATIAL_SEPARATION, "SpatialSeparation"); |
---|
| 42 | /* debug vice */ |
---|
| 43 | this->createQuadtree(model); |
---|
[4790] | 44 | } |
---|
| 45 | |
---|
[4923] | 46 | |
---|
[4810] | 47 | /** |
---|
[4836] | 48 | * standard constructor |
---|
| 49 | * @param model the model that is to be separated |
---|
| 50 | * @param overlapSize each box will overlap for a given size |
---|
[4790] | 51 | |
---|
[4810] | 52 | The boxes are overlaping because this makes collision detection a lot simpler |
---|
| 53 | */ |
---|
[6022] | 54 | SpatialSeparation::SpatialSeparation (Model* model, Model* playerModel) |
---|
[4810] | 55 | { |
---|
| 56 | this->setClassID(CL_SPATIAL_SEPARATION, "SpatialSeparation"); |
---|
| 57 | |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | |
---|
[4790] | 61 | /** |
---|
[4836] | 62 | * standard deconstructor |
---|
[4923] | 63 | */ |
---|
[4790] | 64 | SpatialSeparation::~SpatialSeparation () |
---|
| 65 | { |
---|
[4968] | 66 | if( this->quadtree) |
---|
| 67 | delete this->quadtree; |
---|
[4790] | 68 | } |
---|
[4819] | 69 | |
---|
| 70 | |
---|
| 71 | /** |
---|
[4923] | 72 | * creates a quadtree |
---|
| 73 | * @param model the model to do a quadtree on |
---|
| 74 | * @param minLength the minimal length of a quadtree node |
---|
| 75 | * @return the new quadtree |
---|
[4819] | 76 | */ |
---|
[6022] | 77 | Quadtree* SpatialSeparation::createQuadtree(Model* model, float minLength) |
---|
[4819] | 78 | { |
---|
| 79 | this->minLength = minLength; |
---|
| 80 | |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | /** |
---|
[4923] | 85 | * brief creates a quadtree |
---|
| 86 | * @param model the model to do a quadtree on |
---|
| 87 | * @param minLength the minimal length of a quadtree node |
---|
| 88 | * @return the new quadtree |
---|
[4819] | 89 | */ |
---|
[6022] | 90 | Quadtree* SpatialSeparation::createQuadtree(Model* model, int treeDepth) |
---|
[4819] | 91 | { |
---|
| 92 | this->treeDepth = treeDepth; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | /** |
---|
[4923] | 97 | * creates a quadtree |
---|
| 98 | * @param model the model to do a quadtree on |
---|
| 99 | * @param minLength the minimal length of a quadtree node |
---|
| 100 | * @return the new quadtree |
---|
| 101 | */ |
---|
[6022] | 102 | Quadtree* SpatialSeparation::createQuadtree(Model* model) |
---|
[4819] | 103 | { |
---|
[4922] | 104 | this->quadtree = new Quadtree(model->getModelInfo(), 4); |
---|
[4819] | 105 | |
---|
| 106 | return this->quadtree; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
[4923] | 110 | /** |
---|
| 111 | * draws all the quadtrees |
---|
| 112 | */ |
---|
[4889] | 113 | void SpatialSeparation::drawQuadtree() |
---|
| 114 | { |
---|
| 115 | if( unlikely( this->quadtree == NULL)) |
---|
| 116 | return; |
---|
[4819] | 117 | |
---|
[4922] | 118 | this->quadtree->drawTree(); |
---|
[4889] | 119 | } |
---|
[4819] | 120 | |
---|
| 121 | |
---|
[4842] | 122 | |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | |
---|