Page 1 of 1

### 3D Voxel Landscape

Posted: Wed Apr 02, 2008 8:27 am
Наконец таки понял фишку воксельных ландшафтов

Code: Select all

``````xsize = 320
ysize = 240
hx = xsize / 2
hy = ysize / 2
resize_pixi( 0, xsize, ysize )

map = new_pixi( 64, 64, 1 )

calc_map = new_pixi( 64, 64, 1 )

set_screen( map )
p = 0
y = 0 while( y < 64 ) {
x = 0 while( x < 64 ) {
v = (sin(x*16)*cos(y*16))/256
v / 4
map[ p ] = get_color( v, v, v )
p + 1
x + 1
}
y + 1
}

start_timer( 0 )

start:

t = get_timer( 0 ) / 8

set_screen( calc_map )
clear( BLUE )
t_reset
t_rotate_z( t, 0, 0, 0 );
pixi( map, 0, 0, 2, 0 )
t_scale( 512, 512, 512 )
print( "VOXEL LANDSCAPE", -32, -4, get_color( sin(t)/4+128, sin(t)/2, sin(t)/2 ) )
t_reset

set_screen( 0 )
clear( BLACK )
map_xsize = get_pixi_xsize( calc_map )
map_ysize = get_pixi_ysize( calc_map )
xstep = xsize / get_pixi_xsize( calc_map )
start_p = map_xsize * ( map_ysize - 1 )
x = 0 while( x < xsize )
{
p = start_p
max_v = 0
prev_v = 0
my = 0 while( my < map_ysize )
{
pixel = calc_map[ p ]
v = get_red( pixel ) + my
if v > max_v
{
c = 255 - ( v - prev_v ) * 8
fbox( x - hx, hy - v, xstep, v - max_v, get_color( c+64, c+32, c ) )
max_v = v
}
p - map_xsize
prev_v = v
my + 1
}
start_p + 1
x + xstep
}

frame( 0 )

go start``````

### Re: 3D Voxel Landscape

Posted: Wed Apr 02, 2008 10:54 am
А вот вариант с перспективой.

Code: Select all

``````xsize = 320
ysize = 240
hx = xsize / 2
hy = ysize / 2
resize_pixi( 0, xsize, ysize )

map = new_pixi( 64, 64, 1 )

calc_map = new_pixi( 64, 64, 1 )

set_screen( map )
p = 0
y = 0 while( y < 64 ) {
x = 0 while( x < 64 ) {
v = (sin(x*16)*cos(y*16))/256
v / 4
map[ p ] = get_color( v, v, v )
p + 1
x + 1
}
y + 1
}

start_timer( 0 )

start:

t = get_timer( 0 ) / 8

set_screen( calc_map )
clear( BLUE )
t_reset
t_rotate_z( t, 0, 0, 0 );
pixi( map, 0, 0, 2, 0 )
t_scale( 512, 512, 512 )
transp( 128 )
print( "VOXEL LANDSCAPE", 16-t/8, 4, get_color( sin(t)/4+128, sin(t)/2, sin(t)/2 ) )
transp( 256 )
t_reset

set_screen( 0 )
clear( BLACK )
map_xsize = get_pixi_xsize( calc_map )
map_ysize = get_pixi_ysize( calc_map )
xstep = xsize / get_pixi_xsize( calc_map )
start_p = map_xsize * ( map_ysize - 1 )
x = 0 while( x < xsize )
{
p = start_p
max_v = 0
prev_v = 0
cam_x = ( map_xsize / 2 ) * 256
cam_d = ( ( ( x / xstep ) * 256 ) - cam_x ) / map_ysize
my = 0 while( my < map_ysize )
{
pixel = calc_map[ p + ( cam_x / 256 ) ]
v = ( ( get_red( pixel ) + my ) * ( 128-my ) ) / 64
if v > max_v
{
c = 255 - my*4
//c = 255 - ( v - prev_v ) * 8
fbox( x - hx, hy - v, xstep, v - max_v, get_color( c+64, c+32, c ) )
max_v = v
}
p - map_xsize
cam_x + cam_d
prev_v = v
my + 1
}
x + xstep
}

frame( 0 )

go start``````

### Re: 3D Voxel Landscape

Posted: Wed Apr 02, 2008 11:55 am
Мощная штука! 3d без 3d... В коде бы разобраться еще )

### Re: 3D Voxel Landscape

Posted: Wed Apr 02, 2008 12:41 pm
:)
А вот более корректная перспектива.
Попробую сделать человеческий пример с координатами камеры.. Это ж можно будет всякие 3D леталки делать!

Code: Select all

``````xsize = 320
ysize = 240
hx = xsize / 2
hy = ysize / 2
resize_pixi( 0, xsize, ysize )

map = new_pixi( 64, 64, 1 )

calc_map = new_pixi( 64, 64, 1 )

set_screen( map )
p = 0
y = 0 while( y < 64 ) {
x = 0 while( x < 64 ) {
v = (sin(x*16)*cos(y*16))/256
v / 1
map[ p ] = get_color( v, v, v )
p + 1
x + 1
}
y + 1
}

start_timer( 0 )

start:

t = get_timer( 0 ) / 8

set_screen( calc_map )
clear( BLUE )
t_reset
t_rotate_z( t, 0, 0, 0 );
pixi( map, 0, 0, 2, 0 )
t_scale( 512, 512, 512 )
transp( 128 )
print( "VOXEL LANDSCAPE", 16-t/8, 4, get_color( sin(t)/4+128, sin(t)/2, sin(t)/2 ) )
transp( 256 )
t_reset

set_screen( 0 )
clear( BLACK )
map_xsize = get_pixi_xsize( calc_map )
map_ysize = get_pixi_ysize( calc_map )
xstep = xsize / get_pixi_xsize( calc_map )
start_p = map_xsize * ( map_ysize - 1 )
x = 0 while( x < xsize )
{
p = start_p
max_v = -1000
prev_v = -1000
cam_x = ( map_xsize / 2 ) * 256
cam_d = ( ( ( x / xstep ) * 256 ) - cam_x ) / map_ysize
my = 0 while( my < map_ysize )
{
pixel = calc_map[ p + ( cam_x / 256 ) ]
if my = 0 { my = 1 }
v = ( (get_red( pixel )/2-64) * ( (64*64)/my ) ) / 64
if v > max_v
{
c = 255 - my*4
//c = 255 - ( v - prev_v ) * 8
fbox( x - hx, -v, xstep, v - max_v, get_color( c+64, c+32, c ) )
max_v = v
}
p - map_xsize
cam_x + cam_d
prev_v = v
my + 1
}
x + xstep
}

frame( 0 )

go start``````

### Re: 3D Voxel Landscape

Posted: Wed Apr 02, 2008 12:43 pm
дум пора делать или вертолетный полет

### Re: 3D Voxel Landscape

Posted: Sat Apr 05, 2008 7:20 am
:mrgreen:

Excellent work Nightradio, it is awesome. Really very very good. I trying understand the code but, it is really complex to my.

I wanna see many works in a Compo64, I am a Fanatic SceneViewer!

Very interesting see

Code: Select all

``````.o...ooo...o.
..o..o.o..o..
...ooo.ooo...
...ooooooo...
.ooooooooooo.
.o.ooooooo.o.
oo.........oo``````
in 3d :mrgreen:

Bye

P.D. Sorry for the language, probably in a few months I can write a little russian phrases , this language is very interesting, but I need more study.

### Re: 3D Voxel Landscape

Posted: Sun Apr 06, 2008 7:02 pm
thanks :))