Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / 2D representations of 3D objects

Author
Message
demons breath
20
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 26th Oct 2009 18:57
I have a maths essay for which we're basically allowed to choose any subject we want to as long as we use plentymany equations and suchlike. I remembered that for one of the Challenges Latch had a code which recreated a 3d matrix using dots. Does anyone know any references I can use for recreating this style of thing in a more broad range? Sort of equations which would be applied, and reasonably respectable looking sources I can include. I know this isn't technically a DarkBASIC question, but I thought given that Latch who posted the code still patrols here and I would be trying to recreate this in DarkBASIC and apply the formulae to it this was the best place to ask.

Latch's code is on Phaelax's site here
http://zimnox.com/dbcc/index.php?page=view&challenge=Boat%20Physics

"A West Texas girl, just like me"
-Bush
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 27th Oct 2009 02:09
Take a look at this thread:

2d to 3d

Read through the whole thing. It should help point you in the direction of the methods I used for that oscilating 3d matrix drawn in 2d.

Enjoy your day.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 27th Oct 2009 17:41
Thanks again for that Latch it was a great help.
The only thing I didn't get working was the backface culling.
It turned out the language I was using struggled to cope with 3 cubes at once! I converted it to DB so it might be fun to play around with it some time.

TGC Forum - converting error messages into sarcasm since 2002.
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 27th Oct 2009 17:45 Edited at: 28th Oct 2009 01:57
Hmmm thats some interesting stuff! I was messing around with it and after a while it makes your head hert! but i kept working with it anyway lol. I was just working with 2 vertices(just a line in 3d space), and coudn't get them to have 2 different y positions much less a hole pyramid like obese did hahaha but on the up side the z scaling stuff was working! lol

edit:

nevermind. got a box to rotate and move lol.

New Site! Check it out \/
demons breath
20
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 28th Oct 2009 16:55
Thanks a lot Latch I've started reading through it and it looks very useful. I'll give it a proper look tomorrow (Me birthday today so I'm pretty much avoiding thinking altogether)... Thanks for that man.

"A West Texas girl, just like me"
-Bush
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 28th Oct 2009 20:25
Quote: "Me birthday today so I'm pretty much avoiding thinking altogether"


Haha, that's usually the day i code the most i always have nothing else to do lol

New Site! Check it out \/
demons breath
20
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 28th Oct 2009 20:38
Yeah but this stuff's for coursework. Chose the topic because it's interesting, but I don't have as much scope to play around and I've got to write a 5 page essay as I go. Really don't want to get started on that though... I didn't choose Maths to write essays...

"A West Texas girl, just like me"
-Bush
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 29th Oct 2009 04:15 Edited at: 29th Oct 2009 04:24
Hahaha i HATE essays!

Question on topic:

How would the calculations work if i wanted to rotate the camera?

and i was moving my object around and if objZ < camZ then the object starts moving away again only mirrored(so if it was on the bottom it's on the top. and if it was on the left it's on the right, and vise versa)

How do i test to see if it's on the screen?

New Site! Check it out \/
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 31st Oct 2009 23:17
@Caleb
It gets more complicated pretty quickly the more you want to do. For rotating the camera, you need to use matrix rotation math. I suppose you use quaternions, but the general rule of thumb is matrix rotation. The thing to keep in mind is, if you rotate the camera, the 3d points of the world are actually rotated in the opposite direction. The approach might be like this:

1. Based on screen resolution, find the distance where 1 screen pixel is equal to 1 3d unit. I'll call this the base z-distance. Using that value, you can create a ratio where you can translate any desired 3d point to a 2d pixel representation based on the 3d point's distance from the camera.

2. Create meshes of vertices and store them in data blocks (arrays, types, memory locations ,etc.)

3. Create 2 sets of 4x4 transform matrices. 1 for world coordinates (in relation to the camera) and the other set for local transformations (the points in the meshes themselves).

4. For local transformations, use the local set of matrices to rotate, scale, or translate any or all of the points in a single mesh.

5. For global transformations, like repositioning or rotating the camera, use the global set of matrices to transform all of the vertices of all of the meshes on the 2d screen. This can mean transforming every single point, or it can mean transforming each local matrix for each mesh which in turn puts the 2d pixel on the screen in the correct place.

It gets complicated, and uses a lot of matrix multiplication. Kevin Picone put together a few examples of 3d from 2d including backface culling on his website. There are some great examples there and a lot of information.

Take a look at DB snippets

Enjoy your day.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 1st Nov 2009 03:59
Quote: "I didn't choose Maths to write essays..."

I hate essays too but you have to write them in any subject. If you can't communicate your ideas then they aren't much use to anyone else, and unfortunately that's what the education system is based on.
You're just a cog in the machine man

TGC Forum - converting error messages into sarcasm since 2002.
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 1st Nov 2009 06:06 Edited at: 1st Nov 2009 23:05
Ok, I have googled before to try and find out how the matrix calculations work but can't find a good explanation! any help?

Edit:

Got it. here are a few pages(among many) that helped me:

for the the transformations:
http://www.gamespp.com/tutorials/matrixTransformationTutorial.html

for projection to the screen(btw that's exactly what latch said )
http://en.wikipedia.org/wiki/3D_projection

Good help for the rotation and scaling aspects
http://wally.cs.iupui.edu/n351/3D/matrix.html

Gave me a good idea of what a matrix was:
http://www.euclideanspace.com/maths/algebra/matrix/index.htm


Most of these say the same thing over and over, but each one says it a little different. Some links describe things better then others.

!!WARNING!!
These pages will be useless unless you read them in there entirety, or if you already have a grasp on the matrix stuff!

New Site! Check it out \/
demons breath
20
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 12th Nov 2009 10:10
Well I've finally finished this coursework. I just wanted to thank everyone for the helpful links and suchlike. I wish I'd used them earlier (went to see Biffy Clyro last night, took me until 3AM to sober up, I've just finished at 10 past 9 after pulling an all nighter and basically starting this thing from scratch). When I get my grade for my coursework back I might stick it up on here. It's basically just a simplified version of Latch's stuff but with a very maths-orientated approach. Also, because I still don't have DarkBASIC with me it meant that I had to basically start learning DarkGDK at 7 this morning - it's similar to DB, but different enough that I make stupid mistakes, and I had a lot of difficulty getting some things to display right.

Anyway, thanks again for the help gang.

"The fools may crash down upon us in thunderous waves, but we shall Jeku slap them back from whence they came"
-BiggAdd Oct 28th 2009
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 12th Nov 2009 18:21 Edited at: 12th Nov 2009 18:40
Quote: "because I still don't have DarkBASIC with me it meant that I had to basically start learning DarkGDK at 7 this morning"


if you don't know c++ that would have been a pain :/ although c++ is better for this type of thing. with the structures/classes/types and pointers it comes in handy.

New Site! Check it out \/

Login to post a reply

Server time is: 2024-04-25 12:27:14
Your offset time is: 2024-04-25 12:27:14