T O P I C R E V I E W

serishema
Member # 4481

posted 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 coordinate 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 coordinate 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.

The Famous Druid
Member # 1769

posted November 05, 2005 20:28
You've missed something, first you have to transform the x,y,z coordinates for the observers pointofview. 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.

serishema
Member # 4481

posted 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.

The Famous Druid
Member # 1769

posted 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 preinternet (or at least pre widely available internet).

serishema
Member # 4481

posted 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.

drunkennewfiemidget
Member # 2814

posted November 07, 2005 06:11
sprintf() would be good for rounding, btw.

serishema
Member # 4481

posted November 11, 2005 19:33
I don't see how, I want to round a floating point value to an integer value

