Is there an easy method to have an fps camera calculate from the center of the screen region instead of the center of the screen?
I have the level being rendered inside a guielement. When toggling the fps camera inputreceiver enabled, as long as the center of the guielement is also the center of the screen, there is no issue, but if the guielement is off to the side, say rendering at 0,0,600,800 then of course the cursor control is off by that much.
I will be digging into the code tonight, but thought someone else may have already accomplished this.
fps camera scale to window
Re: fps camera scale to window
ok so no simple method, but copying scenenodes, animatos and guielements to make new ones is becoming a daily experience.
we now have a CSSceneNodeAnimatorCameraFPS class that will allow the user to render the scene onto an arbitrary section of the screen and the fps camera will react properly.
well, we have a shell for it all. Tomorrow I will figure out the math behind it...
for now this all work fantastically......
1)save the viewport
2)set the viewport to the window location and size
3)render
4)restore the viewport back to the old size
unfortunately, the fps camera expects the viewport to be in the center of the main window.
added functionality for CursorOffset
math to figure out.
center of oldviewport is 0.5,0.5
what is center of temporary viewport relative to the oldviewport so that cursor control can be set properly
tomorrow will be a better time for math.
math is hard........
we now have a CSSceneNodeAnimatorCameraFPS class that will allow the user to render the scene onto an arbitrary section of the screen and the fps camera will react properly.
well, we have a shell for it all. Tomorrow I will figure out the math behind it...
for now this all work fantastically......
1)save the viewport
2)set the viewport to the window location and size
3)render
4)restore the viewport back to the old size
unfortunately, the fps camera expects the viewport to be in the center of the main window.
added functionality for CursorOffset
math to figure out.
center of oldviewport is 0.5,0.5
what is center of temporary viewport relative to the oldviewport so that cursor control can be set properly
tomorrow will be a better time for math.
math is hard........
Re: fps camera scale to window
I've had to make a custom fps type camera controller, it's not an animator or anything. It computes a 'MoveDelta' which you can apply towards your camera rotation. The only thing you should need to do to 'offset' the center position is change CursorControl->setPosition() to wherever you want to be the center of the screen. I'll go ahead and post it below.
Two things to take note here:
1st you can set "Mouse_Free" to true to disable updating the camera and resetting the mouse position, therefore you can freely move the mouse around on the screen to click buttons etc..
2nd I had to add a variable called "Mouse_IgnorePosUpdates" since this runs inside my event receiver whenever the mouse is moved thus calling "CursorControl->setPosition(0.5F, 0.5F)" would trigger the event in the event receiver and screw up the move delta.
This unfortunately only allows the move delta to be computed every other frame and could be avoided by having the ability to pass a bool into setPosition which controlled weather or not it would fire the event receiver, wink wink nudge nudge........
Code: Select all
irr::gui::ICursorControl* CursorControl;
irr::core::vector2di Mouse_LastPos;
irr::core::vector2di Mouse_MoveDelta;
bool Mouse_IgnorePosUpdates;
bool Mouse_Free;Code: Select all
if (!Mouse_IgnorePosUpdates)
{
irr::core::vector2di CursorPos = CursorControl->getPosition();
Mouse_MoveDelta = CursorPos - Mouse_LastPos;
if (!Mouse_Free)
{
//
// Update ControlledActor
if (ControlledActor != NULL)
{
irr::core::vector3df CameraRotation = ControlledActor->GetRotation();
CameraRotation.X += (0.2F*Mouse_MoveDelta.Y);
CameraRotation.Y += (0.2F*Mouse_MoveDelta.X);
ControlledActor->CameraRotated(CameraRotation.X, CameraRotation.Y, true);
}
CursorControl->setPosition(0.5F, 0.5F);
Mouse_IgnorePosUpdates = true;
}
Mouse_LastPos = CursorPos;
}
else {
Mouse_LastPos = CursorControl->getPosition();
Mouse_IgnorePosUpdates = false;
}1st you can set "Mouse_Free" to true to disable updating the camera and resetting the mouse position, therefore you can freely move the mouse around on the screen to click buttons etc..
2nd I had to add a variable called "Mouse_IgnorePosUpdates" since this runs inside my event receiver whenever the mouse is moved thus calling "CursorControl->setPosition(0.5F, 0.5F)" would trigger the event in the event receiver and screw up the move delta.
This unfortunately only allows the move delta to be computed every other frame and could be avoided by having the ability to pass a bool into setPosition which controlled weather or not it would fire the event receiver, wink wink nudge nudge........
Dream Big Or Go Home.
Help Me Help You.
Help Me Help You.
Re: fps camera scale to window
excellent. Thanks for the code!
Re: fps camera scale to window
You're welcome! Now if only there was a way to call CursorControl->setPosition() without it firing the event receiver.
Dream Big Or Go Home.
Help Me Help You.
Help Me Help You.
Re: fps camera scale to window
my end result :
my windows have a clientrect that I render the scene into
// get the center of the window
rect<s32> r = getClientRect();
vector2d<f32> center1;
// calculate the center of the window as a percentage of the entire screen
center1.X = (float)r.getCenter().X / oldViewport.getWidth();
center1.Y = (float)r.getCenter().Y / oldViewport.getHeight();
// set the cursor offset
m_CameraAnimator->setCursorOffset(center1.X, center1.Y);
now, everywhere that the fps camera uses 0.5f we change it to use m_CursorOffset (.X and .Y)
this works like a charm but I should probably call it setCursorCenterPosition() or something similar.......
anyhow, thanks again for the push. I am really getting excited about this project.