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

Pages: [1]
1
General / Re: Using sf::View as camera when mixing opengl and SFML
« on: October 10, 2014, 05:42:17 pm »
Ended up fixing this problem a while ago but forgot to update this question. I ended up creating a Camera class which handles sf::View and then translates anything drawn by opengl by how much the sf::view has moved as well (almost like having 2 separate cameras).

2
General / Using sf::View as camera when mixing opengl and SFML
« on: September 29, 2014, 11:48:41 pm »
Hi,
I'm having some trouble with using an sf::VIew as a camera when mixing raw opengl calls with SFML. For example, here in my code I'm mixing opengl calls with SFML: https://github.com/SundeepK/Clone/blob/wip/add_splittable_enviroment/src/Game.cpp#L58. Everything drawn by SFML is correct but the textures drawn manually using opengl calls follow the camera, rather than staying put. Here's an example image: http://i.imgur.com/umME791.png?1 . When I move, you can see that the wooden texture follows rather than staying where it's supposed to be.

What would be the general way of handling a camera in this scenario?

3
General / Re: Unable to load tiledmap box2d object using sfml-tmxloader
« on: September 16, 2014, 11:12:29 pm »
So I fixed the problem a while back and forgot to post back, but to fix the problem I stored a pointer to my b2world object. Which I believe was not working previously (maybe you can confirm my understanding)  because I was passing by reference and then using the copy constructor to copy over my b2world to this other class, which was incorrect. For example:

LoadMap::LoadMap(b2world& box2dWorld) : m_world(box2dWorld){
}

So I switched to using a unique_ptr and will probably use pointers for such objects.

4
General / Unable to load tiledmap box2d object using sfml-tmxloader
« on: September 10, 2014, 10:41:38 pm »
Hi,

I've been hacking together a simply game prototype using various technologies in an aim to build a quick game. I've started to integrate tiled maps in my game by using sfml-tmxloader to load my map and my static box2d objects. Unfortunately, I'm having odd problems loading my static box2d object via sfml-tmxloader. The problem is that I am unable to actually create box2d object via the tmx::BodyCreator::Add function anywhere else but my main function.

Here's how I load maps and static bodies through my main function:
https://github.com/SundeepK/Clone/blob/wip/add_tmx_loading/src/main.cpp#L37

And here's how I load it in my game class:
https://github.com/SundeepK/Clone/blob/wip/add_tmx_loading/src/Game.cpp#L14

My code is slightly hacky and messy since I've been trying for hours to find out why I am unable to load box2d object from the tmx::BodyCreator::Add anywhere else but my main function (before my game class is actually created). I don't know if my game class is some how altering my box2d world, but I can create box2d manually without using tmx::BodyCreator::Add and they show fine. I much rather avoid having to re-write the code to create box2d object because its pretty much free in tmx::BodyCreator. A second pair of eyes would help me greatly! Thanks.

5
General / Re: Fixed timestep issue with box2d and sfml
« on: June 07, 2014, 08:29:56 pm »
I've also now created a visual studio project (2010) that also shows the same problem:

https://www.dropbox.com/s/ghazj8tqyppk8v9/sfml%20test.zip

I guess it's not specific to linux, I might try and re-write it using just opengl with sfml and see what happens  :-\

6
General / Re: Fixed timestep issue with box2d and sfml
« on: June 06, 2014, 10:10:23 pm »
I've attached an executable (should run on linux). You'll need to have SFML, Box2d  and opengl installed. Could any one give this a go and see if they can see any issues (seems more noticeable in full screen).  Thanks.

https://www.dropbox.com/s/dzf4f8w6f6fl1o0/FixedTimeStepTest.rar

7
General / Re: Fixed timestep issue with box2d and sfml
« on: June 04, 2014, 09:54:48 pm »
First off, I'd try it without the timestep, and see what happens.  If you still get artifacts, then maybe it's a vsync problem.  If you're running in fullscreen, try enabling vsync, or else try running in a window.

This line of code could also be a culprit.
Code: [Select]
const int clampedSteps = std::min(steps, MAX_STEPS);If MAX_STEPS is ever limiting steps, then you're going to get jittery movement.

What value for FIXED_TIMESTEP are you using?

I've already tried everything you've said and still looks odd. It isn't jittery, more the fact that the movable square looks blurry and stretched when moving.  So it's not all that jittery. FIXED_TIMESTEP = 1f/60f and MAX_STEPS=5. changing these values doesn't change much. I've also already tried using setframerate to 60 but that hasn't done a thing.

I'm begging to think that it may be a platform thing? I may give sdl a go and see how things look, though I really much rather stick with sfml.

8
General / Re: Fixed timestep issue with box2d and sfml
« on: June 01, 2014, 10:21:07 pm »
My guess would be that the square is at non-integer coordinates.

If I understand correctly, you mean something like this:

        rect.setPosition(sf::Vector2f(floor(c->smoothedPosition.x*30-10),floor(c->smoothedPosition.y*30-10)));
 

Unfortuanly, that didn't fix the issue. Also I forgot to mention, I'm using 64bit ubuntu 13.04. Oh and the problem seems worse when using interpolated values to set the rect position versus using the box2d GetPosition (although you can still see the problem).

9
General / Fixed timestep issue with box2d and sfml
« on: June 01, 2014, 09:04:30 pm »
I've been recently attempting to create a simple example game using both sfml and box2d. To get simple framework together, I wanted to implement a fixed timestep and I've pretty much based the fixed timestep code off this http://www.unagames.com/blog/daniele/2010/06/fixed-time-step-implementation-box2d . At the moment its simple demo with a square box that you can move with wasd keys. The problem is that when ever I attempt to move the square, I get this odd blur on the square (almost like its stretching) whilst moving. I've tried a few things from this forum and even attempting to just set the frame rate to 60, but it doesn't seem to change any thing.

Below is my fixed timestep:
void B2DWorld::update(float dt, ActionController<std::string>& actionController){
    m_fixedTimestepAccumulator += dt;
    const int steps = floor(m_fixedTimestepAccumulator / FIXED_TIMESTEP);

    if (steps > 0)
        {
                m_fixedTimestepAccumulator -= steps * FIXED_TIMESTEP;
        }

        assertAccumilation();
    m_fixedTimestepAccumulatorRatio = m_fixedTimestepAccumulator / FIXED_TIMESTEP;

    const int clampedSteps = std::min(steps, MAX_STEPS);
        for (int i = 0; i < clampedSteps; ++ i)
        {
                resetStates();
                actionController.triggerCallbacks(m_fixedTimestepAccumulatorRatio);
                step(FIXED_TIMESTEP);
        }

        interpolateStates();
        m_world.DrawDebugData();

}

void B2DWorld::step(float dt){
    m_world.Step(dt, VELOCITY_ITERATIONS, POSITION_ITERATIONS);
}

void B2DWorld::interpolateStates(){

        const float oneMinusRatio = 1.0f - m_fixedTimestepAccumulatorRatio;

        for (b2Body * b = m_world.GetBodyList (); b != NULL; b = b->GetNext ())
        {
                if (b->GetType () == b2_staticBody)
                {
                        continue;
                }

                PhysicsComponent *c   = (PhysicsComponent*) b->GetUserData();
                c->smoothedPosition =
                m_fixedTimestepAccumulatorRatio * b->GetPosition () +
                oneMinusRatio * c->previousPosition;
                c->smoothedAngle =
                m_fixedTimestepAccumulatorRatio * b->GetAngle () +
                oneMinusRatio * c->previousAngle;
        }

}
 

Here's the full code: https://github.com/SundeepK/Clone/tree/wip/fix_time_step
Any suggestions on what be causing the issue or other example code/projects that implement fixed timestep with sfml?

Pages: [1]