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

Pages: [1]
1
General / Re: [WIN7] Odd problem with std::cout
« on: January 26, 2013, 04:25:18 am »
int main()
{
    //variables
    float playerX = 400;
    float playerY = 300;

    float mouseX = 0.0;
    float mouseY = 0.0;

    double dx = 0;
    double dy = 0;

    float trigresult = 0.0;

    //shapes
    sf::RectangleShape playerRect;
    playerRect.setSize(sf::Vector2f(BLOCK_SIZE,BLOCK_SIZE));
    playerRect.setPosition(playerX,playerY);
    playerRect.setOrigin(BLOCK_SIZE/2,BLOCK_SIZE/2);
    playerRect.setTexture(&tex_playerRect);

    //gameloop//////////////////////
    while(bPlay == true)
    {
        //EVENTS//
        while(window.pollEvent(event))
        {
            /////////////////////////////////////
            //mouse

            //check if mouse moved
            if(event.type == sf::Event::MouseMoved)
            {
                mouseX = event.mouseMove.x;
                mouseY = event.mouseMove.y;
            }
        }
        //LOGIC//

        //point playerRect at mouse pos
        std::cout << mouseX << "\n";
        std::cout << mouseX << "\n";

        dx = mouseX - playerX;
        dy = mouseY - playerY;
        trigresult = atan2(dy,dx) * 180/PI;
        playerRect.setRotation(trigresult + 90);
       
        //RENDERING//

        window.clear();

        window.draw(playerRect);

        window.display();
    }
}

I hope this is enough code for you to help(also note that the first std::cout for mouseX didn't actually output anything to the console, but when I inserted it twice it worked ( ??? )

2
General / [WIN7] Odd problem with std::cout
« on: January 26, 2013, 12:47:29 am »
I'm in an odd situation right now:
        //point playerRect at mouse pos
        std::cout << mouseX << "\n";

        dx = mouseX - playerX;
        dy = mouseY - playerY;
        trigresult = atan2(dy,dx) * 180/PI;
        playerRect.setRotation(trigresult + 90);
For some reason, whenever I comment out the "std::cout << mouseX << "\n"", the trigresult only outputs 90 or -90 degrees with cout(so playerRect is either pointing straight up or straight down). And whenever it is there/isn't commented out, it works correctly and trigresult prints out correct results. Anyone know why this is?

Thanks in advance.

Pages: [1]
anything