Add node rotating

master
rubenwardy 2014-11-05 17:31:17 +00:00
parent c16ab4632c
commit c77c446849
10 changed files with 144 additions and 34 deletions

BIN
media/rotate_x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 661 B

BIN
media/rotate_y.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 694 B

BIN
media/rotate_z.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 662 B

View File

@ -83,12 +83,13 @@ void MenuState::init()
), false, true, 0, GUI_SIDEBAR
);
sidebar->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
sidebar->setNotClipped(true);
}
bool MenuState::OnEvent(const SEvent& event){
if (dialog)
return dialog->OnEvent(event);
if (event.EventType == irr::EET_MOUSE_INPUT_EVENT &&
event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) {
if (rect<s32>(10, 32, 42, 64).isPointInside(state->mouse_position)){
@ -197,7 +198,7 @@ bool MenuState::OnEvent(const SEvent& event){
// Get directory to save to
std::string dir = getSaveLoadDirectory(state->settings->get("save_directory"), state->settings->getBool("installed"));
std::cerr << "Saving to " << dir + "exit.nbe" << std::endl;
if (!writer.write(state->project, dir + "exit.nbe"))
std::cerr << "Failed to save file for unknown reason." << std::endl;

View File

@ -9,7 +9,7 @@
// NOTE: the maximum that can be here is 20
// see in MenuState.h to raise limit
enum NODEBOX_EDITOR_GUI_IDS {
ENB_GUI_MAIN_LISTBOX = GUI_SIDEBAR + 1,
ENB_GUI_MAIN_LISTBOX = GUI_SIDEBAR + 1,
ENB_GUI_MAIN_MSG,
ENB_GUI_PROP,
ENB_GUI_PROP_X1,
@ -20,7 +20,10 @@ enum NODEBOX_EDITOR_GUI_IDS {
ENB_GUI_PROP_Z2,
ENB_GUI_PROP_NAME,
ENB_GUI_PROP_UPDATE,
ENB_GUI_PROP_REVERT
ENB_GUI_PROP_REVERT,
ENB_GUI_ROT_X,
ENB_GUI_ROT_Y,
ENB_GUI_ROT_Z
};
NBEditor::NBEditor(EditorState* st) :
@ -29,11 +32,11 @@ NBEditor::NBEditor(EditorState* st) :
prop_needs_update(false)
{
for (int i = 0; i < 4; i++) {
cdrs[i*5] = CDR((Viewport)i, CDR_L);
cdrs[i*5 + 1] = CDR((Viewport)i, CDR_R);
cdrs[i*5 + 2] = CDR((Viewport)i, CDR_U);
cdrs[i*5 + 3] = CDR((Viewport)i, CDR_D);
cdrs[i*5 + 4] = CDR((Viewport)i, CDR_M);
cdrs[i*5] = CDR((Viewport)i, CDR_L);
cdrs[i*5 + 1] = CDR((Viewport)i, CDR_R);
cdrs[i*5 + 2] = CDR((Viewport)i, CDR_U);
cdrs[i*5 + 3] = CDR((Viewport)i, CDR_D);
cdrs[i*5 + 4] = CDR((Viewport)i, CDR_M);
}
}
@ -53,8 +56,9 @@ void NBEditor::load()
IGUIStaticText* t = guienv->addStaticText(L"No node selected",
rect<s32>(20, 30, 140, 100),
false, true, sidebar, ENB_GUI_MAIN_MSG);
IGUIListBox* lb = guienv->addListBox(rect<s32>(20, 30, 230, 128),
IGUIListBox *lb = guienv->addListBox(rect<s32>(20, 35, 230, 133),
sidebar, ENB_GUI_MAIN_LISTBOX, true);
if (lb) {
@ -67,6 +71,24 @@ void NBEditor::load()
b2->setNotClipped(true);
}
// Rotate X
static ITexture *rot_x = state->device->getVideoDriver()->getTexture("media/rotate_x.png");
IGUIButton *btn = guienv->addButton(rect<s32>(120, 0, 120+32, 32), 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<s32>(120 + (32+5)*1, 0, 120+32 + (32+5)*1, 32), sidebar, ENB_GUI_ROT_Y, L"", L"Rotate node through Y axis");
btn->setImage(rot_y);
btn->setUseAlphaChannel(true);
// Rotate Z|
static ITexture *rot_z = state->device->getVideoDriver()->getTexture("media/rotate_z.png");
btn = guienv->addButton(rect<s32>(120 + (32+5)*2, 0, 120+32 + (32+5)*2, 32), 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<s32>(0, 170, 120, 190),
@ -107,7 +129,7 @@ void NBEditor::load_ui()
sidebar->getElementFromId(ENB_GUI_MAIN_LISTBOX)->setVisible(false);
sidebar->getElementFromId(ENB_GUI_PROP)->setVisible(false);
} else {
IGUIListBox *lb = (IGUIListBox *) sidebar->getElementFromId(ENB_GUI_MAIN_LISTBOX);
IGUIListBox *lb = (IGUIListBox *) sidebar->getElementFromId(ENB_GUI_MAIN_LISTBOX);
sidebar->getElementFromId(ENB_GUI_MAIN_MSG)->setVisible(false);
sidebar->getElementFromId(ENB_GUI_PROP)->setVisible(false);
@ -398,7 +420,7 @@ bool NBEditor::OnEvent(const irr::SEvent &event) {
}
case GUI_PROJ_DELETE_BOX: {
Node* node = state->project->GetCurrentNode();
IGUIListBox* lb = (IGUIListBox*) state->menu->sidebar->getElementFromId(ENB_GUI_MAIN_LISTBOX);
IGUIListBox* lb = (IGUIListBox*) state->menu->sidebar->getElementFromId(ENB_GUI_MAIN_LISTBOX);
if (node && node->GetNodeBox(lb->getSelected())){
node->deleteNodebox(lb->getSelected());
load_ui();
@ -411,10 +433,28 @@ bool NBEditor::OnEvent(const irr::SEvent &event) {
case ENB_GUI_PROP_UPDATE:
updateProperties();
break;
case ENB_GUI_ROT_X: {
Node* node = state->project->GetCurrentNode();
if (node)
node->rotate(EAX_X);
break;
}
case ENB_GUI_ROT_Y: {
Node* node = state->project->GetCurrentNode();
if (node)
node->rotate(EAX_Y);
break;
}
case ENB_GUI_ROT_Z: {
Node* node = state->project->GetCurrentNode();
if (node)
node->rotate(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);
IGUIListBox* lb = (IGUIListBox*) state->menu->sidebar->getElementFromId(ENB_GUI_MAIN_LISTBOX);
if (node && lb && node->GetNodeBox(lb->getSelected())){
node->select(lb->getSelected());
}

View File

@ -99,7 +99,8 @@ void Node::setTexture(CubeSide face, Media::Image *image)
}
// Build node models
void Node::remesh() {
void Node::remesh()
{
for (std::vector<NodeBox*>::iterator it = boxes.begin();
it != boxes.end();
++it) {
@ -107,7 +108,8 @@ void Node::remesh() {
}
}
void Node::remesh(NodeBox *box) {
void Node::remesh(NodeBox *box)
{
box->buildNode(state, position, device, images);
}
@ -124,4 +126,13 @@ void Node::hide()
}
}
void Node::rotate(EAxis axis) {
for (std::vector<NodeBox*>::iterator it = boxes.begin();
it != boxes.end();
++it) {
(*it)->rotate(axis);
}
remesh();
}

View File

@ -29,6 +29,7 @@ public:
void remesh(); // creates the node mesh
void remesh(NodeBox *box);
void setAllTextures(Media::Image *def);
void rotate(EAxis axis);
void hide();
void setTexture(CubeSide face, Media::Image *image);

View File

@ -210,7 +210,7 @@ void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevi
// Initialise buffers
SMeshBuffer *buffer = new SMeshBuffer();
SMeshBuffer *buffer2 = new SMeshBuffer();
SMeshBuffer *buffer2 = new SMeshBuffer();
SMeshBuffer *buffer3 = new SMeshBuffer();
SMeshBuffer *buffer4 = new SMeshBuffer();
SMeshBuffer *buffer5 = new SMeshBuffer();
@ -240,7 +240,7 @@ void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevi
std::string lighting = editor->settings->get("lighting");
// Front face
vector2df topl((one.X+0.5), (-two.Y+0.5));
vector2df topl((one.X+0.5), (-two.Y+0.5));
vector2df btmr((two.X+0.5), (-one.Y+0.5));
buffer->Vertices.set_used(4);
buffer->Vertices[0] = video::S3DVertex(x0,x0,x0, -1,-1,-1, cubeColour, topl.X, btmr.Y);
@ -251,7 +251,7 @@ void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevi
ITexture *texture = NULL;
if (lighting == "2")
texture = darken(driver, copied[ECS_FRONT]->get(), 0.5);
else if (lighting == "1")
else if (lighting == "1")
texture = darken(driver, copied[ECS_FRONT]->get(), 0.5);
else
texture = driver->addTexture("media/texture_box.png", copied[ECS_FRONT]->get());
@ -263,18 +263,18 @@ void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevi
// Back face
topl = vector2df((-two.X + 0.5), (-two.Y + 0.5));
topl = vector2df((-two.X + 0.5), (-two.Y + 0.5));
btmr = vector2df((-one.X + 0.5), (-one.Y + 0.5));
buffer2->Vertices.set_used(4);
buffer2->Vertices[0] = video::S3DVertex(x1,x0,x1, 1, -1, 1, cubeColour, topl.X, btmr.Y);
buffer2->Vertices[1] = video::S3DVertex(x0,x0,x1, -1,-1, 1, cubeColour, btmr.X, btmr.Y);
buffer2->Vertices[2] = video::S3DVertex(x0,x1,x1, -1, 1, 1, cubeColour, btmr.X, topl.Y);
buffer2->Vertices[3] = video::S3DVertex(x1,x1,x1, 1, 1, 1, cubeColour, topl.X, topl.Y);
buffer2->BoundingBox.reset(0,0,0);
buffer2->BoundingBox.reset(0,0,0);
texture = NULL;
if (lighting == "2")
texture = darken(driver, copied[ECS_BACK]->get(), 0.5);
else if (lighting == "1")
else if (lighting == "1")
texture = darken(driver, copied[ECS_BACK]->get(), 0.5);
else
texture = driver->addTexture("media/texture_box.png", copied[ECS_BACK]->get());
@ -286,7 +286,7 @@ void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevi
// Left face
topl = vector2df((-two.Z + 0.5), (-two.Y + 0.5));
topl = vector2df((-two.Z + 0.5), (-two.Y + 0.5));
btmr = vector2df((-one.Z + 0.5), (-one.Y + 0.5));
buffer3->Vertices.set_used(4);
buffer3->Vertices[0] = video::S3DVertex(x0,x0,x1, -1,-1, 1, cubeColour, topl.X, btmr.Y);
@ -297,7 +297,7 @@ void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevi
texture = NULL;
if (lighting == "2")
texture = darken(driver, copied[ECS_LEFT]->get(), 0.7);
else if (lighting == "1")
else if (lighting == "1")
texture = darken(driver, copied[ECS_LEFT]->get(), 0.7);
else
texture = driver->addTexture("media/texture_box.png", copied[ECS_LEFT]->get());
@ -309,7 +309,7 @@ void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevi
// Right face
topl = vector2df((one.Z + 0.5), (-two.Y + 0.5));
topl = vector2df((one.Z + 0.5), (-two.Y + 0.5));
btmr = vector2df((two.Z + 0.5), (-one.Y + 0.5));
buffer4->Vertices.set_used(4);
buffer4->Vertices[0] = video::S3DVertex(x1,x0,x0, 1,-1,-1, cubeColour, topl.X, btmr.Y);
@ -320,7 +320,7 @@ void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevi
texture = NULL;
if (lighting == "2")
texture = darken(driver, copied[ECS_RIGHT]->get(), 0.7);
else if (lighting == "1")
else if (lighting == "1")
texture = darken(driver, copied[ECS_RIGHT]->get(), 0.7);
else
texture = driver->addTexture("media/texture_box.png", copied[ECS_RIGHT]->get());
@ -329,10 +329,10 @@ void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevi
buffer4->Material = mat;
cubeMesh->addMeshBuffer(buffer4);
buffer4->drop();
// Top face
topl = vector2df((one.X + 0.5), (-two.Z + 0.5));
// Top face
topl = vector2df((one.X + 0.5), (-two.Z + 0.5));
btmr = vector2df((two.X + 0.5), (-one.Z + 0.5));
buffer5->Vertices.set_used(4);
buffer5->Vertices[0] = video::S3DVertex(x0,x1,x0, -1, 1,-1, cubeColour, topl.X, btmr.Y);
@ -341,7 +341,7 @@ void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevi
buffer5->Vertices[3] = video::S3DVertex(x0,x1,x1, -1, 1, 1, cubeColour, topl.X, topl.Y);
buffer5->BoundingBox.reset(0,0,0);
texture = NULL;
if (lighting == "1")
if (lighting == "1")
texture = darken(driver, copied[ECS_TOP]->get(), 0.7);
else
texture = driver->addTexture("media/texture_box.png", copied[ECS_TOP]->get());
@ -352,8 +352,8 @@ void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevi
buffer5->drop();
// Bottom face
topl = vector2df((-one.X + 0.5), (-one.Z + 0.5));
// Bottom face
topl = vector2df((-one.X + 0.5), (-one.Z + 0.5));
btmr = vector2df((-two.X + 0.5), (-two.Z + 0.5));
buffer6->Vertices.set_used(4);
buffer6->Vertices[0] = video::S3DVertex(x0,x0,x1, -1,-1, 1, cubeColour, topl.X, btmr.Y);
@ -363,7 +363,7 @@ void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevi
buffer6->BoundingBox.reset(0,0,0);
if (lighting == "2")
texture = darken(driver, copied[ECS_BOTTOM]->get(), 0.4);
else if (lighting == "1")
else if (lighting == "1")
texture = darken(driver, copied[ECS_BOTTOM]->get(), 0.4);
else
texture = driver->addTexture("media/texture_box.png", copied[ECS_BOTTOM]->get());
@ -383,3 +383,52 @@ void NodeBox::buildNode(EditorState* editor, vector3di nd_position, IrrlichtDevi
model->setMaterialFlag(EMF_LIGHTING, false);
}
void NodeBox::rotate(EAxis axis)
{
switch (axis) {
case EAX_X: {
f32 tmp = one.X;
one.X = one.Y;
one.Y = -tmp;
tmp = two.X;
two.X = two.Y;
two.Y = -tmp;
break;
}
case EAX_Y: {
f32 tmp = one.X;
one.X = one.Z;
one.Z = -tmp;
tmp = two.X;
two.X = two.Z;
two.Z = -tmp;
break;
}
case EAX_Z: {
f32 tmp = one.Z;
one.Z = one.Y;
one.Y = -tmp;
tmp = two.Z;
two.Z = two.Y;
two.Y = -tmp;
break;
}};
// Check relative sizes
if (one.X > two.X) {
f32 tmp = one.X;
one.X = two.X;
two.X = tmp;
}
if (one.Y > two.Y) {
f32 tmp = one.Y;
one.Y = two.Y;
two.Y = tmp;
}
if (one.Z > two.Z) {
f32 tmp = one.Z;
one.Z = two.Z;
two.Z = tmp;
}
}

View File

@ -46,6 +46,7 @@ public:
void resizeNodeBoxFace(EditorState* editor, CDRType type, vector3df position, bool both);
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);
};
#endif

View File

@ -27,6 +27,13 @@ enum CubeSide
ECS_FRONT
};
enum EAxis
{
EAX_X,
EAX_Y,
EAX_Z
};
enum Viewport
{
VIEW_TL = 0,
@ -58,7 +65,7 @@ enum CDR_TYPE
enum CDRType
{
CDR_NONE = 0,
CDR_X_P,
CDR_X_P,
CDR_X_N,
CDR_Y_P,
CDR_Y_N,