Code to help people using PhysX and DirectXprogram in DirectX

Started by
-1 comments, last by chillypacman 15 years, 4 months ago
You can download it here: http://medsgames.com/?page_id=3 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

This topic is closed to new replies.

Advertisement