Changeset 8908 in orxonox.OLD for branches/single_player_map/src/world_entities
- Timestamp:
- Jun 29, 2006, 3:30:20 PM (18 years ago)
- Location:
- branches/single_player_map/src/world_entities/npcs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/single_player_map/src/world_entities/npcs/generic_npc.cc
r8894 r8908 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" … … 27 29 28 30 #include "loading/resource_manager.h" 29 30 #include "generic_npc.h"31 32 #include "animation/animation3d.h"33 34 using namespace std;35 36 31 37 32 … … 41 36 CREATE_SCRIPTABLE_CLASS(GenericNPC, CL_GENERIC_NPC, 42 37 // 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)) 38 addMethod("walkTo", ExecutorLua3<GenericNPC,float,float,float>(&GenericNPC::walkTo)) 39 ->addMethod("turnTo", ExecutorLua1<GenericNPC,float>(&GenericNPC::turnTo)) 46 40 // Display 47 41 ->addMethod("hide", ExecutorLua0<WorldEntity>(&WorldEntity::hide)) … … 53 47 ->addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor)) 54 48 ->addMethod("setAbsDir", ExecutorLua4<PNode,float,float,float,float>(&PNode::setAbsDir)) 55 49 56 50 ); 57 51 … … 71 65 72 66 73 GenericNPC::GenericNPC()74 : NPC(NULL)75 {76 77 }78 79 67 /** 80 68 * deconstructor … … 82 70 GenericNPC::~GenericNPC () 83 71 { 84 if( this->currentAnim != NULL)85 delete this->currentAnim;86 72 } 87 73 … … 151 137 152 138 153 /**154 * walt to155 * @param coordinate: coordinate to go to156 */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 goal163 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 distance185 Vector distance = this->getAbsCoor() - this->destCoor;186 return distance.len();187 }188 189 190 /**191 * walk to a specific place with direction192 *193 * @param x: x coordinate to go to194 * @param y: y coordinate to go to195 * @param z: z coordinate to go to196 *197 * without turning itself198 */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 direction210 *211 * @param x: x coordinate to go to212 * @param y: y coordinate to go to213 * @param qu: angle to rotate214 * @param qx: x coordinate of rotation vector215 * @param qy: y coordinate of rotation vector216 * @param qz: z coordinate of rotation vector217 *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 direction227 *228 * @param coor: vector place229 * @param dir: direction230 *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 direction241 *242 * @param x: x coordinate to go to243 * @param y: y coordinate to go to244 * @param z: z coordinate to go to245 * @param qu: angle to rotate246 * @param qx: x coordinate of rotation vector247 * @param qy: y coordinate of rotation vector248 * @param qz: z coordinate of rotation vector249 *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 goal257 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 distance279 Vector distance = this->getAbsCoor() - this->destCoor;280 return distance.len();281 }282 283 284 /**285 * run to a specific place with direction286 *287 * @param x: x coordinate to go to288 * @param y: y coordinate to go to289 * @param qu: angle to rotate290 * @param qx: x coordinate of rotation vector291 * @param qy: y coordinate of rotation vector292 * @param qz: z coordinate of rotation vector293 *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 direction303 *304 * @param coor: vector place305 * @param dir: direction306 *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 direction316 *317 * @param x: x coordinate to go to318 * @param y: y coordinate to go to319 * @param z: z coordinate to go to320 * @param qu: angle to rotate321 * @param qx: x coordinate of rotation vector322 * @param qy: y coordinate of rotation vector323 * @param qz: z coordinate of rotation vector324 *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 goal332 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 distance353 Vector distance = this->getAbsCoor() - this->destCoor;354 return distance.len();355 }356 357 358 /**359 * couch to a specific place with direction360 *361 * @param x: x coordinate to go to362 * @param y: y coordinate to go to363 * @param qu: angle to rotate364 * @param qx: x coordinate of rotation vector365 * @param qy: y coordinate of rotation vector366 * @param qz: z coordinate of rotation vector367 *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 direction378 *379 * @param coor: vector place380 * @param dir: direction381 *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 }387 388 139 389 140 /** … … 392 143 void GenericNPC::stop() 393 144 { 394 if( this->currentAnim != NULL) 395 { 396 this->currentAnim->stop(); 397 delete this->currentAnim; 398 this->currentAnim = NULL; 399 400 this->setAnimation(STAND, MD2_ANIM_LOOP); 401 } 402 } 145 146 } 147 148 149 void GenericNPC::walkTo(const Vector& coordinate) 150 { 151 } 152 153 void GenericNPC::walkTo(float x, float y) 154 {} 155 156 void GenericNPC::walkTo(float x, float y, float z) 157 {} 158 159 /* running functions */ 160 void GenericNPC::runTo(const Vector& coordinate) 161 {} 162 void GenericNPC::runTo(float x, float y) 163 {} 164 void GenericNPC::runTo(float x, float y, float z) 165 {} 166 167 /* couching functinos */ 168 void GenericNPC::crouchTo(const Vector& coordinate) 169 {} 170 void GenericNPC::crouchTo(float x, float y) 171 {} 172 void GenericNPC::crouchTo(float x, float y, float z) 173 {} 174 175 176 177 void GenericNPC::turnTo(float degreeInY) 178 {} 179 403 180 404 181 … … 407 184 * @param worldEntity: the worldentity to look at 408 185 */ 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 } 186 void GenericNPC::lookAt(WorldEntity* worldEntity) 187 {} 188 453 189 454 190 … … 459 195 * @param dialogNr: sound nr to be played (from the xml load tags) 460 196 */ 461 floatGenericNPC::talkTo(WorldEntity* worldEntity, int dialogNr)197 void GenericNPC::talkTo(WorldEntity* worldEntity, int dialogNr) 462 198 {} 463 199 -
branches/single_player_map/src/world_entities/npcs/generic_npc.h
r8894 r8908 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 … … 40 35 41 36 42 /* npc controlling functions */43 37 38 bool finalGoalReached() const { return this->behaviourList.empty(); }; 39 40 /* npc controlling functions to be Queued */ 44 41 /* 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); 42 void walkTo(const Vector& coordinate); 43 void walkTo(float x, float y); 44 void walkTo(float x, float y, float z); 49 45 50 46 /* 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);47 void runTo(const Vector& coordinate); 48 void runTo(float x, float y); 49 void runTo(float x, float y, float z); 54 50 55 51 /* 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);52 void crouchTo(const Vector& coordinate); 53 void crouchTo(float x, float y); 54 void crouchTo(float x, float y, float z); 59 55 60 56 /* stopping the movement */ … … 62 58 63 59 /* some oriantation functions */ 64 float lookAt(WorldEntity* worldEntity); 65 bool turnTo(float qu, float qx, float qy, float qz); 60 void lookAt(WorldEntity* worldEntity); 61 void turnTo(float qu, float qx, float qy, float qz); 62 void turnTo(float degreeInY); 66 63 67 64 /* talking funcitons*/ 68 floattalkTo(WorldEntity* worldEntity, int dialogNr);65 void talkTo(WorldEntity* worldEntity, int dialogNr); 69 66 70 67 /* shooting functions */ … … 77 74 void playSound(int i); 78 75 79 void setTime(float newTime){ this->time = newTime; };80 81 76 virtual void tick (float time); 82 77 … … 84 79 void destroy(); 85 80 81 private: 82 void init(); 83 86 84 87 85 private: 86 87 typedef enum { 88 Walk, 89 Run, 90 Crouch, 91 Jump, 92 TurnTo, 93 LookAt, 94 TalkTo, 95 96 Shoot, 97 98 99 } AnimType; 100 101 typedef struct Anim 102 { 103 Anim(); 104 105 Vector v; 106 Quaternion q; 107 108 109 WorldEntity* entity; 110 float speed; 111 112 113 AnimType type; 114 }; 115 typedef std::list<GenericNPC::Anim> genNPCAnimList; 116 117 118 88 119 OrxSound::SoundSource soundSource; 89 120 OrxSound::SoundBuffer* soundBuffer; 90 121 float soundVolume; 91 122 123 std::list<GenericNPC::Anim> behaviourList; 92 124 Vector destCoor; 93 125 Quaternion destDir;
Note: See TracChangeset
for help on using the changeset viewer.