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 ... 9 10 [11]
151
Window / sf::Input.GetMouseX() and Y()
« on: December 18, 2010, 09:50:57 am »
Any ideas? I don't want to be limited to 200FPS. Also, if I set the framerate limit, the problem persists.

152
Window / [SFML2] Input on another thread
« on: December 18, 2010, 03:01:51 am »
Okay then. What is meant by update?

153
General / Quick Question about OpenGL
« on: December 18, 2010, 01:50:22 am »
In OpenGL, (0,0) is the bottom left.

154
SFML projects / Can Someone Test My Game?
« on: December 18, 2010, 01:45:45 am »
Or the .dlls are 64-bit ones.

155
General discussions / How to make an sprite go to correct direction
« on: December 18, 2010, 01:18:01 am »
The easiest thing to do is to store the player's current direction somewhere, so you can then apply that to the bullet.

156
Window / [SFML2] Input on another thread
« on: December 18, 2010, 12:50:32 am »
It probably isn't worth having the input thread on a seperate thread. If one thread is held up (e.g. rendering), the input will be problematic, and gameplay could be adversely affected.

157
Window / sf::Input.GetMouseX() and Y()
« on: December 17, 2010, 10:50:42 am »
Quote from: "Laurent"
Try moving your event loop at the beginning of your main loop.

Hasn't worked :(

Quote from: "Laurent"

Then, what does "The view hardly moves with the same mouse movements" mean exactly? What framerate do you have?

In Linux, if I move the mouse say 5cm, the view on screen moves as expected in the window.
However, in Windows, for the same 5cm mouse movement, the view moves a much smaller amount, and in jumps. The framerate stays relatively constant. (~300-400 FPS)

158
Window / sf::Input.GetMouseX() and Y()
« on: December 17, 2010, 10:21:56 am »
Complete code? Here we go...
(keep in mind it's not finished/optimised yet, and I'm relatively new to C++ and SFML)
Code: [Select]

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////

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

#define ALL_CUBES 1
using namespace std;

////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////

class Block
{
    public:
        int x, y, z, size;
        Block(int blockSize, int xCoord, int yCoord, int zCoord) {x = xCoord; y=yCoord; z=zCoord; size = blockSize; }
};

//DrawCube - creates 6 face polygons, with size and position arguments
void DrawCube(float size, float xOffset, float yOffset, float zOffset)
{
    size = size / 2;
    //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glBegin(GL_QUADS);
        glEdgeFlag(GL_TRUE);

        glColor3f(((xOffset/16+10)/20), ((yOffset/16+10)/20), ((zOffset/16+10)/20));

        glVertex3f(-size + xOffset, -size + yOffset, -size + zOffset);
        glVertex3f(-size + xOffset,  size + yOffset, -size + zOffset);
        glVertex3f( size + xOffset,  size + yOffset, -size + zOffset);
        glVertex3f( size + xOffset, -size + yOffset, -size + zOffset);

        glVertex3f(-size + xOffset, -size + yOffset, size + zOffset);
        glVertex3f(-size + xOffset,  size + yOffset, size + zOffset);
        glVertex3f( size + xOffset,  size + yOffset, size + zOffset);
        glVertex3f( size + xOffset, -size + yOffset, size + zOffset);

        glVertex3f(-size + xOffset, -size + yOffset, -size + zOffset);
        glVertex3f(-size + xOffset,  size + yOffset, -size + zOffset);
        glVertex3f(-size + xOffset,  size + yOffset,  size + zOffset);
        glVertex3f(-size + xOffset, -size + yOffset,  size + zOffset);

        glVertex3f(size + xOffset, -size + yOffset, -size + zOffset);
        glVertex3f(size + xOffset,  size + yOffset, -size + zOffset);
        glVertex3f(size + xOffset,  size + yOffset,  size + zOffset);
        glVertex3f(size + xOffset, -size + yOffset,  size + zOffset);

        glVertex3f(-size + xOffset, -size + yOffset,  size + zOffset);
        glVertex3f(-size + xOffset, -size + yOffset, -size + zOffset);
        glVertex3f( size + xOffset, -size + yOffset, -size + zOffset);
        glVertex3f( size + xOffset, -size + yOffset,  size + zOffset);

        glVertex3f(-size + xOffset, size + yOffset,  size + zOffset);
        glVertex3f(-size + xOffset, size + yOffset, -size + zOffset);
        glVertex3f( size + xOffset, size + yOffset, -size + zOffset);
        glVertex3f( size + xOffset, size + yOffset,  size + zOffset);
    glEnd();
}
int main()
{
    bool moving = false;
    //up/down rotation
    float rotation = 0;
    //horizintal rotation
    float zRotation = 0;

    //player movement variables - need to make into player class - maybe
    float playerSpeed = 1;
    float playerX = 0;
    float playerY = 0;
    float playerZ = 0;
    float xStep = 0;
    float yStep = 0;
    float zStep = 0;

    float mouseDeltaX = 0;
    float mouseDeltaY = 0;

    int mousePrevX;
    int mousePrevY;

    //PI
    const float PI = 3.14159265358979323846264338329750288419716939937510582;

    //settings for OpenGL rendering context
    sf::WindowSettings Settings;
    Settings.DepthBits         = 24; // Request a 24 bits depth buffer
    Settings.StencilBits       = 8;  // Request a 8 bits stencil buffer
    Settings.AntialiasingLevel = 8;  // Request 8 levels of antialiasing

    // Create the main window and appropriate variables
    sf::VideoMode bestMode = sf::VideoMode::GetMode(0);
    int bestWidth = bestMode.Width;
    int bestHeight = bestMode.Height;
    int centreX = bestWidth / 2;
    int centreY = bestHeight / 2;

    Block * allBlocks[8000];

    sf::RenderWindow * App = new sf::RenderWindow(sf::VideoMode(bestWidth, bestHeight, 32), "Rendering Test", sf::Style::Fullscreen, Settings); //, sf::Style::Fullscreen

    // Hide the cursor
    App->ShowMouseCursor(false);
    //App->SetFramerateLimit(200);

    // real-time input handler
    //const sf::Input& Input = App->GetInput();

    // Set color and depth clear value
    glShadeModel(GL_SMOOTH);
    // Colours and depths to clear to
    glClearDepth(1.f);
    glClearColor(0.f, 0.f, 0.3f, 0.f);


    // Enable Z-buffer read and write
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);

    // Setup a perspective projection
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-1.f, 1.f, -1.f, 1.f, 1.5f, 10000.f);
    glViewport (0, 0, bestWidth, bestHeight);

    // DisplayList for cubes
    int iterator = 0;
    for (int i = -10; i < 10;i++)
    {
        for (int j = -10; j < 10; j++)
        {
            for (int k = -10; k < 10; k++)
            {
                allBlocks[iterator] = new Block(16, i*60, j*60, k*60);
                iterator++;
            }
        }
    }

    glNewList(ALL_CUBES, GL_COMPILE);
    for (int i = 0; i < 8000; i++)
    {
        DrawCube(allBlocks[i]->size, allBlocks[i]->x, allBlocks[i]->y, allBlocks[i]->z);
        //cout << "" << allBlocks[i]->size << " " << allBlocks[i]->x << " " << allBlocks[i]->y << " " << allBlocks[i]->z << endl;
        delete allBlocks[i];
    }
    glEndList();


    //cout << "zRot: " << zRotation << " rot: " << rotation << endl;
    // Start game loop
    while (App->IsOpened())
    {
        const sf::Input& Input = App->GetInput();
        //sf::Sleep(0.005);
        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;
        }

        // 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");
            }
        }

        // 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;
}

159
SFML projects / Can Someone Test My Game?
« on: December 16, 2010, 08:28:43 am »
Yeah, I got the following error in Windows 7 32-bit when I run it. The same thing happeans with each .dll

"C:\Users\***\Desktop\Pikin\OPENGL32.dll is either not designed to run on Windows or it contains an error. Try installing the program again using the original installation media or contact your system administrator or the software vendor for support."

Did you only compile on a 64-bit machine? That's the only obvious problem I can think of.

160
Window / sf::Input.GetMouseX() and Y()
« on: December 16, 2010, 08:06:56 am »
I call it just after creating my sf::RenderWindow() object (outside the game loop). I tried moving it to the main loop, but it didn't help out.

161
Window / sf::Input.GetMouseX() and Y()
« on: December 15, 2010, 02:44:50 am »
Fixed it somewhat. Added sf::Sleep(0.005) to the mail game loop, but this does expectedly lower the framerate. Is there a better way to give the inputs a chance to register, but keep a higher framerate?

162
Window / Is window in focus or minimized?
« on: December 15, 2010, 02:25:58 am »
There are the events LostFocus and GainedFocus, but these don't really work with minimising. Unfortunately you'll have to wait until SFML 2.0 for Activated and Deactivated.

163
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 ... 9 10 [11]
anything