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

Author Topic: Anyone Know What is Causing This?  (Read 3346 times)

0 Members and 1 Guest are viewing this topic.

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Anyone Know What is Causing This?
« on: January 31, 2011, 07:37:50 am »
I'm sure I'm just doing views wrong, but how would I fix this?



This should be a REALLY large image vertically. It seems to hold a 1:1 ratio along the X-Axis, but as you can see... the Y-Axis has been crushed from 90,000 to what look more like 5,000. ;( *tear*

Here is my minimal code that reproduces the error:
I'm getting good at this! ;D

Code: [Select]
#include <SFML\Graphics.hpp>

int main()
{
    sf::RenderWindow Window(sf::VideoMode::GetMode(0), "Laz's Interactive Map");

    sf::Shape Map;
    Map.AddPoint(0,0,sf::Color(0,100,0));
    Map.AddPoint(30000,0,sf::Color(0,100,0));
    Map.AddPoint(30000,90000,sf::Color(0,100,0));
    Map.AddPoint(0,90000,sf::Color(0,100,0));
    Map.EnableFill(true);
    Map.EnableOutline(false);

    sf::View MainView;
    MainView.SetFromRect(sf::FloatRect(0,0,30000,90000));
    MainView.Zoom(.4f);

    sf::Shape Circle = sf::Shape::Circle(5000,5000,2500,sf::Color::Red, 5, sf::Color::Red);

    while (Window.IsOpened()) {
        Window.Clear();

        Window.SetView(MainView);
            Window.Draw(Map);
            Window.Draw(Circle);

        Window.Display();
    }
    return 0;
}


PS: I'm am 90% sure that this is a View error... I am VERY sketchy in my views... I never know what I'm doing.

Thanks in advance.
-Wander

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Anyone Know What is Causing This?
« Reply #1 on: January 31, 2011, 07:47:45 am »
The content of the view is mapped to the window, so here you are mapping 30000x90000 units to, let's say, 1024x768 pixels. That's why the Y axis is so much squeezed. If you don't want your scene to be distorted, your view must have the same aspect ratio as your window.
Laurent Gomila - SFML developer

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Anyone Know What is Causing This?
« Reply #2 on: February 01, 2011, 04:52:31 am »
So, I'm going to have to change my view's size so it won't hold my REALLY large image?
-Wander

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Anyone Know What is Causing This?
« Reply #3 on: February 01, 2011, 06:01:17 am »
Oh! I see what you are saying. But how would I make it change for each different screen size its on.

I tried putting variables in as a replacement for some of the values in the sf::FloatRect but it made my program crash. :/
-Wander

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Anyone Know What is Causing This?
« Reply #4 on: February 01, 2011, 07:48:49 am »
If you want to keep the same aspect ratio as the window, create your view from the default view of the window and then only use Zoom().

Using variables should be fine, show us your code if it doesn't work.
Laurent Gomila - SFML developer

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Anyone Know What is Causing This?
« Reply #5 on: February 01, 2011, 07:58:03 am »
Okay it doesn't seem to be working. I will post some minimal code within 10 minutes.
-Wander

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Anyone Know What is Causing This?
« Reply #6 on: February 01, 2011, 08:13:26 am »
Hmmm. I'm having trouble reproducing the error in minimal code... Should I just send a screenshot and view code?
-Wander

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Anyone Know What is Causing This?
« Reply #7 on: February 01, 2011, 08:20:47 am »
Quote
Hmmm. I'm having trouble reproducing the error in minimal code... Should I just send a screenshot and view code?

This means that the error is not trivial. So the only way to figure it out, is to gradually fill the gap between the minimal code that works, and the real code that fails. At one point you'll find which little thing makes it go crazy.
Laurent Gomila - SFML developer

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Anyone Know What is Causing This?
« Reply #8 on: February 01, 2011, 08:22:03 am »
So the error isn't in my view code? Okay. I'll try to find it. :) Thanks.
-Wander

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
Anyone Know What is Causing This?
« Reply #9 on: February 01, 2011, 08:25:48 am »
I'm looking at my code and I really don't see anything that could possible cause this.... Got any ideas? It's the crushing thing again. Just any broad ideas.

EDIT: Oh my god! I just went through my entire code and never found a solution that kept my program fully operational. I fixed it once but that fix caused my key presses to quit working....
-Wander

Zweistein

  • Newbie
  • *
  • Posts: 29
    • View Profile
Anyone Know What is Causing This?
« Reply #10 on: February 02, 2011, 06:05:42 pm »
Yeah, Programming is never an easy task... Good luck! :)

 

anything