View Full Version : Coliding or subtracting graphic objets
Hi all,
I have another intereting programming problem.
I am trying to do a subractive graphic.
Here it goes.
1 draw the first sphere with a small radius
2 draw a second sphere with a much larger radius ( is can also be an egg shaped object)
3 I make them collide.
4 I asume that the area of the colision becomes invisible by taking on the colour of the background.
5 The remaining area (pls see attachment) then becomes a section of a sphere or which can be rotated, zoomed, shaded etc...
(http://www.i-optic.com/3dshape.jpg) in case the attachment can't be seen.
What are the chances of doing this with thinbasic ?
Do I first calculate the geometric area of the remaining sphere section and then render it ?
where to start ?
Best regards
Rob
-o-o-
Michael Hartlef
11-01-2009, 13:00
Sorry, my english isn't my native language so somtimes I have to ask again before I can try to help.
So before I go searching a formular on the net, do you want the colliding area to become a 3D modell that can be transformed or do you want the rest of the first sphere and the rest of the 2nd sphere to become a 3D model?
ErosOlmi
11-01-2009, 13:05
Mike,
just in case you didn't noticed it, Rob is from Australia so his reply can arrive a some hours time :lol:
Ciao
Eros
Michael Hartlef
11-01-2009, 13:14
No problem. I have patience. I'm already googling up the term Constructive solid geometry.
http://en.wikipedia.org/wiki/Constructive_solid_geometry
I'm sure once I understand exactly what he wants to make, we can come up with a solution for it. I find the stuff he does very interesing. A project like this can help pushing TBGL and other modules a little again.
Michael Hartlef
11-01-2009, 13:17
Also it could probably help Francko with his 3D modeller project. No good 3D modelling software without boolean operations, or ;)
ErosOlmi
11-01-2009, 14:22
Yes, it seems to me to recall very closely your 3D/2D example:
http://community.thinbasic.com/index.php?topic=1292.0
;)
Hi,
am awake again :)
I am trying to keep the black -remaining section of the black sphere, and then zoom, rotate it etc...
A kind of subtractive collision of geometric objects.
best regards
Rob
-o-o-
Petr Schreiber
11-01-2009, 23:16
Hi Rob,
CSG is not implemented yet, but here is code you can just copy and paste and you will see one of the ways to create and manipulate 2 spheres.
So "geometry subtracting" is not here yet, but you can get basic idea how 3D works in ThinBasic.
Uses "TBGL"
BEGIN CONST
' -- Scene IDs
%sScene = 1
' -- Entity IDs
%eCamera = 1
%eLight
%eSpherePivot
%eSphereA
%eSphereB
END CONST
FUNCTION TBMAIN()
LOCAL hWnd As DWORD
LOCAL FrameRate AS DOUBLE
' -- Create and show window
hWnd = TBGL_CreateWindowEx("Two spheres - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
' -- Create scene
TBGL_SceneCreate(%sScene)
' -- Higher number, higher quality
TBGL_SetPrimitiveQuality 50
' -- Create basic entities
' -- Create camera to look from 15, 15, 15 to 0, 0, 0
TBGL_EntityCreateCamera(%sScene, %eCamera)
TBGL_EntitySetPos(%sScene, %eCamera, 0, 0, 7)
TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)
' -- Create point light
TBGL_EntityCreateLight(%sScene, %eLight)
TBGL_EntitySetPos(%sScene, %eLight, 0, 10, 10)
' -- Create something to look at
TBGL_EntityCreatePivot(%sScene, %eSpherePivot)
TBGL_EntityCreateSphere(%sScene, %eSphereA, %eSpherePivot, 1)
TBGL_EntitySetColor(%sScene, %eSphereA, 255, 128, 0)
TBGL_EntitySetPos(%sScene, %eSphereA, -0.5, 0, 0)
TBGL_EntityCreateSphere(%sScene, %eSphereB, %eSpherePivot, 1.5)
TBGL_EntitySetColor(%sScene, %eSphereB, 0, 128, 255)
TBGL_EntitySetPos(%sScene, %eSphereB, 1, 0, 0)
' -- Resets status of all keys
TBGL_ResetKeyState()
' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
TBGL_ClearFrame
TBGL_SceneRender(%sScene)
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
' -- Spheres are attached to pivot point, when we turn or move pivot, spheres will go with it
IF TBGL_GetWindowKeyState(hWnd, %VK_LEFT) Then
TBGL_EntityTurn(%sScene, %eSpherePivot, 0,-90/FrameRate, 0)
ELSEIF TBGL_GetWindowKeyState(hWnd, %VK_RIGHT) Then
TBGL_EntityTurn(%sScene, %eSpherePivot, 0, 90/FrameRate, 0)
END IF
IF TBGL_GetWindowKeyState(hWnd, %VK_PGUP) Then
TBGL_EntityMove(%sScene, %eSpherePivot, 0, 0,-1/FrameRate)
ELSEIF TBGL_GetWindowKeyState(hWnd, %VK_PGDN) Then
TBGL_EntityMove(%sScene, %eSpherePivot, 0, 0, 1/FrameRate)
END IF
Wend
TBGL_DestroyWindow
END FUNCTION
ErosOlmi
11-01-2009, 23:20
Just for the "ignorant" (meaning in Latin: ignore) like me: CSG
:lol:
Michael Clease
12-01-2009, 00:50
Look at rendering to a texture would be my suggestion.
Michael Hartlef
12-01-2009, 13:35
Hi,
am awake again :)
I am trying to keep the black -remaining section of the black sphere, and then zoom, rotate it etc...
A kind of subtractive collision of geometric objects.
best regards
Rob
-o-o-
Rob, so you just have to make the remaining area visible and transform it. Is there no need for the actually 3D data of the resulting object? Like to export them to a text file? If you just have to display it, then using my method from the 2D/3D sample could be a solution.
1) Transform and draw 1.Sphere
2) Clear color buffer
3) Transform and draw 2.Sphere
I have to test this but I'm at work now. I will try it and let you know.
Michael
Michael Hartlef
12-01-2009, 17:31
Ok, the 2D/3D algo doesn't work for it, as the blocked visible faces are not drawn.
Petr Schreiber
12-01-2009, 19:18
Stay tuned,
I got interesting resource on topic of CSG and OpenGL, will give you back soon.
Ok- thanks
have begun to play more seriously with thinbasic & TBGL and it amasing and the
response to my questions on this board is super ! thanks to all ! :)
rob
-o-o-
ErosOlmi
12-01-2009, 23:08
... response to my questions on this board is super ! thanks to all !
That's the style we try to keep and strongly protect on this board.
:wink:
Michael Hartlef
16-01-2009, 20:11
Hi Rob,
so there is no easy out of the box solution for this. And nothing I could come up with it fastly. CSG is a very complex thing. But I will explore it further and let you know when I have something done!
Michael
Petr Schreiber
16-01-2009, 23:00
Hi Rob,
I was investigating on this field too, with results similar to Mike's ones:
Realisable (mostly via "stencil buffer" technique)
Not possible to do instantly as some rules must be followed
So results won't be visible soon, but once ready, you will be the first to know about it!
Lionheart008
17-01-2009, 00:12
Hi rob, hi all:)
I have worked some years ago with AutoCAD LT, Realsoft and Rhino 3D and have built some figures and Buildings with Boolean Operations ... very interesting stuff, but I haven't any idea to build it with TBGL or thinbasic so as petr have said it takes some releases to create such code stuff... I am curious how to find a best fitted algorithmus for it :)
picture add for you with some boolean functions... you can find here more:
"http://www.we-r-here.com/cad/tutorials/level_3/3-11.htm"
and a little figure I have created some minutes before, some like a bumblebee, have used petr's example at this board and have got some new learning stuff for translation objects and pivot functionality, I never used before ;)
hope we can see one day these csg functions also for thinbasic, would be great :) and I can imagine some guys can realize it here :-D
bye, Lionheart
ps: add one rhino example with boolean functions :D
Hi Lionheart. hi all ...
This looks great !
It's quite amasing !
I have a long way to go before I get near yout skills :)
thanks for sharing this neat code. :)
best regards
ROb
-o-o-
Michael Hartlef
17-01-2009, 11:43
Hi Rob,
I'm in the process of converting a C sample to use the stencil buffer for CSG. It's a visual thing so you won't be able to export the result but as I understand it you will be able to view it from all sides. Is that ok for you?
Michael
Hi Michael,
So does that mean that thinbasic will then be able to do its first CSG output to screen ?
Super! many thanks :)
Many thanks
Rob
-o-o-
Michael Hartlef
19-01-2009, 07:28
Hi Rob,
we are trying. I can't confirm it but we are getting closer.
Thanks !
am eagerly looking forward to the result :)
thanks to all !
Rob
-o-o-