summaryrefslogtreecommitdiff
path: root/src/lib/ephysics
diff options
context:
space:
mode:
authorHenrique Dante de Almeida <hdante@profusion.mobi>2013-01-29 11:17:09 -0200
committerLucas De Marchi <lucas.demarchi@profusion.mobi>2013-02-26 10:17:28 -0300
commitb9ac180af64ef810eed95a5e08940cfa2a55b83a (patch)
tree5a4dbeb4ef3c467a7b14dbaf1c023260b46e407a /src/lib/ephysics
parent95623dee10f47328b7b52ed9faf228d3fa209f8b (diff)
ephysics: turn EPhysics_Body into a POD-type struct
EPhysics_Body is an Eina_Inlist, and Eina_Inlist iterator macros use offsetof(). Since using offsetof in C++ classes is invalid, EPhysics_Body must be a POD-type struct.
Diffstat (limited to 'src/lib/ephysics')
-rw-r--r--src/lib/ephysics/ephysics_body.cpp30
-rw-r--r--src/lib/ephysics/ephysics_private.h5
2 files changed, 23 insertions, 12 deletions
diff --git a/src/lib/ephysics/ephysics_body.cpp b/src/lib/ephysics/ephysics_body.cpp
index c27b99d..791ea50 100644
--- a/src/lib/ephysics/ephysics_body.cpp
+++ b/src/lib/ephysics/ephysics_body.cpp
@@ -795,7 +795,9 @@ _ephysics_body_new(EPhysics_World *world, btScalar mass, double cm_x, double cm_
795 } 795 }
796 796
797 rate = ephysics_world_rate_get(world); 797 rate = ephysics_world_rate_get(world);
798 body->scale = btVector3(1, 1, 1); 798 body->scale[0] = 1;
799 body->scale[1] = 1;
800 body->scale[2] = 1;
799 body->size.w = rate; 801 body->size.w = rate;
800 body->size.h = rate; 802 body->size.h = rate;
801 body->size.d = rate; 803 body->size.d = rate;
@@ -1057,7 +1059,7 @@ _ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Eva
1057 double mx, my, mz, sx, sy, sz; 1059 double mx, my, mz, sx, sy, sz;
1058 btTransform trans; 1060 btTransform trans;
1059 int wy, height; 1061 int wy, height;
1060 btVector3 body_scale; 1062 btVector3 body_scale, old_scale;
1061 1063
1062 ephysics_world_render_geometry_get(body->world, NULL, &wy, NULL, 1064 ephysics_world_render_geometry_get(body->world, NULL, &wy, NULL,
1063 NULL, &height, NULL); 1065 NULL, &height, NULL);
@@ -1073,10 +1075,11 @@ _ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Eva
1073 trans = _ephysics_body_transform_get(body); 1075 trans = _ephysics_body_transform_get(body);
1074 trans.setOrigin(btVector3(mx, my, mz)); 1076 trans.setOrigin(btVector3(mx, my, mz));
1075 body_scale = btVector3(sx, sy, sz); 1077 body_scale = btVector3(sx, sy, sz);
1078 old_scale = btVector3(body->scale[0], body->scale[1], body->scale[2]);
1076 1079
1077 if (body->type == EPHYSICS_BODY_TYPE_SOFT) 1080 if (body->type == EPHYSICS_BODY_TYPE_SOFT)
1078 { 1081 {
1079 body->soft_body->scale(btVector3(1, 1, 1) / body->scale); 1082 body->soft_body->scale(btVector3(1, 1, 1) / old_scale);
1080 body->soft_body->scale(body_scale); 1083 body->soft_body->scale(body_scale);
1081 body->rigid_body->proceedToTransform(trans); 1084 body->rigid_body->proceedToTransform(trans);
1082 _ephysics_body_transform_set(body, trans); 1085 _ephysics_body_transform_set(body, trans);
@@ -1085,7 +1088,7 @@ _ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Eva
1085 else if (body->type == EPHYSICS_BODY_TYPE_CLOTH) 1088 else if (body->type == EPHYSICS_BODY_TYPE_CLOTH)
1086 { 1089 {
1087 body->soft_body->setTotalMass(body->mass, true); 1090 body->soft_body->setTotalMass(body->mass, true);
1088 body->soft_body->scale(btVector3(1, 1, 1) / body->scale); 1091 body->soft_body->scale(btVector3(1, 1, 1) / old_scale);
1089 body->soft_body->scale(body_scale); 1092 body->soft_body->scale(body_scale);
1090 _ephysics_body_transform_set(body, trans); 1093 _ephysics_body_transform_set(body, trans);
1091 _ephysics_body_cloth_constraints_rebuild(body); 1094 _ephysics_body_cloth_constraints_rebuild(body);
@@ -1107,7 +1110,9 @@ _ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Eva
1107 body->size.w = w; 1110 body->size.w = w;
1108 body->size.h = h; 1111 body->size.h = h;
1109 body->size.d = d; 1112 body->size.d = d;
1110 body->scale = body_scale; 1113 body->scale[0] = sx;
1114 body->scale[1] = sy;
1115 body->scale[2] = sz;
1111 1116
1112 DBG("Body %p position changed to (%lf, %lf, %lf).", body, mx, my, mz); 1117 DBG("Body %p position changed to (%lf, %lf, %lf).", body, mx, my, mz);
1113 DBG("Body %p scale changed to (%lf, %lf, %lf).", body, sx, sy, sz); 1118 DBG("Body %p scale changed to (%lf, %lf, %lf).", body, sx, sy, sz);
@@ -1131,9 +1136,10 @@ _ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h, Evas_Coor
1131 body_scale = btVector3(sx, sy, sz); 1136 body_scale = btVector3(sx, sy, sz);
1132 if (body->type == EPHYSICS_BODY_TYPE_SOFT) 1137 if (body->type == EPHYSICS_BODY_TYPE_SOFT)
1133 { 1138 {
1139 btVector3 old_scale(body->scale[0], body->scale[1], body->scale[2]);
1134 trans = _ephysics_body_transform_get(body); 1140 trans = _ephysics_body_transform_get(body);
1135 1141
1136 body->soft_body->scale(btVector3(1, 1, 1) / body->scale); 1142 body->soft_body->scale(btVector3(1, 1, 1) / old_scale);
1137 body->soft_body->scale(body_scale); 1143 body->soft_body->scale(body_scale);
1138 1144
1139 _ephysics_body_transform_set(body, trans); 1145 _ephysics_body_transform_set(body, trans);
@@ -1158,7 +1164,9 @@ _ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h, Evas_Coor
1158 body->size.w = w; 1164 body->size.w = w;
1159 body->size.h = h; 1165 body->size.h = h;
1160 body->size.d = d; 1166 body->size.d = d;
1161 body->scale = body_scale; 1167 body->scale[0] = sx;
1168 body->scale[1] = sy;
1169 body->scale[2] = sz;
1162 1170
1163 ephysics_body_activate(body, EINA_TRUE); 1171 ephysics_body_activate(body, EINA_TRUE);
1164} 1172}
@@ -3547,17 +3555,17 @@ ephysics_body_geometry_get(const EPhysics_Body *body, Evas_Coord *x, Evas_Coord
3547 } 3555 }
3548 3556
3549 trans = _ephysics_body_transform_get(body); 3557 trans = _ephysics_body_transform_get(body);
3550 scale = body->scale; 3558 scale = btVector3(body->scale[0], body->scale[1], body->scale[2]);
3551 3559
3552 rate = ephysics_world_rate_get(body->world); 3560 rate = ephysics_world_rate_get(body->world);
3553 ephysics_world_render_geometry_get(body->world, NULL, &wy, NULL, 3561 ephysics_world_render_geometry_get(body->world, NULL, &wy, NULL,
3554 NULL, &height, NULL); 3562 NULL, &height, NULL);
3555 height += wy; 3563 height += wy;
3556 3564
3557 if (x) *x = round((trans.getOrigin().getX() - scale.x() / 2) * rate); 3565 if (x) *x = round((trans.getOrigin().getX() - scale[0] / 2) * rate);
3558 if (y) *y = height - round((trans.getOrigin().getY() + scale.y() / 2) 3566 if (y) *y = height - round((trans.getOrigin().getY() + scale[1] / 2)
3559 * rate); 3567 * rate);
3560 if (z) *z = round((trans.getOrigin().getZ() - scale.z() / 2) * rate); 3568 if (z) *z = round((trans.getOrigin().getZ() - scale[2] / 2) * rate);
3561 if (w) *w = body->size.w; 3569 if (w) *w = body->size.w;
3562 if (h) *h = body->size.h; 3570 if (h) *h = body->size.h;
3563 if (d) *d = body->size.d; 3571 if (d) *d = body->size.d;
diff --git a/src/lib/ephysics/ephysics_private.h b/src/lib/ephysics/ephysics_private.h
index 36ece8c..5b09a29 100644
--- a/src/lib/ephysics/ephysics_private.h
+++ b/src/lib/ephysics/ephysics_private.h
@@ -131,6 +131,9 @@ struct _EPhysics_Body_Face_Slice {
131 Eina_List *slices; 131 Eina_List *slices;
132}; 132};
133 133
134// EPhysics_Body is an Eina_Inlist, and Eina_Inslist iterator macros use
135// offsetof(). Since using offsetof in C++ classes is invalid,
136// EPhysics_Body must be a POD-type struct.
134struct _EPhysics_Body { 137struct _EPhysics_Body {
135 EINA_INLIST; 138 EINA_INLIST;
136 btCollisionShape *collision_shape; 139 btCollisionShape *collision_shape;
@@ -140,7 +143,7 @@ struct _EPhysics_Body {
140 EPhysics_World *world; 143 EPhysics_World *world;
141 int walking; 144 int walking;
142 EPhysics_Body_Size size; 145 EPhysics_Body_Size size;
143 btVector3 scale; 146 btScalar scale[3];
144 void *data; 147 void *data;
145 Eina_Inlist *callbacks; 148 Eina_Inlist *callbacks;
146 Eina_List *collision_groups; 149 Eina_List *collision_groups;