Including 3D rendering engine


I have made this 3D rendering engine to be as generic as possible, unlike Math3DView. It can render 3D meshes and polylines stored as list of vertices and triangular faces. Render3D comes with four HB++ projects illustrating how to use it and how to embed 3D scenes as binary data or as Palm OS database.

3D engine code location

For all 3D rendering engines you will find a Windows DLL file and a binary file. The DLL file is used when your application is running on the Palm OS simulator, launched from the IDE. This DLL is usefull to debug your project. The binary file is the ARM compiled code, that must be embedded in your project, called by the main class to render the 3D scene.

The path to the DLL file and the properties of the binary resource (the ARM code) are stored in the global module, as shown in that example:

Public Const View3D_DllName As String  = "ARM_source_code\arm_render3d.dll" 
Public Const View3D_FunName As String  = "Render3D" 
Public Const View3D_ResNum  As Integer = 1  

Using the code

In that example, the codes are located in the ARM_source_code directory, the name of the main function is Render3D, you must not change it (unless you change it in the source code, that implies to recompile it).

Here is the method that loads such a code:

'--- SUB: Load ARM code and init params
Private Sub LoadARMCode(szDllName As String, szFuncName As String, ARMCodeID As Integer)
 On Error Goto Code_Err
 'Load ARM Code
 Select Case DeviceProc
  Case procX86
   Set FstreamARM = New StreamMemory
   FstreamARM.Write  hbProjectPath & szDllName
   FstreamARM.Write  szFuncName
   FARMLoaded = True
  Case procARM
   Set FstreamARM = Clone(App.Resource("ARMc",ARMCodeID))
   FARMLoaded = (Not FstreamARM Is Nothing)
 End Select
 'Init Params
 Set FstreamParams = New StreamMemory
 FstreamParams.Write  Clng(0)
 Exit Sub
End Sub 

And how it is initialized in the main class:

'--- Init arm code and variables
Private Sub InitARMandVariables()
 'load ARM code
 LoadARMCode View3D_DllName,View3D_FunName, View3D_ResNum
 'Set debug pointer to NULL
 'back color
 FBkColor = Color(200,200,200)
 'Init Camera
 ClearMatrixCamera  'Fill with "0", done once!
 SetPoint3f FCameraIsAt,0,0,0
 SetPoint3f FCameraLookAt,0,0,0
 SetCamera FCameraIsAt,FCameraLookAt
 swScaleX = SwapLong(1*FixedPoint)
 swScaleY = SwapLong(1*FixedPoint)
 swScaleZ = SwapLong(1*FixedPoint)
 'Init Light (what you want here)
 LightAngle 0,0
 AmbiantLight = 0.5
 DiffuseLight = 0.5
 SpecularLight = 0.4
 LightOptions = eNoLight
 'init global rendering options
End Sub 

If you are not familiar with the use of ARM codes in HB++ projects, I advise you to keep the directory and codes as they are predefined.