# Perspective

This topic is 5142 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've written some matrix functions to use fixed point math. Namly I'm using integers * 100. This all works fine until I create a perspective matrix. E.g [100, 0, 0, 0 0,100, 0, 0 0, 0,100, 33 0, 0, 0, 0] What is a general viewing distance people use in cases like this? Armand

##### Share on other sites
Can you clarify why you are using fixed-point math? If you think it'll be faster than floating-point, you're wrong... theoretically it is, but it won't give you a single additional frame per second on today's systems, especially with everything else going on.

##### Share on other sites
Using *100 means that you have to use /100 each time you do a multiply. Division is much more expensive than multiplication.

If I were you, I'd use *128, so you can adjust by shifting right 7 bits.

##### Share on other sites
FIxed point math = Every thing inside the matrixes is multed by 100.

Manly for the trig functions.

CGameProgrammer : I'm not using it for speed. but bacause I've hit more than one platform that does not support real numbers.

hplus0603 : I'm using 100 more for clarity. Saving some of the mental math when looking at the output. but the 128 not a bad idea.

Code example
#define FIXEDSCALE 100tPoint * M_MultMatrixPoint(tPoint * res, tPoint * a, tMatrix * b){	s16 j,k;	s32 sum;	tPoint tmp;	for (j=0; j<4; j++)	{		sum = 0;		for (k=0; k<4; k++)			sum += (a->a[k]) * (b->a[j][k]);		tmp.a[j] = sum;	}	if (tmp.a[3] != FIXEDSCALE)	{		tmp.a[0] /= tmp.a[3];		tmp.a[1] /= tmp.a[3];		tmp.a[3] = FIXEDSCALE;	}	for (j=0; j<4; j++)		res->a[j] = tmp.a[j] / FIXEDSCALE;	return res;}tMatrix * M_MakeRotateY(tMatrix * in, s16 ang){	M_Ident(in);		in->a[0][0] = in->a[2][2] = cos(ang);	in->a[2][0] = -sin(ang);	in->a[0][2] = sin(ang);	return in;}tMatrix * M_MakePercpec(tMatrix * in, s16 d){	M_Ident(in);	in->a[2][3] = (FIXEDSCALE/d);	in->a[3][3] = 0;	return in;}

Edit: Box insted of CODE section

[Edited by - Armand on August 25, 2004 9:56:53 PM]

##### Share on other sites
Quote:
 Original post by ArmandCGameProgrammer : I'm not using it for speed. but bacause I've hit more than one platform that does not support real numbers.

Wow, really? What platforms are you developing for?

Also, just as /128 can be done by right-shifting by 7, *128 can be done with left-shifting. But 128 won't give you much precision at all, if you need that...

##### Share on other sites
Palm pilot manly.
It has some floating point ops but they either require a libary, ASM to the FP registers (if you can find them and your compiler lets you push values there) or some funky compiler magic.

The PS2 stuff I currently having fun with seems to have something of it (either fixed 12.4 bit floats) which you can throw at the Graphic synth.

Gcc still has floats but there dosn't seem to be any other types like it that I've seen in the header files I've been playing with so I'm treating it like a fixed point machine.

Any way, this does not change my original question.
A given 4x4 projection matrix
1,0,0,00,1,0,00,0,1,X0,0,0,0

what is a good? value for X?
Or are there other values I'm missing for this?

Armand

##### Share on other sites
A description of the way OpenGL calculates it may be found here. Although the math seems ugly at first, most of it simplifies out very quickly.

Armand.

##### Share on other sites
Quote:
 Original post by Armand... What is a general viewing distance people use in cases like this?
1 is an extremely convenient viewing distance (assuming you mean the distance to the view plane).

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 41
• ### Forum Statistics

• Total Topics
632634
• Total Posts
3007556
• ### Who's Online (See full list)

There are no registered users currently online

×