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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Mangocheese

Pages: [1]
1
Graphics / Deleting points in a shape
« on: March 25, 2010, 04:48:32 pm »
Thanks for the prompt replies!

My application only needs to display the shape so I know where my logical shape is. So I just added this to the SFML Shape source code:

Code: [Select]

void Shape::ClearShape()
{
myPoints.clear();
    // Put a placeholder for the center of the shape
    myPoints.push_back(Point())
}


Pretty easy. Although, I am not too sure how much it "breaks" the shape, but it doesn't matter for me since I just use the logical shape anyway.

2
Graphics / Deleting points in a shape
« on: March 25, 2010, 01:56:49 pm »
Hello again,

I searched high and low for a function or a way to delete the points within a shape, and I haven't been able to find anything!

How do I delete points from a shape?

Thanks

3
Graphics / Point inside polygon shape?
« on: March 24, 2010, 05:37:58 am »
I've done a bit of research and created some code (with help from http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/).

Below is my code, sloppy as it is, it does the trick. I hope it is helpful to those who need it. For this code, I found that I had to add the point twice into the vector. Can anyone refine the process, or am I on the right track?

Code: [Select]

#include <SFML/Graphics.hpp>
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

const double pi = 3.14;
const double twopi = 6.28;

struct Point
{
int x, y;
};

bool InsidePolygon(vector<Point> Poly, int sides, Point mouseCoods);
double Angle2D(double x1, double y1, double x2, double y2);

int main()
{
sf::RenderWindow App(sf::VideoMode(800,600,32), "Inside Polygon Test");

App.SetFramerateLimit(60);

sf::Event appEvent;
vector<Point> vPolygon;

sf::Shape Polygon;

while(App.IsOpened())
{
while(App.GetEvent(appEvent))
{
if(appEvent.Type == sf::Event::Closed)
{
App.Close();
}

if(appEvent.Type == sf::Event::MouseButtonPressed)
{
if(appEvent.MouseButton.Button == sf::Mouse::Left)
{
Point temp;

temp.x = appEvent.MouseButton.X;
temp.y = appEvent.MouseButton.Y;

if(InsidePolygon(vPolygon, vPolygon.size(), temp))
{
cout << "Inside." << endl;
}
}
if(appEvent.MouseButton.Button == sf::Mouse::Right)
{
Point temp;
temp.x = appEvent.MouseButton.X;
temp.y = appEvent.MouseButton.Y;

Polygon.AddPoint(temp.x, temp.y);

vPolygon.push_back(temp);
vPolygon.push_back(temp);
}
}
}

App.Clear();

App.Draw(Polygon);

App.Display();
}

return 0;
}

bool InsidePolygon(vector<Point> Poly, int sides, Point mouseCoods)
{
int i;
double angle=0;
Point p1,p2;

for (i=0;i<sides;i++) {
p1.x = Poly[i].x - mouseCoods.x;
p1.y = Poly[i].y - mouseCoods.y;
p2.x = Poly[(i+1)%sides].x - mouseCoods.x;
p2.y = Poly[(i+1)%sides].y - mouseCoods.y;
angle += Angle2D(p1.x,p1.y,p2.x,p2.y);
}

if (abs(angle) < pi)
return(FALSE);
else
return(TRUE);
}

double Angle2D(double x1, double y1, double x2, double y2)
{
   double dtheta,theta1,theta2;

   theta1 = atan2(y1,x1);
   theta2 = atan2(y2,x2);
   dtheta = theta2 - theta1;
   while (dtheta > pi)
      dtheta -= twopi;
   while (dtheta < -pi)
      dtheta += twopi;

   return(dtheta);
}


Thanks.  :D

4
Graphics / Point inside polygon shape?
« on: March 22, 2010, 03:01:32 pm »
Thanks, that piece of code helped out a lot!

5
Graphics / Point inside polygon shape?
« on: March 22, 2010, 02:07:27 pm »
Hello,

Is there any way to test if a point is within a polygon shape?

Also,

When a sprite is rotated, does it rotate the bounding box aswell?

Thanks!

Pages: [1]
anything