View Full Version : how to catch "sphere" vertices?
largo_winch
06-09-2011, 10:23
hello. How I can get the vertices (faces) by mouse or activate the vertices of a sphere (in general of primitives) using tbgl ? that's not possible I can imagine because there are no entries (values) of slices or segments of sphere. little easy example I show. I only changed "TBGL_PolygonLook %GL_LINE to see faces (vertex points) of sphere, bye, largo
Petr Schreiber
06-09-2011, 10:39
Hi Largo,
TBGL is not 3D editor, it is general purpose 2D/3D engine. It is possible to develop what you show on the picture, but of course, it should be done in programmers control.
The first step would be generating the sphere geometry to array. Information on how the sphere is defined can be found for example on Wikipedia (http://en.wikipedia.org/wiki/Sphere) or Wolfram Math World (http://mathworld.wolfram.com/Sphere.html)
The second step could be rendering the sphere in multiple passes - as solid, as wire and via the points. TBGL has all the resources you need for defining the geometry, the TBGL_PointLook could be good helper for switching the look from solid to points, but it is not necessary, if you render the primitives directly
The third step could be picking the points on the sphere. Combination of TBGL_GetPixelInfo and mouse functions makes possible to detect where user clicks in scene, as I shown in another example for you. Testing whether the point found is in radius around some of the existing vertices could be made via TBGL_PointInside3D and query to your data structure holding the position information
Good knowledge of math might be useful, for reference you could use for example the previously linked Wolfram Math World or any good book on the topic of course.
I hope it helps,
Petr
largo_winch
06-09-2011, 14:20
good tips and links, I've have a look at these pages, thank you petr!
I've found some code snippets for math. sphere correctness and want to convert it to thinbasic. there will be some more question. I am starting here:
' Empty GUI script created on 09-06-2011 14:03:52 by (ThinAIR) Dim sint1(0) As Double
Dim cost1(0) As Double
Dim sint2(0) As Double
Dim cost2(0) As Double
Dim slices As Long
call CircleTable(sint1(), cost1(), -slices)
Sub CircleTable (ByRef sint1() As Double, ByRef cost1() As Double, ByVal n As Long)
End Sub
that's not correct for arrays handling, what's wrong?
2) glNormal3d ?
TBGL_BeginPoly(%GL_TRIANGLE_FAN)
glNormal3d(0, 0, 1)
'glVertex3d
TBGL_Vertex(0, 0, radius)
For j = slices To 0 Step -1
'glNormal3d(cost1(j)*r1, sint1(j)*r1, z1 )
'glVertex3d(cost1(j)*r1*radius, sint1(j)*r1*radius, z1*radius)
TBGL_Vertex(cost1(j)*r1*radius, sint1(j)*r1*radius, z1*radius)
Next
TBGL_EndPoly
bye, thanks, largo
Petr Schreiber
06-09-2011, 14:25
Hi Largo,
Ad1)
As documented, ThinBASIC arrays start from 1. When passing array, it is enough to pass its name, without ().
Your example could become something like:
Dim cost1(1) As Double
Dim sint1(1) As Double
Dim cost2(1) As Double
Dim slices As Long
CircleTable(sint1, cost2, slices)
Sub CircleTable (ByRef sint1() As Double, ByRef cost1() As Double, ByVal n As Long)
End Sub
Ad 2)
Normals are implemented as TBGL_Normal command. You can look it up in the TBGL help file under Functions list/Lighting/TBGL_Normal.
TBGL help file can be launched from Help/User help/thinBasic_TBGL.chm from thinAir.
Petr
largo_winch
06-09-2011, 15:31
hello petr, thank your for array tip. ok, I've made this attempt for solid sphere and you can see new sphere at right side in scene, but it's wire modus, I don't know why, this sphere should be shown in solid modus. This sphere is more mathematical correct than other tbgl spheres before ;)
perhaps this can be a good starting point for my idea, what do you are thinking about this example?
"TBGL_BeginPolygon %GL_FRONT_AND_BACK, %GL_LINE
TBgl_BeginPolygon %GL_FRONT_AND_BACK, %GL_FILL"
these both commands could be very useful too.
bye largo
largo_winch
06-09-2011, 19:00
addendum to my preview post: this second example shows spheres in solid modus. a) I wanted to have original tbgl sphere and cube in wire modus and b) my new "math. solid sphere" in solid modus. I thought to change "TBGL_PolygonLook %GL_LINE" into "TBGL_PolygonLook %GL_FILL" must get it, but that doesn't work. bye, largo
Petr Schreiber
06-09-2011, 23:28
Hi Largo,
when you need custom geometric entity, I can recommend using actor_object template to create one. To do so:
click File/New
pick TBGL templates
click actor_object.taguit
in newly created file replace "<object>" with your name for object
save with tBasicU extension
fill the code in
I prepaired this way the EditorSphere for you, and attached code here for further study.
As an excercise, you can try to add custom EditorSphere_SetWireColor method ;)
Petr
largo_winch
07-09-2011, 12:56
petr: "when you need custom geometric entity, I can recommend using actor_object template to create one. "
thank you for editor_sphere example! :=) ok, that's alternative way of programming, I know already a little and I am thinking you're using for better object (entity) manipulation, thanks I will keep this new kind of tbgl programming in my mind! :)
Finally I show here two examples for math. Spheres in a) wire and b) solid modus. uses arrows up,down,left,right to rotate spheres. the example is provided with "wire" modus, but if you change in main script ("Editorsphere_testscript2.tbasic") the include file ('#INCLUDE "actor_EditorSphere2.tBasicU" into #INCLUDE "actor_EditorSphere2a.tBasicU") you will get the solid modus ;) the conversion of math. sphere code example (freeglut part) to thinbasic was relative easy!
feel free for testing!
zip file with examples for solid + Wire Spheres as attachement.
bye, largo
largo_winch
07-09-2011, 19:58
petr, do you're thinking it's possible with this current example to select faces of spheres like you can see in first post? my idea was to select some faces and drag and drop vertices (change complete the shape) of sphere. I will try to modify my math. sphere examples with "point-inside" and "getpixel infos" for user inputs ;) bye, largo
Petr Schreiber
08-09-2011, 07:16
Hi Largo,
I think it would be possible if the vertex data would be stored somewhere, and not just created for the purpose of rendering.
If you manage to split rendering and data, you have all you need for the manipulations.
Petr