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

Author Topic: Primitives, more points in polygon than are in code  (Read 3048 times)

0 Members and 1 Guest are viewing this topic.

ThreeDumps

  • Newbie
  • *
  • Posts: 34
    • View Profile
Primitives, more points in polygon than are in code
« on: July 18, 2011, 04:04:57 pm »
I want to make efect like in WOW. When skill is not ready he has a black rect. Rect is disappears like clock. From 12:00 to 12:15 to 12:30, to 12:45, 12:00, but smoothly. I have something like this:

Code: [Select]

#include <iostream>
#include <conio.h>
#include <SFML/Graphics.hpp>

int main()
{
sf::RenderWindow oknoAplikacji( sf::VideoMode( 800, 600, 32 ), "Craftsman" );

// Left top point in rect
float x1 = 150;
float y1 = 50;

// Right down point in rect
float x2 = 650;
float y2 = 550;

// Coords of moving point
float ax = (x1+x2)/2;
float ay = y1;

// stopien - size of move for moving point
int stopien = 10;

// time - time from break to next step
int time = 0;

// how meny point will not draw
int point=0;

while(1)
{
oknoAplikacji.Clear( sf::Color( 255, 0, 0 ) );

sf::Shape Polygon;
Polygon.SetColor(sf::Color(0,0,0,100));


// When my moving point (ax, ay) is in one of nine points
// that point must be deletet (or not draw)
if      (ax == x2 && ay == y1)
point = 1;
else if (ax == x2 && ay == (y1+y2)/2)
point = 2;
else if (ax == x2 && ay == y2)
point = 3;
else if (ax == (x1+x2)/2 && ay == y2)
point = 4;
else if (ax == x1 && ay == y2)
point = 5;
else if (ax == x1 && ay == (y1+y2)/2)
point = 6;
else if (ax == x1 && ay == y1)
point = 7;
else if (ax == (x1+x2)/2 && ay == y1 && point == 7)
{
// starts from begin
ax = (x1+x2)/2;
ay = y1;
point = 0;
}

// behavior of moving point (when go left, when down etc.)
if (time >= 5)
{
if (point == 0)
{
ax+=stopien;
if (ax > x2)
ax = x2;
}
else if (point == 1)
{
ay+=stopien;
if (ay > (y2+y1)/2)
ay = (y2+y1)/2;
}
else if (point == 2)
{
ay+=stopien;
if (ay > y2)
ay = y2;
}
else if (point == 3)
{
ax-=stopien;

if (ax < (x2+x1)/2)
ax = (x2+x1)/2;
}
else if (point == 4)
{
ax-=stopien;
if (ax < x1)
ax = x1;
}
else if (point == 5)
{
ay-=stopien;
if (ay < (y2+y1)/2)
ay = (y2+y1)/2;
}
else if (point == 6)
{
ay-=stopien;
if (ay < y1)
ay = y1;
}
else if (point == 7)
{
ax+=stopien;
if (ax > (x2+x1)/2)
ax = (x2+x1)/2;
}
time = 0;
}

// Points of my Polygon

// my movin point to...
Polygon.AddPoint(ax,ay, sf::Color(0,0,0));


// ...next pionts (if exists)
if ( point <= 0 )
Polygon.AddPoint(x2,y1, sf::Color(0,0,0));
if ( point <= 1 )
Polygon.AddPoint(x2,(y1+y2)/2, sf::Color(0,0,0));
if ( point <= 2 )
Polygon.AddPoint(x2,y2, sf::Color(0,0,0));
if ( point <= 3 )
Polygon.AddPoint((x1+x2)/2,y2, sf::Color(0,0,0));
if ( point <= 4 )
Polygon.AddPoint(x1,y2, sf::Color(0,0,0));
if ( point <= 5 )
Polygon.AddPoint(x1,(y1+y2)/2, sf::Color(0,0,0));
if ( point <= 6 )
Polygon.AddPoint(x1,y1, sf::Color(0,0,0));

// always being, middle top point (we start from this point, and end hear)
Polygon.AddPoint((x1+x2)/2,y1, sf::Color(0,0,0));

    // middle of rect
Polygon.AddPoint((x1+x2)/2,(y1+y2)/2+70, sf::Color(0,0,0));

// for safety ( i don`t whant to have time biger than range int
if (time < 5)
time++;

oknoAplikacji.Draw(Polygon);

// drawing ALL POINTS OF POLYGON!
for (unsigned int i=0;i<Polygon.GetNbPoints();i++)
oknoAplikacji.Draw(sf::Shape::Circle(Polygon.GetPointPosition(i).x, Polygon.GetPointPosition(i).y, 5, sf::Color(255,255,255)));

oknoAplikacji.Display();
}
return 0;
}


But... WTF is this :

I draw all Points in my poly so why i have else?
Code: [Select]
for (unsigned int i=0;i<Polygon.GetNbPoints();i++)
oknoAplikacji.Draw(sf::Shape::Circle(Polygon.GetPointPosition(i).x, Polygon.GetPointPosition(i).y, 5, sf::Color(255,255,255)));

Zinlibs

  • Full Member
  • ***
  • Posts: 127
    • View Profile
Primitives, more points in polygon than are in code
« Reply #1 on: July 18, 2011, 04:17:14 pm »
You just cannot use non-convex shapes with SFML. This is an openGL limitation.
Zoost & Zoom libraries : An easy way to create and handle geometric objets, animate and use them for better graphics !

ThreeDumps

  • Newbie
  • *
  • Posts: 34
    • View Profile
Primitives, more points in polygon than are in code
« Reply #2 on: July 18, 2011, 04:23:23 pm »
so what use to draw non-convex shapes?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Primitives, more points in polygon than are in code
« Reply #3 on: July 18, 2011, 04:28:15 pm »
You must decompose your concave shape into several convex shapes.
Laurent Gomila - SFML developer

ThreeDumps

  • Newbie
  • *
  • Posts: 34
    • View Profile
Primitives, more points in polygon than are in code
« Reply #4 on: July 18, 2011, 04:32:29 pm »
Ohh... I had hope that is other solution... Well :) I go to coding.

Thank you Laurent and Zinlibs for help :)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Primitives, more points in polygon than are in code
« Reply #5 on: July 18, 2011, 05:34:56 pm »
Quote from: "akwes"
so what use to draw non-convex shapes?
Use thor::ConcaveShape :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Haikarainen

  • Guest
Primitives, more points in polygon than are in code
« Reply #6 on: July 18, 2011, 08:28:36 pm »
Quote from: "Nexus"
Quote from: "akwes"
so what use to draw non-convex shapes?
Use thor::ConcaveShape :)


Your library just have a solution to all the small things SFML doesnt do :D I friggin love it.

Nice threadstart btw! Was thinking about doing something similiar myself :)

 

anything