From 20bef07919d6e6758cb6562f23c07cdb5ece2d81 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 1 Mar 2015 19:17:36 +0000 Subject: [PATCH] Add flipping --- media/flip_x.png | Bin 0 -> 286 bytes media/flip_y.png | Bin 0 -> 279 bytes media/flip_z.png | Bin 0 -> 289 bytes src/Node.cpp | 13 +++++++++- src/Node.hpp | 1 + src/NodeBox.cpp | 43 +++++++++++++++++++++++++++++++++ src/NodeBox.hpp | 1 + src/modes/NBEditor.cpp | 53 +++++++++++++++++++++++++++++++++++------ 8 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 media/flip_x.png create mode 100644 media/flip_y.png create mode 100644 media/flip_z.png diff --git a/media/flip_x.png b/media/flip_x.png new file mode 100644 index 0000000000000000000000000000000000000000..08cad277f4eea927b799e5ab7d2b673a0e5111e4 GIT binary patch literal 286 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7a$D;Kb?2i11Zh|kH}&M z25w;xW@MN(M*=9wUgGKN%6^}jQJ6*deevAwKq1Kz*N775{M_8syb=cIqSVBa)D(sC z%#sWRcTeAd@J2pyprSTU7srr@!*8cs^D!uLxXj)Ae{Q<;_L~`p+*yTJXt1QonKY$z z_bg|1=iK4WaAC*ex3VlIeOpX_az@tNjDAJ-j0>y39DK90 z(`lb{z?*-?d@s4&_S&)-oP5g?7PoJT(>!U5hjk{}?2VJ({TDgJxxh|MbpeYDcLn1V XJ_TRDBeidVE@JR>^>bP0l+XkK_6A(J literal 0 HcmV?d00001 diff --git a/media/flip_y.png b/media/flip_y.png new file mode 100644 index 0000000000000000000000000000000000000000..d6bf3a257424f10a870987570a0a70fcc4a777c7 GIT binary patch literal 279 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7a$D;Kb?2i11Zh|kH}&M z25w;xW@MN(M*=9wUgGKN%6^}jQJB@JI$l%q#!@H?B6Hbs&gUct?d`hP#R2Dy^A@ zDwa_PteF@t3RmA(cu@G{>`MO!{nh??xlDrJuSu118r+G_a^-ljU&6YjA%{_Z!**F;X@jHg QK&LQxy85}Sb4q9e07ej5)Bpeg literal 0 HcmV?d00001 diff --git a/media/flip_z.png b/media/flip_z.png new file mode 100644 index 0000000000000000000000000000000000000000..71e769a98d843bd9c8095c670a9d9d1b721fbcc9 GIT binary patch literal 289 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7a$D;Kb?2i11Zh|kH}&M z25w;xW@MN(M*=9wUgGKN%6^}jQJ76GY3e*>ppayVYeb22er|4RUI~M9QEFmIYKlU6 zW=V#EyQgnJcq5-UP*JC+i(^Q{;kVNdavd<>aDM&b|No-0>2f{0G93>_uRgh&LzH2) z(Y#O@Ie#3Fw;_c>*9o5;r`&fA1ExhEK=>9^>u#)A(_I4rX zz>aebD=l3c3jEFOuioQi@iTs??67a|iju$=o7s)F&1-k!XR6Qx24GFM9=a6oaR$pUXO@geCyr;$WEo literal 0 HcmV?d00001 diff --git a/src/Node.cpp b/src/Node.cpp index cfa6dd2..0964bfe 100644 --- a/src/Node.cpp +++ b/src/Node.cpp @@ -126,7 +126,8 @@ void Node::hide() } } -void Node::rotate(EAxis axis) { +void Node::rotate(EAxis axis) +{ for (std::vector::iterator it = boxes.begin(); it != boxes.end(); ++it) { @@ -134,3 +135,13 @@ void Node::rotate(EAxis axis) { } remesh(); } + +void Node::flip(EAxis axis) +{ + for (std::vector::iterator it = boxes.begin(); + it != boxes.end(); + ++it) { + (*it)->flip(axis); + } + remesh(); +} diff --git a/src/Node.hpp b/src/Node.hpp index c6088f3..3642765 100644 --- a/src/Node.hpp +++ b/src/Node.hpp @@ -30,6 +30,7 @@ class Node void remesh(NodeBox *box); void setAllTextures(Media::Image *def); void rotate(EAxis axis); + void flip(EAxis axis); void hide(); void setTexture(CubeSide face, Media::Image *image); diff --git a/src/NodeBox.cpp b/src/NodeBox.cpp index d069079..0e68638 100644 --- a/src/NodeBox.cpp +++ b/src/NodeBox.cpp @@ -431,3 +431,46 @@ void NodeBox::rotate(EAxis axis) two.Z = tmp; } } + +void NodeBox::flip(EAxis axis) +{ + switch (axis) { + case EAX_X: { + f32 tmp = one.X; + one.X = -two.X; + two.X = -tmp; + break; + } + case EAX_Y: { + f32 tmp = one.Y; + one.Y = -two.Y; + two.Y = -tmp; + break; + } + case EAX_Z: { + f32 tmp = one.Z; + one.Z = -two.Z; + two.Z = -tmp; + break; + }}; + + // Check relative sizes + if (one.X > two.X) { + std::cerr << "This shouldn't happen! (X)" << std::endl; + f32 tmp = one.X; + one.X = two.X; + two.X = tmp; + } + if (one.Y > two.Y) { + std::cerr << "This shouldn't happen! (Y)" << std::endl; + f32 tmp = one.Y; + one.Y = two.Y; + two.Y = tmp; + } + if (one.Z > two.Z) { + std::cerr << "This shouldn't happen! (Z)" << std::endl; + f32 tmp = one.Z; + one.Z = two.Z; + two.Z = tmp; + } +} diff --git a/src/NodeBox.hpp b/src/NodeBox.hpp index cc87658..8688e19 100644 --- a/src/NodeBox.hpp +++ b/src/NodeBox.hpp @@ -47,6 +47,7 @@ class NodeBox void moveNodeBox(EditorState* editor, CDRType type, vector3df position); void buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevice* device, Media::Image* images[6]); void rotate(EAxis axis); + void flip(EAxis axis); }; #endif diff --git a/src/modes/NBEditor.cpp b/src/modes/NBEditor.cpp index 626b952..ca8bb34 100644 --- a/src/modes/NBEditor.cpp +++ b/src/modes/NBEditor.cpp @@ -7,7 +7,7 @@ // The gui id numbers for this mode // NOTE: the maximum that can be here is 20 -// see in MenuState.h to raise limit +// see in MenuState.hpp to raise the limit enum NODEBOX_EDITOR_GUI_IDS { ENB_GUI_MAIN_LISTBOX = GUI_SIDEBAR + 1, ENB_GUI_MAIN_MSG, @@ -21,6 +21,9 @@ enum NODEBOX_EDITOR_GUI_IDS { ENB_GUI_PROP_NAME, ENB_GUI_PROP_UPDATE, ENB_GUI_PROP_REVERT, + ENB_GUI_FLP_X, + ENB_GUI_FLP_Y, + ENB_GUI_FLP_Z, ENB_GUI_ROT_X, ENB_GUI_ROT_Y, ENB_GUI_ROT_Z @@ -58,7 +61,7 @@ void NBEditor::load() false, true, sidebar, ENB_GUI_MAIN_MSG); - IGUIListBox *lb = guienv->addListBox(rect(20, 35, 230, 133), + IGUIListBox *lb = guienv->addListBox(rect(10, 35+20, 227, 133+20), sidebar, ENB_GUI_MAIN_LISTBOX, true); if (lb) { @@ -71,27 +74,46 @@ void NBEditor::load() b2->setNotClipped(true); } + + // Rotate X + static ITexture *flp_x = state->device->getVideoDriver()->getTexture("media/flip_x.png"); + IGUIButton *btn = guienv->addButton(rect(10, 20, 120+32 - (32+5)*3, 52), sidebar, ENB_GUI_FLP_X, L"", L"Rotate node through X axis"); + btn->setImage(flp_x); + btn->setUseAlphaChannel(true); + + // Rotate Y + static ITexture *flp_y = state->device->getVideoDriver()->getTexture("media/flip_y.png"); + btn = guienv->addButton(rect(121 - (32+5)*2, 20, 120+32 - (32+5)*2, 32+20), sidebar, ENB_GUI_FLP_Y, L"", L"Rotate node through Y axis"); + btn->setImage(flp_y); + btn->setUseAlphaChannel(true); + + // Rotate Z + static ITexture *flp_z = state->device->getVideoDriver()->getTexture("media/flip_z.png"); + btn = guienv->addButton(rect(121 - (32+5), 20, 120+32 - (32+5), 32+20), sidebar, ENB_GUI_FLP_Z, L"", L"Rotate node through Z axis"); + btn->setImage(flp_z); + btn->setUseAlphaChannel(true); + // Rotate X static ITexture *rot_x = state->device->getVideoDriver()->getTexture("media/rotate_x.png"); - IGUIButton *btn = guienv->addButton(rect(120, 0, 120+32, 32), sidebar, ENB_GUI_ROT_X, L"", L"Rotate node through X axis"); + btn = guienv->addButton(rect(121, 20, 120+32, 32+20), sidebar, ENB_GUI_ROT_X, L"", L"Rotate node through X axis"); btn->setImage(rot_x); btn->setUseAlphaChannel(true); // Rotate Y static ITexture *rot_y = state->device->getVideoDriver()->getTexture("media/rotate_y.png"); - btn = guienv->addButton(rect(120 + (32+5)*1, 0, 120+32 + (32+5)*1, 32), sidebar, ENB_GUI_ROT_Y, L"", L"Rotate node through Y axis"); + btn = guienv->addButton(rect(121 + (32+5)*1, 20, 120+32 + (32+5)*1, 32+20), sidebar, ENB_GUI_ROT_Y, L"", L"Rotate node through Y axis"); btn->setImage(rot_y); btn->setUseAlphaChannel(true); - // Rotate Z| + // Rotate Z static ITexture *rot_z = state->device->getVideoDriver()->getTexture("media/rotate_z.png"); - btn = guienv->addButton(rect(120 + (32+5)*2, 0, 120+32 + (32+5)*2, 32), sidebar, ENB_GUI_ROT_Z, L"", L"Rotate node through Z axis"); + btn = guienv->addButton(rect(121 + (32+5)*2, 20, 120+32 + (32+5)*2, 32+20), sidebar, ENB_GUI_ROT_Z, L"", L"Rotate node through Z axis"); btn->setImage(rot_z); btn->setUseAlphaChannel(true); // Create nodebox properties t = guienv->addStaticText(L"Properties", - rect(0, 170, 120, 190), + rect(0, 170+20, 120, 190+20), false, true, sidebar, ENB_GUI_PROP); t->setVisible(false); @@ -449,7 +471,24 @@ bool NBEditor::OnEvent(const irr::SEvent &event) { node->rotate(EAX_Z); break; } + case ENB_GUI_FLP_X: { + Node* node = state->project->GetCurrentNode(); + if (node) + node->flip(EAX_X); + break; } + case ENB_GUI_FLP_Y: { + Node* node = state->project->GetCurrentNode(); + if (node) + node->flip(EAX_Y); + break; + } + case ENB_GUI_FLP_Z: { + Node* node = state->project->GetCurrentNode(); + if (node) + node->flip(EAX_Z); + break; + }} } else if (event.GUIEvent.EventType == EGET_LISTBOX_CHANGED) { Node* node = state->project->GetCurrentNode(); IGUIListBox* lb = (IGUIListBox*) state->menu->sidebar->getElementFromId(ENB_GUI_MAIN_LISTBOX);