View Full Version : Playing with lines based on tutorial code
Here is a result of playing with lines based on Petr's tbgl tutorials.
this one is a noise like pattern :)
'
' Lesson #2 from thinBASIC TBGL tutorials
' "Colors"
'
' by Petr Schreiber
'
' Downloaded from http://psch.thinbasic.com/
'
Uses "TBGL"
Uses "UI"
DIM hWnd AS DWORD
DIM vx as long
'MsgBox (0, "You should see blue screen with colorful triangle soon"+$LF+$LF+"Press ESCAPE to quit window", %MB_ICONINFORMATION, "Lesson 2")
' We will initialize OpenGL and internal buffers
' Function also returns window handle
hWnd = tbgl_CreateWindow( "Lesson 2 - press ESC to quit")
tbgl_ShowWindow ' This will display the window on the screen
tbgl_BackColor 0, 0, 0 ' Let's set the default background to darkblue - just one call needed !
tbgl_Color 0, 255, 0
GetAsyncKeyState(%VK_ESCAPE) ' Reset status of the ESCAPE to prevent immediate quit
while iswindow(hWnd) ' While window exists, we will draw and check for ESCAPE
win_SetTitle( hWnd, TBGL_GetFramerate & " Noise or Scratch Effect - Press ESC to EXIT")
tbgl_ClearFrame ' This clears the frame and prepares it for drawing
tbgl_Camera 0,0,cos(timer)*100,0,0,0 ' We will look from point 0,0,5 to 0,0,0 ( origin of coordinates )
tbgl_rotateXYZ 0,cos(timer)*30,0
tbgl_linewidth rnd(1,2)
for vx = 1 to 50 step 1
tbgl_BeginPoly %GL_LINES' Here begins definition of traditional triangle polygon
' Pulsing Black-To-Red
tbgl_Color 225, 200, 0
tbgl_Vertex -rnd(1,50),rnd(1,50),rnd(1,50)
'vx = rnd(1,100)
tbgl_Vertex rnd(1,50),-rnd(1,50),rnd(1,50)
tbgl_EndPoly ' We must end the definition of polygon
next
tbgl_linewidth rnd(1,3)
for vx = 1 to 50 step 1
tbgl_BeginPoly %GL_LINES' Here begins definition of traditional triangle polygon
tbgl_Color 255, 100,0
tbgl_Vertex -rnd(1,75),rnd(1,75),rnd(1,75)
'vx = rnd(1,100)
tbgl_Vertex rnd(1,75),-rnd(1,75),rnd(1,75)
tbgl_EndPoly ' We must end the definition of polygon
next
tbgl_linewidth 1
for vx = 1 to 50 step 1
tbgl_BeginPoly %GL_LINES' Here begins definition of traditional triangle polygon
tbgl_Color 255, 150 , 0
tbgl_Vertex -rnd(1,25),rnd(1,25),rnd(1,25)
'vx = rnd(1,100)
tbgl_Vertex rnd(1,25),-rnd(1,25),rnd(1,25)
tbgl_EndPoly ' We must end the definition of polygon
next
tbgl_DrawFrame ' This will display the scene
' When ESCAPE is pressed, we will leave the main loop
IF GetAsyncKeyState(%VK_ESCAPE) THEN EXIT while
Wend
tbgl_DestroyWindow ' This will destroy the window
This one is like inside of a laser projector:
'
' Lesson #2 from thinBASIC TBGL tutorials
' "Colors"
'
' by Petr Schreiber
'
' Downloaded from http://psch.thinbasic.com/
'
Uses "TBGL"
Uses "UI"
DIM hWnd AS DWORD
DIM vx,vy,vz,angle as double
DIM lw as integer = 1
'MsgBox (0, "You should see blue screen with colorful triangle soon"+$LF+$LF+"Press ESCAPE to quit window", %MB_ICONINFORMATION, "Lesson 2")
' We will initialize OpenGL and internal buffers
' Function also returns window handle
hWnd = tbgl_CreateWindow( "Lesson 2 - press ESC to quit")
tbgl_ShowWindow ' This will display the window on the screen
tbgl_BackColor 0, 0, 0 ' Let's set the default background to darkblue - just one call needed !
'tbgl_Color 75, 100, 75
GetAsyncKeyState(%VK_ESCAPE) ' Reset status of the ESCAPE to prevent immediate quit
while iswindow(hWnd) ' While window exists, we will draw and check for ESCAPE
win_SetTitle( hWnd, TBGL_GetFramerate & " Inside Laser Projector Effect - Press ESC to EXIT")
tbgl_ClearFrame ' This clears the frame and prepares it for drawing
tbgl_Camera 0,0,cos(timer),0,0,0 ' We will look from point 0,0,5 to 0,0,0 ( origin of coordinates )
'tbgl_rotateXYZ 0,cos(timer)*30,0 'adds some rotation to the camera
'lw = rnd(1,2)
tbgl_linewidth lw
tbgl_BeginPoly %GL_LINES' Here begins definition of traditional triangle polygon
vz = 0.0
for angle = 0.0 to 3*3.1415 step 0.05
tbgl_Color rnd(1,10), rnd(1,200) , rnd(1,10)
vx = 50.0*sin(angle)
vy = 50.0*cos(angle)
tbgl_Vertex vx, vy, vz
vx = 50.0*sin(angle+3.1415)
vy = 50.0*cos(angle+3.1415)
tbgl_Vertex vx, vy, vz
next
tbgl_EndPoly ' We must end the definition of polygon
tbgl_DrawFrame ' This will display the scene
' When ESCAPE is pressed, we will leave the main loop
IF GetAsyncKeyState(%VK_ESCAPE) THEN EXIT while
Wend
tbgl_DestroyWindow ' This will destroy the window
Petr Schreiber
28-01-2007, 19:12
Hi kryton9,
this is psychedelic ;D
I can imagine it as post process for some halucinating scenes.
This would require just to render scene and then your effect with depth flag off and possibly some kind of blending
Bye,
Petr
Thanks Petr, you are kind, just goofing around with line codes and came up with some stuff. If you turn of the z depth, would it still plot the line vertices into the z plane?
I am going to play more with lines as I know I can come up with something really good, just haven't figured it out yet :)
Petr Schreiber
29-01-2007, 12:15
Hi kryton9,
turning off depth means just turning of depth test, it means if you first draw foreground part of cube and then the back part, you will see the back part. This is unusable for classical rendering, but good for post process stuff and particles, if you draw them as last ones.
Looking forward for next creations,
Petr
Thanks for explanation Petr, that will come in handy!!
This is to mimic sort of a red laser security system like seen in movies for museums. The camera tilts slowly up from looking towards the floor. to show the room being scanned. No room in this, but you can get the idea :)
'
' Lesson #2 from thinBASIC TBGL tutorials
' "Colors"
'
' by Petr Schreiber
'
' Downloaded from http://psch.thinbasic.com/
'
Uses "TBGL"
Uses "UI"
DIM hWnd AS DWORD
DIM vx,vy,vz,angle,cy as double
DIM lw as integer = 1
'MsgBox (0, "You should see blue screen with colorful triangle soon"+$LF+$LF+"Press ESCAPE to quit window", %MB_ICONINFORMATION, "Lesson 2")
' We will initialize OpenGL and internal buffers
' Function also returns window handle
hWnd = tbgl_CreateWindow( "Lesson 2 - press ESC to quit")
tbgl_ShowWindow ' This will display the window on the screen
tbgl_BackColor 0, 0, 0 ' Let's set the default background to darkblue - just one call needed !
'tbgl_Color 75, 100, 75
GetAsyncKeyState(%VK_ESCAPE) ' Reset status of the ESCAPE to prevent immediate quit
cy = -0.1
while iswindow(hWnd) ' While window exists, we will draw and check for ESCAPE
win_SetTitle( hWnd, TBGL_GetFramerate & " Inside Laser Projector Effect - Press ESC to EXIT")
tbgl_ClearFrame ' This clears the frame and prepares it for drawing
tbgl_Camera 0,0,0.1,0,cy,0 ' We will look from point 0,0,5 to 0,0,0 ( origin of coordinates )
cy += 0.0001
if cy > -0.01 then cy = -0.1
'tbgl_rotateXYZ 0,cos(timer)*30,0 'adds some rotation to the camera
'lw = rnd(1,2)
tbgl_linewidth lw
' tbgl_BeginPoly %GL_LINES' Here begins definition of traditional triangle polygon
' vz = 0.0
' for angle = 0.0 to 3*3.1415 step 0.05
' tbgl_Color rnd(1,10), rnd(1,10) , rnd(1,255)
' vx = 50.0*sin(angle)
' vy = 50.0*cos(angle)
' tbgl_Vertex vx, vy, vz
' vx = 50.0*sin(angle+3.1415)
' vy = 50.0*cos(angle+3.1415)
' tbgl_Vertex vx, vy, vz
' next
' tbgl_EndPoly ' We must end the definition of polygon
tbgl_BeginPoly %GL_LINES' Here begins definition of traditional triangle polygon
vz = 0.00
for angle = 0.0 to 3*3.1415 step 0.05
tbgl_Color rnd(1,255), rnd(1,10) , rnd(1,10)
vx = 50.0*sin(angle)+0.25
vy = 50.0*cos(angle)
tbgl_Vertex vx, vy, vz
vx = 50.0*sin(angle+3.1415)
vy = 50.0*cos(angle+3.1415)
tbgl_Vertex vx, vy, vz
next
tbgl_EndPoly ' We must end the definition of polygon
tbgl_BeginPoly %GL_LINES' Here begins definition of traditional triangle polygon
vz = 0.00
for angle = 0.0 to 3*3.1415 step 0.05
tbgl_Color rnd(1,255), rnd(1,10) , rnd(1,10)
vx = 50.0*sin(angle)-0.25
vy = 50.0*cos(angle)
tbgl_Vertex vx, vy, vz
vx = 50.0*sin(angle+3.1415)
vy = 50.0*cos(angle+3.1415)
tbgl_Vertex vx, vy, vz
next
tbgl_EndPoly ' We must end the definition of polygon
tbgl_DrawFrame ' This will display the scene
' When ESCAPE is pressed, we will leave the main loop
IF GetAsyncKeyState(%VK_ESCAPE) THEN EXIT while
Wend
tbgl_DestroyWindow ' This will destroy the window
Here is my story idea maybe, the good side forces (thinBasic) are being infiltrated by The Ruby Python Organization. RPO sent its agents to steal the code from deep with thinBasic Headquarters in the Master Code Vault, the much protected secret code file to free the world from complicated programming syntax and bring joy and fun to the world, Project Super thinBasic.
I found hints of this top secret file in the new examples in the recent release :)
I played with making a logo for Ruby Python Organization to get me motivated, will see where it leads too. Have to come up with something for thinBasic now :)
Petr Schreiber
30-01-2007, 20:09
;D,
kryton9, this idea is scary !
If I imagine someone would stole tB source :)
The laser effect is good. I have just one suggestion - instead of random color I would go for SIN or something like that to make it harmonically pulse. I like the snake logo, it is quite scary to see something like that at the night.
Just don't know if Python and Ruby users won't feel upset by the idea of making them the "evil ones" :)
Anyway, here is very very simple laser study ( :) ) of secure room:
'
' Laser chamber
'
Uses "TBGL"
Uses "UI"
DIM hWnd AS DWORD
hWnd = tbgl_CreateWindow( "Laser chamber - press ESC to quit")
tbgl_ShowWindow ' This will display the window on the screen
GetAsyncKeyState(%VK_ESCAPE) ' Reset status of the ESCAPE to prevent immediate quit
tbgl_UseLightSource %GL_LIGHT0, 1
tbgl_SetLightParameter %GL_LIGHT0, %TBGL_LIGHT_position, 0,2,0,1
dim i, j as single
dim FrameTime as single
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 5, 5, 5, 0, 1, 0
tbgl_Rotate GetTickCount/80, 0, 1, 0
FrameTime = getTickCount/500
' Pillars
tbgl_UseLighting 1
tbgl_Color 255, 128, 0
PlacePillar(-1, -1)
PlacePillar( 1, -1)
PlacePillar( 1, 1)
PlacePillar(-1, 1)
tbgl_UseLighting 0
tbgl_UseBlend 1
tbgl_UseDepthMask 0
tbgl_BeginPoly %GL_LINES
for i = 0.25 to 2 step 0.25
tbgl_Color sin(FrameTime+i)*64+127, 0, 0
tbgl_Vertex -1, i, -1
tbgl_Vertex 1, i, -1
next
for i = 0.25 to 2 step 0.25
tbgl_Color sin(FrameTime+i+2)*64+127, 0, 0
tbgl_Vertex -1, i, 1
tbgl_Vertex 1, i, 1
next
for i = 0.25 to 2 step 0.25
tbgl_Color sin(FrameTime+i+3)*64+127, 0, 0
tbgl_Vertex -1, i, -1
tbgl_Vertex -1, i, 1
next
tbgl_EndPoly
for i = 0.25 to 2 step 0.25
tbgl_BeginPoly %GL_LINE_STRIP
tbgl_Vertex 1, i, -1
for j = -1 to 0.75 step 0.25
tbgl_Color sin(FrameTime+i+j)*64+127, 0, 0
tbgl_Vertex 1, i+sin(FrameTime+i*i+j*j+j)/5, j
next
tbgl_Vertex 1, i, 1
tbgl_EndPoly
next
tbgl_UseDepthMask 1
tbgl_UseBlend 0
tbgl_DrawFrame
' When ESCAPE is pressed, we will leave the main loop
IF GetAsyncKeyState(%VK_ESCAPE) THEN EXIT while
Wend
tbgl_DestroyWindow ' This will destroy the window
sub PlacePillar( x as single, z as single )
tbgl_Pushmatrix
tbgl_Translate x, 1, z
tbgl_Box 0.25, 2, 0.25
tbgl_popmatrix
end sub
One laser wall has very special properties :)
Bye,
Petr
Petr, you are too good. Very cool, thanks I will borrow some of that code in the near future :)
I actually am very impressed with Ruby and Python is the KING in scripting now with Perl it seems.
I will make sure to make a message that this is in fun and no bad intentions to those coders.
Just Ruby Python made such a good combo :)
It will be a funny short demo to test what can be done at the moment. Of course will love your additions
to it. I will do the whole thing, then send it to you and you can look at it and tweak where you see fit.
It will be a couple of weeks, but you never know how creativity goes, maybe it will flood with simple to do ideas
and come together.
As always thanks for your feedback and ideas and always cool code!!
Petr Schreiber
31-01-2007, 00:16
Yes, Ruby Python sounds good :D
Looking forward to the game, when in coding troubles just ask ;)
Bye,
Petr
I made a thinBasic emblem just awhile ago. Wanted to convey happiness and light airy feel as the alternative to rubypython.
Actually if there were a super thinBasic it probably would be like Ruby :) But this is all fiction and fun.
Petr Schreiber
31-01-2007, 09:42
Hi,
yes, quite relaxing comparing to evil snake :)
Any ideas how the game will be played ?
Bye,
Petr
If anything I will make a movie that will lead into a simple game. The game will be controlling a remote device that has to fly between the laser beams in the secure vault, Once it gets there. It scans the CD-ROM in the display to get the code and then fly back to safety. To scan the code ok, you have to hold the remote device pretty steady within a certain margin or you have to rescan the disk again. You have 5 minutes as the room is completely scanned from top to bottom every 5 minutes and you will for sure be detected in that amount of time.
I will try keep everything simple and hopefully we can make something happen.
I did manage to get a test object I made in sketchup into Blender and then into thinEdge.
When i tried to do a complicated model I downloaded i got errors in blender because materials were missing. That is when I decided to make one without materials in sketchup and try and it worked.
I will work on the artwork, buildings, rooms and remote vehicle to relearn modeling again. A friend of mine who is good with doing voices will do any voice work needed so that will be good. Maybe even some music. I can make music too, but who has the time :)
I also decided while you are working on getting all the new things into tbgl, I will concentrate on Delphi, go through some books I have, then I will go through Visual C++. It seems everything points to C++ no matter how much I try to avoid it. But I will be doing some database work so I want to learn Delphi good enough to crank out some stuff. IN the meantime for fun I will work on the media for this little story.
Let me know if you have any ideas or for even a different story you might want to work on, but something simple like this one. We don't have to do Ruby Python, I feel bad about that too as I like what I see inthose 2 languages too. But that logo I think looks menacing :)
I am totally open to anything simple you would like to do and I can work onthe medial for that while you do your code development!!
Petr Schreiber
31-01-2007, 10:59
Hi kryton9,
terrific news. Voice over, music ... perfect.
I have one idea which will be politically correct :D for both sides.
You may choose if you will be Ruby Python "alien" or thinBasic community member :)
So first you could fly with the plane/vehicle and try to steal :) or, as tBcM try to catch an "enemy" vehicle in field of lasers.
Two games in one :) But this is just idea...
Bye,
Petr
I could do the game in 2 parts almost. One as mentioned and then part 2, or play as TBCommando, if the enemy get the disk and as they make their escape, as you mentioned have a flight chase shoot'em up game. If I can ever get the first part done, then the second part will be easier, at least I hope so :)
Petr Schreiber
01-02-2007, 20:04
Hi kryton9,
do you have some models done in SketchUp for this project yet?
Regarding lasers - to make them look they light through dusty environment, we can texture lines (!) using some noise texture.
Bye,
Petr
No Petr, I worked on Delphi last night. A new tutorial came out for handling ball bounce, velocity and gravity. Lots of fun. I coded the example and will try to make it a slightly different game to show my appreciation to the teachers.
Is there something in particular you would like me to make in sketchup and bring to thinEdge? Let me know, I should be able to do it pretty quickly, I hope :)
You can add textures to lines?, cool!! Great Idea!!
Petr Schreiber
02-02-2007, 15:00
Hi kryton9,
I have not a special request regarding SketchUp, just let me know if you found in it some good ideas I could introduce in thinEdge. I cannot guarantee I will put it in immediately, as I am busy now with TBGL, web and thinEdge performance tuning, but if I can make thinEdge better I will try :)
Have fun with Delphi, and don't forget to share ideas from tutorial, maybe we can use them in tB too
Bye,
Petr
Petr Schreiber
02-02-2007, 20:44
Hi kryton9,
I have just seen the news - it seems you have tornado troubles on Florida :(
Is it serious in your area ?
Bye,
Petr
Thank you, we got it mild compared to about an hour away from here. The worse damage was there. I am looking outside and I don't see anything unusual, but I did hear tree grinding equipment earlier in the morning, probably cleaning up the fallen tree branches.
Thanks for the concern, amazing how the news goes around the world so fast!!
I will post the program I made in Delphi following the tutorial, I will comment it as best as I can so you can see if you can make the same in TBGL, it does need the mouse, so that will be motivation to get the mouse stuff going. I hope to have all of that up by tomorrow.
The next project is cool too, a dynamic sin wave, you change the amplitude and frequency slidebars and the sine wave updates dynamically. I have yet to code that, but will this weekend and also post that up for study.
I will place those at coding monkeys in the delphi section when finished.
Till then, thanks for the concern and happy coding and making all your contributions that much better for us!!
Petr Schreiber
03-02-2007, 20:54
Hi,
good to hear all is relatively ok in your area.
Your Delphi sample is very nice ! I started to work on TBGL 0.1.9 today - already developed TBGL_MouseGetPosX and TBGL_MouseGetPosY ( it was not that hard ;D ) and now looking on picking of objects.
Also normal calculations for specific model layer are in progress - surprisingly useful :) Imagine you have model with table, where table body is quite angular. And on table is curved mesh of tablecloth. Now you would need to split it in 2 models and one render with precise normals, second with smooth ones. In next TBGL you will just specify layer properties for one model.
I also made some tuning on thinEdge, so hope to publish another preview soon.
Bye,
Petr
Wow that layer idea sounds great Petr. I Never thought about something like that or seen that. I can see how useful it will be.
That is great that you have mouse code in already. It will really add to what can be done. Selecting will be something else, I don't know how in other programs they know where in a line you are on, wether it is that line or the line behind. It must run through lists of some sort, but I never did any coding like that. Good luck.
I cheated by using a intersect routine in Delphi to check for collision, I will study robot duel to see how you did it there, if I can figure it out that is.
Petr Schreiber
04-02-2007, 00:27
Hi,
so now I have:
TBGL_MouseGetPosX
TBGL_MouseGetPosY
TBGL_MouseGetLButton
TBGL_MouseGetRButton
TBGL_MouseGetMButton
TBGL_MouseGetWheelDelta
Nothing super, but enough for basic tasks.
Regarding picking of objects, it is part of OpenGL functions, but it is quite complicated. I need to find way to encapsulate it to friendly shape in TBGL. I was struggling with it this evening, but I must miss something. I have working sample in PB...
Bye,
Petr
P.S. In RobotDuel the collision detection is not better than in your sample, I rely on high processing speed of script ;)