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
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I don't have any code for fluid physics at all... sio2 did that on his own and didn't share the source code...
Image Image Image
rootroot1
Posts: 44
Joined: Wed Nov 25, 2009 6:42 pm
Location: Odessa, Ukraine

Post by rootroot1 »

Hello, Chris !!!!!!

Sio2 is not one of the most responsible persons :lol: :lol:

Currently i try to work with character controllers
I have implemented class for this, everething works fine, but
maybe you can help me to implement moveBackward, moveLeft and moveRight methods

Here is my code

Code: Select all

//
//character controller player class 
//
class CPlayer
{
public:
	CPlayer(
		CCharacterManager * charManager, 
		IPhysxManager * physxManager, 
		ICameraSceneNode * playerCamera,
		vector3df position,
		NxReal r,
		NxReal h) 
		: m_cManager(charManager), m_pManager(physxManager), m_Camera(playerCamera), m_radius(r), m_height(h)
	{
		//init character physics 
		m_bPushCharacter = false;
		m_DefaultGravity = NxVec3(0, G, 0);
		m_CharacterVec = NxVec3(0,0,0);
		m_fCharacterSpeed = 20;
		m_bJump = false;

		//create character
		m_charCapsuleController = 
			new MyCharacterController(
			charManager->getManager(), 
			physxManager->getScene(), 
			NxVec3(position.X, position.Y, position.Z),
			r, h);
	}

	~CPlayer()
	{
		if(m_charCapsuleController)
		NX_DELETE_SINGLE(m_charCapsuleController);
	}

	void StartJump(NxF32 v0)
	{
		if (m_bJump)  return;
		m_fJumpTime = 0.0f;
		m_V0 = v0;
		m_bJump = true;
	}

	void StopJump()
	{
		m_bJump = false;
	}

	void UpdateCharacter(NxReal deltaTime)
	{
		NxVec3 disp = m_DefaultGravity;

		//camera & character sync
		m_cameraTarget = m_Camera->getTarget() - m_Camera->getPosition();
		m_cameraTarget.normalize();

		if (m_bPushCharacter)
		{
			NxVec3 horizontalDisp = m_CharacterVec;
			horizontalDisp.y = 0.0f;
			horizontalDisp.normalize();
			disp += horizontalDisp * m_fCharacterSpeed;
		}

		disp *= deltaTime;
		NxF32 height = GetHeight(deltaTime); // compute height(Y) in jumping
		if (height != 0.0f)
		{
			disp.y += height;
		}

		NxU32 collisionFlags;
		m_charCapsuleController->Move(disp, collisionFlags);
		if (collisionFlags & NXCC_COLLISION_DOWN)  
			StopJump();

		m_cManager->getManager()->updateControllers();

		//update camera position
		NxExtendedVec3 pos = m_charCapsuleController->GetCharacterPos();
		m_Camera->setPosition(vector3df(pos.x, pos.y + m_height, pos.z));

	}

	void PushCharacter(bool bPush)
	{
		m_bPushCharacter = bPush;
	}

	void moveForward()
	{
		m_CharacterVec = NxVec3(m_cameraTarget.X, m_cameraTarget.Y, m_cameraTarget.Z); 
	}

	void moveBackward()
	{
		m_CharacterVec = NxVec3(m_cameraTarget.X, m_cameraTarget.Y, m_cameraTarget.Z);
		m_CharacterVec = -m_CharacterVec; 
	}

	void moveRight()
	{
		//???
	}

	void moveLeft()
	{
		//???
	}

	void setSpeed(NxReal newSpeed)
	{
		m_fCharacterSpeed = newSpeed;
	}

private:
	
	vector3df	 m_cameraTarget; 
	bool  		 m_bPushCharacter;
	NxVec3		 m_DefaultGravity;
	NxF32 		 m_V0;
	NxVec3		 m_CharacterVec;
	NxF32 		 m_fJumpTime;
	NxF32 		 m_fCharacterSpeed;
	bool  		 m_bJump;

	NxReal		 m_radius;
	NxReal		 m_height;

	CCharacterManager     * m_cManager;
	IPhysxManager		  * m_pManager;
	MyCharacterController * m_charCapsuleController;
	ICameraSceneNode	  * m_Camera;

private:

	NxF32 GetHeight(NxF32 elapsedTime)
	{
		if (!m_bJump)  return 0.0f;
		NxF32 Vt = m_V0 + G*m_fJumpTime; // Vt = Vo + GT
		m_fJumpTime += elapsedTime;
		return Vt*elapsedTime + 1/2*G*elapsedTime*elapsedTime; // S = VtT + 1/2GT^2
	}
};
Thanks in advance.
Your project is great!!!! it helpes me a lot.
I give the second place for it, after Irrlicht, ofcourse :D

Here is the binary of my demo.
http://etlweb.net.ua/bin.zip
Last edited by rootroot1 on Mon Jan 11, 2010 7:26 pm, edited 2 times in total.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

You basically need some notion of a 'forwards' direction for your character. This can possibly just be a fairly arbitrary initial vector such as (1,0,0) so it starts facing down the X-axis.

Then when you rotate left and right you want to rotate that vector by the same amount so that you always know which way is forward.

When you want to strafe left and right you can take the perpendicular vector to your forward vector to know which direction to strafe in. You could do that by rotating your forward vector by 90 degrees and using that as the direction to move in.

For moving backwards you merely move in the negative direction to your forward vector.

Hope that helps!
Image Image Image
rootroot1
Posts: 44
Joined: Wed Nov 25, 2009 6:42 pm
Location: Odessa, Ukraine

Post by rootroot1 »

Ok, that helps me to implement moveBakwards,
Maybe I'm stupid :oops: :oops: Sorry..
I am about to blow my mind :cry:

Could you give a little example with C++ code ro Right or Left movement
maybe 1 or 2 lines.
Pleeeeeeeeaaaaaaaaaaseeeeeeeeee.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Perhaps you can check the FPS camera animator code in IRRlicht. It use a forward vector to move the camera.
roelor
Posts: 240
Joined: Wed Aug 13, 2008 8:06 am

Post by roelor »

in the game demo this

Code: Select all

	// Preload our texture animators
	c8 tmp[64]; sprintf_s
	for (s32 i = 1 ; i <= 10 ; ++i) {
		sprintf_s(tmp, "../media/explosion/%02d.jpg", i);
		explosionTextures.push_back(smgr->getVideoDriver()->getTexture(tmp));
	}
	for (s32 i = 1 ; i <= 6 ; ++i) {
		sprintf_s(tmp, "../media/impact/%02d.jpg", i);
		impactTextures.push_back(smgr->getVideoDriver()->getTexture(tmp));
	}
doesn't compile for me. it said: "|312|error: `sprintf_s' was not declared in this scope|"
It also noted something about expecting ";" before "for".. Also, when I run the game example in the bin folder it just crashes.
Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

Post by Insomniacp »

interesting, try commenting out the sprintf_s... it looks like it was supposed to give some data out to the command prompt window but was never actually done which is why it errors.

We still have a list of about 9 things to wrap up before a release and I'm not sure what is meant by a few of them, I will talk with JP about what exactly needs to be done with them. We are also having an issue with the collision example that I was unable to solve.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

For Irrlicht apps, use snprintf instead of sprintf_s. It will be automatically replaced if applicable.
roelor
Posts: 240
Joined: Wed Aug 13, 2008 8:06 am

Post by roelor »

The sprintf_s statement that comes before the for loop isn't correct according to the "gcc compiler".
it said there should be a ";" before the for statement

Code: Select all

c8 tmp[64]; sprintf_s 
for..
I also get a weird compiler error, (first I got one from irrlicht too but I just changed the irrlicht lib directory from Irrlicht to the location on my hd.)

Anyway the error said: (I commented the previous error out. you know, the one with "sprintf")
ld.exe||cannot find -l-mwindows| (codeblocks) I know it is not really relevant, but I don't know how I can solve this.

And the boxed example returns that preprocessing has failed.
rootroot1
Posts: 44
Joined: Wed Nov 25, 2009 6:42 pm
Location: Odessa, Ukraine

Post by rootroot1 »

// Preload our texture animators
c8 tmp[64];
for (s32 i = 1 ; i <= 10 ; ++i) {
sprintf_s(tmp, "../media/explosion/%02d.jpg", i);
explosionTextures.push_back(smgr->getVideoDriver()->getTexture(tmp));
}
for (s32 i = 1 ; i <= 6 ; ++i) {
sprintf_s(tmp, "../media/impact/%02d.jpg", i);
impactTextures.push_back(smgr->getVideoDriver()->getTexture(tmp));
}

and everything will be fine !!!! verry funny
rootroot1
Posts: 44
Joined: Wed Nov 25, 2009 6:42 pm
Location: Odessa, Ukraine

Post by rootroot1 »

Currently i try to work with character controllers
I have implemented class for this, everething works fine, but
maybe you can help me to implement, moveLeft and moveRight methods

Here is my code

Code: Select all

//
//character controller player class 
//
class CPlayer
{
public:
	CPlayer(
		CCharacterManager * charManager, 
		IPhysxManager * physxManager, 
		ICameraSceneNode * playerCamera,
		vector3df position,
		NxReal r,
		NxReal h) 
		: m_cManager(charManager), m_pManager(physxManager), m_Camera(playerCamera), m_radius(r), m_height(h)
	{
		//init character physics 
		m_bPushCharacter = false;
		m_DefaultGravity = NxVec3(0, G, 0);
		m_CharacterVec = NxVec3(0,0,0);
		m_fCharacterSpeed = 20;
		m_bJump = false;

		//create character
		m_charCapsuleController = 
			new MyCharacterController(
			charManager->getManager(), 
			physxManager->getScene(), 
			NxVec3(position.X, position.Y, position.Z),
			r, h);
	}

	~CPlayer()
	{
		if(m_charCapsuleController)
		NX_DELETE_SINGLE(m_charCapsuleController);
	}

	void StartJump(NxF32 v0)
	{
		if (m_bJump)  return;
		m_fJumpTime = 0.0f;
		m_V0 = v0;
		m_bJump = true;
	}

	void StopJump()
	{
		m_bJump = false;
	}

	void UpdateCharacter(NxReal deltaTime)
	{
		NxVec3 disp = m_DefaultGravity;

		//camera & character sync
		m_cameraTarget = m_Camera->getTarget() - m_Camera->getPosition();
		m_cameraTarget.normalize();

		if (m_bPushCharacter)
		{
			NxVec3 horizontalDisp = m_CharacterVec;
			horizontalDisp.y = 0.0f;
			horizontalDisp.normalize();
			disp += horizontalDisp * m_fCharacterSpeed;
		}

		disp *= deltaTime;
		NxF32 height = GetHeight(deltaTime); // compute height(Y) in jumping
		if (height != 0.0f)
		{
			disp.y += height;
		}

		NxU32 collisionFlags;
		m_charCapsuleController->Move(disp, collisionFlags);
		if (collisionFlags & NXCC_COLLISION_DOWN)  
			StopJump();

		m_cManager->getManager()->updateControllers();

		//update camera position
		NxExtendedVec3 pos = m_charCapsuleController->GetCharacterPos();
		m_Camera->setPosition(vector3df(pos.x, pos.y + m_height, pos.z));

	}

	void PushCharacter(bool bPush)
	{
		m_bPushCharacter = bPush;
	}

	void moveForward()
	{
		m_CharacterVec = NxVec3(m_cameraTarget.X, m_cameraTarget.Y, m_cameraTarget.Z); 
	}

	void moveBackward()
	{
		m_CharacterVec = NxVec3(m_cameraTarget.X, m_cameraTarget.Y, m_cameraTarget.Z);
		m_CharacterVec = -m_CharacterVec; 
	}

	void moveRight()
	{
		//???
	}

	void moveLeft()
	{
		//???
	}

	void setSpeed(NxReal newSpeed)
	{
		m_fCharacterSpeed = newSpeed;
	}

private:
	
	vector3df	 m_cameraTarget; 
	bool  		 m_bPushCharacter;
	NxVec3		 m_DefaultGravity;
	NxF32 		 m_V0;
	NxVec3		 m_CharacterVec;
	NxF32 		 m_fJumpTime;
	NxF32 		 m_fCharacterSpeed;
	bool  		 m_bJump;

	NxReal		 m_radius;
	NxReal		 m_height;

	CCharacterManager     * m_cManager;
	IPhysxManager		  * m_pManager;
	MyCharacterController * m_charCapsuleController;
	ICameraSceneNode	  * m_Camera;

private:

	NxF32 GetHeight(NxF32 elapsedTime)
	{
		if (!m_bJump)  return 0.0f;
		NxF32 Vt = m_V0 + G*m_fJumpTime; // Vt = Vo + GT
		m_fJumpTime += elapsedTime;
		return Vt*elapsedTime + 1/2*G*elapsedTime*elapsedTime; // S = VtT + 1/2GT^2
	}
};
Someone, plese help with some code !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Thanks in advance.
Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

Post by Insomniacp »

Code: Select all

 void moveForward()
   {
      m_CharacterVec = NxVec3(m_cameraTarget.X, m_cameraTarget.Y, m_cameraTarget.Z);
   }

   void moveBackward()
   {
      m_CharacterVec = NxVec3(m_cameraTarget.X, m_cameraTarget.Y, m_cameraTarget.Z);
      m_CharacterVec = -m_CharacterVec;
   }

   void moveRight()
   {
      m_CharacterVec = NxVec3(m_cameraTarget.X, m_cameraTarget.Y, m_cameraTarget.Z);
      m_CharacterVec = m_CharacterVec.rotateXZBy(90);
//i think this is the right way may be -90
   }

   void moveLeft()
   {
      m_CharacterVec = NxVec3(m_cameraTarget.X, m_cameraTarget.Y, m_cameraTarget.Z);
      m_CharacterVec = m_CharacterVec.rotateXZBy(-90);
//once again this may be the wrong direction try opposite if its wrong
   } 
i believe this is the best way to do it and what they are refering to above. Simply takes your forward vector and rotates it 90 or -90 degrees to go in either left or right direction. They may be switched though since I don't remember which direction it rotates.
rootroot1
Posts: 44
Joined: Wed Nov 25, 2009 6:42 pm
Location: Odessa, Ukraine

Post by rootroot1 »

Thanks for your attention, and thanks for your trying to help me,
but, I also tried to do smth like this but no result :cry: :cry:

Any other suggestions ?????????? :idea: :idea:
rootroot1
Posts: 44
Joined: Wed Nov 25, 2009 6:42 pm
Location: Odessa, Ukraine

Post by rootroot1 »

Code: Select all


	void moveForward()
	{
		m_CharacterVec = m_cameraTarget;
	}

	void moveBackward()
	{
		m_CharacterVec = m_cameraTarget;
		m_CharacterVec = -m_CharacterVec; 
	}

	void moveRight()
	{
	    /// Wrong !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	    // nothing happen 
		m_CharacterVec = m_cameraTarget;
		m_CharacterVec.rotateXZBy(90, m_CharacterVec); 
	}

	void moveLeft()
	{
		//???
	}

Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

Post by Insomniacp »

m_CharacterVec = m_cameraTarget.rotateXZBy(90);

try that :P
think it didn't work cause i didn't set it equal to the vector after rotating so nothing actually changed. Sorry bout the simple mistake :P
Post Reply