If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
markmze
Posts: 24 Joined: Fri Apr 19, 2013 1:09 am
Post
by markmze » Tue May 14, 2013 2:47 pm
Hi everybody,
I'm trying to add Xbox Joystick handle to work with the collision example (which I'm sure would be useful).
So I changed a few settings on some code found on the forum, and you can now move around with the left hat stick.
Here's the code, I think it could be useful to someone (need to be put in the while run loop; and to be combined with the joystick tutorial for initialising the device)
Code: Select all
core::vector3df nodePosition = camera->getPosition();
bool movedWithJoystick = false; //to check if we are using joystick
if(joystickInfo.size() > 0) //if we are using joystick do:
{
f32 moveHorizontal = 0.f;
f32 moveVertical = 0.f;
const SEvent::SJoystickEvent & joystickData = receiver.GetJoystickState();
const f32 DEAD_ZONE = 0.05f; //to prevent
moveHorizontal =
(f32)joystickData.Axis[SEvent::SJoystickEvent::AXIS_X] / 32767.f;
if(fabs(moveHorizontal) < DEAD_ZONE)
moveHorizontal = 0.f;
moveVertical =
(f32)joystickData.Axis[SEvent::SJoystickEvent::AXIS_Y] / 32767.f;
if(fabs(moveVertical) < DEAD_ZONE)
moveVertical = 0.f;
const u16 povDegrees = joystickData.POV / 100;
if(povDegrees < 360)
{
if(povDegrees > 0 && povDegrees < 180)
moveHorizontal = -1.f;
else if(povDegrees > 180)
moveHorizontal = 1.f;
if(povDegrees > 90 && povDegrees < 270)
moveVertical = 1.f;
else if(povDegrees > 270 || povDegrees < 90)
moveVertical = -1.f;
}
if(!core::equals(moveHorizontal, 0.f) || !core::equals(moveVertical, 0.f))
{
nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime * moveHorizontal;
nodePosition.X += MOVEMENT_SPEED * frameDeltaTime * moveVertical;
movedWithJoystick = true;
}
}
camera->setPosition(nodePosition);
My big problem right now is to use the right hat stick to move the camera vision around (like every fps).
And I simply don't know how to check if this stick is used; Can someone tip me ? Thanks.
Last edited by
markmze on Tue May 28, 2013 2:00 pm, edited 1 time in total.
markmze
Posts: 24 Joined: Fri Apr 19, 2013 1:09 am
Post
by markmze » Tue May 14, 2013 3:45 pm
Alright, it's a bit better, but still not okay.
The displacement do not coincide with the relative angle of the camera, and the angle of the camera does only work for Y axis... Any help?
Code: Select all
core::vector3df nodePosition = camera->getPosition();
core::vector3df nodeRotation = camera->getRotation();
bool movedWithJoystick = false; //to check if we are using joystick
if(joystickInfo.size() > 0) //if we are using joystick do:
{
f32 moveHorizontal = 0.f;
f32 moveVertical = 0.f;
f32 moveHorizontalstick2 = 0.f;
f32 moveVerticalstick2 = 0.f;
const SEvent::SJoystickEvent & joystickData = receiver.GetJoystickState();
const SEvent::SJoystickEvent & joystickData2 = receiver.GetJoystickState();
const f32 DEAD_ZONE = 0.05f; //to prevent
moveHorizontal =
(f32)joystickData.Axis[SEvent::SJoystickEvent::AXIS_X] / 32767.f;
if(fabs(moveHorizontal) < DEAD_ZONE)
moveHorizontal = 0.f;
moveVertical =
(f32)joystickData.Axis[SEvent::SJoystickEvent::AXIS_Y] / 32767.f;
if(fabs(moveVertical) < DEAD_ZONE)
moveVertical = 0.f;
moveHorizontalstick2 =
(f32)joystickData2.Axis[SEvent::SJoystickEvent::AXIS_Z] / 32767.f;
if(fabs(moveHorizontalstick2) < DEAD_ZONE)
moveHorizontalstick2 = 0.f;
moveVerticalstick2 =
(f32)joystickData2.Axis[SEvent::SJoystickEvent::AXIS_R] / 32767.f;
if(fabs(moveVerticalstick2) < DEAD_ZONE)
moveVerticalstick2 = 0.f;
const u16 povDegrees = joystickData.POV / 100;
if(povDegrees < 360)
{
if(povDegrees > 0 && povDegrees < 180)
moveHorizontal = -1.f;
else if(povDegrees > 180)
moveHorizontal = 1.f;
if(povDegrees > 180 && povDegrees < 360)
moveVertical = 1.f;
else if(povDegrees > 360 || povDegrees < 180)
moveVertical = -1.f;
}
const u16 povDegrees2 = joystickData2.POV / 100;
if(povDegrees2 < 360)
{
if(povDegrees2 > 0 && povDegrees2 < 180)
moveHorizontalstick2 = -1.f;
else if(povDegrees2 > 180)
moveHorizontalstick2 = 1.f;
if(povDegrees2 > 180 && povDegrees2 < 360)
moveVerticalstick2 = 1.f;
else if(povDegrees2 > 360 || povDegrees2 < 180)
moveVerticalstick2 = -1.f;
}
if(!core::equals(moveHorizontal, 0.f) || !core::equals(moveVertical, 0.f))
{
nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime * moveHorizontal;
nodePosition.X += MOVEMENT_SPEED * frameDeltaTime * moveVertical;
movedWithJoystick = true;
camera->setPosition(nodePosition);
}
if(!core::equals(moveHorizontalstick2, 0.f) || !core::equals(moveVerticalstick2, 0.f))
{
nodeRotation.Y += MOVEMENT_SPEED2 * frameDeltaTime * moveHorizontalstick2;
nodeRotation.Y += MOVEMENT_SPEED2 * frameDeltaTime * moveVerticalstick2;
movedWithJoystick = true;
camera->setRotation(nodeRotation);
}
}
markmze
Posts: 24 Joined: Fri Apr 19, 2013 1:09 am
Post
by markmze » Tue May 14, 2013 7:26 pm
I'm trying to do something like that for making my camera moving relative to the view orientation and not the scene :
Code: Select all
if(!core::equals(moveHorizontal, 0.f) || !core::equals(moveVertical, 0.f))
{
nodeRotation2 = camera->getRotation();
if((nodeRotation2.Y > 0 && nodeRotation2.Y < 90) || (nodeRotation2.Y > 270 && nodeRotation2.Y < 360)){
nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime * moveHorizontal;}
if(nodeRotation2.Y > 90 && nodeRotation2.Y < 270){
nodePosition.Z += MOVEMENT_SPEED2 * frameDeltaTime * (-moveHorizontal);}
if(nodeRotation2.Y > 180 && nodeRotation2.Y < 360){
nodePosition.X += MOVEMENT_SPEED2 * frameDeltaTime * (-moveVertical);}
if(nodeRotation2.Y > 0 && nodeRotation2.Y < 180){
nodePosition.X += MOVEMENT_SPEED2 * frameDeltaTime * (moveVertical);}
movedWithJoystick = true;
camera->setPosition(nodePosition);
}
With absolutely no success... Any tips guys?
CuteAlien
Admin
Posts: 9734 Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:
Post
by CuteAlien » Wed May 15, 2013 9:08 am
Check the code of CSceneNodeAnimatorCameraFPS::animateNode, I think it does more or less what you want to do. It's in CSceneNodeAnimatorCameraFPS.cpp
markmze
Posts: 24 Joined: Fri Apr 19, 2013 1:09 am
Post
by markmze » Wed May 15, 2013 4:37 pm
Couldn't find what you are talking about !
Anyway, i did it my way :
Code: Select all
core::vector3df nodePosition = camera->getPosition();
core::vector3df nodeRotation = camera->getRotation();
core::vector3df nodeRotation2 = camera->getRotation();
bool movedWithJoystick = false; //to check if we are using joystick
if(joystickInfo.size() > 0) //if we are using joystick do:
{
f32 moveHorizontal = 0.f;
f32 moveVertical = 0.f;
f32 moveHorizontalstick2 = 0.f;
f32 moveVerticalstick2 = 0.f;
const SEvent::SJoystickEvent & joystickData = receiver.GetJoystickState();
const SEvent::SJoystickEvent & joystickData2 = receiver.GetJoystickState();
const f32 DEAD_ZONE = 0.5f; //to prevent
moveHorizontal =
(f32)joystickData.Axis[SEvent::SJoystickEvent::AXIS_X] / 32767.f;
if(fabs(moveHorizontal) < DEAD_ZONE)
moveHorizontal = 0.f;
moveVertical =
(f32)joystickData.Axis[SEvent::SJoystickEvent::AXIS_Y] / 32767.f;
if(fabs(moveVertical) < DEAD_ZONE)
moveVertical = 0.f;
moveHorizontalstick2 =
(f32)joystickData2.Axis[SEvent::SJoystickEvent::AXIS_Z] / 32767.f;
if(fabs(moveHorizontalstick2) < DEAD_ZONE)
moveHorizontalstick2 = 0.f;
moveVerticalstick2 =
(f32)joystickData2.Axis[SEvent::SJoystickEvent::AXIS_R] / -32767.f;
if(fabs(moveVerticalstick2) < DEAD_ZONE)
moveVerticalstick2 = 0.f;
const u16 povDegrees = joystickData.POV / 100;
if(povDegrees < 360)
{
if(povDegrees > 0 && povDegrees < 180)
moveHorizontal = -1.f;
else if(povDegrees > 180)
moveHorizontal = 1.f;
if(povDegrees > 90 && povDegrees < 270)
moveVertical = 1.f;
else if(povDegrees > 270 || povDegrees < 90)
moveVertical = -1.f;
}
nodeRotation2 = camera->getRotation();
const u16 povDegrees2 = joystickData2.POV / 100;
if(povDegrees2 < 360)
{
if(povDegrees2 > 0 && povDegrees2 < 180)
moveHorizontalstick2 = -1.f;
else if(povDegrees2 > 180)
moveHorizontalstick2 = 1.f;
if(povDegrees2 > 90 && povDegrees2 < 270)
moveVerticalstick2 = -1.f;
else if(povDegrees2 > 270 || povDegrees2 < 90)
moveVerticalstick2 = 1.f;
}
if(!core::equals(moveVerticalstick2, 0.f))
{
nodeRotation.Y += MOVEMENT_SPEED2 * frameDeltaTime * (-moveVerticalstick2);
movedWithJoystick = true;
camera->setRotation(nodeRotation);
}
/* Here is the part that doesn't work, don't know why.
if(!core::equals(moveHorizontalstick2, 0.f))
{
if((nodeRotation2.Y > 0 && nodeRotation2.Y < 30) || (nodeRotation2.Y > 330 && nodeRotation2.Y < 360)){
nodeRotation.X += MOVEMENT_SPEED * frameDeltaTime * (moveHorizontalstick2);}
if((nodeRotation2.Y > 60 && nodeRotation2.Y < 120)){
nodeRotation.Z += MOVEMENT_SPEED * frameDeltaTime * (moveHorizontalstick2);}
if((nodeRotation2.Y > 150 && nodeRotation2.Y < 210)){
nodeRotation.X += MOVEMENT_SPEED * frameDeltaTime * (moveHorizontalstick2);}
if((nodeRotation2.Y > 240 && nodeRotation2.Y < 300)){
nodeRotation.Z += MOVEMENT_SPEED * frameDeltaTime * (moveHorizontalstick2);}
////////////////////////////////////////////////////////////////////////
if((nodeRotation2.Y > 30 && nodeRotation2.Y < 60)){
nodeRotation.Z += MOVEMENT_SPEED * frameDeltaTime * (moveHorizontalstick2);
nodeRotation.X += MOVEMENT_SPEED * frameDeltaTime * (moveHorizontalstick2);
}
if((nodeRotation2.Y > 120 && nodeRotation2.Y < 150)){
nodeRotation.Z += MOVEMENT_SPEED * frameDeltaTime * (moveHorizontalstick2);
nodeRotation.X += MOVEMENT_SPEED2 * frameDeltaTime * (moveHorizontalstick2);
}
if((nodeRotation2.Y > 210 && nodeRotation2.Y < 240)){
nodeRotation.Z += MOVEMENT_SPEED * frameDeltaTime * (moveHorizontalstick2);
nodeRotation.X += MOVEMENT_SPEED2 * frameDeltaTime * (moveHorizontalstick2);}
if((nodeRotation2.Y > 300 && nodeRotation2.Y < 330)){
nodeRotation.Z += MOVEMENT_SPEED * frameDeltaTime * (moveHorizontalstick2);
nodeRotation.X += MOVEMENT_SPEED2 * frameDeltaTime * (moveHorizontalstick2);
}
movedWithJoystick = true;
camera->setRotation(nodeRotation);
}
*/
if(!core::equals(moveVertical, 0.f))
{
if((nodeRotation2.Y > 0 && nodeRotation2.Y < 30) || (nodeRotation2.Y > 330 && nodeRotation2.Y < 360)){
nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime * (-moveVertical);}
if((nodeRotation2.Y > 60 && nodeRotation2.Y < 120)){
nodePosition.X += MOVEMENT_SPEED * frameDeltaTime * (-moveVertical);}
if((nodeRotation2.Y > 150 && nodeRotation2.Y < 210)){
nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime * (moveVertical);}
if((nodeRotation2.Y > 240 && nodeRotation2.Y < 300)){
nodePosition.X += MOVEMENT_SPEED * frameDeltaTime * (moveVertical);}
////////////////////////////////////////////////////////////////////////
if((nodeRotation2.Y > 30 && nodeRotation2.Y < 60)){
nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime * (-moveVertical);
nodePosition.X += MOVEMENT_SPEED * frameDeltaTime * (-moveVertical);
}
if((nodeRotation2.Y > 120 && nodeRotation2.Y < 150)){
nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime * (moveVertical);
nodePosition.X += MOVEMENT_SPEED2 * frameDeltaTime * (-moveVertical);
}
if((nodeRotation2.Y > 210 && nodeRotation2.Y < 240)){
nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime * (moveVertical);
nodePosition.X += MOVEMENT_SPEED2 * frameDeltaTime * (moveVertical);}
if((nodeRotation2.Y > 300 && nodeRotation2.Y < 330)){
nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime * (-moveVertical);
nodePosition.X += MOVEMENT_SPEED2 * frameDeltaTime * (moveVertical);
}
camera->setPosition(nodePosition);
}
if(!core::equals(moveHorizontal, 0.f))
{
if((nodeRotation2.Y > 0 && nodeRotation2.Y < 30) || (nodeRotation2.Y > 330 && nodeRotation2.Y < 360)){
nodePosition.X += MOVEMENT_SPEED * frameDeltaTime * (moveHorizontal);}
if((nodeRotation2.Y > 60 && nodeRotation2.Y < 120)){
nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime * (-moveHorizontal);}
if((nodeRotation2.Y > 150 && nodeRotation2.Y < 210)){
nodePosition.X += MOVEMENT_SPEED * frameDeltaTime * (-moveHorizontal);}
if((nodeRotation2.Y > 240 && nodeRotation2.Y < 300)){
nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime * (moveHorizontal);}
////////////////////////////////////////////////////////////////////////
if((nodeRotation2.Y > 30 && nodeRotation2.Y < 60)){
nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime * (-moveHorizontal);
nodePosition.X += MOVEMENT_SPEED * frameDeltaTime * (moveHorizontal);
}
if((nodeRotation2.Y > 120 && nodeRotation2.Y < 150)){
nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime * (-moveHorizontal);
nodePosition.X += MOVEMENT_SPEED2 * frameDeltaTime * (-moveHorizontal);
}
if((nodeRotation2.Y > 210 && nodeRotation2.Y < 240)){
nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime * (moveHorizontal);
nodePosition.X += MOVEMENT_SPEED2 * frameDeltaTime * (-moveHorizontal);}
if((nodeRotation2.Y > 300 && nodeRotation2.Y < 330)){
nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime * (moveHorizontal);
nodePosition.X += MOVEMENT_SPEED2 * frameDeltaTime * (moveHorizontal);
}
camera->setPosition(nodePosition);
}
}
It all works fine for the movement and the horizontal vision, but not for the vertical vision, I'm trying to figure out why.
But vertical vision works with the two top triggers RT LT... And I just don't know why !
Anyway, I hope someone would find this helpful. And if you don't manage to integrate it, just ask, it would be a pleasure.