Changeset 8195 in orxonox.OLD for branches/bsp_model/src/lib/graphics
- Timestamp:
- Jun 7, 2006, 3:14:46 PM (18 years ago)
- Location:
- branches/bsp_model/src/lib/graphics/importer
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/bsp_model/src/lib/graphics/importer/bsp_file.cc
r8186 r8195 37 37 #include <SDL/SDL_image.h> 38 38 39 // STL Containers 40 #include <vector> 41 39 42 using namespace std; 40 43 … … 50 53 int BspFile::read(const char* name) 51 54 { 52 //this->scale = 0.4;55 this->scale = 1.0; 53 56 int offset; 54 57 int size; … … 605 608 sc = ((unsigned char *)(&lightMapTexture))[i]; 606 609 sc *= 1/255.0; 607 scale = 2.0;610 scale = 1.0; 608 611 if(sc > 1.0f && (temp = (1.0f/sc)) < scale) scale=temp; 609 612 scale*=255.0; -
branches/bsp_model/src/lib/graphics/importer/bsp_file.h
r8186 r8195 18 18 */ 19 19 20 #include <vector> 20 21 class SDL_Surface; 21 22 class BspTreeNode; … … 212 213 213 214 214 215 ::std::vector<MoviePlayer* > MovieMaterials; //!< Movieplayer Materials 215 216 }; 216 217 -
branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc
r8186 r8195 1 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 4 4 Copyright (C) 2006 orx 5 5 6 6 This program is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by 8 8 the Free Software Foundation; either version 2, or (at your option) 9 9 any later version. 10 10 11 11 ### File Specific: 12 12 main-programmer: bottac@ee.ethz.ch 13 13 14 14 Inspired by: 15 15 Rendering Q3 Maps by Morgan McGuire http://graphics.cs.brown.edu/games/quake/quake3.html 16 16 Unofficial Quake 3 Map Specs by Kekoa Proudfoot http://graphics.stanford.edu/~kekoa/q3/ 17 17 18 18 Collision detection adapted from: 19 19 Quake 3 Collision Detection by Nathan Ostgard http://www.devmaster.net/articles/quake3collision/ … … 47 47 48 48 49 49 50 //CREATE_FACTORY( BspManager, CL_BSP_MODEL); 50 51 … … 59 60 this->alreadyVisible = new bool [this->bspFile->numFaces]; 60 61 */ 61 CDEngine::getInstance()->setBSPModel(this); 62 62 63 } 63 64 … … 66 67 BspManager::BspManager(const TiXmlElement* root) 67 68 { 68 69 69 70 70 71 if( root != NULL) 71 72 this->loadParams(root); 72 73 73 74 CDEngine::getInstance()->setBSPModel(this); 74 75 } */ … … 77 78 { 78 79 //this->setClassID(CL_BSP_MODEL, "BspManager"); 79 80 // open a BSP file 80 81 this->bspFile = new BspFile(); 81 82 this->bspFile->scale = scale; … … 85 86 this->alreadyVisible = new bool [this->bspFile->numFaces]; 86 87 88 CDEngine::getInstance()->setBSPModel(this); 87 89 88 90 } … … 97 99 this->root = this->bspFile->get_root(); 98 100 this->alreadyVisible = new bool [this->bspFile->numFaces]; 99 101 100 102 CDEngine::getInstance()->setBSPModel(this); 101 103 } 102 104 */ 103 105 106 const void BspManager::tick(float time) 107 { 108 109 } 104 110 const void BspManager::draw() 105 111 { … … 109 115 this->out1 = this->out; 110 116 this->out2 = this->out; 111 if(this->collPlane != NULL) 112 { 113 this->out1.x += this->collPlane->x*5.0; 114 this->out1.y += this->collPlane->y*5.0; 115 this->out1.z += this->collPlane->z*5.0; 116 117 this->out2.x += this->collPlane->x*10.0; 118 this->out2.y += this->collPlane->y*10.0; 119 this->out2.z += this->collPlane->z*10.0; 117 if(this->collPlane != NULL) { 118 this->out1.x += this->collPlane->x*5.0; 119 this->out1.y += this->collPlane->y*5.0; 120 this->out1.z += this->collPlane->z*5.0; 121 122 this->out2.x += this->collPlane->x*10.0; 123 this->out2.y += this->collPlane->y*10.0; 124 this->out2.z += this->collPlane->z*10.0; 120 125 } 121 126 this->drawDebugCube(&this->out1); 122 127 this->drawDebugCube(&this->out2); 128 123 129 */ 130 131 124 132 // Draw Debug Terrain 125 133 /* … … 148 156 149 157 150 // this->viewDir= State::getCameraTarget()->getAbsCoor() - State::getCamera()->getAbsCoor();158 this->viewDir= State::getCamera()->getAbsDirX(); 151 159 float d = (cam.x*viewDir.x + cam.y*viewDir.y + cam.z * viewDir.z); 152 160 … … 157 165 158 166 159 this->cam = State::getCameraTargetNode()->getAbsCoor(); 160 // this->checkCollision(this->root, &this->cam); //!< Test Collision Detection 167 168 // this->checkCollision(this->root, &this->cam); //!< Test Collision Detection 169 170 161 171 this->outputStartsOut = true; 162 172 this->outputAllSolid = false; 163 173 this->outputFraction = 1.0f; 164 165 this->checkCollisionRay(this->root,0.0f,1.0f, &(State::getCameraTargetNode()->getLastAbsCoor()), &this->cam); 166 167 //if(this->outputFraction != 1.0f || this->outputAllSolid ) this->drawDebugCube(&this->cam); 174 this->checkCollision(State::getPlayer()->getPlayable()); 175 168 176 169 177 if ( viscluster < 0 || ((int *)(this->bspFile->header))[35] == 0 ) //!< if (sizeof(Visdata) == 0) … … 172 180 173 181 174 // Iterate through all Leafs public final double readLEDouble()182 // Iterate through all Leafs 175 183 for(int i = 0; i < this->bspFile->numLeafs ; i++ ) 176 184 { … … 179 187 if(curLeaf.cluster<0) continue; 180 188 181 182 189 /** Do Frustum culling and draw 'em all **/ 183 bool inFrustum = true; 184 185 Vector dir; 186 dir.x = State::getCameraNode()->getAbsDirX().x; 187 dir.y = State::getCameraNode()->getAbsDirX().y; 188 dir.z = State::getCameraNode()->getAbsDirX().z; 190 191 Vector dir = State::getCameraNode()->getAbsDirX(); 192 189 193 float dist = dir.x*this->cam.x +dir.y*this->cam.y +dir.z*this->cam.z; 190 194 //if(dist < 0) dist = -dist; … … 192 196 const float dMaxs = dir.x*(float)curLeaf.maxs[0] +dir.y*(float)curLeaf.maxs[1] +dir.z*(float)curLeaf.maxs[2] - dist ; 193 197 194 if(dMins < - 150.0 && dMaxs < -150.0) {198 if(dMins < -300.0 && dMaxs < -300.0) { 195 199 continue; 196 200 } 197 if( (this->cam - Vector(curLeaf.mins[0],curLeaf.mins[1], curLeaf.mins[2])).len() > 3000 && (this->cam - Vector(curLeaf.maxs[0],curLeaf.maxs[1], curLeaf.maxs[2])).len() > 3000) {201 if( (this->cam - Vector(curLeaf.mins[0],curLeaf.mins[1], curLeaf.mins[2])).len() > 2000 && (this->cam - Vector(curLeaf.maxs[0],curLeaf.maxs[1], curLeaf.maxs[2])).len() > 2000) { 198 202 continue; 199 203 } … … 206 210 if (f >=0 && !this->isAlreadyVisible(f)) { 207 211 this->alreadyVisible[f] = true; 208 209 212 addFace(f); // "visibleFaces.append(f)" 210 213 } … … 794 797 // STEP 3: calculate the middle point for the first side 795 798 middleFraction = startFraction + 796 (endFraction - startFraction) * fraction1;799 (endFraction - startFraction) * fraction1; 797 800 798 801 middle.x = start->x + fraction1 * (end->x - start->x); … … 805 808 806 809 else this->checkCollisionRayN(node->right,startFraction, middleFraction, 807 start, &middle );810 start, &middle ); 808 811 809 812 // STEP 5: calculate the middle point for the second side 810 813 middleFraction = startFraction + 811 (endFraction - startFraction) * fraction2;814 (endFraction - startFraction) * fraction2; 812 815 813 816 middle.x = start->x + fraction2 * (end->x - start->x); … … 824 827 825 828 } 829 void BspManager::checkCollisionBox(void) 830 { 831 832 }; 833 834 void BspManager::TraceBox( Vector& inputStart, Vector& inputEnd, 835 Vector& inputMins, Vector& inputMaxs ) 836 { 837 if (inputMins.x == 0 && inputMins.y == 0 && inputMins.z == 0 && 838 inputMaxs.x == 0 && inputMaxs.y == 0 && inputMaxs.z == 0) 839 { // the user called TraceBox, but this is actually a ray 840 //!> FIXME TraceRay( inputStart, inputEnd ); 841 } 842 else 843 { // setup for a box 844 //traceType = TT_BOX; 845 this->traceMins = inputMins; 846 this->traceMaxs = inputMaxs; 847 this->traceExtents.x = -traceMins.x > traceMaxs.x ? 848 -traceMins.x : traceMaxs.x; 849 this->traceExtents.y = -traceMins.y > traceMaxs.y ? 850 -traceMins.y : traceMaxs.y; 851 this->traceExtents.z = -traceMins.z > traceMaxs.z ? 852 -traceMins.z : traceMaxs.z; 853 //!> FIXME Trace( inputStart, inputEnd ); 854 } 855 } 826 856 827 857 void BspManager::checkCollision(WorldEntity* worldEntity) 828 858 { 829 return; 859 830 860 831 861 Vector position = worldEntity->getAbsCoor(); … … 833 863 834 864 Vector forwardDir = worldEntity->getAbsDirX(); 835 forwardDir.x = 2.0*forwardDir.x;836 forwardDir.y = 2.0*forwardDir.y;837 forwardDir.z = 2.0*forwardDir.z;865 forwardDir.x =8.0*forwardDir.x; 866 forwardDir.y =8.0*forwardDir.y; 867 forwardDir.z =8.0*forwardDir.z; 838 868 839 869 Vector upDir = worldEntity->getAbsDirY(); … … 842 872 dest.y += forwardDir.y; 843 873 dest.z += forwardDir.z; 844 Vector out = Vector(-1875.0,-1875.0,-1875.0);874 Vector out = dest; 845 875 if(!worldEntity->isA(CL_PLAYABLE)) { 846 847 876 848 877 … … 855 884 Vector dest1 = position1 + forwardDir; 856 885 Vector dest2 = position2 + forwardDir; 857 dest = position - upDir;886 dest = position - Vector(0.0, 20.0,0.0); 858 887 Vector out1; 859 888 Vector out2; … … 871 900 this->checkCollisionRayN(this->root,0.0f,1.0f, &position2, &dest2 ); 872 901 if(this->outputFraction == 1.0f) out2= dest; 873 else 874 { 902 else { 875 903 collision = true; 876 out2.x = position2.x + (dest2.x -position2.x) * this->outputFraction;877 out2.y = position2.y + (dest2.y -position2.y) * this->outputFraction;878 out2.z = position2.z + (dest2.z - position2.z) * this->outputFraction;904 out2.x = position2.x + (dest2.x -position2.x) * this->outputFraction; 905 out2.y = position2.y + (dest2.y -position2.y) * this->outputFraction; 906 out2.z = position2.z + (dest2.z - position2.z) * this->outputFraction; 879 907 880 908 } … … 882 910 this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest ); 883 911 if(this->outputFraction == 1.0f) out = dest; 884 else 885 { 886 collision = true; 887 out.x = position.x + (dest.x -position.x) * this->outputFraction; 888 out.y = position.y + (dest.y -position.y) * this->outputFraction; 889 out.z = position.z + (dest.z -position.z) * this->outputFraction; 890 891 //Vector out3 = out + Vector(3*this->collPlane->x,3*this->collPlane->y,3*this->collPlane->z); 892 //this->out = out; 893 //this->out1 = out1; 894 //this->out2 = out2; 895 //this->drawDebugCube(&out1); 896 //this->drawDebugCube(&out2); 897 898 //this->drawDebugCube(&out3); 912 else { 913 collision = true; 914 out.x = position.x + (dest.x -position.x) * this->outputFraction; 915 out.y = position.y + (dest.y -position.y) * this->outputFraction; 916 out.z = position.z + (dest.z -position.z) * this->outputFraction; 917 918 Vector out3 = out + Vector(3*this->collPlane->x,3*this->collPlane->y,3*this->collPlane->z); 919 this->out = out; 920 this->out1 = out1; 921 this->out2 = out2; 922 //this->drawDebugCube(&out1); 923 //this->drawDebugCube(&out2); 924 925 //this->drawDebugCube(&out3); 899 926 900 927 } 901 928 902 929 // Return the normal here: Normal's stored in this->collPlane; 903 // if(collision) worldEntity->collidesWithGround(out,out1,out2); 930 931 if(collision) worldEntity->collidesWithGround(out,out1,out2); 904 932 905 933 } … … 938 966 this->drawDebugCube(&this->cam); 939 967 this->drawDebugCube(&next); 940 State::getPlayer()->getPlayable()->setRelCoor(-100,-100,-100);941 State::getPlayer()->getPlayable()->collidesWith(NULL, State::getCameraTargetNode()->getLastAbsCoor());968 // State::getPlayer()->getPlayable()->setRelCoor(-100,-100,-100); 969 //State::getPlayer()->getPlayable()->collidesWith(NULL, State::getCameraTargetNode()->getLastAbsCoor()); 942 970 } 943 971 -
branches/bsp_model/src/lib/graphics/importer/bsp_manager.h
r8186 r8195 52 52 // Functions 53 53 const void draw(); 54 const void tick(float time); 54 55 void draw_debug_face(int Face); 55 56 void draw_face(int Face); … … 57 58 58 59 59 void checkCollision(WorldEntity* worldEntity); 60 void checkCollision(WorldEntity* worldEntity); /*!< WorldEntities use this function to check wheter they collided with the BSPEntity. 61 If a collision has been detected, the collides-function of worldEntity will be called.*/ 60 62 61 63 private: 62 64 // Functions 63 65 BspTreeNode* getLeaf(BspTreeNode* node, Vector* cam) ; //!< Traverses the tree 64 void checkCollision(BspTreeNode* node, Vector* cam); 66 void checkCollision(BspTreeNode* node, Vector* cam); //!< Obsolete. Use this function for debugging only! 65 67 void checkCollisionRay(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end); 66 void checkCollisionRayN(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end); 68 void checkCollisionRayN(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end); 69 void TraceBox( Vector& inputStart, Vector& inputEnd,Vector& inputMins, Vector& inputMaxs ); 70 void checkCollisionBox(void); 67 71 void checkBrushRay(brush* curBrush); 68 72 void checkBrushRayN(brush* curBrush); … … 80 84 int lastTex; 81 85 82 //obsolete 86 //obsolete: global variables for collision detection 83 87 bool outputStartsOut; 84 88 bool outputAllSolid; 85 89 float outputFraction; 90 Vector traceMins; //!< Mins of current bbox 91 Vector traceMaxs; //!< Maxs of current bbox 92 Vector traceExtents; /*!< Stores the maximum of the absolute value of each axis in the box. 93 For example, if traceMins was (-100,-3,-15) and traceMaxs was (55,22,7), traceExtents */ 86 94 95 87 96 bool * alreadyVisible; 88 97 // Deques to store the visible faces … … 90 99 ::std::deque<int> opal; //!< the others here. 91 100 92 Vector out; 93 Vector out1; 94 Vector out2; 101 Vector out; //!< For debugging only 102 Vector out1; //!< For debugging only 103 Vector out2; //!< For debugging only 95 104 }; 96 105
Note: See TracChangeset
for help on using the changeset viewer.