Commit 06b6dd64 by Alisa Jung

successfully and against all odds added RigidBodyTransformation, Primitive and Box.

parent 58478b68
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.5.1, 2015-11-19T23:00:19. -->
<!-- Written by QtCreator 3.5.1, 2015-11-19T23:28:44. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......
......@@ -20,6 +20,10 @@ MyGLWidget::MyGLWidget(int index, Controller* c, bool isPerspective, QQuaternion
controller = c;
this->isPerspective = isPerspective;
this->isFocused = isPerspective; //start with focus on perspective view
platzhalter = "bla";
primitive = new Box(0,platzhalter,1);
rbt = new RigidBodyTransformation(primitive);
}
MyGLWidget::~MyGLWidget()
......@@ -146,126 +150,7 @@ void MyGLWidget::paintGL(){
glMultMatrixf(camRot.data());
glTranslatef(camRotCenter.x(),camRotCenter.y(),camRotCenter.z());
//for cube rotation
QMatrix4x4 m = QMatrix4x4();
m.rotate(qubeRotation);
//for cube translation
QMatrix4x4 translateRot1 = QMatrix4x4(1,0,0,cubeTranslation.x(),0,1,0,cubeTranslation.y(),0,0,1,cubeTranslation.z(),0,0,0,1);
//stack matrices
glMultMatrixf(translateRot1.data());//Punkte zurück schieben damit rotation um qube zentrum ist
glMultMatrixf(m.data());
//tesselation
double qubeWidth = 1.0;
double dist = qubeWidth/(double)tesselation;
//4.1.1 Unit Qube + Tesselation + Diffuse Material
{
GLfloat specularColor[] = {1,1,1};
GLfloat shininess[] = {128};//specular exponent
glMaterialfv(GL_FRONT,GL_SPECULAR,specularColor);
glMaterialfv(GL_FRONT,GL_SHININESS,shininess);
//vorne // z-Achse
// glColor3f(0,0,1);//blau //alt und doof
GLfloat blue[] = {0,0,1};
glMaterialfv(GL_FRONT,GL_DIFFUSE,blue);
glNormal3f(0,0,1);
glBegin(GL_QUADS);
for (int i = 0; i < tesselation; i++){
for (int j = 0; j < tesselation; j++){
glVertex3f(0.5-dist*i,0.5-dist*j,0.5);
glVertex3f(0.5-dist*(i+1),0.5-dist*j,0.5);
glVertex3f(0.5-dist*(i+1),0.5-dist*(j+1),0.5);
glVertex3f(0.5-dist*i,0.5-dist*(j+1),0.5);
}
}
glEnd();
//oben // y-Achse
GLfloat green[] = {0,1,0};
glMaterialfv(GL_FRONT,GL_DIFFUSE,green);
glNormal3f(0,1,0);
glBegin(GL_QUADS);
for (int i = 0; i < tesselation; i++){
for (int j = 0; j < tesselation; j++){
glVertex3f(0.5-dist*(i+1), 0.5, 0.5-dist*(j+1));
glVertex3f(0.5-dist*(i+1), 0.5, 0.5-dist*j);
glVertex3f(0.5-dist*i, 0.5, 0.5-dist*j);
glVertex3f(0.5-dist*i, 0.5, 0.5-dist*(j+1));
}
}
glEnd();
//rechts //x-Achse
GLfloat red[] = {1,0,0};
glMaterialfv(GL_FRONT,GL_DIFFUSE,red);
glNormal3f(1,0,0);
glBegin(GL_QUADS);
for (int i = 0; i < tesselation; i++){
for (int j = 0; j < tesselation; j++){
glVertex3f(0.5, 0.5-dist*i, 0.5-dist*j);
glVertex3f(0.5, 0.5-dist*(i+1), 0.5-dist*j);
glVertex3f(0.5, 0.5-dist*(i+1), 0.5-dist*(j+1));
glVertex3f(0.5, 0.5-dist*i, 0.5-dist*(j+1));
}
}
glEnd();
//hinten // z-Achse
GLfloat yellow[] = {1,0.9f,0};
glMaterialfv(GL_FRONT,GL_DIFFUSE,yellow);
glNormal3f(0,0,-1);
glBegin(GL_QUADS);
for (int i = 0; i < tesselation; i++){
for (int j = 0; j < tesselation; j++){
glVertex3f(0.5-dist*i, 0.5-dist*(j+1), -0.5);//4
glVertex3f(0.5-dist*(i+1), 0.5-dist*(j+1), -0.5);//3
glVertex3f(0.5-dist*(i+1), 0.5-dist*j, -0.5);//2
glVertex3f(0.5-dist*i, 0.5-dist*j, -0.5);//1
}
}
glEnd();
//links
GLfloat cyan[] = {0,1,1};
glMaterialfv(GL_FRONT,GL_DIFFUSE,cyan);
glNormal3f(-1,0,0);
glBegin(GL_QUADS);
for (int i = 0; i < tesselation; i++){
for (int j = 0; j < tesselation; j++){
glVertex3f(-0.5, 0.5-dist*i, 0.5-dist*(j+1));
glVertex3f(-0.5, 0.5-dist*(i+1), 0.5-dist*(j+1));
glVertex3f(-0.5, 0.5-dist*(i+1), 0.5-dist*j);
glVertex3f(-0.5, 0.5-dist*i, 0.5-dist*j);
}
}
glEnd();
//unten //-y
GLfloat magenta[] = {1,0,1};
glMaterialfv(GL_FRONT,GL_DIFFUSE,magenta);
glNormal3f(0,-1,0);
glBegin(GL_QUADS);
for (int i = 0; i < tesselation; i++){
for (int j = 0; j < tesselation; j++){
glVertex3f(0.5-dist*i, -0.5, 0.5-dist*(j+1));
glVertex3f(0.5-dist*i, -0.5, 0.5-dist*j);
glVertex3f(0.5-dist*(i+1), -0.5, 0.5-dist*j);
glVertex3f(0.5-dist*(i+1), -0.5, 0.5-dist*(j+1));
}
}
glEnd();
}
rbt->drawChild();
//has to be down here or will be overpainted by above code
if (isFocused) highlightViewport();
......@@ -360,7 +245,8 @@ void MyGLWidget::translateCamera(double xDiff, double yDiff, double zDiff)
}
void MyGLWidget::translateQube(double xDiff, double yDiff){
cubeTranslation += cameraRotation.conjugate().rotatedVector(QVector3D(xDiff, yDiff,0));
// cubeTranslation += cameraRotation.conjugate().rotatedVector(QVector3D(xDiff, yDiff,0));
rbt->addTranslation(cameraRotation.conjugate().rotatedVector(QVector3D(xDiff, yDiff,0)));
updateGL();
}
......@@ -373,8 +259,11 @@ void MyGLWidget::rotateQube(QQuaternion diff){
* in which q′ corresponds to the rotation q1 followed by the rotation q2.
* (Note that quaternion multiplication is not commutative.)
*/
qubeRotation = diff*qubeRotation;
qubeRotation.normalize();
rbt->addRotation(diff);
// qubeRotation = diff*qubeRotation;
// qubeRotation.normalize();
updateGL();
......
......@@ -14,6 +14,9 @@
#include <QStyleOption>
#include <QStylePainter>
#include <rigidbodytransformation.h>//vorläufig, bis szenengraph steht.
#include <box.h>
class Controller;
......@@ -83,6 +86,10 @@ private:
//Phong Shader
QGLShaderProgram *phongShader;
RigidBodyTransformation* rbt;
Primitive* primitive;
char* platzhalter;
void highlightViewport();
void resetProjectionMatrix();
......
#include "rigidbodytransformation.h"
RigidBodyTransformation::RigidBodyTransformation(Primitive child)
RigidBodyTransformation::RigidBodyTransformation(Primitive* child)
{
tx = 0;
ty = 0;
......@@ -15,10 +15,21 @@ void RigidBodyTransformation::setTranslation(double x, double y, double z){
tz = z;
}
void RigidBodyTransformation::addTranslation(QVector3D diff){
tx += diff.x();
ty += diff.y();
tz += diff.z();
}
QQuaternion RigidBodyTransformation::getRotation(){
return rotation;
}
void RigidBodyTransformation::addRotation(QQuaternion diff){
rotation = diff*rotation;
rotation.normalize();
}
void RigidBodyTransformation::setRotation(QQuaternion newRotation){
rotation = newRotation;
}
......@@ -40,5 +51,5 @@ void RigidBodyTransformation::drawChild(){
//maybe a foreach later on?
child.drawPrimitive();
child->drawPrimitive();
}
......@@ -7,10 +7,12 @@
class RigidBodyTransformation
{
public:
RigidBodyTransformation(Primitive child);
RigidBodyTransformation(Primitive* child);
void setTranslation(double x, double y, double z);
void addTranslation(QVector3D diff);
void setRotation(QQuaternion newRotation);
void addRotation(QQuaternion diff);
QQuaternion getRotation();
void drawChild();
......@@ -22,7 +24,7 @@ private :
QQuaternion rotation;
//child in scene graph
Primitive child;
Primitive* child;
};
#endif // RIGIDBODYTRANSFORMATION_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