Sign in to follow this  
chillypacman

Code to help people using PhysX and DirectXprogram in DirectX

Recommended Posts

chillypacman    100
You can download it here: [url="http://medsgames.com/?page_id=3"]http://medsgames.com/?page_id=3[/url] There's actually a lot of code so I'm just going to post the header file of the create actor functions so you can get an idea of their functionality: Convex actor creation:
#pragma once

#include "emlib.h"
#include <vector>

class EmPhysXUtil::Convex
{
public:
	public:
		static NxActor* CreateActorFromID3DXMesh(ID3DXMesh* in_mesh, NxBodyDesc* body = NULL, NxScene* scene = NULL, NxPhysicsSDK* physicsSDK = NULL);


		//Creates an NxConvexMeshDesc from the provided ID3DXMesh
		static NxConvexMeshDesc CreateDescFromID3DXMesh(ID3DXMesh* in_mesh);
		//generates a convex shape desc from a convex desc ( can be used in conjunction with EmPhysXUtil::CreateConvexDescFromID3DXMesh() )
		static bool GenShapeDescFromDesc(NxConvexMeshDesc& in_cmd, NxConvexShapeDesc& out_convexShapeDesc, NxPhysicsSDK* in_physicsSDK = NULL);
		//saves convex desc (aka cooks to file to file and palces it at the given directory
		static bool SaveToFile(const std::string in_dir, NxConvexMeshDesc in_cmd);
		//create convex shape desc from file
		static bool CreateShapeDescFromFile(NxConvexShapeDesc& out_convShape, const std::string& in_dir, NxPhysicsSDK* in_physicsSDK);
		//create actor desc from ID3DXMesh
		static NxActorDesc CreateActorDescFromID3DXMesh(ID3DXMesh* in_mesh, NxBodyDesc* in_body = NULL, NxPhysicsSDK* in_physicsSDK = NULL);
};

Triangle mesh actor creation:
#pragma once

#include "emlib.h"

class EmPhysXUtil::TriMesh
{
public:
	static NxActor* CreateActorFromID3DXMesh(ID3DXMesh* in_mesh, NxBodyDesc* body = NULL, NxScene* scene = NULL, NxPhysicsSDK* physicsSDK = NULL);


	static NxTriangleMeshDesc CreateDescFromID3DXMesh(ID3DXMesh* model);
	static bool GenShapeDescFromDesc(NxTriangleMeshDesc& in_cmd, NxTriangleMeshShapeDesc& out_convexShapeDesc, NxPhysicsSDK* in_physicsSDK = NULL);
	static bool SaveToFile(const std::string in_dir, NxTriangleMeshDesc in_triMeshDesc);
	static bool CreateShapeDescFromFile(::NxTriangleMeshShapeDesc& out_triShape, const std::string& in_dir, NxPhysicsSDK* in_physicsSDK);
	static NxActorDesc CreateActorDescFromID3DXMesh(ID3DXMesh* in_mesh, NxBodyDesc* in_body = NULL, NxPhysicsSDK* in_physicsSDK = NULL);
};

Check the link for more details on how to make use of the functions. It's still not finished but shouldn't crash (I say shouldn't no warranties provided ^_^) and if it does please be sure to tell me so I can look into it. The meshes I've used have been loaded up from directx .x files which were exported from 3D studio max using the Panda DirectX exporter. Of course you'll need to link up all the appropriate PhysX libraries and directories to make it work. Feel free to ask any questions or send death threats for my poor coding skills :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this