summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorLeandro Dorileo <dorileo@profusion.mobi>2012-12-18 21:15:25 +0000
committerLeandro Dorileo <dorileo@profusion.mobi>2012-12-18 21:15:25 +0000
commit1329aad821b7ee741bb29c7d40a2f91b0e03cb91 (patch)
tree0d31332c2f86da000b8139663f35d1be0bd9aa7b /legacy
parent412c269b1c2b58b3a985ebf52ed326b4980550fc (diff)
EPhysics: add soft body light implementation
Do not use the evas map 3d light util function for every slice and avoid the unexpected "mosaic" effect. SVN revision: 81306
Diffstat (limited to '')
-rw-r--r--legacy/ephysics/src/lib/ephysics_body.cpp64
1 files changed, 61 insertions, 3 deletions
diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp
index ce56efed53..98d8fce79d 100644
--- a/legacy/ephysics/src/lib/ephysics_body.cpp
+++ b/legacy/ephysics/src/lib/ephysics_body.cpp
@@ -24,7 +24,7 @@ extern "C" {
24 WRN("Not supported for cloth"); \ 24 WRN("Not supported for cloth"); \
25 return; \ 25 return; \
26 } \ 26 } \
27 } while(0); 27 } while(0)
28 28
29typedef struct _EPhysics_Body_Callback EPhysics_Body_Callback; 29typedef struct _EPhysics_Body_Callback EPhysics_Body_Callback;
30typedef struct _EPhysics_Body_Evas_Stacking EPhysics_Body_Evas_Stacking; 30typedef struct _EPhysics_Body_Evas_Stacking EPhysics_Body_Evas_Stacking;
@@ -80,13 +80,67 @@ _ephysics_body_cloth_anchor_mass_reset(EPhysics_Body *body)
80 DBG("Cloth anchors mass reset."); 80 DBG("Cloth anchors mass reset.");
81} 81}
82 82
83EAPI void
84_ephysics_body_soft_body_light_apply(Evas_Map *m, Evas_Coord lx, Evas_Coord ly, Evas_Coord lz, int lr, int lg, int lb, int ar, int ag, int ab, Evas_Coord bx, Evas_Coord by, Evas_Coord bz)
85{
86 double x, y, z, nx, ny, nz, ln, br;
87 Evas_Coord mx, my, mz, mr, mg, mb, ma;
88 int i;
89
90 for (i = 0; i < 4; i++)
91 {
92
93 evas_map_point_coord_get(m, i, &mx, &my, &mz);
94 evas_map_point_color_get(m, i, NULL, NULL, NULL, &ma);
95
96 x = mx;
97 y = my;
98 z = mz;
99
100 nx = sqrt(pow(bx - x, 2));
101 ny = sqrt(pow(by - y, 2));
102 nz = sqrt(pow(bz - z, 2));
103 ln = nx + ny + nz;
104
105 if (ln != 0.0)
106 {
107 nx /= ln;
108 ny /= ln;
109 nz /= ln;
110 }
111
112 x = lx - bx;
113 y = ly - by;
114 z = lz - bz;
115
116 ln = pow(x, 2) + pow(y, 2) + pow(z, 2);
117 ln = sqrt(ln);
118
119 if (ln != 0.0)
120 {
121 x /= ln;
122 y /= ln;
123 z /= ln;
124 }
125
126 br = (nx * x) + (ny * y) + (nz * z);
127 if (br < 0.0) br = 0.0;
128
129 mr = ar + ((lr - ar) * br);
130 mg = ag + ((lg - ag) * br);
131 mb = ab + ((lb - ab) * br);
132
133 evas_map_point_color_set(m, i, mr, mg, mb, ma);
134 }
135}
136
83static void 137static void
84_ephysics_body_soft_body_slices_apply(EPhysics_Body *body, Evas_Object *evas_obj, Eina_List *slices) 138_ephysics_body_soft_body_slices_apply(EPhysics_Body *body, Evas_Object *evas_obj, Eina_List *slices)
85{ 139{
86 double rate; 140 double rate;
87 void *list_data; 141 void *list_data;
88 Eina_List *l; 142 Eina_List *l;
89 Evas_Coord wy, wh, y0, y1, y2, x0, x1, x2, z0, z1, z2, w, h; 143 Evas_Coord wy, wh, y0, y1, y2, x0, x1, x2, z0, z1, z2, w, h, bx, by, bz;
90 Evas_Map *map; 144 Evas_Map *map;
91 btVector3 p0, p1, p2; 145 btVector3 p0, p1, p2;
92 btSoftBody::tFaceArray faces; 146 btSoftBody::tFaceArray faces;
@@ -95,6 +149,7 @@ _ephysics_body_soft_body_slices_apply(EPhysics_Body *body, Evas_Object *evas_obj
95 Evas_Coord lx, ly, lz; 149 Evas_Coord lx, ly, lz;
96 Eina_Bool light = EINA_FALSE; 150 Eina_Bool light = EINA_FALSE;
97 EPhysics_Camera *camera; 151 EPhysics_Camera *camera;
152
98 int px, py, pz, foc; 153 int px, py, pz, foc;
99 Eina_Bool perspective = EINA_FALSE; 154 Eina_Bool perspective = EINA_FALSE;
100 155
@@ -104,6 +159,8 @@ _ephysics_body_soft_body_slices_apply(EPhysics_Body *body, Evas_Object *evas_obj
104 NULL); 159 NULL);
105 evas_object_geometry_get(evas_obj, NULL, NULL, &w, &h); 160 evas_object_geometry_get(evas_obj, NULL, NULL, &w, &h);
106 161
162 ephysics_body_geometry_get(body, &bx, &by, &bz, NULL, NULL, NULL);
163
107 if ((body->light_apply) || 164 if ((body->light_apply) ||
108 (ephysics_world_light_all_bodies_get(body->world))) 165 (ephysics_world_light_all_bodies_get(body->world)))
109 { 166 {
@@ -174,7 +231,8 @@ _ephysics_body_soft_body_slices_apply(EPhysics_Body *body, Evas_Object *evas_obj
174 } 231 }
175 232
176 if (light) 233 if (light)
177 evas_map_util_3d_lighting(map, lx, ly, lz, lr, lg, lb, ar, ag, ab); 234 _ephysics_body_soft_body_light_apply(map, lx, ly, lz, lr, lg, lb, ar,
235 ag, ab, bx, by, bz);
178 236
179 evas_object_map_set(slice->evas_obj, map); 237 evas_object_map_set(slice->evas_obj, map);
180 evas_object_map_enable_set(slice->evas_obj, EINA_TRUE); 238 evas_object_map_enable_set(slice->evas_obj, EINA_TRUE);