Page 26 of 29

Posted: Wed Dec 23, 2009 10:18 am
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...

Posted: Sun Jan 10, 2010 10:04 pm
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

Posted: Mon Jan 11, 2010 1:39 pm
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!

Posted: Mon Jan 11, 2010 4:45 pm
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.

Posted: Mon Jan 11, 2010 5:56 pm
by christianclavet
Perhaps you can check the FPS camera animator code in IRRlicht. It use a forward vector to move the camera.

Posted: Mon Jan 11, 2010 8:38 pm
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.

Posted: Mon Jan 11, 2010 8:39 pm
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.

Posted: Mon Jan 11, 2010 9:01 pm
by hybrid
For Irrlicht apps, use snprintf instead of sprintf_s. It will be automatically replaced if applicable.

Posted: Mon Jan 11, 2010 9:10 pm
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.

Posted: Mon Jan 11, 2010 10:00 pm
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

Posted: Mon Jan 11, 2010 10:01 pm
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.

Posted: Mon Jan 11, 2010 11:08 pm
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.

Posted: Mon Jan 11, 2010 11:26 pm
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:

Posted: Mon Jan 11, 2010 11:28 pm
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()
	{
		//???
	}


Posted: Tue Jan 12, 2010 1:24 am
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