How to make 1000 Cubes ?

Blitz3D Forums/Blitz3D Beginners Area/How to make 1000 Cubes ?

ChaseHatesEggs(Posted 2015) [#1]
In a Problem I have to make 1000 Cubes inside a sphere and have them explode out the only issue I have is making 1000 Cubes.Help?


stayne(Posted 2015) [#2]
For i = 1 to 1000
cube = CreateCube()
PositionEntity cube,x,y,z
Next

Someone smarter than me can elaborate on the positioning.


Guy Fawkes(Posted 2015) [#3]



Floyd(Posted 2015) [#4]
The answer depends on the details of the problem.

Size and position of the sphere, size restrictions on cubes, can cubes overlap...

In any case we shouldn't be doing your school work.


RemiD(Posted 2015) [#5]
@Guy Fawkes>>Some observations about your code :

-the variables "max_cubes" does not need to be a global

-you can rotate an entity from -180.0 to 180.0 not from -359.0 to 359.0

-updateworld() is useless in your code

-your indentation does not make sense, it should look more like this :

Do what you want with these advices...



@ChaseHatesEggs>>
you can use tformpoint() and rnd(min,max) to randomly position a cube inside a sphere.
or
randomly position the cube between rnd(minX,maxX),rnd(minY,maxY),rnd(minZ,maxZ), then check if the cube is inside the sphere with a distance check, if yes good, if no reposition this cube


stayne(Posted 2015) [#6]
I was wondering why he put all 1000 of them at 1.001 on the Y axis.

Anyway - I just tossed OP a bone to get him started.


Matty(Posted 2015) [#7]
Now....do you have to also arrange the cubes in a spherical arrangement with no overlaps?

There are a number of methods of doing this......


KronosUK(Posted 2015) [#8]
Was feeling bored so threw this together




Guy Fawkes(Posted 2015) [#9]
@RemiD: You can correct everything else, but do NOT tell ME how to space and / or tab my OWN CODE! You have absolutely NO right to do so! And if you do it again or smart off to me, I'm GOING to report it!


LineOf7s(Posted 2015) [#10]
..to the Indent Police? The Tab League? The Spacing Institute?


stayne(Posted 2015) [#11]
His little all caps stuff is cute. I still think it's Puki.


RemiD(Posted 2015) [#12]
I would use a goto Line to prevent different cubes from overlapping :
.LineChooseCubePosition
;position the cube
;check if the cube is far enough from others cubes
;if yes
 ;good
;if no
 ;goto LineChooseCubePosition


but if you use this technique, be sure to not create too many cubes compared to the size of the empty space or it will be an endless loop !


Matty(Posted 2015) [#13]
RemiD - if I knew how many cubes I had, their initial size, the size I wanted to fit them in....I'd simply calculate their correct position with a bit of mathematics and place them....no need to enter a potentially endless loop!


RemiD(Posted 2015) [#14]
If you know the size of each cube and the size of the empty space, you can have an idea of approximately how many cubes you can fit in it so there will be no endless loop.
I often use this technique to position things randomly in a scene and there is no problem if you always underestimate the number of things that you can fit in a scene depending on the size of the thing and the size of the scene.
But i agree that this is not the best way.


ChaseHatesEggs(Posted 2015) [#15]
Thanks All!
@Floyd The problem is more than just making the cubes I just didn't know how to go about it, thanks anyway.