Exemplo n.º 1
0
void QPoolRectObject::updateFromEngine()
{
	// Get rectangular engineObject
    std::shared_ptr<engine::RectangleShape> rectShape
    (
        std::static_pointer_cast<engine::RectangleShape>(poolObject()->shape())
    );
    
	// Create new rect
	double centerX = rectShape->center()[0];
	double centerY = rectShape->center()[1];
	
    double w = rectShape->width();
	double h = rectShape->height();
	
	QRectF qRect
	(
		centerX-0.5*w,
		centerY-0.5*h,
		rectShape->width(),
		rectShape->height()
	);
	
	// Update rectangle
	this->setRect(qRect);
	
	/*
	qDebug() << "set center to " <<centerX<< ", "<<centerY;
	this->setPos(centerX,centerY);
	*/
}
Exemplo n.º 2
0
QPoolRectObject::QPoolRectObject
(
	QPoolEngine* engine,
	std::shared_ptr<engine::Object> poolObject
)
:
QPoolObject(engine,poolObject)
{
	// Compute geometric properties
    std::shared_ptr<engine::RectangleShape> rectShape
    (
        std::static_pointer_cast<engine::RectangleShape>(poolObject->shape())
    );
	
	double centerX = poolObject->shape()->center()[0];
	double centerY = poolObject->shape()->center()[1];
    double w = rectShape->width();
	double h = rectShape->height();

	this->setRect
	(
		centerX-0.5*w,
		centerY-0.5*h,
		rectShape->width(),
		rectShape->height()
    );
}
Exemplo n.º 3
0
void PlatformDemoState::buildPhysics()
{
    auto groundBody = xy::Component::create<xy::Physics::RigidBody>(m_messageBus, xy::Physics::BodyType::Static);
    
    xy::Physics::CollisionRectangleShape rectShape({ 128.f, 1080.f });
    groundBody->addCollisionShape(rectShape);
    rectShape.setRect({ 128.f, 1080.f - 128.f, 2560.f, 128.f });
    groundBody->addCollisionShape(rectShape);
    rectShape.setRect({ 2688.f, 0.f, 128.f, 1080.f });
    groundBody->addCollisionShape(rectShape);
    rectShape.setRect({ 128.f, -20.f, 2560.f, 20.f });
    groundBody->addCollisionShape(rectShape);

    //add platforms
    std::vector<sf::Vector2f> points = 
    {
        {420.f, 800.f},
        {400.f, 765.f},
        {784.f, 765.f},
        {768.f, 800.f}
    };
    xy::Physics::CollisionEdgeShape ce(points);
    groundBody->addCollisionShape(ce);
    
    points =
    {
        { 2020.f, 639.f },
        { 2000.f, 604.f },
        { 2384.f, 604.f },
        { 2364.f, 639.f }
    };
    ce.setPoints(points);
    groundBody->addCollisionShape(ce);

    points =
    {
        { 1690.f, 533.f },
        { 1670.f, 497.f },
        { 2054.f, 497.f },
        { 2034.f, 533.f }
    };
    ce.setPoints(points);
    groundBody->addCollisionShape(ce);

    points =
    {
        { 1230.f, 700.f },
        { 1210.f, 665.f },
        { 1584.f, 665.f },
        { 1564.f, 700.f }
    };
    ce.setPoints(points);
    groundBody->addCollisionShape(ce);

    auto entity = xy::Entity::create(m_messageBus);
    entity->addComponent(groundBody);

    m_scene.addEntity(entity, xy::Scene::Layer::BackFront);
}
Exemplo n.º 4
0
		void SFML::DrawFilledRect( Gwen::Rect rect )
		{
			Translate( rect );

			#if SFML_VERSION_MAJOR == 2
			sf::RectangleShape rectShape( sf::Vector2f( rect.w, rect.h ) );
			rectShape.SetPosition( rect.x, rect.y );
			rectShape.SetFillColor( m_Color );

			m_Target.Draw( rectShape );
			#else
			m_Target.Draw( sf::Shape::Rectangle( rect.x, rect.y, rect.x + rect.w, rect.y + rect.h, m_Color ) );
			#endif
		}
Exemplo n.º 5
0
void QPoolRectObject::size(double width, double height)
{
	// Set size of engineObject
    std::shared_ptr<engine::RectangleShape> rectShape
    (
        std::static_pointer_cast<engine::RectangleShape>(poolObject()->shape())
    );
	rectShape->size(width,height);
	
	QRectF newRect(this->rect());
	newRect.setWidth(width);
	newRect.setHeight(height);
	
	this->setRect(newRect);
}
Exemplo n.º 6
0
		void SFML::DrawTexturedRect( Gwen::Texture* pTexture, Gwen::Rect rect, float u1, float v1, float u2, float v2 )
		{
#if SFML_VERSION_MAJOR == 2
			const sf::Texture* tex = static_cast<sf::Texture*>( pTexture->data );
#else 
			const sf::Image* tex = static_cast<sf::Image*>( pTexture->data );
#endif 

			if ( !tex ) 
				return DrawMissingImage( rect );

			Translate( rect );
		
#if SFML_VERSION_MAJOR == 2
			u1 *= tex->GetWidth();
			v1 *= tex->GetHeight();

			u2 *= tex->GetWidth();
			u2 -= u1;

			v2 *= tex->GetHeight();
			v2 -= v1;

			sf::RectangleShape rectShape( sf::Vector2f( rect.w, rect.h ) );
			rectShape.SetPosition( rect.x, rect.y );
			rectShape.SetTexture( tex );
			rectShape.SetTextureRect( sf::IntRect( u1, v1, u2, v2 ) );
			
			m_Target.Draw( rectShape );
#else
			tex->Bind();

			glColor4f(1, 1, 1, 1 );

			glBegin( GL_QUADS );
				glTexCoord2f( u1, v1 );		glVertex2f(rect.x,     rect.y);
				glTexCoord2f( u1, v2 );		glVertex2f(rect.x,     rect.y + rect.h);
				glTexCoord2f( u2, v2 );		glVertex2f(rect.x + rect.w, rect.y + rect.h);
				glTexCoord2f( u2, v1 );		glVertex2f(rect.x + rect.w, rect.y) ;
			glEnd();

			glBindTexture( GL_TEXTURE_2D, 0);
#endif
		}
Exemplo n.º 7
0
int main()
{
    // create a window
    sf::Event event;
    sf::RenderWindow window(sf::VideoMode(300, 300), "Hi");
    //Create a shape 
    // circle
    sf::CircleShape circleShape(50);
    circleShape.setFillColor(sf::Color::Red);
    circleShape.setOutlineColor(sf::Color::Blue);
    circleShape.setOutlineThickness(3);

    // rectangle
    sf::RectangleShape rectShape(sf::Vector2f(50,50));
    rectShape.setFillColor(sf::Color::Green);

    // game loop 
    while(window.isOpen())
    {
        // handle events 
        sf::Event event;
        while(window.pollEvent(event))
        {
           if(event.type == sf::Event::Closed)
               window.close();

        }
        // update the scene
        rectShape.setRotation(30);
        rectShape.move(sf::Vector2f(.11f, 0));
        // render cycle
        window.clear(sf::Color::Black);
        // draw the objects
        window.draw(circleShape);
        window.draw(rectShape);
        window.display();
    }
}
Exemplo n.º 8
0
void QPoolRectObject::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
	QPoolObject::mousePressEvent(event);
	
	std::shared_ptr<engine::RectangleShape> rectShape
	(
		std::static_pointer_cast<engine::RectangleShape>
		(
			poolObject()->shape()
		)
	);
	
	// Update geometry
	double width ( rectShape->width() );
	double height ( rectShape->height() );
	
	int size ( (width<height) ? width : height );
	bool horizontal ( (width<height) ? false : true );
	int ratio ( horizontal ? width/height : height/width );
	
	engine()->ui()->sizeBox->setValue( size );
	engine()->ui()->aspectRatioBox->setValue ( ratio );
	engine()->ui()->horizontalBox->setChecked( horizontal );
}