sources:
attribute.cpp (1.1k)
attribute.h (1.5k)
cgapplication.cpp (4.1k)
cgapplication.h (4.8k)
cgrobot.cpp (7.9k)
cgrobot.h (716 bytes)
node.cpp (2.4k)
node.h (2.3k)
shape.cpp (3.2k)
shape.h (966 bytes)
transformation.cpp (2.9k)
transformation.h (2.4k)
vector.cpp (1.4k)
vector.h (5.3k)


website:
more info here


screenshot:
studies/grafik/Computergrafik-Code8/node.cpp
download file

  1 // Computergraphik I
  2 // Prof. Dr. Juergen Doellner
  3 // Sommersemester 2001
  4 //
  5 // Rahmenprogramm fuer Aufgabenzettel 8
  6
  7 #include "node.h"
  8
  9 #include <assert.h>
 10 #include <iostream.h>
 11 #include <GL/glut.h>
 12
 13 //
 14 // LeafNode
 15 //
 16
 17 LeafNode::LeafNode(Shape* shape)
 18     : shape_(shape) {
 19 }
 20
 21 void LeafNode::traverse() {
 22     if(shape_) { shape_->render(); }
 23
 24 // cout << shape_ << " ";
 25 }
 26
 27 //
 28 // GroupNode
 29 //
 30
 31 GroupNode::GroupNode() {
 32     // Initialisiere alle Attribute mit NULL
 33     for(unsigned int i = 0; i < MAX_ATTRIBUTES; ++i) {
 34         attributes_[i] = 0;
 35     }
 36
 37     // Initialisiere alle Kind-Knoten mit NULL
 38     for(unsigned int j = 0; j < MAX_CHILD_NODES; ++j) {
 39         children_[j] = 0;
 40     }
 41 }
 42
 43 GroupNode* GroupNode::shareNode(Node* nodeObject, int nCount, Attribute* attrTransform1, Attribute* attrTransform2)
 44 {
 45     GroupNode* sharedNode = NULL;
 46
 47     for (int shape = 1; shape <= nCount; shape++)
 48     {
 49         static GroupNode* oldNode;
 50         oldNode = sharedNode;
 51         sharedNode = new GroupNode;
 52        
 53         if (shape < nCount)
 54         {
 55             if (attrTransform1 != NULL)
 56                 sharedNode->setAttribute(0, attrTransform1);
 57             if (attrTransform2 != NULL)
 58                 sharedNode->setAttribute(1, attrTransform2);
 59         }
 60
 61         sharedNode->setChildNode(0, nodeObject);
 62
 63         if (oldNode != NULL)
 64             sharedNode->setChildNode(1, oldNode);
 65     }
 66
 67     return sharedNode;
 68 }
 69
 70
 71 Attribute* GroupNode::getAttribute(unsigned int index) const {
 72     assert(index < MAX_ATTRIBUTES);
 73     return attributes_[index];
 74 }
 75
 76 void GroupNode::setAttribute(unsigned int index, Attribute* attribute) {
 77     assert(index < MAX_ATTRIBUTES);
 78     attributes_[index] = attribute;
 79 }
 80
 81 Node* GroupNode::getChildNode(unsigned int index) const {
 82     assert(index < MAX_CHILD_NODES);
 83     return  children_[index];
 84 }
 85
 86 void GroupNode::setChildNode(unsigned int index, Node* child) {
 87     assert(index < MAX_CHILD_NODES);
 88     children_[index] = child;
 89 }
 90
 91 void GroupNode::traverse() {
 92     // Setzte alle Attribute
 93     for(unsigned int i = 0; i < MAX_ATTRIBUTES; ++i) {
 94         if(attributes_[i]) { attributes_[i]->set(); }
 95     }
 96
 97     // Traversiere alle Kind-Knoten
 98     for(unsigned int j = 0; j < MAX_CHILD_NODES; ++j) {
 99         if(children_[j]) { children_[j]->traverse(); }
100     }
101
102     // Setzte alle Attribute in umgekehrter Reihenfolge zurueck
103     for(unsigned int k = MAX_ATTRIBUTES; k > 0; --k) {
104         if(attributes_[k - 1]) { attributes_[k - 1]->unset(); }
105     }
106 }
107
108