Imports Irrlicht
Imports Irrlicht.Core
Imports Irrlicht.Scene
Imports Irrlicht.Video
Imports Irrlicht.GUI
Imports Irrlicht.IO
Imports System.Math
Public Class IsoCam
Public m_pTargetNode As ISceneNode
Public m_cam As ICameraSceneNode
Public lastTargetPos As Vector3D
Public m_height As Single 'distance above object camera tries to float at
Public m_leash As Single 'max distance object can be from camera before it moves
Public m_speed As Single
Public h_tolerance As Single
Public h_delta As Single
Public Sub INITCamera(ByVal targetNode As ISceneNode, ByVal smgr As ISceneManager, ByVal height As Single, ByVal leash As Single, ByVal speed As Single)
m_speed = speed
m_height = height
m_leash = leash
'create a camera
lastTargetPos = targetNode.Position
m_cam = smgr.AddCameraSceneNode(Nothing, New Vector3D(0, lastTargetPos.Y + m_height, lastTargetPos.Z + m_leash), lastTargetPos, -1)
m_pTargetNode = targetNode
End Sub
Public Sub MoveCamera(ByVal cameranode As ISceneNode, ByVal spd As Integer)
Dim facing As Vector3D
facing = New Vector3D(Sin(cameranode.Rotation.Y * PI / 180.0F), 0, Cos(cameranode.Rotation.Y * PI / 180.0F))
facing.RotateXZBy(-90, New Vector3D(0, 0, 0))
facing.Normalize()
Dim newPos As Vector3D
newPos = New Vector3D((facing.X * spd) + cameranode.Position.X, (facing.Y * spd) + cameranode.Position.Y, (facing.Z * spd) + cameranode.Position.Z)
cameranode.Position = newPos
End Sub
Public Sub Update()
Dim currTargetPos As Vector3D = m_pTargetNode.Position
'if too far away, move camera closer
Dim camToTarg As Vector3D
camToTarg.X = currTargetPos.X - m_cam.Position.X
camToTarg.Y = currTargetPos.Y - m_cam.Position.Y
camToTarg.Z = currTargetPos.Z - m_cam.Position.Z
'leash is only in the X-Z plane, so only count distance using X and Z
Dim xzDist As Vector2D
xzDist = New Vector2D(camToTarg.X, camToTarg.Z)
If (xzDist.GetLength > m_leash) Then
camToTarg = New Vector3D(xzDist.X, 0, xzDist.Y)
camToTarg = camToTarg.Normalize()
'set X-Z position
m_cam.Position = New Vector3D(m_cam.Position.X + camToTarg.X, m_cam.Position.Y + camToTarg.Y, m_cam.Position.Z + camToTarg.Z) 'move closer
'set Y position
h_tolerance = m_height / 10 'the ammount of leway given to how close we need to be to the right height
h_delta = m_cam.Position.Y - currTargetPos.Y + m_height 'distance from prefered height position
End If
If (m_cam.Position.Y < (currTargetPos.Y + m_height) - h_tolerance) Then
m_cam.Position = New Vector3D(m_cam.Position.X, m_cam.Position.Y + h_delta / 2, m_cam.Position.Z)
ElseIf (m_cam.Position.Y > (currTargetPos.Y + m_height) + h_tolerance) Then
m_cam.Position = New Vector3D(m_cam.Position.X, m_cam.Position.Y - h_delta / 2, m_cam.Position.Z)
End If
m_cam.Target = New Vector3D(currTargetPos.X, currTargetPos.Y, currTargetPos.Z) 'look at Target position
lastTargetPos = currTargetPos
End Sub
End Class
////the litle demo for the test
Imports Irrlicht
Imports Irrlicht.Core
Imports Irrlicht.Scene
Imports Irrlicht.Video
Imports Irrlicht.GUI
Imports Irrlicht.IO
Module Module1
Public device As New IrrlichtDevice(DriverType.OPENGL, New Dimension2D(640, 480), 16, False, True, False)
Public MeshPlayer As IAnimatedMesh = device.SceneManager.GetMesh("..\..\..\media\faerie.md2")
Public Player As IAnimatedMeshSceneNode = device.SceneManager.AddAnimatedMeshSceneNode(MeshPlayer, Nothing, -1)
Public camm As New IsoCam
Public Xc, Yc, Zc, Xc2, Yc2, Zc2 As Single
Sub Main()
device.EventReceiver = New MyEventReceiver
Dim MeshLand As IAnimatedMesh = device.SceneManager.GetMesh("..\..\..\media\land.3ds")
Dim Land As ISceneNode = device.SceneManager.AddOctTreeSceneNode(MeshLand, Nothing, -1)
Dim tex As ITexture = device.VideoDriver.GetTexture("C:\zip\irrlicht\vb\IrrTUTORIAL\hiiplane\wall.bmp")
Dim tex2 As ITexture = device.VideoDriver.GetTexture("..\..\..\media\faerie2.bmp")
Xc = -50 : Yc = 80 : Zc = -350
Land.Position = New Core.Vector3D(0, 7, 0)
Land.SetMaterialTexture(0, tex)
Land.SetMaterialFlag(MaterialFlag.LIGHTING, False)
Player.Position = New Core.Vector3D(Xc, Yc, Zc)
Player.SetMaterialTexture(0, tex2)
Player.SetMaterialFlag(MaterialFlag.LIGHTING, False)
Player.Scale = New Vector3D(3, 3, 3)
Player.SetMD2Animation("stand")
'stand,attack,pain,run,jump,flip,salute,taunt,wave,point,crstnd,crwalk,crattak
'crpain,crdeath,death
camm.INITCamera(Player, device.SceneManager, 200, 150, 2)
While device.Run() = True
If device.WindowActive Then
device.VideoDriver.BeginScene(True, True, New Color(0, 100, 100, 100))
camm.Update()
End If
device.SceneManager.DrawAll()
device.VideoDriver.EndScene()
End While
End Sub
End Module
Public Class MyEventReceiver
Implements IEventReceiver
Public Function OnEvent(ByVal e As [Event]) As Boolean Implements IEventReceiver.OnEvent
If e.Type = EventType.KeyInput Then
'37=leftkey,38=upkey,39=rightkey,40=downkey,
If e.Key = 27 Then End
If e.Key = 39 Then
Player.Rotation = New Vector3D(0, Player.Rotation.Y + 10, 0)
End If
If e.Key = 37 Then
Player.Rotation = New Vector3D(0, Player.Rotation.Y - 10, 0)
End If
If e.Key = 38 Then
Player.SetMD2Animation("run")
camm.MoveCamera(Player, 4)
End If
Return True
End If
Return False
End Function
End Class
iso camera class in vb.net
-
- Posts: 41
- Joined: Sat Jan 15, 2005 8:03 pm
- Contact:
I might still be a bit new to this VB.NET thing however, upon successful compiling, and then running I get this error message:
I even added Irrlicht.NET.DLL to the references and this is somewhat mind boggling to me.Unhandled Exception: System.TypeInitializationException: The type initializer fo
r "Module1" threw an exception. ---> System.IO.FileNotFoundException: File or as
sembly name Irrlicht.NET, or one of its dependencies, was not found.
File name: "Irrlicht.NET"
at Module1..cctor()
=== Pre-bind state information ===
LOG: DisplayName = Irrlicht.NET, Version=0.11.2014.30590, Culture=neutral, Publi
cKeyToken=null
(Fully-specified)
LOG: Appbase = C:\Documents and Settings\DynamiteSoul.XXXX\My Documents\SharpDev
elop Projects\viewme\bin\Debug\
LOG: Initial PrivatePath = NULL
Calling assembly : viewme, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
.
===
LOG: Application configuration file does not exist.
LOG: Policy not being applied to reference at this time (private, custom, partia
l, or location-based assembly bind).
LOG: Post-policy reference: Irrlicht.NET, Version=0.11.2014.30590, Culture=neutr
al, PublicKeyToken=null
LOG: Attempting download of new URL file:///C:/Documents and Settings/DynamiteSo
ul.XXXX/My Documents/SharpDevelop Projects/viewme/bin/Debug/Irrlicht.NET.DLL.
--- End of inner exception stack trace ---
at Module1.Main()
Press any key to continue . . .