primo
25-03-2020, 17:05
while searching an old 3d models i have found a strange *.obj model it looks like a spherical dumples with spikes. also it reminds me of the virus-19 but with two heads, don't scare please
10140
i have converted it to *.M15 thinbasic model using TBGL_OBJ2M15 utility
i have used Petr code in this thread http://www.thinbasic.com/community/showthread.php?12635-Rotation-issues
i have added only the coloring of vertices and adjusted the camera
the code below needs the spikey.m15 model attached below together with the spikey.obj
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
10140
i have converted it to *.M15 thinbasic model using TBGL_OBJ2M15 utility
i have used Petr code in this thread http://www.thinbasic.com/community/showthread.php?12635-Rotation-issues
i have added only the coloring of vertices and adjusted the camera
the code below needs the spikey.m15 model attached below together with the spikey.obj
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