Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8823 in orxonox.OLD for branches/single_player_map


Ignore:
Timestamp:
Jun 27, 2006, 2:24:30 PM (18 years ago)
Author:
snellen
Message:

added setTime function

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

    r8822 r8823  
    4242                        //addMethod("walkTo", ExecutorLua7ret<GenericNPC,float, float, float, float, float, float, float, float>(&GenericNPC::walkTo))
    4343                        addMethod("walkTo", ExecutorLua3ret<GenericNPC,float,float,float,float>(&GenericNPC::walkTo))
     44                        ->addMethod("setTime", ExecutorLua1<GenericNPC,float>(&GenericNPC::setTime))
    4445                       );
    4546
     
    8788  this->soundBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/rain.wav", WAV);
    8889
     90  time = 30.0f;
    8991  // collision reaction registration
    9092//   this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);
     
    153155    this->destDir = destDir;
    154156
    155     float time = 10.0f;
     157    float time = 100.0f;
     158
     159    if( this->currentAnim != NULL)
     160      delete this->currentAnim;
     161
     162    this->currentAnim = new Animation3D(this);
     163    this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), 0.0f, ANIM_LINEAR, ANIM_LINEAR);
     164    this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(),time, ANIM_LINEAR, ANIM_LINEAR);
     165    this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
     166//     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
     167//     this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
     168
     169    this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
     170    this->currentAnim->play();
     171
     172    this->setAnimation(RUN, MD2_ANIM_LOOP);
     173  }
     174
     175  // calculate the distance
     176  Vector distance = this->getAbsCoor() - this->destCoor;
     177  return distance.len();
     178}
     179
     180
     181/**
     182 * walk to a specific place with direction
     183 *
     184 * @param x: x coordinate to go to
     185 * @param y: y coordinate to go to
     186 * @param z: z coordinate to go to
     187 *
     188 * without turning itself
     189 */
     190float GenericNPC::walkTo(float x, float y, float z)
     191{
     192  Quaternion q = this->getAbsDir();
     193
     194  //printf("%s moving to %f, %f, %f \n",this->getName(),x,y,z);
     195
     196  return this->walkTo(x, y, z, q.w, q.v.x, q.v.y, q.v.z);
     197}
     198
     199/**
     200 * walk to a specific place with direction
     201 *
     202 * @param x: x coordinate to go to
     203 * @param y: y coordinate to go to
     204 * @param qu: angle to rotate
     205 * @param qx: x coordinate of rotation vector
     206 * @param qy: y coordinate of rotation vector
     207 * @param qz: z coordinate of rotation vector
     208 *
     209 */
     210float GenericNPC::walkTo(float x, float y, float qu, float qx, float qy, float qz)
     211{
     212  return this->walkTo(x, y, 0.0f, qu, qx, qy, qz);
     213}
     214
     215
     216/**
     217 * walk to a specific place with direction
     218 *
     219 * @param coor: vector place
     220 * @param dir: direction
     221 *
     222 */
     223float GenericNPC::walkTo(const Vector& coor, const Quaternion& dir)
     224{
     225  return this->walkTo(coor.x, coor.y, coor.z, dir.w, dir.v.x, dir.v.y, dir.v.z);
     226}
     227
     228
     229
     230/**
     231 * run to a specific place with direction
     232 *
     233 * @param x: x coordinate to go to
     234 * @param y: y coordinate to go to
     235 * @param z: z coordinate to go to
     236 * @param qu: angle to rotate
     237 * @param qx: x coordinate of rotation vector
     238 * @param qy: y coordinate of rotation vector
     239 * @param qz: z coordinate of rotation vector
     240 *
     241 */
     242float GenericNPC::runTo(float x, float y, float z, float qu, float qx, float qy, float qz)
     243{
     244  Vector destCoor = Vector(x, y, z);
     245  Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu);
     246
     247  // check if this is the current goal
     248  if( this->destCoor != destCoor || this->destDir != destDir)
     249  {
     250    this->destCoor = destCoor;
     251    this->destDir = destDir;
     252
     253    float time = 5.0f;
    156254
    157255    if( this->currentAnim != NULL)
     
    177275
    178276/**
    179  * walk to a specific place with direction
    180  *
    181  * @param x: x coordinate to go to
    182  * @param y: y coordinate to go to
    183  * @param z: z coordinate to go to
    184  *
    185  * without turning itself
    186  */
    187 float GenericNPC::walkTo(float x, float y, float z)
    188 {
    189   Quaternion q = this->getAbsDir();
    190 
    191   //printf("%s moving to %f, %f, %f \n",this->getName(),x,y,z);
    192 
    193   return this->walkTo(x, y, z, q.w, q.v.x, q.v.y, q.v.z);
    194 }
    195 
    196 /**
    197  * walk to a specific place with direction
     277 * run to a specific place with direction
    198278 *
    199279 * @param x: x coordinate to go to
     
    205285 *
    206286 */
    207 float GenericNPC::walkTo(float x, float y, float qu, float qx, float qy, float qz)
    208 {
    209   return this->walkTo(x, y, 0.0f, qu, qx, qy, qz);
    210 }
    211 
    212 
    213 /**
    214  * walk to a specific place with direction
     287float GenericNPC::runTo(float x, float y, float qu, float qx, float qy, float qz)
     288{
     289  this->runTo(x, y, 0.0f, qu, qx, qy, qz);
     290}
     291
     292
     293/**
     294 * run to a specific place with direction
    215295 *
    216296 * @param coor: vector place
     
    218298 *
    219299 */
    220 float GenericNPC::walkTo(const Vector& coor, const Quaternion& dir)
    221 {
    222   return this->walkTo(coor.x, coor.y, coor.z, dir.w, dir.v.x, dir.v.y, dir.v.z);
    223 }
    224 
    225 
    226 
    227 /**
    228  * run to a specific place with direction
     300float GenericNPC::runTo(const Vector& coordinate, const Quaternion& dir)
     301{
     302  this->runTo(coordinate.x, coordinate.y, coordinate.z, dir.w, dir.v.x, dir.v.y, dir.v.z);
     303}
     304
     305
     306/**
     307 * crouch to a specific place with direction
    229308 *
    230309 * @param x: x coordinate to go to
     
    237316 *
    238317 */
    239 float GenericNPC::runTo(float x, float y, float z, float qu, float qx, float qy, float qz)
     318float GenericNPC::crouchTo(float x, float y, float z, float qu, float qx, float qy, float qz)
    240319{
    241320  Vector destCoor = Vector(x, y, z);
     
    248327    this->destDir = destDir;
    249328
    250     float time = 5.0f;
    251329
    252330    if( this->currentAnim != NULL)
     
    254332
    255333    this->currentAnim = new Animation3D(this);
    256     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), 0.1f, ANIM_LINEAR, ANIM_LINEAR);
    257     this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
    258334    this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
    259335    this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
    260336
    261     this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
    262     this->currentAnim->play();
    263 
    264     this->setAnimation(RUN, MD2_ANIM_LOOP);
    265   }
    266 
    267   // calculate the distance
    268   Vector distance = this->getAbsCoor() - this->destCoor;
    269   return distance.len();
    270 }
    271 
    272 
    273 /**
    274  * run to a specific place with direction
    275  *
    276  * @param x: x coordinate to go to
    277  * @param y: y coordinate to go to
    278  * @param qu: angle to rotate
    279  * @param qx: x coordinate of rotation vector
    280  * @param qy: y coordinate of rotation vector
    281  * @param qz: z coordinate of rotation vector
    282  *
    283  */
    284 float GenericNPC::runTo(float x, float y, float qu, float qx, float qy, float qz)
    285 {
    286   this->runTo(x, y, 0.0f, qu, qx, qy, qz);
    287 }
    288 
    289 
    290 /**
    291  * run to a specific place with direction
    292  *
    293  * @param coor: vector place
    294  * @param dir: direction
    295  *
    296  */
    297 float GenericNPC::runTo(const Vector& coordinate, const Quaternion& dir)
    298 {
    299   this->runTo(coordinate.x, coordinate.y, coordinate.z, dir.w, dir.v.x, dir.v.y, dir.v.z);
    300 }
    301 
    302 
    303 /**
    304  * crouch to a specific place with direction
    305  *
    306  * @param x: x coordinate to go to
    307  * @param y: y coordinate to go to
    308  * @param z: z coordinate to go to
    309  * @param qu: angle to rotate
    310  * @param qx: x coordinate of rotation vector
    311  * @param qy: y coordinate of rotation vector
    312  * @param qz: z coordinate of rotation vector
    313  *
    314  */
    315 float GenericNPC::crouchTo(float x, float y, float z, float qu, float qx, float qy, float qz)
    316 {
    317   Vector destCoor = Vector(x, y, z);
    318   Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu);
    319 
    320   // check if this is the current goal
    321   if( this->destCoor != destCoor || this->destDir != destDir)
    322   {
    323     this->destCoor = destCoor;
    324     this->destDir = destDir;
    325 
    326     float time = 5.0f;
    327 
    328     if( this->currentAnim != NULL)
    329       delete this->currentAnim;
    330 
    331     this->currentAnim = new Animation3D(this);
    332     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), 0.1f, ANIM_LINEAR, ANIM_LINEAR);
    333     this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
    334     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
    335     this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
    336337
    337338    this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
  • branches/single_player_map/src/world_entities/npcs/generic_npc.h

    r8817 r8823  
    7676  void playSound(int i);
    7777
    78 
     78  void setTime(float newTime){ this->time = newTime; };
     79 
    7980  virtual void tick (float time);
    8081
     
    9192
    9293   Animation3D*                            currentAnim;
     94   float                                   time;          //!< Duration of the action
    9395};
    9496
Note: See TracChangeset for help on using the changeset viewer.