Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 24, 2009, 10:38:06 PM (16 years ago)
Author:
scheusso
Message:

first approach of having client-side pong physics
some optimisations in TrafficControl

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/netp3/src/orxonox/objects/worldentities/PongBall.cc

    r2896 r3043  
    3232#include "core/CoreIncludes.h"
    3333#include "core/GameMode.h"
    34 #include "objects/worldentities/PongBat.h"
    3534#include "objects/gametypes/Gametype.h"
    3635
     
    4746        this->speed_ = 0;
    4847        this->bat_ = 0;
     48        this->batID_ = new unsigned int[2];
     49        this->batID_[0] = OBJECTID_UNKNOWN;
     50        this->batID_[1] = OBJECTID_UNKNOWN;
    4951        this->relMercyOffset_ = 0.05;
     52       
     53        this->registerVariables();
     54    }
     55   
     56    void PongBall::registerVariables()
     57    {
     58        registerVariable( this->batID_[0] );
     59        registerVariable( this->batID_[1], variableDirection::toclient, new NetworkCallback<PongBall>( this, &PongBall::applyBats) );
    5060    }
    5161
     
    119129                this->setPosition(position);
    120130        }
     131        else
     132        {
     133          Vector3 position = this->getPosition();
     134          Vector3 velocity = this->getVelocity();
     135
     136          if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
     137          {
     138            velocity.z = -velocity.z;
     139
     140            if (position.z > this->fieldHeight_ / 2)
     141              position.z = this->fieldHeight_ / 2;
     142            if (position.z < -this->fieldHeight_ / 2)
     143              position.z = -this->fieldHeight_ / 2;
     144          }
     145
     146          if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
     147          {
     148            float distance = 0;
     149
     150            if (this->bat_)
     151            {
     152              if (position.x > this->fieldWidth_ / 2 && this->bat_[1])
     153              {
     154                distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2);
     155                if (fabs(distance) <= 1)
     156                {
     157                  position.x = this->fieldWidth_ / 2;
     158                  velocity.x = -velocity.x;
     159                  velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
     160                }
     161              }
     162              if (position.x < -this->fieldWidth_ / 2 && this->bat_[0])
     163              {
     164                distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2);
     165                if (fabs(distance) <= 1)
     166                {
     167                  position.x = -this->fieldWidth_ / 2;
     168                  velocity.x = -velocity.x;
     169                  velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
     170                }
     171              }
     172            }
     173          }
     174
     175          if (velocity != this->getVelocity())
     176            this->setVelocity(velocity);
     177          if (position != this->getPosition())
     178            this->setPosition(position);
     179        }
    121180    }
    122181
Note: See TracChangeset for help on using the changeset viewer.