PDA

View Full Version : thinBasic newbee



scidog
04-04-2008, 19:09
Hello,

I stumbled across thinBasic and immediately downloaded it.

I have just looked at the samples, and I have one question: Where is the best place to start?

John

Petr Schreiber
04-04-2008, 19:15
Hi Scidog,

welcome to the thinBASIC world :) !

To answer your question properly, maybe it would be good to tell us for what purpose do you want to use thinBASIC, then we can "navigate" you better.


Thanks,
Petr

Michael Clease
04-04-2008, 20:39
Hello John

I would start by looking at the sample scripts and then ask any questions from there.

thanks
Mike

ErosOlmi
04-04-2008, 21:18
Ciao John.

First, please be sure to download latest preview version of thinBasic. It contains a lot of changes and fixes.

As said, you can start from the many script examples and looking around if you feel comfortable with thinBasic language.
There are many very simple scripts under \thinBasic\SampleScripts\General\ directory that will let you introduce with the language. Than there are many scripts specific to thinBasic module (thinBasic language extensions wotking on specific programming areas) in other directory \thinBasic\SampleScripts\ Just open them from thinAir and press F5 to run them.

When installing thinBasic you have a full thinBasic .CHM help file integrated with thinAir (thinBasic IDE).
But you can also looking an offline version of html help downloadable from thinBasic download area: http://www.thinbasic.com/index.php?option=com_docman&task=cat_view&gid=21&Itemid=66

Or you can ask here about specific areas of interest.

Let us know.
Ciao
Eros

Michael Hartlef
04-04-2008, 21:44
Hi John and welcome big time.

You will see that this is one of the best communities you can find in the net. What is your background programming wise?

Cheers
Michael

matthew
05-04-2008, 08:26
Hi John 8)

scidog
09-04-2008, 04:38
Hello,

Thanks for all the replies. I figured I would study some before asking questions.

I am assuming that I am either blind, stupid, or there is neither a "Reply" nor "Reply To All" anywhere on the any of the Forum's screens. I hope this message is replied to all.I gave it my best shot.

I have noticed that the standard camera in the TGBL (which is very cool and excellent work man) is always such that one sits flat on one plane with one's head pointing toward +Y.At least I think it's +Y.

Did I get that right?

I glanced at the "entity systems" about cameras and I'm just not there yet. Later yes, but for now does anyone have a camera with the ability to be flown in-program via looped variable equations or read from a preexisting text file? I am not talking so much about joystick input. For right now I'm just looking to move a camera about high-resolution 3D graphs in a controllable manner. Variable focus and zoom would rock.

I want to fly through old text book graph equations; that kind of thing.


Next step after that is a second time element put in to change equation parameters while moving the camera about.

I figured that the completion of my little plan above could set me on my way to joystick input.

So, if anyone could tell me the terms and buzzwords to look for I will read those sections.

Oh, and last here is mashed up tutorial file that rotates a camera circularly in the XY plane I think. It is though I am standing on a platform that always remains horizontal, yes?

For what it's worth; thinBasic is great and I have told people so.

Thanks,

John

'=========
'=========
'
' WORK BAX Lesson #3 from thinBASIC TBGL tutorials
' "Various types of polygons"
'
' made by mashing Petr Schreiber's file
'
' Downloaded from http://psch.thinbasic.com/
'


Uses "TBGL"
Uses "UI"

DIM hWnd as dword
dim i as long
dim PolyMode as integer = %GL_POINTS
dim PolyNames as string = "%GL_POINTS,%GL_LINES,%GL_LINE_LOOP,%GL_LINE_STRIP,%GL_TRIANGLES,%GL_TRIANGLE_STRIP,%GL_TRIANGLE_FAN,%GL_QUADS,%GL_QUAD_STRIP,%GL_POLYGON"


DIM TESTcounter AS DOUBLE
DIM TEST_INC AS DOUBLE
DIM PIE AS DOUBLE
DIM CAMDIST AS DOUBLE



TESTcounter = 0.0
TEST_INC = 0.00010
PIE = 3.141618
CAMDIST = 3.5

'MsgBox (0, "You should see black screen with points soon"+$LF+$LF+"Try to push SPACE to watch various types of polygons"+$LF+$LF+"Press ESCAPE to quit", %MB_ICONINFORMATION, "BAX Lesson 3")

' We will initialize OpenGL and internal buffers
' Function also returns window handle
hWnd = tbgl_CreateWindow

tbgl_ShowWindow ' This will display the window on the screen

' FUNCTION DECLARATION This will set caption of the window
function UpdateWindowTitle() as long
Win_SetTitle (hWnd, "BAX Lesson 3 - Polygon style : "&PARSE$( PolyNames , ",",PolyMode+1-%GL_POINTS)&" - press SPACE to change style, ESC to quit")
end function

UpdateWindowTitle

GetAsyncKeyState(%VK_ESCAPE) ' Reset status of the ESCAPE to prevent immediate quit
GetAsyncKeyState(%VK_SPACE)

tbgl_PointSize 1 ' This will set the default point size to 3 pixels
tbgl_LineWidth 1 ' This will set the default line width to 3 pixels

while IsWindow(hWnd) ' While window exists, we will draw and check for ESCAPE

tbgl_ClearFrame ' This clears the frame and prepares it for drawing

tbgl_Camera CAMDIST*cos(TESTcounter*(180/PIE)),CAMDIST*sin(TESTcounter*(180/PIE)),(2*CAMDIST),0,0,2 ' We will look from point 5,5,5 to 0,0,0 ( origin of coordinates ) NOTE:SEEMS THAT WHERE ONE PUTS THIS LINE AFFECTS THE CAMERA.
'I THINK IT'S SUPPOSSED TO BE RIGHT AFTER "tbgl_ClearFrame". This seems to work all the time as far as I can tell...

tbgl_BeginPoly PolyMode ' Here begins definition of selected polygon type, we will use 12 vertexes
for i = 0 to 5 'EX: 0 TO 5 MAKES 6 SETS FOR TOTAL OF 12 VERTICES. HERE Z VALUES GOES 0 TO +5, THUS Z ORDINATES PROGRESS TOWARD THE SCREEN; AS IT SHOULD IN RHS OF COORDINATES.

tbgl_Color sin(i)*255,sin(i+1)*255,sin(i+2)*255 'makes each set f 3 verties a different color

tbgl_Vertex -1,0,i
tbgl_Vertex 1,0,i
tbgl_Vertex 0,1,i

next
tbgl_EndPoly ' We must end the definition

tbgl_DrawFrame ' This will display the scene

TESTcounter=TESTcounter+TEST_INC


'OK, THE ABOVE LOOP CHUGS ALONG UNTIL YOU HAVE ONE F THE BELOW IF STATEMENTS VALIDATED (MADE TRUE), AS IN BY HITTING THE "ESC" BUTTON OR THE SPACE BAR (in this example)


' When ESCAPE is pressed, we will leave the main loop
IF GetAsyncKeyState(%VK_ESCAPE) THEN EXIT while

' When SPACE is pressed, we will set next polygon mode
IF GetAsyncKeyState(%VK_SPACE) THEN
sleep 100 '<== just a sleazy trick to make sure that a human can tap a key and not have the computer tink it's been hit a zillion times during said key tap
if PolyMode < %GL_POLYGON then ' " " is the last one in the list designated by "dim PolyNames as string" seen near top of this program
incr PolyMode
else
PolyMode = %GL_POINTS
end if
UpdateWindowTitle
end if

Wend

tbgl_DestroyWindow ' This will destroy the window

'=========
'=========

Michael Clease
09-04-2008, 09:03
Very interesting demo

only one problem the GL_Quads are being clipped change CAMDIST = 3.5 to 4.5 and its ok.

Petr Schreiber
09-04-2008, 09:12
Hi scidog!,

very nice version, I did not know someone bothers with my old tutorials, so you made me happy :)

The TBGL_CAMERA has an up-vector of [0, 1, 0], so as long as:
target y = camera y

...the camera remains "horizontal" as you say.

Entity camera is much more freestyle :)

Regarding your special version of tutorial - thanks for sharing! I have to rework the tutorials as TBGL has evolved, so here is more fresh version of your version :) I marked the new parts with [ ! ].

What changed ? ( but backward compatiblity still works ):

TBGL_CreateWindowEx is more flexible way to create window, please use it
UI module is not required for checking of TBGL window existence, keyboard input or setting windows title
TBGL_GetWindowKeyOnce eliminates need for SLEEP 100 to prevent repeated presses.




' WORK BAX Lesson #3 from thinBASIC TBGL tutorials
' "Various types of polygons"
'
' made by mashing Petr Schreiber's file
'
' Downloaded from http://psch.thinbasic.com/
'

Uses "TBGL"

DIM hWnd as dword
dim i as long
dim PolyMode as integer = %GL_POINTS
dim PolyNames as string = "%GL_POINTS,%GL_LINES,%GL_LINE_LOOP,%GL_LINE_STRIP,%GL_TRIANGLES,%GL_TRIANGLE_STRIP,%GL_TRIANGLE_FAN,%GL_QUADS,%GL_QUAD_STRIP,%GL_POLYGON"

DIM TESTcounter AS DOUBLE = 0.0
DIM TEST_INC AS DOUBLE = 0.00010
DIM PIE AS DOUBLE = M_PI
DIM CAMDIST AS DOUBLE = 4.5

' We will initialize OpenGL and internal buffers
' Function also returns window handle

' [!] - CreateWindowEx is the best way to create window now
hWnd = tbgl_CreateWindowEx("", 640, 480, 32, %TBGL_WS_WINDOWED or %TBGL_WS_MAXIMIZEBOX or %TBGL_WS_MINIMIZEBOX or %TBGL_WS_CLOSEBOX)
tbgl_ShowWindow ' This will display the window on the screen

UpdateWindowTitle

' [!] - To reset all keys, just pass -1
TBGL_GetAsyncKeyState(-1) ' Reset status of the ALL keys to prevent immediate quit

tbgl_PointSize 1 ' This will set the default point size to 3 pixels
tbgl_LineWidth 1 ' This will set the default line width to 3 pixels

' [!] No need for UI module IsWindow, TBGL has its own
while TBGL_IsWindow(hWnd) ' While window exists, we will draw and check for ESCAPE

tbgl_ClearFrame ' This clears the frame and prepares it for drawing

tbgl_Camera CAMDIST*cos(TESTcounter*(180/PIE)),CAMDIST*sin(TESTcounter*(180/PIE)),(2*CAMDIST),0,0,2 ' NOTE:SEEMS THAT WHERE ONE PUTS THIS LINE AFFECTS THE CAMERA.
'I THINK IT'S SUPPOSSED TO BE RIGHT AFTER "tbgl_ClearFrame". This seems to work all the time as far as I can tell...

tbgl_BeginPoly PolyMode ' Here begins definition of selected polygon type, we will use 12 vertexes
for i = 0 to 5 'EX: 0 TO 5 MAKES 6 SETS FOR TOTAL OF [!] 18 VERTICES. HERE Z VALUES GOES 0 TO +5, THUS Z ORDINATES PROGRESS TOWARD THE SCREEN; AS IT SHOULD IN RHS OF COORDINATES.

tbgl_Color sin(i)*255,sin(i+1)*255,sin(i+2)*255 'makes each set f 3 verties a different color

tbgl_Vertex -1,0,i
tbgl_Vertex 1,0,i
tbgl_Vertex 0,1,i

next
tbgl_EndPoly ' We must end the definition

tbgl_DrawFrame ' This will display the scene

TESTcounter += TEST_INC ' [!] The same as TESTcounter = TESTcounter + TEST_INC, but faster

'OK, THE ABOVE LOOP CHUGS ALONG UNTIL YOU HAVE ONE F THE BELOW IF STATEMENTS VALIDATED (MADE TRUE), AS IN BY HITTING THE "ESC" BUTTON OR THE SPACE BAR (in this example)


' When ESCAPE is pressed, we will leave the main loop
' [!] TBGL_GetWindowKeyState reacts only when TBGL window is active
IF TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE) THEN EXIT while

' When SPACE is pressed, we will set next polygon mode
' [!] "Once" eliminates need for SLEEP 100
IF TBGL_GetWindowKeyONCE( hWnd, %VK_SPACE) THEN
if PolyMode < %GL_POLYGON then ' " " is the last one in the list designated by "dim PolyNames as string" seen near top of this program
incr PolyMode
else
PolyMode = %GL_POINTS
end if
UpdateWindowTitle()
end if

Wend

tbgl_DestroyWindow ' This will destroy the window

'=========
'=========

' FUNCTION DECLARATION This will set caption of the window
function UpdateWindowTitle() as long
' [!] TBGL function for setting title
TBGL_SetWindowTitle (hWnd, "BAX Lesson 3 - Polygon style : " & PARSE$( PolyNames , ",", PolyMode+1-%GL_POINTS) & " - press SPACE to change style, ESC to quit")
end function


The camera following some path is not implemented yet, but I have some sample on the disk, which I made with cooperation with Kryton9, once I will find it I will post it here.

Zoom aka field-of-view manipulation is on the list, I am working on it.
If you mean focus in the way to produce depth of field effect, this is more tricky as it needs use of accumulation buffer ( works but slow ) or shaders ( not on all cards ). So this will need some deep study on my side :)

Please expect some more examples and stuff on Friday!


Petr

Petr Schreiber
09-04-2008, 09:27
Abraxas,

how do you mean clipped, like cut of by near plane ?
Can you post screen?


Thanks,
Petr

Michael Clease
09-04-2008, 11:41
yes.

Petr Schreiber
09-04-2008, 12:48
Thanks,

I think it is the same here.

Just one thing, the code produces 18 (6x3) vertices. 18 / 4 ( for quads ) is not integer number, so it would be better to use FOR i = 0 TO 3, as 4x3 = 12, which is more suitable for all kinds of primitives.

That leads me to the idea the orignal tutorial sample is kind of bad, and needs rewrite.


Thanks,
Petr