Changeset 9003 in orxonox.OLD for trunk/src/world_entities
- Timestamp:
- Jul 2, 2006, 1:36:13 PM (19 years ago)
- Location:
- trunk/src/world_entities
- Files:
-
- 2 deleted
- 15 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
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.