- Timestamp:
- Feb 3, 2006, 11:44:59 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/coord/p_node.cc
r7003 r7008 42 42 */ 43 43 PNode::PNode (PNode* parent, long nodeFlags) 44 : Synchronizeable(), BaseObject()44 : Synchronizeable(), BaseObject() 45 45 { 46 46 this->setClassID(CL_PARENT_NODE, "PNode"); … … 88 88 deleteNode = tmp; 89 89 tmp++; 90 // printf("TEST::%s(%s) %s\n", (*deleteNode)->getName(), (*deleteNode)->getClassName(), this->getName());90 // printf("TEST::%s(%s) %s\n", (*deleteNode)->getName(), (*deleteNode)->getClassName(), this->getName()); 91 91 if ((this->parentMode & PNODE_PROHIBIT_CHILD_DELETE) || 92 92 ((*deleteNode)->parentMode & PNODE_PROHIBIT_DELETE_WITH_PARENT)) … … 102 102 103 103 if (this->parent != NULL) 104 105 106 107 104 { 105 this->parent->eraseChild(this); 106 this->parent = NULL; 107 } 108 108 109 109 // remove all other allocated memory. … … 127 127 128 128 LoadParam(root, "rel-coor", this, PNode, setRelCoor) 129 129 .describe("Sets The relative position of the Node to its parent."); 130 130 131 131 LoadParam(root, "abs-coor", this, PNode, setAbsCoor) 132 132 .describe("Sets The absolute Position of the Node."); 133 133 134 134 LoadParam(root, "rel-dir", this, PNode, setRelDir) 135 135 .describe("Sets The relative rotation of the Node to its parent."); 136 136 137 137 LoadParam(root, "abs-dir", this, PNode, setAbsDir) 138 138 .describe("Sets The absolute rotation of the Node."); 139 139 140 140 LoadParam(root, "parent", this, PNode, setParent) 141 141 .describe("the Name of the Parent to set for this PNode"); 142 142 143 143 LoadParam(root, "parent-mode", this, PNode, setParentMode) 144 144 .describe("the mode to connect this node to its parent ()"); 145 145 146 146 // cycling properties … … 150 150 { 151 151 LoadParam_CYCLE(element, "child", this, PNode, addChild) 152 152 .describe("adds a new Child to the current Node."); 153 153 154 154 } … … 245 245 if( likely(this->parentMode & PNODE_MOVEMENT)) 246 246 { 247 247 /* if you have set the absolute coordinates this overrides all other changes */ 248 248 if (likely(this->parent != NULL)) 249 249 this->relCoordinate = absCoord - parent->getAbsCoor (); … … 260 260 261 261 this->bRelCoorChanged = true; 262 // this->absCoordinate = absCoord;262 // this->absCoordinate = absCoord; 263 263 } 264 264 … … 287 287 if( likely(this->parentMode & PNODE_MOVEMENT)) 288 288 { 289 289 /* if you have set the absolute coordinates this overrides all other changes */ 290 290 if (likely(this->parent != NULL)) 291 291 *this->toCoordinate = absCoordSoft - parent->getAbsCoor (); … … 404 404 this->relDirection = absDir / this->parent->getAbsDir(); 405 405 else 406 this->relDirection = absDir;406 this->relDirection = absDir; 407 407 408 408 this->bRelDirChanged = true; … … 437 437 *this->toDirection = absDirSoft / this->parent->getAbsDir(); 438 438 else 439 *this->toDirection = absDirSoft;439 *this->toDirection = absDirSoft; 440 440 441 441 this->bias = bias; … … 477 477 { 478 478 if( likely(child->parent != NULL)) 479 479 child->parent->eraseChild(child); 480 480 if (this->checkIntegrity(child)) 481 481 { … … 485 485 child->parentCoorChanged(); 486 486 487 // if(this->getUniqueID() == NET_UID_UNASSIGNED)488 // {489 // PRINTF(1)("Adding to an UNASSIGNED PNode - looking for next assigned Node\n");490 // PNode* node = this->seekNextAssignedPNode(this);491 // if( node == NULL)492 // PRINTF(1)(" Got NULL - Is this the NULLParent - uid %i\n", this->getUniqueID());493 // else494 // PRINTF(1)(" Found next assigned node: %i\n", node->getUniqueID());495 // }487 // if(this->getUniqueID() == NET_UID_UNASSIGNED) 488 // { 489 // PRINTF(1)("Adding to an UNASSIGNED PNode - looking for next assigned Node\n"); 490 // PNode* node = this->seekNextAssignedPNode(this); 491 // if( node == NULL) 492 // PRINTF(1)(" Got NULL - Is this the NULLParent - uid %i\n", this->getUniqueID()); 493 // else 494 // PRINTF(1)(" Found next assigned node: %i\n", node->getUniqueID()); 495 // } 496 496 } 497 497 else … … 529 529 { 530 530 PNode* childNode = dynamic_cast<PNode*>(ClassList::getObject(childName, CL_PARENT_NODE)); 531 // PRINTF(0)("Adding the Child: %s to: %s\n", childName, this->getName());532 // assert( childNode != NULL );531 // PRINTF(0)("Adding the Child: %s to: %s\n", childName, this->getName()); 532 // assert( childNode != NULL ); 533 533 if (childNode != NULL) 534 534 { … … 547 547 { 548 548 if (child != NULL) 549 child->removeNode();549 child->removeNode(); 550 550 } 551 551 … … 652 652 parentNode->addChild(this); 653 653 654 if (this->parentMode & PNODE_ROTATE_MOVEMENT && this->parent != NULL)655 this->relCoordinate = this->parent->getAbsDir().inverse().apply(tmpV - this->parent->getAbsCoor());656 else657 this->relCoordinate = tmpV - parentNode->getAbsCoor();658 659 this->relDirection = tmpQ / parentNode->getAbsDir();654 if (this->parentMode & PNODE_ROTATE_MOVEMENT && this->parent != NULL) 655 this->relCoordinate = this->parent->getAbsDir().inverse().apply(tmpV - this->parent->getAbsCoor()); 656 else 657 this->relCoordinate = tmpV - parentNode->getAbsCoor(); 658 659 this->relDirection = tmpQ / parentNode->getAbsDir(); 660 660 } 661 661 … … 759 759 if( likely(this->parent != NULL)) 760 760 { 761 // movement for nodes with smoothMove enabled 762 if (unlikely(this->toCoordinate != NULL)) 761 // movement for nodes with smoothMove enabled 762 if (unlikely(this->toCoordinate != NULL)) 763 { 764 float shiftLen = fabsf(dt)*bias; 765 if (shiftLen >= 1.0) 766 shiftLen = 1.0; 767 Vector moveVect = (*this->toCoordinate - this->relCoordinate) * shiftLen; 768 if (likely(moveVect.len() >= PNODE_ITERATION_DELTA)) 763 769 { 764 Vector moveVect = (*this->toCoordinate - this->relCoordinate) *fabsf(dt)*bias; 765 if (likely(moveVect.len() >= PNODE_ITERATION_DELTA)) 766 { 767 this->shiftCoor(moveVect); 768 } 769 else 770 { 771 delete this->toCoordinate; 772 this->toCoordinate = NULL; 773 PRINTF(5)("SmoothMove of %s finished\n", this->getName()); 774 } 770 this->shiftCoor(moveVect); 775 771 } 776 if (unlikely(this->toDirection != NULL))772 else 777 773 { 778 //printf("%s::%s %f\n", this->getClassName(), this->getName(), this->toStep ); 779 Quaternion rotQuat = Quaternion::quatSlerp(this->relDirection,*this->toDirection, .1); 780 if (this->relDirection.distance(rotQuat) > PNODE_ITERATION_DELTA) 781 { 782 this->relDirection = rotQuat; 783 this->bRelDirChanged; 784 } 785 else 786 { 787 delete this->toDirection; 788 this->toDirection = NULL; 789 PRINTF(5)("SmoothRotate of %s finished\n", this->getName()); 790 this->bRelDirChanged; 791 } 774 delete this->toCoordinate; 775 this->toCoordinate = NULL; 776 PRINTF(5)("SmoothMove of %s finished\n", this->getName()); 792 777 } 793 794 // MAIN UPDATE /////////////////////////////////////795 this->lastAbsCoordinate = this->absCoordinate;796 797 PRINTF(5)("PNode::update - '%s::%s' - (%f, %f, %f)\n", this->getClassName(), this->getName(),798 this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);799 800 801 if (this->bRelDirChanged && this->parentMode & PNODE_LOCAL_ROTATE)778 } 779 if (unlikely(this->toDirection != NULL)) 780 { 781 float shiftLen = fabsf(dt)*bias; 782 if (shiftLen >= 1.0) 783 shiftLen = 1.0; 784 //printf("%s::%s %f\n", this->getClassName(), this->getName(), this->toStep ); 785 Quaternion rotQuat = Quaternion::quatSlerp(this->relDirection,*this->toDirection, shiftLen); 786 if (this->relDirection.distance(rotQuat) > PNODE_ITERATION_DELTA) 802 787 { 803 /* update the current absDirection - remember * means rotation around sth.*/ 804 this->prevRelCoordinate = this->relCoordinate; 805 this->absDirection = parent->getAbsDir() * this->relDirection; 788 this->relDirection = rotQuat; 789 this->bRelDirChanged; 806 790 } 807 808 if(likely(this->bRelCoorChanged && this->parentMode & PNODE_MOVEMENT)) 791 else 809 792 { 793 delete this->toDirection; 794 this->toDirection = NULL; 795 PRINTF(5)("SmoothRotate of %s finished\n", this->getName()); 796 this->bRelDirChanged; 797 } 798 } 799 800 // MAIN UPDATE ///////////////////////////////////// 801 this->lastAbsCoordinate = this->absCoordinate; 802 803 PRINTF(5)("PNode::update - '%s::%s' - (%f, %f, %f)\n", this->getClassName(), this->getName(), 804 this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z); 805 806 807 if(this->bRelDirChanged && this->parentMode & PNODE_LOCAL_ROTATE ) 808 { 809 /* update the current absDirection - remember * means rotation around sth.*/ 810 this->prevRelCoordinate = this->relCoordinate; 811 this->absDirection = parent->getAbsDir() * this->relDirection; 812 } 813 814 if(likely(this->bRelCoorChanged && this->parentMode & PNODE_MOVEMENT)) 815 { 810 816 /* update the current absCoordinate */ 811 this->prevRelCoordinate = this->relCoordinate; 812 this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate; 813 } 814 else if( this->parentMode & PNODE_ROTATE_MOVEMENT && (this->bRelCoorChanged || this->bRelDirChanged)) 815 { 816 /* update the current absCoordinate */ 817 this->prevRelCoordinate = this->relCoordinate; 818 this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate); 819 } 820 ///////////////////////////////////////////////// 817 this->prevRelCoordinate = this->relCoordinate; 818 this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate; 821 819 } 822 823 else // Nodes without a Parent are handled faster :: MOST LIKELY THE NULLPARENT 820 else if( this->parentMode & PNODE_ROTATE_MOVEMENT && (this->bRelCoorChanged || this->bRelDirChanged)) 821 { 822 /* update the current absCoordinate */ 823 this->prevRelCoordinate = this->relCoordinate; 824 this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate); 825 } 826 ///////////////////////////////////////////////// 827 } 828 829 else // Nodes without a Parent are handled faster :: MOST LIKELY THE NULLPARENT 824 830 { 825 831 PRINTF(4)("update ParentLess Node (%s::%s) - (%f, %f, %f)\n", this->getClassName(), this->getName(), 826 832 this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z); 827 if (this->bRelCoorChanged) 828 { 829 this->prevRelCoordinate = this->relCoordinate; 830 this->absCoordinate = this->relCoordinate; 831 } 832 if (this->bRelDirChanged) 833 { 834 this->prevRelDirection = this->relDirection; 835 this->absDirection = this->getAbsDir () * this->relDirection; 836 } 833 if (this->bRelCoorChanged) 834 { 835 this->prevRelCoordinate = this->relCoordinate; 836 this->absCoordinate = this->relCoordinate; 837 } 838 if (this->bRelDirChanged) 839 { 840 this->prevRelDirection = this->relDirection; 841 this->absDirection = this->getAbsDir () * this->relDirection; 837 842 } 838 843 } 839 840 if(!this->children.empty() && (this->bActive || this->parentMode & PNODE_UPDATE_CHILDREN_IF_INACTIVE )) 844 } 845 846 if(!this->children.empty() && (this->bActive || this->parentMode & PNODE_UPDATE_CHILDREN_IF_INACTIVE )) 847 { 848 list<PNode*>::iterator child; 849 for (child = this->children.begin(); child != this->children.end(); child ++) 841 850 { 842 list<PNode*>::iterator child; 843 for (child = this->children.begin(); child != this->children.end(); child ++) 844 { 845 /* if this node has changed, make sure, that all children are updated also */ 846 if( likely(this->bRelCoorChanged)) 847 (*child)->parentCoorChanged (); 848 if( likely(this->bRelDirChanged)) 849 (*child)->parentDirChanged (); 850 851 (*child)->updateNode(dt); 852 } 851 /* if this node has changed, make sure, that all children are updated also */ 852 if( likely(this->bRelCoorChanged)) 853 (*child)->parentCoorChanged (); 854 if( likely(this->bRelDirChanged)) 855 (*child)->parentDirChanged (); 856 857 (*child)->updateNode(dt); 853 858 } 854 this->velocity = (this->absCoordinate - this->lastAbsCoordinate) / dt; 855 this->bRelCoorChanged = false; 856 this->bRelDirChanged = false; 859 } 860 this->velocity = (this->absCoordinate - this->lastAbsCoordinate) / dt; 861 this->bRelCoorChanged = false; 862 this->bRelDirChanged = false; 857 863 } 858 864 … … 949 955 this->getAbsCoor ().y, 950 956 this->getAbsCoor ().z); 951 // this->getAbsDir ().matrix (matrix);957 // this->getAbsDir ().matrix (matrix); 952 958 953 959 /* rotate */ … … 993 999 { 994 1000 // drawing the Dependency graph 995 if (this != PNode::getNullParent())1001 if (this != PNode::getNullParent()) 996 1002 { 997 glBegin(GL_LINES);998 glColor3f(color.x, color.y, color.z);999 glVertex3f(this->getAbsCoor ().x,1000 this->getAbsCoor ().y,1001 this->getAbsCoor ().z);1003 glBegin(GL_LINES); 1004 glColor3f(color.x, color.y, color.z); 1005 glVertex3f(this->getAbsCoor ().x, 1006 this->getAbsCoor ().y, 1007 this->getAbsCoor ().z); 1002 1008 glColor3f(childColor.x, childColor.y, childColor.z); 1003 1009 glVertex3f((*child)->getAbsCoor ().x, … … 1074 1080 SYNCHELP_READ_FKT( BaseObject::writeState, NWT_PN_BO_WRITESTATE ); 1075 1081 1076 // char * parentName = NULL;1077 // SYNCHELP_READ_STRINGM( parentName );1078 //1079 // if ( strcmp(parentName, "")==0 )1080 // {1081 // setParent( (char*)NULL );1082 // }1083 // else1084 // {1085 // setParent( parentName );1086 // }1087 //1088 // delete[] parentName;1082 // char * parentName = NULL; 1083 // SYNCHELP_READ_STRINGM( parentName ); 1084 // 1085 // if ( strcmp(parentName, "")==0 ) 1086 // { 1087 // setParent( (char*)NULL ); 1088 // } 1089 // else 1090 // { 1091 // setParent( parentName ); 1092 // } 1093 // 1094 // delete[] parentName; 1089 1095 1090 1096 int parentMode; … … 1106 1112 this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) ); 1107 1113 1108 // int n;1109 // char * childName;1110 //1111 // PRINTF(0)("JKLO %d %d %d %d\n", data[__synchelp_read_i], data[__synchelp_read_i+1], data[__synchelp_read_i+2], data[__synchelp_read_i+3]);1112 // SYNCHELP_READ_INT( n );1113 // PRINTF(0)("read %s:n=%d\n", this->getName(), n);1114 //1115 // for (int i = 0; i<n; i++)1116 // {1117 // SYNCHELP_READ_STRINGM( childName );1118 // PRINTF(0)("RCVD CHILD = %s\n", childName);1119 // addChild( childName );1120 // delete childName;1121 // childName = NULL;1122 // }1114 // int n; 1115 // char * childName; 1116 // 1117 // PRINTF(0)("JKLO %d %d %d %d\n", data[__synchelp_read_i], data[__synchelp_read_i+1], data[__synchelp_read_i+2], data[__synchelp_read_i+3]); 1118 // SYNCHELP_READ_INT( n ); 1119 // PRINTF(0)("read %s:n=%d\n", this->getName(), n); 1120 // 1121 // for (int i = 0; i<n; i++) 1122 // { 1123 // SYNCHELP_READ_STRINGM( childName ); 1124 // PRINTF(0)("RCVD CHILD = %s\n", childName); 1125 // addChild( childName ); 1126 // delete childName; 1127 // childName = NULL; 1128 // } 1123 1129 1124 1130 return SYNCHELP_READ_N; … … 1137 1143 SYNCHELP_WRITE_FKT( BaseObject::readState, NWT_PN_BO_WRITESTATE ); 1138 1144 1139 // if ( this->parent )1140 // {1141 // SYNCHELP_WRITE_STRING( parent->getName() );1142 // }1143 // else1144 // {1145 // SYNCHELP_WRITE_STRING( "" );1146 // }1145 // if ( this->parent ) 1146 // { 1147 // SYNCHELP_WRITE_STRING( parent->getName() ); 1148 // } 1149 // else 1150 // { 1151 // SYNCHELP_WRITE_STRING( "" ); 1152 // } 1147 1153 1148 1154 SYNCHELP_WRITE_INT( this->parentMode, NWT_PN_PARENTMODE ); … … 1157 1163 SYNCHELP_WRITE_FLOAT( this->relDirection.v.z, NWT_PN_ROTZ ); 1158 1164 1159 // int n = children.size();1160 // //check if camera is in children1161 // for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)1162 // {1163 // if ( (*it)->isA(CL_CAMERA) )1164 // n--;1165 // }1166 // PRINTF(0)("write %s:n=%d\n", this->getName(), n);1167 // SYNCHELP_WRITE_INT( n );1168 // PRINTF(0)("ASDF %d %d %d %d\n", data[__synchelp_write_i-4], data[__synchelp_write_i-3], data[__synchelp_write_i-2], data[__synchelp_write_i-1]);1169 //1170 //1171 // for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++)1172 // {1173 // //dont add camera because there is only one camera attached to local player1174 // if ( !(*it)->isA(CL_CAMERA) )1175 // {1176 // PRINTF(0)("SENDING CHILD: %s\n", (*it)->getName());1177 // SYNCHELP_WRITE_STRING( (*it)->getName() );1178 // }1179 // }1165 // int n = children.size(); 1166 // //check if camera is in children 1167 // for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++) 1168 // { 1169 // if ( (*it)->isA(CL_CAMERA) ) 1170 // n--; 1171 // } 1172 // PRINTF(0)("write %s:n=%d\n", this->getName(), n); 1173 // SYNCHELP_WRITE_INT( n ); 1174 // PRINTF(0)("ASDF %d %d %d %d\n", data[__synchelp_write_i-4], data[__synchelp_write_i-3], data[__synchelp_write_i-2], data[__synchelp_write_i-1]); 1175 // 1176 // 1177 // for (std::list<PNode*>::const_iterator it = children.begin(); it!=children.end(); it++) 1178 // { 1179 // //dont add camera because there is only one camera attached to local player 1180 // if ( !(*it)->isA(CL_CAMERA) ) 1181 // { 1182 // PRINTF(0)("SENDING CHILD: %s\n", (*it)->getName()); 1183 // SYNCHELP_WRITE_STRING( (*it)->getName() ); 1184 // } 1185 // } 1180 1186 1181 1187 return SYNCHELP_WRITE_N;
Note: See TracChangeset
for help on using the changeset viewer.