Changeset 8796 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Jun 26, 2006, 3:43:40 PM (19 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/collision_reaction/cr_physics_ground_walk.cc
r8724 r8796 25 25 26 26 #include <vector> 27 28 #include "aabb.h" 27 29 28 30 using namespace std; … … 62 64 // collision->getEntityB()->getAbsCoor().debug(); 63 65 66 Vector height; 67 AABB* box = collision->getEntityB()->getModelAABB(); 68 69 70 71 if(box!=NULL) 72 height = ( ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor() )*(-1.0f) ; 73 else 74 height = ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor() ; 64 75 65 Vector height = ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor(); 66 67 if(ce->getCollisionPosition().x <= 0.9 && ce->getGroundNormal().len() <= 1.4f) { 68 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor()); 69 return; 70 } 71 if(ce->getGroundNormal().len() <= 0.1f) { 72 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor()); 73 return; 74 } 75 if(ce->getGroundNormal().len() >= 1.4f) { 76 downspeed++; 77 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0)); 78 return; 79 } 76 if(box!=NULL) { 80 77 81 78 82 if(height.y < -3.510001 + 10.0) // Above ground 83 { 84 if(height.y > -15.6) // Snap in 85 { 86 downspeed = 0; 87 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,height.y+3.500005 + 10.0,0.0)); 88 } else 89 { 79 if(ce->getCollisionPosition().x <= 0.9 && ce->getGroundNormal().len() <= 1.4f) { 80 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor()); 81 return; 82 } 83 if(ce->getCollisionPosition().z <= 0.9 && ce->getGroundNormal().len() <= 1.4f) { 84 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor()); 85 return; 86 } 87 88 if(ce->getGroundNormal().len() <= 0.1f) { 89 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor()); 90 return; 91 } 92 93 94 if(ce->getGroundNormal().len() >= 1.4f) { 90 95 downspeed++; 91 96 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0)); 97 return; 92 98 } 93 99 94 } 95 else { 96 if(height.y > -3.50000 + 10.0 && height.y < 9.9+ 10.0) // below ground 100 101 if(height.y > box->halfLength[1] + 0.0f ) // Above ground 97 102 { 98 //if(downspeed <= 0) downspeed =1; 99 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0, 0.00001 /*height.y+3.500005 + 10.0*/,0.0)); 100 //collision->getEntityB()->setVelocity(Vector(0.0,0.0,0.0)); 101 downspeed = 0; 103 if(height.y < box->halfLength[1] + 1.3f) // Snap in 104 { 105 downspeed = 0; 106 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() - Vector(0.0,height.y - box->halfLength[1] - 0.0f,0.0)); 107 } else 108 { 109 downspeed++; 110 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0)); 111 } 112 113 } 114 else { 115 if(height.y < box->halfLength[1] + 0.0f /* && height.y > - 55.0f*/) // below ground 116 { 117 //if(downspeed <= 0) downspeed =1; 118 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0, -height.y + box->halfLength[1] + 2.0f/* 0.00001 *//*height.y+3.500005 + 10.0*/,0.0)); 119 //collision->getEntityB()->setVelocity(Vector(0.0,0.0,0.0)); 120 downspeed = 0; 121 } 122 102 123 } 103 124 104 } 105 106 125 }// if(box!= NULL) 107 126 /* 108 127 PRINTF(0)("Collision with Ground: \n"); -
trunk/src/lib/graphics/importer/bsp_manager.cc
r8724 r8796 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/ … … 44 44 #include "util/loading/factory.h" 45 45 46 #include "aabb.h" 47 46 48 47 49 … … 67 69 BspManager::BspManager(const TiXmlElement* root) 68 70 { 69 70 71 72 71 73 if( root != NULL) 72 74 this->loadParams(root); 73 75 74 76 CDEngine::getInstance()->setBSPModel(this); 75 77 } */ … … 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 } … … 105 107 { 106 108 107 if(!this->bspFile->MovieMaterials.empty()) 108 { 109 ::std::vector<MoviePlayer *>::iterator it = this->bspFile->MovieMaterials.begin() ; 110 while(it != this->bspFile->MovieMaterials.end()) 111 { 112 (*it)->tick(time); 113 it++; 114 } 115 //this->bspFile->MovieMaterials.front()->tick(time ); 109 if(!this->bspFile->MovieMaterials.empty()) { 110 ::std::vector<MoviePlayer *>::iterator it = this->bspFile->MovieMaterials.begin() ; 111 while(it != this->bspFile->MovieMaterials.end()) { 112 (*it)->tick(time); 113 it++; 114 } 115 //this->bspFile->MovieMaterials.front()->tick(time ); 116 116 117 117 … … 177 177 178 178 179 // this->checkCollision(this->root, &this->cam); //!< Test Collision Detection179 // this->checkCollision(this->root, &this->cam); //!< Test Collision Detection 180 180 181 181 … … 314 314 return; 315 315 } 316 // if(curFace.type != 1) return;316 // if(curFace.type != 1) return; 317 317 if((char*)(this->bspFile->textures)[curFace.texture*72]== 0) return; 318 318 319 319 if(this->lastTex != curFace.texture) { 320 320 if(this->bspFile->Materials[curFace.texture].animated) { 321 // glBlendFunc(GL_ZERO,GL_ONE);321 // glBlendFunc(GL_ZERO,GL_ONE); 322 322 323 323 … … 342 342 glEnable(GL_TEXTURE_2D); 343 343 } else { 344 // glEnable(GL_BLEND);344 // glEnable(GL_BLEND); 345 345 //glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); 346 346 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); … … 348 348 glBindTexture(GL_TEXTURE_2D, this->bspFile->glLightMapTextures[curFace.lm_index]); 349 349 glEnable(GL_TEXTURE_2D); 350 // glDisable(GL_BLEND);350 // glDisable(GL_BLEND); 351 351 } 352 352 … … 596 596 bool endsOut = false; 597 597 598 // Vector inputStart = State::getCameraTargetNode()->getLastAbsCoor();599 // Vector inputEnd = State::getCameraTargetNode()->getAbsCoor();598 // Vector inputStart = State::getCameraTargetNode()->getLastAbsCoor(); 599 // Vector inputEnd = State::getCameraTargetNode()->getAbsCoor(); 600 600 601 601 for (int i = 0; i < curBrush->n_brushsides; i++) { … … 840 840 this->checkBrushRayN(&curBrush); 841 841 if(curBrush.n_brushsides <=0) this->outputAllSolid = true; 842 } 843 842 } 843 844 844 return; 845 845 } … … 912 912 { 913 913 leaf& curLeaf = this->bspFile->leaves[node->leafIndex]; 914 for(int i = 0; i < curLeaf.n_leaffaces ; i++) 915 { 916 914 for(int i = 0; i < curLeaf.n_leaffaces ; i++) { 917 915 } 918 916 return 10.0f; … … 921 919 void BspManager::checkCollisionBox(void) 922 920 { 923 924 };921 } 922 ; 925 923 926 924 void BspManager::TraceBox( Vector& inputStart, Vector& inputEnd, 927 Vector& inputMins, Vector& inputMaxs )925 Vector& inputMins, Vector& inputMaxs ) 928 926 { 929 927 if (inputMins.x == 0 && inputMins.y == 0 && inputMins.z == 0 && 930 inputMaxs.x == 0 && inputMaxs.y == 0 && inputMaxs.z == 0) 931 { // the user called TraceBox, but this is actually a ray 932 //!> FIXME TraceRay( inputStart, inputEnd ); 933 } 934 else 935 { // setup for a box 928 inputMaxs.x == 0 && inputMaxs.y == 0 && inputMaxs.z == 0) { // the user called TraceBox, but this is actually a ray 929 //!> FIXME TraceRay( inputStart, inputEnd ); 930 } else { // setup for a box 936 931 //traceType = TT_BOX; 937 932 this->traceMins = inputMins; 938 933 this->traceMaxs = inputMaxs; 939 934 this->traceExtents.x = -traceMins.x > traceMaxs.x ? 940 -traceMins.x : traceMaxs.x;935 -traceMins.x : traceMaxs.x; 941 936 this->traceExtents.y = -traceMins.y > traceMaxs.y ? 942 -traceMins.y : traceMaxs.y;937 -traceMins.y : traceMaxs.y; 943 938 this->traceExtents.z = -traceMins.z > traceMaxs.z ? 944 -traceMins.z : traceMaxs.z;945 //!> FIXME Trace( inputStart, inputEnd );939 -traceMins.z : traceMaxs.z; 940 //!> FIXME Trace( inputStart, inputEnd ); 946 941 } 947 942 } … … 950 945 { 951 946 947 // Init Collision Detection 952 948 this->outputStartsOut = true; 953 949 this->outputAllSolid = false; 954 950 this->outputFraction = 1.0f; 955 951 956 952 // Retrieve Bounding box 953 AABB* box = worldEntity->getModelAABB(); 957 954 958 955 … … 965 962 upDir.z = 0.0; 966 963 Vector dest; 967 /* 968 dest.x += forwardDir.x; 969 dest.y += forwardDir.y; 970 dest.z += forwardDir.z; 971 */ 972 Vector position = worldEntity->getAbsCoor() + upDir*10.0f ; 964 965 966 Vector position = worldEntity->getAbsCoor(); //+ upDir*10.0f ; 973 967 dest = worldEntity->getAbsCoor() - upDir*40.0f; // 974 968 Vector out = dest; 975 969 976 970 977 978 979 971 bool collision = false; 980 Vector position1 = position; // + Vector(0.0,0.6,0.0);972 Vector position1 = position; 981 973 Vector position2 = position + Vector(0.0,1.0,0.0); 982 974 Vector dest1 = position + forwardDir*4.0f; … … 986 978 Vector out2; 987 979 980 988 981 989 982 float height = 40; 990 983 984 985 if( box != NULL) 986 { 987 position = worldEntity->getAbsCoor() + box->center; // + box->axis[1] * box->halfLength[1]; 988 dest = worldEntity->getAbsCoor() + box->center - box->axis[1] * box->halfLength[1] * 40.0; 989 990 position1 = worldEntity->getAbsCoor() + box->center + box->axis[0] * box->halfLength[0] * 2.0f; 991 dest1 = worldEntity->getAbsCoor() + box->center - box->axis[0] * box->halfLength[0] *2.0f; 992 993 994 position2 = worldEntity->getAbsCoor() + box->center + box->axis[2] * box->halfLength[2] * 2.0f; 995 dest2 = worldEntity->getAbsCoor() + box->center - box->axis[2] * box->halfLength[2] * 2.0f; 996 997 } 998 else 999 { 1000 1001 } 1002 1003 1004 1005 // 991 1006 this->inputStart = position; 992 1007 this->inputEnd = dest; 993 1008 this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest ); 994 995 996 997 // PRINTF(0)(" checking collision: %s, solid = %i, fraction = %f\n", worldEntity->getClassName(), this->outputAllSolid, this->outputFraction); 998 // PRINTF(0)("checking collision!! Pos.Coords: %f , %f , %f\n", position.x , position.y, position.z); 999 // PRINTF(0)("checking collision!! Dest.Coords: %f , %f , %f\n", dest.x , dest.y, dest.z); 1000 1001 // position1.debug(); 1002 1003 if(!this->outputStartsOut ) 1004 { 1009 1010 1011 // 1012 if(!this->outputStartsOut ) { 1005 1013 this->collPlane = new plane; 1006 1014 this->collPlane->x = 0.0f; … … 1008 1016 this->collPlane->z = 0.0f; 1009 1017 collision = true; 1010 } 1011 else 1012 { 1013 1014 1015 1016 1017 if( this->outputFraction == 1.0f) 1018 { 1019 if(this->outputAllSolid ) 1020 { 1021 this->collPlane = new plane; 1022 this->collPlane->x = 0.0f; 1023 this->collPlane->y = 0.0f; 1024 this->collPlane->z = 0.0f; 1018 } else { 1019 1020 if( this->outputFraction == 1.0f) { 1021 if(this->outputAllSolid ) { 1022 this->collPlane = new plane; 1023 this->collPlane->x = 0.0f; 1024 this->collPlane->y = 0.0f; 1025 this->collPlane->z = 0.0f; 1026 collision = true; 1027 } else 1028 collision = false; 1029 1030 1031 out = dest; 1032 1033 } else { 1025 1034 collision = true; 1026 } 1027 else 1028 collision = false; 1029 1030 1031 out = dest; 1032 } 1033 else { 1034 1035 collision = true; 1036 out.x = position.x + (dest.x -position.x) * this->outputFraction; 1037 out.y = position.y + (dest.y -position.y) * this->outputFraction; 1038 out.z = position.z + (dest.z -position.z) * this->outputFraction; 1039 1040 Vector out3 = out + Vector(height*this->collPlane->x,height*this->collPlane->y,height*this->collPlane->z); 1041 this->out = out; 1042 } 1043 1044 1045 } 1035 out.x = position.x + (dest.x -position.x) * this->outputFraction; 1036 out.y = position.y + (dest.y -position.y) * this->outputFraction; 1037 out.z = position.z + (dest.z -position.z) * this->outputFraction; 1038 1039 Vector out3 = out + Vector(height*this->collPlane->x,height*this->collPlane->y,height*this->collPlane->z); 1040 this->out = out; 1041 } 1042 1043 1044 } 1045 1046 plane* testPlane = this->collPlane; 1047 1046 1048 1047 plane* testPlane = this->collPlane; 1048 1049 // 2nd Collision Detection 1049 1050 this->outputStartsOut = true; 1050 1051 this->outputAllSolid = false; 1051 1052 this->outputFraction = 1.0f; 1052 this->inputStart = position ;1053 this->inputStart = position1; 1053 1054 this->inputEnd = dest1; 1054 this->checkCollisionRayN(this->root,0.0f,1.0f, &position , &dest1 );1055 this->checkCollisionRayN(this->root,0.0f,1.0f, &position1, &dest1 ); 1055 1056 out.x = this->outputFraction; 1057 //out.z = this->outputFraction; 1058 1059 1060 // 3rd Collision Detection 1061 this->outputStartsOut = true; 1062 this->outputAllSolid = false; 1063 this->outputFraction = 1.0f; 1064 this->inputStart = position2; 1065 this->inputEnd = dest2; 1066 this->checkCollisionRayN(this->root,0.0f,1.0f, &position2, &dest2 ); 1067 //out.x = this->outputFraction; 1056 1068 out.z = this->outputFraction; 1057 1069 1070 1058 1071 /* 1072 This is how you would calculate the Coordinates where worldEntity Collided with the BSP world. 1059 1073 out.x = position1.x + (dest.x -position1.x) * this->outputFraction; 1060 1061 1074 out.z = position1.z + (dest.z -position1.z) * this->outputFraction; 1062 1075 */ 1063 1064 1076 1077 1065 1078 // Return the normal here: Normal's stored in this->collPlane; 1066 if( collision) { 1079 if( collision) 1080 { 1067 1081 PRINTF(5)("We got a collision!! Are you sure: outputFraction = %f\n", this->outputFraction); 1068 1082 worldEntity->registerCollision(this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out); 1069 } 1083 } 1070 1084 else worldEntity->registerCollision(this->parent, worldEntity, Vector(0.0, 2.0, 0.0), dest); 1071 1085 … … 1104 1118 this->drawDebugCube(&this->cam); 1105 1119 this->drawDebugCube(&next); 1106 // State::getPlayer()->getPlayable()->setRelCoor(-100,-100,-100);1120 // State::getPlayer()->getPlayable()->setRelCoor(-100,-100,-100); 1107 1121 //State::getPlayer()->getPlayable()->collidesWith(NULL, State::getCameraTargetNode()->getLastAbsCoor()); 1108 1122 }
Note: See TracChangeset
for help on using the changeset viewer.