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 - Kojay

Pages: 1 ... 4 5 [6] 7
76
SFML projects / Re: Looking for a Few Bored People
« on: September 04, 2013, 02:39:28 am »
If you get a bunch of people all wishing to do some project, how do you decide what and who does what? It already sounds like a nightmare. Plus it's nice to have a lot of ideas for all sorts of wonderful projects but actually picking one is a commitment.

That said,

Quote
I, for one, am interested in all types of development!

Can share that feeling. I don't do this for a living and don't know if I could contribute to whatever this ends up being but I would not mind finding out.

77
General / Re: Rotating Help
« on: August 31, 2013, 11:44:32 pm »
sf::Sprite::getGlobalBounds takes into account transformations and returns a sf::FloatRect. Conveniently, the latter has a function to check intersection with other FloatRects.

78
SFML projects / Re: Thor 2.0
« on: August 31, 2013, 07:01:19 pm »
Is it necessary that thor::ParticleSystem be initialized with a sf::Texture, which in turn must have already been loaded? I find it impossible to have a system as member of a class without allocating it on the heap.

79
SFML wiki / Line Shape
« on: August 31, 2013, 12:14:50 pm »
Following my suggestion in the features section to add a sf::Line again, I looked to the wiki about adding the proposed class and found there is a page on it already.. I believe though the classes presented there are overkill and would suggest these instead:

Deriving from sf::Drawable

A simple class that derives from sf::Drawable only.

class sfLine : public sf::Drawable
{
public:
    sfLine(const sf::Vector2f& point1, const sf::Vector2f& point2):
        color(sf::Color::Yellow), thickness(5.f)
    {
        sf::Vector2f direction = point2 - point1;
        sf::Vector2f unitDirection = direction/std::sqrt(direction.x*direction.x+direction.y*direction.y);
        sf::Vector2f unitPerpendicular(-unitDirection.y,unitDirection.x);

        sf::Vector2f offset = (thickness/2.f)*unitPerpendicular;

        vertices[0].position = point1 + offset;
        vertices[1].position = point2 + offset;
        vertices[2].position = point2 - offset;
        vertices[3].position = point1 - offset;

        for (int i=0; i<4; ++i)
            vertices[i].color = color;
    }

    void draw(sf::RenderTarget &target, sf::RenderStates states) const
    {
        target.draw(vertices,4,sf::Quads);
    }


private:
    sf::Vertex vertices[4];
    float thickness;
    sf::Color color;
};
 

Deriving from sf::Shape
Header and source for a sf::LineShape, closely modelled after sf::RectangleShape. These can be easily added to one's copy of SFML with minor additions to the relevant CMakeLists.txt and the Graphics master header. Doxygen comments were removed for space.

#ifndef SFML_LINESHAPE_HPP
#define SFML_LINESHAPE_HPP

#include <SFML/Graphics/Export.hpp>
#include <SFML/Graphics/Shape.hpp>


namespace sf
{
        class SFML_GRAPHICS_API LineShape : public Shape
        {
                public :

                explicit LineShape(const Vector2f& point1, const Vector2f& point2);

                void setThickness(float thickness);

                float getThickness() const;

                float getLength() const;

                virtual unsigned int getPointCount() const;

                virtual Vector2f getPoint(unsigned int index) const;

                private :

    Vector2f m_direction; ///< Direction of the line
    float m_thickness;    ///< Thickness of the line
};

} // namespace sf


#endif // SFML_LINESHAPE_HPP
 

#include <SFML/Graphics/LineShape.hpp>
#include <cmath>


namespace sf
{

LineShape::LineShape(const Vector2f& point1, const Vector2f& point2):
    m_direction(point2 - point1)    
{
    setPosition(point1);
    setThickness(2.f);    
}


void LineShape::setThickness(float thickness)
{
    m_thickness = thickness;
    update();
}


float LineShape::getThickness() const
{
    return m_thickness;
}


float LineShape::getLength() const
{
    return std::sqrt(m_direction.x*m_direction.x+m_direction.y*m_direction.y);
}


unsigned int LineShape::getPointCount() const
{
    return 4;
}


Vector2f LineShape::getPoint(unsigned int index) const
{
    Vector2f unitDirection = m_direction/getLength();
    Vector2f unitPerpendicular(-unitDirection.y,unitDirection.x);

    Vector2f offset = (m_thickness/2.f)*unitPerpendicular;

    switch (index)
    {
        default:
        case 0: return offset;
        case 1: return (m_direction + offset);
        case 2: return (m_direction - offset);
        case 3: return (-offset);
    }
}

} // namespace sf
 

80
Feature requests / Re: A simple sf::Line (segment)
« on: August 26, 2013, 09:41:57 am »
Since it's not clear what the proposed class does, it it basically this:



Given point1 and point2, it draws a quad between vertices 0-3.

81
Feature requests / A simple sf::Line (segment)
« on: August 25, 2013, 07:31:04 pm »
This has been asked for here and on irc. The tutorial claims a line with no thickness is simply two sf::Vertex, whereas a line with thickness is a rotated rectangle.
However, there's a difference: if the user has two points and he wants a line segment between them with thickness, then boilerplate code needs to be written for said rectangle to achieve desired effect.

A simple class for line segments could look like this:

class sfLine : public sf::Drawable
{
public:
    sfLine(const sf::Vector2f& point1, const sf::Vector2f& point2):
        color(sf::Color::Yellow), thickness(5.f)
    {
        sf::Vector2f direction = point2 - point1;
        sf::Vector2f unitDirection = direction/std::sqrt(direction.x*direction.x+direction.y*direction.y);
        sf::Vector2f unitPerpendicular(-unitDirection.y,unitDirection.x);

        float halfThick = thickness/2;

        vertices[0].position = point1 + halfThick*unitPerpendicular;
        vertices[1].position = point2 + halfThick*unitPerpendicular;
        vertices[2].position = point2 - halfThick*unitPerpendicular;
        vertices[3].position = point1 - halfThick*unitPerpendicular;

        for (auto& vertex : vertices)
            vertex.color = color;
    }

    void draw(sf::RenderTarget &target, sf::RenderStates states) const
    {
        target.draw(vertices.data(),4,sf::Quads);
    }


private:
    std::array<sf::Vertex,4> vertices;
    float thickness;
    sf::Color color;
};
 

The c++11 keywords can be done away with, setters for color and thickness added, assert that the points are distinct.

Note how Thor library offers a line shape and given point1 and point2 a segment could be obtained this way:

auto myLine = thor::Shapes::line(point2-point1,sf::Color::Yellow, 3.f);
myLine.setPosition(point1);
 

But I do think this results in a 'heavier' myLine than the class presented above.




82
SFML projects / Re: Black Wolf - a cross-platform chess gui v0.2
« on: August 22, 2013, 05:24:52 pm »
It was indeed made using the library SFGUI, no customization. The board and piece art are courtesy of Peter Wong.

Word of advice tho, most projects using sfgui aren't customizing the UI and they start to all look the same, which feeds up a little and takes away some wow factor

True! Choice of board and piece art has now been added and customizing the look of the widgets is certainly in the plans.

Meanwhile though, it can be depressing to play blitz against a strong engine so the more immediate plans are:

-offer the ability to tweak engine options as well as longer time controls
-make the gui usable as a client to play online

83
SFML projects / Black Wolf, an open source chess gui - play on FICS!
« on: August 11, 2013, 06:27:56 am »
Black Wolf is an open source cross platform chess gui to play on the Free Internet Chess Server



Source at: https://github.com/Kojirion/blackWolf

84
SFML projects / Re: SFGUI (0.1.1 released)
« on: August 07, 2013, 07:08:10 am »
I can, but it means the class I built around the canvas needs to keep a reference to the big window the canvas is in. Ok no big deal, but otherwise the class doesn't care at all about big window.

85
SFML projects / Re: SFGUI (0.1.1 released)
« on: August 07, 2013, 03:55:03 am »
Good to see binary hasn't been left struggling all by himself  ;D

Needless to say, I think the new Canvas is what everyone looking for separate drawing areas was wishing for.
Is there any chance we will see it behave more like an sfml window, such as using sf::Views on it, or getting local mouse coordinates (getAbsolutePosition() isn't enough by itself for the latter).

86
SFML projects / Re: [LandS] SFML Jam Game
« on: August 06, 2013, 09:21:59 am »
Yes actually, built sfml 2.1 and it's in the path.

87
SFML projects / Re: [LandS] SFML Jam Game
« on: August 06, 2013, 02:19:38 am »
Tried the 64-bit linux version but got a segfault on launching it, so played the windows one instead.

Are you planning to add diagonal movement, or is that against the spirit of the game? It's definitely harder without.
Like the music.

88
General / Re: How to make a grid?
« on: August 02, 2013, 07:47:18 pm »
Have you checked the SFML Graphic tutorials to get familiar with how everything works?

Here's the above code in a basic working example

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(300, 150), "Dots");
    sf::CircleShape dot(5.f);
    dot.setFillColor(sf::Color::Yellow);

        const int nofRows = 5; //number of rows
        const int nofCols = 10; //number of columns
        const int distance = 30; //distance between dots
        const float offset = distance/2.f; //offset for odd rows
        const float height = std::sqrt(std::pow(distance,2.f) - std::pow(offset,2.f)); //height of triangles

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }

                window.clear();
                for (int i=0; i<nofRows; ++i){
                        for (int j=0; j<nofCols; ++j){
                                if (i%2==0) dot.setPosition(j*distance, i*height); //even rows
                                else dot.setPosition(j*distance+offset, i*height); //odd rows
                                window.draw(dot);
                        }
                }
                window.display();
        }

        return 0;
}
 

(had forgotten to take square root for correct height)
Good luck.

89
General / Re: How to make a grid?
« on: August 02, 2013, 06:47:36 pm »
That was a mere suggestion in kind of pseudo-code.

dot is whatever you want it to be. It can be a CirleShape, a Sprite, a class you write yourself with a setPosition() method. You can draw the same one multiple times; or you can have multiple and put them in a container - in which case
dot[i][j].setPosition()
is more like what you 'd have in your code.

90
General / Re: How to make a grid?
« on: August 02, 2013, 01:01:47 am »
Something like this?

const int nofRows;
const int nofCols;
const int distance; //distance between dots
const float offset = distance/2.f;
const float height = std::sqrt(std::pow(distance,2) - std::pow(offset,2));

for (int i=0; i<nofRows; ++i){
        for (int j=0; j<nofCols; ++j){
                if (i%2==0) dot.setPosition(j*distance, i*height);
                else dot.setPosition(j*distance+offset, i*height);
        }
}

Odd rows get offset by half the distance. Gap between rows is the height of the equilateral triangles.

Pages: 1 ... 4 5 [6] 7
anything