[Evas\evas-3d\example] Add example of 3d-shooter

Reviewers: cedric, raster, Hermet

Subscribers: cedric

Differential Revision: https://phab.enlightenment.org/D1215
This commit is contained in:
perepelits.m 2014-07-29 16:37:25 +09:00 committed by ChunEon Park
parent 171d9bc135
commit 0ea04a4870
13 changed files with 8590 additions and 0 deletions

View File

@ -217,6 +217,11 @@ evas_3d_cube_rotate_SOURCES = evas-3d-cube-rotate.c
evas_3d_cube_rotate_LDADD = $(ECORE_EVAS_COMMON_LDADD) @EFL_PTHREAD_LIBS@
evas_3d_cube_rotate_CPPFLAGS = $(ECORE_EVAS_COMMON_CPPFLAGS)
EXTRA_PROGRAMS += evas_3d_shooter
evas_3d_shooter_SOURCES = shooter/evas-3d-shooter.c shooter/evas-3d-shooter-header.c
evas_3d_shooter_LDADD = $(ECORE_EVAS_COMMON_LDADD) @EFL_PTHREAD_LIBS@
evas_3d_shooter_CPPFLAGS = $(ECORE_EVAS_COMMON_CPPFLAGS)
EXTRA_PROGRAMS += evas_3d_obj
evas_3d_obj_SOURCES = evas-3d-obj.c
evas_3d_obj_LDADD = $(ECORE_EVAS_COMMON_LDADD) @EFL_PTHREAD_LIBS@

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 MiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 575 KiB

View File

@ -0,0 +1,279 @@
#include "evas-3d-shooter-header.h"
void evas_vec3_set(vec3 *dst, Evas_Real x, Evas_Real y, Evas_Real z)
{
dst->x = x;
dst->y = y;
dst->z = z;
}
void evas_box3_empty_set(Box3 *box)
{
evas_vec3_set(&box->p0, 0.0, 0.0, 0.0);
evas_vec3_set(&box->p1, 0.0, 0.0, 0.0);
}
void evas_box3_set(Box3 *box, Evas_Real x0, Evas_Real y0, Evas_Real z0, Evas_Real x1, Evas_Real y1, Evas_Real z1)
{
box->p0.x = x0;
box->p0.y = y0;
box->p0.z = z0;
box->p1.x = x1;
box->p1.y = y1;
box->p1.z = z1;
}
void evas_box3_union(Box3 *out, const Box3 *a, const Box3 *b)
{
evas_vec3_set(&out->p0, MIN(a->p0.x, b->p0.x), MIN(a->p0.y, b->p0.y), MIN(a->p0.z, b->p0.z));
evas_vec3_set(&out->p1, MAX(a->p1.x, b->p1.x), MAX(a->p1.y, b->p1.y), MAX(a->p1.z, b->p1.z));
}
void _add_annulus(float * current_r1, int size, float r1, float r2, float z1, float z2)
{
int i;
float * current_r2 = current_r1 + 12 * size;
float arc = (float)2 * 3.1415 / size;
for( i = 0 ; i < size ; i++)
{
*current_r1 = r1 * (float)sin(i * arc);
current_r1 += 1;
*current_r1 = r1 * (float)cos(i * arc);
current_r1 += 1;
*current_r1 = z1;
current_r1 += 1;
*current_r1 = (float)sin(i * arc) * (r2 - r1);
current_r1 += 1;
*current_r1 = (float)cos(i * arc) * (r2 - r1);
current_r1 += 1;
*current_r1 = (z2 - z1);
current_r1 += 7;
*current_r2 = r2 * (float)sin(i * arc);
current_r2 += 1;
*current_r2 = r2 * (float)cos(i * arc);
current_r2 += 1;
*current_r2 = z2;
current_r2 += 1;
*current_r2 = (float)sin(i * arc) * (r2 -r1);
current_r2 += 1;
*current_r2 = (float)cos(i * arc) * (r2 - r1);
current_r2 += 1;
*current_r2 = (z2 - z1);
current_r2 += 7;
}
}
void _add_annulus_vertices(unsigned short * current_r1, int size, int first)
{
int i;
for( i = 0 ; i < size - 1 ; i++)
{
*current_r1 = first + i;
current_r1 += 1;
*current_r1 = first + 1 + i;
current_r1 += 1;
*current_r1 = first + size + i;
current_r1 += 1;
*current_r1 = first + size + i;
current_r1 += 1;
*current_r1 = first + 1 + size + i;
current_r1 += 1;
*current_r1 = first + 1 + i;
current_r1 += 1;
}
*current_r1 = first + size - 1;
current_r1 += 1;
*current_r1 = first;
current_r1 += 1;
*current_r1 = first + 2 * size - 1;
current_r1 += 1;
*current_r1 = first + 2 * size - 1;
current_r1 += 1;
*current_r1 = first + size;
current_r1 += 1;
*current_r1 = first;
current_r1 += 1;
}
void
_scale(Evas_3D_Node *node, Evas_Real scale)
{
eo_do(node, evas_3d_node_scale_set(1.0 * scale, 1.0 * scale, 1.0 * scale));
}
void _add_solid_of_revolution(float * start, int size, float * vertic, unsigned short * indic)
{
int i;
int accurancy = 35;
float * current = start;
for( i = 0 ; i < size ; i++)
{
_add_annulus(&vertic[i*accurancy*24], accurancy, *current, *(current + 2), *(current + 1), *(current + 3));
current+=2;
_add_annulus_vertices(&indic[i*accurancy*6], accurancy, i*accurancy*2);
}
}
void
_camera_setup(Scene_Data *data)
{
data->camera = eo_add(EVAS_3D_CAMERA_CLASS, evas);
eo_do(data->camera,
evas_3d_camera_projection_perspective_set(65.0, 1.0, 1.0, 100.0));
data->mediator_node = eo_add_custom(EVAS_3D_NODE_CLASS, evas,
evas_3d_node_constructor(EVAS_3D_NODE_TYPE_NODE));
data->camera_node = eo_add_custom(EVAS_3D_NODE_CLASS, evas,
evas_3d_node_constructor(EVAS_3D_NODE_TYPE_CAMERA));
eo_do(data->root_node, evas_3d_node_member_add(data->mediator_node));
eo_do(data->mediator_node, evas_3d_node_member_add(data->camera_node));
eo_do(data->camera_node,
evas_3d_node_camera_set(data->camera),
evas_3d_node_position_set(0.0, 0.0, 1.0);
evas_3d_node_look_at_set(EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0));
}
void
_light_setup(Scene_Data *data)
{
data->light = eo_add(EVAS_3D_LIGHT_CLASS, evas);
eo_do(data->light,
evas_3d_light_ambient_set(0.2, 0.2, 0.2, 1.0),
evas_3d_light_diffuse_set(1.0, 1.0, 1.0, 1.0),
evas_3d_light_specular_set(1.0, 1.0, 1.0, 1.0));
data->light_node = eo_add_custom(EVAS_3D_NODE_CLASS, evas,
evas_3d_node_constructor(EVAS_3D_NODE_TYPE_LIGHT));
eo_do(data->light_node,
evas_3d_node_light_set(data->light),
evas_3d_node_position_set(15.0, 0.0, 30.0),
evas_3d_node_look_at_set(EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_3D_SPACE_PARENT, 0.0, 0.0, 1.0));
eo_do(data->root_node, evas_3d_node_member_add(data->light_node));
}
Eina_Bool _mesh_aabb(Evas_3D_Mesh **mesh, Scene_Data *scene)
{
Evas_Real x0, y0, z0, x1, y1, z1;
eo_do(scene->mesh_node_level[10],
evas_3d_node_bounding_box_get(&x0, &y0, &z0, &x1, &y1, &z1));
float vertixes[] =
{
x0, y0, z1, 0.0, 0.0, 1.0,
x0, y1, z1, 0.0, 0.0, 1.0,
x1, y1, z1, 0.0, 0.0, 1.0,
x1, y0, z1, 0.0, 0.0, 1.0,
x0, y0, z0, 0.0, 0.0, -1.0,
x1, y0, z0, 0.0, 0.0, -1.0,
x0, y1, z0, 0.0, 0.0, -1.0,
x1, y1, z0, 0.0, 0.0, -1.0,
x0, y0, z0, -1.0, 0.0, 0.0,
x0, y1, z0, -1.0, 0.0, 0.0,
x0, y0, z1, -1.0, 0.0, 0.0,
x0, y1, z1, -1.0, 0.0, 0.0,
x1, y0, z0, 1.0, 0.0, 0.0,
x1, y1, z0, 1.0, 0.0, 0.0,
x1, y1, z1, 1.0, 0.0, 0.0,
x1, y0, z1, 1.0, 0.0, 0.0,
x0, y1, z0, 0.0, 1.0, 0.0,
x1, y1, z0, 0.0, 1.0, 0.0,
x0, y1, z1, 0.0, 1.0, 0.0,
x1, y1, z1, 0.0, 1.0, 0.0,
x0, y0, z0, 0.0, -1.0, 0.0,
x1, y0, z0, 0.0, -1.0, 0.0,
x1, y0, z1, 0.0, -1.0, 0.0,
x0, y0, z1, 0.0, -1.0, 0.0
};
unsigned short indixes[] =
{
0, 1, 2, 3, 1, 2, 0, 3,
4, 5, 5, 7, 7, 6, 6, 4,
8, 9, 9, 11, 11, 10, 10, 8,
12, 13, 13, 14, 14, 15, 15, 12,
16, 17, 17, 19, 19, 18, 18, 16,
20, 21, 21, 22, 22, 23, 23, 20
};
if (*mesh)
{
eo_do(*mesh,
evas_3d_mesh_frame_vertex_data_copy_set(0, EVAS_3D_VERTEX_POSITION, 6 * sizeof(float), &vertixes[ 0]),
evas_3d_mesh_index_data_copy_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT, 48, &indixes[0]));
return EINA_TRUE;
}
return EINA_FALSE;
}
void _on_delete(Ecore_Evas *ee EINA_UNUSED)
{
ecore_main_loop_quit();
}
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);
}
Eina_Bool _horizontal_circle_resolution(Evas_3D_Node *node, Evas_Real x, Evas_Real z, Evas_Real r)
{
Evas_Real x0, y0, z0, x1, y1, z1;
eo_do(node,
evas_3d_node_bounding_box_get(&x0, &y0, &z0, &x1, &y1, &z1));
if (((x0 - x) * (x0 - x)) + ((z0 - z) * (z0 - z)) < r * r) return EINA_FALSE;
if (((x0 - x) * (x0 - x)) + ((z1 - z) * (z1 - z)) < r * r) return EINA_FALSE;
if (((x1 - x) * (x1 - x)) + ((z0 - z) * (z0 - z)) < r * r) return EINA_FALSE;
if (((x1 - x) * (x1 - x)) + ((z1 - z) * (z1 - z)) < r * r) return EINA_FALSE;
if ((((x + r < x0) && (x + r > x1)) || ((x + r > x0) && (x+r < x1))) && (((z < z0) && (z > z1)) || ((z > z0) && (z < z1))))
return EINA_FALSE;
if ((((x - r < x0) && (x - r > x1)) || ((x - r > x0) && (x-r < x1))) && (((z < z0) && (z > z1)) || ((z > z0) && (z < z1))))
return EINA_FALSE;
if ((((z + r < z0) && (z + r > z1)) || ((z + r > z0) && (z+r < z1))) && (((x < x0) && (x > x1)) || ((x > x0) && (x < x1))))
return EINA_FALSE;
if ((((z - r < z0) && (z - r > z1)) || ((z - r > z0) && (z-r < z1))) && (((x < x0) && (x > x1)) || ((x > x0) && (x < x1))))
return EINA_FALSE;
return EINA_TRUE;
}
Eina_Bool _horizontal_position_resolution(Evas_3D_Node *node, Evas_Real x, Evas_Real z)
{
Evas_Real x0, y0, z0, x1, y1, z1;
eo_do(node,
evas_3d_node_bounding_box_get(&x0, &y0, &z0, &x1, &y1, &z1));
if ((x > x0) && (x < x1) && (z > z0) && (z < z1))
return EINA_FALSE;
if ((x > x0) && (x < x1) && (z < z0) && (z > z1))
return EINA_FALSE;
if ((x < x0) && (x > x1) && (z > z0) && (z < z1))
return EINA_FALSE;
if ((x < x0) && (x > x1) && (z < z0) && (z > z1))
return EINA_FALSE;
return EINA_TRUE;
}

View File

@ -0,0 +1,134 @@
#define EFL_EO_API_SUPPORT
#define EFL_BETA_API_SUPPORT
#include <stdio.h>
#include <math.h>
#include <Ecore.h>
#include <Ecore_Evas.h>
#include <Evas.h>
#include "Eo.h"
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
typedef struct _Scene_Data
{
Eo *texture_diffuse_eagle;
Eo *texture_diffuse_world;
Eo *texture_diffuse_grass;
Eo *root_node;
Eo *camera_node;
Eo *mesh_node_world;
Eo *mesh_node_grass[30];
Eo *light_node;
Eo *mediator_node;
Eo *mesh_node_cube;
Eo *mesh_node_eagle;
Eo *mesh_node_gun;
Eo *mesh_node_gun_butt;
Eo *mesh_node_gun_cage;
Eo *mesh_node_gun_bling[3];
Eo *mesh_node_rocket;
Eo *mesh_node_level[11];
Eo *mesh_node_snake;
Eo *camera;
Eo *light;
Eo *mesh_world;
Eo *mesh_grass[30];
Eo *mesh_cube;
Eo *mesh_eagle;
Eo *mesh_gun;
Eo *mesh_gun_cage;
Eo *mesh_gun_butt;
Eo *mesh_gun_bling[3];
Eo *mesh_rocket;
Eo *mesh_level[4];
Eo *mesh_snake;
Eo *material_world;
Eo *material_grass;
Eo *material_eagle;
Eo *material_cube;
Eo *material_level;
Eo *material_snake;
Eo *material_gun_butt;
Eo *material_gun_bling;
Eo *material_gun_cage;
Eo *gun;
Eo *rocket;
Eo *texture;
Eo *texture_snake;
} Scene_Data;
static Evas *evas = NULL;
static Eo *background = NULL;
static Eo *image = NULL;
typedef struct _vec4
{
float x;
float y;
float z;
float w;
} vec4;
typedef struct _vec3
{
float x;
float y;
float z;
} vec3;
typedef struct _vec2
{
float x;
float y;
} vec2;
typedef struct _Box3
{
vec3 p0;
vec3 p1;
} Box3;
typedef struct _vertex
{
vec3 position;
vec3 normal;
vec3 tangent;
vec4 color;
vec3 texcoord;
} vertex;
void evas_vec3_set(vec3 *dst, Evas_Real x, Evas_Real y, Evas_Real z);
void evas_box3_empty_set(Box3 *box);
void evas_box3_set(Box3 *box, Evas_Real x0, Evas_Real y0, Evas_Real z0, Evas_Real x1, Evas_Real y1, Evas_Real z1);
void evas_box3_union(Box3 *out, const Box3 *a, const Box3 *b);
/* fill vector by indices which are on one rotation ring */
void _add_annulus(float * current_r1, int size, float r1, float r2, float z1, float z2);
/* fill vector by vertices which are arranged between two rotation rings */
void _add_annulus_vertices(unsigned short * current_r1, int size, int first);
void _scale(Evas_3D_Node *node, Evas_Real scale);
void _add_solid_of_revolution(float * start, int size, float * vertic, unsigned short * indic);
void _camera_setup(Scene_Data *data);
void _light_setup(Scene_Data *data);
Eina_Bool _mesh_aabb(Evas_3D_Mesh **mesh, Scene_Data *scene);
void _on_delete(Ecore_Evas *ee EINA_UNUSED);
void _on_canvas_resize(Ecore_Evas *ee);
Eina_Bool _horizontal_circle_resolution(Evas_3D_Node *node, Evas_Real x, Evas_Real z, Evas_Real r);
Eina_Bool _horizontal_position_resolution(Evas_3D_Node *node, Evas_Real x, Evas_Real z);

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 718 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 882 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 KiB