Exemple #1
0
void MblkGeometry::getDx(
   const hier::Box& domain,
   const int level_number,
   const int block_number,
   double* dx)

{
   if (d_geom_problem == "CARTESIAN") {
      if (!d_metrics_set[level_number][block_number]) {
         setCartesianMetrics(domain,
            level_number, 
            block_number);
      }
   }

   if (d_geom_problem == "WEDGE") {
      if (!d_metrics_set[level_number][block_number]) {
         setWedgeMetrics(domain,
            level_number);
      }
   }

   if (d_geom_problem == "SPHERICAL_SHELL") {
      if (!d_metrics_set[level_number][block_number]) {
         setSShellMetrics(domain,
            level_number);
      }
   }

   getDx(level_number,
      block_number,
      dx);

}
void ForceDirectedGraphDrawing::computeAttractiveForces(std::shared_ptr<GraphClass>g)
{
    MDtype k = 0.1 * sqrt((*HEIGHT * *WIDTH) / (1.0 + g->vertices->size()));
    for(unsigned int i = 0; i < g->edges->size(); ++i){
        std::shared_ptr<VertexClass> v1 = g->edges->at(i)->A;
        std::shared_ptr<VertexClass> v2 = g->edges->at(i)->B;
        MDtype distance = getDistanceBetweenVertex(v1, v2);
        MDtype attractiveF = distance*distance / k * *ATTRACTION;
        if (distance > 0) {
            v1->xForce += (getDx(v1, v2) / distance) * attractiveF;
            v1->yForce += (getDy(v1, v2) / distance) * attractiveF;
            v2->xForce -= (getDx(v1, v2) / distance) * attractiveF;
            v2->yForce -= (getDy(v1, v2) / distance) * attractiveF;
        }
    }
}
Exemple #3
0
void Player::Update(HGE* hge) {
    float dt=hge->Timer_GetDelta();
    if(x>784) {
        x=784-(x-784);
        dx=-dx;
    }
    if(x<16) {
        x=16+16-x;
        dx=-dx;
    }
    if(y>584) {
        y=584-(y-584);
        dy=-dy;
    }
    if(y<16) {
        y=16+16-y;
        dy=-dy;
    }
    // Process keys
    if (hge->Input_KeyDown(HGEK_SPACE)) this->Rotate();
    if (hge->Input_GetKeyState(key) && simpleRotation==0) setDx(getDx()+getSpeed()*dt);
    if (hge->Input_GetKeyState(key) && simpleRotation==1) setDy(getDy()+getSpeed()*dt);
    if (hge->Input_GetKeyState(key) && simpleRotation==2) setDx(getDx()-getSpeed()*dt);
    if (hge->Input_GetKeyState(key) && simpleRotation==3) setDy(getDy()-getSpeed()*dt);
    if (invulnerableTimer > 0) {
        invulnerableTimer -= dt;
        displayShipTimer -= dt;
        if (displayShipTimer < 0) {
            displayShipTimer = 0.25f;
            if (displayShip) displayShip = false;
            else displayShip = true;
        }
    }
    else displayShip = true;
    Ship::Update(hge);
}
void ForceDirectedGraphDrawing::computeRepulsiveForces(std::shared_ptr<GraphClass> g)
{
    MDtype k = sqrt((*WIDTH * *HEIGHT) / (1.0 + g->vertices->size()));
    for(unsigned int i = 0; i < g->vertices->size(); ++i){
        for(unsigned int j = 0; j < g->vertices->size(); ++j){
            if(i != j){
                std::shared_ptr<VertexClass> v1 = g->vertices->at(i);
                std::shared_ptr<VertexClass> v2 = g->vertices->at(j);
                MDtype distance = getDistanceBetweenVertex(v1, v2);
                if (distance > 0) {
                    MDtype repulsiveF = k*k / distance * *REPULSION;
                    v1->xForce -= (( getDx(v1,v2) / distance) * repulsiveF);
                    v1->yForce -= (( getDy(v1,v2) / distance) * repulsiveF);
                }
            }
        }
    }
}
MDtype GetDistance::getDistanceBetweenVertex(std::shared_ptr<VertexClass> v1, std::shared_ptr<VertexClass> v2) {
    MDtype dx = getDx(v1, v2);
    MDtype dy = getDy(v1, v2);
    return sqrt(dx*dx + dy*dy);
}