Problem to do a FPS camara mogrenewt VB express 2008

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 :

'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.

feanor91

03-08-2008 20:57:22

Hi

Well, I found something, I add myWorld.Update(step) ine my timer update...So, now, my camera move by 113 units, on X oy Z, but no more....when reaching 113 units on either axes, the callback function cease to be called and my camera stop...I cant move backward or left ou forwaard or right, in fact myworld.update cease to work....

Why?

A clue? If I multiply mu cam size by 10 (passing it to 1000), I multyply mu movement by about 2 (200 units) but the symptom are the same, all stop....

I'm suck!

ProfesorX

04-08-2008 17:28:03

when reaching 113 units on either axes, the callback function cease to be called and my camera stop

By default, in newton/OgreNewt the size of the world is (100, 100, 100)
You must use world.SetWorldSize() to set a bigger world.

feanor91

04-08-2008 17:53:09

Hi,

Yeah I found this. Thanks to notice. By now, I'm searching to understand why my object in my world let passes camera trough them and why my cam start to rotate like a crazy thing by moments. Newton is not easy to understand, I must say.