- Timestamp:
- Jul 2, 2006, 1:36:13 PM (18 years ago)
- Location:
- trunk/src
- Files:
-
- 2 deleted
- 30 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/defs/class_id.h
r8973 r9003 188 188 CL_SKYDOME = 0x00000313, 189 189 CL_DOOR = 0x00000314, 190 CL_REPAIR_STATION = 0x00000315, 191 CL_CRANE = 0x00000316, 192 CL_BRAKING_WALL = 0X00000317, 190 193 191 194 // Playables -
trunk/src/lib/collision_reaction/cr_physics_ground_walk.cc
r8894 r9003 23 23 #include "world_entity.h" 24 24 #include "cr_physics_ground_walk.h" 25 #include "collision_reaction.h" 25 26 26 27 #include <vector> … … 58 59 void CRPhysicsGroundWalk::reactToCollision(Collision* collision) 59 60 { 60 CollisionEvent* ce = collision->getCollisionEvents().front(); 61 Vector normal = ce->getGroundNormal(); 62 // normal.normalize(); 63 64 // put it back 65 // PRINTF(0)("putting it back to lastPos: \n"); 66 // this->lastPositions[0].debug(); 67 // PRINTF(0)("current pos:\n"); 68 // collision->getEntityB()->getAbsCoor().debug(); 69 70 float height; 61 71 62 AABB* box = collision->getEntityB()->getModelAABB(); 72 63 WorldEntity* entity = collision->getEntityB(); 73 74 // collision position maths75 Vector collPos = collision->getEntityB()->getAbsCoor() + box->center - ce->getCollisionPosition();76 77 float CR_MAX_WALK_HEIGHT = 2.0f;78 float CR_THRESHOLD = 0.2f;79 64 80 65 if( box == NULL) … … 85 70 86 71 87 switch( ce->getType()) 72 float CR_MAX_WALK_HEIGHT = 2.0f; 73 float CR_THRESHOLD = 0.2f; 74 75 float height = 0; 76 float front = 0; 77 float side = 0; 78 79 //PRINTF(0)("collision raction======================================\n"); 80 81 const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents()); 82 std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin(); 83 for(; it != collisionEvents->end(); it++) 88 84 { 89 case COLLISION_TYPE_AXIS_Y: 90 91 height = collPos.y - box->halfLength[1]; 92 // PRINTF(0)("height: %f , model height: %f\n", height, box->halfLength[1]); 93 // PRINTF(0)(" ground normal: %f, %f, %f\n", normal.x, normal.y, normal.z); 94 95 // object is beneath the plane (ground) 96 if( height <= 0.0f ) 97 { 98 entity->shiftCoor(Vector(0, -height, 0)); 99 } 100 // object is already in the wall 101 else if( ce->isInWall()) 102 { 103 entity->setAbsCoor(entity->getLastAbsCoor()); 104 } 105 break; 106 107 108 case COLLISION_TYPE_AXIS_X: 109 case COLLISION_TYPE_AXIS_Z: 110 break; 111 112 } 113 114 85 86 CollisionEvent* ce = (*it); 87 Vector normal = ce->getGroundNormal(); 88 89 // calculate the collision position 90 Vector collPos = collision->getEntityB()->getAbsCoor() + box->center - ce->getCollisionPosition(); 91 92 // test the 3 axis differently 93 switch( ce->getType()) 94 { 95 // collision in the x-axis 96 case COLLISION_TYPE_AXIS_X: 97 front = collPos.x - box->halfLength[0]; // should be [0] 98 99 // object is beneath the plane (ground) 100 if( front <= 0.0f ) 101 { 102 Vector backoff = entity->getAbsDirX() * front; 103 // entity->shiftCoor(backoff); 104 } 105 // object is already in the wall 106 else if( ce->isInWall()) 107 { 108 // entity->setAbsCoor(entity->getLastAbsCoor()); 109 } 110 break; 111 112 113 // collision in the y-axis 114 case COLLISION_TYPE_AXIS_Y: 115 // calulate the height above ground 116 height = collPos.y - box->halfLength[1]; 117 118 119 // object is beneath the plane (ground) 120 if( height <= 0.0f ) 121 { 122 entity->shiftCoor(Vector(0.0f, -height, 0.0f)); 123 entity->setOnGround(true); 124 } 125 // object is already in the wall 126 else if( ce->isInWall()) 127 { 128 entity->setAbsCoor(entity->getLastAbsCoor()); 129 } 130 else 131 { 132 // entity is not on ground 133 entity->setOnGround(false); 134 } 135 break; 136 137 138 // collision in the z-axis 139 case COLLISION_TYPE_AXIS_Z: 140 141 side = collPos.z - box->halfLength[2]; // should be [2] 142 143 // object is beneath the plane (ground) 144 if( side <= 0.0f ) 145 { 146 Vector backoff = entity->getAbsDirX() * side; 147 // entity->shiftCoor(backoff); 148 } 149 // object is already in the wall 150 else if( ce->isInWall()) 151 { 152 // entity->setAbsCoor(entity->getLastAbsCoor()); 153 } 154 break; 155 } 156 } 157 //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side); 115 158 116 159 … … 126 169 127 170 128 if( box != NULL) { 129 130 131 if(ce->getCollisionPosition().x <= 0.9 && ce->getGroundNormal().len() <= 1.4f) { 171 if( box != NULL) 172 { 173 174 175 if(ce->getCollisionPosition().x <= 0.9 && ce->getGroundNormal().len() <= 1.4f) 176 { 132 177 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor()); 133 178 return; 134 179 } 135 if(ce->getCollisionPosition().z <= 0.9 && ce->getGroundNormal().len() <= 1.4f) { 180 if(ce->getCollisionPosition().z <= 0.9 && ce->getGroundNormal().len() <= 1.4f) 181 { 136 182 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor()); 137 183 return; 138 184 } 139 185 140 if(ce->getGroundNormal().len() <= 0.1f) { 186 if(ce->getGroundNormal().len() <= 0.1f) 187 { 141 188 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor()); 142 189 return; … … 144 191 145 192 146 if(ce->getGroundNormal().len() >= 1.4f) { 193 if(ce->getGroundNormal().len() >= 1.4f) 194 { 147 195 downspeed++; 148 196 collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0)); … … 164 212 165 213 } 166 else { 214 else 215 { 167 216 if(height.y < box->halfLength[1] + 0.0f /* && height.y > - 55.0f*/) // below ground 168 217 { … … 194 243 */ 195 244 void CRPhysicsGroundWalk::update(WorldEntity* owner) 196 { 197 198 } 199 200 245 {} 246 247 -
trunk/src/lib/graphics/importer/bsp_file.cc
r8894 r9003 46 46 BspFile::BspFile() 47 47 {} 48 49 BspFile::~ BspFile() 50 { 51 delete [] nodes; 52 delete [] leaves; 53 delete [] planes; 54 delete [] bspModels; 55 delete [] leafFaces; 56 delete [] faces; 57 delete [] leafBrushes; 58 delete [] brushes; 59 delete [] brushSides; 60 delete [] vertice; 61 delete [] meshverts; 62 delete [] visData; 63 delete [] textures; 64 delete [] patchVertice; 65 delete [] patchIndexes; 66 // delete [] patchTrianglesPerRow; 67 delete [] lightMaps; 68 69 for(int i = 0; i < this->numPatches; ++i) delete this->VertexArrayModels[i]; 70 // delete [] VertexArrayModels; 71 72 for(int i = 0; i < this->numTextures; ++i) 73 { 74 delete this->Materials[i].mat; 75 //delete this->Materials[i].aviMat; 76 } 77 delete [] this->Materials; 78 //delete [] testSurf; 79 80 81 82 } 48 83 49 84 /** … … 294 329 this->patchVertice = new char[8*8*44*(this->numPatches+10)]; 295 330 this->patchIndexes = new char[7*8*2*4*(this->numPatches+10)]; 296 this->patchRowIndexes = new int*[7*4*this->numPatches];331 // this->patchRowIndexes = new int*[7*4*this->numPatches]; Not needed? 297 332 this->patchTrianglesPerRow = new char[7*4*this->numPatches]; 298 333 this->VertexArrayModels = new VertexArrayModel*[this->numPatches]; … … 464 499 465 500 if(File(absFileName).exists()) { 466 PRINTF( 0)("BSP FILE: gefunden . \n");501 PRINTF(4)("BSP FILE: gefunden . \n"); 467 502 this->Materials[i] = this->loadAVI(fileName); 468 503 continue; … … 553 588 } 554 589 555 PRINTF(0)("BSP FILE: Textur %s nicht gefunden . \n", &this->textures[8+72*i]);590 PRINTF(0)("BSP FILE: Texture %s not found.",&this->textures[8+ 72*i] ); 556 591 // Default Material 557 592 this->Materials[i].mat = new Material(); … … 1012 1047 Face->meshvert = patchOffset -sz; //3*(patchOffset-sz)*level1*level1; 1013 1048 Face->n_meshverts = sz; 1014 PRINTF( 4)("BSP FILE: sz: %i. \n", sz);1015 PRINTF( 4)("BSP FILE: Face->meshvert %i . \n", Face->meshvert);1049 PRINTF(0)("BSP FILE: sz: %i. \n", sz); 1050 PRINTF(0)("BSP FILE: Face->meshvert %i . \n", Face->meshvert); 1016 1051 1017 1052 //Face->n_meshverts = sz; -
trunk/src/lib/graphics/importer/bsp_file.h
r8490 r9003 151 151 public: 152 152 BspFile(); 153 ~BspFile(); 153 154 int read(const char* name ); 154 155 void build_tree(); … … 183 184 184 185 int** patchRowIndexes; 185 VertexArrayModel** VertexArrayModels; 186 VertexArrayModel** VertexArrayModels; 186 187 int patchOffset; 187 188 -
trunk/src/lib/graphics/importer/bsp_manager.cc
r8894 r9003 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/ … … 69 69 BspManager::BspManager(const TiXmlElement* root) 70 70 { 71 72 71 72 73 73 if( root != NULL) 74 74 this->loadParams(root); 75 75 76 76 CDEngine::getInstance()->setBSPModel(this); 77 77 } */ 78 78 79 void BspManager::load(const char* fileName, float scale) 79 BspManager::~BspManager() 80 { 81 if(this->bspFile) 82 delete this->bspFile; 83 } 84 85 int BspManager::load(const char* fileName, float scale) 80 86 { 81 87 // open a BSP file 88 89 82 90 this->bspFile = new BspFile(); 83 91 this->bspFile->scale = scale; 84 this->bspFile->read(ResourceManager::getFullName(fileName).c_str()); 92 if(this->bspFile->read(ResourceManager::getFullName(fileName).c_str()) == -1) 93 return -1; 94 85 95 this->bspFile->build_tree(); 86 96 this->root = this->bspFile->get_root(); … … 88 98 89 99 this->outputFraction = 1.0f; 100 101 return 0; 90 102 } 91 103 /* … … 99 111 this->root = this->bspFile->get_root(); 100 112 this->alreadyVisible = new bool [this->bspFile->numFaces]; 101 113 102 114 CDEngine::getInstance()->setBSPModel(this); 103 115 } … … 962 974 Vector dest = worldEntity->getAbsCoor() - upDir*40.0f; // 963 975 Vector dest1 = position + forwardDir*4.0f; 964 Vector dest2 = position2 + forwardDir ;976 Vector dest2 = position2 + forwardDir*4.0; 965 977 dest = position - Vector(0.0, 40.0,0.0); 966 978 Vector out = dest; … … 974 986 975 987 if( box != NULL) { 976 position = worldEntity->getAbsCoor() + box->center; // + box->axis[1] * box->halfLength[1]; 977 dest = worldEntity->getAbsCoor() + box->center - box->axis[1] * box->halfLength[1] * 40.0; 978 979 position1 = worldEntity->getAbsCoor() + box->center + box->axis[0] * box->halfLength[0] * 2.0f; 980 dest1 = worldEntity->getAbsCoor() + box->center - box->axis[0] * box->halfLength[0] *2.0f; 981 982 983 position2 = worldEntity->getAbsCoor() + box->center + box->axis[2] * box->halfLength[2] * 2.0f; 984 dest2 = worldEntity->getAbsCoor() + box->center - box->axis[2] * box->halfLength[2] * 2.0f; 988 position = worldEntity->getAbsCoor() + box->center + Vector(0.0, 1.0, 0.0) * box->halfLength[1]; 989 dest = worldEntity->getAbsCoor() + box->center - Vector(0.0, 1.0, 0.0) * (box->halfLength[1] + BSP_Y_OFFSET); 990 991 position1 = worldEntity->getAbsCoor() + box->center - worldEntity->getAbsDirX() * (box->halfLength[0] + BSP_X_OFFSET); 992 dest1 = worldEntity->getAbsCoor() + box->center + worldEntity->getAbsDirX() * (box->halfLength[0] + BSP_X_OFFSET); 993 994 position2 = worldEntity->getAbsCoor() + box->center - worldEntity->getAbsDirZ() * (box->halfLength[2] + BSP_Z_OFFSET); 995 dest2 = worldEntity->getAbsCoor() + box->center + worldEntity->getAbsDirZ() * (box->halfLength[2] + BSP_Z_OFFSET); 985 996 986 997 } else { … … 989 1000 } 990 1001 1002 1003 // PRINTF(0)("x and v\n"); 1004 // worldEntity->getAbsDirX().debug(); 1005 // worldEntity->getAbsDirV().debug(); 991 1006 992 1007 … … 1035 1050 plane* testPlane = this->collPlane; 1036 1051 1037 1038 1052 bool xCollision = false; 1039 1053 bool zCollision = false; 1040 if(!SolidFlag) { 1054 1041 1055 1042 1056 // 2nd Collision Detection … … 1048 1062 this->checkCollisionRayN(this->root,0.0f,1.0f, &position1, &dest1 ); 1049 1063 1050 if( !this->outputAllSolid !=1.0f) {1064 if(this->outputFraction < 1.0f) { 1051 1065 out.x = dest1.x + (dest1.x -position1.x) * this->outputFraction; 1066 dest1 = position1 + (dest1 -position1) * this->outputFraction; 1052 1067 xCollision = true; 1053 1068 testPlane = this->collPlane; 1054 1069 } 1055 if(this->outputAllSolid) { 1070 if(this->outputAllSolid ) { 1071 1072 this->collPlane = new plane; 1073 this->collPlane->x = 0.0f; 1074 this->collPlane->y = 0.0f; 1075 this->collPlane->z = 0.0f; 1076 testPlane = this->collPlane; 1056 1077 SolidFlag = true; 1057 xCollision = true; 1078 xCollision = true; 1058 1079 } 1059 1080 //out.z = this->outputFraction; 1060 1081 1061 if(!SolidFlag) { 1082 1062 1083 1063 1084 // 3rd Collision Detection … … 1067 1088 this->inputStart = position2; 1068 1089 this->inputEnd = dest2; 1090 1069 1091 this->checkCollisionRayN(this->root,0.0f,1.0f, &position2, &dest2 ); 1070 1092 //out.x = this->outputFraction; 1071 1093 1072 if(this->outputFraction !=1.0f ) {1094 if(this->outputFraction < 1.0f ) { 1073 1095 out.z = out.z = dest2.z + (dest2.z -position2.z) * this->outputFraction; 1096 dest2 = position2 + (dest2 -position2) * this->outputFraction; 1074 1097 zCollision = true; 1075 1098 testPlane = this->collPlane; 1076 1099 1077 1100 } 1078 if(this->outputAllSolid) { 1079 SolidFlag = true; 1080 zCollision = true; 1101 if(this->outputAllSolid ) { 1102 this->collPlane = new plane; 1103 this->collPlane->x = 0.0f; 1104 this->collPlane->y = 0.0f; 1105 this->collPlane->z = 0.0f; 1106 testPlane = this->collPlane; 1107 1108 SolidFlag = true; 1109 zCollision = true; 1081 1110 } 1082 } 1083 }//end if1111 1112 //end if 1084 1113 /* 1085 1114 This is how you would calculate the Coordinates where worldEntity Collided with the BSP world. … … 1091 1120 // Return the normal here: Normal's stored in this->collPlane; 1092 1121 if( collision) { 1093 PRINTF(5)("We got a collision!! Are you sure: outputFraction = %f\n", this->outputFraction); 1094 worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y || (xCollision ? COLLISION_TYPE_AXIS_X :0) | (zCollision ? COLLISION_TYPE_AXIS_Z :0), this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out, SolidFlag); 1095 } else { 1096 if(xCollision || zCollision) { 1097 1098 worldEntity->registerCollision((xCollision ? COLLISION_TYPE_AXIS_X :0) | (zCollision ? COLLISION_TYPE_AXIS_Z :0) , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out, SolidFlag); 1099 } 1100 1101 } 1122 worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out, SolidFlag); 1123 } 1124 if(xCollision) { 1125 worldEntity->registerCollision(COLLISION_TYPE_AXIS_X , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z),dest1 , SolidFlag); 1126 } 1127 if(zCollision) { 1128 worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), dest2 , SolidFlag); 1129 } 1130 1131 1102 1132 //else worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y, this->parent, worldEntity, Vector(0.0, 2.0, 0.0), dest, false); 1103 1133 -
trunk/src/lib/graphics/importer/bsp_manager.h
r8724 r9003 28 28 29 29 30 #define BSP_X_OFFSET 20.0f 31 #define BSP_Y_OFFSET 40.0f 32 #define BSP_Z_OFFSET 20.0f 33 30 34 31 35 // FORWARD DECLARATIONS … … 41 45 class WorldEntity; 42 46 47 48 // Obsolete 43 49 struct BspCollisionEvent 44 50 { … … 54 60 55 61 BspManager(const char* fileName, float scale = 0.4f); 56 void load(const char* fileName, float scale); 62 63 // Deconstructor 64 ~BspManager(); 65 66 57 67 58 68 // Functions 69 int load(const char* fileName, float scale); 59 70 const void draw(); 60 71 const void tick(float time); … … 99 110 Vector inputStart; 100 111 Vector inputEnd; 101 112 102 113 Vector traceMins; //!< Mins of current bbox 103 114 Vector traceMaxs; //!< Maxs of current bbox … … 112 123 ::std::deque<int> opal; //!< the others here. 113 124 114 Vector out; //!< For debugging only125 Vector out; //!< Stores collision coordinates 115 126 Vector out1; //!< For debugging only 116 127 Vector out2; //!< For debugging only 117 128 118 129 int tgl; 119 130 }; -
trunk/src/lib/graphics/importer/interactive_model.h
r8894 r9003 40 40 virtual int getAnimation() = 0; 41 41 42 virtual bool isAnimationFinished() { return false; } 43 42 44 virtual void setAnimationSpeed(float speed) {} 43 45 }; -
trunk/src/lib/graphics/importer/md2/md2Model.cc
r8894 r9003 85 85 86 86 this->scaleFactor = scale; 87 this->animationSpeed = 1.0f; 87 88 88 89 shadeDots = MD2Model::anormsDots[0]; … … 103 104 this->pModelInfo.pTexCoor = (float*)this->data->pTexCoor; 104 105 105 this->animationSpeed = 1.0f;106 106 107 107 // triangle conversion -
trunk/src/lib/graphics/importer/md2/md2Model.h
r8894 r9003 161 161 inline int MD2Model::getAnimation() { return this->animationState.type; } 162 162 virtual void setAnimationSpeed(float speed) { this->animationSpeed = speed; } 163 virtual bool isAnimationFinished() { return (this->animationState.currentFrame == this->animationState.endFrame )?true:false; } 163 164 /** scales the current model @param scaleFactor: the factor [0..1] to use for scaling */ 164 165 void scaleModel(float scaleFactor) { this->scaleFactor = scaleFactor;} -
trunk/src/lib/script_engine/script.cc
r8783 r9003 24 24 25 25 #include "class_list.h" 26 // uncommet this when the std:string and the const bug is fixed 27 //CREATE_SCRIPTABLE_CLASS(Script, CL_SCRIPT, 28 // addMethod("addObject", ExecutorLua2<Script,std::string,std::string>(&Script::addObject)) 29 // ): 26 30 27 31 Script::Script(const TiXmlElement* root) … … 73 77 bool Script::loadFile(const std::string& filename) 74 78 { 75 79 this->setName(filename); 76 80 std::string filedest(ResourceManager::getInstance()->getDataDir()); 77 81 filedest += "scripts/" + filename; … … 93 97 { 94 98 currentFile = filename; 99 //this->addThisScript(); 95 100 return true; 96 101 } … … 323 328 } 324 329 330 331 void Script::addThisScript() 332 { 333 BaseObject* scriptClass = ClassList::getObject("Script", CL_SCRIPT_CLASS); 334 if (scriptClass != NULL) 335 { 336 static_cast<ScriptClass*>(scriptClass)->registerClass(this); 337 static_cast<ScriptClass*>(scriptClass)->insertObject(this, this,"thisscript", false); 338 } 339 } 340 325 341 int Script::reportError(int error) 326 342 { -
trunk/src/lib/script_engine/script.h
r8711 r9003 31 31 void loadFileNoRet(const std::string& filename) { loadFile(filename); }; 32 32 bool loadFile(const std::string& filename); 33 void addObject( const std::string& className,const std::string& objectName);33 void addObject( const std::string& className,const std::string& objectName); 34 34 35 35 /// QUERRYING … … 61 61 62 62 private: 63 63 void addThisScript(); 64 64 int reportError(int error); //!< Get errormessage from the lua stack and print it. 65 65 bool registerStandartClasses(); //!< Register all the classes that the script might need -
trunk/src/lib/script_engine/script_class.h
r8408 r9003 34 34 virtual void registerClass(Script* script) = 0; 35 35 virtual int insertObject(Script* L, BaseObject* obj, bool gc=false) = 0; 36 virtual int insertObject(Script* L, BaseObject* obj, const std::string& name, bool gc=false) = 0; 36 37 37 38 const ScriptMethod* scriptMethods() const { return this->_scriptMethods; } … … 64 65 return Lunar<T>::insertObject(L, dynamic_cast<T*>(obj), obj->getName(), gc); 65 66 } 67 68 virtual int insertObject(Script* L, BaseObject* obj,const std::string& name, bool gc=false) 69 { 70 return Lunar<T>::insertObject(L, dynamic_cast<T*>(obj), name, gc); 71 } 66 72 }; 67 73 -
trunk/src/lib/script_engine/script_manager.cc
r8711 r9003 74 74 while(!scripts->empty()) 75 75 delete scripts->front(); 76 //Delete all triggers 77 if(this->getTriggers()) 78 while(!triggers->empty()) 79 delete triggers->front(); 80 76 81 } 77 82 -
trunk/src/lib/util/executor/executor_lua.cc
r8894 r9003 37 37 template<> void toLua<float>(lua_State* state, float value) { lua_pushnumber(state, (lua_Number) value); }; 38 38 template<> void toLua<char>(lua_State* state, char value) { lua_pushnumber(state, (lua_Number) value); }; 39 template<> void toLua<const std::string&>(lua_State* state, const std::string& value) { lua_pushstring (state, value.c_str()); }39 template<> void toLua<const std::string&>(lua_State* state, const std::string& value) { lua_pushstring (state, value.c_str()); } -
trunk/src/util/hud.cc
r9001 r9003 59 59 60 60 this->subscribeEvent(ES_ALL, EV_VIDEO_RESIZE); 61 this->subscribeEvent(ES_ALL, SDLK_TAB); 61 62 62 63 … … 226 227 if (event.type == EV_VIDEO_RESIZE) 227 228 this->updateResolution(); 228 } 229 230 229 else if (event.type == SDLK_TAB) 230 { 231 /// TODO SHOW THE INPUT-LINE 232 // this->inputLine->select(); 233 } 234 235 236 } 237 238 -
trunk/src/world_entities/WorldEntities.am
r8994 r9003 5 5 world_entities/npcs/ground_turret.cc \ 6 6 world_entities/npcs/generic_npc.cc \ 7 world_entities/npcs/door.cc \ 8 world_entities/npcs/repair_station.cc \ 7 9 \ 8 10 world_entities/environment.cc \ … … 16 18 world_entities/character_attributes.cc \ 17 19 world_entities/test_entity.cc \ 18 world_entities/door.cc \19 20 world_entities/planet.cc \ 20 21 world_entities/bsp_entity.cc \ … … 67 68 npcs/npc_test1.h \ 68 69 npcs/ground_turret.h \ 70 npcs/door.cc \ 71 npcs/repair_station.cc \ 72 \ 69 73 environment.h \ 70 74 skysphere.h \ … … 77 81 character_attributes.h \ 78 82 test_entity.h \ 79 door.h \80 83 planet.h \ 81 84 bsp_entity.h \ -
trunk/src/world_entities/bsp_entity.cc
r8490 r9003 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: Claudio Botta … … 15 15 16 16 #include "bsp_entity.h" 17 #include "util/loading/resource_manager.h" 17 18 #include "util/loading/resource_manager.h" 18 19 … … 38 39 BspEntity::~BspEntity () 39 40 { 40 if( this->bspManager )41 if( this->bspManager != NULL) 41 42 delete this->bspManager; 42 43 } 44 43 45 44 46 … … 49 51 void BspEntity::init() 50 52 { 51 this->setClassID(CL_BSP_ENTITY, "BspEntity");52 53 53 this->bspManager = new BspManager(this); 54 this->toList(OM_ENVIRON); 55 54 this->bspManager = NULL; 56 55 /** 57 56 * @todo: Write CL_BSP_ENTITY INTO THE src/defs/class_id.h (your own definition) … … 64 63 PRINTF(0)("+++++++++++ LOADING NAME %s\n", name.c_str()); 65 64 66 this->bspManager->load(name.c_str(), 0.1f); 65 // Check wether file exists.... 66 if ( File(ResourceManager::getFullName(name)).exists() ) { 67 68 this->setClassID(CL_BSP_ENTITY, "BspEntity"); 69 this->bspManager = new BspManager(this); 70 71 if(this->bspManager->load(name.c_str(), 0.1f) == -1 ) { 72 this->bspManager = NULL; 73 74 } else { 75 this->toList(OM_ENVIRON); // Success!!! 76 } 77 } else { 78 this->bspManager = NULL; 79 this->toList(OM_DEAD); 80 } 67 81 } 68 82 … … 76 90 { 77 91 // all the clases this Entity is directly derived from must be called in this way, to load all settings. 78 // WorldEntity::loadParam(root);92 // WorldEntity::loadParam(root); 79 93 80 94 LoadParam(root, "Name", this, BspEntity, setName) 81 95 .describe("Sets the of the BSP file."); 82 96 83 /* LoadParam(root, "Scale", this, BSpEntity, setScale)84 .describe("Sets the scale factore of the bsp level.");85 */97 /* LoadParam(root, "Scale", this, BSpEntity, setScale) 98 .describe("Sets the scale factore of the bsp level."); 99 */ 86 100 87 101 /** … … 115 129 */ 116 130 void BspEntity::collidesWith (WorldEntity* entity, const Vector& location) 117 { 118 119 } 131 {} -
trunk/src/world_entities/creatures/fps_player.cc
r8894 r9003 83 83 this->bBackward = false; 84 84 this->bJump = false; 85 this->bPosBut = false; 85 86 86 87 this->xMouse = 0.0f; … … 90 91 this->setHealth(80); 91 92 93 this->fallVelocity = 0.0f; 92 94 93 95 this->cameraNode.setParent(this); … … 121 123 122 124 this->getWeaponManager().setSlotCount(2); 123 this->getWeaponManager().setSlotPosition(0, Vector( 0.0, 5.0, 0.0));124 this->getWeaponManager().setSlotDirection(1, Quaternion(M_PI_4*.5, Vector(0,1,0)));125 this->getWeaponManager().setSlotPosition(0, Vector(1.5, -0.7, 1.1)); 126 // this->getWeaponManager().setSlotDirection(0, Quaternion(M_PI_2, Vector(0,1,0))); 125 127 this->getWeaponManager().setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); 126 this->getWeaponManager().setSlotPosition(1, Vector( -0.5, .2, 1.9));128 this->getWeaponManager().setSlotPosition(1, Vector(5.0, 0.0, 0.0)); 127 129 this->getWeaponManager().setSlotDirection(1, Quaternion(M_PI_4*.5, Vector(1,0,0))); 128 130 … … 205 207 void FPSPlayer::tick (float time) 206 208 { 209 210 if( this->bPosBut) 211 { 212 this->bPosBut = false; 213 printf("prisoner:walkTo( %f, height, %f)\n",this->getAbsCoorX(),this->getAbsCoorZ()); 214 } 215 207 216 Playable::tick( time ); 208 217 … … 251 260 } 252 261 262 253 263 velocity *= 100; 254 264 265 266 // physical falling of the player 267 if( !this->isOnGround()) 268 { 269 this->fallVelocity += 300.0f * time; 270 velocity -= Vector(0.0, 1.0, 0.0) * this->fallVelocity; 271 } 272 else 273 { 274 this->fallVelocity = 0.0f; 275 } 276 277 255 278 this->shiftCoor( velocity*time ); 279 280 281 256 282 257 283 … … 321 347 } 322 348 else if( event.type == KeyMapper::PEV_JUMP) 323 this-> getAbsCoor().debug();324 } 325 326 327 328 349 this->bPosBut = event.bPressed; 350 } 351 352 353 354 -
trunk/src/world_entities/creatures/fps_player.h
r8731 r9003 42 42 bool bBackward; 43 43 bool bJump; //!< jumping 44 bool bPosBut; //!< position button 44 45 45 46 float xMouse; //!< mouse moved in x-Direction … … 51 52 52 53 PNode cameraNode; 54 55 float fallVelocity; //!< velocity for falling down 53 56 }; 54 57 -
trunk/src/world_entities/elements/glgui_radar.cc
r9002 r9003 135 135 glRotatef((this->_centerNode->getAbsDir().getHeading() - M_PI_2)* 180.0 /M_PI , 0, 0, 1); 136 136 137 glPointSize( 2.0f);137 glPointSize(4.0f); 138 138 for (unsigned int i = 0; i < this->_dotLists.size(); ++i) 139 139 { -
trunk/src/world_entities/npcs/generic_npc.cc
r8894 r9003 17 17 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY 18 18 19 #include "generic_npc.h" 20 19 21 20 22 #include "util/loading/factory.h" … … 28 30 #include "loading/resource_manager.h" 29 31 30 #include "generic_npc.h"31 32 #include "animation/animation3d.h"33 34 using namespace std;35 36 37 32 38 33 CREATE_FACTORY(GenericNPC, CL_GENERIC_NPC); … … 40 35 #include "script_class.h" 41 36 CREATE_SCRIPTABLE_CLASS(GenericNPC, CL_GENERIC_NPC, 42 // Move 43 addMethod("walkTo", ExecutorLua3ret<GenericNPC,float,float,float,float>(&GenericNPC::walkTo)) 44 ->addMethod("setTime", ExecutorLua1<GenericNPC,float>(&GenericNPC::setTime)) 45 ->addMethod("turnTo", ExecutorLua4ret<GenericNPC,bool,float,float,float,float>(&GenericNPC::turnTo)) 46 // Display 37 // Move 38 addMethod("walkTo", ExecutorLua3<GenericNPC,float,float,float>(&GenericNPC::walkTo)) 39 ->addMethod("runTo", ExecutorLua3<GenericNPC,float,float,float>(&GenericNPC::runTo)) 40 ->addMethod("turnTo", ExecutorLua1<GenericNPC,float>(&GenericNPC::turnTo)) 41 ->addMethod("finalGoalReached", ExecutorLua0ret<GenericNPC,bool>(&GenericNPC::finalGoalReached)) 42 // Display 47 43 ->addMethod("hide", ExecutorLua0<WorldEntity>(&WorldEntity::hide)) 48 44 ->addMethod("unhide", ExecutorLua0<WorldEntity>(&WorldEntity::unhide)) 49 // Coordinates45 // Coordinates 50 46 ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX)) 51 47 ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY)) … … 53 49 ->addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor)) 54 50 ->addMethod("setAbsDir", ExecutorLua4<PNode,float,float,float,float>(&PNode::setAbsDir)) 55 51 56 52 ); 57 53 … … 62 58 */ 63 59 GenericNPC::GenericNPC(const TiXmlElement* root) 64 : NPC(root)60 : NPC(root) 65 61 { 66 62 this->init(); … … 71 67 72 68 73 GenericNPC::GenericNPC()74 : NPC(NULL)75 {76 77 }78 79 69 /** 80 70 * deconstructor 81 71 */ 82 72 GenericNPC::~GenericNPC () 83 { 84 if( this->currentAnim != NULL) 85 delete this->currentAnim; 86 } 73 {} 87 74 88 75 … … 100 87 101 88 time = 30.0f; 89 102 90 // collision reaction registration 103 //this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);91 this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY); 104 92 } 105 93 … … 128 116 129 117 118 119 /** 120 * @returns the current animation number 121 */ 122 int GenericNPC::getAnimation() 123 { 124 if( likely(this->getModel(0) != NULL)) 125 return ((InteractiveModel*)this->getModel(0))->getAnimation(); 126 else 127 return -1; 128 } 129 130 131 132 /** 133 * @returns true if animation is finished 134 */ 135 bool GenericNPC::isAnimationFinished() 136 { 137 if( likely(this->getModel(0) != NULL)) 138 return ((InteractiveModel*)this->getModel(0))->isAnimationFinished(); 139 else 140 return false; 141 } 142 143 144 /** 145 * sets the animation speed of this entity 146 */ 147 void GenericNPC::setAnimationSpeed(float speed) 148 { 149 if( likely(this->getModel(0) != NULL)) 150 ((InteractiveModel*)this->getModel(0))->setAnimationSpeed(speed); 151 } 152 153 154 130 155 /** 131 156 * sets the animation of this npc … … 146 171 */ 147 172 void GenericNPC::playSound(std::string filename) 148 { 149 150 } 151 152 153 /** 154 * walt to 155 * @param coordinate: coordinate to go to 156 */ 157 float GenericNPC::walkTo(float x, float y, float z, float qu, float qx, float qy, float qz) 158 { 159 Vector destCoor = Vector(x, y, z); 160 Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu); 161 162 // check if this is the current goal 163 if( this->destCoor != destCoor || this->destDir != destDir) 164 { 165 this->destCoor = destCoor; 166 this->destDir = destDir; 167 168 //float time = 100.0f; 169 170 if( this->currentAnim != NULL) 171 delete this->currentAnim; 172 173 this->currentAnim = new Animation3D(this); 174 this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), 0.0f, ANIM_LINEAR, ANIM_LINEAR); 175 this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR); 176 this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR); 177 178 this->currentAnim->setInfinity(ANIM_INF_CONSTANT); 179 this->currentAnim->play(); 180 181 this->setAnimation(RUN, MD2_ANIM_LOOP); 182 } 183 184 // calculate the distance 185 Vector distance = this->getAbsCoor() - this->destCoor; 186 return distance.len(); 187 } 188 189 190 /** 191 * walk to a specific place with direction 192 * 193 * @param x: x coordinate to go to 194 * @param y: y coordinate to go to 195 * @param z: z coordinate to go to 196 * 197 * without turning itself 198 */ 199 float GenericNPC::walkTo(float x, float y, float z) 200 { 201 Quaternion q = this->getAbsDir(); 202 203 //printf("%s moving to %f, %f, %f \n",this->getName(),x,y,z); 204 205 return this->walkTo(x, y, z, q.w, q.v.x, q.v.y, q.v.z); 206 } 207 208 /** 209 * walk to a specific place with direction 210 * 211 * @param x: x coordinate to go to 212 * @param y: y coordinate to go to 213 * @param qu: angle to rotate 214 * @param qx: x coordinate of rotation vector 215 * @param qy: y coordinate of rotation vector 216 * @param qz: z coordinate of rotation vector 217 * 218 */ 219 float GenericNPC::walkTo(float x, float y, float qu, float qx, float qy, float qz) 220 { 221 return this->walkTo(x, y, 0.0f, qu, qx, qy, qz); 222 } 223 224 225 /** 226 * walk to a specific place with direction 227 * 228 * @param coor: vector place 229 * @param dir: direction 230 * 231 */ 232 float GenericNPC::walkTo(const Vector& coor, const Quaternion& dir) 233 { 234 return this->walkTo(coor.x, coor.y, coor.z, dir.w, dir.v.x, dir.v.y, dir.v.z); 235 } 236 237 238 239 /** 240 * run to a specific place with direction 241 * 242 * @param x: x coordinate to go to 243 * @param y: y coordinate to go to 244 * @param z: z coordinate to go to 245 * @param qu: angle to rotate 246 * @param qx: x coordinate of rotation vector 247 * @param qy: y coordinate of rotation vector 248 * @param qz: z coordinate of rotation vector 249 * 250 */ 251 float GenericNPC::runTo(float x, float y, float z, float qu, float qx, float qy, float qz) 252 { 253 Vector destCoor = Vector(x, y, z); 254 Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu); 255 256 // check if this is the current goal 257 if( this->destCoor != destCoor || this->destDir != destDir) 258 { 259 this->destCoor = destCoor; 260 this->destDir = destDir; 261 262 float time = 5.0f; 263 264 if( this->currentAnim != NULL) 265 delete this->currentAnim; 266 267 this->currentAnim = new Animation3D(this); 268 this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR); 269 this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR); 270 271 272 this->currentAnim->setInfinity(ANIM_INF_CONSTANT); 273 this->currentAnim->play(); 274 275 this->setAnimation(RUN, MD2_ANIM_LOOP); 276 } 277 278 // calculate the distance 279 Vector distance = this->getAbsCoor() - this->destCoor; 280 return distance.len(); 281 } 282 283 284 /** 285 * run to a specific place with direction 286 * 287 * @param x: x coordinate to go to 288 * @param y: y coordinate to go to 289 * @param qu: angle to rotate 290 * @param qx: x coordinate of rotation vector 291 * @param qy: y coordinate of rotation vector 292 * @param qz: z coordinate of rotation vector 293 * 294 */ 295 float GenericNPC::runTo(float x, float y, float qu, float qx, float qy, float qz) 296 { 297 this->runTo(x, y, 0.0f, qu, qx, qy, qz); 298 } 299 300 301 /** 302 * run to a specific place with direction 303 * 304 * @param coor: vector place 305 * @param dir: direction 306 * 307 */ 308 float GenericNPC::runTo(const Vector& coordinate, const Quaternion& dir) 309 { 310 this->runTo(coordinate.x, coordinate.y, coordinate.z, dir.w, dir.v.x, dir.v.y, dir.v.z); 311 } 312 313 314 /** 315 * crouch to a specific place with direction 316 * 317 * @param x: x coordinate to go to 318 * @param y: y coordinate to go to 319 * @param z: z coordinate to go to 320 * @param qu: angle to rotate 321 * @param qx: x coordinate of rotation vector 322 * @param qy: y coordinate of rotation vector 323 * @param qz: z coordinate of rotation vector 324 * 325 */ 326 float GenericNPC::crouchTo(float x, float y, float z, float qu, float qx, float qy, float qz) 327 { 328 Vector destCoor = Vector(x, y, z); 329 Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu); 330 331 // check if this is the current goal 332 if( this->destCoor != destCoor || this->destDir != destDir) 333 { 334 this->destCoor = destCoor; 335 this->destDir = destDir; 336 337 338 if( this->currentAnim != NULL) 339 delete this->currentAnim; 340 341 this->currentAnim = new Animation3D(this); 342 this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR); 343 this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR); 344 345 346 this->currentAnim->setInfinity(ANIM_INF_CONSTANT); 347 this->currentAnim->play(); 348 349 this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP); 350 } 351 352 // calculate the distance 353 Vector distance = this->getAbsCoor() - this->destCoor; 354 return distance.len(); 355 } 356 357 358 /** 359 * couch to a specific place with direction 360 * 361 * @param x: x coordinate to go to 362 * @param y: y coordinate to go to 363 * @param qu: angle to rotate 364 * @param qx: x coordinate of rotation vector 365 * @param qy: y coordinate of rotation vector 366 * @param qz: z coordinate of rotation vector 367 * 368 */ 369 float GenericNPC::crouchTo(float x, float y, float qu, float qx, float qy, float qz) 370 { 371 this->crouchTo(x, y, 0.0f, qu, qx, qy, qz); 372 } 373 374 375 376 /** 377 * crouch to a specific place with direction 378 * 379 * @param coor: vector place 380 * @param dir: direction 381 * 382 */ 383 float GenericNPC::crouchTo(const Vector& coordinate, const Quaternion& dir) 384 { 385 this->crouchTo(coordinate.x, coordinate.y, coordinate.z, dir.w, dir.v.x, dir.v.y, dir.v.z); 386 } 173 {} 174 387 175 388 176 … … 391 179 */ 392 180 void GenericNPC::stop() 393 { 394 if( this->currentAnim != NULL) 395 { 396 this->currentAnim->stop(); 397 delete this->currentAnim; 398 this->currentAnim = NULL; 399 181 {} 182 183 184 185 void GenericNPC::initNPC() 186 { 187 if (!this->behaviourList.empty()) 188 { 189 GenericNPC::Anim currentAnimation = this->behaviourList.front(); 190 191 switch(this->behaviourList.front().type) 192 { 193 case Walk: 194 { 195 if( this->getAnimation() != RUN) 196 this->setAnimation(RUN, MD2_ANIM_LOOP); 197 198 Vector dir = (currentAnimation.v - this->getAbsCoor()); 199 dir.y = 0.0f; 200 dir.getNormalized(); 201 this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0))); 202 203 this->setAnimationSpeed(0.5f); 204 } 205 break; 206 case Run: 207 { 208 if( this->getAnimation() != RUN) 209 this->setAnimation(RUN, MD2_ANIM_LOOP); 210 211 Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized(); 212 this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0))); 213 214 this->setAnimationSpeed(1.0f); 215 } 216 break; 217 case Crouch: 218 { 219 if( this->getAnimation() != CROUCH_WALK) 220 this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP); 221 222 Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized(); 223 this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0))); 224 225 this->setAnimationSpeed(1.0f); 226 } 227 break; 228 case LookAt: 229 if( this->getAnimation() != STAND) 230 this->setAnimation(STAND, MD2_ANIM_LOOP); 231 break; 232 case Shoot: 233 if( this->getAnimation() != STAND) 234 this->setAnimation(STAND, MD2_ANIM_LOOP); 235 break; 236 237 default: 238 if( this->getAnimation() != STAND) 239 this->setAnimation(STAND, MD2_ANIM_LOOP); 240 break; 241 242 } 243 } 244 } 245 246 247 void GenericNPC::nextStep() 248 { 249 if (!this->behaviourList.empty()) 250 this->behaviourList.pop_front(); 251 else 252 return; 253 254 255 if (!this->behaviourList.empty()) 256 { 257 GenericNPC::Anim currentAnimation = this->behaviourList.front(); 258 259 switch( currentAnimation.type) 260 { 261 case Walk: 262 { 263 if( this->getAnimation() != RUN) 264 this->setAnimation(RUN, MD2_ANIM_LOOP); 265 266 Vector dir = (currentAnimation.v - this->getAbsCoor()); 267 dir.y = 0.0f; 268 dir.getNormalized(); 269 this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0); 270 271 this->setAnimationSpeed(0.5f); 272 } 273 break; 274 case Run: 275 { 276 if( this->getAnimation() != RUN) 277 this->setAnimation(RUN, MD2_ANIM_LOOP); 278 279 Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized(); 280 this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0); 281 282 this->setAnimationSpeed(1.0f); 283 } 284 break; 285 case Crouch: 286 { 287 if( this->getAnimation() != CROUCH_WALK) 288 this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP); 289 290 Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized(); 291 this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0); 292 293 this->setAnimationSpeed(1.0f); 294 } 295 break; 296 case LookAt: 297 { 298 if( this->getAnimation() != STAND) 299 this->setAnimation(STAND, MD2_ANIM_LOOP); 300 } 301 break; 302 case Shoot: 303 if( this->getAnimation() != STAND) 304 this->setAnimation(STAND, MD2_ANIM_LOOP); 305 break; 306 307 default: 308 if( this->getAnimation() != STAND) 309 this->setAnimation(STAND, MD2_ANIM_LOOP); 310 break; 311 312 } 313 } 314 else 315 { 400 316 this->setAnimation(STAND, MD2_ANIM_LOOP); 401 317 } 402 318 } 319 320 321 322 323 void GenericNPC::walkTo(const Vector& coordinate) 324 { 325 326 GenericNPC::Anim anim; 327 anim.v = coordinate; 328 anim.type = Walk; 329 anim.speed = 30.0f; 330 331 if( this->behaviourList.empty()) 332 { 333 this->behaviourList.push_back(anim); 334 this->initNPC(); 335 } 336 else 337 this->behaviourList.push_back(anim); 338 } 339 340 void GenericNPC::walkTo(float x, float y, float z) 341 { 342 //printf("Walking to %f, %f, %f \n",x,y,z); 343 this->walkTo(Vector(x,y,z)); 344 345 } 346 347 /* running functions */ 348 void GenericNPC::runTo(const Vector& coordinate) 349 { 350 GenericNPC::Anim anim; 351 anim.v = coordinate; 352 anim.type = Run; 353 anim.speed = 60.0f; 354 355 if( this->behaviourList.empty()) 356 { 357 this->behaviourList.push_back(anim); 358 this->initNPC(); 359 } 360 else 361 this->behaviourList.push_back(anim); 362 } 363 364 void GenericNPC::runTo(float x, float y, float z) 365 { 366 this->runTo(Vector(x,y,z)); 367 } 368 369 /* couching functinos */ 370 void GenericNPC::crouchTo(const Vector& coordinate) 371 { 372 GenericNPC::Anim anim; 373 anim.v = coordinate; 374 anim.type = Crouch; 375 376 if( this->behaviourList.empty()) 377 { 378 this->behaviourList.push_back(anim); 379 this->initNPC(); 380 } 381 else 382 this->behaviourList.push_back(anim); 383 } 384 void GenericNPC::crouchTo(float x, float y, float z) 385 { 386 this->crouchTo(Vector(x,y,z)); 387 } 388 389 390 391 void GenericNPC::turnTo(float degreeInY) 392 { 393 GenericNPC::Anim anim; 394 anim.q = Quaternion(Vector(0,1,0), degreeInY); 395 anim.type = TurnTo; 396 397 if( this->behaviourList.empty()) 398 { 399 this->behaviourList.push_back(anim); 400 this->initNPC(); 401 } 402 else 403 this->behaviourList.push_back(anim); 404 } 405 403 406 404 407 … … 407 410 * @param worldEntity: the worldentity to look at 408 411 */ 409 float GenericNPC::lookAt(WorldEntity* worldEntity) 410 {} 411 412 413 /** 414 * turns to a given direction 415 */ 416 bool GenericNPC::turnTo(float qu, float qx, float qy, float qz) 417 { 418 Quaternion destDir = Quaternion(Vector(qx, qy, qz).getNormalized(), qu); 419 420 printf("Turning: %f, %f, %f, %f \n",qu,qx,qy,qz); 421 // check if this is the current goal 422 if( this->destDir != destDir) 423 { 424 // if( this->currentAnim != NULL) 425 // this->currentAnim->stop(); 426 // 427 PRINTF(0)("SET ANIMATION\n"); 428 this->destDir = destDir; 429 // 430 431 432 if( this->currentAnim != NULL) 433 delete this->currentAnim; 434 435 this->setAbsDir(destDir); 436 /* 437 this->currentAnim = new Animation3D(this); 438 this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), 0.0f, ANIM_LINEAR, ANIM_LINEAR); 439 this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR); 440 this->currentAnim->addKeyFrame(this->getAbsCoor(), this->destDir, time, ANIM_LINEAR, ANIM_LINEAR); 441 442 443 this->currentAnim->setInfinity(ANIM_INF_CONSTANT); 444 this->currentAnim->play();*/ 445 446 this->setAnimation(STAND, MD2_ANIM_LOOP); 447 } 448 449 // calculate the distance 450 Vector distance = this->getAbsCoor() - this->destCoor; 451 return distance.len(); 452 } 412 void GenericNPC::lookAt(WorldEntity* worldEntity) 413 { 414 GenericNPC::Anim anim; 415 anim.entity = worldEntity; 416 anim.type = LookAt; 417 418 if( this->behaviourList.empty()) 419 { 420 this->behaviourList.push_back(anim); 421 this->initNPC(); 422 } 423 else 424 this->behaviourList.push_back(anim); 425 } 426 453 427 454 428 … … 459 433 * @param dialogNr: sound nr to be played (from the xml load tags) 460 434 */ 461 floatGenericNPC::talkTo(WorldEntity* worldEntity, int dialogNr)435 void GenericNPC::talkTo(WorldEntity* worldEntity, int dialogNr) 462 436 {} 463 437 … … 483 457 * @param time: time in seconds expirded since the last tick 484 458 */ 485 void GenericNPC::tick (float time)459 void GenericNPC::tick (float dt) 486 460 { 487 461 if( likely(this->getModel(0) != NULL)) 488 ((InteractiveModel*)this->getModel(0))->tick(time); 462 ((InteractiveModel*)this->getModel(0))->tick(dt); 463 464 465 if (!this->behaviourList.empty()) 466 { 467 GenericNPC::Anim currentAnimation = this->behaviourList.front(); 468 469 switch( currentAnimation.type) 470 { 471 case Walk: 472 { 473 Vector dest = currentAnimation.v - this->getAbsCoor(); 474 if (dest.len() < .5) 475 this->nextStep(); 476 else 477 { 478 dest.y = 0.0f; 479 this->shiftCoor(dest.getNormalized() * currentAnimation.speed * dt); 480 481 } 482 } 483 break; 484 485 case Run: 486 { 487 Vector dest = currentAnimation.v - this->getAbsCoor(); 488 if (dest.len() < .5) 489 this->nextStep(); 490 else 491 { 492 this->shiftCoor(dest.getNormalized() * currentAnimation.speed * dt); 493 } 494 } 495 break; 496 497 case Crouch: 498 { 499 Vector dest = currentAnimation.v - this->getAbsCoor(); 500 if (dest.len() < .5) 501 this->nextStep(); 502 else 503 { 504 this->shiftCoor(dest.getNormalized() * currentAnimation.speed * dt); 505 } 506 } 507 break; 508 509 case TurnTo: 510 //Quaternion direction = this-> 511 break; 512 513 case LookAt: 514 break; 515 516 case Shoot: 517 break; 518 519 default: 520 break; 521 522 } 523 } 524 525 // physical falling of the player 526 if( !this->isOnGround()) 527 { 528 this->fallVelocity += 300.0f * dt; 529 velocity -= Vector(0.0, 1.0, 0.0) * this->fallVelocity; 530 // PRINTF(0)("%s is not on ground\n", this->getName()); 531 } 532 else 533 { 534 this->fallVelocity = 0.0f; 535 } 536 537 this->shiftCoor(Vector(0, -this->fallVelocity * dt,0)); 489 538 490 539 } … … 495 544 { 496 545 int randi = (int)(5.0f * (float)rand()/(float)RAND_MAX); 546 547 this->setAnimationSpeed(1.0f); 497 548 498 549 if( randi == 1) -
trunk/src/world_entities/npcs/generic_npc.h
r8894 r9003 10 10 #include "npc.h" 11 11 12 #include <string>13 12 14 13 #include "sound_source.h" 15 16 #include "vector.h"17 #include "quaternion.h"18 19 14 20 15 namespace OrxSound{ class SoundSource; } … … 27 22 class GenericNPC : public NPC 28 23 { 24 25 29 26 public: 30 GenericNPC(); 31 GenericNPC(const TiXmlElement* root); 27 GenericNPC(const TiXmlElement* root = NULL); 32 28 virtual ~GenericNPC (); 33 29 34 void init();35 30 virtual void loadParams(const TiXmlElement* root); 36 31 37 void setAnimation(int animationIndex, int animPlaybackMode);38 32 /** sets the sound volume to @param vol: volume of the sound */ 39 33 inline void setVolume(float vol) { this->soundVolume = vol; } 40 34 41 35 42 /* npc controlling functions */43 36 37 bool finalGoalReached() { return this->behaviourList.empty(); }; 38 39 /* npc controlling functions to be Queued */ 44 40 /* walking functions */ 45 float walkTo(const Vector& coordinate, const Quaternion& dir); 46 float walkTo(float x, float y, float z); 47 float walkTo(float x, float y, float z, float qu, float qx, float qy, float qz); 48 float walkTo(float x, float y, float qu, float qx, float qy, float qz); 41 void walkTo(const Vector& coordinate); 42 void walkTo(float x, float y, float z); 49 43 50 44 /* running functions */ 51 float runTo(const Vector& coordinate, const Quaternion& dir); 52 float runTo(float x, float y, float z, float qu, float qx, float qy, float qz); 53 float runTo(float x, float y, float qu, float qx, float qy, float qz); 45 void runTo(const Vector& coordinate); 46 void runTo(float x, float y, float z); 54 47 55 48 /* couching functinos */ 56 float crouchTo(const Vector& coordinate, const Quaternion& dir); 57 float crouchTo(float x, float y, float z, float qu, float qx, float qy, float qz); 58 float crouchTo(float x, float y, float qu, float qx, float qy, float qz); 49 void crouchTo(const Vector& coordinate); 50 void crouchTo(float x, float y, float z); 59 51 60 52 /* stopping the movement */ 61 53 void stop(); 54 void nextStep(); 62 55 63 56 /* some oriantation functions */ 64 float lookAt(WorldEntity* worldEntity); 65 bool turnTo(float qu, float qx, float qy, float qz); 57 void lookAt(WorldEntity* worldEntity); 58 void turnTo(float qu, float qx, float qy, float qz); 59 void turnTo(float degreeInY); 66 60 67 61 /* talking funcitons*/ 68 floattalkTo(WorldEntity* worldEntity, int dialogNr);62 void talkTo(WorldEntity* worldEntity, int dialogNr); 69 63 70 64 /* shooting functions */ … … 77 71 void playSound(int i); 78 72 79 void setTime(float newTime){ this->time = newTime; };80 81 73 virtual void tick (float time); 82 74 … … 84 76 void destroy(); 85 77 78 private: 79 void init(); 80 81 void setAnimation(int animationIndex, int animPlaybackMode); 82 int getAnimation(); 83 bool isAnimationFinished(); 84 void setAnimationSpeed(float speed); 85 86 void initNPC(); 87 86 88 87 89 private: 90 91 typedef enum { 92 Walk, 93 Run, 94 Crouch, 95 Jump, 96 TurnTo, 97 LookAt, 98 TalkTo, 99 100 Shoot, 101 102 103 } AnimType; 104 105 typedef struct Anim 106 { 107 Vector v; 108 Quaternion q; 109 110 111 WorldEntity* entity; 112 float speed; 113 114 115 AnimType type; 116 }; 117 typedef std::list<GenericNPC::Anim> genNPCAnimList; 118 119 120 88 121 OrxSound::SoundSource soundSource; 89 122 OrxSound::SoundBuffer* soundBuffer; 90 123 float soundVolume; 91 124 125 std::list<GenericNPC::Anim> behaviourList; 92 126 Vector destCoor; 93 127 Quaternion destDir; … … 95 129 Animation3D* currentAnim; 96 130 float time; //!< Duration of the action 131 float fallVelocity; 97 132 }; 98 133 -
trunk/src/world_entities/npcs/npc.cc
r8894 r9003 29 29 30 30 this->toList(OM_GROUP_00); 31 31 32 } 32 33 -
trunk/src/world_entities/script_trigger.cc
r8894 r9003 14 14 */ 15 15 16 17 16 #include "script_trigger.h" 18 17 #include "class_list.h" … … 23 22 24 23 CREATE_SCRIPTABLE_CLASS(ScriptTrigger, CL_SCRIPT_TRIGGER, 25 addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor)) 26 ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX)) 27 ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY)) 28 ->addMethod("getAbsCoorZ", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorZ)) 24 //Position 25 addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor)) 26 ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX)) 27 ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY)) 28 ->addMethod("getAbsCoorZ", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorZ)) 29 //Set values 30 // ->addMethod("setTarget", ExecutorLua1<ScriptTrigger, std::string >(&ScriptTrigger::setTarget)) 31 // ->addMethod("setTriggerParent", ExecutorLua1<ScriptTrigger, std::string >(&ScriptTrigger::setTriggerParent)) 32 ->addMethod("setTriggerLasts", ExecutorLua1<ScriptTrigger, bool >(&ScriptTrigger::setTriggerLasts)) 33 ->addMethod("setInvert", ExecutorLua1<ScriptTrigger, bool >(&ScriptTrigger::setInvert)) 34 ->addMethod("setRadius", ExecutorLua1<ScriptTrigger, float >(&ScriptTrigger::setRadius)) 35 //->addMethod("setScript", ExecutorLua1<ScriptTrigger, std::string >(&ScriptTrigger::setScript)) 36 //->addMethod("setFunction", ExecutorLua1<ScriptTrigger, std::string >(&ScriptTrigger::setFunction)) 37 ->addMethod("setDebugDraw", ExecutorLua1<ScriptTrigger, bool >(&ScriptTrigger::setInvert)) 29 38 ); 30 39 … … 92 101 LoadParam(root, "radius", this, ScriptTrigger, setRadius) 93 102 .describe("the fileName of the script, that should be triggered by this script trigger") 94 .defaultValues(0);95 LoadParam(root, "delay", this, ScriptTrigger, setDelay)96 .describe("the delay after which the funtion sould be triggered")97 103 .defaultValues(0); 98 104 LoadParam(root, "worldentity", this, ScriptTrigger, setTarget) -
trunk/src/world_entities/script_trigger.h
r8894 r9003 38 38 void setInvert(const bool inv) { this->invert = invert; } 39 39 void setRadius(const float radius) { if(radius>0) this->radius = radius; } 40 void setDelay(const float time){if(delay>0) this->delay = delay; }41 40 void setScript(const std::string& file); 42 41 void setFunction(const std::string& function){ this->functionName = function;} -
trunk/src/world_entities/test_entity.cc
r8778 r9003 37 37 38 38 CREATE_FACTORY(TestEntity, CL_TEST_ENTITY); 39 40 #include "script_class.h" 41 CREATE_SCRIPTABLE_CLASS(TestEntity, CL_TEST_ENTITY, 42 addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor)) 43 ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX)) 44 ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY)) 45 ->addMethod("getAbsCoorZ", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorZ)) 46 47 ); 39 48 40 49 -
trunk/src/world_entities/weapons/fps_sniper_rifle.cc
r8894 r9003 67 67 { 68 68 // model will be deleted from WorldEntity-destructor 69 if( this->material != NULL) 70 delete this->material; 69 71 } 70 72 … … 74 76 this->setClassID(CL_FPS_SNIPER_RIFLE, "FPSSniperRifle"); 75 77 76 this->loadModel("models/guns/fps_sniper_rifle.obj", 0.1); 78 this->loadModel("models/guns/fps_sniper_rifle.obj", 0.2); 79 this->material = new Material(); 80 this->material->setIllum(3); 81 this->material->setAmbient(1.0, 1.0, 1.0); 82 this->material->setDiffuseMap("maps/rifle01tex.jpg"); 77 83 78 84 this->setStateDuration(WS_SHOOTING, .1); … … 149 155 150 156 157 158 159 /** 160 * this will draw the weapon 161 */ 162 void FPSSniperRifle::draw () const 163 { 164 /* draw gun body */ 165 glMatrixMode(GL_MODELVIEW); 166 glPushMatrix(); 167 glTranslatef (this->getAbsCoor ().x, 168 this->getAbsCoor ().y, 169 this->getAbsCoor ().z); 170 171 Vector tmpRot = this->getAbsDir().getSpacialAxis(); 172 glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); 173 174 if( this->leftRight == W_RIGHT) 175 glScalef(1.0, 1.0, -1.0); 176 177 this->material->select(); 178 static_cast<StaticModel*>(this->getModel())->draw(); 179 180 glPopMatrix(); 181 182 } 183 184 185 -
trunk/src/world_entities/weapons/fps_sniper_rifle.h
r8894 r9003 35 35 36 36 37 class Material; 38 37 39 class FPSSniperRifle : public Weapon 38 40 { … … 50 52 virtual void fire(); 51 53 54 virtual void draw() const; 55 56 52 57 53 58 private: 54 int leftRight; // this will become an enum 59 int leftRight; //!< this will become an enum 60 Material* material; //!< material 55 61 56 62 }; -
trunk/src/world_entities/world_entity.cc
r8977 r9003 72 72 73 73 this->objectListNumber = OM_INIT; 74 this->lastObjectListNumber = OM_INIT; 74 75 this->objectListIterator = NULL; 75 76 … … 78 79 this->collisionHandles[i] = NULL; 79 80 this->bReactive = false; 81 this->bOnGround = false; 80 82 81 83 // registering default reactions: … … 613 615 } 614 616 615 if( this->aabbNode != NULL)616 this->aabbNode->drawBV(0, DRAW_BV_POLYGON, Vector(1, 0.6, 0.2), true);617 // if( this->aabbNode != NULL) 618 // this->aabbNode->drawBV(0, DRAW_BV_POLYGON, Vector(1, 0.6, 0.2), true); 617 619 618 620 glPopMatrix(); -
trunk/src/world_entities/world_entity.h
r8974 r9003 94 94 CollisionHandle* getCollisionHandle(CREngine::CRType type) const { return this->collisionHandles[type]; } 95 95 96 /** @returns true if this entity is standing on ground (BSP model) */ 97 bool isOnGround() const { return this->bOnGround; } 98 /** @param flag: marks if this entity is standing on ground */ 99 void setOnGround(bool flag) { this->bOnGround = flag; } 100 96 101 virtual void hit(float damage); 97 102 virtual void destroy(); … … 117 122 118 123 void hide() { if( this->objectListNumber != OM_DEAD) this->lastObjectListNumber = this->objectListNumber; this->toList(OM_DEAD); } 119 void unhide() { this->toList(this->lastObjectListNumber); }124 void unhide() { if( this->objectListNumber != this->lastObjectListNumber) this->toList(this->lastObjectListNumber); } 120 125 121 126 … … 194 199 195 200 PhysicsInterface physicsInterface; //!< the physics object of the WorldEntity 196 201 bool bOnGround; //!< true if this entity is standing on the ground 197 202 198 203 protected:
Note: See TracChangeset
for help on using the changeset viewer.