Sign in to follow this  

Perspective

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 100

tPoint * 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 this post


Link to post
Share on other sites
Quote:
Original post by Armand
CGameProgrammer : 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 this post


Link to post
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,0
0,1,0,0
0,0,1,X
0,0,0,0


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

Armand

Share this post


Link to post
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.

Share this post


Link to post
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).

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this