perspective.c
1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**************************************************************************
* *
* Copyright (C) 1994, Silicon Graphics, Inc. *
* *
* These coded instructions, statements, and computer programs contain *
* unpublished proprietary information of Silicon Graphics, Inc., and *
* are protected by Federal copyright law. They may not be disclosed *
* to third parties or copied or duplicated in any form, in whole or *
* in part, without the prior written consent of Silicon Graphics, Inc. *
* *
**************************************************************************/
#include "guint.h"
#include <ultratypes.h>
void guPerspectiveF(float mf[4][4], u16 *perspNorm, float fovy, float aspect, float near, float far, float scale)
{
float cot;
int i, j;
guMtxIdentF(mf);
fovy *= 3.1415926 / 180.0;
cot = cosf (fovy/2) / sinf (fovy/2);
mf[0][0] = cot / aspect;
mf[1][1] = cot;
mf[2][2] = (near + far) / (near - far);
mf[2][3] = -1;
mf[3][2] = (2 * near * far) / (near - far);
mf[3][3] = 0;
for (i=0; i<4; i++)
for (j=0; j<4; j++)
mf[i][j] *= scale;
if (perspNorm != (u16 *) NULL) {
if (near+far<=2.0) {
*perspNorm = (u16) 0xFFFF;
} else {
*perspNorm = (u16) ((2.0*65536.0)/(near+far));
if (*perspNorm<=0)
*perspNorm = (u16) 0x0001;
}
}
}
void guPerspective(Mtx *m, u16 *perspNorm, float fovy, float aspect, float near, float far, float scale)
{
Matrix mf;
guPerspectiveF(mf, perspNorm, fovy, aspect, near, far, scale);
guMtxF2L(mf, m);
}