Problem with PhysX Candy Wrapper

IvanJ147

18-11-2011 13:54:37

Hi all!!
I have a problem with PhysX Candy Wrapper.
I created a scene with maya: http://www.fileden.com/files/2007/8/9/1334751//imgProvaCandy01.jpg
There is only a cube, and its center is in the origin of axis. As you can see in the image, rotation and traslation is set to zero.
Then I created a software with this code:

Private Sub creaScena()
o.mSceneMgr = o.mRoot.CreateSceneManager(Mogre.SceneType.ST_GENERIC)
o.mRootNode = o.mSceneMgr.RootSceneNode

o.mSceneMgr.ShadowTechnique = ShadowTechnique.SHADOWTYPE_STENCIL_ADDITIVE

o.cameras(0) = o.mSceneMgr.CreateCamera("camera")
o.cameras(0).Position = New Mogre.Vector3(147, 83, 94)
o.cameras(0).LookAt(New Mogre.Vector3(0, 20, 0))
o.cameras(0).NearClipDistance = 1
o.viewPorts(0) = o.mRenderWindows(0).AddViewport(o.cameras(0))
o.viewPorts(0).BackgroundColour = New Mogre.ColourValue(0.8, 0.8, 0.8)
o.cameras(0).AutoAspectRatio = True

'creo luce
Dim l As Light
l = o.mSceneMgr.CreateLight("luce")
l.Position = New Vector3(0, 50, 50)
l.SetAttenuation(200, 0.8, 0.01, 0)

phy = Physics.Create
phy.Parameters.SkinWidth = 0.0025
sceneD = New SceneDesc
sceneD.SetToDefault()
sceneD.Gravity = New Vector3(0, -9.8, 0)
scene = phy.CreateScene(sceneD)
scene.Materials(0).Restitution = 0.5
scene.Materials(0).StaticFriction = 0.5
scene.Materials(0).DynamicFriction = 0.5
scene.Simulate(0)


'creo il piano
Dim e As Entity
Dim n As SceneNode
Dim a As ActorDesc
Dim actor As Actor
Dim an As ActorNode
Dim b As BodyDesc

Dim p As Plane = New Plane(Vector3.UNIT_Y, 0)
MeshManager.Singleton.CreatePlane("Terra", "Gruppo risorse", p, 100, 100, 1, 1, True, 10, 5, 5, Vector3.UNIT_Z)
e = o.mSceneMgr.CreateEntity("ground", "Terra")
e.SetMaterialName("matOggettoVerde")
n = o.mRootNode.CreateChildSceneNode("GroundNode", New Vector3(0, 0, 0))
n.AttachObject(e)
n._update(True, True)
a = New ActorDesc
a.Density = 1
a.Body = Nothing
a.GlobalPosition = n.Position
a.GlobalOrientation = n.Orientation.ToRotationMatrix
a.Shapes.Add(New PlaneShapeDesc(p)) ', Vector3.ZERO))
a.Shapes(0).LocalPose.SetScale(New Vector3(1, 1, 1))
actor = scene.CreateActor(a)
actor.Name = "Terreno"
an = New ActorNode(n, actor)
ActorNodeList.Add(an)

e = o.mSceneMgr.CreateEntity("cubo1", "Cubo.mesh")
e.SetMaterialName("matOggettoRosso")
e.CastShadows = True
n = o.mRootNode.CreateChildSceneNode("cuboNode1", New Vector3(0, 80, 0))
n.AttachObject(e)
n._update(True, True)
b = New BodyDesc
b.LinearVelocity = New Vector3(0, 0, 0)
b.AngularVelocity = New Vector3(0.2, 0.8, 0.2)
b.AngularDamping = 0
a = New ActorDesc
a.Density = 1
a.Body = b
a.GlobalPosition = n.Position
a.GlobalOrientation = n.Orientation.ToRotationMatrix
a.Shapes.Add(New BoxShapeDesc((e.BoundingBox.Size)))
actor = scene.CreateActor(a)
actor.Name = "Cubo1"
an = New ActorNode(n, actor)
ActorNodeList.Add(an)
End Sub


ActorNode is definite in this way:

Private Class ActorNode
Private sn As SceneNode
Private a As Actor

Public Sub New(scenenode As SceneNode, actor As Actor)
sn = scenenode
a = actor
End Sub

Public Sub update()
Dim mat As Matrix4 = a.GlobalPose
Dim rot As Quaternion = a.GlobalOrientationQuaternion
sn.Orientation = rot
sn.Position = mat.GetTrans
End Sub
End Class


At last, this is the render loop:

Private Sub EnterRenderLoop()
While disegnaScena
Application.DoEvents()
For Each a As ActorNode In ActorNodeList
a.update()
Next
scene.Simulate(1 / 60)
o.mRenderWindows(0).Update()
o.mRoot.RenderOneFrame()
scene.FlushStream()
scene.FetchResults(SimulationStatuses.AllFinished, True)
contaFrames += 1
End While
End
End Sub

Now, I have a problem: seems that the collision box is different than the cube mesh. The video of his behave is here:
http://www.youtube.com/watch?v=vcn1MT6aW2o
Anybody can help me? :(

McDonte

18-11-2011 22:02:49

Hey,
I had a similiar problem when I tried to let simple cubes fall onto a plane. It semmed that the mehes were too big for the collision shapes. Unfortunately I never found a solution for this problem. I guess Ogre and PhysX are using a different system of world units so they do not match. So a solution could be to set every point of the mesh and the collision shape simultaniously...
Sorry for not being a big help :?

Pyritie

20-11-2011 12:12:48

holy hell dude, use more descriptive variable names!

IvanJ147

21-11-2011 10:33:10

holy hell dude, use more descriptive variable names!
You're right!! :) I used these names only to make this fast proof, usuallly I use decent names :)

Unfortunately I never found a solution for this problem.
I tried to change this code:
a.Shapes.Add(New BoxShapeDesc((e.BoundingBox.Size)))
with this:
a.Shapes.Add(New BoxShapeDesc((New Vector3(e.BoundingBox.HalfSize.x, e.BoundingBox.HalfSize.y, e.BoundingBox.HalfSize.z))))
and now works perfectly (but I still don't know why... if somebody know please explain me... ). :(
Here's an example:
http://www.youtube.com/watch?v=UQYBsXoeG64

McDonte

24-11-2011 21:18:12

I tried to change this code:
a.Shapes.Add(New BoxShapeDesc((e.BoundingBox.Size)))
with this:
a.Shapes.Add(New BoxShapeDesc((New Vector3(e.BoundingBox.HalfSize.x, e.BoundingBox.HalfSize.y, e.BoundingBox.HalfSize.z))))
and now works perfectly (but I still don't know why... if somebody know please explain me... ). :(

I have no answer but take a look at the PhysX SDK where the parameters of the constructor for a new BoxShapeDesc are explained. Maybe you are supposed to pass only half the size or something. It's also possible that your parameters are wrong but producing "accidentally" the right result...

IvanJ147

30-11-2011 17:01:05

From PhysX documentation:
This other simple Shape Geometry takes three parameters, the three extents halved:
PxShape* aBoxShape = aBoxActor->createShape(PxBoxGeometry(a/2, b/2, c/2), aMaterial);
Where a, b and c are the side lengths of the resulting box.

:wink:

McDonte

20-12-2011 08:12:05

From PhysX documentation:
Isn't this sort of a stupid parameter? I would never expect something like this...
Thanks anyway for the solution :D