Jump to content
  • Advertisement
Sign in to follow this  
Viperrr

OpenGL DirectX and PhysX

This topic is 3753 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does any here have experience using AGEIA PhysX with DirectX? And specifically its character controller? I am looking for a tutorial on how to use the PhysX character controller with DirectX, to create a standard First Person Shooter control. The samples that come with the documentation of PhysX are for openGL, and are not explained very well. I have never used PhysX before, can someone help me get started please?

Share this post


Link to post
Share on other sites
Advertisement
I could use this nfo also. The tuts for the character controller are not very good for me. Can anyone post some simplistic code for this?

thanks in advance,

Share this post


Link to post
Share on other sites
Never got around to using the character API, but I had PhysX integrated into my old D3D9 engine. If you any specific question not related to the character API I can try to answer them for you, if you like.

Share this post


Link to post
Share on other sites
Ok well, how about I start simple: creating a plane, and displaying it onscreen (for debugging)

This is part of what I have now:
[source lang=cpp]
...
pGroundPlane = CreateGroundPlane();
...

NxActor* CreateGroundPlane()
{
// Create a plane with default descriptor
NxPlaneShapeDesc planeDesc;
NxActorDesc actorDesc;
actorDesc.shapes.pushBack(&planeDesc);
return pScene->createActor(actorDesc);
}



How would I render this plane onscreen? Using directX..

Share this post


Link to post
Share on other sites
I see alot of people are viewing this topic.

If you, like me and 7thAvatar, would like to see a tutorial on charactercontrol with PhysX + DirectX, drop a line here!

If there is enough interest for it, maybe someone will be kind enough to make us one :)

Share this post


Link to post
Share on other sites
Perhaps important to point out (and I sense this is the point of confusion): the mesh or shape you supply to PhysX has absolutely nothing to do with the mesh that you render. They are completely different meshes who's data is stored in different places. In general, the mesh you supply to PhysX is a really simplified version of your actual mesh but in practice they share no data and can thus be considered "completely different".

So in your code you've created an NxPlaneShape but you have nothing to render because you still need to create an actual mesh to render. i.e. some set of vertices, indices, uv coordinates, textures, shaders and whatnot for DirectX to handle.

To put another way, if you don't already know how to create objects and draw them in DirectX (i.e. have an already working application that does this) then do not try to use these 2 APIs together. Start by building a basic "game" just using DirectX: have some objects that move around under your own control which are drawn to the screen.

Otherwise, if I'm off the mark I'm not entirely sure what the problem is. So here's another stab.

Think of PhysX as the "where stuff is" manager. DirectX is just the "draw stuff" manager.

Usually you'd draw something like this (in API agnostic pseudo-code)


MyAPIPushMatrix( myThingsOrientationMatrix );

DrawThing();

MyAPIPopMatrix();




Now if you're not using PhysX then:


myThingsOrientationMatrix == myThing.getMatrix();




however, you're using PhysX to figure out where stuff is so


myThingsOrientationMatrix = myThing->myNxActor.getMatrix();

//replace getMatrix() with the actual API call. too lazy to look it up right now




-me

Share this post


Link to post
Share on other sites
Palidine,

I know how to draw things with DirectX. Infact, I have the graphics part of my engine down; I can load and display meshes, using pixelshaders.

So my engine is at the point where I have a building (which consists of some meshes) and I can walk through it with WASD + mouse look. You know, the controls pretty much all FPS use. (I use DirectInput to do it)

But like you said, Direct3D has nothing to do with collision detection, it just draws. Now I need a way to keep the player from walking through walls, so I looked around and found PhysX :)

I also understand that PhysX meshes are completely seperate from Direct3D meshes. I understand what you mean by "where stuff is" manager. I knew that.

However, looking at the samples for openGL, I noticed they actually draw the PhysX meshes to the screen, for debug purposes. That way I could line up the PhysX meshes with the Direct3D meshes.

The reason I wanted to draw the plane now, is this:
If it shows up on screen, it mean Im doing something right! ;)

Are you saying this is not possible?

Share this post


Link to post
Share on other sites
Quote:
Original post by Viperrr
Palidine,

I know how to draw things with DirectX. Infact, I have the graphics part of my engine down; I can load and display meshes, using pixelshaders.

So my engine is at the point where I have a building (which consists of some meshes) and I can walk through it with WASD + mouse look. You know, the controls pretty much all FPS use. (I use DirectInput to do it)

But like you said, Direct3D has nothing to do with collision detection, it just draws. Now I need a way to keep the player from walking through walls, so I looked around and found PhysX :)

I also understand that PhysX meshes are completely seperate from Direct3D meshes. I understand what you mean by "where stuff is" manager. I knew that.

However, looking at the samples for openGL, I noticed they actually draw the PhysX meshes to the screen, for debug purposes. That way I could line up the PhysX meshes with the Direct3D meshes.

The reason I wanted to draw the plane now, is this:
If it shows up on screen, it mean Im doing something right! ;)

Are you saying this is not possible?


No they don't. In the demo code they build simple geom shapes with OpenGL calls. If you start with DrawActor() and go deep enough their are a whole bunch of utility functions that draw shapes in OpenGL.

The demos uses the PhysX internal list of objects as the render list so it looks like they are rendering the actual PhysX object. My entities have a pointer to their physics body and I keep my own list of rendering objects. Then I poll the entities physics object world matrix as the position to place the D3D mesh. Same as Palidine pseudo code.

Share this post


Link to post
Share on other sites
The PhysX physics simulation is SEPARATE from the DirectX Rendering API. To use them together, you want to supply some data from your scene (original matrix positions, bounding volume size, a simplified set of mesh data etc.) along with the physical attributes of the things in your scene to the physX simulation via NxActors. The simulation then runs and updates the actors world matrices - thats essentially all it does. Next you take the world matrix of the NxActor (NxActor->getMatrix()) and apply it before rendering your DirectX representation of the object. Remember the two things are separate!

Share this post


Link to post
Share on other sites
The PhysX SDK comes with an interactive debugger ... it's a long time since I've used it but I remember it being very helpful. You can also get PhysX to spit out buffers full of vertices for rendering debug shapes in-game. Rendering these will give you a visual representation of the actual PhysX actors (including character controller) within your scene. It's all in the docs :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!