1 /* ResidualVM - A 3D game interpreter 2 * 3 * ResidualVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the AUTHORS 5 * file distributed with this source distribution. 6 * 7 * Additional copyright for this file: 8 * Copyright (C) 1999-2000 Revolution Software Ltd. 9 * This code is based on source code created by Revolution Software, 10 * used with permission. 11 * 12 * This program is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; either version 2 15 * of the License, or (at your option) any later version. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU General Public License for more details. 21 * 22 * You should have received a copy of the GNU General Public License 23 * along with this program; if not, write to the Free Software 24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 25 * 26 */ 27 28 #ifndef ICB_SHADE_H 29 #define ICB_SHADE_H 30 31 #include "engines/icb/gfx/psx_pcdefines.h" 32 #include "engines/icb/gfx/rlp_api.h" 33 34 namespace ICB { 35 36 typedef struct FVECTOR { 37 float vx; 38 float vy; 39 float vz; 40 } FVECTOR; 41 42 // Handy maths function 43 void makePlaneEquation(FVECTOR *v0, FVECTOR *v1, FVECTOR *v2, int32 *d, FVECTOR *pn); 44 45 void preprocessShadeData(FVECTOR v[3], ShadeTriangle *s); 46 47 void preprocessShadeData(FVECTOR v[4], ShadeQuad *s); 48 49 #define DOT_PRODUCT(v0x, v0y, v0z, v1x, v1y, v1z) (((v0x) * (v1x)) + ((v0y) * (v1y)) + ((v0z) * (v1z))) 50 51 #define CROSS_PRODUCT(v0x, v0y, v0z, v1x, v1y, v1z, v2x, v2y, v2z) \ 52 { \ 53 v2x = ((v0y) * (v1z)) - ((v0z) * (v1y)); \ 54 v2y = ((v0z) * (v1x)) - ((v0x) * (v1z)); \ 55 v2z = ((v0x) * (v1y)) - ((v0y) * (v1x)); \ 56 } 57 58 #define VEC_SUB(v0x, v0y, v0z, v1x, v1y, v1z, v2x, v2y, v2z) \ 59 { \ 60 v2x = v0x - v1x; \ 61 v2y = v0y - v1y; \ 62 v2z = v0z - v1z; \ 63 } 64 65 #define VEC_ADD(v0x, v0y, v0z, v1x, v1y, v1z, v2x, v2y, v2z) \ 66 { \ 67 v2x = v0x + v1x; \ 68 v2y = v0y + v1y; \ 69 v2z = v0z + v1z; \ 70 } 71 72 #define DOT_PRODUCT(v0x, v0y, v0z, v1x, v1y, v1z) (((v0x) * (v1x)) + ((v0y) * (v1y)) + ((v0z) * (v1z))) 73 74 #define CROSS_PRODUCT(v0x, v0y, v0z, v1x, v1y, v1z, v2x, v2y, v2z) \ 75 { \ 76 v2x = ((v0y) * (v1z)) - ((v0z) * (v1y)); \ 77 v2y = ((v0z) * (v1x)) - ((v0x) * (v1z)); \ 78 v2z = ((v0x) * (v1y)) - ((v0y) * (v1x)); \ 79 } 80 81 #define NORMALISE(v0x, v0y, v0z) \ 82 { \ 83 double r = sqrt(DOT_PRODUCT(v0x, v0y, v0z, v0x, v0y, v0z)); \ 84 (v0x) = (float)((v0x) / r); \ 85 (v0y) = (float)((v0y) / r); \ 86 (v0z) = (float)((v0z) / r); \ 87 } 88 89 #define NORMALISE_VECTOR(v) NORMALISE((v).vx, (v).vy, (v).vz) 90 91 #define DOT_PRODUCT_VECTOR(v0, v1) DOT_PRODUCT(((v0).vx), ((v0).vy), ((v0).vz), ((v1).vx), ((v1).vy), ((v1).vz)) 92 93 #define CROSS_PRODUCT_VECTOR(v0, v1, v2) CROSS_PRODUCT(((v0).vx), ((v0).vy), ((v0).vz), ((v1).vx), ((v1).vy), ((v1).vz), ((v2).vx), ((v2).vy), ((v2).vz), ) 94 95 #define VEC_ADD_VECTOR(v0, v1, v2) VEC_ADD(((v0).vx), ((v0).vy), ((v0).vz), ((v1).vx), ((v1).vy), ((v1).vz), ((v2).vx), ((v2).vy), ((v2).vz), ) 96 97 #define VEC_SUB_VECTOR(v0, v1, v2) VEC_SUB(((v0).vx), ((v0).vy), ((v0).vz), ((v1).vx), ((v1).vy), ((v1).vz), ((v2).vx), ((v2).vy), ((v2).vz), ) 98 99 #define DOT_PRODUCT_SVECTOR(v0, v1) (DOT_PRODUCT((v0.vx), (v0.vy), (v0.vz), (v1.vx), (v1.vy), (v1.vz))) 100 101 } // End of namespace ICB 102 103 #endif // #ifndef SHADE_H 104