fixed to 2D physics, makes it work again
This commit is contained in:
parent
a7854d3ae6
commit
52e2a1e98d
7 changed files with 22 additions and 12 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);\
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue