Ejemplo n.º 1
0
  double
  OPMSD::calcStructMSD(const Topology& Itop) const
  {
    //Required to get the correct results
    Sim->dynamics->updateAllParticles();

    double acc = 0.0;
    for (const shared_ptr<IDRange>& molRange : Itop.getMolecules())
      {
	Vector  origPos(0,0,0), currPos(0,0,0);
	double totmass = 0.0;
	for (const unsigned long& ID : *molRange)
	  {
	    double pmass = Sim->species[Sim->particles[ID]]->getMass(ID);

	    totmass += pmass;
	    currPos += Sim->particles[ID].getPosition() * pmass;
	    origPos += initPos[ID] * pmass;
	  }
      
	currPos /= totmass;
	origPos /= totmass;

	acc += (currPos - origPos).nrm2();
      }

    acc /= Itop.getMoleculeCount() * Sim->units.unitArea();
  
    return acc;
  }
Ejemplo n.º 2
0
void Player::Update(sf::Time elapsed, MB::EventList* events)
{
    MB::GameComponent::Update(elapsed, events);

    int dirX = 0;
    int dirY = 0;
    bool moved = false;

    sf::Vector2f origPos(this->playerSprite.getPosition());
    float origRot = this->playerSprite.getRotation();

    Game* g = (Game*)this->game;


    /*if(g->HasFocus()){*/
    if ( (this->actions->Exists("Player Move Up") && this->actions->Get("Player Move Up")->IsActive() ) ||
            ( this->actions->Exists("Player Move Up Alt") && this->actions->Get("Player Move Up Alt")->IsActive())) {
        dirY = -1;
        moved = true;
    }

    if ( (this->actions->Exists("Player Move Down") && this->actions->Get("Player Move Down")->IsActive() ) ||
            ( this->actions->Exists("Player Move Down Alt") && this->actions->Get("Player Move Down Alt")->IsActive())) {
        dirY = 1;
        moved = true;
    }

    if ( (this->actions->Exists("Player Move Left") && this->actions->Get("Player Move Left")->IsActive() ) ||
            ( this->actions->Exists("Player Move Left Alt") && this->actions->Get("Player Move Left Alt")->IsActive())) {
        dirX = -1;
        moved = true;
    }

    if ( (this->actions->Exists("Player Move Right") && this->actions->Get("Player Move Right")->IsActive() ) ||
            ( this->actions->Exists("Player Move Right Alt") && this->actions->Get("Player Move Right Alt")->IsActive())) {
        dirX = 1;
        moved = true;
    }

    //}


    sf::Vector2f direction(dirX,dirY);


    // Change position (based on elapsed time)
    // Limit elapsed time first
    float limitedElapsed = (float)elapsed.asMilliseconds();
    if(limitedElapsed > 31.0f) {
        limitedElapsed = 31.0f;
    }

    sf::Vector2f velocity(dirX * 1.f * limitedElapsed, dirY * 1.f * limitedElapsed);

    // Now check collision

    sf::IntRect origRect(this->playerSprite.getGlobalBounds());
    origRect.top = origPos.y;
    origRect.left = origPos.x;
    origRect.width = origRect.height = 32;

    // Slight offset correction (from origin)
    origRect.top -= 16;
    origRect.left -= 16;

    sf::Vector2f correctedVector = gameMap->collisionDetect(origRect, velocity, direction ) ;

    correctedVector.x += origPos.x;
    correctedVector.y += origPos.y;

    this->playerSprite.setPosition(correctedVector);

    // Set sprite orientation based on dir
    float rotation = 0.0f;

    // Diagonals

    if(dirY == -1 && dirX == -1) {
        rotation = 315.0f;
    } else if(dirY == -1 && dirX == 1) {
        rotation = 45.0f;
    } else if(dirY == 1 && dirX == -1) {
        rotation = 225.0f;
    } else if(dirY == 1 && dirX == 1) {
        rotation = 135.0f;
    }

    if(rotation == 0.0f) {
        if(dirY == 1) {
            rotation = 180.0f;
        } else if(dirX == -1) {
            rotation = 270.0f;
        } else if(dirX == 1) {
            rotation = 90.0f;
        }
    }

    this->playerSprite.setRotation(rotation);


    if(moved) {
        // Update the local copy of weapon hitbox only if moved
        UpdateWeaponHitBox();
        this->directionVector = sf::Vector2i(dirX,dirY);
        // Send Packet
        Packets packets;
        WorkQueues::packetsToSend().push(packets.CreateSendThisPlayerPos(playerSprite.getPosition(),playerSprite.getRotation()));

    } else {
        this->playerSprite.setRotation(origRot);
    }


    if (
        (this->actions->Exists("UseItem") && this->actions->Get("UseItem")->IsActive()) ||
        (this->actions->Exists("UseItem Alt") && this->actions->Get("UseItem Alt")->IsActive())
    )
    {
        this->UseItem();
    }
    this->attacking = false;
    if (this->game->GetActions()->Exists("Attack") && this->game->GetActions()->Get("Attack")->IsActive())
    {
        this->attacking = true;
        this->Attack();

    }
}