Rotation and Toggle Normals

This commit is contained in:
Riku Avelar 2016-11-30 16:22:35 -05:00
parent e3b690b42d
commit 1a04dd8db3
5 changed files with 149 additions and 31 deletions

View File

@ -63,6 +63,26 @@
<property name="horizontalSpacing"> <property name="horizontalSpacing">
<number>6</number> <number>6</number>
</property> </property>
<item row="3" column="1">
<widget class="QPushButton" name="cw_x">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>-X</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="ccw_x">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>+X</string>
</property>
</widget>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
@ -70,18 +90,15 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="6" column="0" colspan="2">
<spacer name="verticalSpacer_2"> <widget class="QPushButton" name="action_delete">
<property name="orientation"> <property name="enabled">
<enum>Qt::Vertical</enum> <bool>false</bool>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="text">
<size> <string>Delete Cube</string>
<width>20</width>
<height>40</height>
</size>
</property> </property>
</spacer> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QComboBox" name="comboBox"> <widget class="QComboBox" name="comboBox">
@ -107,6 +124,13 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Forme</string>
</property>
</widget>
</item>
<item row="2" column="1"> <item row="2" column="1">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
@ -120,12 +144,18 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label"> <spacer name="verticalSpacer_2">
<property name="text"> <property name="orientation">
<string>Forme</string> <enum>Qt::Vertical</enum>
</property> </property>
</widget> <property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QPushButton" name="pushButton"> <widget class="QPushButton" name="pushButton">
@ -140,13 +170,43 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="2"> <item row="4" column="0">
<widget class="QPushButton" name="action_delete"> <widget class="QPushButton" name="ccw_y">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="text"> <property name="text">
<string>Delete Cube</string> <string>+Y</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QPushButton" name="cw_y">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>-Y</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QPushButton" name="ccw_z">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>+Z</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QPushButton" name="cw_z">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>-Z</string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -235,9 +235,7 @@ void Viewer::mousePressEvent(QMouseEvent* e) {
} }
selectedObj.shape = selectedGeom.shape; selectedObj.shape = selectedGeom.shape;
selectedObj.shape->getParent()->addChild(selection); selectedObj.shape->getParent()->addChild(selection);
cubeSelected(true); cubeSelected(true);
rotateSelected(X_CCW);
} }
if(!selectedGeom.position.isIdentity() && e->modifiers().testFlag(Qt::ShiftModifier)) if(!selectedGeom.position.isIdentity() && e->modifiers().testFlag(Qt::ShiftModifier))
@ -847,6 +845,13 @@ void Viewer::toggleNormalMaps(bool state) {
} }
void Viewer::deleteSelected() { void Viewer::deleteSelected() {
m_program->bind();
int pointCLocs[3] = {m_c1Loc, m_c2Loc, m_c3Loc};
m_program->setUniformValue(pointCLocs[0], QColor(0,0,0));
m_program->setUniformValue(pointCLocs[1], QColor(0,0,0));
m_program->setUniformValue(pointCLocs[2], QColor(0,0,0));
// Remove Shape from its parent // Remove Shape from its parent
if(selectedObj.shape == nullptr) return; if(selectedObj.shape == nullptr) return;
// selectedObj.shape->getParent()->getChildren()->erase( // selectedObj.shape->getParent()->getChildren()->erase(
@ -887,6 +892,24 @@ void Viewer::startAniumation(){}
void Viewer::stopAnimation(){} void Viewer::stopAnimation(){}
void Viewer::rotateSelectedObjXCCW() {
rotateSelected(RotateDirection::X_CCW);
}
void Viewer::rotateSelectedObjXCW() {
rotateSelected(RotateDirection::X_CW);
}
void Viewer::rotateSelectedObjYCCW() {
rotateSelected(RotateDirection::Y_CCW);
}
void Viewer::rotateSelectedObjYCW() {
rotateSelected(RotateDirection::Y_CW);
}
void Viewer::rotateSelectedObjZCCW() {
rotateSelected(RotateDirection::Z_CCW);
}
void Viewer::rotateSelectedObjZCW() {
rotateSelected(RotateDirection::Z_CW);
}
void Viewer::rotateSelected(RotateDirection dir) { void Viewer::rotateSelected(RotateDirection dir) {
if(selectedObj.shape == nullptr || selectedObj.shape->getParent() == nullptr) return; if(selectedObj.shape == nullptr || selectedObj.shape->getParent() == nullptr) return;

View File

@ -56,6 +56,17 @@ public:
virtual void visit(Cube &s); virtual void visit(Cube &s);
virtual void visit(Sphere &s); virtual void visit(Sphere &s);
enum RotateDirection {
X_CCW,
X_CW,
Y_CCW,
Y_CW,
Z_CCW,
Z_CW
};
public slots: public slots:
void cleanup(); void cleanup();
void changeColor(QColor); void changeColor(QColor);
@ -64,6 +75,12 @@ public slots:
void setMinLinear(bool); void setMinLinear(bool);
void deleteSelected(); void deleteSelected();
void toggleNormalMaps(bool); void toggleNormalMaps(bool);
void rotateSelectedObjXCCW();
void rotateSelectedObjXCW();
void rotateSelectedObjYCCW();
void rotateSelectedObjYCW();
void rotateSelectedObjZCCW();
void rotateSelectedObjZCW();
signals: signals:
int shapeSelected(int); int shapeSelected(int);
@ -154,16 +171,7 @@ private:
GLuint m_Buffers[NumBuffers]; GLuint m_Buffers[NumBuffers];
GLuint m_RenderBuffers[NumRenderBuffers]; GLuint m_RenderBuffers[NumRenderBuffers];
Shape* generateShapeFromIndex(int); Shape* generateShapeFromIndex(int);
enum RotateDirection {
X_CCW,
X_CW,
Y_CCW,
Y_CW,
Z_CCW,
Z_CW
};
enum Textures{ enum Textures{
TEX_DRYGOUND, TEX_DRYGOUND,

View File

@ -3,6 +3,7 @@
#include <QBoxLayout> #include <QBoxLayout>
#include <QColorDialog> #include <QColorDialog>
#include <QActionGroup> #include <QActionGroup>
#include <QButtonGroup>
namespace { namespace {
Viewer* view; Viewer* view;
@ -27,6 +28,16 @@ MainWindow::MainWindow(QWidget *parent) :
magFilterGroup->addAction(ui->actionMagLinear); magFilterGroup->addAction(ui->actionMagLinear);
magFilterGroup->addAction(ui->actionMagNear); magFilterGroup->addAction(ui->actionMagNear);
controlGroup = new QButtonGroup(this);
controlGroup->addButton(ui->action_delete);
controlGroup->addButton(ui->ccw_x);
controlGroup->addButton(ui->cw_x);
controlGroup->addButton(ui->ccw_y);
controlGroup->addButton(ui->cw_y);
controlGroup->addButton(ui->ccw_z);
controlGroup->addButton(ui->cw_z);
connect(ui->pushButton, SIGNAL(clicked(bool)), this, SLOT(onColorPickerActivate())); connect(ui->pushButton, SIGNAL(clicked(bool)), this, SLOT(onColorPickerActivate()));
} }
@ -49,7 +60,21 @@ void MainWindow::addViewer(Viewer* viewer)
connect(ui->actionNormal_Maps, SIGNAL(toggled(bool)), viewer, SLOT(toggleNormalMaps(bool))); connect(ui->actionNormal_Maps, SIGNAL(toggled(bool)), viewer, SLOT(toggleNormalMaps(bool)));
connect(ui->action_delete, SIGNAL(clicked(bool)), viewer, SLOT(deleteSelected())); connect(ui->action_delete, SIGNAL(clicked(bool)), viewer, SLOT(deleteSelected()));
connect(viewer, SIGNAL(cubeSelected(bool)), ui->action_delete, SLOT(setEnabled(bool))); connect(viewer, SIGNAL(cubeSelected(bool)), ui->action_delete, SLOT(setEnabled(bool)));
connect(viewer, SIGNAL(cubeSelected(bool)), ui->ccw_x, SLOT(setEnabled(bool)));
connect(viewer, SIGNAL(cubeSelected(bool)), ui->cw_x, SLOT(setEnabled(bool)));
connect(viewer, SIGNAL(cubeSelected(bool)), ui->ccw_y, SLOT(setEnabled(bool)));
connect(viewer, SIGNAL(cubeSelected(bool)), ui->cw_y, SLOT(setEnabled(bool)));
connect(viewer, SIGNAL(cubeSelected(bool)), ui->ccw_z, SLOT(setEnabled(bool)));
connect(viewer, SIGNAL(cubeSelected(bool)), ui->cw_z, SLOT(setEnabled(bool)));
connect(ui->ccw_x, SIGNAL(clicked(bool)), viewer, SLOT(rotateSelectedObjXCCW()));
connect(ui->cw_x, SIGNAL(clicked(bool)), viewer, SLOT(rotateSelectedObjXCW()));
connect(ui->ccw_y, SIGNAL(clicked(bool)), viewer, SLOT(rotateSelectedObjYCCW()));
connect(ui->cw_y, SIGNAL(clicked(bool)), viewer, SLOT(rotateSelectedObjYCW()));
connect(ui->ccw_z, SIGNAL(clicked(bool)), viewer, SLOT(rotateSelectedObjZCCW()));
connect(ui->cw_z, SIGNAL(clicked(bool)), viewer, SLOT(rotateSelectedObjZCW()));
} }
void MainWindow::onColorPickerActivate(){ void MainWindow::onColorPickerActivate(){

View File

@ -4,6 +4,7 @@
#include <QMainWindow> #include <QMainWindow>
#include <QColorDialog> #include <QColorDialog>
#include <QActionGroup> #include <QActionGroup>
#include <QButtonGroup>
#include "src/viewer/simpleViewer.h" #include "src/viewer/simpleViewer.h"
namespace Ui { namespace Ui {
@ -30,6 +31,7 @@ private:
QActionGroup *lightTypeGroup; QActionGroup *lightTypeGroup;
QActionGroup *minFilterGroup; QActionGroup *minFilterGroup;
QActionGroup *magFilterGroup; QActionGroup *magFilterGroup;
QButtonGroup *controlGroup;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H