From 52e2a1e98df9f1a7d69c2b35c7be9edc1a8e9753 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 15 Jan 2017 09:49:58 -0300 Subject: [PATCH] fixed to 2D physics, makes it work again --- main/tests/test_physics.cpp | 7 ++++++- main/tests/test_physics_2d.cpp | 13 +++++++++---- servers/physics/body_sw.cpp | 2 +- servers/physics_2d/body_pair_2d_sw.cpp | 2 +- servers/physics_2d/collision_solver_2d_sw.cpp | 4 ++-- servers/physics_2d/shape_2d_sw.h | 2 +- servers/physics_2d/space_2d_sw.cpp | 4 ++-- 7 files changed, 22 insertions(+), 12 deletions(-) diff --git a/main/tests/test_physics.cpp b/main/tests/test_physics.cpp index ea98da34caf..20c0c080705 100644 --- a/main/tests/test_physics.cpp +++ b/main/tests/test_physics.cpp @@ -345,11 +345,16 @@ public: /* CAMERA */ camera = vs->camera_create(); + RID viewport = vs->viewport_create(); + Size2i screen_size = OS::get_singleton()->get_window_size(); + vs->viewport_set_size(viewport,screen_size.x,screen_size.y); + vs->viewport_attach_to_screen(viewport,Rect2(Vector2(),screen_size)); + vs->viewport_set_active(viewport,true); vs->viewport_attach_camera( viewport, camera ); - vs->viewport_attach_to_screen(viewport); vs->viewport_set_scenario( viewport, scenario ); + vs->camera_set_perspective(camera,60,0.1,40.0); vs->camera_set_transform(camera,Transform( Basis(), Vector3(0,9,12))); //vs->scenario_set_debug(scenario,VS::SCENARIO_DEBUG_WIREFRAME); diff --git a/main/tests/test_physics_2d.cpp b/main/tests/test_physics_2d.cpp index 8a6a8c78f9c..76d1afd2acf 100644 --- a/main/tests/test_physics_2d.cpp +++ b/main/tests/test_physics_2d.cpp @@ -63,7 +63,7 @@ class TestPhysics2DMainLoop : public MainLoop { }; - BodyShapeData body_shape_data[6]; + BodyShapeData body_shape_data[8]; void _create_body_shape_data() { @@ -191,7 +191,7 @@ class TestPhysics2DMainLoop : public MainLoop { Image image(convex_png); - body_shape_data[Physics2DServer::SHAPE_CUSTOM+1].image=vs->texture_create_from_image(image); + body_shape_data[Physics2DServer::SHAPE_CONVEX_POLYGON].image=vs->texture_create_from_image(image); RID convex_polygon_shape = ps->shape_create(Physics2DServer::SHAPE_CONVEX_POLYGON); @@ -206,7 +206,7 @@ class TestPhysics2DMainLoop : public MainLoop { arr.push_back(Point2(11,7)-sb); ps->shape_set_data(convex_polygon_shape,arr); - body_shape_data[Physics2DServer::SHAPE_CUSTOM+1].shape = convex_polygon_shape; + body_shape_data[Physics2DServer::SHAPE_CONVEX_POLYGON].shape = convex_polygon_shape; } @@ -382,8 +382,13 @@ public: RID vp = vs->viewport_create(); canvas = vs->canvas_create(); + + Size2i screen_size = OS::get_singleton()->get_window_size(); vs->viewport_attach_canvas(vp,canvas); - vs->viewport_attach_to_screen(vp,Rect2(Vector2(),OS::get_singleton()->get_window_size())); + vs->viewport_set_size(vp,screen_size.x,screen_size.y); + vs->viewport_attach_to_screen(vp,Rect2(Vector2(),screen_size)); + vs->viewport_set_active(vp,true); + Transform2D smaller; //smaller.scale(Vector2(0.6,0.6)); //smaller.elements[2]=Vector2(100,0); diff --git a/servers/physics/body_sw.cpp b/servers/physics/body_sw.cpp index 81604dd5e11..a67dda3a015 100644 --- a/servers/physics/body_sw.cpp +++ b/servers/physics/body_sw.cpp @@ -621,7 +621,7 @@ void BodySW::integrate_velocities(real_t p_step) { if (ang_vel!=0.0) { Vector3 ang_vel_axis = total_angular_velocity / ang_vel; - Basis rot( ang_vel_axis, -ang_vel*p_step ); + Basis rot( ang_vel_axis, ang_vel*p_step ); Basis identity3(1, 0, 0, 0, 1, 0, 0, 0, 1); transform.origin += ((identity3 - rot) * transform.basis).xform(center_of_mass_local); transform.basis = rot * transform.basis; diff --git a/servers/physics_2d/body_pair_2d_sw.cpp b/servers/physics_2d/body_pair_2d_sw.cpp index 72ae221c398..e6b62ffa661 100644 --- a/servers/physics_2d/body_pair_2d_sw.cpp +++ b/servers/physics_2d/body_pair_2d_sw.cpp @@ -249,7 +249,7 @@ bool BodyPair2DSW::setup(float p_step) { Transform2D xform_A = xform_Au * A->get_shape_transform(shape_A); Transform2D xform_Bu = B->get_transform(); - xform_Bu.translate(-A->get_transform().get_origin()); + xform_Bu.elements[2]-=A->get_transform().get_origin(); Transform2D xform_B = xform_Bu * B->get_shape_transform(shape_B); Shape2DSW *shape_A_ptr=A->get_shape(shape_A); diff --git a/servers/physics_2d/collision_solver_2d_sw.cpp b/servers/physics_2d/collision_solver_2d_sw.cpp index 02d59b69f03..20a5934eb83 100644 --- a/servers/physics_2d/collision_solver_2d_sw.cpp +++ b/servers/physics_2d/collision_solver_2d_sw.cpp @@ -203,14 +203,14 @@ bool CollisionSolver2DSW::solve_concave(const Shape2DSW *p_shape_A,const Transfo cinfo.aabb_tests=0; Transform2D rel_transform = p_transform_A; - rel_transform.translate(-p_transform_B.get_origin()); + rel_transform.elements[2]-=p_transform_B.get_origin(); //quickly compute a local Rect2 Rect2 local_aabb; for(int i=0;i<2;i++) { - Vector2 axis( p_transform_B.get_axis(i) ); + Vector2 axis( p_transform_B.elements[i] ); float axis_scale = 1.0/axis.length(); axis*=axis_scale; diff --git a/servers/physics_2d/shape_2d_sw.h b/servers/physics_2d/shape_2d_sw.h index 9160d064ef5..07a9d84ec86 100644 --- a/servers/physics_2d/shape_2d_sw.h +++ b/servers/physics_2d/shape_2d_sw.h @@ -150,7 +150,7 @@ _FORCE_INLINE_ void project_range_cast(const Vector2& p_cast, const Vector2& p_n real_t mina,maxa;\ real_t minb,maxb;\ Transform2D ofsb=p_transform;\ - ofsb.translate(p_cast);\ + ofsb.elements[2]+=p_cast;\ project_range(p_normal,p_transform,mina,maxa);\ project_range(p_normal,ofsb,minb,maxb); \ r_min=MIN(mina,minb);\ diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index e95707f135e..a48b6d38278 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -714,7 +714,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co break; } - body_transform.translate(recover_motion); + body_transform.elements[2]+=recover_motion; body_aabb.pos+=recover_motion; recover_attempts--; @@ -863,7 +863,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co //it collided, let's get the rest info in unsafe advance Transform2D ugt = body_transform; - ugt.translate(p_motion*unsafe); + ugt.elements[2]+=p_motion*unsafe; _RestCallbackData2D rcd; rcd.best_len=0;