Commit 46873760 by Alisa Jung

grid

parent fbbc62b6
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.5.1, 2015-11-23T17:08:38. --> <!-- Written by QtCreator 3.5.1, 2015-11-23T22:09:40. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
......
...@@ -220,6 +220,21 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -220,6 +220,21 @@ MainWindow::MainWindow(QWidget *parent)
} }
gridSizeInput = new QSpinBox(toolBar);
gridSizeInput->setRange(0,100);
gridSizeInput->setValue(5);
toolBar->addWidget(gridSizeInput);
gridSizeInput->setToolTip("Grid Size");
gridStepInput = new QSpinBox(toolBar);
gridStepInput->setRange(1,10);
toolBar->addWidget(gridStepInput);
gridStepInput->setToolTip("Grid Step Size");
for(int i = 0; i < 4; i++){
connect(gridSizeInput,SIGNAL(valueChanged(int)),allWidgets[i],SLOT(setGridSize(int)));
connect(gridStepInput,SIGNAL(valueChanged(int)),allWidgets[i],SLOT(setGridStepSize(int)));
}
qDebug("Done initializing"); qDebug("Done initializing");
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <QDockWidget> #include <QDockWidget>
#include <QLineEdit> #include <QLineEdit>
#include <QInputDialog> #include <QInputDialog>
#include <QSpinBox>
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
...@@ -92,6 +93,9 @@ private: ...@@ -92,6 +93,9 @@ private:
QLineEdit* textInput; QLineEdit* textInput;
QSpinBox* gridSizeInput;
QSpinBox* gridStepInput;
public slots : public slots :
void showAboutBox ( ) ; void showAboutBox ( ) ;
void showTextEditBox(); void showTextEditBox();
......
...@@ -21,6 +21,9 @@ MyGLWidget::MyGLWidget(int index, Controller* c, bool isPerspective, QQuaternion ...@@ -21,6 +21,9 @@ MyGLWidget::MyGLWidget(int index, Controller* c, bool isPerspective, QQuaternion
scene = controller->getSceneGraph(); scene = controller->getSceneGraph();
scene->registerView(this); scene->registerView(this);
gridSize = 5;
gridStepSize = 1;
} }
MyGLWidget::~MyGLWidget() MyGLWidget::~MyGLWidget()
...@@ -222,6 +225,8 @@ void MyGLWidget::paintGL(){ ...@@ -222,6 +225,8 @@ void MyGLWidget::paintGL(){
glTranslatef(camRotCenter.x(),camRotCenter.y(),camRotCenter.z()); glTranslatef(camRotCenter.x(),camRotCenter.y(),camRotCenter.z());
// scene->drawAll(); // scene->drawAll();
drawGrid();
const QList<RigidBodyTransformation*> graph = scene->getGraph(); const QList<RigidBodyTransformation*> graph = scene->getGraph();
QList<RigidBodyTransformation*>::const_iterator i; QList<RigidBodyTransformation*>::const_iterator i;
for (i = graph.begin(); i != graph.end(); ++i){ for (i = graph.begin(); i != graph.end(); ++i){
...@@ -428,7 +433,6 @@ void MyGLWidget::drawBox(int tesselation){ ...@@ -428,7 +433,6 @@ void MyGLWidget::drawBox(int tesselation){
//4.1.1 Unit Qube + Tesselation + Diffuse Material //4.1.1 Unit Qube + Tesselation + Diffuse Material
GLfloat specularColor[] = { 1, 1, 1 }; GLfloat specularColor[] = { 1, 1, 1 };
GLfloat shininess[] = { 128 };//specular exponent GLfloat shininess[] = { 128 };//specular exponent
glMaterialfv(GL_FRONT, GL_SPECULAR, specularColor); glMaterialfv(GL_FRONT, GL_SPECULAR, specularColor);
...@@ -587,3 +591,68 @@ void MyGLWidget::drawTorus(int tesselation){ ...@@ -587,3 +591,68 @@ void MyGLWidget::drawTorus(int tesselation){
glEnd(); glEnd();
} }
void MyGLWidget::drawGrid(){
GLfloat specularColor[] = {0,0,0};
GLfloat shininess[] = {128};
glMaterialfv(GL_FRONT,GL_SPECULAR,specularColor);
glMaterialfv(GL_FRONT,GL_SHININESS, shininess);
GLfloat grey[] = {1,0.5,0.5};
glMaterialfv(GL_FRONT,GL_DIFFUSE,grey);
glNormal3f(0,1,0);
phongShader->release();
glDisable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glLineWidth(1);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINES);
glBegin(GL_LINES);
float stepSize = gridStepSize;
float x = stepSize;
float y = stepSize;
if (stepSize <= 0) stepSize = 1;
for(; x < gridSize; x += stepSize){
glVertex3f(x,0,-gridSize);
glVertex3f(x,0,gridSize);
glVertex3f(-x,0,-gridSize);
glVertex3f(-x,0,gridSize);
}
for (; y < gridSize; y += stepSize){
glVertex3f(-gridSize, 0, y);
glVertex3f(gridSize,0,y);
glVertex3f(-gridSize,0,-y);
glVertex3f(gridSize,0,-y);
}
glEnd();
GLfloat red[] = {1,0,0};
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,red);
glBegin(GL_LINES);
glVertex3f(0,0,-gridSize);
glVertex3f(0,0,gridSize);
glEnd();
GLfloat green[] = {0,1,0};
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,green);
glBegin(GL_LINES);
glVertex3f(-gridSize,0,0);
glVertex3f(gridSize,0,0);
glEnd();
glPolygonMode(GL_FRONT,GL_FILL);
glEnable(GL_LIGHTING);
phongShader->bind();
}
void MyGLWidget::setGridSize(int size){
gridSize = size;
updateGL();
}
void MyGLWidget::setGridStepSize(int stepSize){
gridStepSize = stepSize;
updateGL();
}
...@@ -102,9 +102,15 @@ private: ...@@ -102,9 +102,15 @@ private:
void drawCylinder(int tesselation); void drawCylinder(int tesselation);
void drawCone(int tesselation); void drawCone(int tesselation);
void drawTorus(int tesselation); void drawTorus(int tesselation);
void drawGrid();
int gridSize;
int gridStepSize;
public slots: public slots:
//4.1.1 slots for shading modes //4.1.1 slots for shading modes
void resetCamera(); void resetCamera();
void setGridSize(int size);
void setGridStepSize(int stepSize);
}; };
#endif // GLWIDGET_H #endif // GLWIDGET_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment