Jo Engine  2020.06.22
Jo Sega Saturn Engine
3d.h
Go to the documentation of this file.
1 /*
2 ** Jo Sega Saturn Engine
3 ** Copyright (c) 2012-2020, Johannes Fetz (johannesfetz@gmail.com)
4 ** All rights reserved.
5 **
6 ** Redistribution and use in source and binary forms, with or without
7 ** modification, are permitted provided that the following conditions are met:
8 ** * Redistributions of source code must retain the above copyright
9 ** notice, this list of conditions and the following disclaimer.
10 ** * Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
13 ** * Neither the name of the Johannes Fetz nor the
14 ** names of its contributors may be used to endorse or promote products
15 ** derived from this software without specific prior written permission.
16 **
17 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 ** DISCLAIMED. IN NO EVENT SHALL Johannes Fetz BE LIABLE FOR ANY
21 ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
36 #ifndef __JO_3D_H__
37 # define __JO_3D_H__
38 
39 #ifdef JO_COMPILE_WITH_3D_SUPPORT
40 
42 # define JO_3D_PLANE_VERTICES(SIZE) \
43 { \
44  { -SIZE, -SIZE, 0 }, \
45  { SIZE, -SIZE, 0 }, \
46  { SIZE, SIZE, 0 }, \
47  { -SIZE, SIZE, 0 } \
48 }
49 
51 # define JO_3D_TRIANGLE_VERTICES(SIZE) \
52 { \
53  { -SIZE, -SIZE, 0 }, \
54  { SIZE, -SIZE, 0 }, \
55  { SIZE, SIZE, 0 } \
56 }
57 
59 # define JO_3D_CUBE_VERTICES(SIZE) \
60 { \
61  { -SIZE, -SIZE, SIZE }, \
62  { SIZE, -SIZE, SIZE }, \
63  { SIZE, SIZE, SIZE }, \
64  { -SIZE, SIZE, SIZE }, \
65  { -SIZE, -SIZE, -SIZE }, \
66  { -SIZE, -SIZE, SIZE }, \
67  { -SIZE, SIZE, SIZE }, \
68  { -SIZE, SIZE, -SIZE }, \
69  { SIZE, -SIZE, -SIZE }, \
70  { -SIZE, -SIZE, -SIZE }, \
71  { -SIZE, SIZE, -SIZE }, \
72  { SIZE, SIZE, -SIZE }, \
73  { SIZE, -SIZE, SIZE }, \
74  { SIZE, -SIZE, -SIZE }, \
75  { SIZE, SIZE, -SIZE }, \
76  { SIZE, SIZE, SIZE }, \
77  { -SIZE, -SIZE, -SIZE }, \
78  { SIZE, -SIZE, -SIZE }, \
79  { SIZE, -SIZE, SIZE }, \
80  { -SIZE, -SIZE, SIZE }, \
81  { -SIZE, SIZE, SIZE }, \
82  { SIZE, SIZE, SIZE }, \
83  { SIZE, SIZE, -SIZE }, \
84  { -SIZE, SIZE, -SIZE } \
85 }
86 
89 
91 typedef struct
92 {
93  union
94  {
95  FIXED viewpoint[XYZ];
96  jo_pos3D viewpoint_pos;
97  };
98  union
99  {
100  FIXED target[XYZ];
101  jo_pos3D target_pos;
102  };
103  ANGLE z_angle;
104 } jo_camera;
105 
107 typedef struct
108 {
109  PDATA data;
110  ATTR attribute;
111 } jo_3d_quad;
112 
114 typedef struct
115 {
116  PDATA data;
117 } jo_3d_mesh;
118 
122 extern jo_3d_quad *__jo_sprite_quad[JO_MAX_SPRITE];
123 bool jo_3d_create_sprite_quad(const int sprite_id);
124 
125 /*
126  ██████╗ █████╗ ███╗ ███╗███████╗██████╗ █████╗
127 ██╔════╝██╔══██╗████╗ ████║██╔════╝██╔══██╗██╔══██╗
128 ██║ ███████║██╔████╔██║█████╗ ██████╔╝███████║
129 ██║ ██╔══██║██║╚██╔╝██║██╔══╝ ██╔══██╗██╔══██║
130 ╚██████╗██║ ██║██║ ╚═╝ ██║███████╗██║ ██║██║ ██║
131  ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝
132 
133 */
134 
141 static __jo_force_inline void jo_3d_camera_set_viewpoint(jo_camera * const cam, const int x, const int y, const int z)
142 {
143  cam->viewpoint_pos.x = JO_MULT_BY_65536(x);
144  cam->viewpoint_pos.y = JO_MULT_BY_65536(y);
145  cam->viewpoint_pos.z = JO_MULT_BY_65536(z);
146 }
147 
154 static __jo_force_inline void jo_3d_camera_set_target(jo_camera * const cam, const int x, const int y, const int z)
155 {
156  cam->target_pos.x = JO_MULT_BY_65536(x);
157  cam->target_pos.y = JO_MULT_BY_65536(y);
158  cam->target_pos.z = JO_MULT_BY_65536(z);
159 }
160 
165 static __jo_force_inline void jo_3d_camera_set_z_angle(jo_camera * const cam, const int angle )
166 {
167  cam->z_angle = DEGtoANG(angle);
168 }
169 
174 {
175  jo_3d_camera_set_viewpoint(cam, 0, 0, -150);
176  jo_3d_camera_set_target(cam, 0, 0, 0);
177  jo_3d_camera_set_z_angle(cam, 0);
178 }
179 
184 {
185  slLookAt(cam->viewpoint, cam->target, cam->z_angle);
186 }
187 
188 /*
189 ███████╗████████╗ █████╗ ████████╗██╗███████╗████████╗██╗ ██████╗███████╗
190 ██╔════╝╚══██╔══╝██╔══██╗╚══██╔══╝██║██╔════╝╚══██╔══╝██║██╔════╝██╔════╝
191 ███████╗ ██║ ███████║ ██║ ██║███████╗ ██║ ██║██║ ███████╗
192 ╚════██║ ██║ ██╔══██║ ██║ ██║╚════██║ ██║ ██║██║ ╚════██║
193 ███████║ ██║ ██║ ██║ ██║ ██║███████║ ██║ ██║╚██████╗███████║
194 ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
195 
196 */
197 
203 {
204  extern Uint16 TotalPolygons;
205  return TotalPolygons;
206 }
207 
213 {
214  extern Uint16 TotalVertices;
215  return TotalVertices;
216 }
217 
223 {
224  extern Uint16 DispPolygons;
225  return DispPolygons;
226 }
227 
228 /*
229  ██████╗██████╗ ███████╗ █████╗ ████████╗███████╗ ███████╗██╗███╗ ███╗██████╗ ██╗ ███████╗
230 ██╔════╝██╔══██╗██╔════╝██╔══██╗╚══██╔══╝██╔════╝ ██╔════╝██║████╗ ████║██╔══██╗██║ ██╔════╝
231 ██║ ██████╔╝█████╗ ███████║ ██║ █████╗ ███████╗██║██╔████╔██║██████╔╝██║ █████╗
232 ██║ ██╔══██╗██╔══╝ ██╔══██║ ██║ ██╔══╝ ╚════██║██║██║╚██╔╝██║██╔═══╝ ██║ ██╔══╝
233 ╚██████╗██║ ██║███████╗██║ ██║ ██║ ███████╗ ███████║██║██║ ╚═╝ ██║██║ ███████╗███████╗
234  ╚═════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚══════╝╚═╝╚═╝ ╚═╝╚═╝ ╚══════╝╚══════╝
235 
236  ██████╗ ██████╗ ██╗███████╗ ██████╗████████╗
237 ██╔═══██╗██╔══██╗ ██║██╔════╝██╔════╝╚══██╔══╝
238 ██║ ██║██████╔╝ ██║█████╗ ██║ ██║
239 ██║ ██║██╔══██╗██ ██║██╔══╝ ██║ ██║
240 ╚██████╔╝██████╔╝╚█████╔╝███████╗╚██████╗ ██║
241  ╚═════╝ ╚═════╝ ╚════╝ ╚══════╝ ╚═════╝ ╚═╝
242 
243 */
244 
249 void jo_3d_create_plane(jo_3d_quad * const quad, jo_vertice * const vertices);
250 
255 void jo_3d_create_cube(jo_3d_quad * array, jo_vertice * const vertices);
256 
261 void jo_3d_create_triangle(jo_3d_quad * const quad, jo_vertice * const vertices);
262 
268 {
269  return (__jo_sprite_quad[sprite_id] == JO_NULL && !jo_3d_create_sprite_quad(sprite_id) ? JO_NULL : __jo_sprite_quad[sprite_id]);
270 }
271 
275 void jo_3d_free_sprite_quad(const int sprite_id);
276 
277 /*
278 ███╗ ███╗███████╗███████╗██╗ ██╗ ████████╗███████╗██╗ ██╗████████╗██╗ ██╗██████╗ ███████╗
279 ████╗ ████║██╔════╝██╔════╝██║ ██║ ╚══██╔══╝██╔════╝╚██╗██╔╝╚══██╔══╝██║ ██║██╔══██╗██╔════╝
280 ██╔████╔██║█████╗ ███████╗███████║ ██║ █████╗ ╚███╔╝ ██║ ██║ ██║██████╔╝█████╗
281 ██║╚██╔╝██║██╔══╝ ╚════██║██╔══██║ ██║ ██╔══╝ ██╔██╗ ██║ ██║ ██║██╔══██╗██╔══╝
282 ██║ ╚═╝ ██║███████╗███████║██║ ██║ ██║ ███████╗██╔╝ ██╗ ██║ ╚██████╔╝██║ ██║███████╗
283 ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
284 
285 */
286 
292 void jo_3d_set_mesh_polygon_texture(jo_3d_mesh * const mesh, const int sprite_id, const unsigned int index);
293 
298 void jo_3d_set_mesh_texture(jo_3d_mesh * const mesh, const int sprite_id);
299 
304 static __jo_force_inline void jo_3d_set_texture(jo_3d_quad * const quad, const int sprite_id)
305 {
306  jo_3d_set_mesh_polygon_texture((jo_3d_mesh *)quad, sprite_id, 0);
307 }
308 
309 /*
310 ███╗ ███╗███████╗███████╗██╗ ██╗ ██╗ ██╗ ██████╗ ██╗ ██╗████████╗
311 ████╗ ████║██╔════╝██╔════╝██║ ██║ ██║ ██║██╔════╝ ██║ ██║╚══██╔══╝
312 ██╔████╔██║█████╗ ███████╗███████║ ██║ ██║██║ ███╗███████║ ██║
313 ██║╚██╔╝██║██╔══╝ ╚════██║██╔══██║ ██║ ██║██║ ██║██╔══██║ ██║
314 ██║ ╚═╝ ██║███████╗███████║██║ ██║ ███████╗██║╚██████╔╝██║ ██║ ██║
315 ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝
316 
317 */
318 
324 static __jo_force_inline void jo_3d_light(const int x, const int y, const int z)
325 {
326  FIXED p[XYZ];
327  p[X] = JO_MULT_BY_65536(x);
328  p[Y] = JO_MULT_BY_65536(y);
329  p[Z] = JO_MULT_BY_65536(z);
330  slLight(p);
331 }
332 
338 void jo_3d_set_mesh_polygon_light(jo_3d_mesh * const mesh, const bool enabled, const unsigned int index);
339 
344 void jo_3d_set_mesh_light(jo_3d_mesh * const mesh, const bool enabled);
345 
350 static __jo_force_inline void jo_3d_set_light(jo_3d_quad *const quad, const bool enabled)
351 {
352  jo_3d_set_mesh_polygon_light((jo_3d_mesh *)quad, enabled, 0);
353 }
354 
355 /*
356 ████████╗██████╗ █████╗ ███╗ ██╗███████╗██████╗ █████╗ ██████╗ ███████╗███╗ ██╗ ██████╗██╗ ██╗
357 ╚══██╔══╝██╔══██╗██╔══██╗████╗ ██║██╔════╝██╔══██╗██╔══██╗██╔══██╗██╔════╝████╗ ██║██╔════╝╚██╗ ██╔╝
358  ██║ ██████╔╝███████║██╔██╗ ██║███████╗██████╔╝███████║██████╔╝█████╗ ██╔██╗ ██║██║ ╚████╔╝
359  ██║ ██╔══██╗██╔══██║██║╚██╗██║╚════██║██╔═══╝ ██╔══██║██╔══██╗██╔══╝ ██║╚██╗██║██║ ╚██╔╝
360  ██║ ██║ ██║██║ ██║██║ ╚████║███████║██║ ██║ ██║██║ ██║███████╗██║ ╚████║╚██████╗ ██║
361  ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝
362 
363 */
364 
370 void jo_3d_set_mesh_polygon_transparency(jo_3d_mesh * const mesh, const bool enabled, const unsigned int index);
371 
376 void jo_3d_set_mesh_transparency(jo_3d_mesh * const mesh, const bool enabled);
377 
382 static __jo_force_inline void jo_3d_set_transparency(jo_3d_quad *const quad, const bool enabled)
383 {
384  jo_3d_set_mesh_polygon_transparency((jo_3d_mesh *)quad, enabled, 0);
385 }
386 
387 /******************************************************
388 * SCREEN DOORS TRANSPARENCY
389 *******************************************************/
390 
396 void jo_3d_set_mesh_polygon_screen_doors(jo_3d_mesh * const mesh, const bool enabled, const unsigned int index);
397 
402 void jo_3d_set_mesh_screen_doors(jo_3d_mesh * const mesh, const bool enabled);
403 
408 static __jo_force_inline void jo_3d_set_screen_doors(jo_3d_quad *const quad, const bool enabled)
409 {
410  jo_3d_set_mesh_polygon_screen_doors((jo_3d_mesh *)quad, enabled, 0);
411 }
412 
413 /*
414  ██████╗ ██████╗ ██╗ ██████╗ ██████╗ ███████╗
415 ██╔════╝██╔═══██╗██║ ██╔═══██╗██╔══██╗██╔════╝
416 ██║ ██║ ██║██║ ██║ ██║██████╔╝███████╗
417 ██║ ██║ ██║██║ ██║ ██║██╔══██╗╚════██║
418 ╚██████╗╚██████╔╝███████╗╚██████╔╝██║ ██║███████║
419  ╚═════╝ ╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
420 
421 */
422 
428 void jo_3d_set_mesh_polygon_color(jo_3d_mesh * const mesh, const jo_color color, const unsigned int index);
429 
434 void jo_3d_set_mesh_color(jo_3d_mesh * const mesh, const jo_color color);
435 
440 static __jo_force_inline void jo_3d_set_color(jo_3d_quad * const quad, const jo_color color)
441 {
442  jo_3d_set_mesh_polygon_color((jo_3d_mesh *)quad, color, 0);
443 }
444 
445 /*
446 ███╗ ███╗ █████╗ ████████╗██████╗ ██╗██╗ ██╗
447 ████╗ ████║██╔══██╗╚══██╔══╝██╔══██╗██║╚██╗██╔╝
448 ██╔████╔██║███████║ ██║ ██████╔╝██║ ╚███╔╝
449 ██║╚██╔╝██║██╔══██║ ██║ ██╔══██╗██║ ██╔██╗
450 ██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║██║██╔╝ ██╗
451 ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝
452 
453 */
454 
458 {
459  slPushMatrix();
460 }
461 
465 {
466  slPopMatrix();
467 }
468 
469 /*
470 ███╗ ███╗ █████╗ ████████╗██████╗ ██╗██╗ ██╗ ██████╗ ██████╗ ████████╗ █████╗ ████████╗██╗ ██████╗ ███╗ ██╗
471 ████╗ ████║██╔══██╗╚══██╔══╝██╔══██╗██║╚██╗██╔╝ ██╔══██╗██╔═══██╗╚══██╔══╝██╔══██╗╚══██╔══╝██║██╔═══██╗████╗ ██║
472 ██╔████╔██║███████║ ██║ ██████╔╝██║ ╚███╔╝ ██████╔╝██║ ██║ ██║ ███████║ ██║ ██║██║ ██║██╔██╗ ██║
473 ██║╚██╔╝██║██╔══██║ ██║ ██╔══██╗██║ ██╔██╗ ██╔══██╗██║ ██║ ██║ ██╔══██║ ██║ ██║██║ ██║██║╚██╗██║
474 ██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║██║██╔╝ ██╗ ██║ ██║╚██████╔╝ ██║ ██║ ██║ ██║ ██║╚██████╔╝██║ ╚████║
475 ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝
476 
477 */
478 
484 static __jo_force_inline void jo_3d_rotate_matrix(short x, short y, short z)
485 {
486  slRotX(JO_MULT_BY_65536(x) / 360.0);
487  slRotY(JO_MULT_BY_65536(y) / 360.0);
488  slRotZ(JO_MULT_BY_65536(z) / 360.0);
489 }
490 
495 {
496  slRotX(JO_MULT_BY_65536(x) / 360.0);
497 }
498 
503 {
504  slRotY(JO_MULT_BY_65536(y) / 360.0);
505 }
506 
511 {
512  slRotZ(JO_MULT_BY_65536(z) / 360.0);
513 }
514 
520 static __jo_force_inline void jo_3d_rotate_matrix_rad(float x, float y, float z)
521 {
522  slRotX(RADtoANG(x));
523  slRotY(RADtoANG(y));
524  slRotZ(RADtoANG(z));
525 }
526 
531 {
532  slRotX(RADtoANG(x));
533 }
534 
539 {
540  slRotY(RADtoANG(y));
541 }
542 
547 {
548  slRotZ(RADtoANG(z));
549 }
550 
551 /*
552 ███╗ ███╗ █████╗ ████████╗██████╗ ██╗██╗ ██╗ ████████╗██████╗ █████╗ ███╗ ██╗███████╗██╗ █████╗ ████████╗██╗ ██████╗ ███╗ ██╗
553 ████╗ ████║██╔══██╗╚══██╔══╝██╔══██╗██║╚██╗██╔╝ ╚══██╔══╝██╔══██╗██╔══██╗████╗ ██║██╔════╝██║ ██╔══██╗╚══██╔══╝██║██╔═══██╗████╗ ██║
554 ██╔████╔██║███████║ ██║ ██████╔╝██║ ╚███╔╝ ██║ ██████╔╝███████║██╔██╗ ██║███████╗██║ ███████║ ██║ ██║██║ ██║██╔██╗ ██║
555 ██║╚██╔╝██║██╔══██║ ██║ ██╔══██╗██║ ██╔██╗ ██║ ██╔══██╗██╔══██║██║╚██╗██║╚════██║██║ ██╔══██║ ██║ ██║██║ ██║██║╚██╗██║
556 ██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║██║██╔╝ ██╗ ██║ ██║ ██║██║ ██║██║ ╚████║███████║███████╗██║ ██║ ██║ ██║╚██████╔╝██║ ╚████║
557 ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝
558 
559 */
560 
566 static __jo_force_inline void jo_3d_translate_matrixf(float x, float y, float z)
567 {
568  slTranslate(toFIXED(x), toFIXED(y), toFIXED(z));
569 }
570 
577 {
578  slTranslate(x, y, z);
579 }
580 
586 static __jo_force_inline void jo_3d_translate_matrix(int x, int y, int z)
587 {
588  slTranslate(jo_int2fixed(x), jo_int2fixed(y), jo_int2fixed(z));
589 }
590 
595 {
596  slTranslate(jo_int2fixed(x), 0, 0);
597 }
598 
603 {
604  slTranslate(0, jo_int2fixed(y), 0);
605 }
606 
611 {
612  slTranslate(0, 0, jo_int2fixed(z));
613 }
614 
615 /*
616 ██████╗ ██████╗ █████╗ ██╗ ██╗██╗███╗ ██╗ ██████╗
617 ██╔══██╗██╔══██╗██╔══██╗██║ ██║██║████╗ ██║██╔════╝
618 ██║ ██║██████╔╝███████║██║ █╗ ██║██║██╔██╗ ██║██║ ███╗
619 ██║ ██║██╔══██╗██╔══██║██║███╗██║██║██║╚██╗██║██║ ██║
620 ██████╔╝██║ ██║██║ ██║╚███╔███╔╝██║██║ ╚████║╚██████╔╝
621 ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝
622 
623 */
624 
628 static __jo_force_inline void jo_3d_draw(jo_3d_quad *const quad)
629 {
630  slPutPolygon(&quad->data);
631 }
632 
637 {
638  slPutPolygon(&mesh->data);
639 }
640 
646 {
647  return mesh->data.nbPolygon;
648 }
649 
654 {
655  jo_3d_draw((jo_3d_quad * const)node->data.ptr);
656 }
657 
661 static __jo_force_inline void jo_3d_draw_list(jo_list *const list)
662 {
664 }
665 
670 static __jo_force_inline void jo_3d_draw_array(jo_3d_quad * const array, int array_size)
671 {
672  while (--array_size >= 0) jo_3d_draw(array + array_size);
673 }
674 
679 static __jo_force_inline bool jo_3d_draw_sprite(const int sprite_id)
680 {
681  if (__jo_sprite_quad[sprite_id] == JO_NULL && !jo_3d_create_sprite_quad(sprite_id)) return (false);
682  jo_3d_draw(__jo_sprite_quad[sprite_id]);
683  return (true);
684 }
685 
692 static __jo_force_inline void jo_3d_draw_sprite_at(const int sprite_id, const int x, const int y, const int z)
693 {
695  jo_3d_translate_matrix(x, y, z);
696  jo_3d_draw_sprite(sprite_id);
698 }
699 
706 static __jo_force_inline void jo_3d_draw_billboard(const int sprite_id, const int x, const int y, const int z)
707 {
708  extern jo_pos3D __jo_sprite_pos;
710  jo_sprite_draw(sprite_id, &__jo_sprite_pos, true, true);
711 }
712 
720 static __jo_force_inline void jo_3d_draw_scaled_billboard(const int sprite_id, const int x, const int y, const int z, const int scale)
721 {
722  if (scale == 1)
723  jo_3d_draw_billboard(sprite_id, x, y, z);
724  else
725  {
726  extern jo_pos3D __jo_sprite_pos;
728  jo_fixed previous_scale_x = __jo_sprite_attributes.fixed_scale_x;
729  jo_fixed previous_scale_y = __jo_sprite_attributes.fixed_scale_y;
732  jo_sprite_draw(sprite_id, &__jo_sprite_pos, true, true);
733  __jo_sprite_attributes.fixed_scale_x = previous_scale_x;
734  __jo_sprite_attributes.fixed_scale_y = previous_scale_y;
735  }
736 }
737 
738 /*
739 ███████╗ ██████╗ █████╗ ██╗ ███████╗
740 ██╔════╝██╔════╝██╔══██╗██║ ██╔════╝
741 ███████╗██║ ███████║██║ █████╗
742 ╚════██║██║ ██╔══██║██║ ██╔══╝
743 ███████║╚██████╗██║ ██║███████╗███████╗
744 ╚══════╝ ╚═════╝╚═╝ ╚═╝╚══════╝╚══════╝
745 
746 */
747 
753 static __jo_force_inline void jo_3d_set_scalef(const float x, const float y, const float z)
754 {
755  slScale(toFIXED(x), toFIXED(y), toFIXED(z));
756 }
757 
763 static __jo_force_inline void jo_3d_set_scale(const int x, const int y, const int z)
764 {
766 }
767 
768 /*
769 ██╗ ██╗██╗███╗ ██╗██████╗ ██████╗ ██╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ██╗███████╗ ██████╗████████╗██╗ ██████╗ ███╗ ██╗
770 ██║ ██║██║████╗ ██║██╔══██╗██╔═══██╗██║ ██║ ██║ ██╔══██╗██╔══██╗██╔═══██╗ ██║██╔════╝██╔════╝╚══██╔══╝██║██╔═══██╗████╗ ██║
771 ██║ █╗ ██║██║██╔██╗ ██║██║ ██║██║ ██║██║ █╗ ██║ ████████╗ ██████╔╝██████╔╝██║ ██║ ██║█████╗ ██║ ██║ ██║██║ ██║██╔██╗ ██║
772 ██║███╗██║██║██║╚██╗██║██║ ██║██║ ██║██║███╗██║ ██╔═██╔═╝ ██╔═══╝ ██╔══██╗██║ ██║██ ██║██╔══╝ ██║ ██║ ██║██║ ██║██║╚██╗██║
773 ╚███╔███╔╝██║██║ ╚████║██████╔╝╚██████╔╝╚███╔███╔╝ ██████║ ██║ ██║ ██║╚██████╔╝╚█████╔╝███████╗╚██████╗ ██║ ██║╚██████╔╝██║ ╚████║
774  ╚══╝╚══╝ ╚═╝╚═╝ ╚═══╝╚═════╝ ╚═════╝ ╚══╝╚══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝
775 
776 */
777 
788 static __jo_force_inline bool jo_3d_window(const int left, const int top, const int right, const int bottom, const int z_limit, const int center_x, const int center_y)
789 {
790  return slWindow(left, top, right, bottom, z_limit, center_x, center_y) != 0;
791 }
792 
796 static __jo_force_inline void jo_3d_perspective_angle(const int angle)
797 {
798 #if JO_DEBUG
799  if (angle < 10 || angle > 160)
800  jo_core_error("Valid angle range is 10 to 160");
801 #endif
802  slPerspective(DEGtoANG(angle));
803 }
804 
808 static __jo_force_inline void jo_3d_display_level(const unsigned short level)
809 {
810  slZdspLevel(level);
811 }
812 
813 #endif /* !JO_COMPILE_WITH_3D_SUPPORT */
814 
815 #endif /* !__JO_3D_H__ */
816 
817 /*
818 ** END OF FILE
819 */
jo_3d_display_level
static __jo_force_inline void jo_3d_display_level(const unsigned short level)
Set the display level of the viewing volume.
Definition: 3d.h:808
jo_3d_rotate_matrix
static __jo_force_inline void jo_3d_rotate_matrix(short x, short y, short z)
Rotate 3D matrix using degree.
Definition: 3d.h:484
jo_3d_set_transparency
static __jo_force_inline void jo_3d_set_transparency(jo_3d_quad *const quad, const bool enabled)
Enable/Disable transparency on the quadrilateral.
Definition: 3d.h:382
jo_3d_get_polygon_count
static __jo_force_inline unsigned int jo_3d_get_polygon_count(void)
Get polygon count (visible and not visible)
Definition: 3d.h:202
jo_3d_rotate_matrix_rad_x
static __jo_force_inline void jo_3d_rotate_matrix_rad_x(float x)
Rotate 3D matrix using radian (X axis)
Definition: 3d.h:530
jo_3d_get_displayed_polygon_count
static __jo_force_inline unsigned int jo_3d_get_displayed_polygon_count(void)
Get displayed polygon count.
Definition: 3d.h:222
jo_3d_light
static __jo_force_inline void jo_3d_light(const int x, const int y, const int z)
Use a light source.
Definition: 3d.h:324
jo_3d_camera_look_at
static __jo_force_inline void jo_3d_camera_look_at(jo_camera *const cam)
look at the camera
Definition: 3d.h:183
jo_core_error
#define jo_core_error(...)
Definition: core.h:45
jo_3d_translate_matrix_y
static __jo_force_inline void jo_3d_translate_matrix_y(int y)
Translate 3D matrix (Y axis)
Definition: 3d.h:602
jo_3d_translate_matrix_fixed
static __jo_force_inline void jo_3d_translate_matrix_fixed(jo_fixed x, jo_fixed y, jo_fixed z)
Translate 3D matrix.
Definition: 3d.h:576
jo_3d_translate_matrixf
static __jo_force_inline void jo_3d_translate_matrixf(float x, float y, float z)
Translate 3D matrix (using floating numbers)
Definition: 3d.h:566
jo_3d_set_mesh_screen_doors
void jo_3d_set_mesh_screen_doors(jo_3d_mesh *const mesh, const bool enabled)
Enable/Disable screen doors transparency on the mesh.
jo_3d_translate_matrix
static __jo_force_inline void jo_3d_translate_matrix(int x, int y, int z)
Translate 3D matrix.
Definition: 3d.h:586
jo_3d_rotate_matrix_x
static __jo_force_inline void jo_3d_rotate_matrix_x(short x)
Rotate 3D matrix using degree (X axis)
Definition: 3d.h:494
jo_3d_set_mesh_texture
void jo_3d_set_mesh_texture(jo_3d_mesh *const mesh, const int sprite_id)
Set a texture on the mesh.
__jo_sprite_attributes
jo_sprite_attributes __jo_sprite_attributes
Current displayed sprite attribute (internal engine usage)
__jo_force_inline
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition: conf.h:154
jo_3d_set_mesh_polygon_light
void jo_3d_set_mesh_polygon_light(jo_3d_mesh *const mesh, const bool enabled, const unsigned int index)
Enable/Disable light on one polygon on the mesh.
jo_3d_camera_set_viewpoint
static __jo_force_inline void jo_3d_camera_set_viewpoint(jo_camera *const cam, const int x, const int y, const int z)
Set the viewpoint of the camera (where the cameraman is)
Definition: 3d.h:141
jo_3d_translate_matrix_z
static __jo_force_inline void jo_3d_translate_matrix_z(int z)
Translate 3D matrix (Z axis)
Definition: 3d.h:610
jo_3d_camera_init
static __jo_force_inline void jo_3d_camera_init(jo_camera *const cam)
Initialize the camera with default values.
Definition: 3d.h:173
jo_vertice
jo_pos3D jo_vertice
Vertice structure.
Definition: 3d.h:88
JO_MULT_BY_65536
#define JO_MULT_BY_65536(X)
Multiply a variable by 65536.
Definition: math.h:138
jo_3d_set_mesh_light
void jo_3d_set_mesh_light(jo_3d_mesh *const mesh, const bool enabled)
Enable/Disable light on the mesh.
jo_3d_draw_list
static __jo_force_inline void jo_3d_draw_list(jo_list *const list)
Draw a list of quadrilateral.
Definition: 3d.h:661
jo_3d_camera_set_target
static __jo_force_inline void jo_3d_camera_set_target(jo_camera *const cam, const int x, const int y, const int z)
Set the target of the camera (where the scene is located)
Definition: 3d.h:154
jo_3d_rotate_matrix_rad_z
static __jo_force_inline void jo_3d_rotate_matrix_rad_z(float z)
Rotate 3D matrix using radian (Z axis)
Definition: 3d.h:546
jo_sprite_draw
void jo_sprite_draw(const int sprite_id, const jo_pos3D *const pos, const bool centered_style_coordinates, const bool billboard)
(internal engine usage)
jo_3d_set_light
static __jo_force_inline void jo_3d_set_light(jo_3d_quad *const quad, const bool enabled)
Enable/Disable light on the quad.
Definition: 3d.h:350
jo_sprite_attributes::fixed_scale_y
jo_fixed fixed_scale_y
Definition: types.h:253
__jo_node::data
jo_list_data data
Definition: list.h:66
jo_color
unsigned short jo_color
15 bits color type
Definition: types.h:39
jo_camera::z_angle
ANGLE z_angle
Definition: 3d.h:103
jo_3d_rotate_matrix_rad_y
static __jo_force_inline void jo_3d_rotate_matrix_rad_y(float y)
Rotate 3D matrix using radian (Y axis)
Definition: 3d.h:538
jo_3d_rotate_matrix_y
static __jo_force_inline void jo_3d_rotate_matrix_y(short y)
Rotate 3D matrix using degree (Y axis)
Definition: 3d.h:502
jo_3d_mesh_draw
static __jo_force_inline void jo_3d_mesh_draw(jo_3d_mesh *const mesh)
Draw a mesh.
Definition: 3d.h:636
JO_NULL
#define JO_NULL
NULL implementation.
Definition: tools.h:170
jo_fixed
int jo_fixed
Fixed point Q16.16 number.
Definition: types.h:46
jo_3d_get_vertices_count
static __jo_force_inline unsigned int jo_3d_get_vertices_count(void)
Get vertice count.
Definition: 3d.h:212
jo_3d_translate_matrix_x
static __jo_force_inline void jo_3d_translate_matrix_x(int x)
Translate 3D matrix (X axis)
Definition: 3d.h:594
jo_3d_draw_sprite_at
static __jo_force_inline void jo_3d_draw_sprite_at(const int sprite_id, const int x, const int y, const int z)
Draw a sprite.
Definition: 3d.h:692
jo_3d_window
static __jo_force_inline bool jo_3d_window(const int left, const int top, const int right, const int bottom, const int z_limit, const int center_x, const int center_y)
Sets up a window region on the projection surface.
Definition: 3d.h:788
jo_int2fixed
static __jo_force_inline jo_fixed jo_int2fixed(const int x)
Convert int to jo engine fixed.
Definition: math.h:405
jo_3d_create_plane
void jo_3d_create_plane(jo_3d_quad *const quad, jo_vertice *const vertices)
Create a four vertices polygon (Quadrilateral shape)
jo_list_foreach
static __jo_force_inline void jo_list_foreach(jo_list *const list, jo_node_callback callback)
Iterate on the list.
Definition: list.h:220
jo_3d_quad::attribute
ATTR attribute
Definition: 3d.h:110
jo_3d_draw_sprite
static __jo_force_inline bool jo_3d_draw_sprite(const int sprite_id)
Draw a sprite.
Definition: 3d.h:679
jo_3d_create_sprite_quad
bool jo_3d_create_sprite_quad(const int sprite_id)
jo_3d_create_cube
void jo_3d_create_cube(jo_3d_quad *array, jo_vertice *const vertices)
Create a cube.
jo_3d_set_scale
static __jo_force_inline void jo_3d_set_scale(const int x, const int y, const int z)
Change scale.
Definition: 3d.h:763
jo_list
List struct.
Definition: list.h:73
jo_camera
Camera structure.
Definition: 3d.h:92
jo_3d_set_mesh_polygon_transparency
void jo_3d_set_mesh_polygon_transparency(jo_3d_mesh *const mesh, const bool enabled, const unsigned int index)
Enable/Disable transparency on one polygon on the mesh.
jo_3d_quad
Quadrilateral shape structure.
Definition: 3d.h:108
jo_3d_mesh::data
PDATA data
Definition: 3d.h:116
jo_3d_mesh
Mesh structure.
Definition: 3d.h:115
jo_3d_set_screen_doors
static __jo_force_inline void jo_3d_set_screen_doors(jo_3d_quad *const quad, const bool enabled)
Enable/Disable screen doors transparency on the quad.
Definition: 3d.h:408
jo_pos3D
3D position
Definition: types.h:66
jo_3d_set_mesh_polygon_color
void jo_3d_set_mesh_polygon_color(jo_3d_mesh *const mesh, const jo_color color, const unsigned int index)
Set the color on one polygon on the mesh.
jo_3d_free_sprite_quad
void jo_3d_free_sprite_quad(const int sprite_id)
Delete sprite quad.
__jo_node
Node struct.
Definition: list.h:65
jo_3d_quad::data
PDATA data
Definition: 3d.h:109
jo_3d_get_mesh_polygon_count
static __jo_force_inline unsigned int jo_3d_get_mesh_polygon_count(jo_3d_mesh *const mesh)
Get polygon count on the mesh.
Definition: 3d.h:645
jo_3d_push_matrix
static __jo_force_inline void jo_3d_push_matrix(void)
Push 3D matrix.
Definition: 3d.h:457
jo_3d_pop_matrix
static __jo_force_inline void jo_3d_pop_matrix(void)
Pop 3D matrix.
Definition: 3d.h:464
jo_3d_set_texture
static __jo_force_inline void jo_3d_set_texture(jo_3d_quad *const quad, const int sprite_id)
Set a texture on the quadrilateral.
Definition: 3d.h:304
jo_sprite_attributes::fixed_scale_x
jo_fixed fixed_scale_x
Definition: types.h:252
jo_3d_create_triangle
void jo_3d_create_triangle(jo_3d_quad *const quad, jo_vertice *const vertices)
Create a triangle.
jo_3d_draw_billboard
static __jo_force_inline void jo_3d_draw_billboard(const int sprite_id, const int x, const int y, const int z)
Draw billboard.
Definition: 3d.h:706
__jo_sprite_quad
jo_3d_quad * __jo_sprite_quad[JO_MAX_SPRITE]
Sprite quads (internal engine usage)
jo_3d_set_mesh_transparency
void jo_3d_set_mesh_transparency(jo_3d_mesh *const mesh, const bool enabled)
Enable/Disable transparency on the mesh.
__internal_jo_sprite_set_position3D
static __jo_force_inline void __internal_jo_sprite_set_position3D(const int x, const int y, const int z)
Internal usage don't use it.
Definition: sprites.h:65
jo_3d_get_sprite_quad
static __jo_force_inline jo_3d_quad * jo_3d_get_sprite_quad(const int sprite_id)
Get sprite quad.
Definition: 3d.h:267
jo_3d_set_mesh_color
void jo_3d_set_mesh_color(jo_3d_mesh *const mesh, const jo_color color)
Set the color on the mesh.
jo_3d_set_mesh_polygon_texture
void jo_3d_set_mesh_polygon_texture(jo_3d_mesh *const mesh, const int sprite_id, const unsigned int index)
Set a texture on one polygon on the mesh.
jo_3d_draw_array
static __jo_force_inline void jo_3d_draw_array(jo_3d_quad *const array, int array_size)
Draw an array of quadrilateral.
Definition: 3d.h:670
jo_3d_set_color
static __jo_force_inline void jo_3d_set_color(jo_3d_quad *const quad, const jo_color color)
Set the color on the quadrilateral.
Definition: 3d.h:440
jo_3d_draw_scaled_billboard
static __jo_force_inline void jo_3d_draw_scaled_billboard(const int sprite_id, const int x, const int y, const int z, const int scale)
Draw billboard with a specific scale.
Definition: 3d.h:720
jo_3d_rotate_matrix_rad
static __jo_force_inline void jo_3d_rotate_matrix_rad(float x, float y, float z)
Rotate 3D matrix using radian.
Definition: 3d.h:520
jo_3d_rotate_matrix_z
static __jo_force_inline void jo_3d_rotate_matrix_z(short z)
Rotate 3D matrix using degree (Z axis)
Definition: 3d.h:510
jo_list_data::ptr
void * ptr
Definition: list.h:59
jo_3d_camera_set_z_angle
static __jo_force_inline void jo_3d_camera_set_z_angle(jo_camera *const cam, const int angle)
Set the angle of the camera.
Definition: 3d.h:165
jo_3d_set_scalef
static __jo_force_inline void jo_3d_set_scalef(const float x, const float y, const float z)
Change scale using floating number.
Definition: 3d.h:753
jo_3d_draw
static __jo_force_inline void jo_3d_draw(jo_3d_quad *const quad)
Draw a quadrilateral.
Definition: 3d.h:628
jo_3d_set_mesh_polygon_screen_doors
void jo_3d_set_mesh_polygon_screen_doors(jo_3d_mesh *const mesh, const bool enabled, const unsigned int index)
Enable/Disable screen doors transparency on one polygon on the mesh.
jo_3d_perspective_angle
static __jo_force_inline void jo_3d_perspective_angle(const int angle)
Set the perspective angle.
Definition: 3d.h:796
__jo_poylgon_draw_iterator
static __jo_force_inline void __jo_poylgon_draw_iterator(jo_node *node)
Internal usage for polygon display.
Definition: 3d.h:653