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 / I have finaly done it! 3D Drawn in 2D!

Author
Message
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 30th Nov 2009 03:32 Edited at: 1st Dec 2009 00:46
This is a little project that i have been working on/am working on. It was a project to help me learn how the 3D world in DirectX works.

It uses matrices to transform the vertices. The meshes are stored in a type that has a vertex buffer which stores all the points of the mesh, and a index buffer which indexes all the points to create the polygons.

Everything is drawn using a pointer to bitmap 0 data(from the GetBitmapData Command) and then every loop is set back with the SetBitmapData command.

I got about 30-35 fps with 500 pyramids on screen. i had no noticable drop until around 400 pyramids.

use the mouse to look around and wsad to move. Space will jump(gives you a better view of all the objects)

you can input the number of objects to draw at the beginning. the exe is attached. here is a screen shot:



thats 495 pyramids and 5 boxes. all with a size of 10(the pyramids have a 10x10 base and the boxes are exact cubes) as you can see it's at 30 fps, but that's when they are all on screen.

Although this is with DarkGDK i had talked about it on this board and half the work for this was done in DarkBASIC classic and converted to DarkGDK. I figured i would post up here just to show anyone that read my old stuff about it.

Edit:

Exe now attached.

New Site! Check it out \/

Attachments

Login to view attachments
demons breath
20
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 30th Nov 2009 04:04 Edited at: 30th Nov 2009 04:06
Nice stuff man - it's further than I got (I literally had one object, one camera angle, and to put the object in you had to have all the 3d co-ordinates and draw a line between them, it was basically just the thing for converting 3D co-ordinates to 2D).

You forgot the .exe though

Ashingda 27
16
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 30th Nov 2009 04:21 Edited at: 30th Nov 2009 04:21
That's awsome, will you be posting your source codes?
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 30th Nov 2009 06:26 Edited at: 30th Nov 2009 06:47
Quote: "(I literally had one object, one camera angle, and to put the object in you had to have all the 3d co-ordinates and draw a line between them, it was basically just the thing for converting 3D co-ordinates to 2D)."


Don't feel bad, I was there for about 2 1/2 weeks. I finaly understood what i was copying and pasting(after about 3 days of constant google ) and then it all just clicked!
Quote: "
That's awsome, will you be posting your source codes? "


If you would like I can. It is in DarkGDK as stated above. So if you know c++ you can have it lol. Like i said this was a learning experience so i would love for others to learn from it. It would need some more commenting here and there for it to be released though.

Demons Breath:

Also, You also have to have the exact vertex positions in 3D space in mine. I inputed all of those positions(well i have a function that creates it. The mighty power of a for loop Lol) and the object screen x is half the work. after that you just need to understand matrices. if you have that then you have pretty much the hole thing. Beyond that it's all just how to get it up to speed.

The matrices do all the work. They will scale, move, rotate, sheer(don't know how to do that one yet), among other things.

As for the exe. It will be uploaded tomorrow morning(not at my computer now) Or you can check out my DarkGDK post. it has it attached(i checked)


All:

I do have a filled drawing method but it is VERY slow and only draws in white(unlike the other method where it will draw whatever vertex color the vector variable is set to in a gradient)

Is anyone interested in the sites that helped me with this? half of it is wiki plus sources from wiki lol

New Site! Check it out \/
demons breath
20
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 30th Nov 2009 15:34
Well I had a coursework on this sort of thing and ended up doing it between 3AM and 9:15 on the day it was due in, hence the lack of development, but as soon as they finish marking them I'll upload my work because that might also help folks looking at this - it goes through and explains the maths involved and suchlike.

Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 30th Nov 2009 15:59
Check out my code snippet for drawing AA lines, combined with cloggy's dll as someone posted, speed shouldn't be much of an issue and you'll get nicer looking shapes on screen.


> SELECT * FROM users WHERE clue > 0
> 0 rows returned
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 1st Dec 2009 00:41
Cloggy's dll? what does it do? what do you mean by "AA Lines" do you mean like manual lines?

New Site! Check it out \/
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 1st Dec 2009 00:55
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 1st Dec 2009 01:25
Oh gotcha lol

New Site! Check it out \/
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 1st Dec 2009 02:15
Cloggy's library lets you draw in 2D a lot faster from what I hear, I've never used it though.


> SELECT * FROM users WHERE clue > 0
> 0 rows returned
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 1st Dec 2009 03:47
Awesome caleb! The real meaning of awesome as in "woooaaaaaah"

I wrote a function last night for drawing opaque triangles, I'll be posting it soon so look out if you want it .

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 1st Dec 2009 03:49
That's for dbp though. this is the dbc board. I forgot i have heard of that(i think i have it actually) It is faster because it has batch operations, and it accesses DirectX directly.

New Site! Check it out \/
demons breath
20
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 1st Dec 2009 03:52
You've done it in DarkGDK though - could you not get something which works with DBP to work with DarkGDK? I thought they were pretty much the same, just with different syntax and suchlike... I may be once again showing my glaring ignorance here...

Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 1st Dec 2009 04:09
Yes this is true, that are basically the same. I believe the .h that is included into dbp plugins(globstruct.h) works with both dbp and dgdk(dgdk defines one thing and dbp defines another so globstruct and diferentiate between the two) so in theory i think you can load up the dll and use it although i am not certain.

New Site! Check it out \/
Melancholic
14
Years of Service
User Offline
Joined: 26th Nov 2009
Location:
Posted: 1st Dec 2009 21:11
@Caleb1994

if you still have all thoase sites i would be intrested, i am simply amazed that one person could manage to do this!. It's inspiring!. i probably will not be able to achieve anything of this magnitude but would love to look into how it all works!.

Your signature has been erased by a mod - Please reduce it to 600x120 maximum size
Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 5th Dec 2009 02:00
Whoa, looks cool.

(\__/) HHAHAHAHAHAH!
(O.o ) / WORLD DOMINATION!!!!!!!!!!
(> < )
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 5th Dec 2009 07:28
Melancholic:

No problem! Here are my matrix sites:

http://www.gamespp.com/tutorials/matrixTransformationTutorial.html

http://www.euclideanspace.com/maths/algebra/matrix/index.htm

http://wally.cs.iupui.edu/n351/3D/matrix.html

the rest is pretty simple. I will upload the code. note. not very well commented. If you have any questions please post on DarkGDK post. because this is the DarkBASIC post, and its in DarkGDK.

Wait my first attempt was in DarkBASIC. I will upload both sources.
the DarkBASIC one doesn't move or rotate the camera. it just deals with a wire frame object and matrix rotations.

Here is the post that got me startedd on this stuff:

http://forum.thegamecreators.com/?m=forum_view&t=159888&b=10

here's a wiki on 3D Projection:

http://en.wikipedia.org/wiki/3D_projection

i thought i had more bookmarked. i think there are some more on that other thread. If you have more questions you can ask or google it(that's what i did )

here's the dbc source:


I don't think there is a single comment in that sorry. I just pretty throughly commented my c++ source. I will post that on the darkGDK board if you want it(i don't want to put c++ stuff up here. i will get mods mad ;P lol)

That dbc isn't great stuff, but it's where kinda where i started(er well a more primitive form)

New Site! Check it out \/
Melancholic
14
Years of Service
User Offline
Joined: 26th Nov 2009
Location:
Posted: 6th Dec 2009 11:10
Thanks Caleb!, i will hopefulyl have some time free over the next week to experiment and read through all of this!
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 6th Dec 2009 23:25
@melancholic
here's another thread you might want to look at
http://forum.thegamecreators.com/?m=forum_view&t=136517&b=10
I didn't get as far as caleb but there's a lot of good info from Latch.

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 7th Dec 2009 00:43
OH thanks obese! I forgot about that one. it helped me a lot also.

New Site! Check it out \/
Melancholic
14
Years of Service
User Offline
Joined: 26th Nov 2009
Location:
Posted: 8th Dec 2009 21:25
Thanks for all the help guys, looks like attempting this is gonna take alot longer then a week. Much diffrent to the math im used to. I have something to attempt over the holiday!, whats life without a challenge ay , cant stress how much i thank you guys for all the help!.
demons breath
20
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 9th Dec 2009 00:12 Edited at: 9th Dec 2009 00:13
This might help... Did this for coursework a few weeks back... Figure it's been long enough now that they should've marked it and I won't get accused of plagiarism if it crops up on t'internet.

Attachments

Login to view attachments
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 9th Dec 2009 05:56
Wow good job demons breath! That explains things in a very good way. Of course i already understand it, but I think that if i didn't already know about it then i would be very well informed now(if that made sense )

New Site! Check it out \/
demons breath
20
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 9th Dec 2009 17:07
Thanks - it's supposed to be basic but informative and easy to understand. I'm thinking of expanding it more... Maybe making a few as a resource... I need a new keyboard first though - everything takes about 50 times as long using the on screen one...

Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 10th Dec 2009 06:11
Sounds good. If you finish it, post it up here. I would love to see it!

New Site! Check it out \/
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 11th Dec 2009 06:57
are you going to implement my triangle function in this?
Feel free to use it if it suits you.

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 11th Dec 2009 18:44
Actually i have been trying! lol it is very fast!

The only problem is, I haven't figured a way to sort the triangles before drawing them. So if one is behind another but has a lower index, it gets draw infront. Which isn't a problem unless they are different colors :/ If you have any ideas i would love you input!

New Site! Check it out \/
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 12th Dec 2009 15:27
For each object you projected, you clip/add the visible faces to the global scene list. The scene list is just a big list of all the polygons to be drawn this frame.

Once you've processed all the scene objects, we then sort the scene list (you can do this real time). Then we draw faces back to front.. aka painters. The polygons are normally sorted upon their average Z depth. AverageZ# = (FaceZ1+FaceZ2+FaceZ3)/3.0

Which how this example (and others) work: Quake MD2 Test

Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 12th Dec 2009 20:27
Oh i geuss it would be a good idea to queue the polygons before drawing them in that example it just draws each object indevidually lol

Thanks for the link!

New Site! Check it out \/
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 22nd Feb 2010 12:10
For the DBC source you posted above, you can speed things up about twice as fast by drawing everything on an offscreen bitmap and copying that to bitmap 0 :



We can even take it a step further and faster by drawing directly to the back buffer using a DLL - following the discussion in the Back Buffer thread. Since the 3d environment is being drawn from scratch, we wouldn't need to read from the back buffer at all, so one could probably up the speed even more - though the only thing DBC would be used for is the display.

Enjoy your day.
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 22nd Feb 2010 14:56
Hmmm Didn't think about that. I didn't know that drawing to an offscreen bitmap was faster at the time i did this. Good one! Another thing i could do is only use one matrix. Of course i would need a matrix multipication function those are a pain lol. I always forget what gets multiplied with what and what gets added where

Quote: "We can even take it a step further and faster by drawing directly to the back buffer using a DLL - following the discussion in the Back Buffer thread. Since the 3d environment is being drawn from scratch, we wouldn't need to read from the back buffer at all, so one could probably up the speed even more - though the only thing DBC would be used for is the display."


Ha true. That would be kind of odd, but at the same time cool. It would open up some possibilities i guess. I might revisit it if we get backbuffer drawing to work good.

New Site! Check it out \/

Login to post a reply

Server time is: 2024-04-16 12:08:50
Your offset time is: 2024-04-16 12:08:50