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

Pages: 1 2 [3] 4 5 6
31
DotNet / Re: [VB.NET] Mouse events for custom drawn gfx controls.
« on: June 10, 2016, 03:39:05 am »
Coming back to this, I have been looking up how to apply a callback function to my custom control, but I am unable to figure this out.  Maybe I rambled on too much in the above posts?  I have sought assistance on other forums, but keep being referred here because no one knows what SFML is, or how to assist.  I'd like to start fresh and see if I can get a pointer, either C# or VB.net, on how to do this.

I'm making a custom control class library, essentially drawn primitives on a render window, to mimic a control such as a button.

Traditional event handlers do not work, so I am having to push the location of the mouse through the render window's event to the location of the button, check if the mouse is over or clicked(down), then set the image over/down for the button.

Moving the mouse with any speed will not toggle the mouse up/leave events, which causes the button to appear to still be hovered or clicked down on the button.  Note the horizontal scroll bars left button:



Every example of a callback that I can find refer to calling back to a .dll file.  I am really lost.  I have noticed other control libraries that allow the functionality for the mouse events to happen without going through what I am, plus there are no issues with the mouse leave events not firing.

Hopefully that can explain my issue better.  I will give someone an awesome hi-five if they can explain what I need to do, or if there is something else that I did not know to look up ;)

32
Graphics / Re: SFML and Game time
« on: June 07, 2016, 04:54:35 pm »
OMG, the comments...how did I not notice them before?!?  You're right, they do provide much clearer explanations of what all is going on in the equations.

No joke, I thought this area would be a general 1-type of equation is going to work, but that is not the case.  He's leaving out friction, and drag is set to 1.  He even further explains that his example IS for 1D, and that t can be used for other things that he isn't covering.

However, after reevaluating everything (the pm I sent) I am going to take a different approach on how to implement the 2d physics class, because not every game is going to use the same class :)

33
General / Re: Laggy fixed time step loop
« on: June 05, 2016, 03:40:16 pm »
You said you were able to make a small example of a basic loop in another project...you might try posting that code which may help these guys better provide an explanation of what you are doing wrong, if anything  ;)

34
Just throwing this out there because I just finished reading this: Game Programming Patterns

It really helped me get a better feel for how I was designing my engine, and how to better setup the architecture.  Following along the best I can with the code example, it looks like you are simply trying to break up the objects rendering from the object.  The section Design Patterns Revisited may be of interest in this situation, but the whole book is really good...and it's free to read ;)

35
DotNet / Re: How to hide the sfml .dlls from my solution explorer?
« on: June 05, 2016, 12:41:11 am »
@zsbzsb - But they will still be required to be in the same folder as the build .exe file, correct?  There is not way to have say a "Libs" folder for all the .dll's, then just have all that put in the build folder?

I just want to be sure I am correct on whether that is the case or not :)

36
General / Re: Laggy fixed time step loop
« on: June 04, 2016, 07:48:36 pm »
I'm using VS 2013 because I'm too lazy to upgrade.  But so far with that simple logic, objects move smoothly, but I have not tried putting a lot of objects on there to see if it makes any difference.

I thought I would throw the idea out there anyways, starting over with a small working example may help pinpoint f there is something else that could be causing any lag with the rest of your code.

Happax has a time step project that may be of interest to you since you are using C++ Kairos - Timing Library.  Since I'm using VB, and not very smart, I am unable to port it so I can use it, LOL

37
General / Re: Laggy fixed time step loop
« on: June 04, 2016, 06:46:44 pm »
I just recently had issues with my time step in another thread.  However, may what helped me will help you get a better idea of how to setup your loop:

SFML and Game time
Some pseudo code for an implementation of fixed timestep:
deltaTime = 0.1 seconds
while (windowIsOpen)
{
    currentTime = clock.currentTime
    timeToProcess = timeToProcess + currentTime - previousTime
    previousTime = currentTime

    while (timeToProcess >= deltaTime)
    {
        applyLogicAndPhysics()
        timeToProcess = timeToProcess - deltaTime
    }

    prepareDisplay()
    drawDisplay()
}

38
Graphics / Re: SFML and Game time
« on: June 04, 2016, 04:57:04 pm »
Yes, I can multiply by scalar values.  What I don't understand is why I would want to multiply the entire position, including horizontal (x) coordinate as well.  This likely has more to do with the type of game you are designing for.  What works for making one planet rotate around a sun (particle A in middle, particle B circling) in an example, is not going to work similarly to a character jumping.  So a normal physics engine is going to use functionA when gravity is pulling in the center, and functionB when gravity is pulling down...probably not likely.

This is the original code from the Gaffer TimeStep and Integration sources:
float acceleration(const State &state, float t)
{
        const float k = 10;
        const float b = 1;
        return - k*state.x - b*state.v;
}
 

I believe it is the same thing as what I am doing, and the b = 1 just makes no sense, because before subtraction, multiplication is going to happen without parenthesis defining which come first.  And why is he passing t (time step?) through, yet doing nothing with it?  However, in Timestep when converted to VB code, the ball in the center just springs left to right, so maybe that is why he is calculating things the way he is?

I am going to have to let this be for now because I am not making any progress understanding how to mush everything else in there, not to mention what all I have to mush in there for it to calculate correctly.  It seems a physics engine is going to be out of the scope of my understanding.  Don't get me wrong, everything you guys have had to say make 100% sense, but I believe trying to properly take into account all the variables that I am supposed to be calculating is just too overwhelming.

All that being said, I have not even touched code in the last few days because I have been reading this: http://gameprogrammingpatterns.com.  Just in case no one has come across it I thought I would pass it along.  It's great and has given me a better insight on how I need to develop my engine.

No joke, I have been so stubborn about changing languages in the last 8 years because of how much I like VB, but now with all this I feel I might make better progress if I just moved to C++ because there is so much more support for doing really complicated stuff...not to mention much smarter people already have working physics engines working for C++  ;D

39
Graphics / Re: SFML and Game time
« on: June 03, 2016, 03:18:49 am »
Quote
You're trying to smush 2 dimensions (x and y) into 1 dimension for rk4.

Yes and no.  Initially I was, but then realized with several examples that the (x, v) referred to position and velocity.  C++ programming examples provided enough info for calculating the position of a particle, but not as a 1 dimensional point, which confused me even more.  Some examples were using single values for their states and not vector values, while others did use vectors, but the same equations as the single value states.

I honestly felt a bit better that no one else had a definitive idea of what they were doing since everyone was doing something different o achieve the same results :)

I had not heard of the Taylor Series, but have the wiki page pulled up to read over in a bit.  I believe "jerk" and "jolt" are possibly "impulse" or "thrust" as well, as I have ran into those references many times over the past few weeks.

I have also ran into RK4 equations that calculate not only (k1, k2, k3, k4) but (l1, l2, l3, l4) which refer to a coupled equation, which I had to read even more info on that made much less sense.  (a1, a2, a3, a4) are in a few as well, but they calculate what I believe is acceleration from (kn, ln).  Honestly the more that is added the more sense it makes, yet confuses the heck out of me even more, LOL

Quote
What you should do in that function, is add together all sources of acceleration on an object. Gravity, collisions, friction, drag.... springs. :) Then return that total.
That is the simplest explanation of what-to-do I have ran into regarding all of this.  It gives me a much better idea of what all needs to be calculated in that function so it will calculate accordingly.

My original goal of extending my engine has been drastically changed to me reinventing the wheel for a lot of things that just do not publicly exist for vb.net apps.  And while there are some C# libraries that I could use, this is proving to be a very eye-opening experience of what little I really understand about what I need to do to accomplish a simple 2d platformer engine, correctly at least.  I am literally 1 month in and essentially have not 1 line of working code that is going to be able to be used in my final project outline (aside from the time step).  That's 6 month's in total on my entire engine that I am putting on the back burner to brush up on more logical and applicable math concepts ;)


40
Graphics / Re: SFML and Game time
« on: June 02, 2016, 03:32:11 pm »
Yes, I have recently tried using vectors to try to work through this, Vector2f to be precise.  Even when I use 2 vectors in the Enum State, one for the [position(x,y) As Vector2f] and one for the [velocity(x,y) As Vector2f], I still have to access them like this:

Obj.State.Position.Y += Obj.State.Velocity.Y * DT
 

Several examples I have come across (in C++) actually use the entire Vector in the calculations.  Those are mostly in particle simulators that change both the (x,y) values at the same time so an object will go in an ellipse around a central object.

After a brief break to brush up on calculus, using the original code from the integration example, I do not understand this:

Private Function acceleration(ByVal state As State, ByVal t As Single) As Single
        Const k As Single = 10                      '//-------gravity
        Const b As Single = 1                        '//-------randomly obscure value
        Return -k * state.pos - b * state.vel  '//------this line, right here...
    End Function
 

I can partially get the slimmed down equations work though, but struggling to understand why so I can finish adding stuff to it.  For the most part every RK2-4 example uses the same math equations regardless of language:

Runge-Kutta_method
double rk4(double(*f)(double, double), double dx, double x, double y)
{
        double  k1 = dx * f(x, y),
                k2 = dx * f(x + dx / 2, y + k1 / 2),
                k3 = dx * f(x + dx / 2, y + k2 / 2),
                k4 = dx * f(x + dx, y + k3);
        return y + (k1 + 2 * k2 + 2 * k3 + k4) / 6;
}
 
double rate(double x, double y)
{
        return x * sqrt(y);
}
 
int main(void)
{
        double *y, x, y2;
        double x0 = 0, x1 = 10, dx = .1;
        int i, n = 1 + (x1 - x0)/dx;
        y = malloc(sizeof(double) * n);
 
        for (y[0] = 1, i = 1; i < n; i++)
                y[i] = rk4(rate, dx, x0 + dx * (i - 1), y[i-1]);
 
        printf("x\ty\trel. err.\n------------\n");
        for (i = 0; i < n; i += 10) {
                x = x0 + dx * i;
                y2 = pow(x * x / 4 + 1, 2);
                printf("%g\t%g\t%g\n", x, y[i], y[i]/y2 - 1);
        }
 
        return 0;
}
 

Unless I am reading that wrong, it and nearly every other code example using RK4 use [pos * Sqrt(vel)] to work out the f functions, which works if I swap the positions and velocities in the function.  However, buried way off in a power point file I alternatively found [dy/dx = y-x^2] to work out the functions.  That does not return proper results though (but I cannot remember what it does right now).

Eh, wall-o-text again :/ .  The reason I need to understand this is because there are several things I am not able to calculate, like Drag & Friction.  Acceleration seems to be calculated somewhere in there, and depending on which method I try to calculate the function will appear to speed up as an object is falling...I just don't know where.

Gonna go back and reevaluate the needs of this method, or needing a physics engine altogether...

41
DotNet / Re: How to hide the sfml .dlls from my solution explorer?
« on: May 30, 2016, 07:51:03 am »
I have come across several threads when I first started using SFML about how to keep the dll's in a separate folder myself.  Unfortunately this is not possible.  The .dll file have to be in the same directory as you exe.

42
Graphics / Re: SFML and Game time
« on: May 29, 2016, 03:58:39 am »
   Private Structure State
        Dim pos As Single
        Dim vel As Single
    End Structure
 

The original C++ code for this structure is:

struct State
{
        float x;
        float v;
};
 

From my understanding of the syntax a float is the smallest variable that can be used and should translate to single in vb.net.

I replaced State(x, v,) with State(pos, vel) so I understand it better (position, velocity).  In a 2d environment there's coordinates for Object.Position(x, y) and Object.Velocity(x, y).  Since I cannot store a vector value in a single, and I have no idea what I am doing, I tried this:

   Private Structure State
        Dim posX As Single
        Dim posY As Single
        Dim velX As Single
        Dim velY As Single
    End Structure
 

And modified the rest of the methods and functions to support that.  But since it is not used in the original C++ code, and none of the simple methods for RK4 used anything like that I felt it was best to try something more realistic, instead of my redneck-math-foo I tried to develop, LOL

I also realized that this was not intended to find the (x) horizontal values for velocity, only the vertical values.  I have found only 1 other source specific to vb for resolving all the physics for a falling ball.  However the maths used for it were very flawed, and were not easily compatible with anything else, such as the trig functions used for multiple object collisions.

Regardless of all that, I have had the gravity partially working before I actually had a fixed time step.  The whole point of starting this was to make sure the maths were correct so I could extend my 2d top down engine to support side scrolling platform.  Since just about all the math involved relies on a fixed time step, I have to sit down again and go over pretty much everything.  I honestly did not know it was going to be this much work, time, and confusion just trying to get not only something that works, but something that works like it is supposed to so that all they other systems work better.

***Note:  I believe my maths are completely wrong on the slimmed down RK4, and I have the positions and velocities backwards.

43
Graphics / Re: SFML and Game time
« on: May 29, 2016, 01:22:00 am »
Yeah, this was all my original code for the RK4 method that I ninja'd from the C++ code examples.  Before I followed your instructions for fixing my timestep I had this working, but since I implemented the fix I am going back over all the code, because there is a lot that is being left out of the calculations (momentum, friction).

More basic equations can be found here Runge Kutta 4...it took me forever to find something that was easy to understand, and not have all the complicated symbols.

One thing I do not understand about all of this is why isn't any of the (x) values being calculated?  Because all this is totally new to me, and I suck at differential equations, this has been a struggle to understand.

Regardless, since this is VB, it is about as close to pseudo code as you can get ;)

    Private Structure State
        Dim pos As Single ' position
        Dim vel As Single ' velocity
    End Structure

    Private Structure Derivative
        Dim dx As Single ' dx/dt = velocity
        Dim dv As Single ' dv/dt = acceleration
    End Structure

    Private Function acceleration(ByVal state As State, ByVal t As Single) As Single
        Const k As Single = 10
        Const b As Single = 1
        Return -(k * state.pos - b * state.vel)
    End Function

    Private Function evaluate(ByVal initial As State, ByVal t As Single) As Derivative
        Dim output As New Derivative()
        output.dx = initial.vel
        output.dv = acceleration(initial, t)
        Return output
    End Function

    Private Function evaluate(ByVal initial As State, ByVal t As Single, ByVal dt As Single, ByVal d As Derivative) As Derivative
        Dim state As New State()
        state.pos = initial.pos + d.dx * dt
        state.vel = initial.vel + d.dv * dt
        Dim output As New Derivative()
        output.dx = state.vel
        output.dv = acceleration(state, t + dt)
        Return output
    End Function

    Private Sub integrate(ByVal state As State, ByVal t As Single, ByVal dt As Single)
        Dim a As Derivative = evaluate(state, t)
        Dim b As Derivative = evaluate(state, t, dt * 0.5F, a)
        Dim c As Derivative = evaluate(state, t, dt * 0.5F, b)
        Dim d As Derivative = evaluate(state, t, dt, c)

        Dim dxdt As Single = (1.0F / 6.0F) * (a.dx + (2.0F * (b.dx + c.dx)) + d.dx)
        Dim dvdt As Single = (1.0F / 6.0F) * (a.dv + (2.0F * (b.dv + c.dv)) + d.dv)

        state.pos = state.pos + dxdt * dt
        state.vel = state.vel + dvdt * dt
    End Sub
 

44
Graphics / Re: SFML and Game time
« on: May 28, 2016, 11:44:14 pm »
No joke, but I literally almost had that exact same code after downloading the actual C++ sources from the tutorial.  It took me quite a while to figure out why the movements were so sudden, meaning I would press a direction and the ball was on the other side of the screen.

I had to look at Kairos Timestep example to figure out I had to multiply by the delta time.  For some reason everything I had for RK4 movement would not work, so I just implemented it inline and now it is working:

                Dim k1 As Double, k2 As Double, k3 As Double, k4 As Double
                '4th order
                k1 = deltaTime * dydx(Ball.Velocity.Y, Ball.Position.Y)
                k2 = deltaTime * dydx(Ball.Velocity.Y + deltaTime / 2, Ball.Position.Y + k1 / 2)
                k3 = deltaTime * dydx(Ball.Velocity.Y + deltaTime / 2, Ball.Position.Y + k2 / 2)
                k4 = deltaTime * dydx(Ball.Velocity.Y + deltaTime, Ball.Position.Y + k3)
                Ball.Position.Y += (1 / 6) * (k1 + (2 * k2) + (2 * k3) + k4)
 

That is probably wrong though, but I will worry with it later.  Thanks again for all the help man!

45
Graphics / Re: SFML and Game time
« on: May 28, 2016, 04:46:50 pm »
I really appreciate you taking the time to explain this stuff better than what I am understanding it.

Okay, so essentially I am doing everything wrong in order to have a consistent game loop.  Current here is my loop:

        While (myRenderWindow.IsOpen)
            CalculateTimers()
            SetupScreen()
            ApplyPhysics()
            DrawEntities()
            DrawInfo()
            PresentScreen()
        End While
        DestroyGame()
 

Instead I should be moving all of my objects (ApplyPhysics) when I am calculating the timers?

All of this is really confusing.  I tried porting over the RK4 integration from his website.  The term "State" used in it is a Structure that holds a Position and Velocity definition.  However, the balls Position and Velocity both have an (x, y) coordinate value.  Since gravity is constantly applied to the Ball, am I only supposed to be calculating the Position.Y and Velocity.Y?

Dim alpha As Double = accumulator / dt
Dim state As State= currentState * alpha + previousState * (1.0 - alpha)
render(state)
 

I don't know about C++, but in VB there is no way to simply add [State(x, v) = currState(x. v) * alpha ...], and instead I would have to add:

[State.x = currState.x * alpha ...]
[State.v = currState.v * alpha ...]

Which is fine, but what does "render(state)" mean?  Is that simply just displaying everything I have moved and drawn to the screen, or have I completely missed the idea and should just take up stamp collecting for a hobby? LOL

Pages: 1 2 [3] 4 5 6