/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Patrick Boenzli co-programmer: ... */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SPATIAL_SEPARATION #include "spatial_separation.h" #include "abstract_model.h" #include "quadtree.h" using namespace std; /** * standard constructor * @param model the model that is to be separated * @param overlapSize each box will overlap for a given size The boxes are overlaping because this makes collision detection a lot simpler */ SpatialSeparation::SpatialSeparation (AbstractModel* model, float overlapSize) { this->setClassID(CL_SPATIAL_SEPARATION, "SpatialSeparation"); } /** * standard constructor * @param model the model that is to be separated * @param overlapSize each box will overlap for a given size The boxes are overlaping because this makes collision detection a lot simpler */ SpatialSeparation::SpatialSeparation (AbstractModel* model, AbstractModel* playerModel) { this->setClassID(CL_SPATIAL_SEPARATION, "SpatialSeparation"); } /** * standard deconstructor */ SpatialSeparation::~SpatialSeparation () { } /** \brief creates a quadtree * @param model the model to do a quadtree on * @param minLength the minimal length of a quadtree node \return the new quadtree */ Quadtree* SpatialSeparation::createQuadtree(AbstractModel* model, float minLength) { this->minLength = minLength; } /** \brief creates a quadtree * @param model the model to do a quadtree on * @param minLength the minimal length of a quadtree node \return the new quadtree */ Quadtree* SpatialSeparation::createQuadtree(AbstractModel* model, int treeDepth) { this->treeDepth = treeDepth; } /** \brief creates a quadtree * @param model the model to do a quadtree on * @param minLength the minimal length of a quadtree node \return the new quadtree */ Quadtree* SpatialSeparation::createQuadtree(AbstractModel* model) { this->quadtree = new Quadtree(model->getModelInfo()); this->quadtree->separate(); return this->quadtree; } /** \brief gets the maximal dimension of a model * @param playerModel the model that this measurement is based on \return the dimension of the AbstractModel as a Rectangle The rectangle is x-z axis aligned. ATTENTION: if there are any vertices in the model, that exceed the size of 999999.0, there probably will be some errors in the dimensions calculations. */ Rectangle* SpatialSeparation::getDimension(AbstractModel* playerModel) { float maxX, maxY; //!< the maximal coordinates axis float minX, minY; //!< minimal axis coorindates const float* pVertices; //!< pointer to the current vertices maxX = -999999; maxY = -999999; minX = 999999; minY = 999999; /* get maximal/minimal x/y */ for( int i = 0; i < playerModel->getModelInfo()->numVertices; ++i) { pVertices = &playerModel->getModelInfo()->pVertices[i * 3]; if( pVertices[0] > maxX) maxX = pVertices[0]; if( pVertices[2] > maxY) maxY = pVertices[2]; if( pVertices[0] < minX) minX = pVertices[0]; if( pVertices[2] < minY) minY = pVertices[2]; PRINTF(0)("Dimension Informationation: X: min/max %f/%f Y: min/max %f/%f\n", minX, maxX, minY, maxY); } }