diff --git a/sources/main.cpp b/sources/main.cpp index b7eedc8..e9e600c 100755 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -194,12 +194,11 @@ /* * initial rotation relative to rotation center */ - /* Vec getInitRotation(Vec* v) { - Vec dir = (*position - *v); - return Vec(atan2(dir.y(), dir.z()), - atan2(dir.x(), dir.z()), - atan2(dir.y(), dir.x())); - }*/ + Vec getInitRotation(Vec* v) { + return Vec(atan2(v->y(), v->z()), + atan2(v->x(), v->z()), + atan2(v->y(), v->x())); + } Vec getSphereCoords(Vec* v) { Vec dir = (*position - *v); @@ -239,6 +238,27 @@ this->rotation->add(rot); } + Vec rotate_x(Vec c) { + Vec initrot = getInitRotation(&c); + Vec rot = initrot + *rotation; + float r = Vec(0, c.y(), c.z()).length(); + return Vec (c.x(), r*cos(rot.x()), r*sin(rot.x())); + } + + Vec rotate_y(Vec c) { + Vec initrot = getInitRotation(&c); + Vec rot = initrot + *rotation; + float r = Vec(c.x(), 0, c.z()).length(); + return Vec (r*sin(rot.y()), c.y(), r*cos(rot.y())); + } + + Vec rotate_z(Vec c) { + Vec initrot = getInitRotation(&c); + Vec rot = initrot + *rotation; + float r = Vec(c.x(), c.y(), 0).length(); + return Vec (r*cos(rot.z()), r*sin(rot.z()), c.z()); + } + void draw() { glBegin (GL_POLYGON); //this->setNormal(); @@ -253,18 +273,30 @@ glBegin (GL_POLYGON); printf("polygonrotated: \n"); for (int v = 0; v < size; v++) { - Vec dir = (*initpoints[v] - *position); - Vec initrot = getSphereCoords(initpoints[v]); - initrot.print(); - Vec rot = initrot + *rotation; + //Vec initrot = getSphereCoords(initpoints[v]); //initpoints[v]->print(); //printf("%f", initpoints[v]->z()); //TODO: WARNING: POLAR COORDINATES - Vec out (rot.x() * sin(rot.y()) * cos(rot.z()), - rot.x() * sin(rot.y()) * sin(rot.z()), - rot.x() * cos(rot.y())); + //Vec out (rot.x() * sin(rot.y()) * cos(rot.z()), + // rot.x() * sin(rot.y()) * sin(rot.z()), + // rot.x() * cos(rot.y())); + + //r = Vec(dir.x(), 0, dir.z()).length(); + //Vec out (r * sin(rot.y()), dir.y(), r*cos(rot.y())); + //Vec out (r * sin(rot.y())+dir(x), r*cos(rot(x))+dir.y(), r*cos(rot.y())+r*sin(rot.x())); + + Vec out = (*initpoints[v] - *position); + out = this->rotate_x(out); + out = this->rotate_y(out); + out = this->rotate_z(out); glVertex3fv((*position + out).c); + + //r = Vec(dir.x(), dir.y(), 0).length(); + //Vec out (r * cos (rot.z()), r * sin (rot.z()), dir.z()); + + //Vec out (dir.x(), dir.y(), dir.z()); + //glVertex3fv((*position + out).c); } glEnd(); } @@ -369,7 +401,7 @@ bool MouseButtonRight, MouseButtonLeft; bool done = false; // Quit application when true - +/* Model* importModel(char* fname) { FILE *fp; @@ -418,7 +450,7 @@ fclose(fp); return mm; } - +*/ /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// @@ -452,6 +484,8 @@ Vec p6 (10,10,10); Vec p7 (0 ,10,10); + Vec cen (5,5,5); + /*Rect surf [SURFACE_COUNT] = { Rect (&p0, &p3, &p2, &p1, &red), Rect (&p4, &p5, &p6, &p7, &blue), @@ -477,8 +511,12 @@ new Poly(pp5, 4), }; - Model* myModel = importModel("teapot.obj"); + //Model* myModel = importModel("teapot.obj"); + for (int x = 0; x < SURFACE_COUNT; x++) { + polys[x]->setCenter(&cen); + } + //Vec* pp [4] = {&p0, &p3, &p2, &p1}; //Poly poly0 (pp,4); @@ -562,10 +600,10 @@ glRotatef(deltay, 0.0f, 1.0f, 0.0f); // Rotation around the Y axis glRotatef(deltaz, 1.0f, 0.0f, 0.0f); - /* for (int i = 0; i < SURFACE_COUNT; i++) { + for (int i = 0; i < SURFACE_COUNT; i++) { polys[i]->draw(); polys[i]->rotate(Vec(0.0f, 0.01f, 0.01f)); - }*/ + } //poly0.draw(); //poly0.rotate(Vec(0.0, 0.01, 0.01)); @@ -573,7 +611,7 @@ light0.draw(); light0.trace(); - myModel->draw(); + //myModel->draw(); //////////////// // Check events: SDL_Event event;