Commit 5aeebcb0 by Alisa Jung

added cube manipulation

parent 7c902f1c
...@@ -12,8 +12,7 @@ MyGLWidget::MyGLWidget(int index, Controller* c, bool isPerspective, QQuaternion ...@@ -12,8 +12,7 @@ MyGLWidget::MyGLWidget(int index, Controller* c, bool isPerspective, QQuaternion
qubeRotation = QQuaternion(); qubeRotation = QQuaternion();
cameraRotation = initialRotation; cameraRotation = initialRotation;
cameraStartRotation = initialRotation; cameraStartRotation = initialRotation;
translatex = 0; cubeTranslation = QVector3D(0,0,0);
translatey = 0;
camRotCenter = QVector3D(0,0,0); camRotCenter = QVector3D(0,0,0);
cameraZoom = cameraZoomDefault; cameraZoom = cameraZoomDefault;
clickStartPosition = QPoint(0,0); clickStartPosition = QPoint(0,0);
...@@ -142,7 +141,7 @@ void MyGLWidget::paintGL(){ ...@@ -142,7 +141,7 @@ void MyGLWidget::paintGL(){
m.rotate(qubeRotation); m.rotate(qubeRotation);
//for cube translation //for cube translation
QMatrix4x4 translateRot1 = QMatrix4x4(1,0,0,translatex,0,1,0,translatey,0,0,1,0,0,0,0,1); QMatrix4x4 translateRot1 = QMatrix4x4(1,0,0,cubeTranslation.x(),0,1,0,cubeTranslation.y(),0,0,1,cubeTranslation.z(),0,0,0,1);
QMatrix4x4 zoomCameraMatrix = QMatrix4x4(1,0,0,0,0,1,0,0,0,0,1,cameraZoom,0,0,0,1); QMatrix4x4 zoomCameraMatrix = QMatrix4x4(1,0,0,0,0,1,0,0,0,0,1,cameraZoom,0,0,0,1);
...@@ -153,9 +152,6 @@ void MyGLWidget::paintGL(){ ...@@ -153,9 +152,6 @@ void MyGLWidget::paintGL(){
// glTranslatef(cameraX,cameraY,0);//TODO anständig machen, kamerarotation fehlt noch. // glTranslatef(cameraX,cameraY,0);//TODO anständig machen, kamerarotation fehlt noch.
//stack matrices
// glMultMatrixf(translateRot1.data());//Punkte zurück schieben damit rotation um qube zentrum ist
// glMultMatrixf(m.data());
//So scheint das zumindest für die Kamera zu funktionieren: //So scheint das zumindest für die Kamera zu funktionieren:
...@@ -167,6 +163,12 @@ void MyGLWidget::paintGL(){ ...@@ -167,6 +163,12 @@ void MyGLWidget::paintGL(){
glTranslatef(camRotCenter.x(),camRotCenter.y(),camRotCenter.z()); glTranslatef(camRotCenter.x(),camRotCenter.y(),camRotCenter.z());
//stack matrices
glMultMatrixf(translateRot1.data());//Punkte zurück schieben damit rotation um qube zentrum ist
glMultMatrixf(m.data());
//tesselation //tesselation
double qubeWidth = 1.0; double qubeWidth = 1.0;
double dist = qubeWidth/(double)tesselation; double dist = qubeWidth/(double)tesselation;
...@@ -319,8 +321,7 @@ void MyGLWidget::translateCamera(double xDiff, double yDiff, double zDiff) ...@@ -319,8 +321,7 @@ void MyGLWidget::translateCamera(double xDiff, double yDiff, double zDiff)
} }
void MyGLWidget::translateQube(double xDiff, double yDiff){ void MyGLWidget::translateQube(double xDiff, double yDiff){
translatex += xDiff; cubeTranslation += cameraRotation.conjugate().rotatedVector(QVector3D(xDiff, yDiff,0));
translatey += yDiff;
updateGL(); updateGL();
} }
...@@ -399,8 +400,7 @@ void MyGLWidget::setTessellation(int t){ ...@@ -399,8 +400,7 @@ void MyGLWidget::setTessellation(int t){
void MyGLWidget::resetCamera(){ void MyGLWidget::resetCamera(){
qubeRotation = QQuaternion(); qubeRotation = QQuaternion();
translatex = 0; cubeTranslation = QVector3D(0,0,0);
translatey = 0;
camRotCenter = QVector3D(0,0,0); camRotCenter = QVector3D(0,0,0);
cameraZoom = cameraZoomDefault; cameraZoom = cameraZoomDefault;
cameraRotation = cameraStartRotation; cameraRotation = cameraStartRotation;
......
...@@ -70,7 +70,7 @@ private: ...@@ -70,7 +70,7 @@ private:
//translate camera //translate camera
QPoint clickStartPosition; QPoint clickStartPosition;
bool rightButtonPressed; bool rightButtonPressed;
double translatex, translatey; QVector3D cubeTranslation;
//rotate cube //rotate cube
bool leftButtonPressed; bool leftButtonPressed;
......
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