forked from veeableful/Quadtree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
55 lines (44 loc) · 1.35 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// QuadtreeSimple.cpp : Demonstrates the use of Quadtree using SFML
//
#include "Quadtree.h"
#include "Object.h"
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/Graphics/Font.hpp>
#include <iostream>
int main()
{
using namespace std;
sf::RenderWindow app( sf::VideoMode( 800, 600, 32 ), "Quadtree" );
app.setFramerateLimit( 60 );
sf::Font font;
font.loadFromFile( "/usr/share/fonts/TTF/DroidSans.ttf" );
Quadtree quadtree( 0.0f, 0.0f, 800.0f, 600.0f, 0, 3 );
quadtree.SetFont( font );
vector<Object> objects;
while( app.isOpen() ) {
sf::Event event;
sf::Vector2i mousePosition = sf::Mouse::getPosition( app );
while( app.pollEvent( event ) ) {
if ( event.type == sf::Event::KeyPressed ) {
if ( event.key.code == sf::Keyboard::Escape ) {
app.close();
}
}
if ( event.type == sf::Event::MouseButtonPressed ) {
objects.push_back( Object( mousePosition.x, mousePosition.y, 32, 32 ) );
}
}
app.clear();
for ( int n = 0; n < objects.size(); ++n ) {
quadtree.AddObject( &objects[n] );
objects[n].Draw( app );
}
quadtree.Draw( app );
vector<Object*> returnObjects = quadtree.GetObjectsAt( mousePosition.x, mousePosition.y );
cout << returnObjects.size() << endl;
quadtree.Clear();
app.display();
}
return 0;
}