Camera behind object

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.
Post Reply
Feuerstern
Posts: 7
Joined: Mon Aug 17, 2015 4:04 pm

Camera behind object

Post by Feuerstern »

Hello
Iam new with irrlicht and want to make a little space game.
I hava a spaceship and a camera behind the Ship. I want that the spaceship moves forward and the direction should change by moving the mouse. (like going in a first person shooter where the player goes in the direction where the camera looks, but in this case third person)
After thinking about it I think there are two option:
- Move the Spaceship in the direction I want and let the camera follow him with seting the spaceship as the parent of the camera.(then I have to find I way how to move the spaceship with the mouse, also when the mouse reach the corners of the window)
- Use a camera as the parent of the spaceship. (Then I need a camera which act how described above)

What is the best way to solve my problem? :?

Thanks for help

Feuerstern
CuteAlien
Admin
Posts: 9670
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Camera behind object

Post by CuteAlien »

It's both correct obviously (code how you feel it's better).

My way of doing is usually:

Control the space-ship - let the camera follow. It's kinda what you would do in the real-world (where we all are flying space-ships while camera-men are following us).

And if there are additional camera-controls I'll keep those in the camera.

For example in typical 3D RPG's you control your person with cursor-keys. And can rotate the camera around the person with the mouse. I think of that as 2 different controls - first one goes to the object - second one to the camera.
Reason is that it makes it easier to switch the camera. For example I might want to add another mode later on where a second person can follow the main objects. That person would have it's own camera-control, but wouldn't be allowed to control the object. Or I might want cameras which do cool replays so I record the object. And because the camera control is indepedent I can just make it follow then a recorded object later on.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Feuerstern
Posts: 7
Joined: Mon Aug 17, 2015 4:04 pm

Re: Camera behind object

Post by Feuerstern »

Thank you for you fast help :D
The method is that which I prefers, too.
But now I have the problem that when the mouse cursor leaves the window, it do not track the mouse position change anymore.
My code in my event receiver for mouse control is:

Code: Select all

 
bool MyEventReceiver::OnEvent(const SEvent &event)
{
    // Remember whether each key is down or up
    if (event.EventType == EET_KEY_INPUT_EVENT)
        mKeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
    else if (event.EventType == EET_MOUSE_INPUT_EVENT)
    {
        switch (event.MouseInput.Event)
        {
        case EMIE_MOUSE_MOVED:
            mOldMousePos = mActualMousePos;
            mActualMousePos.X = event.MouseInput.X;
            mActualMousePos.Y = event.MouseInput.Y;
            break;          
        } 
    }
    return false;
}
 
Do you have any idea how to solve the problem?
CuteAlien
Admin
Posts: 9670
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Camera behind object

Post by CuteAlien »

Typical solution is to hide the cursor while it's used to control the camera. So the player doesn't notice it's constantly positioned back to the center. Check a few games where the mouse controls the camera and you will notice it.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Feuerstern
Posts: 7
Joined: Mon Aug 17, 2015 4:04 pm

Re: Camera behind object

Post by Feuerstern »

I already hide the cursor. I dont move the Camera with the mouse, I rotate the spaceship with it. (depending on the direction the mouse is moved by the player)
My problem is that after a time the mouse reaches the edges of the window and then the nouse position do not change anymore.
When I position the mouse back to the center of the window after every frame the movements gets very jerky.
CuteAlien
Admin
Posts: 9670
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Camera behind object

Post by CuteAlien »

The movement should not get jerky if you do it correct. Because the relative movement is the same if you just continue endless or if you reset in between and check movement since last reset before. If it's jerky you probably reset in the wrong moment so you cut some of the movement data. Make sure you get the new position first and then reset.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Feuerstern
Posts: 7
Joined: Mon Aug 17, 2015 4:04 pm

Re: Camera behind object

Post by Feuerstern »

Thank you very much for you help, now it works :)
Post Reply