176 lines
5.6 KiB
C
176 lines
5.6 KiB
C
/// _
|
|
/// __ _| |__ __ _ _ __ ___
|
|
/// \ \/ / '_ \ / _` | '_ \ / _ \
|
|
/// > <| | | | (_| | |_) | __/
|
|
/// /_/\_\_| |_|\__,_| .__/ \___|
|
|
/// |_|
|
|
///
|
|
/// 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 {
|
|
natural vertex_count;
|
|
natural index_count;
|
|
natural vertex_limit;
|
|
natural index_limit;
|
|
real * vertex_array;
|
|
natural * index_array;
|
|
} shape_node;
|
|
|
|
static shape_node * shape_allocate (natural vertex_limit, natural 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 procedure shape_add_vertex_unwrap_colour (shape_node * shape, real x, real y, real z, real u, real v, natural 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 procedure shape_add_index (shape_node * shape, natural a, natural b, natural 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 (real x, real y, real z, real scale) {
|
|
//~static shape_node * shape_tetrahedron_unwrap_colour (real x, real y, real z, real scale, natural colour) {
|
|
static shape_node * shape_tetrahedron_colour (real x, real y, real z, real scale, natural colour) {
|
|
shape_node * shape = shape_allocate (4 * 9, 4 * 3);
|
|
|
|
real 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 (natural vertex = 0; vertex < 4; ++vertex) {
|
|
real x = vertices [3 * vertex + 0];
|
|
real y = vertices [3 * vertex + 1];
|
|
real z = vertices [3 * vertex + 2];
|
|
real u = (binary_sign (vertex >> 0) + 1.0f) / 2.0f;
|
|
real 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, real scale, natural colour) {
|
|
//~shape_node * shape = shape_allocate (4, 2 * 3);
|
|
|
|
//~shape_set_origin (shape, origin);
|
|
|
|
//~real 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 (natural vertex = 0; vertex < 4; ++vertex) {
|
|
//~vector_3 pointeger = {
|
|
//~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, real scale, natural colour) {
|
|
//~shape_node * shape = shape_allocate (8, 12 * 3);
|
|
|
|
//~shape_set_origin (shape, origin);
|
|
|
|
//~real 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 (natural vertex = 0; vertex < 8; ++vertex) {
|
|
//~vector_3 pointeger = {
|
|
//~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);
|
|
//~}
|