IrrPhysx 0.2 - Nvidia Physx 2.8.1 wrapper
Hello, Chris !!!!!!
Sio2 is not one of the most responsible persons
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
Thanks in advance.
Your project is great!!!! it helpes me a lot.
I give the second place for it, after Irrlicht, ofcourse
Here is the binary of my demo.
http://etlweb.net.ua/bin.zip
Sio2 is not one of the most responsible persons
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
}
};
Your project is great!!!! it helpes me a lot.
I give the second place for it, after Irrlicht, ofcourse
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.
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!
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!
-
- Posts: 1638
- Joined: Mon Apr 30, 2007 3:24 am
- Location: Montreal, CANADA
- Contact:
in the game demo this 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.
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));
}
It also noted something about expecting ";" before "for".. Also, when I run the game example in the bin folder it just crashes.
-
- Posts: 288
- Joined: Wed Apr 16, 2008 1:45 am
- Contact:
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.
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.
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
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.
it said there should be a ";" before the for statement
Code: Select all
c8 tmp[64]; sprintf_s
for..
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.
// 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
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
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
Someone, plese help with some code !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Thanks in advance.
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
}
};
Thanks in advance.
-
- Posts: 288
- Joined: Wed Apr 16, 2008 1:45 am
- Contact:
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
}
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()
{
//???
}
-
- Posts: 288
- Joined: Wed Apr 16, 2008 1:45 am
- Contact: