27 #ifndef ICB_PC_CAPRI_MATHS_H 28 #define ICB_PC_CAPRI_MATHS_H 30 #include "engines/icb/psx_config.h" 31 #include "engines/icb/common/px_capri_maths_pc.h" 35 #if (_PSX_ON_PC == 0) && !defined ICB_PSX_PCDEFINES_H 57 bool operator==(
const SVECTOR &v) {
return ((v.vx == vx) && (v.vy == vy) && (v.vz == vz)); }
65 bool operator==(
const CVECTOR &v) {
return ((v.r == r) && (v.g == g) && (v.b == b)); }
68 #endif // #if (_PSX_ON_PC==0) 71 #define myPI (3.141592654f) 73 inline int32 myNINT(
float f) {
80 #define VectorNormal myVectorNormal 81 #define ApplyMatrixLV myApplyMatrixLV 82 #define ApplyMatrixSV myApplyMatrixSV 83 #define RotMatrix_gte myRotMatrix_gte 84 #define gte_MulMatrix0 mygte_MulMatrix0 85 #define gte_RotTrans mygte_RotTrans 86 #define gte_RotTransPers mygte_RotTransPers 87 #define gte_RotTransPers3 mygte_RotTransPers3 88 #define gte_SetRotMatrix mygte_SetRotMatrix 89 #define gte_SetTransMatrix mygte_SetTransMatrix 90 #define gte_ApplyRotMatrix mygte_ApplyRotMatrix 91 #define gte_SetGeomScreen mygte_SetGeomScreen 92 #define gte_SetBackColor mygte_SetBackColor 93 #define gte_SetColorMatrix mygte_SetColorMatrix 94 #define gte_SetLightMatrix mygte_SetLightMatrix 95 #define gte_NormalColorCol mygte_NormalColorCol 96 #define gte_NormalColorCol3 mygte_NormalColorCol3 97 #define gte_NormalClip mygte_NormalClip 98 #define gte_AverageZ3 mygte_AverageZ3 104 extern int16 gteback[3];
105 extern int32 gtegeomscrn;
106 extern uint8 dcache[1024];
108 #define getScratchAddr(x) ((uint32 *)(dcache + x)) 118 inline void mygte_RotTrans(
SVECTOR *in0,
VECTOR *out0, int32 *flag);
120 inline void mygte_RotTransPers(
SVECTOR *in0, int32 *sxy0, int32 *p, int32 *flag, int32 *z);
122 inline void mygte_RotTransPers3(
SVECTOR *in0,
SVECTOR *in1,
SVECTOR *in2, int32 *sxy0, int32 *sxy1, int32 *sxy2, int32 *p, int32 *flag, int32 *z);
124 inline void mygte_SetRotMatrix(
MATRIX *m);
126 inline void mygte_SetTransMatrix(
MATRIX *m);
128 inline void mygte_ApplyRotMatrix(
SVECTOR *invec,
VECTOR *outvec);
132 inline void mygte_SetColorMatrix(
MATRIX *m);
134 inline void mygte_SetLightMatrix(
MATRIX *m);
136 inline void mygte_SetGeomScreen(int32 h);
138 inline void mygte_SetBackColor(int32 r, int32 g, int32 b);
144 inline void mygte_NormalClip(int32 sxy0, int32 sxy1, int32 sxy2, int32 *flag);
146 inline void mygte_AverageZ3(int32 z0, int32 z1, int32 z2, int32 *sz);
149 outvec->vx = ((int)m->m[0][0] * invec->vx + (
int)m->m[0][1] * invec->vy + (int)m->m[0][2] * invec->vz) / 4096;
150 outvec->vy = ((int)m->m[1][0] * invec->vx + (
int)m->m[1][1] * invec->vy + (int)m->m[1][2] * invec->vz) / 4096;
151 outvec->vz = ((int)m->m[2][0] * invec->vx + (
int)m->m[2][1] * invec->vy + (int)m->m[2][2] * invec->vz) / 4096;
155 outvec->vx = (int16)(((
int)m->m[0][0] * invec->vx + (
int)m->m[0][1] * invec->vy + (
int)m->m[0][2] * invec->vz) / 4096);
156 outvec->vy = (int16)(((
int)m->m[1][0] * invec->vx + (int)m->m[1][1] * invec->vy + (
int)m->m[1][2] * invec->vz) / 4096);
157 outvec->vz = (int16)(((
int)m->m[2][0] * invec->vx + (int)m->m[2][1] * invec->vy + (
int)m->m[2][2] * invec->vz) / 4096);
163 if ((out == m1) || (out == m2))
167 work->m[0][0] = (int16)(((
int)m1->m[0][0] * (
int)m2->m[0][0] + (
int)m1->m[0][1] * (
int)m2->m[1][0] + (
int)m1->m[0][2] * (
int)m2->m[2][0]) / 4096);
168 work->m[0][1] = (int16)(((
int)m1->m[0][0] * (int)m2->m[0][1] + (
int)m1->m[0][1] * (int)m2->m[1][1] + (
int)m1->m[0][2] * (int)m2->m[2][1]) / 4096);
169 work->m[0][2] = (int16)(((
int)m1->m[0][0] * (int)m2->m[0][2] + (
int)m1->m[0][1] * (int)m2->m[1][2] + (
int)m1->m[0][2] * (int)m2->m[2][2]) / 4096);
170 work->m[1][0] = (int16)(((
int)m1->m[1][0] * (int)m2->m[0][0] + (
int)m1->m[1][1] * (int)m2->m[1][0] + (
int)m1->m[1][2] * (int)m2->m[2][0]) / 4096);
171 work->m[1][1] = (int16)(((
int)m1->m[1][0] * (int)m2->m[0][1] + (
int)m1->m[1][1] * (int)m2->m[1][1] + (
int)m1->m[1][2] * (int)m2->m[2][1]) / 4096);
172 work->m[1][2] = (int16)(((
int)m1->m[1][0] * (int)m2->m[0][2] + (
int)m1->m[1][1] * (int)m2->m[1][2] + (
int)m1->m[1][2] * (int)m2->m[2][2]) / 4096);
173 work->m[2][0] = (int16)(((
int)m1->m[2][0] * (int)m2->m[0][0] + (
int)m1->m[2][1] * (int)m2->m[1][0] + (
int)m1->m[2][2] * (int)m2->m[2][0]) / 4096);
174 work->m[2][1] = (int16)(((
int)m1->m[2][0] * (int)m2->m[0][1] + (
int)m1->m[2][1] * (int)m2->m[1][1] + (
int)m1->m[2][2] * (int)m2->m[2][1]) / 4096);
175 work->m[2][2] = (int16)(((
int)m1->m[2][0] * (int)m2->m[0][2] + (
int)m1->m[2][1] * (int)m2->m[1][2] + (
int)m1->m[2][2] * (int)m2->m[2][2]) / 4096);
178 out->m[0][0] = work->m[0][0];
179 out->m[0][1] = work->m[0][1];
180 out->m[0][2] = work->m[0][2];
182 out->m[1][0] = work->m[1][0];
183 out->m[1][1] = work->m[1][1];
184 out->m[1][2] = work->m[1][2];
186 out->m[2][0] = work->m[2][0];
187 out->m[2][1] = work->m[2][1];
188 out->m[2][2] = work->m[2][2];
192 inline void mygte_SetRotMatrix(
MATRIX *m) { *gterot = *m; }
194 inline void mygte_SetTransMatrix(
MATRIX *m) { *gtetrans = *m; }
196 inline void mygte_ApplyRotMatrix(
SVECTOR *invec,
VECTOR *outvec) {
197 outvec->vx = (((int)gterot->m[0][0] * (
int)invec->vx + (int)gterot->m[0][1] * (
int)invec->vy + (int)gterot->m[0][2] * (
int)invec->vz) / 4096);
198 outvec->vy = (((int)gterot->m[1][0] * (
int)invec->vx + (int)gterot->m[1][1] * (
int)invec->vy + (int)gterot->m[1][2] * (
int)invec->vz) / 4096);
199 outvec->vz = (((int)gterot->m[2][0] * (
int)invec->vx + (int)gterot->m[2][1] * (
int)invec->vy + (int)gterot->m[2][2] * (
int)invec->vz) / 4096);
202 inline void mygte_RotTrans(
SVECTOR *in0,
VECTOR *out0, int32 *flag) {
203 mygte_ApplyRotMatrix(in0, out0);
204 out0->vx += gtetrans->t[0];
205 out0->vy += gtetrans->t[1];
206 out0->vz += gtetrans->t[2];
212 inline void mygte_RotTransPers(
SVECTOR *in0, int32 *sxy0, int32 * , int32 *flag, int32 *z) {
216 gte_RotTrans(in0, &cam, flag);
221 scrn->vx = (int16)((cam.vx * gtegeomscrn) / cam.vz);
222 scrn->vy = (int16)((cam.vy * gtegeomscrn) / cam.vz);
231 if (abs(scrn->vx) > 1024)
233 if (abs(scrn->vy) > 1024)
241 inline void mygte_RotTransPers3(
SVECTOR *in0,
SVECTOR *in1,
SVECTOR *in2, int32 *sxy0, int32 *sxy1, int32 *sxy2, int32 *p, int32 *flag, int32 *z) {
244 int32 flag0, flag1, flag2;
246 mygte_RotTransPers(in0, sxy0, &p0, &flag0, &z0);
247 mygte_RotTransPers(in1, sxy1, &p1, &flag1, &z1);
248 mygte_RotTransPers(in2, sxy2, &p2, &flag2, &z2);
251 *flag = flag0 | flag1 | flag2;
257 const int32 one = (1 << 12);
258 float ang0 = (float)rot->vx * 2.0f * myPI / one;
260 int32 c0 = myNINT(one * (
float)cos(ang0));
261 int32 s0 = myNINT(one * (
float)sin(ang0));
267 m0.m[1][1] = (int16)c0;
268 m0.m[1][2] = (int16)-s0;
271 m0.m[2][1] = (int16)s0;
272 m0.m[2][2] = (int16)c0;
274 float ang1 = (float)rot->vy * 2.0f * myPI / one;
275 int32 c1 = myNINT(one * (
float)cos(ang1));
276 int32 s1 = myNINT(one * (
float)sin(ang1));
278 m1.m[0][0] = (int16)c1;
280 m1.m[0][2] = (int16)s1;
286 m1.m[2][0] = (int16)-s1;
288 m1.m[2][2] = (int16)c1;
290 float ang2 = (float)rot->vz * 2.0f * myPI / one;
291 int32 c2 = myNINT(one * (
float)cos(ang2));
292 int32 s2 = myNINT(one * (
float)sin(ang2));
295 m2.m[0][0] = (int16)c2;
296 m2.m[0][1] = (int16)-s2;
299 m2.m[1][0] = (int16)s2;
300 m2.m[1][1] = (int16)c2;
307 mygte_MulMatrix0(&m0, &m1, m);
308 mygte_MulMatrix0(m, &m2, m);
311 inline void mygte_SetBackColor(int32 r, int32 g, int32 b) {
312 gteback[0] = (int16)r;
313 gteback[1] = (int16)g;
314 gteback[2] = (int16)b;
317 inline void mygte_SetColorMatrix(
MATRIX *m) { *gtecolour = *m; }
319 inline void mygte_SetLightMatrix(
MATRIX *m) { *gtelight = *m; }
321 inline void mygte_SetGeomScreen(int32 h) { gtegeomscrn = h; }
326 ApplyMatrixSV(gtelight, v0, &lightEffect);
327 if (lightEffect.vx < 0)
329 if (lightEffect.vy < 0)
331 if (lightEffect.vz < 0)
336 ApplyMatrixSV(gtecolour, &lightEffect, &colourEffect);
337 if (colourEffect.vx < 0)
339 if (colourEffect.vy < 0)
341 if (colourEffect.vz < 0)
346 colourEffect.vx = (int16)((colourEffect.vx >> 4) + gteback[0]);
347 colourEffect.vy = (int16)((colourEffect.vy >> 4) + gteback[1]);
348 colourEffect.vz = (int16)((colourEffect.vz >> 4) + gteback[2]);
352 int32 red = ((in0->r * colourEffect.vx) >> 8);
353 int32 green = ((in0->g * colourEffect.vy) >> 8);
354 int32 blue = ((in0->b * colourEffect.vz) >> 8);
363 out0->r = (uint8)(red);
364 out0->g = (uint8)(green);
365 out0->b = (uint8)(blue);
369 gte_NormalColorCol(v0, in0, out0);
370 gte_NormalColorCol(v1, in0, out1);
371 gte_NormalColorCol(v2, in0, out2);
374 inline int32 myVectorNormal(
VECTOR *in0,
VECTOR *out0) {
375 int32 r2 = (in0->vx * in0->vx + in0->vy * in0->vy + in0->vz * in0->vz);
376 float r = (float)sqrt((
float)r2) / 4096.0f;
378 if (fabs(r) < 1.0e-6)
381 out0->vx = (int32)((
float)in0->vx / r);
382 out0->vy = (int32)((
float)in0->vy / r);
383 out0->vz = (int32)((
float)in0->vz / r);
387 inline void mygte_NormalClip(int32 sxy0, int32 sxy1, int32 sxy2, int32 *flag) {
393 int32 l0x = v1->vx - v0->vx;
394 int32 l0y = v1->vy - v0->vy;
395 int32 l1x = v2->vx - v0->vx;
396 int32 l1y = v2->vy - v0->vy;
398 *flag = ((l0x * l1y) - (l0y * l1x));
401 inline void mygte_AverageZ3(int32 z0, int32 z1, int32 z2, int32 *sz) {
402 *sz = (z0 + z1 + z2) / 3;
408 #endif // #ifndef __PC_CAPRI_MATHS_H Definition: px_capri_maths.h:53
Definition: px_capri_maths.h:61
Definition: px_capri_maths.h:46
Definition: px_capri_maths.h:38