View Full Version : Circles question
Lionheart008
28-01-2009, 01:03
hi:)
I am looking for 'TBGL_DrawCircles' perhaps it's just a silly question, don't know... TBGL_DrawSphere does exists, but what about circles??? It's just 2d, isn't it??? It's better to go the direct way with primitives as kind of "2d in 3d" ???
Some days ago I would like to build a yin-yang symbol... with colours, thought about it and try to make circles... (2d circles)... without success... with 'tbgl_DrawCircle'
FUNCTION RenderMyImage( hCtrl as dword )
STATIC FrameRate AS DOUBLE
DIM i, x, y, f, r AS INTEGER
Dim Radius As Number
'- Dim Color As Number '- TBGL_Color( R, G, B ) as number !
if TBGL_CanvasBound(hCtrl) then
FrameRate = TBGL_GetFrameRate
FOR i = 1 to 500
x = INT(RND*639)+1 'Zufallszahlen generieren
y = INT(RND*479)+1
f = INT(RND*255)+1
r = INT(RND*400)+1
DrawCircle( x,y,r,f ) 'Kreis zeichnen
If TBGL_GetWindowKeyState(hctrl, %VK_ESCAPE) Then END '- ???
Sleep 10
next i
end
TBGL_ClearFrame
TBGL_SceneRender(%sScene)
TBGL_DrawFrame
end if
END FUNCTION
sub DrawCircle( x as single, y as single, f as single, r as single )
tbgl_PushMatrix
tbgl_color 255, 0, 0
tbgl_translate 0,-1,0
tbgl_DrawCircle 0.75,2.5,r,f '- 0.75, 2.5 und circle (300,250),r,f
'- TBGL_Circle(X, Y), Radius, Color
-'with tbgl_DrawSphere script runs but withouth circle ;)
tbgl_PopMatrix
end sub
perhaps somebody can give any hint to the theme "Circles" (link or script or something else) or I have choosed totally the wrong way :)
my script example is just a try to build in circles... the idea with yin-yang is just another task ;)
good night, Lionheart with courage to blame myself :lol:
ps: please take attention, the script doesn't run at all :roll:
Michael Clease
28-01-2009, 01:53
Frank it doesnt exist but it could. I havent tried the code below but it should work.
%DL_Circle = 1
%DEG2RAD = 3.14159/180 AS DOUBLE
SUB drawCircle(radius AS SINGLE)
LOCAL i AS LONG
LOCAL degInRAD AS DOUBLE
TBGL_NewList %DL_Circle
TBGL_PushMatrix
TBGL_BeginPoly %GL_LINE_LOOP
FOR i = 0 TO 360
degInRad = i*%DEG2RAD
TBGL_Vertex cos(degInRad)*radius, sin(degInRad)*radius
NEXT
TBGL_ENDPOLY
TBGL_PopMatrix
TBGL_EndList
END SUB
Lionheart008
28-01-2009, 04:29
hi michael :)
thanks a lot for your prompted help!
really good idea and looks very nice your script, even I can follow the structure ;), but how should I get the entity of %DL_Circles??? I mean this special part for '%eDL_Circle, %DL_Circle' (doesn't matter here if it's right, the script doesn't show the circle ;(... hmh)
'---------------------------------------------------------------------------
' -- Create something to look at
'- TBGL_EntityCreateCircle(%sScene, %eDL_Circle, 0, 1.25, 255, 155, 255)
'- TBGL_EntitySetPos(%sScene, %eDL_Circle, -1, 1, 3)
'---------------------------------------------------------------------------
tbgl module cannot build: 'TBGL_EntityCreateCircle' or similar things...
I have found some infos about 'circles' from freebasic ;) and has translated it...
Syntax: CIRCLE [Puffer,] [STEP] (x,y), Radius[, [Color][, [startangle][, [endangle][, [Aspect][, F]]]]]
[aspect] does mean: relation between y-Radius and x-Radius so you can follow...
"ratio = (y_radius / x_radius) * pixel_aspect_ratio"
[F] = Flag for color, fill the circle, arc, ellipse with color (yes, not)
so in freebasic you can use this code for creation of circles, arc, ellipsoids
CIRCLE (320, 240), 200, 15
' draw a white CIRCLE
(320, 240), 200, 2, , , 0.2, F
' draws a filled EllipseCIRCLE
(320, 240), 200, 4, 0.83, 1.67, 3
' draws a little arc.
perhaps we can find a solution or somebody can program / code such some day a new circles, arc, ellipse syntax :-D but I can wait for it ;) it's not urgent...
best wishes, have a nice "good morning", bye, Lionheart
ps: add a script but still without circles... but perhaps it's just a simple thing I cannot understand how to build it...
Michael Clease
28-01-2009, 09:55
try this Frank.
SUB drawCircle(Xpos AS LONG, Ypos AS LONG, Width AS SINGLE, Height AS SINGLE, StepSize AS SINGLE)
Note: Stepsize is the number of steps to make 360, so 1 would be smooth and 3 would be a triangle.
use the scaling to making it bigger or smaller
TBGL_EntitySetScale( SceneID, EntityID, X, Y, Z )
Update: Improved the sub routine to include position for 2D.
Petr Schreiber
28-01-2009, 10:26
Michael,
as usually, big thanks for support! :occasion:
Frank, Mike provided you with display list version of circle.
Can it be used as entity? Sure, because it is display list, which can be binded using TBGL_EntityCreateDLSlot.
As Mike said, using scaling you can modify the dimensions of such a display list circle template.
Petr
Michael Clease
28-01-2009, 10:40
Frank here is something you might be interested in.
DrawCircle 2, 5, (360/NumberOfSides)
if you want a hexagon you make NumberOfSides = 6, I dont think you need more detail than that ;)
Michael Clease
28-01-2009, 15:19
made some improvements, see the post which start "try this Frank".
Lionheart008
28-01-2009, 15:44
...short reply, must go at work now...
hi michael, dear petr, yes, very good one :)
DrawCircle 2, 5, (360/NumberOfSides)
and
DrawCircle 200,200,20, 50, (360/3)
I have tried the new script above and it works for me with one circle or hexagon or octagon (I have coded and tried it too:) this morning... )
=>my problem was to create more than one circle, hexagon or something with new forms... I have tried to build two, three circles and rotated them... but didn't found a way to show it... (add my script with problems... according to tbgl_new list)
=> with display list I can create more circles (or boxes or spheres...) so I wish, but it doesn't run at the moment... to create eg 4 (8) circles with different degrees (rotation)...
%DL_Circle = 2
TBGL_NewList %DL_Circle
TBGL_PushMatrix
TBGL_BeginPoly %GL_LINE_LOOP
FOR i = 0 TO 360 STEP StepSize
degInRad = i*%DEG2RAD
TBGL_Color 255,0,250
TBGL_Vertex cos(degInRad)*Width, sin(degInRad)*Height
NEXT
TBGL_ENDPOLY
TBGL_Translate 0, 1.25, 0
TBGL_Rotate 90, 0, 0, 0
TBGL_BeginPoly %GL_LINE_LOOP
FOR i = 0 TO 360 STEP StepSize
degInRad = i*%DEG2RAD
TBGL_Color 255,0,25
TBGL_Vertex cos(degInRad)*Width, sin(degInRad)*Height
NEXT
TBGL_ENDPOLY
TBGL_PopMatrix
next problem: it's not useful to make a second drawcircle as I can use the TBGL_NewList %DL_Circle functions or what do you think??? it should run with 'display list', but didn't ;(
DrawCircle 2, 5, 1.5 '- (360/4)
TBGL_EntityCreateDLSlot(%sScene, %eCircle, 0, %DL_Circle )
'- TBGL_EntityCreateDLSlot( SceneID, EntityID, ParentEntityID, DisplayList )
TBGL_EntitySetPos(%sScene, %eCircle, -4, 0, 0)
TBGL_EntitySetTargetPos(%sScene, %eCircle, 8, 8, 8 )
DrawCircle 2.5, 6, 1.5 '- (360/8)
TBGL_EntityCreateDLSlot(%sScene, %eCircle1, 0, %DL_Circle )
TBGL_EntitySetRot(%sScene, %eCircle1, 90, 0, 0)
TBGL_EntitySetColor(%sScene, %eCircle1, 250,255,255 )
TBGL_EntitySetPos(%sScene, %eCircle1, 1, 2, 1)
TBGL_EntitySetTargetPos(%sScene, %eCircle1, 8, 8, 8 )
my script isn't just perfect, I know, will try it this evening again, thanks a lot, in this way we can create circles, ellipse, arcs and much more :)
ok, more will come later... thanks michael! :-) I like it to get more good tbgl support 8)
see you, Lionheart
Michael Hartlef
28-01-2009, 17:58
Frank it doesnt exist but it could. I havent tried the code below but it should work.
%DL_Circle = 1
%DEG2RAD = 3.14159/180 AS DOUBLE
SUB drawCircle(radius AS SINGLE)
LOCAL i AS LONG
LOCAL degInRAD AS DOUBLE
TBGL_NewList %DL_Circle
TBGL_PushMatrix
TBGL_BeginPoly %GL_LINE_LOOP
FOR i = 0 TO 360
degInRad = i*%DEG2RAD
TBGL_Vertex cos(degInRad)*radius, sin(degInRad)*radius
NEXT
TBGL_ENDPOLY
TBGL_PopMatrix
TBGL_EndList
END SUB
Hi Michael,
it exists but isn't documented yet. The current TBGL has it allready inside. TBGL_LINE2D, TBGL_CIRCLE2D, TBGL_RECT2D and TBGL_BOX2D. Petr and I decided to rename them without the 2D for the next release and then the help file should be updated too.