diff --git a/sources/main.cpp b/sources/main.cpp index 4fc4c1d..09538b3 100755 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -93,10 +93,11 @@ return r; } - Vec cross(Vec v) { - Vec r = Vec(y * v.z - z * v.y, + Vec* cross(Vec v) { + Vec* r = new Vec(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x); + return r; } Vec normalize() { @@ -128,7 +129,9 @@ p[1] = p1; p[2] = p2; col = c; - normal = ((*p[1] - *p[0]).cross(*p[2] - *p[0])).clone(); + Vec v1 = (*p[1] - *p[0]); + Vec v2 = (*p[2] - *p[0]); + normal = (v1).cross(v2); } ~Tri() { @@ -140,15 +143,14 @@ this->setNormal(); col->setColor(); for (int v = 0; v < 3; v++) { - glVertex3f (scale * p[v]->x, scale * p[v]->y, scale * p[v]->z); + glVertex3f (scale * p[v]->x, scale * p[v]->y, scale * p[v]->z); } - glEnd(); + glEnd(); this->print(); } void setNormal() { - //glNormal3f(); - //this->normal(); + glNormal3f(this->normal->x, this->normal->y, this->normal->z); } void print() { @@ -156,6 +158,8 @@ for (int v = 0; v < 3; v++) { p[v]->print(); } + printf("normal: "); + normal->print(); printf("\n"); } };