Sorry if this post is a bit vague, it has been very difficult to wrap my head around everything involved.
For starters:
Language - VB.NET...yes, I already know -_-
SFML - Posting these questions here because the graphics engine plays a key part in my maths.
Farseer - Unable to locate examples that will translate into vb.net
Box2d - I found 1 C# example that I was able to get translated, but am unable to grasp how to set the objects sizes and positions...let's pretend that I don't program as a 9-5, and/or am an idiot.
Okay, with that out of the way I have been transitioning a top down game engine to be able to support 2D side-scrolling. To test I have been simply trying to get a ball to have visually accurate physics in a testbed application. It didn't take very long to determine that I would need to incorporate a physics engine for the simple purpose of providing (any) objects realistic physics...and since I have been unable to locate a solid example in vb.net, and trying to get the above engines to work properly is beyond the scope of my understanding, I am simplifying things and building my own engine.
Change in Time, or
Delta Time, is one thing that has come up in just about every physics equation that I would have to use to calculate falling/collision/velocity. The way I am using SFML in my application has a large effect on the time that I need to calculate:
Private Sub InitializeEngine()
' Request a 24-bits depth bufer when creating the window.
Dim contextSettings As New ContextSettings()
contextSettings.DepthBits = 24
' Create main window.
_testbedWindow = New RenderWindow(New VideoMode(800, 600), "SFML Graphic Controls Testbed Application.", Styles.Default, contextSettings)
_testbedWindow.SetVerticalSyncEnabled(True)
_testbedWindow.SetFramerateLimit(60)
End Sub
I understand what SetFramerateLimit does, but when it is turned off it seems pointless since SetVerticalSyncEnabled keeps my FPS around ~60. However, just found out that is most likely due to the refresh rate of my monitor, and someone with a 75hertz refresh rate would have a higher FPS without the limit. Perfect, and I understand it...
Now in my game loop I am calling this every loop:
' Reset to keep all timers in sync.
_currentTick = Environment.TickCount
' Counts time every loop, then updates the FPS every second.
If _currentTick - _timeCount >= 1000 Then
_fps = _fpsCount
_fpsCount = 0
_timeCount = _currentTick
Else
_fpsCount += 1
End If
Great...every loop add 1 to the _fpsCount until it reaches 1000 ticks, then update my _fps value that will display on my screen...Check!
In order to achieve realistic physics, I have to get the
Change in Time between each game loop. Since I am already returning the Environment.TickCount every loop, what is the most practical, and most accurate, method to produce the time between the frames? I could have a Delta_Time variable setup, but I honestly have no clue using SFML the way currently am to return a value to apply to it, that can be applied to the physics equations I have found with my google-foo.
Please not I'm not looking for code, just the logic behind how this is supposed to work properly. If there is anything that I have overlooked, please let me know.