View Full Version : TBGL_Cylinder aligned between two specified points
Hi,
the basic TBGL_Cylinder must be aligned during creation. I wanted to have it fit between two points but I could not find any code to do that. I could find some OpenGL code that seems to do this but it does not work directly in TB and needed to be modified quite a bit before it worked.
As an example I attach code that shows it being used to create a number of cylinders in all axes to show that it is a generic solution.
7957
7956
Petr Schreiber
21-09-2012, 22:00
Beautiful! Beautiful! Beautiful!
Math is strong with this one :)
In TBGL it is possible to make one graphic element looking at other using TBGL_EntityLookAt, to do what you need could be achieved with this then:
' -- Measure distance cylinder-sphere
distance = TBGL_EntityGetDistance(%sScene, %eCylinder, %eSphere)
' -- Destroy old cylinder
TBGL_EntityDestroy(%sScene, %eCylinder)
' -- Make new
TBGL_EntityCreateCylinder(%sScene, %eCylinder, 0, 0.1, 0.1, distance, 0, 255, 255, 255)
' -- Make the entity eCylinder to be looking at eSphere (with +Z)
TBGL_EntitySetTarget(%sScene, %eCylinder, %eSphere)
' -- We want to make it look with +Y, lets turn it around X then
TBGL_EntityTurn(%sScene, %eCylinder, 90, 0, 0)
I attach basic example with one cylinder and sphere you can move in realtime using arrows.
Petr
Sorry Petr, but your example does not work on my machine - it paints a black screen then simply hangs...
7962
it locks up on line 73: TBGL_SceneRender(%sScene)
I have no idea why it does this. I couldn't find a way to make it work.
I must admit that I do not understand the code, and as it does not run, I have not been able to play with it to see how it does its magic. So for now I will stick with the subroutine I wrote.
Given that I have had other TB related troubles perhaps I need to reinstall TB or something. Perhaps it is my graphics card? I have an ATI FirePro V5800 (FireGL), which works fine for Processing, Cinema C4d, Houdini etc.
Petr Schreiber
22-09-2012, 14:07
I am sorry you experienced such a problems, do you have ThinBASIC 1.8.9.0 installed?
GPU should be perfectly enough - TBGL scales the rendering routines back to OpenGL 1.1 when necessary, that would run on cards manufactured before year 2000 :)
Petr
I did a complete TB & graphics card driver reinstall - this solved the problem.
My supplied code is necessary for people who want to use primitives as TBGL_EntitySetTarget is not available for primitives.
Hopefully the code may be of help to someone who does not want to get involved with the maths.
The advantage of your code is that both TBGL_EntitySetTarget and TBGL_EntitySetTargetPos are available.
The slight disadvantage is that one must build a set of EntityIDs and manage them.
Presumably, most people will prefer to use this newer scene/entity system rather than the original primitives.
Petr Schreiber
22-09-2012, 20:07
Uff, I am happy it works for you know!
You are right that for quick scripts the classic way is more suitable. When you need more control or when you are not strong in math, the entities come in handy.
I personally use both approaches, depending on the project :)
And you can also combine the classic way with entities as well - by creating user defined entity. The approach is described in article User defined entities (http://www.thinbasic.com/community/content.php?19-tbgl-user-defined-entities).
I am personally very happy to have you on the forum, your examples are very interesting both visually and when looking at the code.
Petr
Thanks Petr, for helping with the various "teething" troubles I have been having, and for your support. Much appreciated.