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 Professional Discussion / Volume of objects from vertexdata (not accurate)

Author
Message
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Jul 2010 18:10 Edited at: 14th Jul 2010 18:41
I'm trying to get the volume of a number of odd shaped objects using the following function:


Now I'm not looking to be accurate I just want the maximum bounds of the objects (1 to 7). This doesn't seem to be quite working right as when I get all seven objects withing a 3x3x3 cube I am sometimes getting results near 12 cubic units where I would expect 9 (3x3x3)...

Has anyone got any ideas why (I know it's not a working version but if I don't get an answer soon I'll upload a full example)? Or a better way to do it?

Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 14th Jul 2010 18:21
3x3x3=27
I'm not sure what you are asking..... or what purpose you would need to know that info.

The fastest code is the code never written.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Jul 2010 18:31 Edited at: 14th Jul 2010 18:33
Sorry, I was doing this in 2D first and got my numbers mixed up...

What I am trying to do is a simple test to check that all the vertices of an object are within a 3x3x3 cube.

Edit: It's a check for whether a Soma Cube is complete.



Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 14th Jul 2010 18:40
Then you don't need a volume, you only need to calculate the center and test each vertex is within 1.5 of it along the 3 axis.

The fastest code is the code never written.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 15th Jul 2010 10:31 Edited at: 15th Jul 2010 14:12
Quote: "Then you don't need a volume, you only need to calculate the center and test each vertex is within 1.5 of it along the 3 axis."

Good idea, that's definitely more efficient but there seems to be a problem with it somewhere else. I'll upload a sample program ASAP.

EDIT: Nevermind, turns out my objects had an extra vertex because of the way they were made... for those of you interested here's the code I'm using:


If objects 1-7 are within a cube 3.2 x 3.2 x 3.2 based aroung their centre it will return a 1 otherwise a zero. I guess this could be adapted for other similar uses...

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 16th Jul 2010 01:15
You could just make a 3x3x3 array of booleans. Set them all to 0, and then set each occupied cell (one with a cube in it) to 1. If every item in the array is 1 then it is complete.

[b]
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 16th Jul 2010 11:24
Quote: "You could just make a 3x3x3 array of booleans. Set them all to 0, and then set each occupied cell (one with a cube in it) to 1. If every item in the array is 1 then it is complete."

Thanks Diggsey. I have this working now, it's quite forgiving on accuracy (positioning of the blocks) and not too hungry on the fps so it's in for now.

It turned out that another major factor was that I was using EZ-Rotate which does some weird things during rotation (vectors were not where they were drawn and stuff) so I'm using some global rotation code I found after a short search of the forums! Now everything's sweet and nearly ready for release. Just need to finish some music and tweek the UI, oh and some optional backgrounds and stuff...

It'll be a free game based on "Soma Cubes", name to be decided as yet.

Login to post a reply

Server time is: 2026-07-25 04:54:46
Your offset time is: 2026-07-25 04:54:46