feanor91
03-08-2008 08:19:04
Hi
I try to implement a such behavior un VB Express 2008 and mogrenewt.
I follow examples found here, adapted to VB but it didn't work, apparently my cambody didn't move. Here my code :
First, variables :
Second the callaback, and various functions (the callaback function seems never be called...:
Then my initNewton function (because I load an OSM Scene, so I seperate the 2 initialisation scene and newton :
I dettach tne reattach camra because it's intialised by osmloader before.
And, finally, my movement, I do it in tumer because I don't use MOIS :
When I press Up arrow, I have no movement at all...What I did wrong?
And finaly, you can find all my project here :
http://rapidshare.com/files/134230788/o ... n.rar.html
I put an osm scene to view in Kites directory. Just a word about project, it is an simple oFusion scene viewer that I wrote as my first ogre project to test functionality that I will need in another project. By now, I manage to do all I want, exept detection collision with cam.
And therefore, I will post it somewhere to help people to understand how to implement ogre in vb .net, because, by now, i found there is so few (well, i found nothing) example in VB.
I someone can help me, it will be great.
Best regards.
I try to implement a such behavior un VB Express 2008 and mogrenewt.
I follow examples found here, adapted to VB but it didn't work, apparently my cambody didn't move. Here my code :
First, variables :
'Déclarations pour Newton
Private myWorld As World 'Le monde physique
Private Gravity As Single = -9.8 'Et oui, on aura un poid...
Private CamSize As Vector3 = New Vector3(10, 10, 10) 'La taille de la caméra
Private CamNode As SceneNode 'Le node de la caméra
Private CamViewNode As SceneNode
Private CamBody As Body 'Le corps physique de la caméra
Private CamColl As CollisionPrimitives.Ellipsoid 'Le type de collision
Private NoMovement As Boolean = True
Second the callaback, and various functions (the callaback function seems never be called...:
Private Function get_body_position(ByVal bod As Body) As Vector3 'get the position of the body
Dim orient As Quaternion
Dim pos As Vector3
bod.GetPositionOrientation(pos, orient)
Return pos
End Function
Private Function get_body_orientation(ByVal bod As Body) As Quaternion ' get the orientation of the body {
Dim orient As Quaternion
Dim pos As Vector3
bod.GetPositionOrientation(pos, orient)
Return orient
End Function
Private Sub camera_force_callback(ByVal Corps As Body)
Dim masse As Single
Dim inertie As Vector3
Dim Force As Vector3
Corps.GetMassMatrix(masse, inertie)
Force = New Vector3(0, Gravity, 0)
Force *= masse
Corps.AddForce(Force)
'Corps.Omega = New Vector3(0, CameraRotationX, 0)
End Sub
Then my initNewton function (because I load an OSM Scene, so I seperate the 2 initialisation scene and newton :
Private Sub InitNewton()
'Initialisation de Newton pour la gestion des collision caméras, je n'y suis pas arrivé avec les RayScenQuery...
myWorld = New World 'le monde physique
Dim cam_size As Vector3 = New Vector3(10, 10, 10)
Dim cam_mass As Single = 40
'MogreNewt.Debugger.Instance.Init(mySceneManager)
'using the new "SceneParser" TreeCollision primitive. this will automatically parse an entire tree of
'SceneNodes (parsing all children), and add collision for all meshes in the tree.
Dim stat_col As MogreNewt.CollisionPrimitives.TreeCollisionSceneParser = New MogreNewt.CollisionPrimitives.TreeCollisionSceneParser(myWorld)
stat_col.ParseScene(mySceneManager.RootSceneNode, True)
Dim bod As MogreNewt.Body = New MogreNewt.Body(myWorld, stat_col)
stat_col.Dispose()
bod.AttachToNode(mySceneManager.RootSceneNode)
bod.SetPositionOrientation(New Vector3(0.0, 0.0, 0.0), Quaternion.IDENTITY)
'Collision of camera
CamNode = mySceneManager.RootSceneNode.CreateChildSceneNode("CamNode")
Me.CamNode.SetScale(Me.CamSize)
Me.CamColl = New CollisionPrimitives.Ellipsoid(myWorld, Me.CamSize)
Me.CamBody = New Body(myWorld, Me.CamColl)
Me.CamColl.Dispose()
Me.CamBody.AttachToNode(Me.CamNode)
Dim cam_inertia As Vector3 = MomentOfInertia.CalcEllipsoidSolid(cam_mass, cam_size)
Me.CamBody.SetMassMatrix(cam_mass, cam_inertia)
AddHandler Me.CamBody.ForceCallback, AddressOf camera_force_callback
Me.CamBody.AutoFreeze = False
'create an upvector. This forces the body to rotate just in the X and Z axes.
Dim uv2 As BasicJoints.UpVector = New BasicJoints.UpVector(myWorld, Me.CamBody, Vector3.UNIT_Y)
Me.CamViewNode = Me.CamNode.CreateChildSceneNode("CamViewNode", New Vector3(0, 5, 0))
'Me.CamViewNode.Position = mySceneManager.GetSceneNode(myCamera.Name).Position
mySceneManager.RootSceneNode.DetachObject(myCamera)
Me.CamViewNode.AttachObject(myCamera)
'myCamera.Position = New Vector3(0, -5, 0)
'Me.CamViewNode.Position = New Vector3(0, 0, 0)
End Sub
I dettach tne reattach camra because it's intialised by osmloader before.
And, finally, my movement, I do it in tumer because I don't use MOIS :
Private Sub timerRendu_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerRendu.Tick
'C'est ici que ce fait le rendu et différents évènements comme la gestion du clavier par exemple
Dim PasdeMouvement As Boolean = True
'on réinitilise les valeurs de mouvement
myTranslation.z = 0
myTranslation.x = 0
myTranslation.y = 0
'et on teste les touches.....
If GetAsyncKeyState(Keys.Up) Then
'myTranslation.z += -TRANSLATE
Dim dep As Vector3
dep.x = 0
dep.y = 1
dep.z = 0
Dim direction As Vector3 = get_body_orientation(CamBody) * Vector3.NEGATIVE_UNIT_Z
CamBody.Velocity = New Vector3(0, 20, 0) '(CamBody.Velocity * dep) + (direction * 30)
'CamBody.AddForce(New Vector3(10, 10, 10))
PasdeMouvement = False
End If
lblBodX.Text = CamBody.Position.x
lblBodY.Text = CamBody.Position.y
lblBodZ.Text = CamBody.Position.z
If GetAsyncKeyState(Keys.Down) Then
myTranslation.z += TRANSLATE
End If
If GetAsyncKeyState(Keys.Left) Then
myTranslation.x += -TRANSLATE
End If
If GetAsyncKeyState(Keys.Right) Then
myTranslation.x += TRANSLATE
End If
If GetAsyncKeyState(Keys.PageUp) Then
myTranslation.y += TRANSLATE
End If
If GetAsyncKeyState(Keys.PageDown) Then
myTranslation.y += -TRANSLATE
End If
'Et on déplace la caméra
myCamera.Position += myCamera.Orientation * myTranslation * timeSinceLastFrame
'Affichage des infos de rendu
Try
lblAvg.Text = "FPS moyennes: " & Mogre.StringConverter.ToString(MyWindow.AverageFPS, 3)
lblCurr.Text = "FPS courantes: " & Mogre.StringConverter.ToString(MyWindow.LastFPS, 3)
lblBest.Text = "Meilleures FPS: " & Mogre.StringConverter.ToString(MyWindow.BestFPS, 3)
lblWorst.Text = "Pires FPS: " & Mogre.StringConverter.ToString(MyWindow.WorstFPS, 3)
lblNumTris.Text = "Triangles: " & Mogre.StringConverter.ToString(MyWindow.TriangleCount)
lblNumBatches.Text = "Nombre de Batch: " & Mogre.StringConverter.ToString(MyWindow.BatchCount)
Catch ex As Exception
End Try
'et on rend une frame
myRoot.RenderOneFrame()
If SceneNodeSelected Is Nothing Then
'si un objet est sélectionné ou pas, on active ou désactive le panneau de paramètre
grpParamObjet.Enabled = False
cmdResetEtat.Enabled = False
Else
grpParamObjet.Enabled = True
cmdResetEtat.Enabled = True
End If
End Sub
When I press Up arrow, I have no movement at all...What I did wrong?
And finaly, you can find all my project here :
http://rapidshare.com/files/134230788/o ... n.rar.html
I put an osm scene to view in Kites directory. Just a word about project, it is an simple oFusion scene viewer that I wrote as my first ogre project to test functionality that I will need in another project. By now, I manage to do all I want, exept detection collision with cam.
And therefore, I will post it somewhere to help people to understand how to implement ogre in vb .net, because, by now, i found there is so few (well, i found nothing) example in VB.
I someone can help me, it will be great.
Best regards.