Uses "TBGL"
Function TBMain()
DWord hWnd = TBGL_CreateWindowEx("something spiky - ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED)
TBGL_ShowWindow
'String modelFile = "simple_house.m15"
String modelFile = "spiky.m15"
TBGL_m15LoadModel ModelFile, "", 1, 1, %TBGL_NORMAL_PRECISE
Dim light As TBGL_TVECTOR3D
TBGL_UseLighting TRUE
TBGL_UseLightSource %GL_LIGHT0, TRUE
TBGL_SetupLightSource %GL_LIGHT0, light.x, light.y, light.z, 32, 32, 32, 255
Dim center As TBGL_TVECTOR3D
center = GetModelCenter(1)
'msgbox 0, str$(center)
TBGL_ResetKeyState()
While TBGL_IsWindow(hWnd)
TBGL_ClearFrame
'TBGL_Camera 0, 20, 60,
' 0, 0, 0
TBGL_Camera 0, 0, 1.5,
0, 0, 0
TBGL_PushMatrix
TBGL_Rotate GetTickCount/10, 0, 1, 0 ' -- Turn model
TBGL_Translate -center.x, -center.y, -center.z ' -- Center the rotation
TBGL_m15DrawModel 1
TBGL_PopMatrix
TBGL_DrawFrame
If TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE ) Then Exit While
Wend
TBGL_DestroyWindow
End Function
Function GetModelCenter( modelId As Long ) As String ' -- Hack to return TYPEs
Long i, vtx
Single x,y,z
vtx = TBGL_m15GetModelVertexcount(modelId)
Single minx, miny, minz = 99999
Single maxx, maxy, maxz = -99999
Dim center As TBGL_TVECTOR3D
For i = 1 To vtx
TBGL_m15GetVertexXYZ(modelId, i, x, y, z)
TBGL_m15SetVertexRGB( 1, i, 240,237,132)
maxx = Max(x, maxx)
minx = Min(x, minx)
maxy = Max(y, maxy)
miny = Min(y, miny)
maxz = Max(z, maxz)
minz = Min(z, minz)
Next
center.x = minx + (maxx - minx) / 2.0
center.y = miny + (maxy - miny) / 2.0
center.z = minz + (maxz - minz) / 2.0
Return center
End Function
Bookmarks