PDA

View Full Version : checkerboard floor - formula???



Lionheart008
03-12-2008, 16:54
dear thinbasic friends... dear petr, hi all :)

short question: I would like to create a simple tbgl entity checkerboard floor (german: Schabrettboden) and ask myself if there is any formula for the entity or copy or translate function to build 64 boxes ... uff... otherwise I can make all the position by hand :D


' -- Create something to look at
TBGL_EntityCreateBox(%sScene, %eBox, 0, 1.25, 0.25, 1.5, 1, 55, 55, 55)
TBGL_EntitySetPos(%sScene, %eBox, 2, 1, 1)
TBGL_EntityCreateBox(%sScene, %eBox1, 0, 1.25, 0.25, 1.5, 1, 255, 255, 55)
TBGL_EntitySetPos(%sScene, %eBox1, 2, 1, -0.6)
TBGL_EntityCreateBox(%sScene, %eBox2, 0, 1.25, 0.25, 1.5, 1, 255, 5, 5)
TBGL_EntitySetPos(%sScene, %eBox2, 0.6, 1, 1)
TBGL_EntityCreateBox(%sScene, %eBox3, 0, 1.25, 0.25, 1.5, 1, 25, 55, 255)
TBGL_EntitySetPos(%sScene, %eBox3, 0.6, 1, -0.6)
TBGL_EntityCreateBox(%sScene, %eBox4, 0, 1.25, 0.25, 1.5, 1, 255, 55, 55)
TBGL_EntitySetPos(%sScene, %eBox4, -0.8, 1, -0.6)
TBGL_EntityCreateBox(%sScene, %eBox5, 0, 1.25, 0.25, 1.5, 1, 255, 255, 255)
TBGL_EntitySetPos(%sScene, %eBox5, -0.8, 1, 1)
TBGL_EntityCreateBox(%sScene, %eBox6, 0, 1.25, 0.25, 1.5, 1, 80, 25, 255)
TBGL_EntitySetPos(%sScene, %eBox6, -0.75, 1, -2.25)
TBGL_EntityCreateBox(%sScene, %eBox7, 0, 1.25, 0.25, 1.5, 1, 255, 0, 255)
TBGL_EntitySetPos(%sScene, %eBox7, 0.6, 1, -2.25)
TBGL_EntityCreateBox(%sScene, %eBox8, 0, 1.25, 0.25, 1.5, 1, 255, 250, 255)
TBGL_EntitySetPos(%sScene, %eBox8, 2, 1, -2.25)

hmh... I can make it, but perhaps somebody has done it before me??? :)

best regards, Lionheart

Petr Schreiber
03-12-2008, 18:29
Hi Frank,

thinbasic has loops, so why not take advantage of it.

64 tiles = 8 x 8 tiles.

So position X varies from 1 to 8, position Z varies from 1 to 8

Loop like this will do it for you:


' -- Create grid of tiles
dim row, column, id as long

id = %eBoxFirst
for row = 1 to 8
for column = 1 to 8
TBGL_EntityCreateBox(%sScene, id, 0, 0.75, 0.25, 0.75, 1, 192, 192, 192)
TBGL_EntitySetPos(%sScene, id, row, 1, column)

incr id
next
next


Bye,
Petr

Lionheart008
03-12-2008, 21:30
hi petr, it works :) very well done... great! it's the easiest way to build such checkerboard without loosing much time ;)

- only one thing... when I am rotating the boxes with this code only the first box of the checkerboard rotates, not the whole object... when I am splitting the rows and columns (1-4) and (5-8) the same effect, I cannot rotate the whole checkerboard... or the boxes seperately, why...??? I will try it again...


id = %eBoxFirst
for row = 1 to 8
for column = 1 to 8
TBGL_EntityCreateBox(%sScene, id, 0, 0.75, 0.25, 0.75, 1, 0, 50, 255)
TBGL_EntitySetPos(%sScene, id, row, 1, column)
TBGL_EntitySetRot(%sScene, %eBoxFirst, GetTickCount/20, 60, 20)

best regards, Lionheart

Petr Schreiber
03-12-2008, 22:36
Hi Frank,

that's the way it is designed.
If you want to make cubes linked together, use for all of them one pivot or parent entity.

Parent entity is the 3rd parameter used during entity creation, no parent = 0, else you can pass there ... well, parent entity ID :).

With such a setup, you turn pivot, and it will turn all objects attached.


Petr