Page 1 of 1

Problem with resetting the camera?

Posted: Thu Jan 26, 2006 6:41 am
by Barts_706
Hello again,

I tried to write a code in my program that would remember the first position and target of the camera, and if user clicks the button called 'Reset' it resets (duh) the camera to that starting position.

First part of code :

Code: Select all

	smgr->addCameraSceneNodeMaya();
	CameraStartPos = Device->getSceneManager()->getActiveCamera()->getPosition();
      CameraStartTar = Device->getSceneManager()->getActiveCamera()->getTarget();
And after button click :

Code: Select all

Device->getSceneManager()->getActiveCamera()->setPosition(CameraStartPos);
Device->getSceneManager()->getActiveCamera()->setTarget(CameraStartTar);
The problem is that after clicking the button for a split second I see the correct result (the change is applied) and then all the objects disappear (it is as if the camera was becoming invalid, off, or what?). Does any of you know what I do wrong and could suggest how to rewrite this part of code?

Posted: Thu Jan 26, 2006 8:29 pm
by pfo
and then all the objects disappear (it is as if the camera was becoming invalid, off, or what?)
sounds like maybe a bad value is being applied to the camera's position, like a -1.#IND, check it with the debugger and verify this isn't happening.

Posted: Fri Jan 27, 2006 1:48 am
by Barts_706
No, the values passed are correct, but just after that something strange happens, as if the camera go invalidated.

Any suggestions someone?

Posted: Fri Jan 27, 2006 2:14 am
by vitek
This seems to work fine..

Code: Select all

class MyEventReceiver : public IEventReceiver 
{ 
public: 
   MyEventReceiver()
   {
   } 


   virtual bool OnEvent(SEvent event)
   {
      if (event.EventType == EET_KEY_INPUT_EVENT)
      {
         // s key saves camera state
         if (event.KeyInput.Key == KEY_KEY_S && event.KeyInput.PressedDown) 
         {
            scene::ICameraSceneNode* theCamera = Device->getSceneManager()->getActiveCamera(); 
            From = theCamera->getPosition(); 
            Target = theCamera->getTarget(); 
            Proj = theCamera->getProjectionMatrix(); 
            return true;
         }
      
         // r key restores camera state
         else if (event.KeyInput.Key == KEY_KEY_R && event.KeyInput.PressedDown) 
         { 
            scene::ICameraSceneNode* theCamera = Device->getSceneManager()->getActiveCamera(); 
            theCamera->setPosition(From); 
            theCamera->setTarget(Target); 
            theCamera->setProjectionMatrix(Proj); 
            return true;
         } 
      }

      return false;
   }

private:
   core::vector3df From; // put the camera where the old camera was 
   core::vector3df Target; // point the new camera at the same location as the old one 
   core::matrix4 Proj; // set the projection matrix (fov and friends) 
};

Posted: Fri Jan 27, 2006 4:19 am
by Barts_706
Well, my code was pretty similar, but I copy-pasted yours just in case.

And unfortunately the same error persists : when I click the "Reset scene" button, there is a split second blink, when the scene is reset (I can see that the camera and objects come to their initial positions), and then every object disappears.

I do not have the slightest idea why this happens.

I checked all the settings (visible, drop etc), to ensure that the objects are not lost from sight for some other reason, but I haven't found any other cause.

Posted: Fri Jan 27, 2006 6:29 am
by vitek
As I said, the above code worked just fine for me. Maybe the camera is being accessed from somewhere else? If you look in the debugger, are the look from and look at values correct?

It may help to reduce your code down to a simple test case. If you are able to reduce it down to something small, then post it. If it starts working all of the sudden, then figure out what you changed...

Posted: Fri Jan 27, 2006 7:06 pm
by needforhint
try getAbsolutePosition() , as your camera might get transported of the space you want, relative position works strange

Posted: Mon Jan 30, 2006 2:30 am
by Barts_706
hmm.. not quite, but still experimenting... Thanks for your contribution nevertheless.

Posted: Wed Apr 12, 2006 11:50 am
by Marvek
Hi

Did you manage to solve your problem? I have quite a similar problem, everything is ok for first time the scene is drawn, but then everything just disappears. With FPS-camera everything looks right and my camera is never moved, so I'm quite out of solutions in this one.