homeGeek CultureWebstoreeCards!Forums!Joy of Tech!AY2K!webcam

The Geek Culture Forums!


Post New Topic  New Poll  Post A Reply
my profile | directory login | | search | faq | forum home
  next oldest topic   next newest topic
» The Geek Culture Forums!   » Techno-Talking   » Math-a-holics and Code Junkies   » Software 3D projection (or yay I actually get maths for once)

 - UBBFriend: Email this page to someone!    
Author Topic: Software 3D projection (or yay I actually get maths for once)
serishema
Geek Apprentice
Member # 4481

Member Rated:
5
Icon 1 posted November 05, 2005 17:03      Profile for serishema     Send New Private Message       Edit/Delete Post   Reply With Quote 
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.

Posts: 42 | From: New Zealand | Registered: Oct 2005  |  IP: Logged
The Famous Druid

Gold Hearted SuperFan!
Member # 1769

Member Rated:
4
Icon 1 posted November 05, 2005 20:28      Profile for The Famous Druid     Send New Private Message       Edit/Delete Post   Reply With Quote 
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.

--------------------
If you watch 'The History Of NASA' backwards, it's about a space agency that has no manned spaceflight capability, then does low-orbit flights, then lands on the Moon.

Posts: 10702 | From: Melbourne, Australia | Registered: Oct 2002  |  IP: Logged
serishema
Geek Apprentice
Member # 4481

Member Rated:
5
Icon 1 posted November 06, 2005 02:07      Profile for serishema     Send New Private Message       Edit/Delete Post   Reply With Quote 
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.

Posts: 42 | From: New Zealand | Registered: Oct 2005  |  IP: Logged
The Famous Druid

Gold Hearted SuperFan!
Member # 1769

Member Rated:
4
Icon 1 posted November 06, 2005 11:43      Profile for The Famous Druid     Send New Private Message       Edit/Delete Post   Reply With Quote 
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).

--------------------
If you watch 'The History Of NASA' backwards, it's about a space agency that has no manned spaceflight capability, then does low-orbit flights, then lands on the Moon.

Posts: 10702 | From: Melbourne, Australia | Registered: Oct 2002  |  IP: Logged
serishema
Geek Apprentice
Member # 4481

Member Rated:
5
Icon 1 posted November 06, 2005 23:52      Profile for serishema     Send New Private Message       Edit/Delete Post   Reply With Quote 
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.

Posts: 42 | From: New Zealand | Registered: Oct 2005  |  IP: Logged
drunkennewfiemidget
BlabberMouth, a Blabber Odyssey
Member # 2814

Member Rated:
4
Icon 1 posted November 07, 2005 06:11      Profile for drunkennewfiemidget     Send New Private Message       Edit/Delete Post   Reply With Quote 
sprintf() would be good for rounding, btw.
Posts: 4897 | From: Cambridge, ON, Canada | Registered: Jun 2004  |  IP: Logged
serishema
Geek Apprentice
Member # 4481

Member Rated:
5
Icon 1 posted November 11, 2005 19:33      Profile for serishema     Send New Private Message       Edit/Delete Post   Reply With Quote 
I don't see how, I want to round a floating point value to an integer value
Posts: 42 | From: New Zealand | Registered: Oct 2005  |  IP: Logged


All times are Eastern Time  
Post New Topic  New Poll  Post A Reply Close Topic    Move Topic    Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:

Contact Us | Geek Culture Home Page

© 2018 Geek Culture

Powered by Infopop Corporation
UBB.classicTM 6.4.0



homeGeek CultureWebstoreeCards!Forums!Joy of Tech!AY2K!webcam