(solved yet)How to PAN left/right?

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
mybiandou
Posts: 32
Joined: Thu Sep 10, 2009 6:20 am

(solved yet)How to PAN left/right?

Post by mybiandou »

-------------------------------------------
Also by using projection matrix, I also have realize the pan view.
The source code has been changed correspondly.
And this article will be close.

Code: Select all

      ICameraSceneNode* cnode;
      cnode=Device->getSceneManager()->getActiveCamera(); 
      CMatrix4<f32> matProj;
      matProj=cnode->getProjectionMatrix();
      vector3df tx(0.1,0.0,0.0);
      matProj.setTranslation(matProj.getTranslation()+tx);
      cnode->setProjectionMatrix(matProj,true);
-------------------------------
I have realized the ZOOM in/out in ortho projection by using projection matrix. The following code has been changed accordingly.

Now, anyone can give me some hints about how to pan left/right/up/down?


---------------------------------------
Hello, everyone.

I am a new beginner to Irrlicht.

I wonder how to realize the ZOOM/PAN function just like in most of CAD software.
It is not the enlarge and movement of the body itself but it is the change of view position or direction(Camera's properties).

I can not find the clear answer after I have search this forum and google.

Someone suggested using setFOV, but I can not realize it.
As the following code shows,
even if I just get the camera.getFOV, and do not modify it,
then setFOV. The body can not be displayed.

Can any one help me to solve this problem? thank you in advance?

The source code is given as the follows

Code: Select all



#include <irrlicht.h>

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;


#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif


//----------------------------
//definition of BODY
class FasterBody
{
 public:
   FasterBody(void){
    name=L"";
    mesh=NULL;
    node=NULL;
    texture=NULL;                        
    };
   stringw name;
   IAnimatedMesh* mesh;
   IAnimatedMeshSceneNode* node;
   ITexture* texture;   
};

//global variables 

// Irrlicht Device
IrrlichtDevice *device ;

// store all of the body(Max=100)
FasterBody fbody[100];


enum
{
	GUI_ID_DIALOG_ROOT_WINDOW  = 0x10000,
	GUI_ID_WIREFRAME,
	GUI_ID_ZOOMIN,
    GUI_ID_PANLEFT    	
};



class MyEventReceiver:public IEventReceiver
{
public:

  virtual bool OnEvent(const SEvent& event)
  {
   //deal with menu event
    if (event.EventType == EET_GUI_EVENT)
    {
        s32 id = event.GUIEvent.Caller->getID();
        switch(event.GUIEvent.EventType)
        {

            case EGET_MENU_ITEM_SELECTED:
              {
                IGUIContextMenu* menu = (IGUIContextMenu*)event.GUIEvent.Caller;
                s32 id = menu->getItemCommandId(menu->getSelectedItem());                                        
                switch(id)
                {
                    case GUI_ID_WIREFRAME:
                        for(int idx=0;idx<100;idx++)
                          if(fbody[idx].mesh) fbody[idx].node->setMaterialFlag(EMF_WIREFRAME,true);
                        break;
                        
                    case GUI_ID_ZOOMIN:
                     {
                          //to do zoom  here!
                        ICameraSceneNode* camera;
                        camera=device->getSceneManager()->getActiveCamera(); 
      CMatrix4<f32> matProj;
      matProj=cnode->getProjectionMatrix();
      matProj.setScale(matProj.getScale()*1.1);
      camera->setProjectionMatrix(matProj,true);                        break;                        
                        }
                    case GUI_ID_PANLEFT:
                          //to do pan left here!                                             
                                             
                        break;                        
                        
                    default:
                        break;
                }
              }
        }
 
          
    }
    return false;      
          
  }
      
};




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

  video::E_DRIVER_TYPE driverType = video::EDT_OPENGL;

  MyEventReceiver Receiver;
	
  device = createDevice(driverType, core::dimension2d<s32>(1024, 768),
		16, false, false, false, &Receiver);
		
  if (device == 0)  return 1; 

  device->setWindowCaption(L"FBtester");
    
    
  video::IVideoDriver* driver = device->getVideoDriver();
  IGUIEnvironment* env = device->getGUIEnvironment();
  scene::ISceneManager* smgr = device->getSceneManager();
  

  // create menu
  gui::IGUIContextMenu* menu = env->addMenu();
  menu->addItem(L"Display", -1, true, true);

  gui::IGUIContextMenu* submenu= menu->getSubMenu(0);
  submenu->addItem(L"Wireframe", GUI_ID_WIREFRAME);  
  submenu->addItem(L"Zoom In", GUI_ID_ZOOMIN);    


// test model
//  fbody[0].mesh=smgr->getMesh("test.stl");
//  fbody[0].node=smgr->addAnimatedMeshSceneNode(fbody[0].mesh);
 // fbody[0].texture=driver->getTexture("water.jpg");
  
  smgr->addCubeSceneNode();

// make an ortho camera
  ICameraSceneNode *camera=smgr->addCameraSceneNode(0,vector3df(0,0,10000.0),vector3df(0.0,0.0,0.0));
  
  CMatrix4<f32> matProj;   
  matProj.buildProjectionMatrixOrthoLH   (1024,768,-100000,100000);
  camera->setProjectionMatrix(matProj,true);    

  while(device->run())
  {
    driver->beginScene(true, true, video::SColor(0,255,255,255));
	
	smgr->drawAll();
	env->drawAll();

	driver->endScene();
   
  }

//release the resource
  device->drop();


  return 0;    
   
}    


[/code]
Last edited by mybiandou on Wed Oct 14, 2009 9:25 am, edited 4 times in total.
cheshirekow
Posts: 105
Joined: Mon Jul 27, 2009 4:06 pm
Location: Cambridge, MA

Post by cheshirekow »

I suggest putting an empty scene node in your scene, and setting it as the target of a third-person style camera animator, with the camera as a child of that target. Then you can rotate your view around that point by normal rotations, you "zoom in" by moving your camera closer to that node, and you can "pan" by moving that node around in the scene. Then you wont have to work with all the math directly. You'll have to think a little about exactly where to put that point, depending on where the mouse is or what the object is you're trying to "zoom into", but it should still simplify the logic a lot.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Zooming is not done by moving closer to target point. If you stand in front of a wall and do that you're likely to move the camera through the wall and see what's on the other side which isn't what zooming should do!
Image Image Image
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

This is how I zoom in to make a mesh fill the screen in my thumbnailer-

Code: Select all

	// transform the camera's view to zoom in a bit
	core::matrix4 zoom;
	zoom.setScale(core::vector3df(1.0*zoomAmount, 1.0*zoomAmount, 1.0f));

	// zoom in
	core::matrix4 proj = zoom * Camera->getProjectionMatrix();
	Camera->setProjectionMatrix(proj);
It also translates, but I removed that code for ease of reading
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
mybiandou
Posts: 32
Joined: Thu Sep 10, 2009 6:20 am

Post by mybiandou »

Sir

By Mr. cheshirekow's suggestion,

I have put one empty node in the scene as the parent for all cameras

Code: Select all

//create the camera target empty scenen node;
camtarget=smgr->addEmptySceneNode();
//set its innitial position to (0,0,0)
camtarget->setPosition(irr::core::vector3df(0.0f,0.0f,0.0f));

//create some ortho cameras 
	CMatrix4<f32> matProj;
	zNear=-300000.0f;  
	zFar= 300000.0f;
       matProj.buildProjectionMatrixOrthoLH (1027,768,zNear,zFar);

	//create the top/side/view camera 
	//create the top view camera
	if(!topcam)
		topcam=smgr->addCameraSceneNode(camtarget);
	topcam->setProjectionMatrix(matProj,true);
	topcam->setPosition(irr::core::vector3df(0,0,zFar));
	topcam->setUpVector(irr::core::vector3df(1,0,0));

	//create the left view camera
	if(!leftcam)
		leftcam=smgr->addCameraSceneNode(camtarget);
	leftcam->setProjectionMatrix(matProj,true);
	leftcam->setPosition(irr::core::vector3df(-zFar,0,0));
	leftcam->setUpVector(irr::core::vector3df(0,0,1));

	//create the front view camera
	if(!frontcam)
		frontcam=smgr->addCameraSceneNode(camtarget);
	frontcam->setProjectionMatrix(matProj,true);
	frontcam->setPosition(irr::core::vector3df(0,zFar,0));
	frontcam->setUpVector(irr::core::vector3df(0,0,1));


// I use the following code to pan left/right/up/down
// first get the active camera up vector v3
// then get the vector from camera position to target position v2
//     because this is relative to the target, so it just equal to the camera position vector
// I can get v2 x v3 , which is perpendicular to up vector in camera plane
// The pan left/right shoulb along this vector
	ICameraSceneNode* cnode;
	cnode=smgr->getActiveCamera(); 
	irr::core::vector3df v1,v2,v3;
	v3=cnode->getUpVector();
	v2=cnode->getPosition();
	v2.normalize();
	v1=v2.crossProduct(v3);
	camtarget->setPosition( camtarget->getPosition()-v1*1000.0f);


//to verify the effects , I put two cubes in my scene
// one is the child of cam target, the other is the child of root
smgr->addCubeSceneNode(1000.0,camtarget);
smgr->addCubeSceneNode(2000.0,0,-1,irr::core::vector3df(0.0,3000,0.0));

I can see the move of the first cube, which if the child of cam target
But the second one can not move, which is not what I thought?

Any one can tell me why or how can realize the pan left/right/up/down in a simple way?




Image
Image
Post Reply