Added delta timestep to 2d simulation
This commit is contained in:
@@ -4446,8 +4446,8 @@ int main(int argc, char * argv[])
|
||||
std::cin >> debug_opt;
|
||||
if(debug_opt.compare("a")==0)
|
||||
{
|
||||
rc_intern_dirChange("/home/n00b/projects/bu/rcbasic_v400a5_linux/test_project_v4a5");
|
||||
rc_filename = "test.cbc";
|
||||
rc_intern_dirChange("/home/n00b/projects/rcbasic_alpha3/test_project");
|
||||
rc_filename = "main.cbc";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -946,7 +946,8 @@ int rc_canvasOpen(int w, int h, int vx, int vy, int vw, int vh, int mode, int ca
|
||||
{
|
||||
b2Vec2 gravity(0, 0);
|
||||
canvas.physics2D.world = new b2World(gravity);
|
||||
canvas.physics2D.timeStep = 1/60.0; //the length of time passed to simulate (seconds)
|
||||
canvas.physics2D.timeStep = -1; //the length of time passed to simulate (seconds)
|
||||
canvas.physics2D.time_stamp = SDL_GetTicks();
|
||||
canvas.physics2D.velocityIterations = 8; //how strongly to correct velocity
|
||||
canvas.physics2D.positionIterations = 3; //how strongly to correct position
|
||||
canvas.physics2D.enabled = true;
|
||||
@@ -3056,7 +3057,9 @@ void rc_preUpdate()
|
||||
if(rc_canvas[i].type != RC_CANVAS_TYPE_SPRITE)
|
||||
continue;
|
||||
|
||||
float step = rc_canvas[i].physics2D.timeStep;
|
||||
Uint32 delta_time = SDL_GetTicks() - rc_canvas[i].physics2D.time_stamp;
|
||||
rc_canvas[i].physics2D.time_stamp = SDL_GetTicks();
|
||||
float step = rc_canvas[i].physics2D.timeStep < 0 ? (delta_time*0.001f) : rc_canvas[i].physics2D.timeStep;
|
||||
int32 velocityIterations = rc_canvas[i].physics2D.velocityIterations;
|
||||
int32 positionIterations = rc_canvas[i].physics2D.positionIterations;
|
||||
|
||||
|
||||
@@ -307,7 +307,7 @@ struct rc_physicsWorld2D_obj
|
||||
b2World* world;
|
||||
|
||||
rc_contactListener_obj* contact_listener;
|
||||
float time_stamp;
|
||||
Uint32 time_stamp;
|
||||
float timeStep = 1/60.0; //the length of time passed to simulate (seconds)
|
||||
int velocityIterations = 8; //how strongly to correct velocity
|
||||
int positionIterations = 3; //how strongly to correct position
|
||||
|
||||
@@ -804,7 +804,9 @@ bool rc_spriteIsVisible(int spr_id)
|
||||
//This function is called on each canvas on update
|
||||
void drawSprites(int canvas_id)
|
||||
{
|
||||
float step = rc_canvas[canvas_id].physics2D.timeStep;
|
||||
Uint32 delta_time = SDL_GetTicks() - rc_canvas[canvas_id].physics2D.time_stamp;
|
||||
rc_canvas[canvas_id].physics2D.time_stamp = SDL_GetTicks();
|
||||
float step = rc_canvas[canvas_id].physics2D.timeStep < 0 ? (delta_time*0.001f) : rc_canvas[canvas_id].physics2D.timeStep;
|
||||
int32 velocityIterations = rc_canvas[canvas_id].physics2D.velocityIterations;
|
||||
int32 positionIterations = rc_canvas[canvas_id].physics2D.positionIterations;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# depslib dependency file v1.0
|
||||
1733023264 source:/home/n00b/Projects/RCBASIC4/rcbasic_runtime/main.cpp
|
||||
1733028476 source:/home/n00b/Projects/RCBASIC4/rcbasic_runtime/main.cpp
|
||||
"rc_os_defines.h"
|
||||
<emscripten.h>
|
||||
<sys/param.h>
|
||||
@@ -1247,7 +1247,7 @@
|
||||
1727545973 /home/n00b/Projects/RCBASIC4/rcbasic_runtime/RealisticWater.h
|
||||
<irrlicht.h>
|
||||
|
||||
1733027113 /home/n00b/Projects/RCBASIC4/rcbasic_runtime/rc_gfx.h
|
||||
1733028476 /home/n00b/Projects/RCBASIC4/rcbasic_runtime/rc_gfx.h
|
||||
"SDL.h"
|
||||
<SDL2/SDL.h>
|
||||
<irrlicht.h>
|
||||
@@ -1271,7 +1271,7 @@
|
||||
"rc_joints.h"
|
||||
<irrtheora.h>
|
||||
|
||||
1733027113 /home/n00b/Projects/RCBASIC4/rcbasic_runtime/rc_gfx_core.h
|
||||
1733028476 /home/n00b/Projects/RCBASIC4/rcbasic_runtime/rc_gfx_core.h
|
||||
"SDL.h"
|
||||
"btBulletDynamicsCommon.h"
|
||||
"BulletSoftBody/btSoftRigidDynamicsWorld.h"
|
||||
@@ -2487,7 +2487,7 @@
|
||||
<irrlicht.h>
|
||||
<cmath>
|
||||
|
||||
1731722537 /home/n00b/Projects/RCBASIC4/rcbasic_runtime/rc_spritelib.h
|
||||
1733028518 /home/n00b/Projects/RCBASIC4/rcbasic_runtime/rc_spritelib.h
|
||||
"SDL.h"
|
||||
<SDL2/SDL.h>
|
||||
"rc_sprite2D.h"
|
||||
|
||||
Reference in New Issue
Block a user