This is topic Software 3D projection (or yay I actually get maths for once) in forum Math-a-holics and Code Junkies at The Geek Culture Forums!.


To visit this topic, use this URL:
http://www.geekculture.com/cgi-bin/ultimatebb/ultimatebb.cgi?ubb=get_topic;f=17;t=000172

Posted by serishema (Member # 4481) on November 05, 2005, 17:03:
 
I've been learning about how 3D graphics works. I was really surprised when I found out what the basic projection equation was x' = x / z y' = y / z with some scaling in there depending on your co-ordinate system.

I always thought it was really really complicated. Has anyone else notice how cirtain feilds of computer programming are some how mystified and made to seem much more difficult than they really are?

So now i'm trying to do some basic wireframe 3D graphics in software.

I was getting some very strange results and then i realised I was casting floats to int. Something tells me this will not work in C++.
I get really nutty co-ordinate values like
-41890284323, etc.

After all ages of being forced to program in java has made me forget how to do basic things like rounding in C++.

But it's nice to actually understand some maths for once. I failed maths all through school, so I always feel really good when i actually get something mathematical.
 
Posted by The Famous Druid (Member # 1769) on November 05, 2005, 20:28:
 
You've missed something, first you have to transform the x,y,z co-ordinates for the observers point-of-view. This involves applying some matrix calculations with sin() and cos() scattered seemingly at random, if memory serves (haven't done any of this in a very long time).

[edit] us usual, wikipedia has some useful info.
 
Posted by serishema (Member # 4481) on November 06, 2005, 02:07:
 
I did all that.. and yes wikipedia has lots of useful info about geometry and matrix algebra for those of us who can never remeber our maths.

it was only the final step that i was never able to figure out.. I was looking for something too complicated as usual.

I'm only drawing cubes at the moment as testing.
But I end up having to scale my points by the size i want (i start off with a vector of points for a cube 1.0f across) by multiplying by a scaling matrix, then rotate by an angle for the way they should face (i increment this in a wrap around fashion so it looks like they're spinning around), then scale by the distance away the viewpoint is supposed to be (another matrix multiply), then finally rotate all the points by another rotation matrix (this time x,y and z axies) from the camera angle. I can see why games take so much CPU now. I know this isn't actually the way it works, but at least i'm learning what it's all about.
 
Posted by The Famous Druid (Member # 1769) on November 06, 2005, 11:43:
 
quote:
Originally posted by serishema:
it was only the final step that i was never able to figure out.. I was looking for something too complicated as usual.

True story:

That last step could be expressed in English as "twice as far away looks half as big" and I once spent half an afternoon trying unsuccessfully to convince a workmate that it's the right way to scale for distance. Drew little diagrams, talked about 'similar triangles', the works, he still preferred his far more complicated method. These days, of course, I'd just point to the wikipedia page, but this was pre-internet (or at least pre widely available internet).
 
Posted by serishema (Member # 4481) on November 06, 2005, 23:52:
 
I think us geeks always go for complicated in preference to simple. It's a fault we all have.

I once spent ages looking for a problem on my home network, trying everything i could possibly think of until finally noticing all the lights on the switch front panel were on, even the ones for ports that weren't being used.

Then it dawned on me, the switch had failed.
 
Posted by drunkennewfiemidget (Member # 2814) on November 07, 2005, 06:11:
 
sprintf() would be good for rounding, btw.
 
Posted by serishema (Member # 4481) on November 11, 2005, 19:33:
 
I don't see how, I want to round a floating point value to an integer value
 


© 2018 Geek Culture

Powered by Infopop Corporation
UBB.classicTM 6.4.0