Post by Mike hartwig on Jan 3, 2010 2:16:30 GMT -5
I am having trouble integrating physx with the wrapper. Here is what I have so far:
Here is what I have for the cphysxanimatedmeshscenenode class.
This is where i am stuck. Not sure how to convert over that from the tutorial on the irrlicht main page. I got the physx wrapper from here:
www.zelsnack.org/jason/JttZ/Novodex_NET_Wrapper/
functions like mesh->grab dont have an equivalent. Also it wont let me implement the ISCENENODE interface. Any help would be appreciated.
[
Imports NovodexWrapper
Imports irrlichtnetcp
Imports SolarExplorer.cUtils
imports System.Runtime.interopservices
Public Class cPhysxManager
public shared lasttime As Single = 0
Public Shared scene As nxscene
public shared sdk As NxPhysicsSDK = Nothing
''' <summary>
''' Create q3 map data and return nxactor
''' </summary>
''' <param name="q3map"></param>
''' <param name="pos"></param>
''' <param name="scale"></param>
''' <returns></returns>
Public Shared Function CreateQuake3Map(ByVal q3map As AnimatedMesh, _
ByVal pos As Vector3D, ByVal scale As Vector3D) As nxactor
'retrieve how many meshes there are
Dim meshbuffercount As Integer = q3map.GetMesh(0).MeshBufferCount
Dim vertices As new list(of nxvec3) 'used for allocating vertices
Dim indices As new list(of Integer) 'used for allocating indices
Dim tempindexcount As Integer = 0 'used for offsetting indices
For i As Integer = 0 To meshbuffercount - 1
'pointer to the maps meshbuffer
Dim mb As meshbuffer = q3map.GetMesh(0).GetMeshBuffer(i) 'for every mesh buffer
Dim numvertices As Integer = mb.VertexCount
Dim numindices As Integer = mb.IndexCount
dim mbVertices as List(Of Vertex3DT2) = meshbuffergetverticest2(mb)
Dim mbindices As list(of integer) = MeshBufferGetIndices(mb)
For j As Integer = 0 To numvertices - 1 'push vertices into an array
vertices.Add(New NxVec3(mbvertices(j).Position.x * scale.X, _
mbvertices(j).Position.Y * scale.Y, mbvertices(j).Position.Z _
* scale.Z))
Next
For q As Integer = 0 To numindices - 1 'push indices into an array
indices.Add(mbindices(q) + tempindexcount)
Next
'the q3 map when loaded into irrlicht is divided into multiply mesh
'buffers. we want the sum of all mesh buffer indices. this way when
'it is loaded into physx it is offset correctly.
tempindexcount += numindices
Next
Dim meshdesc As new NxTriangleMeshDesc 'mesh description
'build physical model
meshdesc.numVertices = vertices.Count
meshdesc.numTriangles = indices.Count / 3
dim tvec as nxvec3
meshdesc.pointStrideBytes = marshal.SizeOf(tvec)
dim tint as integer
meshdesc.triangleStrideBytes = 3 * Marshal.SizeOf(tint)
meshdesc.flags = 0
dim q3maptrimesh as NxTriangleMesh = NovodexUtil.createTriangleMesh(meshdesc)
Dim mapmeshshapedesc As new NxTriangleMeshShapeDesc
mapmeshshapedesc.MeshData = q3maptrimesh
'Dim actordesc As NxActorDesc
'actordesc.addShapeDesc(mapmeshshapedesc)
'actordesc.globalPose.t = c
Dim gpose As nxmat34
gpose.t = New NxVec3(pos.X, pos.Y, pos.Z)
indices.Clear
vertices.Clear
dim q3actor As NxActor = novodexutil.createTriangleMeshActor(scene, q3maptrimesh, gpose, 1)
return q3actor
End Function
''' <summary>
''' Initialize the physx sdk
''' </summary>
''' <returns></returns>
Public Shared function initphysics() as boolean
sdk = nxphysicssdk.create
'set the physics parameters
sdk.setparameter(nxparameter.NX_SKIN_WIDTH, 0.0f)
'set the debug visualization parameters
sdk.setParameter(nxparameter.NX_VISUALIZATION_SCALE, 1)
sdk.setParameter(nxparameter.NX_VISUALIZE_COLLISION_SHAPES, 1)
sdk.setParameter(nxparameter.NX_VISUALIZE_ACTOR_AXES, 1)
'create the scene
Dim scenedesc As New NxSceneDesc
scenedesc.gravity = New nxvec3(0, -9.81f ,0)
scene = sdk.createScene(scenedesc)
'create the default material
Dim defmat As nxmaterial = scene.getDefaultMaterial
defmat.Restitution = 0.125f
defmat.StaticFriction = 0.25f
defmat.DynamicFriction = 0.25f
'get the current time
updatetime
'start the first frame of the simulation
startphysics
return true
End Function
''' <summary>
''' Release Physx Resources
''' </summary>
Public Shared sub ReleaseNX()
SDK.releaseScene(scene)
SDK.release
End sub
''' <summary>
''' Run this every frame
''' </summary>
Public Shared Sub StartPhysics
Dim deltatime As Double = updatetime
scene.simulate(deltatime * 5.0f)
scene.flushstream
End Sub
''' <summary>
''' Maintain a smooth simulate by updating the time
''' </summary>
Public shared function UpdateTime() as double
dim time as double = NovodexUtil.getTimeInSeconds()
dim deltatime as double = time - lastTime / 1000000.0f
lastTime=time
return deltatime
End function
End Class
Here is what I have for the cphysxanimatedmeshscenenode class.
imports IrrlichtNETCP
Public Class cPhysxAnimatedSceneNode
implements AnimatedMeshSceneNode
Public Shared Sub AlignToUpVector(ByVal m As Matrix4, ByVal up As Vector3D)
Dim quatrot As New Quaternion(up.Z, 0f, -up.X, 1 + up.Y)
quatrot.Normalize
m = quatrot.matrix
End Sub
' Public Shared Sub OnRegisterSceneNode
'Dim driver As VideoDriver
' Dim istransparentpass As Boolean = SceneNodeRenderPass.Transparent
'End Sub
End Class
This is where i am stuck. Not sure how to convert over that from the tutorial on the irrlicht main page. I got the physx wrapper from here:
www.zelsnack.org/jason/JttZ/Novodex_NET_Wrapper/
functions like mesh->grab dont have an equivalent. Also it wont let me implement the ISCENENODE interface. Any help would be appreciated.
[