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.


Topics - tntexplosivesltd

Pages: 1 [2]
16
Window / sf::Sleep problem and mouse input problem.
« on: December 27, 2010, 06:10:17 am »
I have a bit of a problem, stemming from this code:
Code: [Select]
while (App->IsOpened())
    {
        sf::Sleep(0.001);
        // Process all "application" events
        sf::Event Event;
        while (App->GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App->Close();

            // Escape key : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App->Close();

            // Resize event : adjust viewport
            if (Event.Type == sf::Event::Resized)
                glViewport(0, 0, Event.Size.Width, Event.Size.Height);

            /*
            if (Event.Key.Code == sf::Key::F1)
            {
                sf::Image Screen = App->Capture();
                Screen.SaveToFile("screenshot.jpg");
            }
            */
        }

        cout << "" << 1/App->GetFrameTime() << endl;
        moving = false;
        // adjust x- y- and z- step amounts based on current direction/view rotation
        xStep = playerSpeed * sin((PI * zRotation) / 180);
        yStep = playerSpeed * cos((PI * zRotation) / 180);
        zStep = -playerSpeed * sin((PI * rotation) / 180);
        //cout << "zRot: " << zRotation << " rot: " << rotation << endl;

        // process real-time input
        if (Input.IsKeyDown(sf::Key::W))    // W = forwards
        {
            moving = true;
            playerX -= (xStep * cos((PI * rotation) / 180));
            playerY -= (yStep * cos((PI * rotation) / 180));
            playerZ -= zStep;
        }

        if (Input.IsKeyDown(sf::Key::S))    // S = backwards
        {
            moving = true;
            playerX += (xStep * cos((PI * rotation) / 180));
            playerY += (yStep * cos((PI * rotation) / 180));
            playerZ += zStep;
        }

        if (Input.IsKeyDown(sf::Key::A))    //A = strafe left
        {
            if ((moving = true))
            {
                xStep *= 0.707106;
                yStep *= 0.707106;
            }
            playerX += yStep;
            playerY -= xStep;
        }

        if (Input.IsKeyDown(sf::Key::D))    //D = strafe right
        {
            if ((moving = true))
            {
                xStep *= 0.707106;
                yStep *= 0.707106;
            }
            playerX -= yStep;
            playerY += xStep;
        }
        // Rotate view based on mouse movement
        mouseDeltaX = Input.GetMouseX() - centreX;
        mouseDeltaY = Input.GetMouseY() - centreY;
        zRotation += (mouseDeltaX / 10);
        rotation += (mouseDeltaY / 10);
        //cout << "DeltaX: " << mouseDeltaX << " DeltaY: " << mouseDeltaY << endl;

        // Z rotation normalisation - between 0 and 360
        if (zRotation >= 360)
        {
            zRotation -= 360;
        }

        if (zRotation < 0)
        {
            zRotation += 360;
        }

        // X/Y rotation limits
        if (rotation < -90)
        {
            rotation = -90;
        }
        if (rotation >= 90)
        {
            rotation = 90;
        }


        // Set the active window before using OpenGL commands
        // It's useless here because active window is always the same,
        // but don't forget it if you use multiple windows or controls
        App->SetActive();

        //  color and depth buffer
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        // Rotate the view first
        glRotatef(-90 + rotation, 1.f, 0.f, 0.f);
        glRotatef(zRotation, 0.f, 0.f, 1.f);

        // Then translate it
        glTranslatef(playerX, playerY, playerZ);

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glCallList(ALL_CUBES);
        glFlush();

        App->Display();
        App->SetCursorPosition(centreX, centreY);
    }
    return EXIT_SUCCESS;
}


What is happening is when I have the sf::Sleep(0.001) in there, the framerate drops to ~60FPS. When I comment it out, it shoots up to ~300-400FPS. Even if it's drawing only one block, the FPS is ~60FPS with sf::Sleep(0.001). This is weird.

Additionally, I still have the same problem listed in this thread, with the mouse input.

So I have a few questions:
1) What is happening with the framerate varying so much?
2) What is the difference between Input.GetMouseX() and Event.MouseMoved.X?

17
Window / sf::Input.GetMouseX() and Y()
« on: December 15, 2010, 12:33:05 am »
I have written some movement code for SFML 1.6 as follows:
Code: [Select]

while (App.IsOpened())
    {
        moving = false;
        // adjust x- y- and z- step amounts based on current direction/view rotation
        xStep = playerSpeed * sin((PI * zRotation) / 180);
        yStep = playerSpeed * cos((PI * zRotation) / 180);
        zStep = -playerSpeed * sin((PI * rotation) / 180);
        cout << "zRot: " << zRotation << " rot: " << rotation << endl;

        // process real-time input
        if (Input.IsKeyDown(sf::Key::W))    // W = forwards
        {
            moving = true;
            playerX -= (xStep * cos((PI * rotation) / 180));
            playerY -= (yStep * cos((PI * rotation) / 180));
            playerZ -= zStep;
        }

        if (Input.IsKeyDown(sf::Key::S))    // S = backwards
        {
            moving = true;
            playerX += (xStep * cos((PI * rotation) / 180));
            playerY += (yStep * cos((PI * rotation) / 180));
            playerZ += zStep;
        }

        if (Input.IsKeyDown(sf::Key::A))    //A = strafe left
        {
            if ((moving = true))
            {
                xStep *= 0.707106;
                yStep *= 0.707106;
            }
            playerX += yStep;
            playerY -= xStep;
        }

        if (Input.IsKeyDown(sf::Key::D))    //D = strafe right
        {
            if ((moving = true))
            {
                xStep *= 0.707106;
                yStep *= 0.707106;
            }
            playerX -= yStep;
            playerY += xStep;
        }
        // Rotate view based on mouse movement
        mouseDeltaX = Input.GetMouseX() - centreX;
        mouseDeltaY = Input.GetMouseY() - centreY;
        zRotation += (mouseDeltaX / 10);
        rotation += (mouseDeltaY / 10);
        App.SetCursorPosition(centreX, centreY);


I then use OpenGL to rotate and translate blah, but that's not important.

Now, in Arch Linux x86_64 (with X11 and XFCE), this works fine. The view rotates fine.
In Windows (Windows 7 32-bit), it's a different story. The view hardly moves with the same mouse movements. It's so annoying! However, the keyboard movement is exactly the same.

What's going on?

Pages: 1 [2]
anything