IrrPhysx 0.2 - Nvidia Physx 2.8.1 wrapper

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
zillion42
Posts: 324
Joined: Wed Aug 29, 2007 12:32 am
Location: Hamburg, Germany

Post by zillion42 »

well it sounds like a math problem...
Can you further explain to us what:

a * sin(body.Y * PI / 180.0);
a * cos(body.Y * PI / 180.0);

and

rotation.Y -= 0.1f * pManager->getDT();
rotation.Y = fmod(rotation.Y, 360.0f);

intend to do ?

sounds very interesting though... for a tank you would expect a more slow response for breaking/acceleration aswell as turning... well if you ever played those evil war video games like battlefield or similar you'll know what I mean. Long time ago I did a 2 player pirate shoot each other up game, with two small ships on a map... the delayed and slowly increasing steering speed was only achieved by using several counters (linear and bezier progression Buildingblock of virtools) working on each other incrementing and decrementing up to max values or zero to make the characteristics of each ship.
Anyway I'm sure you'll get it and merry Xmas...
Pie21
Posts: 13
Joined: Mon Oct 06, 2008 11:21 am
Location: Melbourne, Australia
Contact:

Post by Pie21 »

Cheers for the help guys, and Merry Christmas! For starters, I'm not at all worried about realistic motion just yet - like I said, I'm just using the whole thing as an experiment. I figure once it all gets working I can come back and write the "moveTankProperly" functions. By the way I probably should mention it's a top-down camera perspective that follows the tank.

Okay so Dorth, I'm not using IrrWizard, just deriving a game structure from it, as summarised here. So far it's been far more enlightening than just putting classes in external files and squishing them all together in main.cpp. Are you suggesting there's something wrong with this? When I was searching around for stuff on game structure, I was thinking of making a post to ask, but I found a bit and thought I get some idea before looking too far ahead. Any better suggestions? Links?

And zillion, it's a pretty basic (in a bad way, presumably) bit of code. From your code:
- a is a multiplier to get the speed right (100.0f atm)
- body.y is the rotation around the y axis, between 0 and 360
- the PI/180 if to make it radians which math.h uses
Basically it's calculating the velocity vector so that it drives in the right direction based on the body's rotation. If the rotation is 30 degrees, then cos > sin, so the Z component of the velocity > X component and it'll drive at 30 degrees (straight, relative to the rotation). I'm sure there's a better way to do everything in my program, but I just haven't heard about them.

That part works fine, it's the rotation that buggers up, and I think I figured out why last night. In the case of the rotation, it gets the current rotation and adds 0.1 * deltaT (which is what pManager->getDT() returns - I figured that belonged in the GameManager, and didn't want to make too many things public) for every frame for which the turn key is held. Again, very crude but it works... at least up to 90 degrees.

The thing is, I had this same problem when coding the barrel turning. It was a child of the body, so I had to get its absolute rotation and add to that, since afaik setRotation() sets the absolute value (at least, I assumed it did and it worked). So at first I tried

Code: Select all

vector3df rotation = [the barrel node*]->getAbsoluteTransformation. getRotationDegrees()
and then used setRotation(rotation - [body node*]->getRotation()) to set it correctly relative to the body. However this got me stuck at 90 degrees again, and I think the problem was that getAbsoluteTransformation returned a matrix4 type, and that the getRotationDegrees() method of that wasn't playing nice. It would stop and jiggle noticeably at about 90 degrees, but it didn't crash... I changed the initial line of code to

Code: Select all

vector3df rotation = [the barrel node*]->getRotation() 0 [body node*]->getRotation()
and it worked fine. I'm thinking it could be the same problem here... but the getRotation() method of an IPhysxObject returns a vector3df (in that annoying store-to-the-argument way), so maybe not? Back to Dorth, I can't think what there is necessarily to test for in such a simple simulation of motion. It's basically a siwtch - if you hold down turn it turns at a constant speed (by setting rotation) and pressing W sets your velocity to a given value.

The same code works without IrrPhysx, so presumably I'm misunderstanding how something works. I'll keep looking into it. Oh, and Salty Dogs looks awesome :D
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

First off, that should be a basic design, at least until your code goes into production and usually past that anyway. Sprinkle tests all over your code. That way, when something goes haywire, all you need to do is peek at a log and you usually can guess why. Do not trust values. Ever.

Also, Gamasutra, GameDev, IGDA and if you do a good search here should give you plenty of more stable and sound game structure than the IrrWiz abomination ^^
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

Ya! Got hardware fluids working! I've got a bit of work to do on the initial demo and then I'll release it for people to test.

At the moment I'm using an Empty scene node in IrrEdit for placement and orientation of the fluid emitter. I also made a CFluidEmitterSceneNode for JP's GameExample framework - it calls functions I added to IrrPhysx to create a fluid and an emitter.
geckoman
Posts: 143
Joined: Thu Nov 27, 2008 11:05 am
Location: Germany
Contact:

Post by geckoman »

:shock: Wow I can't wait for that !
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Nice one sio2, looking forward to seeing what you've done!

Pie, you may well have come across an annoying thing with Physx which fmx and i have been looking into fixing.. basically it seems like rotations are completely borked.... Irrlicht will accept anything out of Physx so you can align a scene node to an IrrPhysx objecty nicely but it seems the other way round will rarely work.. only in very simple cases.

Something which may help you is that i think Physx likes its angles between -180 and +180 (in radians if i remember correctly) so making sure that's the case may help you somewhat. If you're rotating on more than one axis then i think you'll end up with a whole load of other problems unfortunately but it seems that you probably only have to worry about y axis rotations for a tank sim.
Image Image Image
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

A couple of tweaks and my framerate is up from 24fps to around 240fps! First tweak was to run the hw physics in parallel with Irrlicht's beginScene/drawAll/endScene (Irrlicht nodes aren't updated until the physics results are fetched though) - this increased frame rate from 24 to 94fps. Second was to batch up the rendering of the fluid particles in a better way, giving the approx 250fps.
Ciderbarrel
Posts: 2
Joined: Fri Jan 02, 2009 8:59 pm
Location: Washington, DC area

Post by Ciderbarrel »

2nd edit: Totally removed my non-problem with compiling the game example.

I do have a real question. I'm trying to read the code and see where the flag is declared and mess with it so I can play with the settings for it. I can't seem to be able to find where it is declared. Can anyone help?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

In the game example? I forget... lol, Is there not a flagCloth array declared somewhere? Or something like that.. (don't have the source on me at the minute)
Image Image Image
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

Well, i've been trying to get this working in NON vc compilers, aside that my WINXP won't allow me to use VC, so switching is not a posibility, has anyone gotten to compile IrrPhysx under DevCPP (for compilers sake..)? i tried, but i get this error

Code: Select all

In file included from G:/Archivos de programa/NVIDIA Corporation/NVIDIA PhysX SDK/v2.8.1/SDKs/Foundation/include/NxVec3.h:18,
                 from G:/Archivos de programa/NVIDIA Corporation/NVIDIA PhysX SDK/v2.8.1/SDKs/Foundation/include/NxBounds3.h:15,
                 from G:/Archivos de programa/NVIDIA Corporation/NVIDIA PhysX SDK/v2.8.1/SDKs/Foundation/include/NxFoundation.h:25,
                 from G:/Archivos de programa/NVIDIA Corporation/NVIDIA PhysX SDK/v2.8.1/SDKs/Physics/include/NxPhysics.h:21,
                 from CPhysxMesh.h:5,
                 from CClothPhysxMesh.h:4,
                 from CCloth.h:5,
                 from CCloth.cpp:3:G:/Archivos de programa/NVIDIA Corporation/NVIDIA PhysX SDK/v2.8.1/SDKs/Foundation/include/NxMath.h: In static member function `static void NxMath::sinCos(NxF32, NxF32&, NxF32&)':
G:/Archivos de programa/NVIDIA Corporation/NVIDIA PhysX SDK/v2.8.1/SDKs/Foundation/include/NxMath.h:757: error: `_asm' undeclared (first use this function)
G:/Archivos de programa/NVIDIA Corporation/NVIDIA PhysX SDK/v2.8.1/SDKs/Foundation/include/NxMath.h:757: error: (Each undeclared identifier is reported only once for each function it appears in.)
G:/Archivos de programa/NVIDIA Corporation/NVIDIA PhysX SDK/v2.8.1/SDKs/Foundation/include/NxMath.h:757: error: expected `;' before "fld"CCloth.cpp: In destructor `IrrPhysx::CCloth::~CCloth()':
CCloth.cpp:37: warning: deleting `void*' is undefined 
And the probable source of this fail is here..

Code: Select all

#ifdef WIN32
      NxF32 localCos, localSin;
      NxF32 local = f;
      _asm   fld      local
      _asm   fsincos
      _asm   fstp   localCos
      _asm   fstp   localSin
      c = localCos;
      s = localSin;
#else
      c = cosf(f);
      s = sinf(f);
#endif 
The trouble is that that code is part of the Physx SDK, so i don't know what to touch or what not. Any idea? I already asked JP, but he told me to put it here to see if anyone could have a clue. The thing is that curiously, the SDK has some LINUX defines, so probably it can be compiled under Linux too (no idea in this meaning) but seems that GCC is either missing something, or that the code is for VC only or... who knows?
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
zillion42
Posts: 324
Joined: Wed Aug 29, 2007 12:32 am
Location: Hamburg, Germany

Post by zillion42 »

Mel wrote:Well, i've been trying to get this working in NON vc compilers, aside that my WINXP won't allow me to use VC, so switching is not a posibility, has anyone gotten to compile IrrPhysx under DevCPP (for compilers sake..)? i tried, but i get this error
Wow... how does xp do that ? I mean VC express is freeware and works even on my onholy installation, compared to IE7 or mediaplayer... If you have no other reason working with another package I would definitly recommend trying VC8 (that is VisualStudioExpress 2005 C++) again and see whats wrong with it. There is 2 service packs for 2005 if I'm not mistaken, you'll also need the Windows® Server 2003 SP1 Platform SDK, aswell as DirectX9 and your set...
Otherwise it would probably be good setting your appropiate

Code: Select all

#define WIN32
on top of your code...
good luck...
Ciderbarrel
Posts: 2
Joined: Fri Jan 02, 2009 8:59 pm
Location: Washington, DC area

Post by Ciderbarrel »

JP wrote:In the game example? I forget... lol, Is there not a flagCloth array declared somewhere? Or something like that.. (don't have the source on me at the minute)
Would this be it: core::array<SPhysxAndNodePair*> flags; at the top of GameExample.cpp?

I just started learning Irrlicht this week, moving over from Ogre. I've had a hard time getting any of their four physics wrappers compiling. So, since I am still getting a handle on Irrlicht and Physx, please excuse any beginner questions :D
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

zillion42 wrote:
Mel wrote:Well, i've been trying to get this working in NON vc compilers, aside that my WINXP won't allow me to use VC, so switching is not a posibility, has anyone gotten to compile IrrPhysx under DevCPP (for compilers sake..)? i tried, but i get this error
Wow... how does xp do that ? I mean VC express is freeware and works even on my onholy installation, compared to IE7 or mediaplayer... If you have no other reason working with another package I would definitly recommend trying VC8 (that is VisualStudioExpress 2005 C++) again and see whats wrong with it. There is 2 service packs for 2005 if I'm not mistaken, you'll also need the Windows® Server 2003 SP1 Platform SDK, aswell as DirectX9 and your set...
Otherwise it would probably be good setting your appropiate

Code: Select all

#define WIN32
on top of your code...
good luck...
The VC installers complain that i don't have WINXP SP2, and i won't be installing it soon because XP works fine for me. And i thought that Win32 thing was defined, you might see the error, it says "_asm undefined" which, i guess, it implies that there is some WIN32 defined anywhere not obstant, i'm not sure about that, so i'll try that thanks! :)
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Ciderbarrel wrote:
JP wrote:In the game example? I forget... lol, Is there not a flagCloth array declared somewhere? Or something like that.. (don't have the source on me at the minute)
Would this be it: core::array<SPhysxAndNodePair*> flags; at the top of GameExample.cpp?

I just started learning Irrlicht this week, moving over from Ogre. I've had a hard time getting any of their four physics wrappers compiling. So, since I am still getting a handle on Irrlicht and Physx, please excuse any beginner questions :D
Yep that'll be the one! Good luck with learning Irrlicht, shouldn't be too tricky but anything you stumble on can be cleared up by searching this forum or posting in the beginners section!

Pfff... Mel, just install SP2 lol what's the worst that could happen? Well sure... lots i guess.. being windows and all... But seriously you're better off keeping it updated i'd say!
Image Image Image
Steel Style
Posts: 168
Joined: Sun Feb 04, 2007 3:30 pm
Location: France

Post by Steel Style »

HI I wanna get Actor for using bones.
Does they're anyway to get them from with a function like IPhysxObject->getActor() ?

I think that I need to do change on the lib but I tried to change the source but I don't think that what I did is good (I never create a lib or something like that).
Post Reply