Exemplo n.º 1
0
void model::rotate(const Matrix2x2& M)
{
    Vector2d tmp;

    //rotate vertices
    for(uint i=0;i<v_size;i++){
        tmp.set(vertices[i].bk_p[0],vertices[i].bk_p[1]);
        tmp=M*tmp;
        vertices[i].p.set(tmp[0],tmp[1]);
    }
    
    //rotate edges
    for(uint i=0;i<e_size;i++){
        for(int j=0;j<2;j++){
            tmp.set(edges[i].bk_in_n[j][0],edges[i].bk_in_n[j][1]);
            tmp=M*tmp;
            edges[i].in_n[j].set(tmp[0],tmp[1]);
        }
        
        tmp.set(edges[i].v[0],edges[i].v[1]);
        tmp=M*tmp;
        edges[i].v.set(tmp[0],tmp[1]);
    }

    //rotate facets
    for(uint i=0;i<t_size;i++){
        tmp.set(tris[i].n[0],tris[i].n[1]);
        tmp=M*tmp;
        tris[i].n.set(tmp[0],tmp[1]);
    }
}
Exemplo n.º 2
0
static void _RoundRectHit(
    const Box2d& rect, float rx, float ry, 
    const Point2d& pt, float tol, const Box2d &rectTol, 
    Point2d* pts, float& distMin, 
    Point2d& nearpt, int& segment)
{
    Point2d ptsBezier[13], ptTemp;
    Vector2d vec;
    float dx = rect.width() * 0.5f - rx;
    float dy = rect.height() * 0.5f - ry;
    
    // 按逆时针方向从第一象限到第四象限连接的四段
    mgcurv::ellipseToBezier(ptsBezier, rect.center(), rx, ry);
    
    pts[3] = ptsBezier[0];
    for (int i = 0; i < 4; i++)
    {
        pts[0] = pts[3];
        pts[1] = ptsBezier[3 * i];
        pts[2] = ptsBezier[3 * i + 1];
        pts[3] = ptsBezier[3 * i + 2];
        
        switch (i)
        {
        case 0: vec.set(dx, dy); break;
        case 1: vec.set(-dx, dy); break;
        case 2: vec.set(-dx, -dy); break;
        case 3: vec.set(dx, -dy); break;
        }
        
        for (int j = 0; j < 4; j++)
            pts[j] += vec;
        
        if (rectTol.isIntersect(Box2d(4, pts)))
        {
            mgnear::nearestOnBezier(pt, pts, ptTemp);
            float dist = pt.distanceTo(ptTemp);
            if (dist <= tol && dist < distMin)
            {
                distMin = dist;
                nearpt = ptTemp;
                segment = (5 - i) % 4;
            }
        }
        
        pts[3] -= vec;
    }
}
Exemplo n.º 3
0
 virtual bool load(MgStorage* s) {
     pt.set(s->readFloat("x", pt.x), s->readFloat("y", pt.y));
     vec.set(s->readFloat("w", vec.x), s->readFloat("h", vec.y));
     stroke = s->readBool("stroke", stroke);
     fill = s->readBool("fill", fill);
     return true;
 }
Exemplo n.º 4
0
//------------------------------------------------------------------------------
void Player::handleUserInput()
{
	assert( mpEngine );
  
  Vector2d aimingDir = getAimingDirection();
  //input usager pour déplacement
  if( mpEngine->isKeyPressed( Qt::Key_Left ) )
  { 
  	moveLeft();
    aimingDir.set( -1.0, 0.0 );
  }
  if( mpEngine->isKeyPressed( Qt::Key_Right ) )
  {
  	moveRight();
    aimingDir.set( 1.0, 0.0 );
  }
  
  if( mpEngine->isKeyPressed( Qt::Key_Up ) )
  { aimingDir.set( 0.0, 1.0 );}
  if( mpEngine->isKeyPressed( Qt::Key_Down ) )
  { aimingDir.set( 0.0, -1.0 ); }

  if( mpEngine->isKeyPressed( Qt::Key_Z ) )
  { jump(); }
  if( mpEngine->isKeyPressed( Qt::Key_X, true ) )
  { attack(); }
  
  setAimingDirection( aimingDir );
  
  //input usager pour changement d'arme
  if( mpEngine->isKeyPressed( Qt::Key_1 ) )
  { 
  	if( hasWeaponInBag( Weapon::tPellet ) )
    { setWeapon( getWeaponFromBag( Weapon::tPellet ) ); }
  }
  if( mpEngine->isKeyPressed( Qt::Key_2 ) )
  {
  	if( hasWeaponInBag( Weapon::tGrenade ) )
    { setWeapon( getWeaponFromBag( Weapon::tGrenade ) ); }
  }
  
  double frictionCoefficient = 0.2;
  if( mpEngine->isKeyPressed( Qt::Key_Left ) || 
  	mpEngine->isKeyPressed( Qt::Key_Right ) )
  {frictionCoefficient = 0.0;}
	setFrictionCoefficient( frictionCoefficient );
}
Exemplo n.º 5
0
void Matrix2d::getCoordSystem(Vector2d& e0, Vector2d& e1, Point2d& origin) const
{
    e0.set(m11, m12);
    e1.set(m21, m22);
    origin.set(dx, dy);
}
Exemplo n.º 6
0
 virtual bool load(MgStorage* s) {
     pt.set(s->readFloat("x", pt.x), s->readFloat("y", pt.y));
     vec.set(s->readFloat("w", vec.x), s->readFloat("h", vec.y));
     return true;
 }