/// _ /// __ _| |__ __ _ _ __ ___ /// \ \/ / '_ \ / _` | '_ \ / _ \ /// > <| | | | (_| | |_) | __/ /// /_/\_\_| |_|\__,_| .__/ \___| /// |_| /// /// Copyright (c) 1997 - Ognjen 'xolatile' Milan Robovic /// /// xolatile@chud.cyou - xhape - Simplistic programmer art 3D model creator library. /// /// This program is free software, free as in freedom and as in free beer, you can redistribute it and/or modify it under the terms of the GNU /// General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version if you wish... /// /// This program is distributed in the hope that it will be useful, but it is probably not, and without any warranty, without even the implied /// warranty of merchantability or fitness for a particular purpose, because it is pointless. Please see the GNU (Geenoo) General Public License /// for more details, if you dare, it is a lot of text that nobody wants to read... typedef struct { uint vertex_count; uint index_count; uint vertex_limit; uint index_limit; float * vertex_array; uint * index_array; } shape_node; static shape_node * shape_allocate (uint vertex_limit, uint index_limit) { shape_node * shape = allocate (sizeof (* shape)); shape->vertex_limit = vertex_limit; shape->index_limit = index_limit; shape->vertex_array = allocate (vertex_limit * sizeof (* shape->vertex_array)); shape->index_array = allocate (index_limit * sizeof (* shape->index_array)); return (shape); } static shape_node * shape_deallocate (shape_node * shape) { shape->vertex_array = deallocate (shape->vertex_array); shape->index_array = deallocate (shape->index_array); return (deallocate (shape)); } static void shape_add_vertex_unwrap_colour (shape_node * shape, float x, float y, float z, float u, float v, uint colour) { fatal_failure (shape->vertex_count + 9 > shape->vertex_limit, "shape_add_vertex"); if (shape->vertex_count + 9 > shape->vertex_limit) return; shape->vertex_array [shape->vertex_count + 0] = x; shape->vertex_array [shape->vertex_count + 1] = y; shape->vertex_array [shape->vertex_count + 2] = z; shape->vertex_array [shape->vertex_count + 3] = u; shape->vertex_array [shape->vertex_count + 4] = v; shape->vertex_array [shape->vertex_count + 5] = normal_r (colour); shape->vertex_array [shape->vertex_count + 6] = normal_g (colour); shape->vertex_array [shape->vertex_count + 7] = normal_b (colour); shape->vertex_array [shape->vertex_count + 8] = normal_a (colour); shape->vertex_count += 9; } static void shape_add_index (shape_node * shape, uint a, uint b, uint c) { fatal_failure (shape->index_count + 3 > shape->index_limit, "shape_add_index"); if (shape->index_count + 3 > shape->index_limit) return; shape->index_array [shape->index_count + 0] = a; shape->index_array [shape->index_count + 1] = b; shape->index_array [shape->index_count + 2] = c; shape->index_count += 3; } //~static shape_node * shape_tetrahedron_unwrap (float x, float y, float z, float scale) { //~static shape_node * shape_tetrahedron_unwrap_colour (float x, float y, float z, float scale, uint colour) { static shape_node * shape_tetrahedron_colour (float x, float y, float z, float scale, uint colour) { shape_node * shape = shape_allocate (4 * 9, 4 * 3); float vertices [12] = { x + scale, y + scale, z + scale, x - scale, y - scale, z + scale, x - scale, y + scale, z - scale, x + scale, y - scale, z - scale }; for (uint vertex = 0; vertex < 4; ++vertex) { float x = vertices [3 * vertex + 0]; float y = vertices [3 * vertex + 1]; float z = vertices [3 * vertex + 2]; float u = (binary_sign (vertex >> 0) + 1.0f) / 2.0f; float v = (binary_sign (vertex >> 1) + 1.0f) / 2.0f; shape_add_vertex_unwrap_colour (shape, x, y, z, u, v, colour); } shape_add_index (shape, 0, 1, 2); shape_add_index (shape, 0, 3, 1); shape_add_index (shape, 0, 2, 3); shape_add_index (shape, 1, 3, 2); return (shape); } //~static shape_node * shape_square (vector_3 * origin, float scale, uint colour) { //~shape_node * shape = shape_allocate (4, 2 * 3); //~shape_set_origin (shape, origin); //~float central = square_root (2.0f) * scale / 2.0f; //~vector_4 normal_colour = { //~normal_r (colour), //~normal_b (colour), //~normal_g (colour), //~normal_a (colour) //~}; //~for (uint vertex = 0; vertex < 4; ++vertex) { //~vector_3 point = { //~origin->x + binary_sign (vertex >> 0) * central, //~origin->y + binary_sign (vertex >> 1) * central, //~origin->z //~}; //~vector_2 unwrap = { //~(binary_sign (vertex >> 0) + 1.0f) / 2.0f, //~(binary_sign (vertex >> 1) + 1.0f) / 2.0f //~}; //~shape_add_vertex (shape, & point, & unwrap, & normal_colour); //~} //~shape_add_index (shape, 0, 1, 2); //~shape_add_index (shape, 1, 3, 2); //~return (shape); //~} //~static shape_node * shape_cube (vector_3 * origin, float scale, uint colour) { //~shape_node * shape = shape_allocate (8, 12 * 3); //~shape_set_origin (shape, origin); //~float central = square_root (3.0f) * scale / 2.0f; //~vector_4 normal_colour = { //~normal_r (colour), //~normal_b (colour), //~normal_g (colour), //~normal_a (colour) //~}; //~for (uint vertex = 0; vertex < 8; ++vertex) { //~vector_3 point = { //~origin->x + binary_sign (vertex >> 0) * central, //~origin->y + binary_sign (vertex >> 1) * central, //~origin->z + binary_sign (vertex >> 2) * central //~}; //~vector_2 unwrap = { //~0.0f, //~0.0f //~}; //~shape_add_vertex (shape, & point, & unwrap, & normal_colour); //~} //~shape_add_index (shape, 0, 1, 2); //~shape_add_index (shape, 1, 3, 2); //~return (shape); //~}