TestBox(bool isCollidable) : sg::Entity(isCollidable) { r0.setSize(sf::Vector2f(100.0f, 50.0f)); r0.setOrigin(50.0f, 25.0f); this->addDrawable(r0, false); bs.addShape(r0); r1.setRadius(40.0f); r1.setOrigin(40.0f, 40.0f); r1.move(100.0f, 0.0f); r1.scale(2.0f, 1.0f); this->addDrawable(r1, false); bs.addShape(r1); r2.setSize(sf::Vector2f(250.0f, 10.0f)); r2.setOrigin(125.0f, 5.0f); r2.rotate(-90.0f); this->addDrawable(r2, false); bs.addShape(r2); r3.setRadius(40.0f); r3.setOrigin(40.0f, 40.0f); r3.move(-100.0f, 0.0f); this->addDrawable(r3, false); bs.addShape(r3); //bs.rotate(-45.0f); this->addTransformable(bs); //this->rotate(45.0f); }
Ball(float mX, float mY) { shape.setPosition(mX, mY); shape.setRadius(defRadius); shape.setFillColor(defColor); shape.setOrigin(defRadius, defRadius); }
Stone (float x, float y, float a, float b) { velocity.x = x; velocity.y = y; s.setRadius(radius); s.setOrigin(radius,radius); s.setFillColor(sf::Color::Black); s.setPosition(a,b); }
void createGeometry() { fill = type == Type::Follower ? sf::Color(198, 156, 109, 255) : sf::Color(0, 191, 243, 255); outline = type == Type::Follower ? sf::Color(166, 124, 82, 255) : sf::Color(64, 140, 203, 255); geometry.setRadius(radius); geometry.setPointCount(6); geometry.setFillColor(fill); geometry.setOutlineColor(outline); geometry.setOutlineThickness(2); geometry.setOrigin(radius, radius); }
void set_circle(sf::CircleShape& circle, const float value, const float norm_radius, const sf::Vector2f& position, const sf::Color& color) { const float radius{sqrt_value_tot_radius(value, norm_radius)}; circle.setRadius(radius); circle.setOrigin(radius, radius); circle.setPosition(position); circle.setFillColor(color); }
// Costruttore: prende come parametri la posizione iniziale // della pallina, sotto forma di due `float`. Ball(float mX, float mY) { // SFML usa un sistema di coordinate avente l'origine // posizionata nell'angolo in alto a sinistra della // finestra. // {Info: coordinate system} shape.setPosition(mX, mY); shape.setRadius(defRadius); shape.setFillColor(defColor); shape.setOrigin(defRadius, defRadius); }
cerclesTransparents(): _mesCercles(), __vectCercles() { sf::Vector2u tailleWindow = _window.getSize(); unsigned int hauteur = tailleWindow.y; unsigned int largeur = tailleWindow.x; float rayon = 400; for(int i = 0 ; i < 10; i++) { _mesCercles.setOrigin(rayon, rayon); _mesCercles.setPosition(400,400); _mesCercles.setRadius(rayon); _mesCercles.setFillColor(sf::Color(0.0, 0.0 + (25*i) , 255 - (25*i), 127)); rayon -= 25; __vectCercles.push_back(_mesCercles); } cout << "Taille du vect --> " << __vectCercles.size() << endl; }
Ball(float mX, float mY) { shape.setPosition(mX, mY); shape.setRadius(ballRadius); shape.setFillColor(sf::Color::Red); shape.setOrigin(ballRadius, ballRadius); }
void Utilities::centerOrigin( sf::CircleShape& circle ) { sf::FloatRect bounds = circle.getLocalBounds(); circle.setOrigin( std::floor( bounds.left + bounds.width / 2.0f ), std::floor( bounds.top + bounds.height / 2.0f ) ); }
int main() { sf::Clock clock; double s = 0; double viewZoom = 1.0f; srand(time(0)); for (u32 i = 0; i < PN; i++) { particule[i]._px = rand() % WINX; particule[i]._py = rand() % WINY; if (INITIAL_SPEED_ACTIVATE) { particule[i]._mx = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV; particule[i]._my = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV; } else { particule[i]._mx = 0; particule[i]._my = 0; } particule[i]._mass = PAR_MASS; particule[i]._color = PCOLOR; } planet.setPosition(sf::Vector2f(WINX/2, WINY/2)); planet.setOrigin(sf::Vector2f(10.0f, 10.0f)); planet.setFillColor(sf::Color::Blue); win.create(sf::VideoMode(WINX, WINY), "ORBITE"); win.setFramerateLimit(MAXFPS); clock.restart(); while (win.isOpen()) { s = clock.restart().asSeconds(); s *= SPEED; sf::View view = win.getDefaultView(); view.zoom(viewZoom); while (win.pollEvent(eve)) { if (eve.type == sf::Event::Closed) win.close(); if (eve.type == sf::Event::KeyPressed) { if (eve.key.code == sf::Keyboard::Add) viewZoom -= 0.25f; else if (eve.key.code == sf::Keyboard::Subtract) viewZoom += 0.25f; else if (eve.key.code == sf::Keyboard::Space) { trace.clear(); for (u32 i = 0; i < PN; i++) { particule[i]._px = rand() % WINX; particule[i]._py = rand() % WINY; if (INITIAL_SPEED_ACTIVATE) { particule[i]._mx = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV; particule[i]._my = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV; } else { particule[i]._mx = 0; particule[i]._my = 0; } particule[i]._mass = PAR_MASS; particule[i]._color = PCOLOR; } } } } planet.setPosition((sf::Vector2f)sf::Mouse::getPosition(win)); for (u32 i = 0; i < PN; i++) { particule[i].updateToPosition(planet.getPosition(), PL_MASS, s); part[i].position = sf::Vector2f(particule[i]._px, particule[i]._py); part[i].color = particule[i]._color; if (ACTIVATE_ORBIT_TRACE) { sf::Vertex cpy = part[i]; trace.append(cpy); } } win.setView(view); win.clear(sf::Color::Black); win.draw(planet); win.draw(part); win.draw(trace); win.display(); } return (0); }
// Circle Shape void Unit::setRadius(float radius) { _circle.setRadius(radius); _circle.setOrigin(_circle.getRadius(), _circle.getRadius()); }