In the same vein, here's the start of an abstracted 3d Model class in VB.Net.
Public Enum CollisionModesEnum
Undefined = 0
Boxes = 1
Spheres = 2
Polygons = 3
End Enum
Public Enum TextureFilteringModesEnum
None = 0
NoSmoothing = 1
Linear = 2
End Enum
Public Class clsObject
#Region "Declarations"
Private m_iId As Integer = -1
Private m_bHidden As Boolean = False
Private m_bLoaded As Boolean = False
Private m_iTextureId As Integer = -1
Private m_iSourceId As Integer = -1
Private m_bCloned As Boolean
Private m_iGhostingMode As Integer = -1
Private m_bZDepthEnabled As Boolean = True
Private m_bZReadEnabled As Boolean = True
Private m_bZWriteEnabled As Boolean = True
Private m_iFadePct As Integer = 0
Private m_bLockedToScreen As Boolean = False
Private m_nUScale As Single = 1.0
Private m_nVScale As Single = 1.0
Private m_nAlphaPct As Single = 100
Private m_bCollisionEnabled As Boolean = False
Private m_oCollisionMode As CollisionModesEnum
Private m_oAmbience As Color
Private m_oDiffuse As Color
Private m_oEmissive As Color
Private m_oSpecular As Color
Private m_bAmbientReactive As Boolean = True
Private m_bFogReactive As Boolean = True
Private m_bLightReactive As Boolean = True
Private m_bCullingEnabled As Boolean = True
Private m_oFilteringMode As TextureFilteringModesEnum = TextureFilteringModesEnum.None
Private m_nSmoothingPct As Single = 0
Private m_bWireframe As Boolean = False
#End Region
#Region "Position, Rotation & Scale"
Public Property X() As Single
Get
Return oDB3D.ObjectPositionX(m_iId)
End Get
Set(ByVal Value As Single)
If m_bLoaded Then
oDB3D.PositionObject(m_iId, Value, oDB3D.ObjectPositionY(m_iId), oDB3D.ObjectPositionZ(m_iId))
End If
End Set
End Property
Public Property Y() As Single
Get
Return oDB3D.ObjectPositionY(m_iId)
End Get
Set(ByVal Value As Single)
If m_bLoaded Then
oDB3D.PositionObject(m_iId, oDB3D.ObjectPositionX(m_iId), Value, oDB3D.ObjectPositionZ(m_iId))
End If
End Set
End Property
Public Property Z() As Single
Get
Return oDB3D.ObjectPositionZ(m_iId)
End Get
Set(ByVal Value As Single)
If m_bLoaded Then
oDB3D.PositionObject(m_iId, oDB3D.ObjectPositionX(m_iId), oDB3D.ObjectPositionY(m_iId), Value)
End If
End Set
End Property
Public Sub XRotate(ByVal Angle As Single)
oDB3D.XRotateObject(m_iId, Angle)
End Sub
Public Sub YRotate(ByVal Angle As Single)
oDB3D.YRotateObject(m_iId, Angle)
End Sub
Public Sub ZRotate(ByVal Angle As Single)
oDB3D.ZRotateObject(m_iId, Angle)
End Sub
Public Sub Scale(ByVal XScale As Single, ByVal YScale As Single, ByVal ZScale As Single)
If Not m_bLoaded Then Exit Sub
oDB3D.ScaleObject(ID, XScale, YScale, ZScale)
End Sub
Public ReadOnly Property XSize() As Single
Get
If Not m_bLoaded Then Return 0
Return oDB3D.objectsizeX(ID)
End Get
End Property
Public ReadOnly Property YSize() As Single
Get
If Not m_bLoaded Then Return 0
Return oDB3D.objectsizeY(ID)
End Get
End Property
Public ReadOnly Property ZSize() As Single
Get
If Not m_bLoaded Then Return 0
Return oDB3D.objectsizeZ(ID)
End Get
End Property
Public Sub FixObjectPivot()
If m_bLoaded Then
oDB3D.FixObjectPivot(m_iId)
End If
End Sub
Public Property LockedToScreen() As Boolean
Get
Return m_bLockedToScreen
End Get
Set(ByVal Value As Boolean)
If m_bLoaded Then
If Value Then
oDB3D.LockObjectOn(m_iId)
Else
oDB3D.LockObjectOff(m_iId)
End If
m_bLockedToScreen = Value
End If
End Set
End Property
Public Sub Move(ByVal Distance As Single)
If m_bLoaded Then
oDB3D.MoveObject(m_iId, Distance)
End If
End Sub
Public Sub MoveDown(ByVal Distance As Single)
If m_bLoaded Then
oDB3D.MoveObjectDown(m_iId, Distance)
End If
End Sub
Public Sub MoveLeft(ByVal Distance As Single)
If m_bLoaded Then
oDB3D.MoveObjectLeft(m_iId, Distance)
End If
End Sub
Public Sub MoveRight(ByVal Distance As Single)
If m_bLoaded Then
oDB3D.MoveObjectRight(m_iId, Distance)
End If
End Sub
Public Sub MoveUp(ByVal Distance As Single)
If m_bLoaded Then
oDB3D.MoveObjectUp(m_iId, Distance)
End If
End Sub
Public ReadOnly Property AngleX() As Single
Get
If Not m_bLoaded Then Return -1
Return oDB3D.ObjectAngleX(m_iId)
End Get
End Property
Public ReadOnly Property AngleY() As Single
Get
If Not m_bLoaded Then Return -1
Return oDB3D.ObjectAngleY(m_iId)
End Get
End Property
Public ReadOnly Property AngleZ() As Single
Get
If Not m_bLoaded Then Return -1
Return oDB3D.ObjectAngleZ(m_iId)
End Get
End Property
Public ReadOnly Property OnScreen() As Boolean
Get
If Not m_bLoaded Then Return False
Return (oDB3D.ObjectInScreen(m_iId) = 1)
End Get
End Property
Public ReadOnly Property ScreenX() As Integer
Get
If Not m_bLoaded Then Return -1
Return oDB3D.ObjectScreenX(m_iId)
End Get
End Property
Public ReadOnly Property ScreenY() As Integer
Get
If Not m_bLoaded Then Return -1
Return oDB3D.ObjectScreenY(m_iId)
End Get
End Property
Public ReadOnly Property SizeX() As Single
Get
If Not m_bLoaded Then Return -1
Return oDB3D.ObjectSizeX(m_iId)
End Get
End Property
Public ReadOnly Property SizeY() As Single
Get
If Not m_bLoaded Then Return -1
Return oDB3D.ObjectSizeY(m_iId)
End Get
End Property
Public ReadOnly Property SizeZ() As Single
Get
If Not m_bLoaded Then Return -1
Return oDB3D.ObjectSizeZ(m_iId)
End Get
End Property
Public ReadOnly Property Visible() As Boolean
Get
If Not m_bLoaded Then Return False
Return (oDB3D.ObjectVisible(m_iId) = 1)
End Get
End Property
Public Sub PitchDown(ByVal Angle As Single)
If m_bLoaded Then
oDB3D.PitchObjectDown(m_iId, Angle)
End If
End Sub
Public Sub PitchUp(ByVal Angle As Single)
If m_bLoaded Then
oDB3D.PitchObjectUp(m_iId, Angle)
End If
End Sub
Public Sub RollLeft(ByVal Angle As Single)
If m_bLoaded Then
oDB3D.RollObjectLeft(m_iId, Angle)
End If
End Sub
Public Sub RollRight(ByVal Angle As Single)
If m_bLoaded Then
oDB3D.RollObjectRight(m_iId, Angle)
End If
End Sub
Public Sub TurnLeft(ByVal Angle As Single)
If m_bLoaded Then
oDB3D.TurnObjectLeft(m_iId, Angle)
End If
End Sub
Public Sub TurnRight(ByVal Angle As Single)
If m_bLoaded Then
oDB3D.TurnObjectRight(m_iId, Angle)
End If
End Sub
Public Sub PointAt(ByVal AtX As Single, ByVal AtY As Single, ByVal AtZ As Single)
If m_bLoaded Then
oDB3D.PointObject(m_iId, AtX, AtY, AtZ)
End If
End Sub
#End Region
#Region "Creation & Destruction"
Public Function Load(ByVal FileName As String, ByVal MyID As Integer) As Boolean
If m_bLoaded Or (oDB3D.ObjectExist(MyID) = 1) Then Return False
oDB3D.LoadObject(FileName, MyID)
m_iId = MyID
m_bLoaded = (oDB3D.ObjectExist(MyID) = 1)
Return (oDB3D.ObjectExist(MyID) = 1)
End Function
Public Function Clone(ByVal SourceId As Integer, ByVal MyId As Integer) As Boolean
If m_bLoaded Then Return False
If oDB3D.ObjectExist(MyId) = 1 Then Return False
If Not oDB3D.ObjectExist(SourceId) = 1 Then Return False
oDB3D.CloneObject(MyId, SourceId)
m_iSourceId = SourceId
m_bCloned = True
m_bLoaded = (oDB3D.ObjectExist(MyId) = 1)
Return (oDB3D.ObjectExist(MyId) = 1)
End Function
Public Function Instance(ByVal SourceId As Integer, ByVal MyId As Integer) As Boolean
If m_bLoaded Then Return False
If oDB3D.ObjectExist(MyId) = 1 Then Return False
If Not oDB3D.ObjectExist(SourceId) = 1 Then Return False
oDB3D.InstanceObject(MyId, SourceId)
m_iSourceId = SourceId
m_bCloned = False
m_bLoaded = (oDB3D.ObjectExist(MyId) = 1)
Return (oDB3D.ObjectExist(MyId) = 1)
End Function
Public ReadOnly Property SourceObjectId() As Integer
Get
Return m_iSourceId
End Get
End Property
Public ReadOnly Property Cloned() As Boolean
Get
Return m_bCloned
End Get
End Property
Public Function Delete() As Boolean
Dim Temp As Integer
If Not m_bLoaded Then Return True
oDB3D.DeleteObject(m_iId)
m_bLoaded = False
Temp = m_iId
ResetProperties()
Return (oDB3D.ObjectExist(Temp) = 0)
End Function
Public ReadOnly Property Loaded() As Boolean
Get
Return m_bLoaded
End Get
End Property
Public Property ID() As Integer
Get
Return m_iId
End Get
Set(ByVal Value As Integer)
m_iId = Value
End Set
End Property
Public Function Save(ByVal FileName As String) As Boolean
If Dir(FileName) <> "" Then Return False
If Not m_bLoaded Then Return False
oDB3D.SaveObject(FileName, m_iId)
Return Not (Dir(FileName) <> "")
End Function
Private Sub ResetProperties()
m_iId = -1
m_iTextureId = -1
m_iSourceId = -1
m_bCloned = False
m_bZDepthEnabled = True
m_bZReadEnabled = True
m_bZWriteEnabled = True
m_iFadePct = 100
m_bLockedToScreen = False
m_nUScale = 1.0
m_nVScale = 1.0
m_nAlphaPct = 100
m_bCollisionEnabled = False
m_oCollisionMode = CollisionModesEnum.Undefined
m_bAmbientReactive = True
m_bFogReactive = True
m_bLightReactive = True
m_bCullingEnabled = True
m_oAmbience = Nothing
m_oDiffuse = Nothing
m_oEmissive = Nothing
m_oSpecular = Nothing
m_oFilteringMode = TextureFilteringModesEnum.None
m_nSmoothingPct = 0
m_bWireframe = False
End Sub
#End Region
#Region "Animation"
Public Sub LoopAnim(Optional ByVal FromFrame As Integer = -1, Optional ByVal ToFrame As Integer = -1)
If FromFrame = -1 Then
oDB3D.LoopObject(m_iId)
Else
If ToFrame = -1 Then
oDB3D.LoopObjectB(m_iId, FromFrame)
Else
oDB3D.LoopObjectC(m_iId, FromFrame, ToFrame)
End If
End If
End Sub
Public Sub PlayAnim(Optional ByVal FromFrame As Integer = -1, Optional ByVal ToFrame As Integer = -1)
If FromFrame = -1 Then
oDB3D.PlayObject(m_iId)
Else
If ToFrame = -1 Then
oDB3D.PlayObjectB(m_iId, FromFrame)
Else
oDB3D.PlayObjectC(m_iId, FromFrame, ToFrame)
End If
End If
End Sub
Public Property CurrentFrame() As Integer
Set(ByVal Value As Integer)
If m_bLoaded Then
oDB3D.SetObjectFrame(m_iId, Value)
End If
End Set
Get
If Not m_bLoaded Then Return -1
Return oDB3D.ObjectFrame(m_iId)
End Get
End Property
Public Property InterpolationPercentage() As Single
Get
If Not m_bLoaded Then Return -1
Return oDB3D.ObjectInterpolation(m_iId)
End Get
Set(ByVal Value As Single)
If m_bLoaded Then
oDB3D.SetObjectInterpolation(m_iId, Value)
End If
End Set
End Property
Public ReadOnly Property Looping() As Boolean
Get
If Not m_bLoaded Then Return False
Return (oDB3D.ObjectLooping(m_iId) = 1)
End Get
End Property
Public ReadOnly Property Playing() As Boolean
Get
If Not m_bLoaded Then Return False
Return (oDB3D.ObjectPlaying(m_iId) = 1)
End Get
End Property
Public Property AnimSpeed() As Single
Get
If Not m_bLoaded Then Return -1
Return oDB3D.ObjectSpeed(m_iId)
End Get
Set(ByVal Value As Single)
If m_bLoaded Then
oDB3D.SetObjectSpeed(m_iId, CInt(Value))
End If
End Set
End Property
#End Region
#Region "Limbs"
Public Function AddLimb(ByVal MeshId As Integer) As Boolean
Dim pre As Integer
If oDB3D.MeshExist(MeshId) <> 1 Then Return False
pre = oDB3D.LimbCount(m_iId)
oDB3D.AddLimb(m_iId, pre, MeshId)
Return (oDB3D.LimbCount(m_iId) = pre + 1)
End Function
Public ReadOnly Property LimbCount()
Get
If Not m_bLoaded Then Return -1
Return oDB3D.LimbCount(m_iId)
End Get
End Property
Public Function RemoveLimb(ByVal LimbId As Integer) As Boolean
If Not m_bLoaded Then Return False
If oDB3D.LimbExist(m_iId, LimbId) = 0 Then Return False
oDB3D.RemoveLimb(m_iId, LimbId)
Return (oDB3D.LimbExist(m_iId, LimbId) = 0)
End Function
#End Region
#Region "Appearance"
Public Sub Hide()
If m_bLoaded Then
m_bHidden = True
oDB3D.HideObject(ID)
End If
End Sub
Public Sub Show()
If m_bLoaded Then
m_bHidden = False
oDB3D.ShowObject(ID)
End If
End Sub
Public ReadOnly Property Hidden() As Boolean
Get
Return m_bHidden
End Get
End Property
Public Property TextureId() As Integer
Get
Return m_iTextureId
End Get
Set(ByVal Value As Integer)
If oDBImage.ImageExist(Value) <> 1 Then Exit Property
If m_bLoaded Then
oDB3D.TextureObject(ID, Value)
m_iTextureId = Value
End If
End Set
End Property
Public ReadOnly Property GhostingMode() As Integer
Get
Return m_iGhostingMode
End Get
End Property
Public Sub Ghost(ByVal GhostMode As Integer)
If m_bLoaded Then
oDB3D.GhostObjectOnB(m_iId, GhostMode)
m_iGhostingMode = GhostMode
End If
End Sub
Public Sub Unghost()
If m_bLoaded Then
m_iGhostingMode = -1
oDB3D.GhostObjectOff(m_iId)
End If
End Sub
Public Sub SetColor(ByVal NewColor As Color)
If m_bLoaded Then
oDB3D.ColorObject(m_iId, NewColor.ToArgb)
End If
End Sub
Public Property ZDepthEnabled() As Boolean
Get
Return m_bZDepthEnabled
End Get
Set(ByVal Value As Boolean)
If m_bLoaded Then
If Value Then
oDB3D.EnableObjectZDepth(m_iId)
Else
oDB3D.DisableObjectZDepth(m_iId)
End If
End If
End Set
End Property
Public Property ZReadEnabled() As Boolean
Get
Return m_bZReadEnabled
End Get
Set(ByVal Value As Boolean)
If m_bLoaded Then
If Value Then
oDB3D.EnableObjectZRead(m_iId)
Else
oDB3D.DisableObjectZRead(m_iId)
End If
End If
End Set
End Property
Public Property ZWriteEnabled() As Boolean
Get
Return m_bZWriteEnabled
End Get
Set(ByVal Value As Boolean)
If m_bLoaded Then
If Value Then
oDB3D.EnableObjectZWrite(m_iId)
Else
oDB3D.DisableObjectZWrite(m_iId)
End If
End If
End Set
End Property
Public Property FadePrecentage() As Integer
Get
Return m_iFadePct
End Get
Set(ByVal Value As Integer)
If m_bLoaded Then
oDB3D.FadeObject(m_iId, Value)
m_iFadePct = Value
End If
End Set
End Property
Public Property UScale() As Single
Get
Return m_nUScale
End Get
Set(ByVal Value As Single)
If m_bLoaded Then
oDB3D.ScaleObjectTexture(m_iId, Value, 1.0)
m_nUScale = Value
End If
End Set
End Property
Public Property VScale() As Single
Get
Return m_nVScale
End Get
Set(ByVal Value As Single)
If m_bLoaded Then
oDB3D.ScaleObjectTexture(m_iId, 1.0, Value)
m_nVScale = Value
End If
End Set
End Property
Public Property AlphaPercentage() As Single
Get
Return m_nAlphaPct
End Get
Set(ByVal Value As Single)
If m_bLoaded Then
oDB3D.SetAlphaMappingOn(m_iId, Value)
m_nAlphaPct = Value
End If
End Set
End Property
Public Property Ambience() As Color
Get
Return m_oAmbience
End Get
Set(ByVal Value As Color)
If m_bLoaded Then
oDB3D.SetObjectAmbience(m_iId, Value.ToArgb)
m_oAmbience = Value
End If
End Set
End Property
Public Property AmbientReactive() As Boolean
Get
Return m_bAmbientReactive
End Get
Set(ByVal Value As Boolean)
If m_bLoaded Then
oDB3D.SetObjectAmbient(m_iId, Value)
m_bAmbientReactive = Value
End If
End Set
End Property
Public Property CullingEnabled() As Boolean
Get
Return m_bCullingEnabled
End Get
Set(ByVal Value As Boolean)
If m_bLoaded Then
If Value Then
oDB3D.SetObjectCull(m_iId, 1)
Else
oDB3D.SetObjectCull(m_iId, 0)
End If
m_bCullingEnabled = Value
End If
End Set
End Property
Public Property Diffuse() As Color
Get
Return m_oDiffuse
End Get
Set(ByVal Value As Color)
If m_bLoaded Then
m_oDiffuse = Value
oDB3D.SetObjectDiffuse(m_iId, Value.ToArgb)
End If
End Set
End Property
Public Property Emissive() As Color
Get
Return m_oEmissive
End Get
Set(ByVal Value As Color)
If m_bLoaded Then
m_oEmissive = Value
oDB3D.SetObjectEmissive(m_iId, Value.ToArgb)
End If
End Set
End Property
Public Property TextureFilteringMode() As TextureFilteringModesEnum
Get
Return m_oFilteringMode
End Get
Set(ByVal Value As TextureFilteringModesEnum)
If m_bLoaded Then
oDB3D.SetObjectFilter(m_iId, Value)
m_oFilteringMode = Value
End If
End Set
End Property
Public Property FogReactive() As Boolean
Get
Return m_bFogReactive
End Get
Set(ByVal Value As Boolean)
If m_bLoaded Then
oDB3D.SetObjectFog(m_iId, Value)
m_bFogReactive = Value
End If
End Set
End Property
Public Property LightReactive() As Boolean
Get
Return m_bLightReactive
End Get
Set(ByVal Value As Boolean)
If m_bLoaded Then
oDB3D.SetObjectLight(m_iId, Value)
m_bLightReactive = Value
End If
End Set
End Property
Public Property SmoothingPercentage() As Single
Get
Return m_nSmoothingPct
End Get
Set(ByVal Value As Single)
If m_bLoaded Then
m_nSmoothingPct = Value
oDB3D.SetObjectSmoothing(m_iId, Value)
End If
End Set
End Property
Public Property Specular() As Color
Get
Return m_oSpecular
End Get
Set(ByVal Value As Color)
If m_bLoaded Then
m_oSpecular = Value
oDB3D.SetObjectSpecular(m_iId, Value.ToArgb)
End If
End Set
End Property
Public Property Wireframe() As Boolean
Get
Return m_bWireframe
End Get
Set(ByVal Value As Boolean)
If m_bLoaded Then
oDB3D.SetObjectWireframe(m_iId, Value)
m_bWireframe = Value
End If
End Set
End Property
#End Region
#Region "Collision"
Public Property CollisionMode() As CollisionModesEnum
Get
Return m_oCollisionMode
End Get
Set(ByVal Value As CollisionModesEnum)
If m_bLoaded Then
Select Case Value
Case CollisionModesEnum.Boxes
oDB3D.SetObjectCollisionToBoxes(m_iId)
oDB3D.SetObjectCollisionOn(m_iId)
Case CollisionModesEnum.Polygons
oDB3D.SetObjectCollisionToPolygons(m_iId)
oDB3D.SetObjectCollisionOn(m_iId)
Case CollisionModesEnum.Spheres
oDB3D.SetObjectCollisionToSpheres(m_iId)
oDB3D.SetObjectCollisionOn(m_iId)
Case CollisionModesEnum.Undefined
oDB3D.SetObjectCollisionOff(m_iId)
End Select
m_oCollisionMode = Value
End If
End Set
End Property
#End Region
End Class
Intel Pentium 4, 3.4GHz, 1280MB RAM, NVidia Quadro FX3000/256MB, 240GB HD, XP Pro