Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7008 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Feb 3, 2006, 11:44:59 AM (19 years ago)
Author:
bensch
Message:

trunk: saved pnode again

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/coord/p_node.cc

    r7003 r7008  
    4242 */
    4343PNode::PNode (PNode* parent, long nodeFlags)
    44   : Synchronizeable(), BaseObject()
     44    : Synchronizeable(), BaseObject()
    4545{
    4646  this->setClassID(CL_PARENT_NODE, "PNode");
     
    8888      deleteNode = tmp;
    8989      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());
    9191      if ((this->parentMode & PNODE_PROHIBIT_CHILD_DELETE) ||
    9292          ((*deleteNode)->parentMode & PNODE_PROHIBIT_DELETE_WITH_PARENT))
     
    102102
    103103  if (this->parent != NULL)
    104    {
    105      this->parent->eraseChild(this);
    106      this->parent = NULL;
    107    }
     104  {
     105    this->parent->eraseChild(this);
     106    this->parent = NULL;
     107  }
    108108
    109109  // remove all other allocated memory.
     
    127127
    128128  LoadParam(root, "rel-coor", this, PNode, setRelCoor)
    129       .describe("Sets The relative position of the Node to its parent.");
     129  .describe("Sets The relative position of the Node to its parent.");
    130130
    131131  LoadParam(root, "abs-coor", this, PNode, setAbsCoor)
    132       .describe("Sets The absolute Position of the Node.");
     132  .describe("Sets The absolute Position of the Node.");
    133133
    134134  LoadParam(root, "rel-dir", this, PNode, setRelDir)
    135       .describe("Sets The relative rotation of the Node to its parent.");
     135  .describe("Sets The relative rotation of the Node to its parent.");
    136136
    137137  LoadParam(root, "abs-dir", this, PNode, setAbsDir)
    138       .describe("Sets The absolute rotation of the Node.");
     138  .describe("Sets The absolute rotation of the Node.");
    139139
    140140  LoadParam(root, "parent", this, PNode, setParent)
    141       .describe("the Name of the Parent to set for this PNode");
     141  .describe("the Name of the Parent to set for this PNode");
    142142
    143143  LoadParam(root, "parent-mode", this, PNode, setParentMode)
    144       .describe("the mode to connect this node to its parent ()");
     144  .describe("the mode to connect this node to its parent ()");
    145145
    146146  // cycling properties
     
    150150    {
    151151      LoadParam_CYCLE(element, "child", this, PNode, addChild)
    152           .describe("adds a new Child to the current Node.");
     152      .describe("adds a new Child to the current Node.");
    153153
    154154    }
     
    245245  if( likely(this->parentMode & PNODE_MOVEMENT))
    246246  {
    247       /* if you have set the absolute coordinates this overrides all other changes */
     247    /* if you have set the absolute coordinates this overrides all other changes */
    248248    if (likely(this->parent != NULL))
    249249      this->relCoordinate = absCoord - parent->getAbsCoor ();
     
    260260
    261261  this->bRelCoorChanged = true;
    262 //  this->absCoordinate = absCoord;
     262  //  this->absCoordinate = absCoord;
    263263}
    264264
     
    287287  if( likely(this->parentMode & PNODE_MOVEMENT))
    288288  {
    289       /* if you have set the absolute coordinates this overrides all other changes */
     289    /* if you have set the absolute coordinates this overrides all other changes */
    290290    if (likely(this->parent != NULL))
    291291      *this->toCoordinate = absCoordSoft - parent->getAbsCoor ();
     
    404404    this->relDirection = absDir / this->parent->getAbsDir();
    405405  else
    406    this->relDirection = absDir;
     406    this->relDirection = absDir;
    407407
    408408  this->bRelDirChanged = true;
     
    437437    *this->toDirection = absDirSoft / this->parent->getAbsDir();
    438438  else
    439    *this->toDirection = absDirSoft;
     439    *this->toDirection = absDirSoft;
    440440
    441441  this->bias = bias;
     
    477477{
    478478  if( likely(child->parent != NULL))
    479       child->parent->eraseChild(child);
     479    child->parent->eraseChild(child);
    480480  if (this->checkIntegrity(child))
    481481  {
     
    485485    child->parentCoorChanged();
    486486
    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 //     }
     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    //     }
    496496  }
    497497  else
     
    529529{
    530530  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 );
    533533  if (childNode != NULL)
    534534  {
     
    547547{
    548548  if (child != NULL)
    549    child->removeNode();
     549    child->removeNode();
    550550}
    551551
     
    652652  parentNode->addChild(this);
    653653
    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();
     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();
    660660}
    661661
     
    759759    if( likely(this->parent != NULL))
    760760    {
    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))
    763769        {
    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);
    775771        }
    776         if (unlikely(this->toDirection != NULL))
     772        else
    777773        {
    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());
    792777        }
    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)
    802787        {
    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;
    806790        }
    807 
    808         if(likely(this->bRelCoorChanged && this->parentMode & PNODE_MOVEMENT))
     791        else
    809792        {
     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      {
    810816        /* 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;
    821819      }
    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
    824830    {
    825831      PRINTF(4)("update ParentLess Node (%s::%s) - (%f, %f, %f)\n", this->getClassName(), this->getName(),
    826832                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;
    837842      }
    838843    }
    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 ++)
    841850    {
    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);
    853858    }
    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;
    857863}
    858864
     
    949955                this->getAbsCoor ().y,
    950956                this->getAbsCoor ().z);
    951 //  this->getAbsDir ().matrix (matrix);
     957  //  this->getAbsDir ().matrix (matrix);
    952958
    953959  /* rotate */
     
    993999    {
    9941000      // drawing the Dependency graph
    995      if (this != PNode::getNullParent())
     1001      if (this != PNode::getNullParent())
    9961002      {
    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);
    10021008        glColor3f(childColor.x, childColor.y, childColor.z);
    10031009        glVertex3f((*child)->getAbsCoor ().x,
     
    10741080  SYNCHELP_READ_FKT( BaseObject::writeState, NWT_PN_BO_WRITESTATE );
    10751081
    1076 //   char * parentName = NULL;
    1077 //   SYNCHELP_READ_STRINGM( parentName );
    1078 //
    1079 //   if ( strcmp(parentName, "")==0 )
    1080 //   {
    1081 //     setParent( (char*)NULL );
    1082 //   }
    1083 //   else
    1084 //   {
    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;
    10891095
    10901096  int parentMode;
     
    11061112  this->setRelDir( Quaternion( Vector(f2, f3, f4), f1 ) );
    11071113
    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  //   }
    11231129
    11241130  return SYNCHELP_READ_N;
     
    11371143  SYNCHELP_WRITE_FKT( BaseObject::readState, NWT_PN_BO_WRITESTATE );
    11381144
    1139 //   if ( this->parent )
    1140 //   {
    1141 //     SYNCHELP_WRITE_STRING( parent->getName() );
    1142 //   }
    1143 //   else
    1144 //   {
    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  //   }
    11471153
    11481154  SYNCHELP_WRITE_INT( this->parentMode, NWT_PN_PARENTMODE );
     
    11571163  SYNCHELP_WRITE_FLOAT( this->relDirection.v.z, NWT_PN_ROTZ );
    11581164
    1159 //   int n = children.size();
    1160 //   //check if camera is in children
    1161 //   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 player
    1174 //     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  //   }
    11801186
    11811187  return SYNCHELP_WRITE_N;
Note: See TracChangeset for help on using the changeset viewer.