PDA

View Full Version : This is some amazing assembly coding



kryton9
05-07-2007, 04:18
Here is an incredibly small interactive 3d terrain. He has gravity and collisions working. Just use the arrow keys to move. This was Written by Steven H Don.

The voxel system is written in C, but still very small. This has colored terrain.

The voxel2 is written in assembly and needs no additional files to run. I would recommend trying that first to see how amazing.

In both use the arrow keys to move around, escape to exit.

matthew
05-07-2007, 19:12
Here is a Routine in thinBASIC that creates a Sphere which looks like it's made from Voxels.

It's a conversion of an old Basic4GL Programme.

You can move the Sphere around using the Cursor Keys and Zoom In and Out using PgUp and PgDn.

Update
This is the New Updated Version 8)



' Voxel Sphere

uses "UI" ' MessageBox Functions
uses "TBGL" ' thinBASIC OpenGL Library
uses "MATH" ' DegToRad Function

#INCLUDE "%APP_INCLUDEPATH%\thinbasic_gl.inc" ' glColor3f

' Create MessageBox
dim chooseDisplay as long
chooseDisplay = msgbox(0, "Would you like to Run in Fullscreen Mode?", %MB_YESNO or %MB_ICONINFORMATION, "Start FullScreen?")

DIM screenResWidth, screenResHeight, screenDepth AS LONG
tbgl_GetDesktopInfo screenResWidth, screenResHeight, screenDepth

dim hWnd as dword

select case chooseDisplay

' Create FullScreen Display, Return Handle.
case %IDYES
hWnd = tbgl_createwindowex("", screenResWidth, screenResHeight, screenDepth, 1)

' Create Windowed Display, Return Handle.
case %IDNO
hWnd = tbgl_createwindowex("Voxel Sphere - Press 'Esc' to Quit", 640, 480, screenDepth, 0)

end select

' Declare Variables here
dim w as single
dim x, y, z as integer
dim scene, cubeSize as integer
dim distance as single
dim angle(2) as single

' Initialize Variables here
distance = 80
cubeSize = 20

'Create Lists here
%CUBE = 1
%SCENE = 2

tbgl_newlist %CUBE
buildCube()
tbgl_endlist

tbgl_newlist %SCENE
createScene()
tbgl_endlist

tbgl_showwindow ' Show Display

TBGL_GetAsyncKeyState(-1) ' Reset all Keys

' Start Main Loop
while tbgl_iswindow(hWnd)

tbgl_clearframe ' Clear Display
tbgl_camera 0,0,1,0,0,0 ' Default Camera, View From 0,0,1 To 0,0,0.

tbgl_translate 0.0, 0.0, -distance
tbgl_rotate angle(1), 1.0, 0.0, 0.0
tbgl_rotate angle(2), 0.0, 1.0, 0.0

tbgl_CallList %SCENE
keyboardControl()

tbgl_drawframe ' Display anything

if tbgl_getasynckeystate(%VK_ESCAPE) then exit while

wend

tbgl_destroywindow ' Closes Display

function buildCube() as long

tbgl_beginpoly %GL_QUADS
tbgl_vertex 0.0, 0.0, 0.0
tbgl_vertex 1.0, 0.0, 0.0
tbgl_vertex 1.0, 1.0 ,0.0
tbgl_vertex 0.0, 1.0 ,0.0

tbgl_vertex 0.0, 0.0, 1.0
tbgl_vertex 1.0, 0.0, 1.0
tbgl_vertex 1.0, 1.0, 1.0
tbgl_vertex 0.0, 1.0, 1.0

tbgl_vertex 0.0, 0.0, 0.0
tbgl_vertex 1.0, 0.0, 0.0
tbgl_vertex 1.0, 0.0, 1.0
tbgl_vertex 0.0, 0.0, 1.0

tbgl_vertex 0.0, 1.0, 0.0
tbgl_vertex 1.0, 1.0, 0.0
tbgl_vertex 1.0, 1.0, 1.0
tbgl_vertex 0.0, 1.0, 1.0

tbgl_vertex 0.0, 0.0, 0.0
tbgl_vertex 0.0, 1.0, 0.0
tbgl_vertex 0.0, 1.0, 1.0
tbgl_vertex 0.0, 0.0, 1.0

tbgl_vertex 1.0, 0.0, 0.0
tbgl_vertex 1.0, 1.0, 0.0
tbgl_vertex 1.0, 1.0, 1.0
tbgl_vertex 1.0, 0.0, 1.0
tbgl_endpoly

end function

function createScene() as long

for z = -cubeSize to cubeSize
for y = -cubeSize to cubeSize
for x = -cubeSize to cubeSize

w = sqr(x*x + y*y + z*z)

if w < 20 and w > 18.75 then
tbgl_pushmatrix
tbgl_translate x, y, z
glcolor3f cos(degtorad(x*7)), cos(degtorad(y*7)), cos(degtorad(z*7))
tbgl_CallList %CUBE
tbgl_popmatrix
endif

next
next
next

end function

function keyboardControl() as long

if tbgl_getasynckeystate(%VK_RIGHT) then angle(2) += 1
if tbgl_getasynckeystate(%VK_LEFT) then angle(2) -= 1
if tbgl_getasynckeystate(%VK_UP) then angle(1) -= 1
if tbgl_getasynckeystate(%VK_DOWN) then angle(1) += 1

if tbgl_getasynckeystate(%VK_PGDN) then distance += 1
if tbgl_getasynckeystate(%VK_PGUP) then distance -= 1

end function

Petr Schreiber
05-07-2007, 19:57
Hi,

matthew nice program ! Really voxelish :)

Just change:


createScene()


in main loop with:


tbgl_CallList %SCENE


You probably just forgot as the list was ready.

I cannot run krytons samples, any ideas why ?


Bye,
Petr

matthew
05-07-2007, 20:57
Thank's for the tip. ;)

Krytons samples work on my computer, it's strange that they don't work on yours.

I've found a version of the Voxel Landscape Programme written in Pascal. I've uploaded it, maybe that will work on your computer.

Petr Schreiber
05-07-2007, 21:03
Thanks matthew,

this works :)
Reminds me of "Delta Force" ( or some simialr name ). It had also voxel terrain and it didn't look bad at all.

krytons samples just start and immediately finish ( just black screen ), will try on other PC.

Bye,
Petr

kryton9
05-07-2007, 21:05
@Petr, sorry the examples didn't work for you. Maybe Matthew's version will work better.

@Matthew, cool program. Thanks for posting it. THat will be useful code for use in the future as some stuff to study in there for sure.
Thanks again.

Michael Hartlef
05-07-2007, 21:48
Cool,

nice job guys!

ErosOlmi
05-07-2007, 22:10
matthew,

first, thanks a lot for this nice example, really !
Second, a lilttle change at initial part of the code to get screen resolution and color depth.

Ciao
Eros



' Create MessageBox
dim fullScreen as long
fullScreen = msgbox(0, "Would you like to Run in Fullscreen Mode?", %MB_YESNO or %MB_ICONINFORMATION, "Start FullScreen?")

DIM ScreenResWidth, ScreenResHeight, ScreenDepth AS LONG
tbgl_GetDesktopInfo ScreenResWidth, ScreenResHeight, ScreenDepth

dim hWnd as dword

select case fullScreen

' Create FullScreen Display, Return Handle.
case %IDYES
hWnd = tbgl_createwindowex("", ScreenResWidth, ScreenResHeight, ScreenDepth, 1)

' Create Windowed Display, Return Handle.
case %IDNO
hWnd = tbgl_createwindowex("Voxel Sphere - Press 'Esc' to Quit", 640, 480, ScreenDepth, 0)

end select

matthew
05-07-2007, 22:16
^^
Thank's for the advice, I'll update the Code. :)