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

Pages: [1]
1
Graphics / Unexpected crash
« on: March 04, 2012, 01:10:57 am »
I think i fixed it.

At some point relativeY becomes = 0 so,

relativeX / relativeY becomes like 1432 / 0.. And that cause the problem, i think.

There was no errors though.

Sorry.  :oops:

2
Graphics / Unexpected crash
« on: March 04, 2012, 12:44:10 am »
Code: [Select]

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
#include <cmath>

using std::cout;
using std::endl;

#include "RenderManager.h"

int relativeX, relativeY;
float speed = 0.05;

const float PI = 3.14159265;

int rotation;

int main()
{
    // Create the main window
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");

    // Render Manager
    cge::RenderManager myRenderManager(window);

    // Load a sprite to display
    sf::Texture texture;
    if (!texture.LoadFromFile("missile.gif"))
        return EXIT_FAILURE;
    sf::Sprite missile(texture);
    myRenderManager.add(missile);

    // Start the game loop
    while (window.IsOpened())
    {
        // ## PROCESS ##
        if (sf::Keyboard::IsKeyPressed(sf::Keyboard::Escape))
        {
            window.Close();
            //return 0;
        }
           
        relativeX = sf::Mouse::GetPosition(window).x - missile.GetPosition().x;
        relativeY = sf::Mouse::GetPosition(window).y - missile.GetPosition().y;

        rotation = atan(relativeX/relativeY)*180/PI;

        if (sf::Mouse::GetPosition(window).x > missile.GetPosition().x)
            missile.Move(.05, 0);
        else
            missile.Move(-.05, 0);

        if (sf::Mouse::GetPosition(window).y > missile.GetPosition().y)
            missile.Move(0, .05);
        else
            missile.Move(0, -.05);

        // ## OUTPUT ##
        //std::cout<< sf::Mouse::GetPosition().x<< std::endl;
        //std::cout<< missile.GetPosition().x<< std::endl;
        //std::cout<< atan(0.1)*180/PI<< endl;

        // Clear screen
        window.Clear();

        // Draw the sprite
        myRenderManager.draw();

        // Update the window
        window.Display();
    }

    return 0;
}


I want to compute arctan of relativeX and Y, but if i use (relativeX/relativeY) anywhere in program it crashes after about 3 seconds. So it compiles. There is no error, or exception even a warning. Nothing.

I'm stuck. :(

Thanks.

Pages: [1]
anything