Main Page | Data Structures | File List | Data Fields | Globals

3d.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003 GFX - a small graphics library 
00004 
00005 Copyright (C) 2004  Rafael de Oliveira Jannone
00006 
00007 This library is free software; you can redistribute it and/or
00008 modify it under the terms of the GNU Lesser General Public
00009 License as published by the Free Software Foundation; either
00010 version 2.1 of the License, or (at your option) any later version.
00011 
00012 This library is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 Lesser General Public License for more details.
00016 
00017 You should have received a copy of the GNU Lesser General Public
00018 License along with this library; if not, write to the Free Software
00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021 Contact the author:
00022         by e-mail : rafael AT jannone DOT org
00023         homepage  : http://jannone.org/gfxlib
00024         ICQ UIN   : 10115284
00025 
00026 See the License at http://www.gnu.org/copyleft/lesser.txt
00027 
00028 =========================================================================*/
00029 
00033 // 3D.H : 3D graphics and vectors functions (header)
00034 
00035 /* === WARNING ==
00036 
00037         This is a work-in-progress, meaning that most of this code is unstable
00038         and it's subject to future changes.  Also, most of it is very hackish,
00039         not properly cleaned up nor tested.
00040 
00041    === WARNING == */
00042 
00043 // note 1: this code uses fixed-point arithmetic
00044 // note 2: every angle is one byte, to be mapped on the lookup tables
00045 // note 3: you must create the look up tables before doing anything
00046 
00047 #ifndef V3D_H
00048 #define V3D_H
00049 
00050 #include "gfx.h"
00051 
00053 extern int *tcos;
00054 
00056 extern int *tsin;
00057 
00059 typedef struct {
00060         int x;  
00061         int y;  
00062         int z;  
00063 } vector_t;
00064 
00066 typedef struct {
00067         vector_t* vertexes[3];  
00068 } triangle_t;
00069 
00071 typedef struct {
00072         int pcount;     
00073         int tcount;     
00074 
00075         vector_t* points;       
00076         triangle_t* triangles;  
00077 } mesh_t;
00078 
00080 typedef struct {
00081         mesh_t* mesh;   
00082         u_char rot_x;   
00083         u_char rot_y;   
00084         u_char rot_z;   
00085         int trans_x;    
00086         int trans_y;    
00087         int trans_z;    
00088 } object_t;
00089 
00091 extern void create_lookup_tables();
00092 
00094 extern void destroy_lookup_tables();
00095 
00097 extern mesh_t* mesh_new(int pcount, int tcount);
00098 
00100 extern void mesh_delete(mesh_t* mesh);
00101 
00103 extern void vector_cross_product (vector_t* v1, vector_t* v2, vector_t* r);
00104 
00106 extern int vector_cross_product_z (vector_t* v1, vector_t* v2);
00107 
00109 extern int vector_dot_product (vector_t* v1, vector_t* v2);
00110 
00112 extern int vector_length_squared (vector_t *v);
00113 
00115 extern int vector_length(vector_t *v);
00116 
00118 extern void vector_normalize(vector_t *p, vector_t *r);
00119 
00121 extern void vector_scalar(vector_t *v, int s, vector_t* r);
00122 
00124 extern void vector_add(vector_t *v1, vector_t *v2, vector_t *r);
00125 
00127 extern void vector_subtract (vector_t *v1, vector_t *v2, vector_t *r);
00128 
00130 extern int vector_distance (vector_t *v1, vector_t *v2);
00131 
00133 extern void vector_rotate(vector_t* p, u_char angle_x, u_char angle_y, u_char angle_z, vector_t* r);
00134 
00136 extern void object_apply_transformations(object_t* obj, vector_t* pbuffer, int x, int y);
00137 
00139 extern void object_render_wireframe(surface_t* s, object_t* obj, vector_t* pbuffer);
00140 
00142 extern void object_render_flatshading(surface_t* s, object_t* obj, vector_t* pbuffer, int* low, int* high, vector_t* light);
00143 
00144 #endif

Generated on Thu Mar 3 19:55:01 2005 for GFX lib by  doxygen 1.4.1