'Experimental Mathematics =
'===============================================================================
Uses "TBGL" , "Math" , "Oxygen"
#Include Once "%APP_INCLUDEPATH%\thinbasic_gl.inc"
#Include Once "%APP_INCLUDEPATH%\thinbasic_glu.inc"
Begin Const
' -- Scene IDs
%sScene = 1
' -- Entity IDs
%eCamera = 1
%eContour
%eLight
%texOne
%lMyPoints
End Const
Type Point3D
x As Single
y As Single
z As Single
red As Single
green As Single
blue As Single
tu As Single
tv As Single
End Type
Global Nb As DWord = 2000000 '401880 '8120601
Global x, y, z, xx, yy,zz As Single
Global FrameRate As Long
Global Vertex(Nb) As Point3D ' single
Global total As Long
'Global ColorA(Nb) As TBGL_TRGB ' Byte
Function TBMain()
Local hWnd As DWord
Global FrameRate As Double
Global ang, earthX, earthZ, OrbitRadius As Single
Global flag, mask As Long
flag = 1 : mask = 1
OrbitRadius = 2.5
' -- Create and show window
hWnd = TBGL_CreateWindowEx("press Space to toggle the camera position , press 'M' to set a mask , 'R' reset mask to default ", 800, 600, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
' -- Create scene
TBGL_SceneCreate(%sScene)
' -- Create basic entities
' -- Create camera to look from 0, 8, 20 to 0, 0, 0
TBGL_EntityCreateCamera(%sScene, %eCamera)
TBGL_EntitySetPos(%sScene, %eCamera, 0, 8, 20)
TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)
' -- Create point light
TBGL_EntityCreateLight(%sScene, %eLight)
TBGL_EntitySetPos(%sScene, %eLight, 10, 20, 50)
' -- Create something to look at
'---Start time
Dim T0 As Double = Timer
CreatePointsList()
Dim T1 As Double = Timer
MsgBox(0, "Total time to create points List " & Format$(T1 - T0, "#0.00") & " secs" & " ... number of points = " & Str$(total))
TBGL_EntityCreateDLSlot(%sScene, %eContour, 0, %lMyPoints)
TBGL_EntitySetColor(%sScene, %eContour, 255, 255, 255)
' -- Resets status of all keys
TBGL_ResetKeyState()
TBGL_EntitySetTexture(%sScene, %eContour, %texOne )
'TBGL_LoadTexture APP_Path+"SampleScripts\TBGL\GBuffers\Textures\Bricks.bmp", %texOne, %TBGL_TEX_MIPMAP
TBGL_LoadTexture APP_Path+"SampleScripts\UI\Dialogs\Images\frogduck.bmp", %texOne, %TBGL_TEX_MIPMAP
' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate
TBGL_SetWindowTitle( hWnd, "FPS = "+Str$(FrameRate)+" press Space to toggle the camera position , press 'M' to set a mask , 'R' reset mask to default ")
TBGL_ClearFrame
If TBGL_GetWindowKeyOnce( hWnd, %VK_SPACE) Then
If flag = 1 Then
TBGL_EntitySetPos(%sScene, %eCamera, 0, 25, 0.1)
TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)
flag * -1
Else
TBGL_EntitySetPos(%sScene, %eCamera, 0, 12, 20)
TBGL_EntitySetTargetPos(%sScene, %eCamera, 0, 0, 0)
flag * -1
End If
End If
If TBGL_GetWindowKeyOnce( hWnd, %VK_M) Then
If mask = 1 Then
TBGL_EntitySetColorMask(%sScene, %eCamera, %TBGL_RED )
mask * -1
Else
TBGL_EntitySetColorMask(%sScene, %eCamera, %TBGL_GREEN )
mask * -1
End If
End If
If TBGL_GetWindowKeyOnce( hWnd, %VK_R) Then
TBGL_EntitySetColorMask(%sScene, %eCamera, %TBGL_DEFAULT)
End If
If TBGL_GetWindowKeyState( hWnd, %VK_UP ) Then
TBGL_EntityGetPos( %sScene, %eCamera, xx, yy, zz)
zz-0.1
TBGL_EntitySetPos(%sScene, %eCamera, xx, yy, zz)
ElseIf TBGL_GetWindowKeyState( hWnd, %VK_DOWN ) Then
TBGL_EntityGetPos( %sScene, %eCamera, xx, yy, zz)
zz+0.1
TBGL_EntitySetPos(%sScene, %eCamera, xx, yy, zz)
ElseIf TBGL_GetWindowKeyState( hWnd, %VK_Z ) Then
TBGL_EntityGetPos( %sScene, %eCamera, xx, yy, zz)
yy+0.1
TBGL_EntitySetPos(%sScene, %eCamera, xx, yy, zz)
ElseIf TBGL_GetWindowKeyState( hWnd, %VK_A ) Then
TBGL_EntityGetPos( %sScene, %eCamera, xx, yy, zz)
yy-0.1
TBGL_EntitySetPos(%sScene, %eCamera, xx, yy, zz)
ElseIf TBGL_GetWindowKeyState( hWnd, %VK_RIGHT ) Then
TBGL_EntityGetPos( %sScene, %eCamera, xx, yy, zz)
xx-0.1
TBGL_EntitySetPos(%sScene, %eCamera, xx, yy, zz)
ElseIf TBGL_GetWindowKeyState( hWnd, %VK_LEFT ) Then
TBGL_EntityGetPos( %sScene, %eCamera, xx, yy, zz)
xx+0.1
TBGL_EntitySetPos(%sScene, %eCamera, xx, yy, zz)
End If
TBGL_EntitySetRot(%sScene, %eContour, 0, GetTickCount/40, 0)
TBGL_SceneRender(%sScene)
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
Wend
TBGL_DestroyWindow
End Function
'==================================
Sub CreatePointsList()
String src = "
' -- Re-declare types
Type Point3D
x As Single
y As Single
z As Single
red As Single
green As Single
blue As Single
tu As Single
tv As Single
End Type
dim oVertex(2000000) At #Vertex As Point3D
dim N At #total As long
'dim oColorA(2000000) At #ColorA As TBGL_TRGB
Long a, b, c, Nb
Single x, z, k, xMin, yMin, zMin, xMax, yMax, zMax, range, step1
Long NbX
Long NbZ
Long NbY
nbx = 300
nby = 300
nbz = 300
'xMin = -2 : yMin = -2: zMin = -2 : xMax = 2: yMax = 2 : zMax = 2
'xMin = -3 : yMin = -3: zMin = -3 : xMax = 3: yMax = 3 : zMax = 3
xMin = -4 : yMin = -4: zMin = -4 : xMax = 4: yMax = 4 : zMax = 4
'xMin = -5 : yMin = -5: zMin = -5 : xMax = 5: yMax = 5 : zMax = 5
range = xMax - xMin
step1 = range / NbX
x = xMin: z = zMin : y = yMin
N = 0
For c = 0 To NbY
For b=0 To NbZ
For a=0 To NbX
'k = 320*(((x*x + (9*y*y)/4 +z*z -1)^3) - x*x*z*z*z - (9*y*y*z*z*z)/80)
k = Sin(x*y)+Sin(y*z)+Sin(z*x)
'k = x^3+y^2+z^2
'k = Pow(x,4) + Pow(y,4) + Pow(z,4) - Pow(x*x + y*y + z*z,2) + 3 * (x*x + y*y + z*z)
'k = x^4 + y^4 + z^4 - (x^2 + y^2 + z^2)^2 + 3 * (x^2 + y^2 + z^2)
If k <= 0.1 And k >= -0.1 Then
'If k <= 0.5 And k >= -0.5 Then
N = N+1
oVertex(N).x = x
oVertex(N).y = y
oVertex(N).z = z
oVertex(N).tu = a/NbX
oVertex(N).tv = b/Nbz
End If
x = x + step1
Next a
x = xMin
z = z + step1
Next b
x = xMin
z = zMin
y = y + step1
Next c
'print str N
terminate
"
' -- Pass the source
'O2_Asmo src
o2_basic src
If Len(o2_error) Then
MsgBox 0, o2_error : Stop
End If
' -- Execute
o2_exec
Long N
TBGL_NewList %lMyPoints
TBGL_PointSize 2
TBGL_UseLighting %FALSE
TBGL_BeginPoly %GL_POINTS
For N=1 To Nb
glTexCoord2f(Vertex(N).tu, Vertex(N).tv)
glVertex3f(Vertex(N).x,Vertex(N).y,Vertex(N).z)
Next
TBGL_EndPoly
TBGL_EndList
TBGL_UseLighting %TRUE
End Sub
Bookmarks