TBGL_Rect in zx plane
issueid=335 14-11-2011 05:32
Number of reported issues by dcromley: 6
TBGL_Rect in zx plane
It works in xy plane and yz plane

This is a big program to show a small problem --
Should TBGL_Rect work to draw a rectangle in the zx plane?
  Uses "TBGL"
  Global hWnd As Long, ax, ay As Single
  hWnd = TBGL_CreateWindowEx("ESC to exit; arrow keys to rotate", 1024, 768, 32, _
    %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)                      
  Do While TBGL_IsWindow(hWnd) And _
      Not TBGL_GetWindowKeyOnce(hWnd, %VK_ESCAPE) 
    If  TBGL_GetWindowKeyState(hWnd, %VK_DOWN)  Then ax+= 1.44 ' 10sec/rev
    If  TBGL_GetWindowKeyState(hWnd, %VK_UP)    Then ax-= 1.44 
    If  TBGL_GetWindowKeyState(hWnd, %VK_RIGHT) Then ay+= 1.44 
    If  TBGL_GetWindowKeyState(hWnd, %VK_LEFT)  Then ay-= 1.44 
    TBGL_Camera 1,1,4, 0,0,0
    TBGL_RotateXYZ ax, ay, 0    
    TBGL_Color 255,255,255
    TBGL_Line 0,0,0, 1,0,0 ' axes
    TBGL_Line 0,0,0, 0,1,0
    TBGL_Line 0,0,0, 0,0,1
    TBGL_Color 255,0,0  
    zrect     .1,.1,.1, .1,.2,.2 ' in yz plane                           
    TBGL_Rect .1,.1,.1, .1,.2,.2                            
    TBGL_Color 0,255,0
    zrect     .3,.3,.3, .4,.3,.4 ' in zx plane                           
    TBGL_Rect .3,.3,.3, .4,.3,.4 ' where is this rectangle?                            
    TBGL_Color 0,0,255  
    zrect     .5,.5,.5, .6,.6,.5 ' in xy plane                           
    TBGL_Rect .5,.5,.5, .6,.6,.5
    Sleep 40
' this sub draws outline only
Sub zRect(x1 As Single, y1 As Single, z1 As Single, _  
          x2 As Single, y2 As Single, z2 As Single)
  If x1=x2 Then ' in yz plane
    TBGL_BeginPoly %GL_LINE_LOOP
      TBGL_Vertex x1,y1,z1
      TBGL_Vertex x1,y2,z1
      TBGL_Vertex x1,y2,z2
      TBGL_Vertex x1,y1,z2
  ElseIf y1=y2 Then ' in zx plane
    TBGL_BeginPoly %GL_LINE_LOOP
      TBGL_Vertex x1,y1,z1
      TBGL_Vertex x1,y1,z2
      TBGL_Vertex x2,y1,z2
      TBGL_Vertex x2,y1,z1
  ElseIf z1=z2 Then ' in xy plane
    TBGL_BeginPoly %GL_LINE_LOOP
      TBGL_Vertex x1,y1,z1
      TBGL_Vertex x2,y1,z1
      TBGL_Vertex x2,y2,z1
      TBGL_Vertex x1,y2,z1
    TBGL_Line x1,y1,z1, x2,y2,z2
  End If
End Sub
Regards, Dave
Issue Details
Issue Number 335
Project TBGL
Category Unknown
Status Not a Bug
Priority 8
Affected Version Unknown
Fixed Version (none)
Users able to reproduce bug 0
Users unable to reproduce bug 0
Assigned Users (none)
Tags (none)

14-11-2011 09:43
Super Moderator
Hi Dave,

thank you for your report. Sadly what you see is documented behavior:
  • first three coordinates are "left upper" corner
  • second three coordintes are "right lower" corner

That means, if we have pair:
(0.3, 0.3, 0.3)-(0.4, 0.3, 0.4)

It basically means the rectangle is in theory rectangle from (0.3, 0.3, 0.3)-(0.4, 0.3, 0.4) with zero height.

To illustrate the example, try to modify your line from:
TBGL_Rect .3,.3,.3,.4,.3,.4
TBGL_Rect .3,.4,.3,.4,.3,.4
I would not like to change the behavior of the TBGL_Rect function to not break compatibility with older code BUT I think we could extend the syntax to allow what you need, by adding one extra parameter to force the check for axis equality and specific plane aligned rendering.

So what about:
TBGL_Rect(x1, y1, z1, x2, y2, z2, planeAlignedFlag)
In such a case if you would draw like:
TBGL_Rect .3,.3,.3,.4,.3,.4, TRUE
it would do what you need.

I apologize I cannot change the TBGL_Rect functionality with default syntax, but it could break older code.


14-11-2011 10:04
Super Moderator
Syntax enhancement developed, will be present in ThinBASIC


14-11-2011 23:06
> .. "left upper" .. [to] .. "right lower" corner
Ah, yes. That explains a lot. I overlooked that.

> .. TBGL_Rect 3,4,3, 4,3,4
Good example

> .. one extra parameter .. planeAlignedFlag ..
Not necessary (now that I understand it), but it might be good.

> I apologize ..
Never! Good grief, you guys are so competent, available, and responsive!

Thanks, Dave

+ Reply