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]


