- Timestamp:
- Jun 22, 2006, 1:40:09 PM (18 years ago)
- Location:
- branches/bsp_model/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/bsp_model/src/lib/collision_reaction/cr_physics_ground_walk.cc
r8699 r8714 1 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 4 4 Copyright (C) 2004 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: Patrick Boenzli … … 24 24 #include "cr_physics_ground_walk.h" 25 25 26 #include "aabb.h"27 28 #include "debug.h"29 30 26 #include <vector> 31 27 … … 37 33 */ 38 34 CRPhysicsGroundWalk::CRPhysicsGroundWalk () 39 : CollisionReaction()35 : CollisionReaction() 40 36 { 41 37 this->setClassID(CL_CR_PHYSICS_GROUND_WALK, "CRPhysicsGroundWalk"); … … 47 43 */ 48 44 CRPhysicsGroundWalk::~CRPhysicsGroundWalk () 49 { 50 } 45 {} 51 46 52 47 … … 59 54 CollisionEvent* ce = collision->getCollisionEvents().front(); 60 55 Vector normal = ce->getGroundNormal(); 56 // normal.normalize(); 61 57 62 AABB* box = ce->getEntityB()->getModelAABB(); 58 // put it back 59 // PRINTF(0)("putting it back to lastPos: \n"); 60 // this->lastPositions[0].debug(); 61 // PRINTF(0)("current pos:\n"); 62 // collision->getEntityB()->getAbsCoor().debug(); 63 63 64 Vector center = ce->getEntityB()->getAbsCoor() /*+ box->center*/;65 Vector collisionPos = ce->getCollisionPosition() - center;66 64 67 float objSize = box->halfLength[1];65 Vector height = ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor(); 68 66 69 if( normal.len() <= 0.1f) 70 { 67 if(ce->getCollisionPosition().x <= 0.9 && ce->getGroundNormal().len() <= 1.4f) { 71 68 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor()); 72 69 return; 73 70 } 74 75 if( collisionPos.y <= -(objSize + 0.1f)) 76 { 71 if(ce->getGroundNormal().len() <= 0.1f) { 72 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor()); 73 return; 74 } 75 if(ce->getGroundNormal().len() >= 1.4f) { 77 76 downspeed++; 78 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0, -0.03 * downspeed, 0.0)); 79 } 80 else 81 { 82 if( collisionPos.y > -objSize && 83 collisionPos.y < (objSize + 0.4)) 84 { 85 //if(downspeed <= 0) downspeed =1; 86 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + 87 Vector(0.0, collisionPos.y + objSize + 0.1, 0.0)); 88 } 89 downspeed = 0; 77 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0)); 78 return; 90 79 } 91 80 92 81 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 { 90 downspeed++; 91 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0)); 92 } 93 94 } 95 else { 96 if(height.y > -3.50000 + 10.0 && height.y < 9.9+ 10.0) // below ground 97 { 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; 102 } 103 104 } 105 106 107 /* 108 PRINTF(0)("Collision with Ground: \n"); 109 collision->getEntityB()->getAbsCoor().debug(); 110 collision->getEntityB()->setVelocity(Vector()); 111 collision->getEntityB()->setAbsCoor(this->lastPositions[1]); 112 113 */ 93 114 } 94 115 … … 103 124 for( int i = 9; i > 0; i--) { 104 125 this->lastPositions[i] = this->lastPositions[i-1]; 105 // PRINTF(0)("lastPosition[%i]: %f, %f, %f\n", i, lastPositions[i].x, lastPositions[i].y, lastPositions[i].z);126 // PRINTF(0)("lastPosition[%i]: %f, %f, %f\n", i, lastPositions[i].x, lastPositions[i].y, lastPositions[i].z); 106 127 } 107 128 this->lastPositions[0] = owner->getAbsCoor(); -
branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc
r8699 r8714 41 41 #include "world_entity.h" 42 42 43 #include "aabb.h"44 45 43 #include "util/loading/load_param.h" 46 44 #include "util/loading/factory.h" … … 842 840 this->checkBrushRayN(&curBrush); 843 841 if(curBrush.n_brushsides <=0) this->outputAllSolid = true; 844 } 842 } 843 845 844 return; 846 845 } … … 909 908 910 909 } 910 911 float BspManager::checkPatchAltitude(BspTreeNode* node) 912 { 913 leaf& curLeaf = this->bspFile->leaves[node->leafIndex]; 914 for(int i = 0; i < curLeaf.n_leaffaces ; i++) 915 { 916 917 } 918 return 10.0f; 919 } 920 911 921 void BspManager::checkCollisionBox(void) 912 922 { … … 944 954 this->outputFraction = 1.0f; 945 955 946 AABB* box = worldEntity->getModelAABB(); 947 948 949 Vector forwardDir; 950 Vector upDir; 956 957 958 959 Vector forwardDir = worldEntity->getAbsDirX(); 960 961 962 Vector upDir = worldEntity->getAbsDirY(); 963 upDir.x = 0.0; 964 upDir.y = 1.0; 965 upDir.z = 0.0; 951 966 Vector dest; 952 Vector position; 953 Vector out; 954 float height; 955 956 if( box != NULL) 957 { 958 forwardDir = worldEntity->getAbsDirX(); 959 forwardDir = forwardDir * box->halfLength[0]; 960 961 upDir = Vector(0,1,0) * box->halfLength[1]; 962 963 position = worldEntity->getAbsCoor() + box->center + box->axis[1] * box->halfLength[1]; 964 dest = worldEntity->getAbsCoor() + box->center - box->axis[1] * box->halfLength[1]; 965 out = dest; 966 967 height = box->halfLength[1]; 968 } 969 else 970 { 971 forwardDir = worldEntity->getAbsDirX(); 972 forwardDir = forwardDir * 8.0f; 973 974 upDir = worldEntity->getAbsDirY(); 975 upDir.x = 0.0; 976 upDir.y = 1.0; 977 upDir.z = 0.0; 978 dest; 979 980 position = worldEntity->getAbsCoor() + upDir*5.0f; 981 dest = worldEntity->getAbsCoor() - upDir*40.0f; // 982 out = dest; 983 984 height = 40; 985 } 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 ; 973 dest = worldEntity->getAbsCoor() - upDir*40.0f; // 974 Vector out = dest; 986 975 987 976 … … 989 978 990 979 bool collision = false; 991 Vector position1 = position + Vector(0.0,0.1,0.0);992 Vector position2 = position + Vector(0.0, 0.2,0.0);993 Vector dest1 = position 1 + forwardDir;980 Vector position1 = position; // + Vector(0.0,0.6,0.0); 981 Vector position2 = position + Vector(0.0,1.0,0.0); 982 Vector dest1 = position + forwardDir*4.0f; 994 983 Vector dest2 = position2 + forwardDir; 995 //dest = position - Vector(0.0, 40.0,0.0);984 dest = position - Vector(0.0, 40.0,0.0); 996 985 Vector out1; 997 986 Vector out2; 998 987 999 988 1000 989 float height = 40; 1001 990 1002 991 this->inputStart = position; 1003 992 this->inputEnd = dest; 1004 993 this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest ); 994 995 1005 996 1006 997 // PRINTF(0)(" checking collision: %s, solid = %i, fraction = %f\n", worldEntity->getClassName(), this->outputAllSolid, this->outputFraction); 1007 998 // PRINTF(0)("checking collision!! Pos.Coords: %f , %f , %f\n", position.x , position.y, position.z); 1008 999 // PRINTF(0)("checking collision!! Dest.Coords: %f , %f , %f\n", dest.x , dest.y, dest.z); 1000 1009 1001 // position1.debug(); 1010 1002 … … 1052 1044 1053 1045 } 1046 1047 plane* testPlane = this->collPlane; 1048 1049 this->outputStartsOut = true; 1050 this->outputAllSolid = false; 1051 this->outputFraction = 1.0f; 1052 this->inputStart = position; 1053 this->inputEnd = dest1; 1054 this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest1 ); 1055 out.x = this->outputFraction; 1056 out.z = this->outputFraction; 1057 1058 /* 1059 out.x = position1.x + (dest.x -position1.x) * this->outputFraction; 1060 1061 out.z = position1.z + (dest.z -position1.z) * this->outputFraction; 1062 */ 1063 1064 1054 1065 // Return the normal here: Normal's stored in this->collPlane; 1055 1066 if( collision) { 1056 1067 PRINTF(5)("We got a collision!! Are you sure: outputFraction = %f\n", this->outputFraction); 1057 worldEntity->registerCollision(this->parent, worldEntity, Vector(t his->collPlane->x, this->collPlane->y, this->collPlane->z), out);1058 } 1059 else worldEntity->registerCollision(this->parent, worldEntity, Vector(0.0, 1.0, 0.0), dest);1068 worldEntity->registerCollision(this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out); 1069 } 1070 else worldEntity->registerCollision(this->parent, worldEntity, Vector(0.0, 2.0, 0.0), dest); 1060 1071 1061 1072 } -
branches/bsp_model/src/lib/graphics/importer/bsp_manager.h
r8490 r8714 73 73 void checkCollisionRay(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end); 74 74 void checkCollisionRayN(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end); 75 void TraceBox( Vector& inputStart, Vector& inputEnd,Vector& inputMins, Vector& inputMaxs );75 void TraceBox( Vector& inputStart, Vector& inputEnd,Vector& inputMins, Vector& inputMaxs ); 76 76 void checkCollisionBox(void); 77 77 void checkBrushRay(brush* curBrush); 78 78 void checkBrushRayN(brush* curBrush); 79 void checkBrushRayN(brush* curBrush, Vector& inputStart, Vector& inputEnd); 79 void checkBrushRayN(brush* curBrush, Vector& inputStart, Vector& inputEnd); 80 float checkPatchAltitude(BspTreeNode* node); //! To be implemented... 80 81 81 82 void drawDebugCube(Vector* cam); -
branches/bsp_model/src/story_entities/game_world.cc
r8490 r8714 300 300 this->tick (); 301 301 302 303 /* update the state */ 304 this->update (); 305 306 302 307 /* collision detection */ 303 308 this->collisionDetection (); … … 305 310 this->collisionReaction (); 306 311 312 /* check the game rules */ 313 this->checkGameRules(); 314 307 315 /* update the state */ 308 316 this->update (); 309 310 /* check the game rules */311 this->checkGameRules();312 317 /* draw everything */ 313 318 this->display (); -
branches/bsp_model/src/world_entities/creatures/md2_creature.cc
r8685 r8714 112 112 this->cameraConnNode.addChild(State::getCameraNode()); 113 113 State::getCameraTargetNode()->setRelCoor(10,0,0); 114 114 115 115 116 … … 171 172 dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false); 172 173 173 this->getWeaponManager().getFixedTarget()->setRelCoor( 10,0,0);174 this->getWeaponManager().getFixedTarget()->setRelCoor(0,0,0); 174 175 175 176 } … … 190 191 dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true); 191 192 192 State::getCameraNode()->setParent Soft(&this->cameraConnNode);193 State::getCameraNode()->setRelCoor Soft(-10, 0,0);193 State::getCameraNode()->setParent(&this->cameraConnNode); 194 State::getCameraNode()->setRelCoor(0, 0,0); 194 195 State::getCameraTargetNode()->setParentSoft(&this->cameraConnNode); 195 196 … … 281 282 // this->cameraConnNode.setRelDir(mouseDirY); 282 283 284 this->cameraConnNode.setRelDir(mouseDirY); 283 285 this->setAbsDir(this->mouseDirX); 284 286 } … … 343 345 } 344 346 345 velocity = accel * 20.0f;347 velocity = accel * 40.0f; 346 348 //rot.normalize(); 347 349 //this->setRelDirSoft(Quaternion(rotVal, rot), 5); -
branches/bsp_model/src/world_entities/playable.cc
r8686 r8714 65 65 66 66 this->bDead = false; 67 68 this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY); 67 69 68 70 registerVar( new SynchronizeableInt( &score, &score, "score" ) );
Note: See TracChangeset
for help on using the changeset viewer.