Ejemplo n.º 1
0
ArmWidget::ArmWidget(QWidget *parent)
    : QGraphicsView(parent), timerId(0)
{

    QGraphicsScene *scene = new QGraphicsScene(this);
    scene->setItemIndexMethod(QGraphicsScene::NoIndex);
    scene->setSceneRect(0, 00, 210, 110);

	shoulder = true;
	elbow = true;
    setScene(scene);
    setCacheMode(CacheBackground);
    setViewportUpdateMode(BoundingRectViewportUpdate);
    setRenderHint(QPainter::Antialiasing);
    setTransformationAnchor(AnchorUnderMouse);
    scale(qreal(1), qreal(1));
    setMinimumSize(210, 110);
    setWindowTitle(tr("Elastic Nodes"));

    joint *joint1 = new joint(this);
    joint *joint2 = new joint(this);
    joint *joint3 = new joint(this);


    scene->addItem(joint1);
    scene->addItem(joint2);
    scene->addItem(joint3);

    joint3->setFlag(joint3->ItemIsMovable);

    double x = armShoulderSegmentMeters;
    double y = armElbowSegmentMeters;

    joint1->setPos(this->sceneRect().left()+ARM_SHOULDER_X+5, this->sceneRect().bottom()-ARM_Y+ARM_BODY_TOP+5);
    joint2->setPos(this->sceneRect().left()+ARM_SHOULDER_X+5, -MetersToPixels(y)-ARM_Y+ARM_BODY_TOP+5+this->sceneRect().bottom());


    joint3->setPos(MetersToPixels(x)+this->sceneRect().left()+ARM_SHOULDER_X+5,
                   -MetersToPixels(y)-ARM_Y+ARM_BODY_TOP+5+this->sceneRect().bottom());
    end_effector = QPointF(0,0);

    QGraphicsLineItem *line = new QGraphicsLineItem(joint1->pos().x()-5,joint1->pos().y()-5,joint2->pos().x()-5,joint2->pos().y()-5);
    scene->addItem(line);
    QGraphicsLineItem *line2 = new QGraphicsLineItem(joint2->pos().x()-5,joint2->pos().y()-5,joint3->pos().x()-5,joint3->pos().y()-5);
    scene->addItem(line2);

 }
Ejemplo n.º 2
0
	//-------------------------------------------------------------------------
	PixelCoordinate OpenStreetMapSource::lonLatToPixel( LonLat lonlat, MagnificationType magnification )
	//-------------------------------------------------------------------------
	{
		double meterX, meterY;
		double pixelX, pixelY;
		LonLatToMeters( lonlat.lon, lonlat.lat, meterX, meterY );
		MetersToPixels( meterX, meterY, magnification, pixelX, pixelY );
		return PixelCoordinate( magnification, (int)pixelX, (int)pixelY );
	}
Ejemplo n.º 3
0
void Box2DPhysics::SyncVisibleScene()
{
    for (std::map<ActorID, b2Body*>::const_iterator it = m_ActorIDToBody.begin(); it != m_ActorIDToBody.end(); ++it)
    {
        ActorID id = it->first;
        glm::vec2 bodyPos = glm::vec2(MetersToPixels(it->second->GetPosition().x), MetersToPixels(it->second->GetPosition().y));
        float     bodyRot = it->second->GetAngle();
        std::shared_ptr<Actor> actor = GameApplication::GetInstance()->GetActor(id);
        // bodyPos is from center of object, first transform to top-left of object so it corresponds with game-logic 
        bodyPos -= actor->GetScale() * 0.5f;
        // due to floating point precision I can't directly compare the positions, compare them given some range interval
        if (!IsVec2Equal(actor->GetPosition(), bodyPos)) // something changed, update scene
        {
            // set actor to correct position and start event that actor has moved (scene will listen to this event for render changes)
            actor->SetPosition(bodyPos);
            actor->SetRotation(bodyRot);
            // send event
            GameApplication::GetInstance()->GetEventManager()->QueueEvent(std::shared_ptr<Event_ActorMoved>(new Event_ActorMoved(id, bodyPos, bodyRot)));
        }
    }
}
Ejemplo n.º 4
0
	//-------------------------------------------------------------------------
	//
	// Convert tile center plus pixel offset to lat/lon. Offset increases right and down
	//
	LonLat GoogleMapSource::tileCenterToLonLat( const int tileSize, const MapTileCoordinate& tile, const double offsetX, const double offsetY )
	//-------------------------------------------------------------------------
	{
		double meterX, meterY;
		TileCenter( getTileSize( ), tile.getX( ), tile.getY( ), tile.getMagnification( ), meterX, meterY );
		
		double pixelX, pixelY;
		MetersToPixels( meterX, meterY, tile.getMagnification( ), pixelX, pixelY );
		pixelX += offsetX;
		pixelY -= offsetY; // google maps y coords increase up
		PixelsToMeters( pixelX, pixelY, tile.getMagnification( ), meterX, meterY );
		
		double lon, lat;
		MetersToLonLat( meterX, meterY, lon, lat );
		
		return LonLat( lon, lat );
	}
Ejemplo n.º 5
0
float Box2DPhysics::GetBodyMass(unsigned int ActorID)
{
	return MetersToPixels(FindBody(ActorID)->GetMass());
}
Ejemplo n.º 6
0
glm::vec2 Box2DPhysics::GetLinearVelocity(unsigned int ActorID)
{
    b2Vec2 linVel = FindBody(ActorID)->GetLinearVelocity();
    return glm::vec2(MetersToPixels(linVel.x), MetersToPixels(linVel.y));
}