Jo Engine 2026.11.6
Jo Sega Saturn Engine
Loading...
Searching...
No Matches
3d.h
Go to the documentation of this file.
1/*
2** Jo Sega Saturn Engine
3** Copyright (c) 2012-2026, 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*/
34
35#ifndef __JO_3D_H__
36# define __JO_3D_H__
37
38#ifdef JO_COMPILE_WITH_3D_SUPPORT
39
41# define JO_3D_PLANE_VERTICES(SIZE) \
42{ \
43 { -SIZE, -SIZE, 0 }, \
44 { SIZE, -SIZE, 0 }, \
45 { SIZE, SIZE, 0 }, \
46 { -SIZE, SIZE, 0 } \
47}
48
50# define JO_3D_TRIANGLE_VERTICES(SIZE) \
51{ \
52 { -SIZE, -SIZE, 0 }, \
53 { SIZE, -SIZE, 0 }, \
54 { SIZE, SIZE, 0 } \
55}
56
58# define JO_3D_CUBE_VERTICES(SIZE) \
59{ \
60 { -SIZE, -SIZE, SIZE }, \
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}
85
88
90# define JO_3D_QUAD_VERTEX_COUNT (4)
91
102static __jo_force_inline void jo_3d_set_quad_vertices(jo_vertice * const vertices, const jo_vertice * const center,
103 const jo_vertice * const right, const jo_vertice * const down)
104{
105 vertices[0].x = center->x - right->x - down->x;
106 vertices[0].y = center->y - right->y - down->y;
107 vertices[0].z = center->z - right->z - down->z;
108 vertices[1].x = center->x + right->x - down->x;
109 vertices[1].y = center->y + right->y - down->y;
110 vertices[1].z = center->z + right->z - down->z;
111 vertices[2].x = center->x + right->x + down->x;
112 vertices[2].y = center->y + right->y + down->y;
113 vertices[2].z = center->z + right->z + down->z;
114 vertices[3].x = center->x - right->x + down->x;
115 vertices[3].y = center->y - right->y + down->y;
116 vertices[3].z = center->z - right->z + down->z;
117}
118
120# define JO_3D_DEFAULT_PERSPECTIVE_ANGLE (90)
121
123# define JO_3D_DEFAULT_DISPLAY_LEVEL (3)
124
125/*
126** 3D model data
127*/
128
130# define JO_3D_SORT_PREVIOUS (0)
132# define JO_3D_SORT_MIN (1)
134# define JO_3D_SORT_MAX (2)
136# define JO_3D_SORT_CENTER (3)
138# define JO_3D_SORT_MASK (3)
139
141# define JO_3D_SINGLE_PLANE (0)
143# define JO_3D_DUAL_PLANE (1)
144
146# define JO_3D_NO_OPTION (0)
148# define JO_3D_USE_TEXTURE (JO_VDP1_OPTION_USE_TEXTURE)
150# define JO_3D_USE_LIGHT (1 << 3)
152# define JO_3D_USE_PALETTE (1 << 5)
154# define JO_3D_NO_TEXTURE (0)
155
157typedef struct
158{
159 jo_pos3D_fixed normal; // Normal vector (unit vector) used for lighting
160 unsigned short vertices[4]; // Vertex indexes
162
164typedef struct
165{
166 unsigned char plane; // JO_3D_SINGLE_PLANE or JO_3D_DUAL_PLANE
167 unsigned char sort; // JO_3D_SORT_xxx | JO_3D_USE_xxx options
168 unsigned short texture_id; // Sprite id
169 unsigned short draw_mode; // JO_VDP1_COLOR_MODE_xxx | JO_VDP1_COLOR_CALC_xxx | ...
170 unsigned short color; // RGB color or palette
171 unsigned short gouraud_table; // Gouraud table address / 8
172 unsigned short direction; // JO_VDP1_FUNCTION_xxx | flip
174
184
186typedef struct
187{
188 unsigned short first; // Index of the first polygon
189 unsigned short count; // Number of polygons
191
202# define JO_3D_ATTRIBUTE(PLANE, SORT, TEXTURE, COLOR, GOURAUD, DRAW_MODE, DIRECTION, OPTIONS) \
203 {(PLANE), (SORT) | JO_VDP1_DIRECTION_OPTIONS(DIRECTION) | (OPTIONS), (TEXTURE), (DRAW_MODE) | JO_VDP1_DIRECTION_DRAW_MODE(DIRECTION), \
204 (COLOR), (GOURAUD), JO_VDP1_DIRECTION_COMMAND(DIRECTION)}
205
211# define JO_3D_NORMAL(X, Y, Z) {JO_FLOAT_TO_FIXED(X), JO_FLOAT_TO_FIXED(Y), JO_FLOAT_TO_FIXED(Z)}
212
219# define JO_3D_VERTICES(A, B, C, D) {(A), (B), (C), (D)}
220
222typedef struct
223{
224 union
225 {
228 };
229 union
230 {
231 jo_fixed target[3];
233 };
235} jo_camera;
236
245
247typedef struct
248{
250} jo_3d_mesh;
251
256bool jo_3d_create_sprite_quad(const int sprite_id);
257
258
259/*
260 ██████╗ █████╗ ███╗ ███╗███████╗██████╗ █████╗
261██╔════╝██╔══██╗████╗ ████║██╔════╝██╔══██╗██╔══██╗
262██║ ███████║██╔████╔██║█████╗ ██████╔╝███████║
263██║ ██╔══██║██║╚██╔╝██║██╔══╝ ██╔══██╗██╔══██║
264╚██████╗██║ ██║██║ ╚═╝ ██║███████╗██║ ██║██║ ██║
265 ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝
266
267*/
268
269/*
270** Internal usage
271*/
273extern unsigned short __jo_3d_polygon_count;
275extern unsigned short __jo_3d_vertice_count;
277extern unsigned short __jo_3d_displayed_polygon_count;
284void __jo_3d_look_at(const jo_fixed * const camera, const jo_fixed * const target, const jo_angle angle);
290void __jo_3d_translate(const jo_fixed x, const jo_fixed y, const jo_fixed z);
296void __jo_3d_scale(const jo_fixed x, const jo_fixed y, const jo_fixed z);
298# define JO_3D_AXIS_X (0)
300# define JO_3D_AXIS_Y (1)
302# define JO_3D_AXIS_Z (2)
307void __jo_3d_rotate(const int axis, const jo_angle angle);
312void __jo_3d_light(const jo_pos3D_fixed * const light);
325void jo_3d_set_front_layer(const int shift);
326
328typedef struct
329{
330 jo_fixed (*matrix)[3]; // 4 rows of 3 (the matrix of the camera and of the part)
331 unsigned short first; // First point
332 unsigned short count; // Number of points
333} jo_3d_part;
334
347bool __jo_3d_draw_ranges_from(const jo_3d_polygon_data * const pdata, const unsigned int first_point,
348 const unsigned int point_count,
349 const jo_3d_polygon_range * const ranges, const int range_count);
350
351bool __jo_3d_draw_ranges(const jo_3d_polygon_data * const pdata, const unsigned int point_count,
352 const jo_3d_polygon_range * const ranges, const int range_count);
353
358static __jo_force_inline bool __jo_3d_draw(const jo_3d_polygon_data * const pdata)
359{
360 return (__jo_3d_draw_ranges(pdata, pdata->point_count, JO_NULL, 0));
361}
362
369static __jo_force_inline void jo_3d_camera_set_viewpoint(jo_camera * const cam, const int x, const int y, const int z)
370{
371 cam->viewpoint_pos.x = JO_MULT_BY_65536(x);
372 cam->viewpoint_pos.y = JO_MULT_BY_65536(y);
373 cam->viewpoint_pos.z = JO_MULT_BY_65536(z);
374}
375
382static __jo_force_inline void jo_3d_camera_set_target(jo_camera * const cam, const int x, const int y, const int z)
383{
384 cam->target_pos.x = JO_MULT_BY_65536(x);
385 cam->target_pos.y = JO_MULT_BY_65536(y);
386 cam->target_pos.z = JO_MULT_BY_65536(z);
387}
388
393static __jo_force_inline void jo_3d_camera_set_z_angle(jo_camera * const cam, const int angle)
394{
395 cam->z_angle = jo_DEGtoANG_int(angle);
396}
397
402{
403 jo_3d_camera_set_viewpoint(cam, 0, 0, -150);
404 jo_3d_camera_set_target(cam, 0, 0, 0);
406}
407
412{
413 __jo_3d_look_at(cam->viewpoint, cam->target, cam->z_angle);
414}
415
416/*
417███████╗████████╗ █████╗ ████████╗██╗███████╗████████╗██╗ ██████╗███████╗
418██╔════╝╚══██╔══╝██╔══██╗╚══██╔══╝██║██╔════╝╚══██╔══╝██║██╔════╝██╔════╝
419███████╗ ██║ ███████║ ██║ ██║███████╗ ██║ ██║██║ ███████╗
420╚════██║ ██║ ██╔══██║ ██║ ██║╚════██║ ██║ ██║██║ ╚════██║
421███████║ ██║ ██║ ██║ ██║ ██║███████║ ██║ ██║╚██████╗███████║
422╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
423
424*/
425
431{
432 return (__jo_3d_polygon_count);
433}
434
440{
441 return (__jo_3d_vertice_count);
442}
443
452
453/*
454 ██████╗██████╗ ███████╗ █████╗ ████████╗███████╗ ███████╗██╗███╗ ███╗██████╗ ██╗ ███████╗
455██╔════╝██╔══██╗██╔════╝██╔══██╗╚══██╔══╝██╔════╝ ██╔════╝██║████╗ ████║██╔══██╗██║ ██╔════╝
456██║ ██████╔╝█████╗ ███████║ ██║ █████╗ ███████╗██║██╔████╔██║██████╔╝██║ █████╗
457██║ ██╔══██╗██╔══╝ ██╔══██║ ██║ ██╔══╝ ╚════██║██║██║╚██╔╝██║██╔═══╝ ██║ ██╔══╝
458╚██████╗██║ ██║███████╗██║ ██║ ██║ ███████╗ ███████║██║██║ ╚═╝ ██║██║ ███████╗███████╗
459 ╚═════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚══════╝╚═╝╚═╝ ╚═╝╚═╝ ╚══════╝╚══════╝
460
461 ██████╗ ██████╗ ██╗███████╗ ██████╗████████╗
462██╔═══██╗██╔══██╗ ██║██╔════╝██╔════╝╚══██╔══╝
463██║ ██║██████╔╝ ██║█████╗ ██║ ██║
464██║ ██║██╔══██╗██ ██║██╔══╝ ██║ ██║
465╚██████╔╝██████╔╝╚█████╔╝███████╗╚██████╗ ██║
466 ╚═════╝ ╚═════╝ ╚════╝ ╚══════╝ ╚═════╝ ╚═╝
467
468*/
469
478jo_3d_mesh *jo_3d_create_mesh_from_vertices_and_normals(const unsigned int quad_count, jo_vertice * const vertices, jo_vector * const normals);
479
486static __jo_force_inline jo_3d_mesh *jo_3d_create_mesh_from_vertices(const unsigned int quad_count, jo_vertice * const vertices)
487{
488 return (jo_3d_create_mesh_from_vertices_and_normals(quad_count, vertices, JO_NULL));
489}
490
496static __jo_force_inline jo_3d_mesh *jo_3d_create_mesh(const unsigned int quad_count)
497{
499}
500
512jo_3d_mesh *jo_3d_create_sphere(const int radius, const unsigned int slices, const unsigned int stacks);
513
518void jo_3d_free_mesh(const jo_3d_mesh * const mesh);
519
524void jo_3d_create_plane(jo_3d_quad * const quad, jo_vertice * const vertices);
525
530void jo_3d_create_cube(jo_3d_quad * array, jo_vertice * const vertices);
531
536void jo_3d_create_triangle(jo_3d_quad * const quad, jo_vertice * const vertices);
537
543{
544#ifdef JO_DEBUG
545 if (sprite_id < 0 || __JO_SPRITE_IS_MISSING(sprite_id))
546 return (JO_NULL);
547#endif
548 return ((__jo_sprite_quad == JO_NULL || __jo_sprite_quad[sprite_id] == JO_NULL) && !jo_3d_create_sprite_quad(sprite_id) ? JO_NULL : __jo_sprite_quad[sprite_id]);
549}
550
554void jo_3d_free_sprite_quad(const int sprite_id);
555
556/*
557███╗ ███╗███████╗███████╗██╗ ██╗ ████████╗███████╗██╗ ██╗████████╗██╗ ██╗██████╗ ███████╗
558████╗ ████║██╔════╝██╔════╝██║ ██║ ╚══██╔══╝██╔════╝╚██╗██╔╝╚══██╔══╝██║ ██║██╔══██╗██╔════╝
559██╔████╔██║█████╗ ███████╗███████║ ██║ █████╗ ╚███╔╝ ██║ ██║ ██║██████╔╝█████╗
560██║╚██╔╝██║██╔══╝ ╚════██║██╔══██║ ██║ ██╔══╝ ██╔██╗ ██║ ██║ ██║██╔══██╗██╔══╝
561██║ ╚═╝ ██║███████╗███████║██║ ██║ ██║ ███████╗██╔╝ ██╗ ██║ ╚██████╔╝██║ ██║███████╗
562╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
563
564*/
565
571void jo_3d_set_mesh_polygon_texture(jo_3d_mesh * const mesh, const int sprite_id, const unsigned int index);
572
582void jo_3d_set_mesh_polygon_texture_bank(jo_3d_mesh * const mesh, const int sprite_id, const jo_palette * const palette,
583 const int bank, const unsigned int index);
584
592void jo_3d_set_mesh_polygon_texture_palette(jo_3d_mesh * const mesh, const int sprite_id, const jo_palette * const palette,
593 const unsigned int index);
594
599void jo_3d_set_mesh_texture(jo_3d_mesh * const mesh, const int sprite_id);
600
605static __jo_force_inline void jo_3d_set_texture(jo_3d_quad * const quad, const int sprite_id)
606{
607 jo_3d_set_mesh_polygon_texture((jo_3d_mesh *)quad, sprite_id, 0);
608}
609
615void jo_3d_set_mesh_polygon_wireframe(jo_3d_mesh * const mesh, const unsigned int index, bool wireframe);
616
617/*
618 8 BITS PALETTE HANDLING
619*/
620
626static __jo_force_inline void jo_3d_set_mesh_polygon_palette(jo_3d_mesh * const mesh, const int palette_id, const unsigned int index)
627{
628#ifdef JO_DEBUG
629 if (__JO_INDEX_IS_WRONG(palette_id, JO_PALETTE_MAX, "palette id") ||
630 __JO_INDEX_IS_WRONG(index, mesh->data.polygon_count, "polygon index"))
631 return;
632#endif
633 mesh->data.attributes[index].color = JO_MULT_BY_256(palette_id);
634}
635
640static __jo_force_inline void jo_3d_set_mesh_palette(jo_3d_mesh * const mesh, const int palette_id)
641{
642 // (once: not an error for each polygon)
643#ifdef JO_DEBUG
644 if (__JO_INDEX_IS_WRONG(palette_id, JO_PALETTE_MAX, "palette id"))
645 return;
646#endif
647 for (unsigned int i = 0; i < mesh->data.polygon_count; ++i)
648 jo_3d_set_mesh_polygon_palette(mesh, palette_id, i);
649}
650
655static __jo_force_inline void jo_3d_set_palette(jo_3d_quad * const quad, const int palette_id)
656{
657#ifdef JO_DEBUG
658 if (__JO_INDEX_IS_WRONG(palette_id, JO_PALETTE_MAX, "palette id"))
659 return;
660#endif
661 quad->attribute.color = JO_MULT_BY_256(palette_id);
662}
663
669static __jo_force_inline bool jo_3d_set_sprite_palette(const int sprite_id, const int palette_id)
670{
671#ifdef JO_DEBUG
672 if (sprite_id < 0 || __JO_SPRITE_IS_MISSING(sprite_id) || __JO_INDEX_IS_WRONG(palette_id, JO_PALETTE_MAX, "palette id"))
673 return (false);
674#endif
675 if ((__jo_sprite_quad == JO_NULL || __jo_sprite_quad[sprite_id] == JO_NULL) && !jo_3d_create_sprite_quad(sprite_id)) return (false);
676 jo_3d_set_palette(__jo_sprite_quad[sprite_id], palette_id);
677 return (true);
678}
679
685void jo_3d_set_mesh_polygon_high_speed_shrink(jo_3d_mesh * const mesh, const bool enabled, const unsigned int index);
686
691void jo_3d_set_mesh_high_speed_shrink(jo_3d_mesh * const mesh, const bool enabled);
692
703void jo_3d_set_high_speed_shrink(const bool enabled);
704
705/*
706███╗ ███╗███████╗███████╗██╗ ██╗ ██╗ ██╗███████╗██████╗ ████████╗██╗ ██████╗███████╗ ██╗ ███╗ ██╗ ██████╗ ██████╗ ███╗ ███╗ █████╗ ██╗
707████╗ ████║██╔════╝██╔════╝██║ ██║ ██║ ██║██╔════╝██╔══██╗╚══██╔══╝██║██╔════╝██╔════╝ ██║ ████╗ ██║██╔═══██╗██╔══██╗████╗ ████║██╔══██╗██║
708██╔████╔██║█████╗ ███████╗███████║ ██║ ██║█████╗ ██████╔╝ ██║ ██║██║ █████╗ ████████╗ ██╔██╗ ██║██║ ██║██████╔╝██╔████╔██║███████║██║
709██║╚██╔╝██║██╔══╝ ╚════██║██╔══██║ ╚██╗ ██╔╝██╔══╝ ██╔══██╗ ██║ ██║██║ ██╔══╝ ██╔═██╔═╝ ██║╚██╗██║██║ ██║██╔══██╗██║╚██╔╝██║██╔══██║██║
710██║ ╚═╝ ██║███████╗███████║██║ ██║ ╚████╔╝ ███████╗██║ ██║ ██║ ██║╚██████╗███████╗ ██████║ ██║ ╚████║╚██████╔╝██║ ██║██║ ╚═╝ ██║██║ ██║███████╗
711╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝
712*/
713
721static __jo_force_inline void jo_3d_set_mesh_vertice(jo_3d_mesh * const mesh, const jo_fixed x, const jo_fixed y, const jo_fixed z, const unsigned int index)
722{
723#ifdef JO_DEBUG
724 if (__JO_INDEX_IS_WRONG(index, mesh->data.point_count, "point index"))
725 return;
726#endif
727 mesh->data.points[index].x = x;
728 mesh->data.points[index].y = y;
729 mesh->data.points[index].z = z;
730}
731
739static __jo_force_inline void jo_3d_set_mesh_normal(jo_3d_mesh * const mesh, const jo_fixed x, const jo_fixed y, const jo_fixed z, const unsigned int index)
740{
741#ifdef JO_DEBUG
742 if (__JO_INDEX_IS_WRONG(index, mesh->data.polygon_count, "polygon index"))
743 return;
744#endif
745 mesh->data.polygons[index].normal.x = x;
746 mesh->data.polygons[index].normal.y = y;
747 mesh->data.polygons[index].normal.z = z;
748}
749
750/*
751███╗ ███╗███████╗███████╗██╗ ██╗ ██╗ ██╗ ██████╗ ██╗ ██╗████████╗
752████╗ ████║██╔════╝██╔════╝██║ ██║ ██║ ██║██╔════╝ ██║ ██║╚══██╔══╝
753██╔████╔██║█████╗ ███████╗███████║ ██║ ██║██║ ███╗███████║ ██║
754██║╚██╔╝██║██╔══╝ ╚════██║██╔══██║ ██║ ██║██║ ██║██╔══██║ ██║
755██║ ╚═╝ ██║███████╗███████║██║ ██║ ███████╗██║╚██████╔╝██║ ██║ ██║
756╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝
757
758*/
759
765static __jo_force_inline void jo_3d_light(const int x, const int y, const int z)
766{
768
769 p.x = JO_MULT_BY_65536(x);
770 p.y = JO_MULT_BY_65536(y);
771 p.z = JO_MULT_BY_65536(z);
772 __jo_3d_light(&p);
773}
774
781static __jo_force_inline void jo_3d_light_fixed(const jo_fixed x, const jo_fixed y, const jo_fixed z)
782{
784
785 p.x = x;
786 p.y = y;
787 p.z = z;
788 __jo_3d_light(&p);
789}
790
800void jo_3d_set_palette_light(const int levels, const int stride);
801
807void jo_3d_set_mesh_polygon_light(jo_3d_mesh * const mesh, const bool enabled, const unsigned int index);
808
813void jo_3d_set_mesh_light(jo_3d_mesh * const mesh, const bool enabled);
814
819static __jo_force_inline void jo_3d_set_light(jo_3d_quad *const quad, const bool enabled)
820{
821 jo_3d_set_mesh_polygon_light((jo_3d_mesh *)quad, enabled, 0);
822}
823
824/*
825████████╗██████╗ █████╗ ███╗ ██╗███████╗██████╗ █████╗ ██████╗ ███████╗███╗ ██╗ ██████╗██╗ ██╗
826╚══██╔══╝██╔══██╗██╔══██╗████╗ ██║██╔════╝██╔══██╗██╔══██╗██╔══██╗██╔════╝████╗ ██║██╔════╝╚██╗ ██╔╝
827 ██║ ██████╔╝███████║██╔██╗ ██║███████╗██████╔╝███████║██████╔╝█████╗ ██╔██╗ ██║██║ ╚████╔╝
828 ██║ ██╔══██╗██╔══██║██║╚██╗██║╚════██║██╔═══╝ ██╔══██║██╔══██╗██╔══╝ ██║╚██╗██║██║ ╚██╔╝
829 ██║ ██║ ██║██║ ██║██║ ╚████║███████║██║ ██║ ██║██║ ██║███████╗██║ ╚████║╚██████╗ ██║
830 ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝
831
832*/
833
839void jo_3d_set_mesh_polygon_transparency(jo_3d_mesh * const mesh, const bool enabled, const unsigned int index);
840
845void jo_3d_set_mesh_transparency(jo_3d_mesh * const mesh, const bool enabled);
846
851static __jo_force_inline void jo_3d_set_transparency(jo_3d_quad *const quad, const bool enabled)
852{
854}
855
856/******************************************************
857* SCREEN DOORS TRANSPARENCY
858*******************************************************/
859
865void jo_3d_set_mesh_polygon_screen_doors(jo_3d_mesh * const mesh, const bool enabled, const unsigned int index);
866
871void jo_3d_set_mesh_screen_doors(jo_3d_mesh * const mesh, const bool enabled);
872
877static __jo_force_inline void jo_3d_set_screen_doors(jo_3d_quad *const quad, const bool enabled)
878{
880}
881
882/******************************************************
883* GOURAUD SHADING
884*******************************************************/
885
892void jo_3d_set_mesh_polygon_gouraud(jo_3d_mesh * const mesh, const unsigned short table, const unsigned int index);
893
901unsigned short jo_3d_set_mesh_gouraud(jo_3d_mesh * const mesh, const jo_color * const tables);
902
903/*
904 ██████╗ ██████╗ ██╗ ██████╗ ██████╗ ███████╗
905██╔════╝██╔═══██╗██║ ██╔═══██╗██╔══██╗██╔════╝
906██║ ██║ ██║██║ ██║ ██║██████╔╝███████╗
907██║ ██║ ██║██║ ██║ ██║██╔══██╗╚════██║
908╚██████╗╚██████╔╝███████╗╚██████╔╝██║ ██║███████║
909 ╚═════╝ ╚═════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
910
911*/
912
919void jo_3d_set_mesh_polygon_color_ex(jo_3d_mesh * const mesh, const jo_color color, const unsigned int index, bool wireframe);
920
926static __jo_force_inline void jo_3d_set_mesh_polygon_color(jo_3d_mesh * const mesh, const jo_color color, const unsigned int index)
927{
928 jo_3d_set_mesh_polygon_color_ex(mesh, color, index, false);
929}
930
935void jo_3d_set_mesh_color(jo_3d_mesh * const mesh, const jo_color color);
936
942void jo_3d_set_mesh_color_ex(jo_3d_mesh * const mesh, const jo_color color, bool wireframe);
943
948static __jo_force_inline void jo_3d_set_color(jo_3d_quad * const quad, const jo_color color)
949{
950 jo_3d_set_mesh_polygon_color((jo_3d_mesh *)quad, color, 0);
951}
952
953/*
954███╗ ███╗ █████╗ ████████╗██████╗ ██╗██╗ ██╗
955████╗ ████║██╔══██╗╚══██╔══╝██╔══██╗██║╚██╗██╔╝
956██╔████╔██║███████║ ██║ ██████╔╝██║ ╚███╔╝
957██║╚██╔╝██║██╔══██║ ██║ ██╔══██╗██║ ██╔██╗
958██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║██║██╔╝ ██╗
959╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝
960*/
961
965
969
970/*
971███╗ ███╗ █████╗ ████████╗██████╗ ██╗██╗ ██╗ ██████╗ ██████╗ ████████╗ █████╗ ████████╗██╗ ██████╗ ███╗ ██╗
972████╗ ████║██╔══██╗╚══██╔══╝██╔══██╗██║╚██╗██╔╝ ██╔══██╗██╔═══██╗╚══██╔══╝██╔══██╗╚══██╔══╝██║██╔═══██╗████╗ ██║
973██╔████╔██║███████║ ██║ ██████╔╝██║ ╚███╔╝ ██████╔╝██║ ██║ ██║ ███████║ ██║ ██║██║ ██║██╔██╗ ██║
974██║╚██╔╝██║██╔══██║ ██║ ██╔══██╗██║ ██╔██╗ ██╔══██╗██║ ██║ ██║ ██╔══██║ ██║ ██║██║ ██║██║╚██╗██║
975██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║██║██╔╝ ██╗ ██║ ██║╚██████╔╝ ██║ ██║ ██║ ██║ ██║╚██████╔╝██║ ╚████║
976╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝
977
978*/
979
985static __jo_force_inline void jo_3d_rotate_matrix(short x, short y, short z)
986{
987 __jo_3d_rotate(JO_3D_AXIS_X, jo_DEGtoANG_int(x));
988 __jo_3d_rotate(JO_3D_AXIS_Y, jo_DEGtoANG_int(y));
989 __jo_3d_rotate(JO_3D_AXIS_Z, jo_DEGtoANG_int(z));
990}
991
996{
997 __jo_3d_rotate(JO_3D_AXIS_X, jo_DEGtoANG_int(x));
998}
999
1004{
1005 __jo_3d_rotate(JO_3D_AXIS_Y, jo_DEGtoANG_int(y));
1006}
1007
1012{
1013 __jo_3d_rotate(JO_3D_AXIS_Z, jo_DEGtoANG_int(z));
1014}
1015
1021static __jo_force_inline void jo_3d_rotate_matrix_rad(float x, float y, float z)
1022{
1023 __jo_3d_rotate(JO_3D_AXIS_X, jo_fixed_rad2ANGLE(jo_float2fixed(x)));
1024 __jo_3d_rotate(JO_3D_AXIS_Y, jo_fixed_rad2ANGLE(jo_float2fixed(y)));
1025 __jo_3d_rotate(JO_3D_AXIS_Z, jo_fixed_rad2ANGLE(jo_float2fixed(z)));
1026}
1027
1032{
1033 __jo_3d_rotate(JO_3D_AXIS_X, jo_fixed_rad2ANGLE(jo_float2fixed(x)));
1034}
1035
1040{
1041 __jo_3d_rotate(JO_3D_AXIS_Y, jo_fixed_rad2ANGLE(jo_float2fixed(y)));
1042}
1043
1048{
1049 __jo_3d_rotate(JO_3D_AXIS_Z, jo_fixed_rad2ANGLE(jo_float2fixed(z)));
1050}
1051
1064
1072
1080
1088
1089/*
1090███╗ ███╗ █████╗ ████████╗██████╗ ██╗██╗ ██╗ ████████╗██████╗ █████╗ ███╗ ██╗███████╗██╗ █████╗ ████████╗██╗ ██████╗ ███╗ ██╗
1091████╗ ████║██╔══██╗╚══██╔══╝██╔══██╗██║╚██╗██╔╝ ╚══██╔══╝██╔══██╗██╔══██╗████╗ ██║██╔════╝██║ ██╔══██╗╚══██╔══╝██║██╔═══██╗████╗ ██║
1092██╔████╔██║███████║ ██║ ██████╔╝██║ ╚███╔╝ ██║ ██████╔╝███████║██╔██╗ ██║███████╗██║ ███████║ ██║ ██║██║ ██║██╔██╗ ██║
1093██║╚██╔╝██║██╔══██║ ██║ ██╔══██╗██║ ██╔██╗ ██║ ██╔══██╗██╔══██║██║╚██╗██║╚════██║██║ ██╔══██║ ██║ ██║██║ ██║██║╚██╗██║
1094██║ ╚═╝ ██║██║ ██║ ██║ ██║ ██║██║██╔╝ ██╗ ██║ ██║ ██║██║ ██║██║ ╚████║███████║███████╗██║ ██║ ██║ ██║╚██████╔╝██║ ╚████║
1095╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝
1096
1097*/
1098
1104static __jo_force_inline void jo_3d_translate_matrixf(float x, float y, float z)
1105{
1106 __jo_3d_translate(jo_float2fixed(x), jo_float2fixed(y), jo_float2fixed(z));
1107}
1108
1118
1124static __jo_force_inline void jo_3d_translate_matrix(int x, int y, int z)
1125{
1126 __jo_3d_translate(jo_int2fixed(x), jo_int2fixed(y), jo_int2fixed(z));
1127}
1128
1133{
1134 __jo_3d_translate(jo_int2fixed(x), 0, 0);
1135}
1136
1141{
1142 __jo_3d_translate(0, jo_int2fixed(y), 0);
1143}
1144
1149{
1150 __jo_3d_translate(0, 0, jo_int2fixed(z));
1151}
1152
1153/*
1154██████╗ ██████╗ █████╗ ██╗ ██╗██╗███╗ ██╗ ██████╗
1155██╔══██╗██╔══██╗██╔══██╗██║ ██║██║████╗ ██║██╔════╝
1156██║ ██║██████╔╝███████║██║ █╗ ██║██║██╔██╗ ██║██║ ███╗
1157██║ ██║██╔══██╗██╔══██║██║███╗██║██║██║╚██╗██║██║ ██║
1158██████╔╝██║ ██║██║ ██║╚███╔███╔╝██║██║ ╚████║╚██████╔╝
1159╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚══╝╚══╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝
1160
1161*/
1162
1167{
1168#ifdef JO_DEBUG
1169 if (quad == JO_NULL)
1170 {
1171 jo_core_error("quad is null");
1172 return;
1173 }
1174#endif
1175 __jo_3d_draw(&quad->data);
1176}
1177
1182{
1183#ifdef JO_DEBUG
1184 if (mesh == JO_NULL)
1185 {
1186 jo_core_error("mesh is null");
1187 return;
1188 }
1189#endif
1191}
1192
1202static __jo_force_inline bool jo_3d_mesh_draw_ranges(const jo_3d_mesh * const mesh, const unsigned int point_count,
1203 const jo_3d_polygon_range * const ranges, const int range_count)
1204{
1205 return (__jo_3d_draw_ranges(&mesh->data, point_count, ranges, range_count));
1206}
1207
1214static __jo_force_inline void jo_3d_add_polygon_range(jo_3d_polygon_range * const ranges, int * const range_count, const int first,
1215 const int count)
1216{
1217 if (count <= 0)
1218 return;
1219 if (*range_count > 0 && ranges[*range_count - 1].first + ranges[*range_count - 1].count == first)
1220 {
1221 ranges[*range_count - 1].count += (unsigned short)count;
1222 return;
1223 }
1224 ranges[*range_count].first = (unsigned short)first;
1225 ranges[*range_count].count = (unsigned short)count;
1226 ++*range_count;
1227}
1228
1234{
1235 return mesh->data.polygon_count;
1236}
1237
1242{
1243 jo_3d_draw((jo_3d_quad * const)node->data.ptr);
1244}
1245
1253
1258static __jo_force_inline void jo_3d_draw_array(jo_3d_quad * const array, int array_size)
1259{
1260 while (--array_size >= 0) jo_3d_draw(array + array_size);
1261}
1262
1267static __jo_force_inline bool jo_3d_draw_sprite(const int sprite_id)
1268{
1269 if ((__jo_sprite_quad == JO_NULL || __jo_sprite_quad[sprite_id] == JO_NULL) && !jo_3d_create_sprite_quad(sprite_id)) return (false);
1270 jo_3d_draw(__jo_sprite_quad[sprite_id]);
1271 return (true);
1272}
1273
1280static __jo_force_inline void jo_3d_draw_sprite_at(const int sprite_id, const int x, const int y, const int z)
1281{
1283 jo_3d_translate_matrix(x, y, z);
1284 jo_3d_draw_sprite(sprite_id);
1286}
1287
1294static __jo_force_inline void jo_3d_draw_billboard(const int sprite_id, const int x, const int y, const int z)
1295{
1296 extern jo_pos3D __jo_sprite_pos;
1297 __internal_jo_sprite_set_position3D(x, y, z);
1298 jo_sprite_draw(sprite_id, &__jo_sprite_pos, true, true);
1299}
1300
1308static __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)
1309{
1310 if (scale == 1)
1311 jo_3d_draw_billboard(sprite_id, x, y, z);
1312 else
1313 {
1314 extern jo_pos3D __jo_sprite_pos;
1315 __internal_jo_sprite_set_position3D(x, y, z);
1318 __jo_sprite_attributes.fixed_scale_x = jo_int2fixed(scale);
1319 __jo_sprite_attributes.fixed_scale_y = jo_int2fixed(scale);
1320 jo_sprite_draw(sprite_id, &__jo_sprite_pos, true, true);
1321 __jo_sprite_attributes.fixed_scale_x = previous_scale_x;
1322 __jo_sprite_attributes.fixed_scale_y = previous_scale_y;
1323 }
1324}
1325
1326/*
1327███████╗ ██████╗ █████╗ ██╗ ███████╗
1328██╔════╝██╔════╝██╔══██╗██║ ██╔════╝
1329███████╗██║ ███████║██║ █████╗
1330╚════██║██║ ██╔══██║██║ ██╔══╝
1331███████║╚██████╗██║ ██║███████╗███████╗
1332╚══════╝ ╚═════╝╚═╝ ╚═╝╚══════╝╚══════╝
1333
1334*/
1335
1341static __jo_force_inline void jo_3d_set_scalef(const float x, const float y, const float z)
1342{
1343 __jo_3d_scale(jo_float2fixed(x), jo_float2fixed(y), jo_float2fixed(z));
1344}
1345
1351static __jo_force_inline void jo_3d_set_scale(const int x, const int y, const int z)
1352{
1354}
1355
1362{
1363 __jo_3d_scale(x, y, z);
1364}
1365
1373
1374/*
1375██╗ ██╗██╗███╗ ██╗██████╗ ██████╗ ██╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ██╗███████╗ ██████╗████████╗██╗ ██████╗ ███╗ ██╗
1376██║ ██║██║████╗ ██║██╔══██╗██╔═══██╗██║ ██║ ██║ ██╔══██╗██╔══██╗██╔═══██╗ ██║██╔════╝██╔════╝╚══██╔══╝██║██╔═══██╗████╗ ██║
1377██║ █╗ ██║██║██╔██╗ ██║██║ ██║██║ ██║██║ █╗ ██║ ████████╗ ██████╔╝██████╔╝██║ ██║ ██║█████╗ ██║ ██║ ██║██║ ██║██╔██╗ ██║
1378██║███╗██║██║██║╚██╗██║██║ ██║██║ ██║██║███╗██║ ██╔═██╔═╝ ██╔═══╝ ██╔══██╗██║ ██║██ ██║██╔══╝ ██║ ██║ ██║██║ ██║██║╚██╗██║
1379╚███╔███╔╝██║██║ ╚████║██████╔╝╚██████╔╝╚███╔███╔╝ ██████║ ██║ ██║ ██║╚██████╔╝╚█████╔╝███████╗╚██████╗ ██║ ██║╚██████╔╝██║ ╚████║
1380 ╚══╝╚══╝ ╚═╝╚═╝ ╚═══╝╚═════╝ ╚═════╝ ╚══╝╚══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝
1381
1382*/
1383
1394static __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)
1395{
1396 __jo_vdp1_set_window(left, top, right, bottom, z_limit, center_x, center_y);
1397 return (true);
1398}
1399
1409static __jo_force_inline void jo_3d_window_clip(const bool clip)
1410{
1412}
1413
1415# define JO_3D_NEAR_WINDOW (0)
1416
1418# define JO_3D_FAR_WINDOW (1)
1419
1421# define JO_3D_FAR_WINDOW_2 (2)
1422
1424# define JO_3D_LAYER_WINDOW (JO_VDP1_OFF_SCREEN_WINDOW)
1425
1429static __jo_force_inline void jo_3d_select_window(const int window)
1430{
1431 __jo_vdp1_select_window(window);
1432}
1433
1441static __jo_force_inline void jo_3d_set_windows_apart(const bool apart)
1442{
1444}
1445
1449static __jo_force_inline void jo_3d_perspective_angle(const int angle)
1450{
1451#ifdef JO_DEBUG
1452 if (angle < 10 || angle > 160)
1453 jo_core_error("Valid angle range is 10 to 160");
1454#endif
1455 __jo_3d_set_perspective(jo_DEGtoANG_int(angle));
1456}
1457
1463{
1464#ifdef JO_DEBUG
1465 if (angle < JO_DEG_TO_ANGLE(10) || angle > JO_DEG_TO_ANGLE(160))
1466 jo_core_error("Valid angle range is 10 to 160 degrees");
1467#endif
1469}
1470
1474static __jo_force_inline void jo_3d_display_level(const unsigned short level)
1475{
1477 __jo_vdp1_update_near_clip();
1478}
1479
1489void jo_3d_enable_dsp(const bool slave_cpu);
1490
1493
1495# define JO_3D_MAX_GUARD_BAND (512)
1498# define JO_3D_DEFAULT_GUARD_BAND (JO_3D_MAX_GUARD_BAND)
1499
1501extern int __jo_3d_guard_band;
1502
1514static __jo_force_inline void jo_3d_set_guard_band(const int pixels)
1515{
1516 __jo_3d_guard_band = pixels < 0 ? 0 : (pixels > JO_3D_MAX_GUARD_BAND ? JO_3D_MAX_GUARD_BAND : pixels);
1517}
1518
1524static __jo_force_inline void jo_3d_set_wireframe(const bool enabled)
1525{
1526 __jo_vdp1_wireframe = enabled;
1527}
1528
1533{
1534 return (__jo_vdp1_wireframe);
1535}
1536
1543static __jo_force_inline void jo_3d_set_depth_bias(const int bias)
1544{
1545 __jo_vdp1_depth_bias = bias;
1546}
1547
1552{
1553 return (__jo_vdp1_depth_bias);
1554}
1555
1556
1563
1569void jo_3d_transform_point_by(const jo_fixed (* const m)[3], const jo_pos3D_fixed * const in,
1570 jo_pos3D_fixed * const out);
1571
1576void jo_3d_slave_select_window(const int window);
1577
1583
1589void jo_3d_reflect_matrix(const jo_pos3D_fixed * const normal, const jo_fixed distance);
1590
1594void jo_3d_set_mirror(const bool mirror);
1595
1604
1611bool jo_3d_is_sphere_visible(const jo_pos3D_fixed * const center, const jo_fixed radius, const jo_fixed max_distance);
1612
1620bool jo_3d_slave_is_sphere_visible(const jo_pos3D_fixed * const center, const jo_fixed radius, const jo_fixed max_distance);
1621
1623typedef struct
1624{
1625 short left;
1626 short top;
1627 short right;
1628 short bottom;
1629} jo_3d_rect;
1630
1636void jo_3d_set_view_rect(const jo_3d_rect * const rect);
1637
1643
1652
1655typedef struct
1656{
1657 short nx; // Normal (Q14)
1658 short ny;
1659 short nz;
1660 short unused;
1661 int d; // n.a (a: the first vertex, whole units)
1662 short box[6]; // Box of the polygon (whole units, a margin of 1): x, y, z min, then max
1664
1675bool jo_3d_mesh_ray_hit(const jo_3d_mesh * const mesh, const jo_pos3D_fixed * const origin,
1676 const jo_pos3D_fixed * const dir, jo_fixed * const best,
1677 jo_pos3D_fixed * const normal);
1678
1685
1695bool jo_3d_mesh_ray_hit_with_planes(const jo_3d_mesh * const mesh, const jo_3d_ray_plane * const planes,
1696 const jo_pos3D_fixed * const origin, const jo_pos3D_fixed * const dir,
1697 jo_fixed * const best, jo_pos3D_fixed * const normal);
1698
1709bool jo_3d_draw_standing_sprite(const int sprite_id, const jo_pos3D_fixed * const foot, const jo_fixed width,
1710 const jo_fixed height, const jo_fixed sway, const bool flip);
1711
1712/*
1713** Fade of the far standing sprites: they appear little by little instead of all at once (the trees at the end of the view).
1714** Their pixels are mixed with the screens of the VDP2 under them (the sky) by the color calculation of the sprites: each
1715** pixel once, at the display (a half transparent polygon of the VDP1 can't be mixed with the VDP2, and its pixels drawn
1716** twice by the lines of a quad were mixed twice). A sprite that fades is drawn with its 16 colors in a bank of the color
1717** RAM: the color calculation bits of the palette pixels (sprite type 3: bits 12 and 11) choose one of the 4 ratios of the
1718** sprites, the bits 0 (near: opaque) to JO_3D_FADE_LEVELS (far: the most transparent).
1719** The VDP2: jo_vdp2_set_blend_mode(JO_VDP2_BLEND_RATIO); jo_vdp2_enable_blend(JO_SPRITE_SCREEN, 0);
1720** jo_vdp2_set_sprite_blend_ratios(0, 8, 16, 24) (ratio 0: the other sprites stay opaque)
1721*/
1722
1724# define JO_3D_FADE_LEVELS (3)
1726# define JO_3D_FADE_LEVEL_SHIFT (11)
1727
1739bool jo_3d_set_sprite_fade(const int sprite_id, const jo_palette * const palette, const int bank);
1740
1747void jo_3d_set_fade_distances(const jo_fixed start, const jo_fixed end);
1748
1756jo_3d_mesh *jo_3d_create_indexed_mesh(const unsigned int point_count, const unsigned int polygon_count);
1757
1772bool jo_3d_set_texture_subdivision(const int sprite_id);
1773
1787bool jo_3d_set_texture_subdivision_fine(const int sprite_id);
1788
1796
1803void jo_3d_set_texture_subdivision_depth(const int sprite_id, const jo_fixed depth);
1804
1811void jo_3d_set_texture_subdivision_error(const int sprite_id, const int pixels);
1812
1821void jo_3d_set_fewer_parts(const bool enabled);
1822
1834bool jo_3d_set_texture_mipmaps(const int sprite_id);
1835
1848bool jo_3d_set_texture_mipmap_copies(const int sprite_id, const int half_id, const int levels);
1849
1850#ifdef JO_COMPILE_WITH_DUAL_CPU_SUPPORT
1851
1852/*
1853** 3D on the slave CPU: the slave CPU draws objects at the same time as the master CPU (for instance the ground on the
1854** slave CPU, the characters and the buildings on the master CPU). Sequence of a frame:
1855** master CPU: camera matrix, jo_3d_slave_begin(), jo_core_exec_on_slave(my_slave_function), other drawings,
1856** jo_core_wait_for_slave(), jo_3d_slave_end()
1857** slave CPU (my_slave_function): jo_3d_slave_mesh_draw() for each object (jo_3d_slave_transform_point() to cull them)
1858** The slave CPU starts with the matrix of the camera given to jo_3d_slave_begin(), it has its own (small) matrix stack
1859*/
1860
1867
1871void jo_3d_slave_set_depth_bias(const int bias);
1872
1877void jo_3d_slave_set_guard_band(const int pixels);
1878
1884
1889
1892
1899
1905void jo_3d_slave_rotate_matrix(const int x, const int y, const int z);
1906
1912void jo_3d_slave_rotate(const int axis, const jo_angle angle);
1913
1920
1928bool jo_3d_slave_mesh_draw_ranges(const jo_3d_mesh * const mesh, const unsigned int point_count,
1929 const jo_3d_polygon_range * const ranges, const int range_count);
1930
1932bool __jo_3d_slave_draw_ranges_from(const jo_3d_mesh * const mesh, const unsigned int first_point,
1933 const unsigned int point_count,
1934 const jo_3d_polygon_range * const ranges, const int range_count);
1935
1941{
1942#ifdef JO_DEBUG
1943 if (mesh == JO_NULL)
1944 {
1945 jo_core_error("mesh is null");
1946 return (false);
1947 }
1948#endif
1950}
1951
1957
1970bool jo_3d_slave_draw_standing_sprite(const int sprite_id, const jo_pos3D_fixed * const foot,
1971 const jo_fixed width, const jo_fixed height,
1972 const jo_fixed sway, const bool flip);
1973
1980
1986
1991
1996
2002
2008void jo_3d_slave_set_kept_commands(const int count);
2009
2010#endif /* !JO_COMPILE_WITH_DUAL_CPU_SUPPORT */
2011
2019unsigned short jo_3d_add_gouraud_tables(const jo_color * const tables, const unsigned int count);
2020
2028void jo_3d_free_gouraud_tables(const unsigned short adr, const unsigned int count);
2029
2039void jo_3d_set_tint(const int r, const int g, const int b);
2040
2045unsigned short jo_3d_get_tint(void);
2046
2050void jo_3d_set_packed_tint(const unsigned short tint);
2051
2057void jo_3d_slave_set_tint(const unsigned short tint);
2058
2064
2077bool jo_3d_set_mesh_environment(jo_3d_mesh * const mesh, const int sprite_id, const int tiles);
2078
2085bool jo_3d_set_mesh_polygon_environment(jo_3d_mesh * const mesh, const unsigned int index);
2086
2087#endif /* !JO_COMPILE_WITH_3D_SUPPORT */
2088
2089#endif /* !__JO_3D_H__ */
2090
2091/*
2092** END OF FILE
2093*/
static __jo_force_inline void jo_3d_camera_look_at(jo_camera *const cam)
look at the camera
Definition 3d.h:411
static __jo_force_inline unsigned int jo_3d_get_displayed_polygon_count(void)
Get displayed polygon count.
Definition 3d.h:448
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.
bool jo_3d_set_texture_subdivision_fine(const int sprite_id)
Add finer tiles to the tiles of a texture (see jo_3d_set_texture_subdivision()): 8 x 8 and 16 x 16 ti...
static __jo_force_inline void jo_3d_rotate_matrix_x(short x)
Rotate 3D matrix using degree (X axis).
Definition 3d.h:995
static __jo_force_inline void jo_3d_translate_matrix(int x, int y, int z)
Translate 3D matrix.
Definition 3d.h:1124
static __jo_force_inline void jo_3d_set_mesh_vertice(jo_3d_mesh *const mesh, const jo_fixed x, const jo_fixed y, const jo_fixed z, const unsigned int index)
Set vertice position in mesh.
Definition 3d.h:721
unsigned short vertices[4]
Definition 3d.h:160
unsigned short texture_id
Definition 3d.h:168
int jo_3d_slave_get_max_vertices(void)
Points of the biggest object the slave CPU can draw (a bigger object is not drawn).
static __jo_force_inline void jo_3d_set_depth_bias(const int bias)
Set a depth added to the polygons and sprites drawn after this call, to sort them (the farthest are d...
Definition 3d.h:1543
void jo_3d_create_cube(jo_3d_quad *array, jo_vertice *const vertices)
Create a cube.
void jo_3d_set_view_rect(const jo_3d_rect *const rect)
The objects are seen only in a rectangle of the screen: jo_3d_is_sphere_visible() is false for the sp...
static __jo_force_inline void jo_3d_set_wireframe(const bool enabled)
Wireframe mode: the polygons and the standing sprites (distorted sprites) are drawn as their outline,...
Definition 3d.h:1524
int __jo_3d_guard_band
Guard band (internal engine usage, see jo_3d_set_guard_band()).
#define JO_3D_AXIS_Y
Y axis for __jo_3d_rotate().
Definition 3d.h:300
static __jo_force_inline void jo_3d_set_scale_fixed(const jo_fixed x, const jo_fixed y, const jo_fixed z)
Change scale using fixed number.
Definition 3d.h:1361
static __jo_force_inline void jo_3d_rotate_matrix_y(short y)
Rotate 3D matrix using degree (Y axis).
Definition 3d.h:1003
static __jo_force_inline void jo_3d_rotate_matrix_rad_z(float z)
Rotate 3D matrix using radian (Z axis).
Definition 3d.h:1047
static __jo_force_inline unsigned int jo_3d_get_polygon_count(void)
Get polygon count (visible and not visible).
Definition 3d.h:430
unsigned short first
Definition 3d.h:188
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:851
void __jo_3d_rotate(const int axis, const jo_angle angle)
Rotate the current matrix around an axis (Internal usage).
bool jo_3d_mesh_ray_hit(const jo_3d_mesh *const mesh, const jo_pos3D_fixed *const origin, const jo_pos3D_fixed *const dir, jo_fixed *const best, jo_pos3D_fixed *const normal)
First polygon of a mesh hit by a ray (the bullets: the walls of a building, the rooms of a level....
static __jo_force_inline void jo_3d_window_clip(const bool clip)
The 3D polygons drawn in the current window are clipped by the VDP1 to its rectangle (user clipping: ...
Definition 3d.h:1409
unsigned short jo_3d_get_tint(void)
The tint of the master CPU, packed (see jo_3d_set_tint()): 5 bits per component (signed,...
bool jo_3d_get_view_rect(jo_3d_rect *const rect)
The rectangle of jo_3d_set_view_rect().
void jo_3d_set_mesh_screen_doors(jo_3d_mesh *const mesh, const bool enabled)
Enable/Disable screen doors transparency on the mesh.
void jo_3d_transform_point_by(const jo_fixed(*const m)[3], const jo_pos3D_fixed *const in, jo_pos3D_fixed *const out)
Transform a point by a matrix (see jo_3d_transform_point(): the same result with the current matrix).
static __jo_force_inline void jo_3d_set_guard_band(const int pixels)
Set the guard band around the screen used by the clipping of the polygons drawn after this call.
Definition 3d.h:1514
jo_pos3D_fixed normal
Definition 3d.h:159
void jo_3d_set_mesh_polygon_texture_palette(jo_3d_mesh *const mesh, const int sprite_id, const jo_palette *const palette, const unsigned int index)
Set a texture of 256 colors on one polygon, its colors taken in a palette (its pixel value n: the col...
unsigned int point_count
Definition 3d.h:179
unsigned short __jo_3d_polygon_count
Polygon count of the current frame (Internal usage).
void jo_3d_slave_set_depth_bias(const int bias)
Change the depth bias of the objects drawn by the slave CPU (call it on the slave CPU).
short bottom
Definition 3d.h:1628
static __jo_force_inline void jo_3d_perspective_angle(const int angle)
Set the perspective angle.
Definition 3d.h:1449
static __jo_force_inline void jo_3d_set_windows_apart(const bool apart)
The windows do not overlap (a split screen: a view per player in its window): the commands of each wi...
Definition 3d.h:1441
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.
void jo_3d_set_fade_distances(const jo_fixed start, const jo_fixed end)
The distances of the fade of the standing sprites (see jo_3d_set_sprite_fade()): opaque up to start,...
short top
Definition 3d.h:1626
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:382
static __jo_force_inline void jo_3d_rotate_matrix(short x, short y, short z)
Rotate 3D matrix using degree.
Definition 3d.h:985
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:1114
void __jo_3d_light(const jo_pos3D_fixed *const light)
Set light direction (Internal usage).
void jo_3d_disable_dsp(void)
Stop using the SCU DSP to transform the vertices (see jo_3d_enable_dsp()).
int jo_3d_mesh_get_bounding_sphere(const jo_3d_mesh *const mesh, jo_pos3D_fixed *const center)
Bounding sphere of the points of a mesh (the sphere around their bounding box).
bool jo_3d_set_texture_mipmap_copies(const int sprite_id, const int half_id, const int levels)
Give a texture its smaller copies made beforehand (see jo_3d_set_texture_mipmaps()): for the textures...
static __jo_force_inline jo_fixed jo_3d_get_projection_distance(void)
Get the projection distance (distance of the projection plane, in pixels).
Definition 3d.h:1600
static __jo_force_inline void jo_3d_rotate_matrix_angle(const jo_angle x, const jo_angle y, const jo_angle z)
Rotate 3D matrix using jo_angle (0x10000 = 360 degrees: a fraction of degree, no float).
Definition 3d.h:1058
static __jo_force_inline bool __jo_3d_draw(const jo_3d_polygon_data *const pdata)
Draw polygons using the current matrix (Internal usage).
Definition 3d.h:358
static __jo_force_inline void __jo_poylgon_draw_iterator(jo_node *node)
Internal usage for polygon display.
Definition 3d.h:1241
void jo_3d_free_gouraud_tables(const unsigned short adr, const unsigned int count)
Give back gouraud tables of jo_3d_add_gouraud_tables() (jo_3d_free_model() gives back the tables of a...
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:1258
jo_3d_ray_plane * jo_3d_mesh_create_ray_planes(const jo_3d_mesh *const mesh)
The planes of the polygons of a mesh for jo_3d_mesh_ray_hit_with_planes() (the rays are faster: the m...
static __jo_force_inline void jo_3d_set_mesh_polygon_palette(jo_3d_mesh *const mesh, const int palette_id, const unsigned int index)
Set a palette on the mesh.
Definition 3d.h:626
void jo_3d_set_mesh_polygon_wireframe(jo_3d_mesh *const mesh, const unsigned int index, bool wireframe)
Set wireframe mode on the mesh.
void jo_3d_prepare_tint(const jo_3d_mesh *const mesh)
Make the tinted copy of the gouraud tables of a mesh for the current tint of the master CPU (see jo_3...
bool jo_3d_is_sphere_visible(const jo_pos3D_fixed *const center, const jo_fixed radius, const jo_fixed max_distance)
Check if a sphere (in the view space) can be seen (view frustum of the screen).
static __jo_force_inline void jo_3d_translate_matrixf(float x, float y, float z)
Translate 3D matrix (using floating numbers).
Definition 3d.h:1104
void jo_3d_pop_matrix(void)
Pop 3D matrix.
bool __jo_3d_draw_ranges_from(const jo_3d_polygon_data *const pdata, const unsigned int first_point, const unsigned int point_count, const jo_3d_polygon_range *const ranges, const int range_count)
Draw polygons using the current matrix (Internal usage).
static __jo_force_inline void jo_3d_set_palette(jo_3d_quad *const quad, const int palette_id)
Set a palette on the quadrilateral.
Definition 3d.h:655
void jo_3d_create_triangle(jo_3d_quad *const quad, jo_vertice *const vertices)
Create a triangle.
void jo_3d_set_high_speed_shrink(const bool enabled)
High speed shrink for every textured polygon drawn from now on (models, meshes, levels),...
void jo_3d_set_mesh_polygon_high_speed_shrink(jo_3d_mesh *const mesh, const bool enabled, const unsigned int index)
Enable/Disable High Speed Shrink on one polygon on the mesh.
static __jo_force_inline bool jo_3d_draw_sprite(const int sprite_id)
Draw a sprite.
Definition 3d.h:1267
static __jo_force_inline void jo_3d_set_mesh_palette(jo_3d_mesh *const mesh, const int palette_id)
Set a palette on one polygon on the mesh.
Definition 3d.h:640
bool jo_3d_mesh_ray_hit_with_planes(const jo_3d_mesh *const mesh, const jo_3d_ray_plane *const planes, const jo_pos3D_fixed *const origin, const jo_pos3D_fixed *const dir, jo_fixed *const best, jo_pos3D_fixed *const normal)
jo_3d_mesh_ray_hit() with the planes of the polygons of the mesh (the same result,...
bool jo_3d_draw_standing_sprite(const int sprite_id, const jo_pos3D_fixed *const foot, const jo_fixed width, const jo_fixed height, const jo_fixed sway, const bool flip)
Draw a sprite standing on the ground and facing the camera (trees, grass, characters far away....
void jo_3d_set_mesh_color(jo_3d_mesh *const mesh, const jo_color color)
Set the color on the mesh.
bool jo_3d_create_sprite_quad(const int sprite_id)
static __jo_force_inline bool jo_3d_set_sprite_palette(const int sprite_id, const int palette_id)
Set a palette on a sprite (3D).
Definition 3d.h:669
jo_3d_quad ** __jo_sprite_quad
Sprite quads (internal engine usage): a quad per sprite, the table allocated with the first quad (JO_...
jo_3d_polygon_data data
Definition 3d.h:249
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:1294
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:877
static __jo_force_inline void jo_3d_set_perspective(const jo_angle angle)
Set the perspective angle using jo_angle (a fraction of degree, as slPerspective() of the SGL).
Definition 3d.h:1462
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:819
void jo_3d_set_palette_light(const int levels, const int stride)
Palette lighting (the light of jo_3d_light() without the RGB colors: the only lighting of the 640 and...
int jo_3d_slave_get_command_count(void)
VDP1 commands used by the slave CPU in the last frame (see jo_3d_slave_end()).
void jo_3d_get_matrix(jo_fixed *m)
Copy the current matrix.
static __jo_force_inline void jo_3d_rotate_matrix_angle_z(const jo_angle z)
Rotate 3D matrix using jo_angle (Z axis).
Definition 3d.h:1084
void jo_3d_slave_select_window(const int window)
Select the window of the next drawings of the slave CPU (call it on the slave CPU; jo_3d_slave_begin(...
void __jo_3d_set_perspective(const jo_angle angle)
Set perspective angle (Internal usage).
void jo_3d_slave_translate_matrix_fixed(const jo_fixed x, const jo_fixed y, const jo_fixed z)
Translate the matrix of the slave CPU (call it on the slave CPU, see jo_3d_translate_matrix_fixed()).
void jo_3d_set_texture_subdivision_depth(const int sprite_id, const jo_fixed depth)
Draw in parts (see jo_3d_set_texture_subdivision()) only the polygons of a texture whose nearest vert...
void jo_3d_slave_rotate_matrix(const int x, const int y, const int z)
Rotate the matrix of the slave CPU (call it on the slave CPU, see jo_3d_rotate_matrix()).
void jo_3d_reflect_matrix(const jo_pos3D_fixed *const normal, const jo_fixed distance)
Multiply the current matrix by a reflection through a plane (a mirror: the camera matrix of the refle...
static __jo_force_inline 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.
Definition 3d.h:926
void jo_3d_slave_end(void)
Add the polygons drawn by the slave CPU to the frame (call it on the master CPU, after jo_core_wait_f...
jo_3d_mesh * jo_3d_create_mesh_from_vertices_and_normals(const unsigned int quad_count, jo_vertice *const vertices, jo_vector *const normals)
Create a mesh programmatically from vertices.
void jo_3d_slave_set_fade_distances(const jo_fixed start, const jo_fixed end)
The distances of the fade of the standing sprites of the slave CPU (see jo_3d_set_fade_distances()),...
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:1233
void jo_3d_free_mesh(const jo_3d_mesh *const mesh)
Free a mesh created with jo_3d_create_mesh().
bool __jo_3d_slave_draw_ranges_from(const jo_3d_mesh *const mesh, const unsigned int first_point, const unsigned int point_count, const jo_3d_polygon_range *const ranges, const int range_count)
jo_3d_slave_mesh_draw_ranges() with the points of the ranges known (see __jo_3d_draw_ranges_from())
static __jo_force_inline void jo_3d_restore_scale(void)
Scale of 1 (nothing changes): the scale of jo_3d_set_scale() is in the current matrix,...
Definition 3d.h:1369
void jo_3d_set_front_layer(const int shift)
The next 3D polygons (of the master CPU) are a front layer: drawn after (over) all the other polygons...
static __jo_force_inline void jo_3d_rotate_matrix_rad_x(float x)
Rotate 3D matrix using radian (X axis).
Definition 3d.h:1031
static __jo_force_inline void jo_3d_mesh_draw(jo_3d_mesh *const mesh)
Draw a mesh.
Definition 3d.h:1181
static __jo_force_inline void jo_3d_translate_matrix_z(int z)
Translate 3D matrix (Z axis).
Definition 3d.h:1148
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:1280
static __jo_force_inline void jo_3d_rotate_matrix_rad_y(float y)
Rotate 3D matrix using radian (Y axis).
Definition 3d.h:1039
short box[6]
Definition 3d.h:1662
static __jo_force_inline bool jo_3d_is_wireframe(void)
Check the wireframe mode (see jo_3d_set_wireframe()).
Definition 3d.h:1532
bool jo_3d_set_texture_mipmaps(const int sprite_id)
Create smaller copies of a texture (half and quarter size, "mipmaps") used when the texture is drawn ...
void jo_3d_set_mesh_polygon_color_ex(jo_3d_mesh *const mesh, const jo_color color, const unsigned int index, bool wireframe)
Set the color on one polygon on the mesh with wireframe option.
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:369
static __jo_force_inline void jo_3d_display_level(const unsigned short level)
Set the display level of the viewing volume.
Definition 3d.h:1474
void __jo_3d_scale(const jo_fixed x, const jo_fixed y, const jo_fixed z)
Scale the current matrix (Internal usage).
void jo_3d_set_mesh_polygon_texture_bank(jo_3d_mesh *const mesh, const int sprite_id, const jo_palette *const palette, const int bank, const unsigned int index)
Set a texture of 16 colors on one polygon, its colors taken in a bank of 16 colors of a palette (in p...
short nz
Definition 3d.h:1659
jo_3d_polygon_attribute * attributes
Definition 3d.h:182
unsigned short jo_3d_set_mesh_gouraud(jo_3d_mesh *const mesh, const jo_color *const tables)
Gouraud shading of the whole mesh: one table of 4 colors per polygon (a color per vertex,...
bool jo_3d_set_mesh_polygon_environment(jo_3d_mesh *const mesh, const unsigned int index)
A polygon shows the environment map of its mesh (see jo_3d_set_mesh_environment()): its gouraud table...
void jo_3d_slave_begin(void)
Prepare the 3D drawing of the slave CPU (call it on the master CPU, before jo_core_exec_on_slave()).
static __jo_force_inline void jo_3d_set_quad_vertices(jo_vertice *const vertices, const jo_vertice *const center, const jo_vertice *const right, const jo_vertice *const down)
Fill the 4 vertices of a quad (a parallelogram) from its center and 2 half edges, in the order of JO_...
Definition 3d.h:102
static __jo_force_inline void jo_3d_draw(jo_3d_quad *const quad)
Draw a quadrilateral.
Definition 3d.h:1166
bool __jo_3d_draw_ranges(const jo_3d_polygon_data *const pdata, const unsigned int point_count, const jo_3d_polygon_range *const ranges, const int range_count)
int jo_3d_slave_get_current_command_count(void)
Commands drawn by the slave CPU since jo_3d_slave_begin() (0 after jo_3d_slave_end()).
int jo_3d_slave_get_max_commands(void)
Commands the slave CPU can draw in a frame (the others are dropped, jo_3d_slave_mesh_draw() returns f...
static __jo_force_inline void jo_3d_add_polygon_range(jo_3d_polygon_range *const ranges, int *const range_count, const int first, const int count)
Add polygons to a list of ranges (see jo_3d_mesh_draw_ranges()): joined to the last range when they f...
Definition 3d.h:1214
void jo_3d_set_mesh_transparency(jo_3d_mesh *const mesh, const bool enabled)
Enable/Disable transparency on the mesh.
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:948
void jo_3d_transform_point(const jo_pos3D_fixed *const in, jo_pos3D_fixed *out)
Transform a point by the current matrix (for instance a world position into the view space,...
jo_3d_mesh * jo_3d_create_indexed_mesh(const unsigned int point_count, const unsigned int polygon_count)
Create an empty mesh made of shared points and polygons (indexes of the points).
unsigned short draw_mode
Definition 3d.h:169
static __jo_force_inline void jo_3d_rotate_matrix_rad(float x, float y, float z)
Rotate 3D matrix using radian.
Definition 3d.h:1021
unsigned short count
Definition 3d.h:189
unsigned short first
Definition 3d.h:331
static __jo_force_inline jo_3d_mesh * jo_3d_create_mesh(const unsigned int quad_count)
Create a mesh programmatically from vertices.
Definition 3d.h:496
short right
Definition 3d.h:1627
void jo_3d_set_mesh_light(jo_3d_mesh *const mesh, const bool enabled)
Enable/Disable light on the mesh.
jo_pos3D_fixed * points
Definition 3d.h:178
void jo_3d_set_mesh_texture(jo_3d_mesh *const mesh, const int sprite_id)
Set a texture on the mesh.
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:1394
void jo_3d_slave_transform_point(const jo_pos3D_fixed *const in, jo_pos3D_fixed *out)
Transform a point by the matrix of the slave CPU (call it on the slave CPU, see jo_3d_transform_point...
bool jo_3d_set_texture_subdivision_near_only(const int sprite_id)
Like jo_3d_set_texture_subdivision(), but only the polygons that cross the near plane (or go very far...
unsigned short direction
Definition 3d.h:172
static __jo_force_inline void jo_3d_camera_init(jo_camera *const cam)
Initialize the camera with default values.
Definition 3d.h:401
short nx
Definition 3d.h:1657
unsigned char sort
Definition 3d.h:167
static __jo_force_inline void jo_3d_rotate_matrix_angle_x(const jo_angle x)
Rotate 3D matrix using jo_angle (X axis).
Definition 3d.h:1068
bool jo_3d_set_mesh_environment(jo_3d_mesh *const mesh, const int sprite_id, const int tiles)
Environment map of a mesh (a reflection, like the paint of a car): its polygons set by jo_3d_set_mesh...
static __jo_force_inline void jo_3d_rotate_matrix_z(short z)
Rotate 3D matrix using degree (Z axis).
Definition 3d.h:1011
bool jo_3d_set_sprite_fade(const int sprite_id, const jo_palette *const palette, const int bank)
A standing sprite that fades with the distance (see jo_3d_set_fade_distances()): its 16 colors copied...
bool jo_3d_slave_is_sphere_visible(const jo_pos3D_fixed *const center, const jo_fixed radius, const jo_fixed max_distance)
jo_3d_is_sphere_visible() for the slave CPU: with the rectangle of jo_3d_set_view_rect() as it was at...
int d
Definition 3d.h:1661
unsigned short color
Definition 3d.h:170
short ny
Definition 3d.h:1658
static __jo_force_inline bool jo_3d_slave_mesh_draw(const jo_3d_mesh *const mesh)
Draw a mesh on the slave CPU (call it on the slave CPU, between jo_3d_slave_begin() and jo_3d_slave_e...
Definition 3d.h:1940
void jo_3d_slave_set_guard_band(const int pixels)
Change the guard band of the objects drawn by the slave CPU (call it on the slave CPU,...
void __jo_3d_look_at(const jo_fixed *const camera, const jo_fixed *const target, const jo_angle angle)
Multiply the current matrix by a camera matrix (Internal usage).
unsigned short gouraud_table
Definition 3d.h:171
jo_pos3D jo_vertice
Vertice structure.
Definition 3d.h:87
void jo_3d_push_matrix(void)
Push 3D matrix.
unsigned int polygon_count
Definition 3d.h:181
static __jo_force_inline void jo_3d_light_fixed(const jo_fixed x, const jo_fixed y, const jo_fixed z)
Use a light source: its direction as a unit vector.
Definition 3d.h:781
static __jo_force_inline void jo_3d_light(const int x, const int y, const int z)
Use a light source.
Definition 3d.h:765
void jo_3d_slave_set_tint(const unsigned short tint)
Tint the next meshes drawn by the slave CPU (call it on the slave CPU).
void jo_3d_slave_pop_matrix(void)
Pop the matrix of the slave CPU (call it on the slave CPU, see jo_3d_pop_matrix()).
void jo_3d_free_sprite_quad(const int sprite_id)
Delete sprite quad.
static __jo_force_inline void jo_3d_draw_list(jo_list *const list)
Draw a list of quadrilateral.
Definition 3d.h:1249
void jo_3d_set_mirror(const bool mirror)
The next polygons of the master CPU are seen in a mirror: their front faces are counterclockwise on t...
void jo_3d_set_mesh_polygon_gouraud(jo_3d_mesh *const mesh, const unsigned short table, const unsigned int index)
Give a gouraud table to one polygon of the mesh (the color of each of its 4 vertices is added to its ...
bool jo_3d_slave_push_matrix(void)
Push the matrix of the slave CPU (call it on the slave CPU, see jo_3d_push_matrix()).
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:393
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.
static __jo_force_inline void jo_3d_select_window(const int window)
Select the window used by jo_3d_window() and by the next drawings.
Definition 3d.h:1429
bool jo_3d_slave_mesh_draw_ranges(const jo_3d_mesh *const mesh, const unsigned int point_count, const jo_3d_polygon_range *const ranges, const int range_count)
Draw some ranges of polygons of a mesh on the slave CPU, without copying them (see jo_3d_mesh_draw_ra...
void jo_3d_slave_set_scale_fixed(const jo_fixed x, const jo_fixed y, const jo_fixed z)
Scale the matrix of the slave CPU (call it on the slave CPU, see jo_3d_set_scale_fixed()).
void jo_3d_set_texture_subdivision_error(const int sprite_id, const int pixels)
Distortion of a texture over which its polygons are drawn in parts (see jo_3d_set_texture_subdivision...
static __jo_force_inline jo_3d_mesh * jo_3d_create_mesh_from_vertices(const unsigned int quad_count, jo_vertice *const vertices)
Create a mesh programmatically from vertices.
Definition 3d.h:486
jo_fixed(* matrix)[3]
Definition 3d.h:330
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.
static __jo_force_inline void jo_3d_set_mesh_normal(jo_3d_mesh *const mesh, const jo_fixed x, const jo_fixed y, const jo_fixed z, const unsigned int index)
Set quad normal in mesh.
Definition 3d.h:739
static __jo_force_inline unsigned int jo_3d_get_vertices_count(void)
Get vertice count.
Definition 3d.h:439
jo_3d_polygon * polygons
Definition 3d.h:180
short left
Definition 3d.h:1625
#define JO_3D_MAX_GUARD_BAND
Biggest guard band around the screen (pixels): the coordinates of the VDP1 are limited.
Definition 3d.h:1495
struct __jo_may_alias jo_3d_quad
Quadrilateral shape structure.
#define JO_3D_AXIS_X
X axis for __jo_3d_rotate().
Definition 3d.h:298
void jo_3d_slave_rotate(const int axis, const jo_angle angle)
Rotate the matrix of the slave CPU around an axis by a precise angle (call it on the slave CPU): a sl...
static __jo_force_inline int jo_3d_get_depth_bias(void)
Get the depth added to the polygons and sprites (see jo_3d_set_depth_bias()).
Definition 3d.h:1551
static __jo_force_inline bool jo_3d_mesh_draw_ranges(const jo_3d_mesh *const mesh, const unsigned int point_count, const jo_3d_polygon_range *const ranges, const int range_count)
Draw some ranges of polygons of a mesh, without copying them (the points are transformed once).
Definition 3d.h:1202
void jo_3d_enable_dsp(const bool slave_cpu)
Transform the vertices with the SCU DSP (the third processor of the Saturn).
unsigned short count
Definition 3d.h:332
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:1341
bool jo_3d_slave_draw_standing_sprite(const int sprite_id, const jo_pos3D_fixed *const foot, const jo_fixed width, const jo_fixed height, const jo_fixed sway, const bool flip)
Draw a sprite standing on the ground and facing the camera on the slave CPU (see jo_3d_draw_standing_...
#define JO_3D_AXIS_Z
Z axis for __jo_3d_rotate().
Definition 3d.h:302
unsigned short __jo_3d_vertice_count
Vertice count of the current frame (Internal usage).
unsigned char plane
Definition 3d.h:166
void jo_3d_slave_set_kept_commands(const int count)
VDP1 commands kept for what is drawn after jo_3d_slave_end() (the weapon, the HUD): the polygons of t...
void jo_3d_set_packed_tint(const unsigned short tint)
Tint the next meshes drawn by the master CPU (see jo_3d_set_tint()).
void jo_3d_set_fewer_parts(const bool enabled)
Draw the polygons in parts only where it is needed to draw them at all (see jo_3d_set_texture_subdivi...
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:605
unsigned short __jo_3d_displayed_polygon_count
Displayed polygon count of the current frame (Internal usage).
bool jo_3d_set_texture_subdivision(const int sprite_id)
Draw the polygons that use a texture in parts when they are near the camera (2 x 2 or 4 x 4 parts,...
jo_3d_mesh * jo_3d_create_sphere(const int radius, const unsigned int slices, const unsigned int stacks)
Create a sphere (UV sphere).
static __jo_force_inline void jo_3d_translate_matrix_x(int x)
Translate 3D matrix (X axis).
Definition 3d.h:1132
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:1308
static __jo_force_inline void jo_3d_rotate_matrix_angle_y(const jo_angle y)
Rotate 3D matrix using jo_angle (Y axis).
Definition 3d.h:1076
static __jo_force_inline void jo_3d_translate_matrix_y(int y)
Translate 3D matrix (Y axis).
Definition 3d.h:1140
void jo_3d_set_mesh_color_ex(jo_3d_mesh *const mesh, const jo_color color, bool wireframe)
Set the color on the mesh.
static __jo_force_inline void jo_3d_set_scale(const int x, const int y, const int z)
Change scale.
Definition 3d.h:1351
void jo_3d_set_tint(const int r, const int g, const int b)
Tint the next meshes drawn by the master CPU: added to the colors of their gouraud tables (the light ...
short unused
Definition 3d.h:1660
unsigned short jo_3d_add_gouraud_tables(const jo_color *const tables, const unsigned int count)
Add gouraud tables in the VDP1 VRAM (4 colors per table, one per vertex of a polygon).
void jo_3d_create_plane(jo_3d_quad *const quad, jo_vertice *const vertices)
Create a four vertices polygon (Quadrilateral shape).
void __jo_3d_translate(const jo_fixed x, const jo_fixed y, const jo_fixed z)
Translate the current matrix (Internal usage).
void jo_3d_set_mesh_high_speed_shrink(jo_3d_mesh *const mesh, const bool enabled)
Enable/Disable High Speed Shrink on the mesh.
static __jo_force_inline jo_3d_quad * jo_3d_get_sprite_quad(const int sprite_id)
Get sprite quad.
Definition 3d.h:542
Mesh structure.
Definition 3d.h:248
Points of a mesh transformed by their own matrix (see __jo_3d_draw_parts()).
Definition 3d.h:329
Polygon (quadrilateral, a triangle repeats the last vertex).
Definition 3d.h:158
Polygon attribute.
Definition 3d.h:165
Polygon data (3D model).
Definition 3d.h:177
Range of polygons of a mesh (see jo_3d_mesh_draw_ranges()).
Definition 3d.h:187
Plane of a polygon for the rays (see jo_3d_mesh_create_ray_planes()): the normal and its distance,...
Definition 3d.h:1656
A rectangle of the screen (pixels, the edges are in it).
Definition 3d.h:1624
#define jo_core_error(...)
Definition core.h:47
#define __JO_INDEX_IS_WRONG(INDEX, COUNT, WHAT)
Check an index given to a function of the engine (Internal usage, JO_DEBUG).
Definition core.h:55
jo_3d_mesh * mesh
Definition entity.h:11
jo_pos3D_fixed center
Definition entity.h:13
int radius
Definition entity.h:3
unsigned short tint
Definition entity.h:32
int height
Definition entity.h:4
jo_list_data data
Definition list.h:67
struct __jo_node jo_node
Node type.
Definition list.h:39
void * ptr
Definition list.h:59
void jo_list_foreach(jo_list *const list, jo_node_callback callback)
Iterate on the list.
List struct.
Definition list.h:74
#define JO_MULT_BY_256(X)
Multiply a variable by 256.
Definition math.h:111
#define JO_DEG_TO_ANGLE(X)
Convert a degree to jo_angle.
Definition math.h:481
#define JO_MULT_BY_65536(X)
Multiply a variable by 65536.
Definition math.h:147
#define JO_PALETTE_MAX
Define the maximum of palette (the 256 colors palettes of the color RAM).
Definition sega_saturn.h:157
jo_3d_polygon_data data
Definition 3d.h:242
jo_3d_polygon_attribute attribute
Definition 3d.h:243
Quadrilateral shape structure.
Definition 3d.h:241
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_sprite_attributes __jo_sprite_attributes
Current displayed sprite attribute (internal engine usage).
#define __JO_SPRITE_IS_MISSING(SPRITE_ID)
Check the id of a sprite given to a function of the engine (Internal usage, JO_DEBUG).
Definition sprites.h:102
#define JO_NO_ZOOM
Value used to keep the original scale (1.0 in jo_fixed).
Definition sprites.h:402
Camera structure.
Definition 3d.h:223
jo_angle z_angle
Definition 3d.h:234
#define JO_NULL
NULL implementation.
Definition tools.h:261
jo_fixed z
Definition types.h:106
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition types.h:39
short jo_angle
Angle.
Definition types.h:65
int y
Definition types.h:87
unsigned short jo_color
15 bits color type
Definition types.h:53
jo_fixed x
Definition types.h:104
jo_fixed y
Definition types.h:105
jo_fixed fixed_scale_y
Definition types.h:290
int jo_fixed
Fixed point Q16.16 number.
Definition types.h:59
int x
Definition types.h:86
int z
Definition types.h:88
jo_fixed fixed_scale_x
Definition types.h:289
Palette contents struct.
Definition types.h:268
3D position
Definition types.h:85
3D position using fixed numbers
Definition types.h:103
Vector for 3D computation using integer.
Definition types.h:158
void __jo_vdp1_set_window(const short left, const short top, const short right, const short bottom, const short zlimit, const short center_x, const short center_y)
Set the current 3D window (internal usage).
bool __jo_vdp1_wireframe
Wireframe mode (internal usage, see jo_3d_set_wireframe()).
jo_fixed __jo_vdp1_projection_distance
Projection distance in Q16.16 (internal usage, see jo_3d_perspective_angle()).
void __jo_vdp1_set_window_clip(const bool clip)
The 3D polygons of the current window clipped to its rectangle (internal usage, see jo_3d_window_clip...
int __jo_vdp1_depth_bias
Depth added to the keys of the commands (see jo_3d_set_depth_bias()).
unsigned short __jo_vdp1_display_level
Near clipping divisor (internal usage, see jo_3d_display_level()).
bool __jo_vdp1_windows_apart
The windows drawn one after the other (internal usage, see jo_3d_set_windows_apart()).