Results 1 to 7 of 7

Thread: TBGL_Cylinder aligned between two specified points

  1. #1

    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.

    Cylinders.jpg

    Cylinders.tbasic

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    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
    Attached Files Attached Files
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3

    Example does not work

    Sorry Petr, but your example does not work on my machine - it paints a black screen then simply hangs...
    rp_Downloads - XYplorer @ XYplorer.ini - v11.60_2012-09-21_23-10-05.jpg
    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.

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #5

    code now works

    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.

  6. #6
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    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.

    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  7. #7
    Thanks Petr, for helping with the various "teething" troubles I have been having, and for your support. Much appreciated.

Similar Threads

  1. nurbsproject: tbgl points movement by mouse
    By christianssen in forum TBGL General
    Replies: 7
    Last Post: 13-04-2010, 12:05

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •