camera nodes, why two?

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
kryton9
Posts: 20
Joined: Sun Feb 22, 2009 7:26 pm

camera nodes, why two?

Post by kryton9 »

ISceneNode which gives functions to ICameraSceneNode, has many of the camera functions like position, target and FOV... And irr::scene::ISceneNodeAnimatorCameraFPS has speed related stuff.

How would I combine their functionality so that my camera can take advantage of all the useful methods from the above Interfaces?

For Example:
I can do:
camera->setAspectRatio(16.0f / 9.0f);
but not:
camera->setMoveSpeed(12.0f);

This seems like a logical way it should work, what am I missing?
Eigen
Competition winner
Posts: 375
Joined: Fri Jan 27, 2006 2:01 pm
Location: Estonia
Contact:

Post by Eigen »

ISceneNodeAnimatorCameraFPS class inherits ICameraSceneNode, so all the methods available there are also available in FPSCamera.
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

Post by Ion Dune »

Eigen wrote:ISceneNodeAnimatorCameraFPS class inherits ICameraSceneNode, so all the methods available there are also available in FPSCamera.
No it doesn't.

However, by using getAnimators() on your camera and searching for the animator with the type ESNAT_CAMERA_FPS, you can locate the pointer of the animator, cast it, and use it.
Eigen
Competition winner
Posts: 375
Joined: Fri Jan 27, 2006 2:01 pm
Location: Estonia
Contact:

Post by Eigen »

Oh, sorry. I didn't notice it was an animator. Thought it was a camera node. .. My bad : )
But since when is the FPS-camera an animator? In SVN version?
kryton9
Posts: 20
Joined: Sun Feb 22, 2009 7:26 pm

Post by kryton9 »

Ion Dune wrote:
Eigen wrote:ISceneNodeAnimatorCameraFPS class inherits ICameraSceneNode, so all the methods available there are also available in FPSCamera.
No it doesn't.

However, by using getAnimators() on your camera and searching for the animator with the type ESNAT_CAMERA_FPS, you can locate the pointer of the animator, cast it, and use it.
Thanks, I will try to figure out what you said. It just seems strange that these methods would not be available readily as I wrote in the first post. They are things that one needs for a camera that is for sure.
Thanks again for some direction.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

kryton9 wrote: Thanks, I will try to figure out what you said. It just seems strange that these methods would not be available readily as I wrote in the first post. They are things that one needs for a camera that is for sure.
Thanks again for some direction.
Well not really. not everyone wants a camera to be a fps camera.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

Post by Ion Dune »

Eigen wrote:Oh, sorry. I didn't notice it was an animator. Thought it was a camera node. .. My bad : )
But since when is the FPS-camera an animator? In SVN version?
It was a change implemented for 1.5, as indicated by the changes.txt file :lol:
Sudi wrote:Well not really. not everyone wants a camera to be a fps camera.
Quite indeed. The FPS camera included with irrlicht is intended more as a simple device to be used for demos or testing.
kryton9
Posts: 20
Joined: Sun Feb 22, 2009 7:26 pm

Post by kryton9 »

@Ion Dune Thanks, I got it working with the tips that you gave.

About the FPS camera, it is confusing I think. It should be called DemoCamera then and not FPS Camera or FPCamera, First Person Camera.
FPS stands for First Person Shooter and that usually means many more functions, jump, crouch, crawl, look around corners just to name a few, in addition to running and walking.

But I am happy now that I got an idea of how to do what I need. Thanks again.
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

well actually shouldn't the features u just mentioned
all that should be done within your game logic.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Ion Dune
Posts: 453
Joined: Mon Nov 12, 2007 8:29 pm
Location: California, USA
Contact:

Post by Ion Dune »

kryton9 wrote:It should be called DemoCamera then and not FPS Camera or FPCamera, First Person Camera.
That's an idea of merit, but it's best to avoid changes to the API which would make older code unusable unless absolutely necessary.

Besides, the documentation outlines this pretty clearly:

Code: Select all

//! Adds a camera scene node with an animator which provides mouse and keyboard control appropriate for first person shooters (FPS).
/** This FPS camera is intended to provide a demonstration of a
camera that behaves like a typical First Person Shooter. It is
useful for simple demos and prototyping but is not intended to
provide a full solution for a production quality game. 
kryton9
Posts: 20
Joined: Sun Feb 22, 2009 7:26 pm

Post by kryton9 »

About code breaking, yes... too late to change now. And as you pointed out it is mentioned clearly in the documentation, so not really complaining just confused, but now I have a clearer picture of how it works. The posts here helped thanks to all responders.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Re: camera nodes, why two?

Post by Acki »

kryton9 wrote:camera nodes, why two?
just as a side note: there are 3 cameras (standard, FPS and Maya)... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
kryton9
Posts: 20
Joined: Sun Feb 22, 2009 7:26 pm

the solution

Post by kryton9 »

I realized I forgot to post the solution, so here is a basic example:

Code: Select all

// WSAD to move the camera
// mouse to steer
//
// Escape to exit
//
// Arrow keys to set the
// camera's move speed
//
// Up twice as fast
// Down 1/10 as fast
// Left 1/100 as fast
// Right reset to original speed (0.1f)
//
#include <irrlicht.h>
#include <windows.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace gui;

bool keys[irr::KEY_KEY_CODES_COUNT];


class MyEventReceiver : public IEventReceiver
{
public:
    virtual bool OnEvent(const SEvent& event)
    {
        if (event.EventType == irr::EET_KEY_INPUT_EVENT)
        {
            keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
            return false;
        }
        return false;
    }
};


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{

    //Key Map allows us to set which keys to use as we want for basic fps movement
    SKeyMap keyMap[8];

    keyMap[1].Action = EKA_MOVE_FORWARD;
    keyMap[1].KeyCode = KEY_KEY_W;

    keyMap[3].Action = EKA_MOVE_BACKWARD;
    keyMap[3].KeyCode = KEY_KEY_S;

    keyMap[5].Action = EKA_STRAFE_LEFT;
    keyMap[5].KeyCode = KEY_KEY_A;

    keyMap[7].Action = EKA_STRAFE_RIGHT;
    keyMap[7].KeyCode = KEY_KEY_D;


    // Init irrlicht
    IrrlichtDevice *device = createDevice(EDT_OPENGL,dimension2d<u32>(800, 600),16,false,false,false);
    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();

    // Setup event reciever
    MyEventReceiver rv;
    device->setEventReceiver(&rv);

    // Init keystates array
    for (int x=0; x<irr::KEY_KEY_CODES_COUNT; x++) keys[x] = false;

    // Add a sphere
    ISceneNode* sphere = smgr->addSphereSceneNode(10,32);
    sphere->setPosition(vector3df(0,0,0));
    sphere->setMaterialFlag(EMF_LIGHTING, true);

    // Add a light
    smgr->addLightSceneNode(0, vector3df(-25,5,-25),
                           SColorf(1.0f, 0.5f, 0.0f, 0.0f), 15.0f);

    // Add a camera
    irr::f32 fv = 10000;
    //////////////////////////////////////////////////////////////////////////////////
    //when the camera is added the moveSpeed is 0.1f---------------|
    ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(0, 50.0f, 0.1f, -1, keyMap, 8);
    //////////////////////////////////////////////////////////////////////////////////
    cam->setFarValue(fv);
    cam->setPosition(vector3df(0,0,-50));
    cam->setTarget(vector3df(0,0,0));
    device->setWindowCaption(L"WSAD to move, Arrow keys change set speed, Esc to Exit");

    //////////////////////////////////////////////////////////////////////////////////
    //here we are doing the search for the camera animator and casting it to camAnim
    //////////////////////////////////////////////////////////////////////////////////
    ISceneNodeAnimatorCameraFPS* camAnim = NULL;
    const core::list<ISceneNodeAnimator*> & animators = cam->getAnimators();
    core::list<ISceneNodeAnimator*>::ConstIterator it = animators.begin();
    while(it != animators.end())
    {
        if(ESNAT_CAMERA_FPS == (*it)->getType())
        {
            camAnim = static_cast<ISceneNodeAnimatorCameraFPS *>(*it);
        }
        it++;
    }

    // disable mouse cursor
	device->getCursorControl()->setVisible(false);

    // Main game loop
    while (device->run() && device)
    {
        //sets cam's move speed
        //twice as fast
        if (keys[KEY_UP])
        {
            camAnim->setMoveSpeed(0.2f);
            device->setWindowCaption(L"Twice as fast now: 0.2f");
        }

        //1/10 as fast
        if (keys[KEY_DOWN])
        {
            camAnim->setMoveSpeed(0.01f);
            device->setWindowCaption(L"1/10 original speed now: 0.01f");
        }

        //1/100 as fast
        if (keys[KEY_LEFT])
        {
            camAnim->setMoveSpeed(0.001f);
            device->setWindowCaption(L"1/100 original speed now: 0.001f");
        }

        //original speed
        if (keys[KEY_RIGHT])
        {
            camAnim->setMoveSpeed(0.1f);
            device->setWindowCaption(L"Original speed now: 0.1f");
        }

        //exit the program
        if (keys[KEY_ESCAPE])
        {
            device->closeDevice();
        }

        // Irrlicht rendering
        driver->beginScene(true, true, video::SColor(0,33,33,33));
            smgr->drawAll();
        driver->endScene();
    }
    device->drop();
    return 0;
}
Post Reply