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

Pages: 1 2 3 [4]
46
General / Re: Implement Timestep and Gravity
« on: April 18, 2013, 11:42:49 am »
As Luis said, the choppiness problem will be solved by delta timing. The basic idea is that you multiply a delta time (change in time) value by the corresponding speed. So, you'd calculate deltaTime in seconds as a float and multiply it by whatever speed you want, for instance 100 pixels per second.

Code: [Select]
sf::Clock deltaClock;
float deltaTime = 0.f;
int lastFrameTime = 0;

sf::Vector2f velocity(0.f, 100.f);

while (myGameIsRunning)
{
            deltaTime = ((float)deltaClock.getElapsedTime().asMilliseconds()-lastFrameTime)/1000.f;
            lastFrameTime = deltaClock.getElapsedTime().asMilliseconds();

           // When moving objects
           characterSprite.move(velocity*deltaTime);
}

I hope that helps. Now, for gravity and movement and whatnot. Off the top of my head, what I would do is have multiple 2D vectors that get summed together for the player's final speed. So, you'll have a movement vector that is modified when keypresses are detected and a gravity vector for handling gravity/jumping. I'll try to code this up, but keep in mind it's more pseudo-code than code you can compile.

Code: [Select]
sf::Vector2f playerSpeed;
sf::Vector2f gravity;

while (myGameIsRunning)
{
            playerSpeed = sf::Vector2f(0.f, 0.f); // Reset the player's speed each frame so we can add to it with each keypress
            if (leftDown) playerSpeed += sf::Vector2f(-100.f, 0.f);
            if (rightDown) playerSpeed += sf::Vector2f(-100.f, 0.f);
            if (upPressed) gravity = sf::Vector2f(0.f, -200.f); // up we go :)

            gravity.y -= 75.f*deltaTime;
            if (gravity.y > 200.f) gravity.y = 200.f; // Don't let gravity get too fast

            playerSprite.move((playerSpeed+gravity)*deltaTime);
}

And that should do it! Sorry I'm too lazy to actually go through your code and make it work, I'm about to go to sleep, have class early tomorrow! Hope this helps

47
General discussions / Re: Z ordering
« on: April 18, 2013, 11:00:09 am »
Probably a bit late to the party, but I'd definitely be interested in this feature. In my game engine, I handle it with this code:


void Scene::render(sf::RenderTarget *target, sf::RenderStates states)
{
    int topLayer = 0;
    for (unsigned int o = 0; o < mGameObjects.size(); o++)
        topLayer = std::max(topLayer, mGameObjects[o]->getRenderLayer());


    for (int l = 0; l <= topLayer; l++)
    {
        for (unsigned int o = 0; o < mGameObjects.size(); o++)
        {
            if (mGameObjects[o]->getRenderLayer() == l)
                mGameObjects[o]->onRender(target, states);
        }
    }
}
 


But if there's some legendary, mega-fast OpenGL depth buffer then that sounds awesome!

EDIT: I agree with Tank, the particle systems example hits home for me. I haven't even started thinking about particles yet, but I'll have to do my own custom particle engine to make the depth work with my game engine's render layers.

Double edit: Although, I suppose I could just call the render function for whatever external library wherever I want, so maybe it isn't such an issue.

48
SFML projects / Fission - A simple, object-component based game engine
« on: April 17, 2013, 11:26:57 pm »
.

49
Graphics / Re: sf::Shape Texture Coordinates
« on: April 14, 2013, 04:26:49 am »
Hey, I finally got around to implementing rendering using a VertexArray, but I'm having trouble visualizing how to calculate texture coordinates based off of the vertex pixel coordinates. The planet is composed of a couple hundred vertices and I would like to have it textured as if I had a tiled texture that the vertices "cut" from like a cookie cutter. I don't know if that makes sense?

The vertex array is rendered as a triangle fan.

EDIT:

For anyone who cares, the texture coordinates are actually going to be exactly the same as the pixel coordinates, no computation required! :D

50
Graphics / Re: sf::Shape Texture Coordinates
« on: April 12, 2013, 03:59:09 am »
Wow, that looks like a great solution, thanks! And thanks for the fast reply :D

51
Graphics / sf::Shape Texture Coordinates
« on: April 12, 2013, 03:06:51 am »
Hi, I'm writing a game that procedurally generates 2D planets. Right now, the entire planet is rendered onto a massive texture, which is fine when there is only one planet. I know, though, that I will be having problems when I have 100 planets. To get around this, instead of generating the planet's texture, I want to store polygons to render in OpenGL, but to do this, I need to be able to set texture coordinates from a source texture. I saw that texturing an sf::Shape is possible in the documentation, but couldn't find a way to set texture coordinates. Is there a way? Or am I going to have to dive into the OpenGL documentation and render my planets without SFML's help?

Thanks for your time!

52
SFML projects / Re: SFML Light System - Let There Be Light
« on: December 11, 2012, 12:28:12 am »
Awesome, thanks!

53
SFML projects / Re: SFML Light System - Let There Be Light
« on: December 10, 2012, 11:05:51 am »
Hi, I just started with SFML today and set up my basic framework and decided to get your light system in it since it looks absolutely beautiful :)

The demo works fine on my computer, but for some reason when I compile your example myself against the latest SFML on GIT I get the screenshot below (I had to add a few cmath and stdlib includes here and there, and also comment out the m_lightAttenuationShader.unbind(); line in LighSystem.cpp). Which version is this supposed to be compiled against?



EDIT: I fixed it! It's working fine now. It turns out m_lightAttenuationShader.unbind(); was important. I replaced it with:

Code: [Select]
//this is the replacement for unbind
sf::priv::GlContext::ensureContext();
glCheck(glUseProgramObjectARB(0));

since the unbind function was removed in this commit: https://github.com/SFML/SFML/commit/121cfeb6a3685e2529b717d5667ee6601533c30e

Pages: 1 2 3 [4]
anything