Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Draw point  (Read 5888 times)

0 Members and 1 Guest are viewing this topic.

hoocker

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Draw point
« on: November 08, 2012, 11:52:03 pm »
I have a very simple code and would like to know how can I when I click with the mouse on the screen and draw a point when clicking a second time, a second point to draw a line connecting one point to another?
My code so far is this:
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
#include <math.h>
#define PI 3.1416
#include "Vector2D.h"

using namespace std;

int main(){
    // Inicializacao da biblioteca
    sf::RenderWindow* app = new sf::RenderWindow(sf::VideoMode(800, 600, 32), "Exercicio 2");
    Vector2D vetor(3,4);
    Vector2D va(3,4);
    Vector2D vb(4,5);
    va+=vb;

    // Gameloop - Le os eventos
    while (app->IsOpened()) {
         //Leitura dos eventos
         sf::Event* event = new sf::Event();
         while (app->GetEvent(*event)) {
            if (event->Type == sf::Event::Closed) {
                app->Close();
            }
        }

        if (app->GetInput().IsKeyDown(sf::Key::Escape)) {//se apertar ESC o jogo fecha
            return EXIT_SUCCESS;
        }



        app->Clear(sf::Color(255, 255, 255));

        sf::Shape Circle = sf::Shape::Circle(200, 200, 5, sf::Color(125, 200, 240), 1, sf::Color(0, 0, 0));

        app->Draw(Circle);
        app->Display();

    }
    return EXIT_SUCCESS;
}
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Draw point
« Reply #1 on: November 09, 2012, 12:35:57 am »
I'd advise you to use SFML 2, since it's less buggy and provides a few nice features which would make it easy to do what you want (with sf::VertexArray).

With SFML 1.6 you can use sf::Shape::Line(..) and pass in the position of the two points.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

hoocker

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Draw point
« Reply #2 on: November 09, 2012, 12:43:13 am »
And by using this command sf :: Shape :: Line (..), when I click a point will come where I clicked?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Draw point
« Reply #3 on: November 09, 2012, 12:47:56 am »
And by using this command sf :: Shape :: Line (..), when I click a point will come where I clicked?
No that's called programming... ;D
You have to learn how to handle input with SFML (which is way easier in SFML 2 btw. ;) ).

You can do it event based or with the input class.

I suggest you read all related tutorials, on the tutorial section and take a good look at the full documentation. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

hoocker

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Draw point
« Reply #4 on: November 09, 2012, 12:58:27 am »
Ok, I'll take a look at the documentation and anything I ask again here, thanks

Brodal

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Email
Re: Draw point
« Reply #5 on: November 10, 2012, 01:20:03 pm »
For registering single clicks or keyboard presses at a time events are easier to use than inputs. Inputs will register far more than one press each time.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Draw point
« Reply #6 on: November 10, 2012, 02:16:36 pm »
For registering single clicks or keyboard presses at a time events are easier to use than inputs. Inputs will register far more than one press each time.
In SFML 1.6 the difference between the two 'systems' are only on the surface and the sf::Input class also depends on events, but in SFML 2 the system are strictly separated and sf::Mouse/sf::Keyboard don't have anything to do with events and thus the sf::Keyboad/sf::Mouse method could in theory be slightly preciser. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything