summaryrefslogtreecommitdiff
path: root/src/lib/evas/canvas/evas_3d_camera.c
blob: 8e84e6860984169381e7b17c15fcede1210b8e73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "evas_common_private.h"
#include "evas_private.h"

#include "Eo.h"

#define MY_CLASS EO_EVAS_3D_CAMERA_CLASS


static Eina_Bool
_camera_node_change_notify(const Eina_Hash *hash EINA_UNUSED, const void *key,
                        void *data EINA_UNUSED, void *fdata)
{
   Evas_3D_Node *n = *(Evas_3D_Node **)key;
   evas_3d_object_change(n, EVAS_3D_STATE_NODE_CAMERA, (Evas_3D_Object *)fdata);
   return EINA_TRUE;
}

EOLIAN static void
_eo_evas_3d_camera_eo_evas_3d_object_change_notify(Eo *obj,Evas_3D_Camera_Data *pd, Evas_3D_State state EINA_UNUSED, Evas_3D_Object *ref EINA_UNUSED)
{
   if (pd->nodes) eina_hash_foreach(pd->nodes, _camera_node_change_notify, obj);
}

EOLIAN static void
_eo_evas_3d_camera_eo_evas_3d_object_update_notify(Eo *obj EINA_UNUSED,
                                                   Evas_3D_Camera_Data *pd EINA_UNUSED)
{

}

void
evas_3d_camera_node_add(Evas_3D_Camera *camera, Evas_3D_Node *node)
{
   Evas_3D_Camera_Data *pd = eo_data_scope_get(camera, MY_CLASS);
   int count = 0;

   if (!pd->nodes)
     {
        pd->nodes = eina_hash_pointer_new(NULL);

        if (!pd->nodes)
          {
             ERR("Failed to create hash table. camera(%p)", camera);
             return;
          }
     }
   else count = (int)eina_hash_find(pd->nodes, &node);
   eina_hash_set(pd->nodes, &node, (const void *)(count + 1));
}

void
evas_3d_camera_node_del(Evas_3D_Camera *camera, Evas_3D_Node *node)
{
   Evas_3D_Camera_Data *pd = eo_data_scope_get(camera, MY_CLASS);
   int count = 0;

   if (!pd->nodes)
     {
        ERR("No node to delete.");
        return;
     }

   count = (int)eina_hash_find(pd->nodes, &node);
   if (count == 1) eina_hash_del(pd->nodes, &node, NULL);
   else eina_hash_set(pd->nodes, &node, (const void *)(count - 1));
}

EOLIAN static void
_eo_evas_3d_camera_eo_base_constructor(Eo *obj,
                                       Evas_3D_Camera_Data *pd EINA_UNUSED)
{
   eo_do_super(obj, MY_CLASS, eo_constructor());
   eo_do(obj, eo_evas_3d_object_type_set(EVAS_3D_OBJECT_TYPE_CAMERA));
}

EOLIAN static void
_eo_evas_3d_camera_eo_base_destructor(Eo *obj EINA_UNUSED,
                                      Evas_3D_Camera_Data *pd)
{
   //evas_3d_object_unreference(&pd->base);
   if (pd->nodes) eina_hash_free(pd->nodes);
}

EAPI Evas_3D_Camera *
evas_3d_camera_add(Evas *e)
{
   MAGIC_CHECK(e, Evas, MAGIC_EVAS);
   return NULL;
   MAGIC_CHECK_END();
   Evas_Object *eo_obj = eo_add(MY_CLASS, e);
   eo_unref(eo_obj);
   return eo_obj;
}

EOLIAN static void
_eo_evas_3d_camera_projection_matrix_set(Eo *obj, Evas_3D_Camera_Data *pd,
                                         const Evas_Real *matrix)
{
   evas_mat4_array_set(&pd->projection, matrix);
   evas_3d_object_change(obj, EVAS_3D_STATE_CAMERA_PROJECTION, NULL);
}

EOLIAN static void
_eo_evas_3d_camera_projection_matrix_get(Eo *obj EINA_UNUSED,
                                         Evas_3D_Camera_Data *pd,
                                         Evas_Real *matrix)
{
   memcpy(matrix, &pd->projection.m[0], sizeof(Evas_Real) * 16);
}

EOLIAN static void
_eo_evas_3d_camera_projection_perspective_set(Eo *obj, Evas_3D_Camera_Data *pd,
                                              Evas_Real fovy, Evas_Real aspect,
                                              Evas_Real near, Evas_Real far)
{
   Evas_Real   xmax;
   Evas_Real   ymax;

   ymax = near * (Evas_Real)tan((double)fovy * M_PI / 360.0);
   xmax = ymax * aspect;

   evas_mat4_frustum_set(&pd->projection, -xmax, xmax, -ymax, ymax, near, far);
   evas_3d_object_change(obj, EVAS_3D_STATE_CAMERA_PROJECTION, NULL);
}

EOLIAN static void
_eo_evas_3d_camera_projection_frustum_set(Eo *obj, Evas_3D_Camera_Data *pd,
                                          Evas_Real left, Evas_Real right,
                                          Evas_Real bottom, Evas_Real top,
                                          Evas_Real near, Evas_Real far)
{
   evas_mat4_frustum_set(&pd->projection, left, right, bottom, top, near, far);
   evas_3d_object_change(obj, EVAS_3D_STATE_CAMERA_PROJECTION, NULL);
}

EOLIAN static void
_eo_evas_3d_camera_projection_ortho_set(Eo *obj, Evas_3D_Camera_Data *pd,
                                        Evas_Real left, Evas_Real right,
                                        Evas_Real bottom, Evas_Real top,
                                        Evas_Real near, Evas_Real far)
{
   evas_mat4_ortho_set(&pd->projection, left, right, bottom, top, near, far);
   evas_3d_object_change(obj, EVAS_3D_STATE_CAMERA_PROJECTION, NULL);
}

#include "canvas/evas_3d_camera.eo.c"