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

Pages: 1 ... 7 8 [9] 10 11
121
Window / sf::Sleep problem and mouse input problem.
« on: December 28, 2010, 05:26:25 am »
Finally fixed it. I looked back at one of my previous snapshots and found that if I moved App->SetCursorPosition(centreX, centreY); from after App->Display(); to just before I take mouse input:
Code: [Select]
App->SetCursorPosition(centreX, centreY);
mouseDeltaX = Input.GetMouseX() - centreX;
mouseDeltaY = Input.GetMouseY() - centreY;
zRotation += (mouseDeltaX / 10);
rotation += (mouseDeltaY / 10);

it works fine. Yay!
On a side note, why does this change it?

122
Window / sf::Sleep problem and mouse input problem.
« on: December 27, 2010, 11:29:13 pm »
Has anyone ever had this problem before? It seems a bit odd.

123
Window / sf::Sleep problem and mouse input problem.
« on: December 27, 2010, 09:41:55 am »
Okay, thanks.
I changed from Input.GetMouseX() to Event.MouseMove.X, and it hasn't changed how the mouse behaves under Windows 7, as outlined in my other thread. I put the sf::Sleep(0.005) in there because it seemed to fix it, but it drags the FPS down to ~60FPS. How can I fix this? Will it improve if I put the rendering in a thread on its own, and everything else in a second thread?

124
Window / sf::Sleep problem and mouse input problem.
« on: December 27, 2010, 08:49:38 am »
I'm using Windows 7 32-bit, and Arch Linux X86_64, and getting the same problem on both operating systems :(

125
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?

126
Graphics / GluPerspective vs. GlOrtho
« on: December 27, 2010, 05:45:20 am »
Well, at the moment, moving the mouse moves the blocks. This is a bad idea. Why not just rotate everything based on the mouse movement? This is a lot faster, and easier to understand.

127
Network / Handling Multiple TCP Connections
« on: December 26, 2010, 09:44:40 am »
Use a 2-dimensional array, e.g. Clients[][]. In Clients[n][0], store the sockets of the clients. In Clients[n][1], store the corresponding username that was sent from that socket at login, when login succeeded. Then, you can search for the socket, get the corresponding username, and use that as you want.

128
Graphics / GluPerspective vs. GlOrtho
« on: December 26, 2010, 09:14:21 am »
For a start, it is a bad idea to use a negative number in gluPerspective() for zNear. I find gluPerspective annoying to use personally.

129
Window / I just do not know what to do!
« on: December 26, 2010, 08:54:16 am »
AFAIK, you can't use SFML with MinGW 4.4.

130
General discussions / video input
« on: December 24, 2010, 07:35:39 am »
The only thing you can do is record sound, AFAIK :(

131
Graphics / GluPerspective vs. GlOrtho
« on: December 23, 2010, 01:34:51 am »
Where from? The .zip from the HTML link has everything, except a glossary.

132
Graphics / GluPerspective vs. GlOrtho
« on: December 23, 2010, 01:28:50 am »
What do you mean? I'm assuming you went to the HTML version and got the .zip?

133
Graphics / GluPerspective vs. GlOrtho
« on: December 23, 2010, 01:25:11 am »
Haha I did the same. It is so useful! :D

134
Graphics / GluPerspective vs. GlOrtho
« on: December 23, 2010, 01:16:49 am »
It is written in Java. It uses LWJGL (Light Weight Java Game Library), which has an interface to OpenGL (much like SFML)

135
Graphics / GluPerspective vs. GlOrtho
« on: December 23, 2010, 01:08:55 am »
Right. Some of the high-end fancy features are only in later versions of OpenGL, so you have to be careful. It always pays to consider what version you want to use - this limits/expands your target PCs, e.g. Hardly any GPUs support OpenGL 4.1, so you want to steer clear of that. OpenGL 1.5/2 is usually a safe bet (MineCraft uses OpenGL 1.4).

Pages: 1 ... 7 8 [9] 10 11
anything