Browse Source
Added initial frustum calculation based on screen parameters and view matrix.
unrollquadloop
Added initial frustum calculation based on screen parameters and view matrix.
unrollquadloop
5 changed files with 75 additions and 9 deletions
@ -0,0 +1,56 @@ |
|||
#include "common.h" |
|||
#include "frustum.h" |
|||
#include "display.h" |
|||
|
|||
#include <inline_c.h> |
|||
|
|||
static SVECTOR left, right, top, bottom; |
|||
|
|||
static INLINE void frustum_buildPlane(MATRIX *view_matrix, VECTOR *normal, SVECTOR *outPlane) |
|||
{ |
|||
ApplyMatrixLV(view_matrix, normal, normal); |
|||
VectorNormalS(normal, outPlane); |
|||
outPlane->pad = m_dot12(cam_pos, *outPlane); |
|||
} |
|||
|
|||
void frustum_update(MATRIX *view_matrix, int width, int height) |
|||
{ |
|||
VECTOR l, r, t, b; |
|||
|
|||
int near; |
|||
gte_ReadGeomScreen(&near); |
|||
|
|||
//FntPrint(-1, "N = %d, W = %d, H = %d\n", near, width, height); |
|||
|
|||
// 2 * near, shifted left for division |
|||
near <<= 13; |
|||
|
|||
l.vx = near / width; |
|||
l.vy = ONE; |
|||
l.vz = 0; |
|||
|
|||
b.vx = 0; |
|||
b.vy = ONE; |
|||
b.vz = near / height; |
|||
|
|||
r.vx = -l.vx; |
|||
r.vy = ONE; |
|||
r.vz = 0; |
|||
|
|||
t.vx = 0; |
|||
t.vy = ONE; |
|||
t.vz = -b.vz; |
|||
|
|||
frustum_buildPlane(view_matrix, &l, &left); |
|||
frustum_buildPlane(view_matrix, &r, &right); |
|||
frustum_buildPlane(view_matrix, &t, &top); |
|||
frustum_buildPlane(view_matrix, &b, &bottom); |
|||
|
|||
// FntPrint(-1, "l = %d %d, r = %d %d, t = %d %d, b = %d %d\n", |
|||
// left.vx, left.pad, right.vx, right.pad, top.vz, top.pad, bottom.vz, bottom.pad); |
|||
} |
|||
|
|||
u_char frustum_checkSphere(SVECTOR *sphere) |
|||
{ |
|||
return 1; |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
#ifndef __FRUSTUM_H__ |
|||
#define __FRUSTUM_H__ |
|||
|
|||
void frustum_update(MATRIX *view_matrix, int width, int height); |
|||
u_char frustum_checkSphere(SVECTOR *sphere); |
|||
|
|||
#endif // __FRUSTUM_H__ |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue