Page 1 of 1

Problems with camera type.

Posted: Wed Jan 18, 2006 5:58 am
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.

Posted: Wed Jan 18, 2006 7:40 am
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.

Posted: Wed Jan 18, 2006 7:48 am
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.

Posted: Wed Jan 18, 2006 7:53 am
by xterminhate
In my own editor, I develop a FPS-like camera, so that I keep control of the GUI cursor......

Posted: Wed Jan 18, 2006 8:00 am
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!

Posted: Wed Jan 18, 2006 9:02 am
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

Posted: Wed Jan 18, 2006 10:18 am
by PsycoDad
THX! For me this is a great help!!

Posted: Thu Jan 19, 2006 1:11 am
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?

Posted: Thu Jan 19, 2006 6:12 am
by vitek
Close. The name is czech, but I'm from Oregon, USA.

Posted: Fri Jan 20, 2006 6:20 am
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,

Posted: Fri Jan 27, 2006 2:49 am
by Barts_706
Excellent job, Vitek!

It is a very good, utilisable and flexible piece of code. My compliments and my thanks!

Posted: Thu Mar 16, 2006 2:50 pm
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.

Posted: Thu Mar 16, 2006 5:55 pm
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