modifying the camera controls
-
- Posts: 271
- Joined: Sat Aug 23, 2003 5:52 pm
- Location: Hurricane Central, Florida
modifying the camera controls
Is there a way to override the camera controls and set different keys, like W,S,A,D instead of the arrows?
Is there a way to change the speed of the camera while moving? Such as, increase the speed the longer the up button is held down (to a max) and keep moving forward at that speed after the button is released. Then there could be a way to slow down such as pressing the down button.
Is there a way to make the camera able to flip over instead of stopping the rotation when looking straight up and down. I want it to be able to move freely around in all directions with no restrictions. This would of course cause the camera to end up rotated on it sides, etc. after moving around but that is what I'm looking for. Will this require hacking into the actual engine code for the camera?
Is there a way to change the speed of the camera while moving? Such as, increase the speed the longer the up button is held down (to a max) and keep moving forward at that speed after the button is released. Then there could be a way to slow down such as pressing the down button.
Is there a way to make the camera able to flip over instead of stopping the rotation when looking straight up and down. I want it to be able to move freely around in all directions with no restrictions. This would of course cause the camera to end up rotated on it sides, etc. after moving around but that is what I'm looking for. Will this require hacking into the actual engine code for the camera?
-
- Posts: 271
- Joined: Sat Aug 23, 2003 5:52 pm
- Location: Hurricane Central, Florida
-
- Posts: 271
- Joined: Sat Aug 23, 2003 5:52 pm
- Location: Hurricane Central, Florida
I know there's not anything in this forum, I checked the old one though and the closest thing I could find was a question on disabling mouse camera control. In which Niko said to derive a new camera class and create the input from scratch. So I guess I'm gonna have to do this in order to make my "SpaceCamera" that can rotate and move in all directions and have user-defined controls. So, anyone know how to get the mouse input? Maybe I'll just find the FPSCamera class, copy it, and modify it to do what I want for my camera...
Is there an easier way to just override the FPSCamera
Is there an easier way to just override the FPSCamera
-
- Posts: 64
- Joined: Mon Sep 08, 2003 8:21 am
- Location: Paris, France
Yanking this straight from CCameraFPSSceneNode.c
It basically just says, if the camea isn't at 0.5,0.5 (dead center) then move the camera and move the cursor back to center.
You can override this by adding to your app:
Code: Select all
s32 now = os::Timer::getTime();
s32 moved = now - LastKeyTime;
LastKeyTime = now;
// Update rotation
Target.set(0,0,1);
if (!CursorControl)
return;
core::position2d<f32> cursorpos = CursorControl->getRelativePosition();
if (cursorpos.X < 0.49f || cursorpos.X > 0.51f ||
cursorpos.Y < 0.49f || cursorpos.Y > 0.51f)
{
RotationX += (0.5f - cursorpos.X) * RotateSpeed;
RotationY += (0.5f - cursorpos.Y) * RotateSpeed;
CursorControl->setPosition(0.5f, 0.5f);
if (RotationY > 89.0f) RotationY = 89.0f;
if (RotationY < -89.0f) RotationY = -89.0f;
}
// set target
core::matrix4 mat;
mat.setRotationDegrees(core::vector3df(-RotationY, -RotationX, 0));
mat.transformVect(Target);
You can override this by adding to your app:
Code: Select all
/*----------------------------------------------------------------------------------------------
Event Handler
----------------------------------------------------------------------------------------------*/
bool MyApp::OnEvent(irr::SEvent event)
{
if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
{
//I'll do my own mouse handling here
return false;
} else {
return device->getSceneManager()->getActiveCamera()->OnEvent(event);
}
}
Crud, how do I do this again?
-
- Posts: 64
- Joined: Mon Sep 08, 2003 8:21 am
- Location: Paris, France
Here is my bad and ugly code :
With this, i can move camera by stay clicked on the right mouse button and moving the mouse.
Is not optimized, just for the demo.
I just put this in my declaration :
And after, in my OnEvent interface, i code this :
With this, i can move camera by stay clicked on the right mouse button and moving the mouse.
Is not optimized, just for the demo.
I just put this in my declaration :
Code: Select all
bool stayRClicked;
s32 oldMouseInputX, oldMouseInputY;
Code: Select all
if (event.EventType==EET_MOUSE_INPUT_EVENT && stayRClicked && event.MouseInput.Event==EMIE_MOUSE_MOVED)
{
s32 deltaX=oldMouseInputX-event.MouseInput.X;
s32 deltaZ=oldMouseInputY-event.MouseInput.Y;
vector3df deltaXZ(deltaZ,0,deltaX);
vector3df positionCamera(camera->getPosition());
vector3df targetCamera(camera->getTarget());
positionCamera+=deltaXZ;
targetCamera+=deltaXZ;
camera->setTarget(targetCamera);
camera->setPosition(positionCamera);
oldMouseInputX=event.MouseInput.X;
oldMouseInputY=event.MouseInput.Y;
}
if (event.EventType==EET_MOUSE_INPUT_EVENT &&
event.MouseInput.Event==EMIE_RMOUSE_PRESSED_DOWN)
{
stayRClicked=true;
oldMouseInputX=event.MouseInput.X;
oldMouseInputY=event.MouseInput.Y;
}
if (event.EventType==EET_MOUSE_INPUT_EVENT &&
event.MouseInput.Event==EMIE_RMOUSE_LEFT_UP)
{
stayRClicked=false;
}
N00b attack
I was thinking, once you have disabled the rotation and movement settings of the FPS camera how hard would it be to implement a simple screen scroll ala the RTS games of today. The below code probably has a few syntax error's coz I am shattered at the moment but you should be able to see what I am getting at:
And so on for the other 3 movements. Set a small increment in there and it should make the screen scroll as long as the mouse is at the far of the screen.
Code: Select all
core::position2d<s32> mousePos = device->getCursorControl()->getPosition();
bool screenScrollLeft ()
{
return (mousePos.X == 0f)
}
if (screenScrollLeft = true)
{
// Move camera Left
}
-
- Posts: 271
- Joined: Sat Aug 23, 2003 5:52 pm
- Location: Hurricane Central, Florida
Actually I was trying to make the game have realistic space physics. I just got it working last night with a lot of modifications to the CCameraFPSSceneNode class and it works freakin awesome... just like flying in zero-gravity. With v0.4.1 Niko made it possible to define additional control keys so the only problem I have left to solve is the rotations. I plan to add a right vector in the engine code in addition to the upVector and use the cross product of the right and target vector to constantly calculate a new upVector so that the player can fully rotate around 360 deg upside down, etc. I hope it works, has anyone else tried this???
I'm trying the exact same thing right now. I don't quite understand what the cameras are doing sometimes. I can't seem to turn the event receiver off for the FPS camera since version 0.4.1 (setInputReceiverEnabled' : is not a member of 'ICameraSceneNode) even though the documentation says it is. The other problem I'm having is the standard ICameraSceneNode seems to ignore 'Rotation' changes and only responds to 'Target' changes. Changing this target 100 times a second has wierd results for me thus far. I welcome any advice .