forked from enlightenment/efl
evas/evas3d: applied eo intensively and fix indentation.
This commit is contained in:
parent
4d8e12089c
commit
022ab7f2e6
|
@ -1,6 +1,5 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
#define EFL_EO_API_SUPPORT
|
||||
#define EFL_BETA_API_SUPPORT
|
||||
|
||||
#include <Eo.h>
|
||||
#include <Evas.h>
|
||||
|
@ -263,7 +262,7 @@ main(void)
|
|||
evas_obj_visibility_set(EINA_TRUE));
|
||||
|
||||
/* Set the image object as render target for 3D scene. */
|
||||
eo_do(image, evas_obj_image_scene_set(data.scene));
|
||||
eo_do(image, evas_obj_image_scene_set(data.scene));
|
||||
|
||||
/* Add animation timer callback. */
|
||||
ecore_timer_add(0.016, _animate_scene, &data);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
#define EFL_EO_API_SUPPORT
|
||||
#define EFL_BETA_API_SUPPORT
|
||||
|
||||
#include <Eo.h>
|
||||
#include <Evas.h>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
#define EFL_EO_API_SUPPORT
|
||||
#define EFL_BETA_API_SUPPORT
|
||||
|
||||
#include <Eo.h>
|
||||
#include <Evas.h>
|
||||
|
|
|
@ -1,63 +1,15 @@
|
|||
#define EFL_EO_API_SUPPORT
|
||||
#define EFL_BETA_API_SUPPORT
|
||||
|
||||
#include <math.h>
|
||||
#include <Eo.h>
|
||||
#include <Evas.h>
|
||||
#include <Ecore.h>
|
||||
#include <Ecore_Evas.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <Evas.h>
|
||||
|
||||
#define WIDTH 400
|
||||
#define HEIGHT 400
|
||||
|
||||
Ecore_Evas *ecore_evas = NULL;
|
||||
Evas *evas = NULL;
|
||||
Evas_Object *background = NULL;
|
||||
Evas_Object *image = NULL;
|
||||
|
||||
Evas_3D_Scene *scene = NULL;
|
||||
Evas_3D_Node *root_node = NULL;
|
||||
Evas_3D_Node *camera_node = NULL;
|
||||
Evas_3D_Camera *camera = NULL;
|
||||
Evas_3D_Node *mesh_node = NULL;
|
||||
Evas_3D_Mesh *mesh = NULL;
|
||||
Evas_3D_Material *material = NULL;
|
||||
Evas_3D_Texture *texture_diffuse = NULL;
|
||||
|
||||
static Eina_Bool
|
||||
_animate_scene(void *data)
|
||||
{
|
||||
static float angle = 0.0f;
|
||||
|
||||
angle += 0.3;
|
||||
|
||||
eo_do((Evas_3D_Node *)data,
|
||||
evas_3d_node_orientation_angle_axis_set(angle, 0.0, 1.0, 0.0));
|
||||
|
||||
/* Rotate */
|
||||
if (angle > 360.0)
|
||||
angle -= 360.0f;
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_on_delete(Ecore_Evas *ee EINA_UNUSED)
|
||||
{
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
static void
|
||||
_on_canvas_resize(Ecore_Evas *ee)
|
||||
{
|
||||
int w, h;
|
||||
|
||||
ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
|
||||
|
||||
evas_object_resize(background, w, h);
|
||||
evas_object_resize(image, w, h);
|
||||
evas_object_move(image, 0, 0);
|
||||
}
|
||||
|
||||
typedef struct _vec4
|
||||
{
|
||||
float x;
|
||||
|
@ -88,11 +40,56 @@ typedef struct _vertex
|
|||
vec3 texcoord;
|
||||
} vertex;
|
||||
|
||||
static int vertex_count = 0;
|
||||
static vertex *vertices = NULL;
|
||||
static Ecore_Evas *ecore_evas = NULL;
|
||||
static Evas *evas = NULL;
|
||||
static Eo *background = NULL;
|
||||
static Eo *image = NULL;
|
||||
static Eo *scene = NULL;
|
||||
static Eo *root_node = NULL;
|
||||
static Eo *camera_node = NULL;
|
||||
static Eo *camera = NULL;
|
||||
static Eo *mesh_node = NULL;
|
||||
static Eo *mesh = NULL;
|
||||
static Eo *material = NULL;
|
||||
static Eo *texture_diffuse = NULL;
|
||||
|
||||
static int index_count = 0;
|
||||
static unsigned short *indices = NULL;
|
||||
static int vertex_count = 0;
|
||||
static vertex *vertices = NULL;
|
||||
static int index_count = 0;
|
||||
static unsigned short *indices = NULL;
|
||||
|
||||
static Eina_Bool
|
||||
_animate_scene(void *data)
|
||||
{
|
||||
static float angle = 0.0f;
|
||||
|
||||
angle += 0.3;
|
||||
|
||||
eo_do((Evas_3D_Node *)data,
|
||||
evas_3d_node_orientation_angle_axis_set(angle, 0.0, 1.0, 0.0));
|
||||
|
||||
/* Rotate */
|
||||
if (angle > 360.0) angle -= 360.0f;
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_on_delete(Ecore_Evas *ee EINA_UNUSED)
|
||||
{
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
static void
|
||||
_on_canvas_resize(Ecore_Evas *ee)
|
||||
{
|
||||
int w, h;
|
||||
|
||||
ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
|
||||
evas_object_resize(background, w, h);
|
||||
evas_object_resize(image, w, h);
|
||||
evas_object_move(image, 0, 0);
|
||||
}
|
||||
|
||||
static inline vec3
|
||||
_normalize(const vec3 *v)
|
||||
|
@ -110,154 +107,139 @@ _normalize(const vec3 *v)
|
|||
static void
|
||||
_sphere_fini()
|
||||
{
|
||||
if (vertices)
|
||||
free(vertices);
|
||||
|
||||
if (indices)
|
||||
free(indices);
|
||||
free(vertices);
|
||||
free(indices);
|
||||
}
|
||||
|
||||
static void
|
||||
_sphere_init(int precision)
|
||||
{
|
||||
int i, j;
|
||||
unsigned short *index;
|
||||
int i, j;
|
||||
unsigned short *index;
|
||||
|
||||
vertex_count = (precision + 1) * (precision + 1);
|
||||
index_count = precision * precision * 6;
|
||||
vertex_count = (precision + 1) * (precision + 1);
|
||||
index_count = precision * precision * 6;
|
||||
|
||||
/* Allocate buffer. */
|
||||
vertices = malloc(sizeof(vertex) * vertex_count);
|
||||
indices = malloc(sizeof(unsigned short) * index_count);
|
||||
/* Allocate buffer. */
|
||||
vertices = malloc(sizeof(vertex) * vertex_count);
|
||||
indices = malloc(sizeof(unsigned short) * index_count);
|
||||
|
||||
for (i = 0; i <= precision; i++)
|
||||
{
|
||||
double lati = (M_PI * (double)i) / (double)precision;
|
||||
double y = cos(lati);
|
||||
double r = fabs(sin(lati));
|
||||
for (i = 0; i <= precision; i++)
|
||||
{
|
||||
double lati = (M_PI * (double)i) / (double)precision;
|
||||
double y = cos(lati);
|
||||
double r = fabs(sin(lati));
|
||||
|
||||
for (j = 0; j <= precision; j++)
|
||||
{
|
||||
double longi = (M_PI * 2.0 * j) / precision;
|
||||
vertex *v = &vertices[i * (precision + 1) + j];
|
||||
for (j = 0; j <= precision; j++)
|
||||
{
|
||||
double longi = (M_PI * 2.0 * j) / precision;
|
||||
vertex *v = &vertices[i * (precision + 1) + j];
|
||||
|
||||
if (j == 0 || j == precision)
|
||||
v->position.x = 0.0;
|
||||
else
|
||||
v->position.x = r * sin(longi);
|
||||
if (j == 0 || j == precision) v->position.x = 0.0;
|
||||
else v->position.x = r * sin(longi);
|
||||
|
||||
v->position.y = y;
|
||||
v->position.y = y;
|
||||
|
||||
if (j == 0 || j == precision)
|
||||
v->position.z = r;
|
||||
else
|
||||
v->position.z = r * cos(longi);
|
||||
if (j == 0 || j == precision) v->position.z = r;
|
||||
else v->position.z = r * cos(longi);
|
||||
|
||||
v->normal = v->position;
|
||||
v->normal = v->position;
|
||||
|
||||
if (v->position.x > 0.0)
|
||||
{
|
||||
v->tangent.x = -v->normal.y;
|
||||
v->tangent.y = v->normal.x;
|
||||
v->tangent.z = v->normal.z;
|
||||
}
|
||||
else
|
||||
{
|
||||
v->tangent.x = v->normal.y;
|
||||
v->tangent.y = -v->normal.x;
|
||||
v->tangent.z = v->normal.z;
|
||||
}
|
||||
if (v->position.x > 0.0)
|
||||
{
|
||||
v->tangent.x = -v->normal.y;
|
||||
v->tangent.y = v->normal.x;
|
||||
v->tangent.z = v->normal.z;
|
||||
}
|
||||
else
|
||||
{
|
||||
v->tangent.x = v->normal.y;
|
||||
v->tangent.y = -v->normal.x;
|
||||
v->tangent.z = v->normal.z;
|
||||
}
|
||||
|
||||
v->color.x = v->position.x;
|
||||
v->color.y = v->position.y;
|
||||
v->color.z = v->position.z;
|
||||
v->color.w = 1.0;
|
||||
v->color.x = v->position.x;
|
||||
v->color.y = v->position.y;
|
||||
v->color.z = v->position.z;
|
||||
v->color.w = 1.0;
|
||||
|
||||
if (j == precision)
|
||||
v->texcoord.x = 1.0;
|
||||
else if (j == 0)
|
||||
v->texcoord.x = 0.0;
|
||||
else
|
||||
v->texcoord.x = (double)j / (double)precision;
|
||||
if (j == precision) v->texcoord.x = 1.0;
|
||||
else if (j == 0) v->texcoord.x = 0.0;
|
||||
else v->texcoord.x = (double)j / (double)precision;
|
||||
|
||||
if (i == precision)
|
||||
v->texcoord.y = 1.0;
|
||||
else if (i == 0)
|
||||
v->texcoord.y = 0.0;
|
||||
else
|
||||
v->texcoord.y = 1.0 - (double)i / (double)precision;
|
||||
}
|
||||
}
|
||||
if (i == precision) v->texcoord.y = 1.0;
|
||||
else if (i == 0) v->texcoord.y = 0.0;
|
||||
else v->texcoord.y = 1.0 - (double)i / (double)precision;
|
||||
}
|
||||
}
|
||||
|
||||
index = &indices[0];
|
||||
index = &indices[0];
|
||||
|
||||
for (i = 0; i < precision; i++)
|
||||
{
|
||||
for (j = 0; j < precision; j++)
|
||||
{
|
||||
*index++ = i * (precision + 1) + j;
|
||||
*index++ = i * (precision + 1) + j + 1;
|
||||
*index++ = (i + 1) * (precision + 1) + j;
|
||||
for (i = 0; i < precision; i++)
|
||||
{
|
||||
for (j = 0; j < precision; j++)
|
||||
{
|
||||
*index++ = i * (precision + 1) + j;
|
||||
*index++ = i * (precision + 1) + j + 1;
|
||||
*index++ = (i + 1) * (precision + 1) + j;
|
||||
|
||||
*index++ = (i + 1) * (precision + 1) + j;
|
||||
*index++ = i * (precision + 1) + j + 1;
|
||||
*index++ = (i + 1) * (precision + 1) + j + 1;
|
||||
}
|
||||
}
|
||||
*index++ = (i + 1) * (precision + 1) + j;
|
||||
*index++ = i * (precision + 1) + j + 1;
|
||||
*index++ = (i + 1) * (precision + 1) + j + 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < index_count; i += 3)
|
||||
{
|
||||
vertex *v0 = &vertices[indices[i + 0]];
|
||||
vertex *v1 = &vertices[indices[i + 1]];
|
||||
vertex *v2 = &vertices[indices[i + 2]];
|
||||
for (i = 0; i < index_count; i += 3)
|
||||
{
|
||||
vertex *v0 = &vertices[indices[i + 0]];
|
||||
vertex *v1 = &vertices[indices[i + 1]];
|
||||
vertex *v2 = &vertices[indices[i + 2]];
|
||||
|
||||
vec3 e1, e2;
|
||||
float du1, du2, dv1, dv2, f;
|
||||
vec3 tangent;
|
||||
vec3 e1, e2;
|
||||
float du1, du2, dv1, dv2, f;
|
||||
vec3 tangent;
|
||||
|
||||
e1.x = v1->position.x - v0->position.x;
|
||||
e1.y = v1->position.y - v0->position.y;
|
||||
e1.z = v1->position.z - v0->position.z;
|
||||
e1.x = v1->position.x - v0->position.x;
|
||||
e1.y = v1->position.y - v0->position.y;
|
||||
e1.z = v1->position.z - v0->position.z;
|
||||
|
||||
e2.x = v2->position.x - v0->position.x;
|
||||
e2.y = v2->position.y - v0->position.y;
|
||||
e2.z = v2->position.z - v0->position.z;
|
||||
e2.x = v2->position.x - v0->position.x;
|
||||
e2.y = v2->position.y - v0->position.y;
|
||||
e2.z = v2->position.z - v0->position.z;
|
||||
|
||||
du1 = v1->texcoord.x - v0->texcoord.x;
|
||||
dv1 = v1->texcoord.y - v0->texcoord.y;
|
||||
du1 = v1->texcoord.x - v0->texcoord.x;
|
||||
dv1 = v1->texcoord.y - v0->texcoord.y;
|
||||
|
||||
du2 = v2->texcoord.x - v0->texcoord.x;
|
||||
dv2 = v2->texcoord.y - v0->texcoord.y;
|
||||
du2 = v2->texcoord.x - v0->texcoord.x;
|
||||
dv2 = v2->texcoord.y - v0->texcoord.y;
|
||||
|
||||
f = 1.0 / (du1 * dv2 - du2 * dv1);
|
||||
f = 1.0 / (du1 * dv2 - du2 * dv1);
|
||||
|
||||
tangent.x = f * (dv2 * e1.x - dv1 * e2.x);
|
||||
tangent.y = f * (dv2 * e1.y - dv1 * e2.y);
|
||||
tangent.z = f * (dv2 * e1.z - dv1 * e2.z);
|
||||
tangent.x = f * (dv2 * e1.x - dv1 * e2.x);
|
||||
tangent.y = f * (dv2 * e1.y - dv1 * e2.y);
|
||||
tangent.z = f * (dv2 * e1.z - dv1 * e2.z);
|
||||
|
||||
v0->tangent = tangent;
|
||||
}
|
||||
v0->tangent = tangent;
|
||||
}
|
||||
|
||||
for (i = 0; i <= precision; i++)
|
||||
{
|
||||
for (j = 0; j <= precision; j++)
|
||||
{
|
||||
if (j == precision)
|
||||
{
|
||||
vertex *v = &vertices[i * (precision + 1) + j];
|
||||
v->tangent = vertices[i * (precision + 1)].tangent;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0; i <= precision; i++)
|
||||
{
|
||||
for (j = 0; j <= precision; j++)
|
||||
{
|
||||
if (j == precision)
|
||||
{
|
||||
vertex *v = &vertices[i * (precision + 1) + j];
|
||||
v->tangent = vertices[i * (precision + 1)].tangent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_on_mouse_down(void *data EINA_UNUSED,
|
||||
Evas *e EINA_UNUSED,
|
||||
Evas_Object *o,
|
||||
void *einfo)
|
||||
_on_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj,
|
||||
void *event_info)
|
||||
{
|
||||
Evas_Event_Mouse_Down *ev = einfo;
|
||||
Evas_Event_Mouse_Down *ev = event_info;
|
||||
Evas_Coord x, y, w, h;
|
||||
Evas_Coord obj_x, obj_y;
|
||||
int scene_w, scene_h;
|
||||
|
@ -267,7 +249,7 @@ _on_mouse_down(void *data EINA_UNUSED,
|
|||
Evas_3D_Mesh *m;
|
||||
Eina_Bool pick;
|
||||
|
||||
evas_object_geometry_get(o, &x, &y, &w, &h);
|
||||
evas_object_geometry_get(obj, &x, &y, &w, &h);
|
||||
|
||||
obj_x = ev->canvas.x - x;
|
||||
obj_y = ev->canvas.y - y;
|
||||
|
@ -278,18 +260,16 @@ _on_mouse_down(void *data EINA_UNUSED,
|
|||
scene_y = obj_y * scene_h / (Evas_Real)h;
|
||||
|
||||
eo_do(scene, pick = evas_3d_scene_pick(scene_x, scene_y, &n, &m, &s, &t));
|
||||
if (pick)
|
||||
printf("Picked : ");
|
||||
else
|
||||
printf("Not picked : ");
|
||||
if (pick) printf("Picked : ");
|
||||
else printf("Not picked : ");
|
||||
|
||||
printf("output(%d, %d) canvas(%d, %d) object(%d, %d) scene(%f, %f) texcoord(%f, %f) "
|
||||
"node(%p) mesh(%p)\n",
|
||||
ev->output.x, ev->output.y,
|
||||
ev->canvas.x, ev->canvas.y,
|
||||
obj_x, obj_y,
|
||||
scene_x, scene_y,
|
||||
s, t, n, m);
|
||||
printf("output(%d, %d) canvas(%d, %d) object(%d, %d) scene(%f, %f) texcoord(%f, %f) "
|
||||
"node(%p) mesh(%p)\n",
|
||||
ev->output.x, ev->output.y,
|
||||
ev->canvas.x, ev->canvas.y,
|
||||
obj_x, obj_y,
|
||||
scene_x, scene_y,
|
||||
s, t, n, m);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -298,13 +278,11 @@ main(void)
|
|||
//Unless Evas 3D supports Software renderer, we set gl backened forcely.
|
||||
setenv("ECORE_EVAS_ENGINE", "opengl_x11", 1);
|
||||
|
||||
if (!ecore_evas_init())
|
||||
return 0;
|
||||
if (!ecore_evas_init()) return 0;
|
||||
|
||||
ecore_evas = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
|
||||
|
||||
if (!ecore_evas)
|
||||
return 0;
|
||||
if (!ecore_evas) return 0;
|
||||
|
||||
ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
|
||||
ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
|
||||
|
@ -321,7 +299,8 @@ main(void)
|
|||
|
||||
/* Add the camera. */
|
||||
camera = eo_add(EVAS_3D_CAMERA_CLASS, evas);
|
||||
eo_do(camera, evas_3d_camera_projection_perspective_set(30.0, 1.0, 1.0, 100.0));
|
||||
eo_do(camera,
|
||||
evas_3d_camera_projection_perspective_set(30.0, 1.0, 1.0, 100.0));
|
||||
|
||||
camera_node =
|
||||
eo_add_custom(EVAS_3D_NODE_CLASS, evas,
|
||||
|
@ -341,17 +320,22 @@ main(void)
|
|||
evas_3d_mesh_vertex_count_set(vertex_count),
|
||||
evas_3d_mesh_frame_add(0),
|
||||
evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION,
|
||||
sizeof(vertex), &vertices[0].position),
|
||||
sizeof(vertex),
|
||||
&vertices[0].position),
|
||||
evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL,
|
||||
sizeof(vertex), &vertices[0].normal),
|
||||
sizeof(vertex),
|
||||
&vertices[0].normal),
|
||||
evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TANGENT,
|
||||
sizeof(vertex), &vertices[0].tangent),
|
||||
sizeof(vertex),
|
||||
&vertices[0].tangent),
|
||||
evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_COLOR,
|
||||
sizeof(vertex), &vertices[0].color),
|
||||
evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TEXCOORD,
|
||||
sizeof(vertex), &vertices[0].texcoord),
|
||||
sizeof(vertex),
|
||||
&vertices[0].texcoord),
|
||||
|
||||
evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT, index_count, &indices[0]),
|
||||
evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT,
|
||||
index_count, &indices[0]),
|
||||
evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES));
|
||||
|
||||
material = eo_add(EVAS_3D_MATERIAL_CLASS, evas);
|
||||
|
@ -360,17 +344,21 @@ main(void)
|
|||
texture_diffuse = eo_add(EVAS_3D_TEXTURE_CLASS, evas);
|
||||
eo_do(texture_diffuse,
|
||||
evas_3d_texture_file_set("EarthDiffuse.png", NULL),
|
||||
evas_3d_texture_filter_set(EVAS_3D_TEXTURE_FILTER_LINEAR, EVAS_3D_TEXTURE_FILTER_LINEAR));
|
||||
evas_3d_texture_filter_set(EVAS_3D_TEXTURE_FILTER_LINEAR,
|
||||
EVAS_3D_TEXTURE_FILTER_LINEAR));
|
||||
eo_do(material,
|
||||
evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, texture_diffuse),
|
||||
|
||||
evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE,
|
||||
texture_diffuse),
|
||||
evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
|
||||
evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
|
||||
evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
|
||||
|
||||
evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.01, 0.01, 0.01, 1.0),
|
||||
evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 1.0, 1.0, 1.0, 1.0),
|
||||
evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
|
||||
evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.01, 0.01, 0.01,
|
||||
1.0),
|
||||
evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 1.0, 1.0, 1.0,
|
||||
1.0),
|
||||
evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0,
|
||||
1.0),
|
||||
evas_3d_material_shininess_set(50.0));
|
||||
|
||||
mesh_node = eo_add_custom(EVAS_3D_NODE_CLASS, evas,
|
||||
|
@ -387,23 +375,23 @@ main(void)
|
|||
evas_3d_scene_size_set(WIDTH, HEIGHT));
|
||||
|
||||
/* Add evas objects. */
|
||||
background = evas_object_rectangle_add(evas);
|
||||
evas_object_color_set(background, 0, 0, 0, 255);
|
||||
evas_object_move(background, 0, 0);
|
||||
evas_object_resize(background, WIDTH, HEIGHT);
|
||||
evas_object_show(background);
|
||||
background = eo_add(EVAS_OBJ_RECTANGLE_CLASS, evas);
|
||||
eo_unref(background);
|
||||
eo_do(background,
|
||||
evas_obj_color_set(0, 0, 0, 255),
|
||||
evas_obj_size_set(WIDTH, HEIGHT),
|
||||
evas_obj_visibility_set(EINA_TRUE));
|
||||
|
||||
image = evas_object_image_filled_add(evas);
|
||||
evas_object_image_size_set(image, WIDTH, HEIGHT);
|
||||
evas_object_image_scene_set(image, scene);
|
||||
evas_object_move(image, 0, 0);
|
||||
evas_object_resize(image, WIDTH, HEIGHT);
|
||||
evas_object_show(image);
|
||||
evas_object_event_callback_add(image, EVAS_CALLBACK_MOUSE_DOWN, _on_mouse_down, NULL);
|
||||
eo_do(image,
|
||||
evas_obj_image_scene_set(scene),
|
||||
evas_obj_size_set(WIDTH, HEIGHT),
|
||||
evas_obj_visibility_set(EINA_TRUE));
|
||||
evas_object_event_callback_add(image, EVAS_CALLBACK_MOUSE_DOWN,
|
||||
_on_mouse_down, NULL);
|
||||
|
||||
ecore_timer_add(0.01, _animate_scene, mesh_node);
|
||||
|
||||
printf ("Enter main loop\n");
|
||||
ecore_main_loop_begin();
|
||||
|
||||
ecore_evas_free(ecore_evas);
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#define EFL_EO_API_SUPPORT
|
||||
#define EFL_BETA_API_SUPPORT
|
||||
|
||||
#include <math.h>
|
||||
#include <Ecore.h>
|
||||
#include <Ecore_Evas.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <Evas.h>
|
||||
|
||||
#define WIDTH 400
|
||||
|
@ -14,24 +14,24 @@
|
|||
|
||||
typedef struct _Scene_Data
|
||||
{
|
||||
Evas_3D_Scene *scene;
|
||||
Evas_3D_Node *root_node;
|
||||
Evas_3D_Node *camera_node;
|
||||
Evas_3D_Node *light_node;
|
||||
Evas_3D_Node *mesh_node;
|
||||
Eo *scene;
|
||||
Eo *root_node;
|
||||
Eo *camera_node;
|
||||
Eo *light_node;
|
||||
Eo *mesh_node;
|
||||
|
||||
Evas_3D_Camera *camera;
|
||||
Evas_3D_Light *light;
|
||||
Evas_3D_Mesh *mesh;
|
||||
Evas_3D_Material *material;
|
||||
Evas_3D_Texture *texture;
|
||||
Eo *camera;
|
||||
Eo *light;
|
||||
Eo *mesh;
|
||||
Eo *material;
|
||||
Eo *texture;
|
||||
} Scene_Data;
|
||||
|
||||
Ecore_Evas *ecore_evas = NULL;
|
||||
Evas *evas = NULL;
|
||||
Evas_Object *background = NULL;
|
||||
Evas_Object *image = NULL;
|
||||
Evas_Object *source = NULL;
|
||||
static Ecore_Evas *ecore_evas = NULL;
|
||||
static Evas *evas = NULL;
|
||||
static Eo *background = NULL;
|
||||
static Eo *image = NULL;
|
||||
static Eo *source = NULL;
|
||||
|
||||
static const float cube_vertices[] =
|
||||
{
|
||||
|
@ -105,10 +105,8 @@ _on_canvas_resize(Ecore_Evas *ee)
|
|||
int w, h;
|
||||
|
||||
ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
|
||||
|
||||
evas_object_resize(background, w, h);
|
||||
evas_object_resize(image, w, h);
|
||||
evas_object_move(image, 0, 0);
|
||||
eo_do(background, evas_obj_size_set(w, h));
|
||||
eo_do(image, evas_obj_size_set(w, h));
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
|
@ -125,11 +123,11 @@ _animate_scene(void *data)
|
|||
evas_3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, 1.0));
|
||||
|
||||
/* Rotate */
|
||||
if (angle > 360.0)
|
||||
angle -= 360.0f;
|
||||
if (angle > 360.0) angle -= 360.0f;
|
||||
|
||||
pixels = (unsigned int *)evas_object_image_data_get(source, EINA_TRUE);
|
||||
stride = evas_object_image_stride_get(source);
|
||||
eo_do(source,
|
||||
pixels = evas_obj_image_data_get(EINA_TRUE),
|
||||
stride = evas_obj_image_stride_get());
|
||||
|
||||
for (i = 0; i < IMG_HEIGHT; i++)
|
||||
{
|
||||
|
@ -141,8 +139,9 @@ _animate_scene(void *data)
|
|||
}
|
||||
}
|
||||
|
||||
evas_object_image_data_set(source, pixels);
|
||||
evas_object_image_data_update_add(source, 0, 0, IMG_WIDTH, IMG_HEIGHT);
|
||||
eo_do(source,
|
||||
evas_obj_image_data_set(pixels),
|
||||
evas_obj_image_data_update_add(0, 0, IMG_WIDTH, IMG_HEIGHT));
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
@ -269,13 +268,11 @@ main(void)
|
|||
|
||||
Scene_Data data;
|
||||
|
||||
if (!ecore_evas_init())
|
||||
return 0;
|
||||
if (!ecore_evas_init()) return 0;
|
||||
|
||||
ecore_evas = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
|
||||
|
||||
if (!ecore_evas)
|
||||
return 0;
|
||||
if (!ecore_evas) return 0;
|
||||
|
||||
ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
|
||||
ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
|
||||
|
@ -284,30 +281,31 @@ main(void)
|
|||
evas = ecore_evas_get(ecore_evas);
|
||||
|
||||
/* Add a background rectangle objects. */
|
||||
background = evas_object_rectangle_add(evas);
|
||||
evas_object_color_set(background, 0, 0, 0, 255);
|
||||
evas_object_move(background, 0, 0);
|
||||
evas_object_resize(background, WIDTH, HEIGHT);
|
||||
evas_object_show(background);
|
||||
background = eo_add(EVAS_OBJ_RECTANGLE_CLASS, evas);
|
||||
eo_unref(background);
|
||||
eo_do(background,
|
||||
evas_obj_color_set(0, 0, 0, 255),
|
||||
evas_obj_size_set(WIDTH, HEIGHT),
|
||||
evas_obj_visibility_set(EINA_TRUE));
|
||||
|
||||
/* Add a background imageg. */
|
||||
/* Add a background image. */
|
||||
source = evas_object_image_filled_add(evas);
|
||||
evas_object_image_size_set(source, IMG_WIDTH, IMG_HEIGHT);
|
||||
evas_object_move(source, 0, 0);
|
||||
evas_object_resize(source, IMG_WIDTH, IMG_HEIGHT);
|
||||
evas_object_show(source);
|
||||
eo_do(source,
|
||||
evas_obj_image_size_set(IMG_WIDTH, IMG_HEIGHT),
|
||||
evas_obj_size_set(IMG_WIDTH, IMG_HEIGHT),
|
||||
evas_obj_visibility_set(EINA_TRUE));
|
||||
|
||||
/* Add an image object for 3D scene rendering. */
|
||||
image = evas_object_image_filled_add(evas);
|
||||
evas_object_move(image, 0, 0);
|
||||
evas_object_resize(image, WIDTH, HEIGHT);
|
||||
evas_object_show(image);
|
||||
eo_do(image,
|
||||
evas_obj_size_set(IMG_WIDTH, IMG_HEIGHT),
|
||||
evas_obj_visibility_set(EINA_TRUE));
|
||||
|
||||
/* Setup scene */
|
||||
_scene_setup(&data);
|
||||
|
||||
/* Set the image object as render target for 3D scene. */
|
||||
evas_object_image_scene_set(image, data.scene);
|
||||
eo_do(image, evas_obj_image_scene_set(data.scene));
|
||||
|
||||
/* Add animation timer callback. */
|
||||
ecore_timer_add(0.016, _animate_scene, &data);
|
||||
|
|
Loading…
Reference in New Issue