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 / making an object from a memblock

Author
Message
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 15th Jan 2010 21:24
I've been playing around with memblocks and meshes recently and finally understood enough to make a mesh directly from a memblock.

What I've managed to do is create a function that creates a box (I've just realised how unimpressive that sounds), where the object number, width, height and length can be specified.



The box can be textured with a single image but each face takes a different portion of the image so that each side of the box can be textured differently.

The UV values have been set up so that it "splits" the image into six areas, 2 rows and 3 columns. I'll let you work out which areas texture which side as I can't quite work out how to put an image in this post (I'm kinda new here and am learning how all this works . Hold on, I'll tell you what, I'll do it as an attachment).

To make the box, four vertices have been used to create each side so that values for the normals and UV coordinates can be assigned to each side

I'm using the term side to mean: front, back, left, right, top and bottom.

I've used fixed values for the normals, rather than calculating them form the vertex data, which is fine for faces that are parallel to the x,y,z axis/plains.

From here, it's a faily simple step to make tapered or skewed boxes (possibly even twisted boxes), at which point calculating the normals would be more preferable.

Once the box has been created it can then treated like any other object.

Attachments

Login to view attachments
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 15th Jan 2010 22:37 Edited at: 15th Jan 2010 22:44
Hey, pretty good. I was eyeballing your code a bit (I haven't run it yet) and noticed you're hard-coding pretty much everything. If we assume that the center of the box is 0,0,0 upon creation, and we know the width, height, and depth, we could create a loop that assigns the values of the vertices (just talking about the verts for now) that is just a calculation of +- 1/2 of the dimensions.

For example:


This code takes 1/2 the width, height, and depth , looks up the +- relationship of the particular vertex from the data table in relation to the center 0,0,0 , then calculates and assigns each vertex. I don't know what the speed difference is, but the consolidation of the code makes it a little easier to see what's going on at a glance. My vert/face order is probably different than yours so you'd have to assign the proper values to the data statements. Each data line represents 1 face.

I would also recommend using variables for the header position/size definitions that you can later use in the function; though your brute force method is a bit faster than making assignments or using loops. You'll just make the code more adaptable and easier to understand if yourself or someone else picks up where you left off.

Enjoy your day.
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 16th Jan 2010 21:17
Thanks for the tip, Latch. I knew there must be a way to make things easier but it never occured to me use data blocks to store all the values in. I'm not really much of a coder so sometimes brute force is all I've got

I've rewritten the code and it works really well and is much easier to play around with all the values.



It's been interesting getting to grips with memblocks and meshes. I'm quite a fan of maths collision and being able to make shapes in DBC makes this easier. Hopfully I'll be able to do some more interesting stuff now.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 17th Jan 2010 20:01
Good stuff 29,
Have you entered the DBC challenges before?

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 17th Jan 2010 23:14
No I haven't entered any of the DBC challenges. I'm not that good with deadlines when it comes to programing (or any of my other hobbies come to think of it).

I might have a go at the current one, it sort of fits with what I'm playing around with at the moment.
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 6th May 2010 22:13
I've been playing around with memblocks and meshes again and have come up with these.





The code uses a combination of making meshes from memblock and then simply adding limbs to make the final model.


Car




Aeroplane / spaceship




Tank




I'll admit now that I've gone back to a brute force method to write all the vertex values to the memblock as I was getting bored with trying to make it more elegant.

I currently drawing a texture for the aeroplane and will post an image when I'm done.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 6th May 2010 23:27
Quote: "I'll admit now that I've gone back to a brute force method to write all the vertex values "

Nippping any comments in the bud I see!

Brute force works!

Nice stuff.

Enjoy your day.
Link102
19
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 6th May 2010 23:56
try making a one sided matrix

Login to post a reply

Server time is: 2024-04-28 11:52:59
Your offset time is: 2024-04-28 11:52:59