1 //
2 // Computergraphik II
3 // Prof. Dr. Juergen Doellner
4 // Wintersemester 2001/02
5 //
6 // Rahmenprogramm zu Aufgabenzettel 8
7 //
8
9 #include "triangle.h"
10 #include <iostream.h>
11 #include <assert.h>
12 #include <algorithm>
13
14 Triangle::Triangle() { }
15
16 Triangle::Triangle(const Vector& v0,const Vector& v1, const Vector& v2) {
17 v_[0] = v0;
18 v_[1] = v1;
19 v_[2] = v2;
20 triNrm_ = makeCWTriangleNormal(v_[0],v_[1],v_[2]);
21 n_[0] = n_[1] = n_[2] = triNrm_;
22 }
23
24
25 void Triangle::normalizeNormals() {
26 n_[0].normalize();
27 n_[1].normalize();
28 n_[2].normalize();
29 }
30
31 //
32 // IO
33 //
34
35
36
37 istream& operator>>(istream& s, Triangle& u) {
38 Vector t0, t1, t2;
39 // for (int i = 0; i < 3; i++) {
40 if (!(s >> t0[0] >> t0[1] >> t0[2] >> t1[0] >> t1[1] >> t1[2] >> t2[0] >> t2[1] >> t2[2]) ) {
41 assert(0);
42 }
43 u.v_[0] = t0;
44 u.v_[1] = t1;
45 u.v_[2] = t2;
46 //}
47 u.triNrm_ = makeCWTriangleNormal(u.v_[0],u.v_[1],u.v_[2]);
48 u.n_[0] = u.n_[1] = u.n_[2] = u.triNrm_;
49 return s;
50 }
51