I'm working at getting the attach to bone sample to work in VB.NET Exprees 2008, and have had some problems.
1) Had an namespace error, which ended up being caused not by the name of the project, but by a variable for the (matrix or mouse?) "My As Long". My is a Key word so its a no,no! I changed the M to an N and the error went away. But I have a question about that to the extent that I don't know if the internal TV3D code requires the use of "My". I've changed the other "My"'s in the rest of the project to reflect the use of Ny, but have other errors to resolve before I can get a working build to find out if the matrix or the mouse works!
Q) Does anyone know if using Ny in place of My will work?
2) I'm currently stuck on two errors
'Here we set the object to the matrix we got in the previouse step !
'Weapon(0).SetMatrix(Matrix(0))
Weapon(0).SetMatrix(Matrix(0)) <-- (Matrix(0)) Structure 'MTV3D65.TV_3DMATRIX' cannot be indexed because it has no default property.
Weapon(1).SetMatrix(Matrix(1)) <-- (Matrix(1)) Structure 'MTV3D65.TV_3DMATRIX' cannot be indexed because it has no default property.
Obviously I've missed something, but right now I haven't got a clue as to what I have missed. Can anyone point me in the right direction?
Here's the code:(hope it fits)
Option Strict Off
Option Explicit On
' Import the MTV3D65 library.
Imports MTV3D65
Public Class frmMain
Inherits System.Windows.Forms.Form
' ________________________________________________________________________
' TRUEVISION 6.5 (web: http://www.truevision3d.com)
' ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
' Sample : Attach To Bone
' ŻŻŻŻŻŻŻŻŻŻŻ
' Description : This sample demonstrates the ability to attach objects to your models etc.
' Here we attach the two Sword blades to this model !
' TrueVision3D Sample - By Arli Mujkic - Www.TrueVision3D.Com -
' Enjoy !
'
' Tiny.x Model: 6000 + Polys !
' Sword.x Model: 700 + Polys !
'
' NOTE:THE SWORD IS NOT TO BE REDISTRUBUTED IT BELONGS TO DOMINUS ONLINE,
' THANKS TO THE DOMINUS ONLINE TEAM FOR BORROWING US THE MODEL FOR THIS TUTORIAL !
' YOU CAN VISIT THEM AT WWW.DOMINUSONLINE.COM
'
' Any Comments or suggestion, please e-mail us at: sample@truevision3d.com
'
'
' Force explicit declarations
'
'
' TV Variables.
Public TV As TVEngine
Public Scene As TVScene
Public Inp As TVInputEngine
Public Globals As TVGlobals
Public Actor As TVActor
Public Weapon(1) As TVMesh
'Public Matrix(1) As D3DXMATRIX
'Public Matrix(1) As TV_3DMATRIX
Public Matrix As TV_3DMATRIX
'Public Mx As Long, My As Long ' My is a key word bad thing!
Public Mx As Long, Ny As Long
Public AngleX As Single, AngleY As Single, AngleYz As Single, AngleXs As Single, AngleYs As Single, AngleZs As Single
Public Mb1 As Integer, Mb2 As Integer, Mb3 As Integer
Public bDoLoop As Boolean
'Public finished As Boolean
Public i As Integer
Declare Function GetFocus Lib "user32" () As Integer
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.SuspendLayout()
'
'frmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(632, 453)
Me.Name = "frmMain"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "TV3D SDK 6.5 AttachToBone Sample"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create the TV Interface first:
TV = New TVEngine
' Set the debug file/options.
' Do this before the 3D init so it can log any errors found during init.
TV.SetDebugMode(True, True)
TV.SetDebugFile(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\debugfile.txt")
' Set the search directory of the objects, textures, ...
TV.SetSearchDirectory(System.IO.Path.GetDirectoryName(Application.ExecutablePath))
' After setting the beta-key/license its time to init the engine:
TV.Init3DWindowed(Me.Handle, True)
'Set Antialiasing Setting to 2 Samples.
'To smooth out any jagged edges in the scene.
TV.SetAntialiasing(True, CONST_TV_MULTISAMPLE_TYPE.TV_MULTISAMPLE_2_SAMPLES)
' Something good to do is to enable the auto-resize feature:
' Get the default viewport and set autoresize to true for it:
TV.GetViewport.SetAutoResize(True)
' Lets display the FPS:
TV.DisplayFPS(True)
' Set the prefered angle system:
TV.SetAngleSystem(MTV3D65.CONST_TV_ANGLE.TV_ANGLE_DEGREE)
' Now after we are done initializing the TVEngine component lets continue:
' Create any other components after TV init.
Scene = New TVScene
Actor = New TVActor
Globals = New TVGlobals
Weapon(1) = New TVMesh
'Matrix(1) = New D3DXMATRIX
'Matrix(1) = New TV_3DMATRIX
Matrix = New TV_3DMATRIX
' Input has an additional init method to call.
Inp = New TVInputEngine
' Lets init both keyboard and mouse:
Inp.Initialize(True, True)
' Now we have setup the most basic of components.
' Something to think about, if the component has a diffrent construct method
' then the Set Object = New TV<NAME>, use that one instead.
' For example:
' Dim Mesh as TVMesh;
' Mesh = Scene.CreateMeshBuilder "MyMesh" <- Instead of Set Mesh = new TVMesh
' Same goes for RenderSurface, Viewport etc.
Actor = Scene.CreateActor("tiny")
Actor.LoadXFile("..\..\tiny.x")
Actor.SetName("tiny")
Actor.SetAnimationID(0)
'Actor.PlayAnimation(2000)
Actor.PlayAnimation(0.2)
Actor.SetMaterial(0)
Actor.SetScale(0.08, 0.08, 0.08)
Actor.SetRotation(-90, 130, 0)
Actor.SetPosition(0, -25, -45)
Actor.SetScale(0.1, 0.1, 0.1)
''Dim i As Integer
'For Me.i = 0 To 1
' Weapon(Me.i) = Scene.CreateMeshBuilder("Weapon")
' Weapon(Me.i).LoadXFile("..\..\sword.x")
' Weapon(Me.i).SetMaterial(0)
' 'Weapon(i).SetScale(2, 2, 2)
' Weapon(Me.i).SetScale(0.4, 0.4, 0.4)
'Next Me.i
Dim i As Integer
For i = 0 To 1
Weapon(i) = Scene.CreateMeshBuilder("Weapon")
Weapon(Me.i).LoadXFile("..\..\sword.x")
Weapon(i).SetMaterial(0)
'Weapon(i).SetScale(2, 2, 2)
Weapon(i).SetScale(0.4, 0.4, 0.4)
Next i
Scene.SetCamera(0, 0, -100, 0, 0, 0)
'finished = False
'RenderMain()
' Lets setup the Loop:
bDoLoop = True
' Display the Form
Me.Show()
Me.Focus()
Do While bDoLoop
' Check if the application has focus, if yes thats when we process the loop.
If GetFocus = Me.Handle.ToInt32 Then
' The actual render loop:
TV.Clear(False)
'Matrix = New TV_3DMATRIX
'Here you get the boneMatrix where you attach your object on later in the code
'Actor.GetBoneMatrix(boneid,vector,matrix);
'Actor.GetBoneMatrix(31, Vector(0, 0, 0), Matrix(0))
Actor.GetBoneMatrix(31)
Globals.Vector(0, 0, 0)
Actor.GetMatrix()
'Actor.GetBoneMatrix(19, Vector(0, 0, 0), Matrix(1))
Actor.GetBoneMatrix(19)
Globals.Vector(0, 0, 0)
Actor.GetMatrix()
'Here we set the object to the matrix we got in the previouse step !
'Weapon(0).SetMatrix(Matrix(0))
Weapon(0).SetMatrix(Matrix(0))
Weapon(1).SetMatrix(Matrix(1))
'We rotate the weapon so its positions correctly
Weapon(0).RotateY(-90)
Weapon(1).RotateY(90)
'Same thing here, and we move it so she holds it correctly
'For Me.i = 0 To 1
' Weapon(Me.i).RotateZ(-40)
' Weapon(Me.i).MoveRelative(5, 7, 18)
'Next Me.i
For i = 0 To 1
Weapon(i).RotateZ(-40)
Weapon(i).MoveRelative(5, 7, 18)
Next i
'Rendering
Actor.Render()
'For Me.i = 0 To 1
' Weapon(Me.i).Render()
'Next Me.i
For i = 0 To 1
Weapon(Me.i).Render()
Next i
' Render Everything
Scene.RenderAll(True)
TV.RenderToScreen()
' Lets check if the user presses ESC key, if yes we will quit the app.
If Inp.IsKeyPressed(MTV3D65.CONST_TV_KEY.TV_KEY_ESCAPE) Then bDoLoop = False
Else
' So we dont call DoEvents to many times if we arent using full CPU power.
System.Threading.Thread.Sleep(100)
End If
' Process any messages Windows has for the application, do this last:
Application.DoEvents()
Inp.GetMouseState(Mx, Ny, Mb1, Mb2, Mb3)
If Mb1 <> 0 Then
AngleX = AngleX - (Mx * TV.TimeElapsed / 5)
AngleY = AngleY - (Ny * TV.TimeElapsed / 5)
End If
If Mb3 <> 0 Then
AngleYz = AngleYz - (Ny * TV.TimeElapsed / 5)
End If
If Mb2 <> 0 Then
AngleXs = AngleXs - (Mx * TV.TimeElapsed / 5)
AngleYs = AngleYs - (Ny * TV.TimeElapsed / 5)
End If
If Inp.IsKeyPressed(CONST_TV_KEY.TV_KEY_LEFTSHIFT) And (Mb2 <> 0) Then
AngleZs = AngleZs - (Ny * TV.TimeElapsed / 5)
End If
'Restrict the rotations
If AngleX > 40 Then
AngleX = 40
End If
If AngleX < -40 Then
AngleX = -40
End If
If AngleY > 40 Then
AngleY = 40
End If
If AngleY < -40 Then
AngleY = -40
End If
If AngleYz > 40 Then
AngleYz = 40
End If
If AngleYz < -40 Then
AngleYz = -40
End If
If AngleXs > 40 Then
AngleXs = 40
End If
If AngleXs < -40 Then
AngleXs = -40
End If
If AngleYs > 40 Then
AngleYs = 40
End If
If AngleYs < -40 Then
AngleYs = -40
End If
If AngleZs > 40 Then
AngleZs = 40
End If
If AngleZs < -40 Then
AngleZs = -40
End If
'Apply the Angles
Actor.SetBoneRotation(19, AngleXs, AngleYs, AngleZs, True)
Actor.SetBoneRotation(9, AngleX, AngleY, AngleYz, True)
Loop
' Additional Info:
'
' Normally you dont have to keep track of the TV component and free it on closing.
' When you free the TV ATL Interface on close it will automatically clean all the internal
' objects aswell. Such as Mesh's, Textures etc.
' Though it might be good to know you do have the ability to destroy and nil objects
' for re-creation or cleanup during runtime if you want that.
' There are several methods for destroying and cleaning up objects.
' TV<NAME>.Destroy , DestroyAll exists for some objects aswell if it is a Factory of some sort.
' Some other good destroy methods are:
' TVScene.DestroyAllMeshs.
' TVTextureFactory.DeleteAllTextures.
' And others...
' Set TV to Nothing
TV = Nothing
' End the application
End
End Sub
Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
' If we close the application stop the loop.
bDoLoop = False
End Sub
End Class
Picture of last working build...