Guest User

Untitled

a guest
Oct 2nd, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 26.80 KB | None | 0 0
  1. #include "Editor.h"
  2.  
  3. Editor::Editor()
  4. :isSplitScreen(true),currentWindow(0),point_on(-1),mouse_down(false),KEY_MOVE_DOWN(false),KEY_SCALE_DOWN(false),menubar(NULL)
  5. {
  6.     for (int i=0;i<4;i++){
  7.         camera[i]=NULL;
  8.     }
  9.  
  10.     for (int i=0;i<12;i++){
  11.         points[i]=NULL;
  12.     }
  13.  
  14.     menus = new list<IEventReceiver*>();
  15. }
  16.  
  17. bool Editor::run(IrrlichtDevice* irr_device){
  18.     // Irrlicht Device
  19.     device=irr_device;
  20.     driver = device->getVideoDriver();
  21.     smgr = device->getSceneManager();
  22.     guienv = device->getGUIEnvironment();
  23.     coli=smgr->getSceneCollisionManager();
  24.     device->setEventReceiver(this);
  25.  
  26.     // Editor Settings
  27.     data=new ed_data();
  28.     data->snapping = true;
  29.     data->limiting = true;
  30.     data->type = TOOL_NODEB;
  31.     data->menu = NULL;
  32.  
  33.     // Load editor
  34.     Load_Scene();
  35.     Load_UI();
  36.  
  37.     // Create project
  38.     project = new Project();
  39.     project->nodes[0] = new Node(device,data);
  40.     MoveTarget(project->nodes[0]->getPosition());
  41.  
  42.     // Set up window   
  43.     device->setWindowCaption(convert((project->mod + stringc(" - The NodeBox Editor")).c_str()));
  44.     device->setResizable(true);
  45.  
  46.     // Step data
  47.     unsigned int counter=0;
  48.     dimension2d<irr::u32> last_render_size = driver->getCurrentRenderTargetSize();
  49.  
  50.     while (device->run()){
  51.         counter++;
  52.         driver->beginScene(true, true, irr::video::SColor(255,100,101,140));
  53.    
  54.         int ResX = driver->getScreenSize().Width;
  55.         int ResY = driver->getScreenSize().Height;
  56.  
  57.         if (isSplitScreen==true)
  58.         {
  59.             // Draw Camera 0
  60.             if (camera[0]){
  61.                 smgr->setActiveCamera(camera[0]);
  62.                 driver->setViewPort(rect<s32>(0,0,ResX/2,ResY/2));
  63.                 smgr->drawAll();
  64.             }
  65.  
  66.             // Draw Camera 1
  67.             if (camera[1]){
  68.                 smgr->setActiveCamera(camera[1]);
  69.                 driver->setViewPort(rect<s32>(ResX/2,0,ResX,ResY/2));
  70.                 smgr->drawAll();
  71.                
  72.                 updatePoint(0,5);
  73.             }
  74.  
  75.             // Draw Camera 2
  76.             if (camera[2]){
  77.                 smgr->setActiveCamera(camera[2]);
  78.                 driver->setViewPort(rect<s32>(0,ResY/2,ResX/2,ResY));
  79.                 smgr->drawAll();
  80.  
  81.                 updatePoint(5,10);
  82.             }
  83.  
  84.             // Draw Camera 3
  85.             if (camera[3]){
  86.                 smgr->setActiveCamera(camera[3]);
  87.                 driver->setViewPort(rect<s32>(ResX/2,ResY/2,ResX,ResY));               
  88.                 smgr->drawAll();
  89.  
  90.                 updatePoint(10,15);
  91.             }
  92.  
  93.             // Draw GUI
  94.             driver->setViewPort(rect<s32>(0,0,ResX,ResY));
  95.             driver->draw2DLine(vector2d<irr::s32>(0,ResY/2),vector2d<irr::s32>(ResX,ResY/2),SColor(175,255,255,255));
  96.             driver->draw2DLine(vector2d<irr::s32>(0,ResY/2-1),vector2d<irr::s32>(ResX,ResY/2-1),SColor(175,255,255,255));
  97.             driver->draw2DLine(vector2d<irr::s32>(ResX/2,0),vector2d<irr::s32>(ResX/2,ResY),SColor(175,255,255,255));
  98.             driver->draw2DLine(vector2d<irr::s32>(ResX/2+1,0),vector2d<irr::s32>(ResX/2+1,ResY),SColor(175,255,255,255));
  99.         }else if (camera[currentWindow]){
  100.             smgr->setActiveCamera(camera[currentWindow]);
  101.             driver->setViewPort(rect<s32>(0,0,ResX,ResY));         
  102.             smgr->drawAll();
  103.             updatePoint(0,15);
  104.         }
  105.  
  106.         guienv->drawAll();
  107.         driver->endScene();
  108.  
  109.        
  110.         if ( driver->getCurrentRenderTargetSize() != last_render_size){
  111.             printf("Adjusting FOV to new screen size...\n");
  112.             last_render_size = driver->getCurrentRenderTargetSize();
  113.             camera[0]->setAspectRatio((float)driver->getScreenSize().Width/(float)driver->getScreenSize().Height);
  114.  
  115.             // reset matrix
  116.             matrix4 projMat;
  117.             irr::f32 orth_w = (float)driver->getScreenSize().Width / (float)driver->getScreenSize().Height;
  118.             orth_w = 3 * orth_w;
  119.             projMat.buildProjectionMatrixOrthoLH(orth_w,3,1,100);
  120.  
  121.             for (int i=1;i<4;i++){
  122.                 if (camera[i]){
  123.                     camera[i]->remove();
  124.                     camera[i]=NULL;
  125.                 }
  126.             }
  127.  
  128.             // Remake cameras
  129.             camera[1]=smgr->addCameraSceneNode(target,vector3df(0,2,-0.01),vector3df(0,0,0));
  130.             camera[1]->setProjectionMatrix(projMat,true);
  131.             camera[2]=smgr->addCameraSceneNode(target,vector3df(0,0,-5),vector3df(0,0,0));
  132.             camera[2]->setProjectionMatrix(projMat,true);
  133.             camera[3]=smgr->addCameraSceneNode(target,vector3df(-5,0,0),vector3df(0,0,0));
  134.             camera[3]->setProjectionMatrix(projMat,true);  
  135.         }
  136.  
  137.         if (counter>500){  
  138.             counter=0;
  139.             if (project->GetCurNode())
  140.                 project->GetCurNode()->update();   
  141.         }
  142.  
  143.     }
  144.  
  145.     return true;
  146. }
  147.  
  148. void Editor::Load_UI(){
  149.     std::cout << "Loading the User Interface" << std::endl;
  150.     guienv->clear();
  151.     guienv->getSkin()->setFont(guienv->getFont("fontlucida.png"));
  152.  
  153.     // The Status Text
  154.     int tmp_b=driver->getScreenSize().Height-58;
  155.     data->d_nb=guienv->addStaticText(L"NodeBox: -",rect<s32>(5,tmp_b,200,tmp_b+15));
  156.     data->d_pos=guienv->addStaticText(L"One: - , - , -",rect<s32>(5,tmp_b+15,300,tmp_b+30));
  157.     data->d_rot=guienv->addStaticText(L"Two: - , - , -",rect<s32>(5,tmp_b+30,300,tmp_b+45));
  158.  
  159.     data->d_nb->setAlignment(EGUIA_UPPERLEFT, EGUIA_UPPERLEFT,EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT);
  160.     data->d_pos->setAlignment(EGUIA_UPPERLEFT, EGUIA_UPPERLEFT,EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT);
  161.     data->d_rot->setAlignment(EGUIA_UPPERLEFT, EGUIA_UPPERLEFT,EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT);
  162.  
  163.  
  164.     // The Menu
  165.     {
  166.         menubar=guienv->addMenu();
  167.         menubar->addItem(L"File",-1,true,true);
  168.         menubar->addItem(L"Edit",-1,true,true);
  169.         menubar->addItem(L"View",-1,true,true);
  170.         menubar->addItem(L"Project",-1,true,true);
  171.         menubar->addItem(L"Node",-1,true,true);
  172.         menubar->addItem(L"Help",-1,true,true);
  173.         gui::IGUIContextMenu* submenu;
  174.  
  175.         // File
  176.         submenu = menubar->getSubMenu(0);
  177.         submenu->addItem(L"New",GUI_ID_NEW);
  178.         submenu->addItem(L"Load",GUI_ID_LOAD,false);
  179.         submenu->addItem(L"Save",GUI_ID_SAVE,false);
  180.         submenu->addSeparator();
  181.         submenu->addItem(L"Import",GUI_ID_IMPORT,false);
  182.         submenu->addItem(L"Export",-1,true,true);
  183.         submenu->addSeparator();
  184.         submenu->addItem(L"Exit",GUI_ID_EXIT);
  185.  
  186.         // Export
  187.         submenu = submenu->getSubMenu(5);
  188.         if (submenu){
  189.             submenu->addItem(L"Project",GUI_ID_EX_PROJ);
  190.             submenu->addSeparator();
  191.             submenu->addItem(L"Entire Node",GUI_ID_EX_NODE);
  192.             submenu->addItem(L"Nodebox table",GUI_ID_EX_NBS);
  193.             submenu->addItem(L"Raw nodebox data",GUI_ID_EX_NB);
  194.         }
  195.  
  196.         // Edit
  197.         submenu = menubar->getSubMenu(1);
  198.         submenu->addItem(L"Snap to grid",GUI_ID_SNAP,true,false,true,true);
  199.         submenu->addItem(L"Limit to node size",GUI_ID_LIMIT,true,false,true,true);
  200.         submenu->addSeparator();
  201.         submenu->addItem(L"Node creator tool",GUI_ID_TOOL_NNODE);
  202.         submenu->addItem(L"Node tool",GUI_ID_TOOL_NODE);
  203.         submenu->addItem(L"Nodebox tool",GUI_ID_TOOL_NODEB);
  204.         submenu->addItem(L"Texture tool",GUI_ID_TOOL_TEXT);
  205.  
  206.         UpdateEditToolMode();
  207.  
  208.         // View
  209.         submenu = menubar->getSubMenu(2);
  210.         submenu->addItem(L"Tiles",GUI_ID_SP_ALL);
  211.         submenu->addSeparator();
  212.         submenu->addItem(L"Perspective",GUI_ID_SP_PER);
  213.         submenu->addItem(L"Top",GUI_ID_SP_TOP);
  214.         submenu->addItem(L"Front",GUI_ID_SP_FRT);
  215.         submenu->addItem(L"Right",GUI_ID_SP_RHT);
  216.  
  217.         // Project
  218.         submenu = menubar->getSubMenu(3);
  219.         submenu->addItem(L"Add a Node",GUI_ID_ADDNODE,false);
  220.         submenu->addItem(L"Switch Node",GUI_ID_SWITCH,false);
  221.  
  222.         // Node
  223.         submenu = menubar->getSubMenu(4);
  224.         submenu->removeAllItems();
  225.         submenu->addItem(L"Node properties",-1,false);
  226.         submenu->addSeparator();
  227.         submenu->addItem(L"Add a nodebox",GUI_ID_BOX);
  228.         submenu->addItem(L"Nodebox properties",GUI_ID_TEXT);
  229.         submenu->addItem(L"Delete current nodebox",GUI_ID_DELETENB);
  230.  
  231.         data->menu = submenu;
  232.  
  233.         // Help
  234.         submenu = menubar->getSubMenu(5);
  235.         submenu->addItem(L"Help",GUI_ID_HELP,false);
  236.         submenu->addSeparator();
  237.         submenu->addItem(L"About",GUI_ID_ABOUT);
  238.     }
  239.  
  240.     // CDRs
  241.     {
  242.         // Add Topdown camera's CDRs
  243.         addPoint(0,CDR_Z_P,1);
  244.         addPoint(1,CDR_X_N,1);
  245.         addPoint(2,CDR_X_P,1);
  246.         addPoint(3,CDR_Z_N,1);
  247.         addPoint(4,CDR_XZ,1);
  248.         // Add front camera's CDRs
  249.         addPoint(5,CDR_Y_P,2);
  250.         addPoint(6,CDR_X_N,2);
  251.         addPoint(7,CDR_X_P,2);
  252.         addPoint(8,CDR_Y_N,2);
  253.         addPoint(9,CDR_XY,1);
  254.         // Add side camera's CDRs
  255.         addPoint(10,CDR_Y_P,3);
  256.         addPoint(11,CDR_Z_P,3);
  257.         addPoint(12,CDR_Z_N,3);
  258.         addPoint(13,CDR_Y_N,3);
  259.         addPoint(14,CDR_ZY,1);
  260.     }
  261. }
  262.  
  263. void Editor::Load_Scene(){
  264. // Calculate Projection Matrix
  265.     matrix4 projMat;
  266.     irr::f32 orth_w = (float)driver->getScreenSize().Width / (float)driver->getScreenSize().Height;
  267.     orth_w = 3 * orth_w;
  268.     projMat.buildProjectionMatrixOrthoLH(orth_w,3,1,100);
  269.  
  270.     // Create target
  271.     target = smgr->addEmptySceneNode(0,200);
  272.     target->setPosition(vector3df(0,0,0));
  273.    
  274.     // Add rotational camera
  275.     pivot=smgr->addEmptySceneNode(target,199);
  276.     camera[0]=smgr->addCameraSceneNode(NULL,vector3df(0,0,-2),vector3df(0,0,0));
  277.     camera[0]->setParent(pivot);
  278.     pivot->setRotation(vector3df(25,-45,0));
  279.  
  280.     // Add Topdown camera
  281.     camera[1]=smgr->addCameraSceneNode(target,vector3df(0,2,-0.01),vector3df(0,0,0));
  282.     camera[1]->setProjectionMatrix(projMat,true);
  283.    
  284.     // Add front camera
  285.     camera[2]=smgr->addCameraSceneNode(target,vector3df(0,0,-5),vector3df(0,0,0));
  286.     camera[2]->setProjectionMatrix(projMat,true);
  287.  
  288.     // Add side camera
  289.     camera[3]=smgr->addCameraSceneNode(target,vector3df(-5,0,0));
  290.     camera[3]->setProjectionMatrix(projMat,true);  
  291.  
  292.     // Add Light
  293.     ILightSceneNode* light=smgr->addLightSceneNode(target,vector3df(25,50,0));
  294.     light->setLightType(ELT_POINT);
  295.     light->setRadius(2000);
  296.  
  297.     // Add Plane
  298.     IMeshSceneNode* plane = smgr->addCubeSceneNode(1,0,-1,vector3df(0.5,-5.5,0.5),vector3df(0,0,0),vector3df(10,10,10));
  299.     plane->setMaterialTexture(0, driver->getTexture("texture_terrain.png"));
  300.     plane->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
  301.     plane->getMaterial(0).getTextureMatrix(0).setTextureScale(10,10);
  302.  
  303.     // Add sky box
  304.     scene::IMeshSceneNode* skybox=smgr->addCubeSceneNode(50);
  305.     skybox->setMaterialTexture(0, driver->getTexture("sky.jpg"));
  306.     skybox->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
  307.     skybox->setMaterialFlag(video::EMF_LIGHTING,false);
  308.     smgr->getMeshManipulator()->flipSurfaces(skybox->getMesh());
  309.     plane_tri=smgr->createOctreeTriangleSelector(skybox->getMesh(),skybox);
  310. }
  311.  
  312. bool Editor::OnEvent(const SEvent& event)
  313. {
  314.     if (event.EventType == irr::EET_MOUSE_INPUT_EVENT &&
  315.         event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP ){
  316.         mouse_down=false;
  317.  
  318.         // drop scale drag point
  319.         if (point_on != -1)
  320.             point_on = -1;
  321.     }else if (event.EventType == irr::EET_MOUSE_INPUT_EVENT &&
  322.         event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN ){
  323.         mouse_down=true;
  324.     }else if (event.EventType == irr::EET_MOUSE_INPUT_EVENT &&
  325.         event.MouseInput.Event == EMIE_MOUSE_MOVED ){
  326.             mouse_position.X=event.MouseInput.X;
  327.             mouse_position.Y=event.MouseInput.Y;
  328.     }else if (event.EventType == EET_KEY_INPUT_EVENT){
  329.         printf("key down %i \n",event.KeyInput.Key);
  330.  
  331.         if (event.KeyInput.Key== KEY_DOWN || event.KeyInput.Key== KEY_KEY_S){
  332.             pivot->setRotation(vector3df(pivot->getRotation().X-1,pivot->getRotation().Y,pivot->getRotation().Z));
  333.         }else if (event.KeyInput.Key== KEY_UP || event.KeyInput.Key== KEY_KEY_W){
  334.             pivot->setRotation(vector3df(pivot->getRotation().X+1,pivot->getRotation().Y,pivot->getRotation().Z));
  335.         }else if (event.KeyInput.Key== KEY_LEFT || event.KeyInput.Key== KEY_KEY_A){
  336.             pivot->setRotation(vector3df(pivot->getRotation().X,pivot->getRotation().Y+1,pivot->getRotation().Z));
  337.         }else if (event.KeyInput.Key== KEY_RIGHT || event.KeyInput.Key== KEY_KEY_D){
  338.             pivot->setRotation(vector3df(pivot->getRotation().X,pivot->getRotation().Y-1,pivot->getRotation().Z));
  339.         }else if (event.KeyInput.Key == 162){
  340.             printf("cntrl toggle\n");
  341.             KEY_SCALE_DOWN  = event.KeyInput.PressedDown;
  342.         }else if (event.KeyInput.Key == 160){
  343.             printf("shift toggle\n");
  344.             KEY_MOVE_DOWN  = event.KeyInput.PressedDown;
  345.         }
  346.     }else if (event.EventType == EET_GUI_EVENT){       
  347.         irr::s32 id = event.GUIEvent.Caller->getID();
  348.         irr::gui::IGUIEnvironment* env = device->getGUIEnvironment();
  349.  
  350.             switch(event.GUIEvent.EventType)
  351.             {
  352.             case EGET_MENU_ITEM_SELECTED:
  353.                 OnMenuItemSelected( (IGUIContextMenu*)event.GUIEvent.Caller );
  354.                 break;
  355.             case EGET_ELEMENT_LEFT:
  356.                 if (id > 299 && id < 324){
  357.                     if (mouse_down == true && point_on == -1){ 
  358.                         printf("Selected scaler id %i\n",id);
  359.                         point_on = id - 300;
  360.                     }
  361.                 }
  362.                 break;
  363.             case EGET_MESSAGEBOX_OK:
  364.                 if (event.GUIEvent.Caller->getID()==GUI_ID_NEW){
  365.                     printf("New project...\n");
  366.                     delete project;
  367.                     project = new Project();
  368.                     project->nodes[0] = new Node(device,data);
  369.                     MoveTarget(project->nodes[0]->getPosition());
  370.                 }else if (event.GUIEvent.Caller->getID()==GUI_ID_EXIT){
  371.                     printf("Exiting...\n");
  372.                     device->closeDevice();
  373.                 }
  374.                 break;
  375.             }
  376.  
  377.             for(list<IEventReceiver*>::Iterator Iterator = menus->begin(); Iterator != menus->end(); ++Iterator)
  378.             {
  379.                 IEventReceiver* m = *Iterator;
  380.                 if (m && m->OnEvent(event)==true)
  381.                     return true;
  382.             }
  383.     }
  384.  
  385.     return false;
  386. }
  387.  
  388. void Editor::OnMenuItemSelected( IGUIContextMenu* menu )
  389. {
  390.     s32 id = menu->getItemCommandId(menu->getSelectedItem());
  391.     IGUIEnvironment* env = device->getGUIEnvironment();
  392.     switch(id)
  393.     {
  394.     case GUI_ID_NEW:
  395.         guienv->addMessageBox(L"Are you sure?",L"You will lose all unsaved changes.",true,(EMBF_OK|EMBF_CANCEL),0,GUI_ID_NEW);
  396.         break;
  397.     case GUI_ID_EXIT:
  398.         guienv->addMessageBox(L"Are you sure?",L"You will lose all unsaved changes.",true,(EMBF_OK|EMBF_CANCEL),0,GUI_ID_EXIT);
  399.         break;
  400.     case GUI_ID_EX_NODE:
  401.         {
  402.             stringc* res = project->GetCurNode()->build(NBT_FULL);
  403.             menus->push_back(new CodeDialog(guienv,convert(res->c_str())));
  404.         }
  405.         break;
  406.     case GUI_ID_EX_NBS:
  407.         {
  408.             stringc* res = project->GetCurNode()->build(NBT_NBS);
  409.             menus->push_back(new CodeDialog(guienv,convert(res->c_str())));
  410.         }
  411.         break;
  412.     case GUI_ID_EX_NB:
  413.         {
  414.             stringc* res = project->GetCurNode()->build(NBT_NB);
  415.             menus->push_back(new CodeDialog(guienv,convert(res->c_str())));    
  416.         }
  417.         break;
  418.     case GUI_ID_TEXT:
  419.         menus->push_back(new NBPropertiesDialog(guienv,project->GetCurNode()->GetCurrentNodeBox(),project->GetCurNode()));
  420.         break;
  421.     case GUI_ID_DELETENB:
  422.         project->GetCurNode()->deleteNodebox(project->GetCurNode()->GetId());
  423.         break;
  424.     case GUI_ID_BOX:
  425.         project->GetCurNode()->addNodeBox();
  426.         break;
  427.     case GUI_ID_ABOUT:
  428.         {
  429.             core::stringw* msg = new core::stringw(L"The Nodebox Editor\n");
  430.             msg->append("Version: ");
  431.             msg->append(EDITOR_TEXT_VERSION);
  432.             msg->append("\n\n");
  433.             msg->append("This free nodebox editor was made by Rubenwardy in C++ and Irrlicht.\n");
  434.             msg->append("You can download newer versions from the Minetest forum.");       
  435.             guienv->addMessageBox(L"About",msg->c_str());
  436.         }
  437.         break; 
  438.     case GUI_ID_SP_ALL:
  439.         printf("View mode changed to tiles\n");
  440.         isSplitScreen=true;
  441.         currentWindow=0;
  442.         break;
  443.     case GUI_ID_SP_PER:
  444.         printf("View mode changed to perspective\n");
  445.         isSplitScreen=false;
  446.         currentWindow=0;
  447.         break;
  448.     case GUI_ID_SP_TOP:
  449.         printf("View mode changed to top\n");
  450.         isSplitScreen=false;
  451.         currentWindow=1;
  452.         break;
  453.     case GUI_ID_SP_FRT:
  454.         printf("View mode changed to front\n");
  455.         isSplitScreen=false;
  456.         currentWindow=2;
  457.         break;
  458.     case GUI_ID_SP_RHT:
  459.         printf("View mode changed to right\n");
  460.         isSplitScreen=false;
  461.         currentWindow=3;
  462.         break;
  463.     case GUI_ID_SNAP:
  464.         data->snapping = menu->isItemChecked(menu->getSelectedItem());
  465.         break;
  466.     case GUI_ID_LIMIT:
  467.         data->limiting = menu->isItemChecked(menu->getSelectedItem());
  468.         break;
  469.     case GUI_ID_TOOL_NNODE:
  470.         data->type = TOOL_NEWNODE;
  471.         UpdateEditToolMode();
  472.         break;
  473.     case GUI_ID_TOOL_NODE:
  474.         data->type = TOOL_NODE;
  475.         UpdateEditToolMode();
  476.         break;
  477.     case GUI_ID_TOOL_NODEB:
  478.         data->type = TOOL_NODEB;
  479.         UpdateEditToolMode();
  480.         break;
  481.     case GUI_ID_TOOL_TEXT:
  482.         data->type = TOOL_TEXT;
  483.         UpdateEditToolMode();
  484.         break;
  485.     default:
  486.         if (id>=250){
  487.             int i = id - 250;
  488.             project->GetCurNode()->select(i);
  489.         }
  490.     }
  491. }
  492.  
  493. void Editor::UpdateEditToolMode(){
  494.     gui::IGUIContextMenu* submenu = menubar->getSubMenu(1);
  495.  
  496.     submenu->setItemChecked(3,(data->type==TOOL_NEWNODE));
  497.     submenu->setItemChecked(4,(data->type==TOOL_NODE));
  498.     submenu->setItemChecked(5,(data->type==TOOL_NODEB));
  499.     submenu->setItemChecked(6,(data->type==TOOL_TEXT));
  500. }
  501.  
  502. void Editor::updatePoint(int start, int count){
  503.     for (int id=start;id<count;id++){
  504.         if (!points[id])
  505.             continue;
  506.  
  507.         bool visible = (
  508.                     project->GetCurNode() &&
  509.                     data->type == TOOL_NODEB &&
  510.                     project->GetCurNode()->GetCurrentNodeBox()!=NULL &&
  511.                     (isSplitScreen==true || currentWindow==points[id]->camera) &&
  512.                     ((KEY_MOVE_DOWN==false && points[id]->type < CDR_XZ) || (KEY_MOVE_DOWN==true && points[id]->type > CDR_Z_N))
  513.                 );
  514.  
  515.         points[id] -> image -> setVisible (visible);
  516.  
  517.         if (!visible)
  518.             continue;
  519.  
  520.         if (point_on == id){
  521.             // get mouse position
  522.             position2di target = mouse_position;
  523.             target.X -= 5;
  524.             target.Y -= 5;
  525.  
  526.             // correct out of bounds
  527.             if (target.X < driver->getViewPort().UpperLeftCorner.X){
  528.                 target.X = driver->getViewPort().UpperLeftCorner.X-5;
  529.             }else if (target.X > driver->getViewPort().LowerRightCorner.X){
  530.                 target.X = driver->getViewPort().LowerRightCorner.X-5;
  531.             }
  532.                
  533.             if (target.Y < driver->getViewPort().UpperLeftCorner.Y){
  534.                 target.Y = driver->getViewPort().UpperLeftCorner.Y-5;  
  535.             }else if (target.Y > driver->getViewPort().LowerRightCorner.Y){
  536.                 target.Y = driver->getViewPort().LowerRightCorner.Y-5;
  537.             }
  538.  
  539.             // set image location
  540.             points[id] -> image -> setRelativePosition(target);
  541.  
  542.             position2di tar2 = target;
  543.             tar2.X -= driver->getViewPort().UpperLeftCorner.X - 5;
  544.             tar2.Y -= driver->getViewPort().UpperLeftCorner.Y - 5;
  545.  
  546.             // get the ray
  547.             line3d<irr::f32> ray = coli -> getRayFromScreenCoordinates(tar2,smgr->getActiveCamera());
  548.            
  549.             // contains the output values
  550.             vector3df wpos = vector3df(0,0,0); // the collision position
  551.             #if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8
  552.                 const ISceneNode* tmpNode; // not needed, but required for function
  553.             #else
  554.                 ISceneNode* tmpNode; // not needed, but required for function
  555.             #endif
  556.             triangle3df tmpTri; // not needed, but required for function
  557.  
  558.             // Execute ray
  559.             coli->getCollisionPoint(ray,plane_tri,wpos,tmpTri,tmpNode);
  560.  
  561.             // Call required function
  562.             if (points[id]->type < CDR_XZ){
  563.                 project->GetCurNode()->resizeNodeBoxFace(points[id]->type,wpos,KEY_SCALE_DOWN);
  564.             }else{
  565.                 project->GetCurNode()->moveNodeBox(points[id]->type,wpos);
  566.             }
  567.         }else{
  568.             vector3df position;
  569.  
  570.             switch (points[id]->type){
  571.             case CDR_X_P:
  572.                 position = project->GetCurNode()->GetCurrentNodeBox()->GetCenter();
  573.                 position.X = project->GetCurNode()->GetCurrentNodeBox()->two.X;
  574.                 break;
  575.             case CDR_X_N:
  576.                 position = project->GetCurNode()->GetCurrentNodeBox()->GetCenter();
  577.                 position.X = project->GetCurNode()->GetCurrentNodeBox()->one.X;
  578.                 break;
  579.             case CDR_Y_P:
  580.                 position = project->GetCurNode()->GetCurrentNodeBox()->GetCenter();
  581.                 position.Y = project->GetCurNode()->GetCurrentNodeBox()->two.Y;
  582.                 break;
  583.             case CDR_Y_N:
  584.                 position = project->GetCurNode()->GetCurrentNodeBox()->GetCenter();
  585.                 position.Y = project->GetCurNode()->GetCurrentNodeBox()->one.Y;
  586.                 break;
  587.             case CDR_Z_P:
  588.                 position = project->GetCurNode()->GetCurrentNodeBox()->GetCenter();
  589.                 position.Z = project->GetCurNode()->GetCurrentNodeBox()->two.Z;
  590.                 break;
  591.             case CDR_Z_N:
  592.                 position = project->GetCurNode()->GetCurrentNodeBox()->GetCenter();
  593.                 position.Z = project->GetCurNode()->GetCurrentNodeBox()->one.Z;
  594.                 break;
  595.             case CDR_XZ:
  596.                 position = project->GetCurNode()->GetCurrentNodeBox()->GetCenter();
  597.                 break;
  598.             case CDR_XY:
  599.                 position = project->GetCurNode()->GetCurrentNodeBox()->GetCenter();
  600.                 break;
  601.             case CDR_ZY:
  602.                 position = project->GetCurNode()->GetCurrentNodeBox()->GetCenter();
  603.                 break;
  604.             }
  605.  
  606.             position.X+=project->GetCurNode()->getPosition().X;
  607.             position.Y+=project->GetCurNode()->getPosition().Y;
  608.             position.Z+=project->GetCurNode()->getPosition().Z;
  609.  
  610.             #if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8
  611.                 vector2d<irr::s32> cpos = coli -> getScreenCoordinatesFrom3DPosition(position,smgr->getActiveCamera());
  612.             #else
  613.                 vector2d<irr::s32> cpos = coli -> getScreenCoordinatesFrom3DPosition(position,smgr->getActiveCamera(),true);
  614.             #endif
  615.             points[id] -> image -> setRelativePosition(position2di(driver->getViewPort().UpperLeftCorner.X+cpos.X-5, driver->getViewPort().UpperLeftCorner.Y+cpos.Y-5));
  616.         }
  617.     }
  618. }
  619.  
  620. void Editor::addPoint(int id, CDR_TYPE type, int camera){
  621.     points[id] = new CDR();
  622.     points[id] -> type = type;
  623.     points[id] -> camera = camera;
  624.     points[id] -> image = guienv->addImage(rect<irr::s32>(0,0,10,10),NULL,300+id);
  625.     points[id] -> image -> setImage(driver->getTexture("gui_scale.png"));
  626.     points[id] -> image -> setVisible (false);
  627. }
  628.  
  629. void Editor::MoveTarget(vector3df pos){
  630.      target->setPosition(pos);
  631.  
  632.      for (int i=0;i<4;i++){
  633.         camera[i]->setTarget(pos);
  634.      }
  635.  }
Advertisement
Add Comment
Please, Sign In to add comment