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 - Inflammatory Nugget

Pages: [1] 2
1
Graphics / Re: Delayed rotation
« on: January 19, 2014, 09:34:33 pm »
Hello again,

I implemented the code in your link into my program like this:
...
shape[1].setRotation(atan2(mouse.y - player.y, mouse.x - player.x) * 180 / PI);
                short temp = angle_difference(shape[1].getRotation(), shape[0].getRotation());
                if (temp > 1)
                        shape[0].rotate(1);
                else if (temp < -1)
                        shape[0].rotate(-1);
                else
                        shape[0].setRotation(shape[1].getRotation());
...
short angle_difference(float angle1, float angle2){
        return ((((static_cast<short>(angle1 - angle2)) % 360) + 540) % 360) - 180;
}
Thank you very much, panithadrum. My program is now running as I wanted  ;D

2
Graphics / Delayed rotation
« on: January 19, 2014, 07:46:47 pm »
Good day,

let's cut to the chase, shall we?

https://www.dropbox.com/s/f4w3ydjm2f8tu4m/Release.rar

This is a small test program in which a green square turns without delay towards the mouse pointer. The red square underneath does the same, but at a lower speed. When the user moves his mouse over the white line, the red square turns the opposite direction of which it is supposed to turn. This means that when the mouse pointer moves over the white line by going up, the red square turns clockwise while it should be turning counterclockwise.

This is the full code of the program:
#include <SFML\Graphics.hpp>
#include <cmath>
#include <thread>
#include <chrono>
// define PI
#define PI 3.14159265
// main
int main(){
        sf::Vector2i mouse;
        sf::Vector2f player;
        sf::RectangleShape shape[3];
        shape[0].setPosition(400, 300);
        shape[0].setSize(sf::Vector2f(200, 200));
        shape[0].setOrigin(100, 100);
        shape[0].setFillColor(sf::Color::Red);
        shape[1].setPosition(400, 300);
        shape[1].setSize(sf::Vector2f(100, 100));
        shape[1].setOrigin(50, 50);
        shape[1].setFillColor(sf::Color::Green);
        shape[2].setPosition(400, 300);
        shape[2].setSize(sf::Vector2f(400, 1));
        shape[2].setFillColor(sf::Color::White);
        player = shape[0].getPosition();
        sf::RenderWindow window(sf::VideoMode(800, 600), "test", sf::Style::Close);
        sf::Event event;
        while (window.isOpen()){
                // check events
                while (window.pollEvent(event)){
                        switch (event.type){
                        case sf::Event::KeyPressed:
                                if (event.key.code == sf::Keyboard::Escape)
                                        window.close();
                                break;
                        case sf::Event::Closed:
                                window.close();
                                break;
                        case sf::Event::MouseMoved:
                                mouse = sf::Mouse::getPosition(window);
                                break;
                        default:
                                break;
                        }
                }
                // logic
                std::this_thread::sleep_for(std::chrono::milliseconds(10));
                shape[1].setRotation(atan2(mouse.y - player.y, mouse.x - player.x) * 180 / PI);
                if (shape[0].getRotation() < shape[1].getRotation() - 1)
                        shape[0].rotate(1);
                else if (shape[0].getRotation() > shape[1].getRotation() + 1)
                        shape[0].rotate(-1);
                else
                        shape[0].setRotation(shape[1].getRotation());
                // draw
                window.clear(sf::Color::Black);
                window.draw(shape[2]);
                window.draw(shape[0]);
                window.draw(shape[1]);
                window.display();
        }
}
I hope you understand the issue.

3
Graphics / Re: Need help with render methods for different layers
« on: January 09, 2014, 10:01:18 pm »
Alright, thank you both for your help and suggestions.
Quote
How many texts did you have before the performance of rendering them became an issue? And what's the alternative?
I haven't tried to find the maximum amount of sf::Text objects before slowdown kicks in. I came to the conclusion that you should try to limit the amount of calls to sf::RenderWindow::draw. Is this incorrect?

Also, could sf::RenderTexture serve a purpose in my program?

4
Graphics / Need help with render methods for different layers
« on: January 08, 2014, 09:37:27 pm »
Hello,

I am attempting to create a video game with a top-down perspective. However, I'm having trouble with finding the best way to render all of the graphics to the sf::RenderWindow. The environment should have 8 different layers:

-1: This is the floor.
-2: This layer includes objects that cannot be moved or rotated. Assets, one could call them.
-3: There should also be a layer for effects, such as some dust kicking up. All objects in this layer should be animations which are removed once finished.
-4: Layer 4 consists of all the characters and objects which the player or other characters can interact with.
-5: This layer has the same base as layer 2, however it includes objects which should be placed over the characters, such as a roof or a treetop.
-6: The final layer includes all the UI: buttons, health bars, indicators...
-7: This should be a layer for all sf::Texts. But by trial I learned that a std::vector<sf::Text*> is not the way to go, because of the many calls to sf::RenderWindow::draw().
-8: This layer consists of a single sf::Sprite that replaces the standard mouse cursor.

I imagine layer 1, 2 and 5 should be sf::VertexArrays, as the objects are static. I'm clueless over what way layer 3, 4, 6 and 7 should be rendered. Ideally, the environment of the game should be one big world with seamless transitions between areas. That means no loading screens or slowdowns during gameplay.

What would be the best render method for every layer? Are there too many layers? Am I asking too much?

Any help would be appreciated.

5
System / Re: sf::Thread has no default constructor
« on: August 13, 2013, 10:53:16 am »
Oh, thanks for telling me!

6
System / Re: sf::Thread has no default constructor
« on: August 13, 2013, 08:57:31 am »
Good morning,

My program runs perfectly fine now. Here's what it looks like:
#include <SFML\System.hpp>
#include <iostream>
class test_class{
private:
        test_class():test_thread(&test_class::loop, this){}
        int *a_p;
public:
        test_class::test_class(int& a):test_thread(&test_class::loop, this),a_p(&a){
                a_p = &a;
        }
        void loop(){
                while(*a_p < 50){
                        std::cout << *a_p << std::endl;
                }
        }
        sf::Thread test_thread;
};
I thank you for your help :D

7
System / Re: sf::Thread has no default constructor
« on: August 12, 2013, 11:02:35 pm »
Er, how exactly? The tutorial nor the thread I linked to tells me how to. Maybe I'm just not awake enough to do this  :-\

Thanks for the swift responses btw, Mr Geedot.

8
System / Re: sf::Thread has no default constructor
« on: August 12, 2013, 10:22:23 pm »
Quote from: The thread tutorial, surprisingly... ( http://www.sfml-dev.org/tutorials/2.1/system-thread.php )
If you want to use a sf::Thread inside a class, don't forget that it doesn't have a default constructor. Therefore, you have to initialize it directly in the constructor's initialization list
It's also written by Laurent in the forum thread that you linked, with a little code example. :o
Yes, that's... what I did?

9
System / sf::Thread has no default constructor
« on: August 12, 2013, 09:30:46 pm »
Greetings,

I was trying to create a class in a separate header. As soon as the constructor for the class would be called, a thread inside that class would run. However, declaring a sf::Thread in a class gives some issues. So I tried to search the web and  I found this forum thread: http://en.sfml-dev.org/forums/index.php?topic=7906.msg52768#msg52768. I attempted what was suggested in this thread:
#include <SFML\System.hpp>
#include <iostream>
class test_class{
private:
        test_class():test_thread(&test_class::loop, this){}
        int *a_p;
        sf::Thread test_thread;
public:
        test_class::test_class(int& a){
                a_p = &a;
        }
        void loop(){
                while(*a_p < 50){
                        std::cout << *a_p << std::endl;
                }
        }
};
However, sf::Thread has no default constructor, so I got the following error:
]1>c:\users\frank\documents\visual studio 2010\projects\cppapplication_4\test.h(9): error C2512: 'sf::Thread' : no appropriate default constructor available
I'm sort of confused what to do next  :-\

Any help will be appreciated.

10
General / Re: sf::NonCopyable error?
« on: August 01, 2013, 10:19:02 am »
Ah, thank you Laurent! This little piece of advice has been very helpful.

My program now runs perfectly fine.

11
General / Re: sf::NonCopyable error?
« on: August 01, 2013, 08:01:48 am »
Thank you for your response. However, I can't used std::ref, because I am using Visual Studio C++ 2010...

I'll have another look at my code and see if I can work around it myself.

12
General / sf::NonCopyable error?
« on: July 31, 2013, 07:58:47 pm »
Greetings,

I have been fiddling around with SFML recently, and I wrote the following program:
#include <iostream>
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include <SFML\Audio.hpp>
#include <SFML\System.hpp>
using namespace std;

struct main_variables{
public:
        sf::Sound main_variables::clock_ticking_1;
        sf::RenderWindow main_variables::application;
        int main_variables::seconds;
};

bool timer(main_variables& m_1);
bool sound_player(main_variables& m_1);

int main(){
        // main variables
        main_variables m;
        m.seconds = 0;
        // icon
        sf::Image icon;
        if(!icon.loadFromFile("data/clock_icon.png"))
                return 1;
        m.application.setIcon(32, 32, icon.getPixelsPtr());
        m.application.create(sf::VideoMode(300, 300, 64), "Clock", sf::Style::Close);
        m.application.setFramerateLimit(30);
        // clock_t
        sf::Texture clock_t;
        if(!clock_t.loadFromFile("data/clock.png"))
                return 1;
        // long_pointer_t
        sf::Texture long_pointer_t;
        if(!long_pointer_t.loadFromFile("data/clock_long_pointer.png"))
                return 1;
        // short_pointer_t
        sf::Texture short_pointer_t;
        if(!short_pointer_t.loadFromFile("data/clock_short_pointer.png"))
                return 1;
        // longest pointer_t
        sf::Texture longest_pointer_t;
        if(!longest_pointer_t.loadFromFile("data/clock_longest_pointer.png"))
                return 1;
        short_pointer_t.setSmooth(1);
        // clock
        sf::RectangleShape clock(sf::Vector2f(300,300));
        clock.setTexture(&clock_t);
        clock.setPosition(0, 0);
        // long_pointer
        sf::RectangleShape long_pointer(sf::Vector2f(125,20));
        long_pointer.setTexture(&long_pointer_t);
        long_pointer.setOrigin(5,10);
        long_pointer.setPosition(150, 150);
        // short pointer
        sf::RectangleShape short_pointer(sf::Vector2f(100,20));
        short_pointer.setTexture(&short_pointer_t);
        short_pointer.setOrigin(5,10);
        short_pointer.setPosition(150, 150);
        // longest pointer
        sf::RectangleShape longest_pointer(sf::Vector2f(125,20));
        longest_pointer.setTexture(&longest_pointer_t);
        longest_pointer.setOrigin(5,10);
        longest_pointer.setPosition(150, 150);
        // sound
        sf::SoundBuffer clock_ticking_1_b;
        if(!clock_ticking_1_b.loadFromFile("data/clock_ticking_2.wav"));
        sf::Sound clock_ticking_1;

        clock_ticking_1.setBuffer(clock_ticking_1_b);
        // event
        sf::Event event;
        // threads
        sf::Thread timer_thread(&timer, m);
        timer_thread.launch();
        sf::Thread sound_player_thread(&sound_player, m);
        sound_player_thread.launch();

        while(m.application.isOpen()){
                while(m.application.pollEvent(event)){
                        if (event.type == sf::Event::Closed ||(event.KeyPressed && event.key.code == sf::Keyboard::Escape)){
                                goto exit;
                        }
                }
                if(m.seconds == (60*60*12))
                        m.seconds = 0;
                longest_pointer.setRotation(static_cast<float>(m.seconds*6-90));
                long_pointer.setRotation(static_cast<float>(m.seconds*6/60-90));
                short_pointer.setRotation(static_cast<float>(m.seconds*6/60/60-90));
               
                m.application.clear(sf::Color::Black);
                m.application.draw(clock);
                m.application.draw(short_pointer);
                m.application.draw(long_pointer);
                m.application.draw(longest_pointer);
                m.application.display();
        }
        exit:
                m.application.close();
                cout << "exiting program..." << endl;
                return 0;
}

bool timer( main_variables& m_1){
        while( m_1.application.isOpen()){
                sf::sleep(sf::seconds(1));
                m_1.seconds++;
        }
        return 0;
}

bool sound_player( main_variables& m_1){
        while( m_1.application.isOpen()){
                m_1.clock_ticking_1.play();
                sf::sleep(sf::seconds(10));
        }
        return 0;
}

The output:
1>------ Build started: Project: CppApplication_2, Configuration: Debug Win32 ------
1>  main.cpp
1>c:\users\frank\documents\visual studio 2010\projects\cppapplication_2\main.cpp(68): warning C4390: ';' : empty controlled statement found; is this the intent?
1>c:\sfml\include\sfml\window\window.hpp(476): error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'
1>          c:\sfml\include\sfml\system\noncopyable.hpp(67) : see declaration of 'sf::NonCopyable::NonCopyable'
1>          c:\sfml\include\sfml\system\noncopyable.hpp(42) : see declaration of 'sf::NonCopyable'
1>          This diagnostic occurred in the compiler generated function 'sf::Window::Window(const sf::Window &)'
1>c:\sfml\include\sfml\graphics\rendertarget.hpp(419): error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'
1>          c:\sfml\include\sfml\system\noncopyable.hpp(67) : see declaration of 'sf::NonCopyable::NonCopyable'
1>          c:\sfml\include\sfml\system\noncopyable.hpp(42) : see declaration of 'sf::NonCopyable'
1>          This diagnostic occurred in the compiler generated function 'sf::RenderTarget::RenderTarget(const sf::RenderTarget &)'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I have no idea why the compiler gives me these errors. As far as I can see, there are no copies being made of m.application or of m.clock_ticking_1, they are only being passed as a reference.

13
General / Re: Troubles with setting up SFML 2.0
« on: July 27, 2013, 06:28:15 pm »
And wasted a lot of time trying to set it up with Code::Blocks and also half a day having trouble with installing Visual Studio 2010 after having installed Visual Studio 2012 (uninstalling Visual Studio 2012 Express doesn't remove all files, and Visual Studio 2010 tries to use those, even though they are not compatible).

But in the end it works! \:D/

14
General / Re: Troubles with setting up SFML 2.0
« on: July 27, 2013, 12:55:51 pm »
It works, it finally works :,)

http://i.imgur.com/gnMswLk.png

Just beautiful.

There are mainly two problems with gcc on Windows:
- there are too many variants of it, that are of course incompatible with each other; it's a hell to find a match between one's gcc and a precompiled library
- people don't read the SFML tutorials carefully

The TDM (SJLJ) pre-compiled SFML package works out-of-the-box with Code::Blocks 12.11's included MinGW. This is written in red in the "Getting started" tutorial.
To be honest, it's possible that I have skipped trough some parts in my haste to see SFML working.

15
General / Re: Troubles with setting up SFML 2.0
« on: July 27, 2013, 08:03:14 am »
"...and with Code::Blocks."

The high amount of "The application has stopped running" messages that it rubbed into my face make me believe otherwise. I think I'll try out Visual Studio Express, if you don't mind...

Pages: [1] 2