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

Author Topic: [Solved] This Looks Right to Me, but Obviously Not...  (Read 5915 times)

0 Members and 3 Guests are viewing this topic.

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
[Solved] This Looks Right to Me, but Obviously Not...
« on: February 02, 2011, 12:30:15 am »
Code: [Select]
#include <iostream>
#include <SFML\Graphics.hpp>
#include "Header\ResourceManager.h"

using namespace std;

int main()
{
    bool Running = true, Shift;
    sf::Shape Map;

    sf::View MainView;

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

    MainView.SetFromRect(Window.GetDefaultView().GetRect());
    MainView.Zoom(.1f);

    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(true);
    Map.SetOutlineWidth(100);

    while (Running) {

        float Offset = 20000.f * Window.GetFrameTime();
        if (Window.GetInput().IsKeyDown(sf::Key::Up) && Shift == false)   { cout << "Up" << endl;MainView.Move( 0,      -Offset);}
        if (Window.GetInput().IsKeyDown(sf::Key::Down) && Shift == false)  MainView.Move( 0,      Offset);
        if (Window.GetInput().IsKeyDown(sf::Key::Left))  MainView.Move(-Offset,  0);
        if (Window.GetInput().IsKeyDown(sf::Key::Right)) MainView.Move(Offset,  0);

        if (Window.GetInput().IsKeyDown(sf::Key::LShift)) Shift = true;
        else if (Window.GetInput().IsKeyDown(sf::Key::RShift)) Shift = true;
        else { Shift = false; }

        if (Window.GetInput().IsKeyDown(sf::Key::Up) && Shift == true)   MainView.Zoom(1.005f);
        if (Window.GetInput().IsKeyDown(sf::Key::Down) && Shift == true) MainView.Zoom(0.994f);

        Window.Clear(sf::Color::Red);

        Window.SetView(MainView);
            Window.Draw(Map);
        for (int i = 10000; i < 90000; i += 10000) {
            sf::Shape Line = sf::Shape::Line(0, i, 30000, i, 200, sf::Color::Red);
            Window.Draw(Line);
        }

        Window.Display();
    }

    return 0;
}



This code looks like it should move my view. I set the view by the DefaultView.
-Wander

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
[Solved] This Looks Right to Me, but Obviously Not...
« Reply #1 on: February 02, 2011, 12:55:05 am »
Code: [Select]
if (Window.GetInput().IsKeyDown(sf::Key::Up) && Shift == true)   MainView.Zoom(1.005f);
        if (Window.GetInput().IsKeyDown(sf::Key::Down) && Shift == true) MainView.Zoom(0.994f);


Zooming is like a scale, your passing values realy close to 1, that should mean almost no change, if any!

If you want to double zoom, use 2, if you want half the zoom, use 0.5, i hope it clarifies it for you.

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
[Solved] This Looks Right to Me, but Obviously Not...
« Reply #2 on: February 02, 2011, 02:56:31 am »
Well, its supposed to be zooming over time. The longer you hold the zoom keys the more it zooms.

I was in a hurry when I posted this so I never got a chance to state the problem. NONE of input() commands even work. It won't go inside of the if statements at all.
-Wander

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
[Solved] This Looks Right to Me, but Obviously Not...
« Reply #3 on: February 02, 2011, 03:31:53 am »
Oh well, imagine your zoom amount is 10, the zoom() method is multiplying a factor, no matter how much you struggle, a constant * 1 = constant
That means 10 * 1 = 10, so, no change to the zoom.

Im assuming thats the problem!

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
[Solved] This Looks Right to Me, but Obviously Not...
« Reply #4 on: February 02, 2011, 03:37:04 am »
I would agree with you, but its not even entering the if statements, as I stated earlier. I put cout statements inside of the if statements and they never get displayed when I press the buttons. :/
-Wander

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
[Solved] This Looks Right to Me, but Obviously Not...
« Reply #5 on: February 02, 2011, 03:43:07 am »
The middle code which handles shift presses, should be in the beggining of the loop, no?

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
[Solved] This Looks Right to Me, but Obviously Not...
« Reply #6 on: February 02, 2011, 03:48:05 am »
Nope. Didn't work. :/ This aggravating. Haha! Does Input() require anything to run?
-Wander

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
[Solved] This Looks Right to Me, but Obviously Not...
« Reply #7 on: February 02, 2011, 04:00:26 am »
A window? :P

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
[Solved] This Looks Right to Me, but Obviously Not...
« Reply #8 on: February 02, 2011, 04:01:46 am »
Haha. Check. Anything else?
-Wander

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
[Solved] This Looks Right to Me, but Obviously Not...
« Reply #9 on: February 02, 2011, 04:32:21 am »
Nothing like debugging a bit, test with smaller cases first, some input must be working!

Also, i am absolutely not sure of what i am saying, but if the window updates the input from the events, you need to process Events, they will be the ones who internally make Input work. just a theory! Thats how i would do it, probably :)

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
[Solved] This Looks Right to Me, but Obviously Not...
« Reply #10 on: February 02, 2011, 04:34:54 am »
WOAH! I added an empty event loop and now it works.... -_-
-Wander

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
[Solved] This Looks Right to Me, but Obviously Not...
« Reply #11 on: February 02, 2011, 04:46:57 am »
Put a GetEvent() loop in. You need to handle close and other events anyway.

Also, I'm not sure if you formatted your code like that just for posting, but a better choice would have been to show a simpler loop with just one GetInput() in it, formatted nicely so it doesn't hurt my eyes so much when I look at it  :lol:

EDIT: BEATEN!!?!?!?  :shock:

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
[Solved] This Looks Right to Me, but Obviously Not...
« Reply #12 on: February 02, 2011, 04:49:08 am »
It is beaten but the Event Loop is empty. There aren't any events to process. :o OH!!! WAIT!! Is the empty event loop notifying the program that the key presses are not events and should be used as real time Input()? :o
-Wander

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
[Solved] This Looks Right to Me, but Obviously Not...
« Reply #13 on: February 02, 2011, 05:04:26 am »
Lol because the event loop is empty doesn't mean anything. What SFML means by process an event, is getting it with GetEvent()! Then you can do what you want with it, its just data, even throw it to the dustbin! Using or not realtime input won't affect how many events will pass into the event loop!

:)

Wander

  • Full Member
  • ***
  • Posts: 170
    • View Profile
    • Email
[Solved] This Looks Right to Me, but Obviously Not...
« Reply #14 on: February 02, 2011, 05:22:45 am »
Well then why does this work with an event loop but not without one?
-Wander