Results 1 to 3 of 3

Thread: Ray-triangle intersection: Example using new function enabled TYPEs

  1. #1
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,155
    Rep Power
    736

    Lightbulb Ray-triangle intersection: Example using new function enabled TYPEs

    Hi,

    you can download sample code for ray-triangle intersection in the attachement.
    It uses newly introduced function enabled types to produce easy to follow code.

    Thanks to this, the main code can be very short:
    Uses "Console"
    
    #INCLUDE Once "tTriangle.tBasicU"
    #INCLUDE Once "tVector3D.tBasicU"
    #INCLUDE Once "tRay.tBasicU"
    
    Function TBMain()
    
      Dim triangle As tTriangle
      
      triangle.Init(-1, -1, 0, ' -- A
                     1, -1, 0, ' -- B
                     0,  1, 0) ' -- C
      
      Dim ray As tRay
      
      ray.Init(0, 0, 1, ' -- Point
               0, 0,-1) ' -- Direction
      
      Dim collisionPoint As tVector3D
      
      PrintL "Ray     : " + ray.ToString()
      PrintL "Triangle: " + triangle.ToString()
      PrintL "-----"
      
      If ray.IntersectsTriangle(triangle, collisionPoint) Then  
        PrintL "Intersection found at " + collisionPoint.ToString()
      Else                                                
        PrintL "No intersection found"
      End If  
      
      WaitKey
    
    End Function
    

    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

  2. #2
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    55
    Posts
    1,555
    Rep Power
    174
    Really very small and very structured. I like small functions. And I'm addicted to structured code

    Edit: One makes me think...
    Function tVectorUtils.MakeVector(pointA As tVector3D, pointB As tVector3D) As String
    
      Dim v As tVector3D
      
      v.x = pointA.x - pointB.x
      v.y = pointA.y - pointB.y
      v.z = pointA.z - pointB.z
      
      Return v
    
    End Function
    
    (same to tVectorUtils.CrossProduct3D)

    I think... if the function result is a string, and v is a tVector3D, and it returns v:
    does tB automatically convert tVector3d to a string so this is equal to
    Return Memory_Get(VarPtr(v), SizeOf(tVector3D) )
    
    ???
    Last edited by ReneMiner; 21-04-2014 at 07:45.
    I think there are missing some Forum-sections as beta-testing and support

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,155
    Rep Power
    736
    Hi Rene,

    BASICally yes. Thanks for bringing it up, I made a feature suggestion


    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

Similar Threads

  1. Triangle
    By peter in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 9
    Last Post: 23-07-2009, 22:53
  2. Sierpinski triangle approximation .... using L-System :D
    By Petr Schreiber in forum TBGL General
    Replies: 7
    Last Post: 11-03-2008, 00:08
  3. Types
    By kryton9 in forum TBGL General
    Replies: 8
    Last Post: 26-11-2006, 00:36
  4. Few functions types
    By Petr Schreiber in forum Win API interface
    Replies: 7
    Last Post: 28-11-2005, 14:30

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
  •