Problems with camera type.

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
Barts_706
Posts: 26
Joined: Tue Nov 01, 2005 1:20 am

Problems with camera type.

Post by Barts_706 »

Hi,

I managed to use MeshViewer tutorial in order to create my application with 2d user interface and 3d presentation window. Okay.

Now the thing is, that in the first version of my program (without menus) I used FPS style camera (smgr->addCameraSceneNodeFPS(0, 100.0f, 100.0f);), and the MeshViewer example uses Maya style camera (smgr->addCameraSceneNodeMaya();). I would like to be able to switch between them, as both have some advantages. My first question is:

- how to change camera type? Do I have to reset scene? How do I do that?

The second problem is as follows :

- when I use the FPS type camera, it blocks mouse cursor movement and mouse input is used for looking around. Is it possible to switch this feature on and off with some command, so that mouse could be used either for navigating 2d menus OR looking around the scene?

I would be grateful for any replies. Thanks in advance.
PsycoDad
Posts: 36
Joined: Mon Jan 09, 2006 8:30 am
Location: Munich/Germany

Post by PsycoDad »

I have the same problem!
And i`m sorry, until jet, i don`t have an answer.
At the moment i have no time to play arround in irrlicht to find
the right way to go, but i can tell you what i think you have to do.

Check the event reciever tutorial and make a switch of the camera mods
by pressing a button.
I think from FPS to Maya would be good!
Please, let me know if you have a soulution.
Wer andern eine Bratwurst brät, der hat ein Bratwurstbratgerät!
Heizi
Posts: 30
Joined: Mon Oct 10, 2005 11:23 am
Location: Steinach/Baden

Post by Heizi »

smgr->setActiveCamera(camera handler1);
smgr->setActiveCamera(camera handler2);

maybe with that you can switch between the cameras.
When you create both cameras you should store them in
different handlers so one doesnt vanish.
Sorry but I dont know the answer to your 2nd question.
xterminhate
Posts: 206
Joined: Thu Sep 01, 2005 9:26 pm
Location: France

Post by xterminhate »

In my own editor, I develop a FPS-like camera, so that I keep control of the GUI cursor......
Return to Irrlicht after years... I'm lovin it.
It's hard to be a Man !
Si vis pacem para belum
PsycoDad
Posts: 36
Joined: Mon Jan 09, 2006 8:30 am
Location: Munich/Germany

Post by PsycoDad »

@xterminhate
I look at your H.E.L.P projekt, but my french is worser than my english,
and that will mean alot.
Where can i download the source code of your FPS!
Wer andern eine Bratwurst brät, der hat ein Bratwurstbratgerät!
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

First question...

Code: Select all


using namespace irr;
using namespace gui;
using namespace scene;

class MyEventReceiver : public IEventReceiver
{
public:
   MyEventReceiver(IrrlichtDevice* device)
      : Device(device)
   {
      Device->grab();
   }

   virtual ~MyEventReceiver()
   {
      Device->drop();

      // remove all cameras
      for (irr::s32 c = 0; c < Cameras.size(); ++c)
         Cameras[c]->drop();
   }

   bool InsertCamera(ICameraSceneNode* camera)
   {
      irr::s32 c = Cameras.linear_search(camera);
      if (c == -1)
      {
         Cameras.push_back(camera);
         camera->grab();
         return true;
      }

      return false;
   }

   bool RemoveCamera(ICameraSceneNode* camera)
   {
      irr::s32 c = Cameras.linear_search(camera);
      if (c != -1)
      {
         Cameras.erase(c);
         camera->drop();
         return true;
      }

      return false;
   }

   virtual bool OnEvent(SEvent event)
   {
      if (event.EventType == EET_KEY_INPUT_EVENT &&
          event.KeyInput.Key == KEY_KEY_C && event.KeyInput.PressedDown)
      {
         // if we have a camera to swap to, swap cameras
         if (!Cameras.empty())
         {
            ICameraSceneNode* oldCamera = Device->getSceneManager()->getActiveCamera();

            ICameraSceneNode* newCamera = Cameras[0];

            // remove the new camera from the list and put it at the end
            Cameras.erase(0);
            Cameras.push_back(newCamera);

            // put the camera where the old camera was
            core::vector3df from = oldCamera->getPosition();
            newCamera->setPosition(from);

            // point the new camera at the same location as the old one
            core::vector3df target = oldCamera->getTarget();
            newCamera->setTarget(target);

            // set the projection matrix (fov and friends)
            core::matrix4 proj = oldCamera->getProjectionMatrix();
            newCamera->setProjectionMatrix(proj);
            
            // replace old camera with new one
            Device->getSceneManager()->setActiveCamera(newCamera);

            return true;
         }
      }
   }

private:
   IrrlichtDevice* Device;

   // queue of cameras known by this event receiver, will cycle through them with C
   core::array<ICameraSceneNode*> Cameras;
};


int main(int argc, char* argv[])
{
   // ...

   // create event receiver that will manage cameras
   MyEventReceiver receiver(Device);
   Device->setEventReceiver(&receiver);

   // add fps camera
   ICameraSceneNode* fpsCamera = SceneManager->addCameraSceneNodeFPS();
   receiver.InsertCamera(fpsCamera);

   // add maya camera
   ICameraSceneNode* mayaCamera = SceneManager->addCameraSceneNodeMaya();
   receiver.InsertCamera(mayaCamera);

   // last camera added to scene manager will be active by default

   // ...

   return 0;
}
Second Question... You can temporarily disable the camera-follows-mouse behavior of the FPS camera by calling

Code: Select all

   Camera->setInputReceiverEnabled(false);
Travis
PsycoDad
Posts: 36
Joined: Mon Jan 09, 2006 8:30 am
Location: Munich/Germany

Post by PsycoDad »

THX! For me this is a great help!!
Wer andern eine Bratwurst brät, der hat ein Bratwurstbratgerät!
Barts_706
Posts: 26
Joined: Tue Nov 01, 2005 1:20 am

Post by Barts_706 »

Wow.

Thanks for the replies, everyone. I have just sat down to start working on that again, so I will test your solutions, investigate possible options and then post about results.

BTW, Vitek, where are you from? Poland, perhaps?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Close. The name is czech, but I'm from Oregon, USA.
Barts_706
Posts: 26
Joined: Tue Nov 01, 2005 1:20 am

Post by Barts_706 »

I am sorry Vitek, but I haven't checked your solution yet - some other wok piled up, so I will probably approach the problem on Monday. I'll let you know about the progress though and whether it worked or not.

Hmm, it is not only Czech - in Polish it is Witek, written with double-u, but pronounced identically. My cousin's name actually (yup, I'm Polish), so I thought I asked.

Regards,
Barts_706
Posts: 26
Joined: Tue Nov 01, 2005 1:20 am

Post by Barts_706 »

Excellent job, Vitek!

It is a very good, utilisable and flexible piece of code. My compliments and my thanks!
oleo
Posts: 27
Joined: Fri Dec 16, 2005 9:50 am

Post by oleo »

vitek wrote:First question...
cutting...
Travis
Hi Vitek!
Why do you handle Cameras inserting, removing and swapping inside event receiver? Is there a precise reason?
Thanks,
Fabio.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

  1. I usually write a full working test so that I know it works before I post it.
  2. I try to make the test as self contained and easy to use as possible.
  3. It was a simple way to illustrate everything that would be needed to answer the question completely.
Travis
Post Reply