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

Pages: [1]
1
Graphics / Re: Moving sf::View with mouse
« on: August 07, 2015, 09:18:49 pm »
I added the zooming code you linked and it works great. However, when i zoom in or out and then move the image with middle mouse button, the zoom resets to default value. I read through the code and noticed this:
sf::Vector2f pos((float)mPos_old.x-mPos.x, (float)mPos_old.y-mPos.y);
camera.move(pos.x, pos.y);
window.setView(camera); // If i remove this, i cant move the image but zoom works.
// If i dont remove it, zooming works but resets whe image is moved.
 
You should be aware that that function modifies the view that is used by the window and then sets the window to use that view.
When you set the view to your own view (camera), it's ignoring any alterations made by the zoom function.
You could either modify the function to pass your view as a parameter and it could alter that one or, after using the function, use something like camera = window.getView();
I got everything working now. Thank you for the help!  8)

2
Graphics / Re: Moving sf::View with mouse
« on: August 07, 2015, 05:44:07 pm »
I added the zooming code you linked and it works great. However, when i zoom in or out and then move the image with middle mouse button, the zoom resets to default value. I read through the code and noticed this:
sf::Vector2f pos((float)mPos_old.x-mPos.x, (float)mPos_old.y-mPos.y);
camera.move(pos.x, pos.y);
window.setView(camera); // If i remove this, i cant move the image but zoom works.
// If i dont remove it, zooming works but resets whe image is moved.
 

I also managed to make the view movable like i wanted but there is a little problem with it.
When i zoom out it moves very slowly and when i zoom in it goes way too fast when moving it.
This is because the size of the world co-ordinates are smaller when you zoom out and larger when you zoom in. You should consider converting the pixel co-ordinates of the mouse position to world co-ordinates.
If you're using views at all, you should really read that entire tutorial and make sure you fully understand it. It can be really confusing at first!
You find that this Wiki Tutorial explains the concept a little more clearly.

I tried multiplying the x and y values with the size of the view like:
Although the solution was given in my previous paragraph, I wanted to just say that the multiplication would needed to have been multiplied by the ratio of the view size to the window size. I don't know where you got the 32 from...
I tried to convert the pixel coordinates like you suggested:
sf::Vector2f pos = window.mapPixelToCoords(sf::Vector2i(mPos_old.x-mPos.x,mPos_old.y-mPos.y));
camera.move(pos.x, pos.y);
window.setView(camera);
 
but when i try to move the image it just moves somewhere really fast.
I read the view tutorial couple of times but i still cant get the hang of it :(
I will read it again but if you could provide some kind of example of how i should convert them i would appreciate that very much.

3
Graphics / Re: Moving sf::View with mouse
« on: August 07, 2015, 04:28:15 pm »
Did you try this;)

That looks just like what i need! Thanks  ;D

I also managed to make the view movable like i wanted but there is a little problem with it.
When i zoom out it moves very slowly and when i zoom in it goes way too fast when moving it.
Here is the code:
mPos = sf::Mouse::getPosition(window);
// ...
float x = (float)mPos_old.x-mPos.x;
float y = (float)mPos_old.y-mPos.y;
camera.move(x, y);
window.setView(camera);
// ...
mPos_old = mPos;
 

I tried multiplying the x and y values with the size of the view like:
float x = ((float)mPos_old.x-mPos.x)*camera.getSize().x/32;
float y = ((float)mPos_old.y-mPos.y)*camera.getSize().y/32;
 
but that dint work :-\

4
Graphics / Re: Moving sf::View with mouse
« on: August 07, 2015, 04:04:36 pm »
Actually i'm not sure how i should move it or what calculations i need to make to move it  :(
But i will try to move it by the change and see how that goes.

5
Graphics / Moving sf::View with mouse
« on: August 07, 2015, 11:47:30 am »
I have an sf::View which i want to move with my mouse. For example in Paint.net when you hold middle mouse button and then move your mouse, the image moves with the mouse. I want to achieve the same effect in SFML.
Also i want to zoom at the mouse position with the mouse wheel like in Paint.net. I have tried various solutions but none worked correclty.

Here is the code which i tried for moving the view:
mPos = sf::Mouse::getPosition(window);
camera.move(mPos.x, mPos.y);
window.setView(camera);

Thanks in advance.

6
Window / Re: Crash on pollEvent
« on: June 09, 2013, 08:08:19 pm »
Thats what i thought too. But i commented out every other thing in the original code but not the window creation and main loop, it doesnt crash during run time now but as soon as i click close on the title bar it crashes.

EDIT: Now it seems to crash in the game deconstructor. In original code.


EDIT2: All crashes were caused by state manager. I deleted it completely and the code works flawlessly!
Thx for help ;)

7
Window / Re: Crash on pollEvent
« on: June 09, 2013, 08:02:57 pm »
SO i made this code which is similiar to the original code but without any other things but the window creation.
This code works, i have no idea why the original doesnt.
#include <sfml/Graphics.hpp>
#include <iostream>

class Game
{
public:
        Game();
        void run();

private:
        sf::RenderWindow window;
};

Game::Game() : window(sf::VideoMode(800, 600), "sfml-app", 7U, sf::ContextSettings(0U, 0U, 10U))
{
}

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

int main()
{
        Game game;
        game.run();

        return 0;
}

8
Window / Re: Crash on pollEvent
« on: June 09, 2013, 07:24:27 pm »
The only thing that isnt working is the game::run function.
Unhandled exception at 0x771615de in sfml-app.exe: 0xC0000005: Access violation reading location 0xbaadf00d.
this is what happpens during debug at crash time.
I have already provided code for game::run and it is actually the same code as in that minimalist main function which is working. strange...

9
Window / Re: Crash on pollEvent
« on: June 09, 2013, 07:13:20 pm »
Removed it, no console errors now. BUt how is this going to fix the crash if i only keep looking at that minimalist main function which is working?

10
Window / Re: Crash on pollEvent
« on: June 09, 2013, 06:57:10 pm »
Here it is, everything in one main function. And what a surprise, it works now in this program but not in the original.

#include <sfml/Graphics.hpp>
#include <iostream>

int main()
{
        sf::RenderWindow window(sf::VideoMode(800, 600), "sfml-app", 7U, sf::ContextSettings(0U, 0U, 10U)), postShader(NULL);

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

Console errors:
Failed to set pixel format for device context -- cannot create OpenGL context
Failed to activate the window's context
Failed to activate the window's context

but no crash..

11
Window / Re: Crash on pollEvent
« on: June 09, 2013, 06:34:04 pm »
Ok here is main function:
int main()
{
        if (!sf::Shader::isAvailable())
        {
                return -1;
        }

        try
        {
                Game game;
                game.Run();
        }
        catch (std::exception& e)
        {
                std::cout << e.what() << std::endl;
                std::cin.get();
        }      
}

Here is constructor for Game class, thats where the window is created:
Game::Game() : window(sf::VideoMode(800, 600), "sfml-app", 7U, sf::ContextSettings(0U, 0U, 10U)), postShader(NULL) //Here window is created, i tried other methods but still crashing
{
        defaultFont.loadFromFile("AllOverAgain.ttf");
        frameTime = 0;
}

Here is the Game::Run function (thats whre the crash happens):
void Game::Run()
{
        while(window.isOpen())
        {
                timer.restart();

                sf::Event event;
                while(window.pollEvent(event)) //here crash
                {
                        stateManager.HandleEvent(event);
                        if (event.type == sf::Event::Closed)
                        {
                                window.close();
                        }
                }

                /*
                // Update
                stateManager.Update(frameTime);

                window.clear();
                stateManager.Draw();
                window.display();
                */


                frameTime = timer.getElapsedTime().asSeconds();
                if (frameTime > 0.1)
                {
                        frameTime = 0.1;
                }
        }
}

Anyway I am curious as of why you are using a unsigned int and not the enums SFML provides for style?

They caused some errors about too many arguments or smth

12
Window / Crash on pollEvent
« on: June 09, 2013, 06:17:16 pm »
Hello. I have a problem in my code but i dont know how to fix.
Here is the problematic code:
while(window.isOpen())
{
                sf::Event event;
                while(window.pollEvent(event))
                {
                        stateManager.HandleEvent(event);
                        if (event.type == sf::Event::Closed)
                        {
                                window.close();
                        }
                }
}

the crash happens in window.pollEvent when i start the program.
Here is code that create window:
Game::Game() : window(sf::VideoMode(800, 600), "sfml-app", 7U, sf::ContextSettings(0U, 0U, 10U)), postShader(NULL)
{
        defaultFont.loadFromFile("AllOverAgain.ttf");
}

definition in header:
sf::RenderWindow window;

WHat can i do to fix this?
I can give more code if needed.

Pages: [1]
anything