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

Pages: [1]
1
Graphics / Converting from Cartesian coordinate system to SFML.
« on: August 28, 2011, 04:00:03 pm »
Quote from: "Nexus"
Code: [Select]
Pos = Pos + a + b - a;
Code: [Select]
Pos += b;
You know that +a and -a sum up to zero? :D
You should write:
Code: [Select]
sf::Vector2f BaseEntity::GameCoordsToSFML(sf::Vector2f Pos)
{
   Pos.y = -Pos.y;
   Pos += sf::Vector2f(pRender->GetWidth() / 2.f, pRender->GetHeight() / 2.f);
   return Pos;
}

Although I find it strange that you also change the X coordinate, if you say that only the Y axis is inverted.


They aren't the same. Screen Center and View Center are different, because the view is moving around. Screen Center is the coordinate of the pixel in the middle of the screen.

You may have misunderstood what the function was meant to do, it is trying to convert game coordinates to which pixel that corresponds to on the screen. This position is dependent on where the view is looking so that is why that's included :)

Code: [Select]

sf::Vector2f BaseEntity::GameCoordsToSFML(sf::Vector2f Pos)
{
sf::Vector2<double> dPos;
dPos.x = Pos.x;
dPos.y = Pos.y;
dPos.y *= -1;
sf::Vector2<double> ScreenCentre = sf::Vector2<double>(pRender->GetWidth() / 2, pRender->GetHeight() / 2);
sf::Vector2<double> ViewCentre;
ViewCentre.x = pRender->GetView().GetCenter().x;
ViewCentre.y = pRender->GetView().GetCenter().y;

dPos = dPos + ViewCentre + (ScreenCentre - ViewCentre);

Pos.x = dPos.x;
Pos.y = dPos.y;

return Pos;
}


I know this has already been solved but I thought I would make a diagram of what situation the above code is useful for, in case anyone else needed it:



The green axis are SFML's coordinate system. The red box represents the pixels on the screen. The green axis is SFML's default origin and SFML's axis (note the Y axis runs in the opposite direction to the game coordinates)

The black axis are the game coordinates. The code takes a coordinate in game space and then converts that to the corresponding pixel on the screen. I hope it isn't too confusing as I can't imagine I am the only one who separated their game coordinates from SFML's.

2
General / SFML freezes when mouse moves (VS 2010)
« on: August 28, 2011, 03:20:16 pm »
Sorry for the bump, but I had a slight development.

The bug goes away when I change the size of the renderwindow from whatever it was when the bug started to appear (in the case of my engine 800 by 800) to something else.

If I then change the screen size back to 800 by 800 the freezing is gone but it eventually comes back.

This is bizarre and I can't really find any sort of pattern, I have been having a few RAM issues lately and this could be some weird manifestation of faulty RAM but I just thought I would update the thread in case anyone is seeing the same thing.

3
Graphics / Converting from Cartesian coordinate system to SFML.
« on: August 25, 2011, 12:53:23 am »
Have been bruteforcing it. Managed to find the answer:

Code: [Select]

sf::Vector2f BaseEntity::GameCoordsToSFML(sf::Vector2f Pos)
{
Pos.y *= -1;
Pos = Pos + pRender->GetView().GetCenter() + (sf::Vector2f(500,500) - pRender->GetView().GetCenter());
return Pos;
}


500,500 is the centre of the screen :)

4
Graphics / Converting from Cartesian coordinate system to SFML.
« on: August 25, 2011, 12:17:02 am »
Hi, my project is using the standard Cartesian system for position (X-axis goes right, Y-Axis goes Up) whereas SFML has an inverted Y axis.

I am trying to convert my game coordinates to SFML coordinates for drawing, it was working fine when I wasn't using views but now I have implemented that my algorithm for converting has failed completely.

Here is my current code:
Code: [Select]

sf::Vector2f BaseEntity::GameCoordsToSFML(sf::Vector2f Pos)
{
Pos.y *= -1;
return pRender->GetView().GetCenter() + Pos;
}

sf::Vector2f BaseEntity::SFMLToGameCoords(sf::Vector2f Pos)
{
Pos = Pos - pRender->GetView().GetCenter();
Pos.y *= -1;
return Pos;
}



I think I am forgetting something when converting because as soon as GetCenter() moves from the centre of the window the whole thing breaks down and it returns weird results.

I was thinking it might involve RenderWindow::ConvertCoords() but I have no idea really I have never played with views before.

5
General / SFML freezes when mouse moves (VS 2010)
« on: August 12, 2011, 04:55:09 pm »
Just did a test to see if they were all mouse movement events. Pretty much all of them are. Any ideas why running visual studio would increase the mouse movement events by 100 fold? :(

Lowering mouse dpi and polling rate does nothing to.

Code: [Select]


#include <iostream>
#include "SFML/System.hpp"
#include "SFML/Graphics.hpp"

int main()
{
    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
   
    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;

int Test = 0;
int Test2 = 0;

        while (App.PollEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
if (Event.Type == sf::Event::MouseMoved)
Test += 1;
Test2 += 1;
        }

std::cout << Test2 - Test << "\n";

        // Clear the screen (fill it with black color)
        App.Clear();

        // Display window contents on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}


Code just in case I am being retarded.

Edit: Just did a test on a hello world program. No slow downs, was probably never going to do anything but I thought I would just eliminate the possibility of it not being SFML at all.

6
General / SFML freezes when mouse moves (VS 2010)
« on: August 12, 2011, 04:43:13 pm »
Hi,

Whenever I run my SFML program through visual studio 2010 (this also happens in 2008) and move the mouse rapidly on top of the window the whole game locks up completely and it uses 100% of the first core on the CPU, as soon as I stop moving the mouse the problem immediately stops.

Restarting visual studio sometimes fixes it for a bit and running the .exe file directly from windows explorer always makes the problem go away but it's getting really annoying.

This also happens in a blank sfml project with just a renderwindow and nothing else so it is not my code.

I have a Razer Deathadder mouse, my theory for why this happens is that the mouse is sending events to the window faster than it can process them causing a build up of events? But that's just speculation.

I hope someone else has come across this problem it's making me feel like my games running slowly when it is just the mouse!

Specs:

Intel Dual Core 2.66Ghz
4GB Ram
Windows 7 64 bit
NVidia gtx 260

Thanks.

Update: Just did some tests printing out how many events are being processed

If Visual studio is running and I move the mouse I get 250 events per frame and it freezes. However if I run it without visual studio (directly clicking the exe) I get a maximum of 1. This is very strange, I'm going to try and figure out if these events are all mouse movement events or if something else is creeping in there that shouldn't be.

PS. Sometimes the event count reaches the thousands if I move the mouse fast enough.

Pages: [1]