Example #1
0
void Semester::showLine(wxDC& dc, Node *snode, Node *par){
  Node *temp = snode,
       *temp2 = par;
  std::vector<int> pos;
  bool dragtemp;
  int y;
  while(temp != NULL){
    temp2 = temp;
    if(dragging && !drageffect){
      pos = checkDragEffect(temp);
      if(pos.size() != 0){
        dc.SetBrush(wxBrush(wxColour("#008888"), wxBRUSHSTYLE_TRANSPARENT));
        dc.SetPen(wxPen(wxColour("#000000"), 2));
        dc.DrawRectangle(pos[0], pos[1], 240, 60);
      }
    }
    switch(temp->GetNodeType()){
      case NODE_NORMAL:
        y = (drageffect)?temp->GetY()+70:temp->GetY();
        dc.DrawBitmap(temp->GetCourse()->bitmap, temp->GetX(), y);
        temp = temp->GetChild();
        break;
      case NODE_SPLIT:
        dragtemp = drageffect;
        showLine(dc, temp->GetChild(1), temp);
        drageffect = dragtemp;
        temp = temp->GetChild();
        break;
      case NODE_CHOICE:
      default: break;
    }
  }
  if(dragging && !drageffect){
    if(temp2 != NULL && temp2 == par){
      pos = checkUnder(temp2->GetX()+125, temp2->GetY() - 70);
    }
    else if(temp2 != NULL && temp2->GetNodeType() == NODE_SPLIT){
      pos = checkUnder(temp2->GetX()-125, temp2->GetY() - 70);
    }
    else
      pos = checkUnder(temp2);
    if(pos.size() != 0){
      dc.SetBrush(wxBrush(wxColour("#008888"), wxBRUSHSTYLE_TRANSPARENT));
      dc.SetPen(wxPen(wxColour("#000000"), 2));
      dc.DrawRectangle(pos[0], pos[1] + 70, 240, 60);
    }
  }
  else
    drageffect = false;
}//showLine
Example #2
0
void Semester::determineWidth(Node *node){
  if(node == root)
    total_width = 240;
  Node *temp = node;
  while(temp != NULL){
    switch(temp->GetNodeType()){
      case NODE_SPLIT:
        determineWidth(temp->GetChild(1));
        total_width += 250;
      default:
        temp = temp->GetChild();
        break;
    }
  }
}
Example #3
0
bool Semester::dropLine(Node *snode, Node *par, Course *course){
  Node *temp = snode,
       *temp2 = par;
  std::vector<int> pos;
  bool dragtemp;
  while(temp != NULL){
    if(!drageffect){
      pos = checkDragEffect(temp);
      if(pos.size() != 0){
        dropUpdate(temp2, temp, course);
        drageffect = false;
        return true;
      }
    }
    temp2 = temp;
    switch(temp->GetNodeType()){
      case NODE_NORMAL:
        temp = temp->GetChild();
        break;
      case NODE_SPLIT:
        dragtemp = drageffect;
        if(dropLine(temp->GetChild(1), temp, course))
          return true;
        drageffect = dragtemp;
        temp = temp->GetChild();
        break;
      case NODE_CHOICE:
      default: break;
    }
  }
  if(!drageffect){
    if(temp2 != NULL && temp2 == par){
      pos = checkUnder(temp2->GetX()+125, temp2->GetY() - 70);
    }
    else if(temp2 != NULL && temp2->GetNodeType() == NODE_SPLIT){
      pos = checkUnder(temp2->GetX()-125, temp2->GetY() - 70);
    }
    else
      pos = checkUnder(temp2);
    if(pos.size() != 0){
      dropUpdate(temp2, temp, course);
      return true;
    }
  }
  else
    drageffect = false;
  return false;
}
Example #4
0
Node* Node::InsertParentWith(Node* sibling)
{
    Node* prevParent = this->parent;

    if (!prevParent)
        return NULL;

    int sindex = -1;
    for (int i = 0; i < prevParent->GetNbChildren(); i++)
    {
        if (prevParent->GetChild(i) == sibling)
        {
            sindex = i;
            break;
        }
    }

    if (sindex == -1)
        return NULL;

    Node* newParent = prevParent->AddChild();

    prevParent->RemoveChild(this);
    prevParent->RemoveChild(sibling);

    newParent->AddSubTree(this);
    newParent->AddSubTree(sibling);

    return newParent;

}
//----------------------------------------------------------------------------
void ReflectionsAndShadows::CopyNormalToTCoord1 (Object* object)
{
    TriMesh* mesh = DynamicCast<TriMesh>(object);
    if (mesh)
    {
        VertexBufferAccessor vba(mesh);
        for (int i = 0; i < vba.GetNumVertices(); ++i)
        {
            vba.TCoord<Vector3f>(1, i) = vba.Normal<Vector3f>(i);
        }
        mRenderer->Update(mesh->GetVertexBuffer());
    }

    Node* node = DynamicCast<Node>(object);
    if (node)
    {
        for (int i = 0; i < node->GetNumChildren(); ++i)
        {
            Spatial* child = node->GetChild(i);
            if (child)
            {
                CopyNormalToTCoord1(child);
            }
        }
    }
}
Example #6
0
bool TraceNode(const Ray &r, HitInfo &hInfo,const Node &node)
{
    Ray ray;
    ray = node.ToNodeCoords(r);
    const Object* obj = node.GetObject();
    bool objHitTest = false;
    
    if (node.GetNumChild() > 0)
    {
        
        for (int i = 0; i < node.GetNumChild(); i++)
        {
            bool childHit = false;
            const Node &childNode = *node.GetChild(i);
            childHit = TraceNode(ray, hInfo, childNode);
            if(childHit)
            {
                objHitTest = true;
            }
        }
    }
    if(obj)
    {
        if(obj->IntersectRay(ray, hInfo)){
            objHitTest=true;
            hInfo.node = &node;
        }
        if(objHitTest){
            //hInfo.node = &node;
            //node.FromNodeCoords(hInfo);
        }
    }
    
    return objHitTest;
}
Example #7
0
bool Trie::isWord(string word)
{
	// entered nothing forget it.
	if(word.length() == 0)
		return false;

	Node* CurrentNode = root;
	// Go down the tree to find the word/
	for(unsigned int i = 0; i < word.length(); i++)
	{
		// Grab child node.
		Node* NextNode = CurrentNode->GetChild(word[i]);
		// If the next node is null the word does not exist.
		if(NextNode != NULL)
			CurrentNode = NextNode;
		else
			return false;		
	}
	
	// Now we are at the end check if it is a word in the dictionary.
	if(CurrentNode->isEndOfWord() == true)
		return true;
	else
		return false;
	
	return false;
}
Example #8
0
//----------------------------------------------------------------------------
void Renderer::ReleaseTextures (Spatial* pkScene)
{
    int i;

    // release all textures attached to this object
    Effect* pkEffect = pkScene->GetEffect();
    if (pkEffect)
    {
        for (i = 0; i < pkEffect->Textures.GetQuantity(); i++)
        {
            Texture* pkTexture = pkEffect->Textures[i];
            if (pkTexture)
            {
                ReleaseTexture(pkTexture);
            }
        }
    }

    // recurse the subtree of this object and release other textures
    Node* pkNode = DynamicCast<Node>(pkScene);
    if (pkNode)
    {
        for (i = 0; i < pkNode->GetQuantity(); i++)
        {
            Spatial* pkChild = pkNode->GetChild(i);
            if (pkChild)
            {
                ReleaseTextures(pkChild);
            }
        }
    }
}
Example #9
0
void Trie::addWord(string word)
{
	Node* CurrentNode = root;
	
	// Check if the string is empty if so return.
	if(word.length() == 0)
		return;
	
	// Loop through the word
	for(unsigned int i = 0; i < word.length(); i++)
	{
		// Grab the child node associated with the character from the current node.
		Node* Child = CurrentNode->GetChild(word[i]);
		
		// If not null the child node is the current node.
		if(Child != NULL)
		{
			CurrentNode = Child;
		}
		else // If the child node is empty we add a new child node to the current.
		{
			Node* NewNode = new Node();
			// Set the new nodes value.
			NewNode->SetValue(word[i]);
			NewNode->SetParent(CurrentNode);
			CurrentNode->addChildNode(NewNode);
			CurrentNode = NewNode;
		}
		
		// If we are at the end of the word set the word mark to true.
		if(word.length() - 1 == i)
			CurrentNode->SetMarkEnd();	
	}
}
Example #10
0
void WizardSkill0::HandleNodeRemoved(StringHash eventType, VariantMap& eventData)
{
	using namespace NodeRemoved;

	Node* nohd = static_cast<Node*>(eventData[P_NODE].GetPtr());

	if (nohd->GetName() != "meteor")
	{
		return;
	}

	Node* fire = nohd->GetChild("fire");

	if (!fire)
	{
		return;
	}

	ParticleEmitter* pe = fire->GetComponent<ParticleEmitter>();

	if (!pe)
	{
		return;
	}

	pe->SetEnabled(false);

	nohd->RemoveAllChildren();
}
Example #11
0
pair<Node*, unordered_map<Node*, Node*> > PolySolverNAD::PolytomizeNAD(Node* nadNode, Node* speciesTree, unordered_map<Node*, Node*> lcaMapping)
{
    set<Node*> leftSubtrees, rightSubtrees;
    Node* s = lcaMapping[nadNode];

    //TODO : there should be a way not to iterate uselessly into a taken subtree (preorder traversal that we stop)
    TreeIterator* it = nadNode->GetPostOrderIterator();
    while (Node* n = it->next())
    {
        if (n != nadNode)
        {
            //here we maximal subtree either on the left or right
            if (lcaMapping[n] != s && lcaMapping[n->GetParent()] == s)
            {
                if (lcaMapping[n]->HasAncestor(s->GetChild(0)))
                {
                    leftSubtrees.insert(n);
                }
                else    //if (lcaMapping[n]->HasAncestor(s->GetChild(1))) should be the only possibility here
                {
                    rightSubtrees.insert(n);
                }
            }
        }
    }
    nadNode->CloseIterator(it);


    Node* newShizzle = new Node(false);
    Node* left = newShizzle->AddChild();
    Node* right = newShizzle->AddChild();
    unordered_map<Node*, Node*> newMapping;

    for (set<Node*>::iterator itLeft = leftSubtrees.begin(); itLeft != leftSubtrees.end(); itLeft++)
    {
        Node* copy = GeneSpeciesTreeUtil::Instance()->CopyTreeWithNodeMapping((*itLeft), lcaMapping, newMapping);
        left->AddSubTree(copy);
    }

    for (set<Node*>::iterator itRight = rightSubtrees.begin(); itRight != rightSubtrees.end(); itRight++)
    {
        Node* copy = GeneSpeciesTreeUtil::Instance()->CopyTreeWithNodeMapping((*itRight), lcaMapping, newMapping);
        right->AddSubTree(copy);
    }

    newMapping[newShizzle] = s;
    if (left->GetNbChildren() > 1)
    {
        newMapping[left] = GeneSpeciesTreeUtil::Instance()->GetSingleNodeLCAMapping(left, speciesTree, newMapping);
    }
    if (right->GetNbChildren() > 1)
    {
        newMapping[right] = GeneSpeciesTreeUtil::Instance()->GetSingleNodeLCAMapping(right, speciesTree, newMapping);
    }

    newShizzle->DeleteSingleChildDescendants();

    return make_pair(newShizzle, newMapping);
}
Example #12
0
bool TraceNode(const Cone &r, HitInfo &hInfo,const Node &node)
{
//    cout<<"Tracenode"<<endl;
    Cone ray = r;
    float timeIns;
    if(node.IsInMotion()){
        if(hInfo.timeInstance == 0.0){
            timeIns = (rand()/(float)RAND_MAX) * camera.shutter;
            ray = node.ToNodeCoords(r, timeIns);
        }
    }
    else{    ray = node.ToNodeCoords(r); }
//    cout<<"...To node coords"<<endl;
    const Object* obj = node.GetObject();
    bool objHitTest = false;
    bool childHit = false;
    
    if(obj)
    {
//        if(!hInfo.front){ hitSide = HIT_FRONT_AND_BACK; } /* Back face hit for refraction */
        
        if(obj->IntersectRay(ray, hInfo)){
            
            objHitTest=true;
            hInfo.node = &node;
            if(hInfo.node->IsInMotion()) hInfo.timeInstance = timeIns;
            
        }
    }
    if (node.GetNumChild() > 0)
    {

        for (int i = 0; i < node.GetNumChild(); i++)
        {
            
//            cout<<"Child "<<i<<endl;
            Cone r = ray;
            const Node &childNode = *node.GetChild(i);
            if(TraceNode(r, hInfo, childNode)){
                    childHit = true;
            }
            
//            cout<<"Child "<<i<<" out"<<endl;
        }
        if(childHit)
        {
            //node.FromNodeCoords(hInfo);
            objHitTest = true;
        }
    }
    
    
    if(objHitTest){
        //hInfo.node = &node;
//        cout<<"..From node coords - child hit not parent"<<endl;
       node.FromNodeCoords(hInfo);
    }
    return objHitTest;
}
Example #13
0
void Semester::getNodes(std::vector<Node*> &nodes, Node *node){
  Node *temp = node;
  while(temp != NULL){
    nodes.push_back(temp);
    switch(temp->GetNodeType()){
      case NODE_NORMAL:
        temp = temp->GetChild();
        break;
      case NODE_SPLIT:
        getNodes(nodes, temp->GetChild(1));
        temp = temp->GetChild(0);
        break;
      case NODE_CHOICE:
      default: break;
    }
  }
}
Example #14
0
void Semester::determineHeight(){
  total_height = y_start;
  Node *temp = root;
  while(temp != NULL){
    total_height += 70;
    temp = temp->GetChild();
  }
}
//----------------------------------------------------------------------------
PX2::Movable *SceneNodeCtrl::GetCurrentCtrlZ()
{
	int index = mCtrlsGroup->GetActiveChild();
	Node *node = DynamicCast<Node>(mCtrlsGroup->GetChild(index));

	if (!node)
		return 0;

	return node->GetChild(2);
}
Example #16
0
bool TraceNode(const Ray &r, HitInfo &hInfo,const Node &node)
{
//    cout<<"Tracenode"<<endl;
    Ray ray = r;
    ray = node.ToNodeCoords(r);
//    cout<<"...To node coords"<<endl;
    const Object* obj = node.GetObject();
    bool objHitTest = false;
    bool childHit = false;
    
    if(obj)
    {
//        if(!hInfo.front){ hitSide = HIT_FRONT_AND_BACK; } /* Back face hit for refraction */
        
        if(obj->IntersectRay(ray, hInfo)){
            
            objHitTest=true;
            hInfo.node = &node;
        }
    }
    if (node.GetNumChild() > 0)
    {

        for (int i = 0; i < node.GetNumChild(); i++)
        {
            
//            cout<<"Child "<<i<<endl;
            Ray r = ray;
            const Node &childNode = *node.GetChild(i);
            if(TraceNode(r, hInfo, childNode)){
                    childHit = true;
            }
            
//            cout<<"Child "<<i<<" out"<<endl;
        }
        if(childHit)
        {
            //node.FromNodeCoords(hInfo);
            objHitTest = true;
        }
    }
    
    
    if(objHitTest){
        //hInfo.node = &node;
//        cout<<"..From node coords - child hit not parent"<<endl;
       node.FromNodeCoords(hInfo);
    }
    return objHitTest;
}
Example #17
0
void Semester::setLine(unsigned int sx, unsigned int sy, Node *snode, unsigned int x_start){
  Node *temp = snode;
  unsigned int x = sx,
               y = sy;
  while(temp != NULL){
    temp->SetPosition(x, y);
    switch(temp->GetNodeType()){
      case NODE_NORMAL:
        y += 70;
        temp = temp->GetChild();
        break;
      case NODE_SPLIT:
        setLine(determineStartX(temp->GetChild(1), x + 125), y, temp->GetChild(1), x + 125);
        temp = temp->GetChild();
        x = determineStartX(temp, x_start);
        break;
      case NODE_CHOICE:
      default:
        temp = temp->GetChild();
        break;
    }
  }
}//setLine
//----------------------------------------------------------------------------
PX2::Movable *SceneNodeCtrl::GetCurrentCtrlXYZ()
{
	if (mCtrlType == CT_SCALE)
	{
		int index = mCtrlsGroup->GetActiveChild();
		Node *node = DynamicCast<Node>(mCtrlsGroup->GetChild(index));

		if (node)
		{
			return node->GetChild(3);
		}

	}

	return 0;
}
Example #19
0
unsigned int Semester::determineStartX(Node *snode, unsigned int s){
  unsigned int x_start = s;
  Node *temp = snode;
  bool split = false;
  while(temp != NULL){
    if(temp->GetNodeType() == NODE_SPLIT){
      if(split)
        x_start += 250;
      else{
        split = true;
        x_start += 125;
      }
    }
    temp = temp->GetChild();
  }
  return x_start;
}
Example #20
0
//----------------------------------------------------------------------------
void Node::TravelExecute(Movable *mov, TravelExecuteFun fun, Any *data)
{
	(*fun)(mov, data);

	Node *node = DynamicCast<Node>(mov);
	if (node)
	{
		for (int i = 0; i < node->GetNumChildren(); i++)
		{
			Movable *child = node->GetChild(i);

			if (child)
			{
				TravelExecute(child, fun, data);
			}
		}
	}
}
Example #21
0
void CharacterDemo::HandlePostUpdate(StringHash eventType, VariantMap& eventData)
{
    if (!character_)
        return;
    
    Node* characterNode = character_->GetNode();
    
    // Get camera lookat dir from character yaw + pitch
    Quaternion rot = characterNode->GetRotation();
    Quaternion dir = rot * Quaternion(character_->controls_.pitch_, Vector3::RIGHT);
    
    // Turn head to camera pitch, but limit to avoid unnatural animation
    Node* headNode = characterNode->GetChild("Bip01_Head", true);
    float limitPitch = Clamp(character_->controls_.pitch_, -45.0f, 45.0f);
    Quaternion headDir = rot * Quaternion(limitPitch, Vector3(1.0f, 0.0f, 0.0f));
    // This could be expanded to look at an arbitrary target, now just look at a point in front
    Vector3 headWorldTarget = headNode->GetWorldPosition() + headDir * Vector3(0.0f, 0.0f, 1.0f);
    headNode->LookAt(headWorldTarget, Vector3(0.0f, 1.0f, 0.0f));
    // Correct head orientation because LookAt assumes Z = forward, but the bone has been authored differently (Y = forward)
    headNode->Rotate(Quaternion(0.0f, 90.0f, 90.0f));

    if (firstPerson_)
    {
        cameraNode_->SetPosition(headNode->GetWorldPosition() + rot * Vector3(0.0f, 0.15f, 0.2f));
        cameraNode_->SetRotation(dir);
    }
    else
    {
        // Third person camera: position behind the character
        Vector3 aimPoint = characterNode->GetPosition() + rot * Vector3(0.0f, 1.7f, 0.0f);
        
        // Collide camera ray with static physics objects (layer bitmask 2) to ensure we see the character properly
        Vector3 rayDir = dir * Vector3::BACK;
        float rayDistance = CAMERA_MAX_DIST;
        PhysicsRaycastResult result;
        scene_->GetComponent<PhysicsWorld>()->RaycastSingle(result, Ray(aimPoint, rayDir), rayDistance, 2);
        if (result.body_)
            rayDistance = Min(rayDistance, result.distance_);
        rayDistance = Clamp(rayDistance, CAMERA_MIN_DIST, CAMERA_MAX_DIST);
        
        cameraNode_->SetPosition(aimPoint + rayDir * rayDistance);
        cameraNode_->SetRotation(dir);
    }
}
Example #22
0
//----------------------------------------------------------------------------
void BlendedAnimations::ComputeVisibleSet (Spatial* object)
{
	TriMesh* mesh = DynamicCast<TriMesh>(object);
	if (mesh)
	{
		mVisibleSet.Insert(mesh);
		return;
	}

	Node* node = DynamicCast<Node>(object);
	if (node)
	{
		for (int i = 0; i < node->GetNumChildren(); ++i)
		{
			Spatial* child = node->GetChild(i);
			if (child)
			{
				ComputeVisibleSet(child);
			}
		}
	}
}
Example #23
0
//----------------------------------------------------------------------------
void Character::_CalAnimNode(Movable *mov)
{
	const std::string &movName = mov->GetName();
	Node *node = DynamicCast<Node>(mov);
	if (node)
	{
		BlendTransformController *btc = DynamicCast<BlendTransformController>(
			node->GetControllerByName("BTC"));
		if (!btc)
		{
			btc = new0 BlendTransformController(0, 0, true);
			node->AttachController(btc);
			btc->SetName("BTC");
		}
		mBTCMap[movName.c_str()] = btc;

		for (int i = 0; i < node->GetNumChildren(); i++)
		{
			_CalAnimNode(node->GetChild(i));
		}
	}
}
void BlendedAnimationsWindow::GetMeshes(
    std::shared_ptr<Spatial> const& object)
{
    Visual* mesh = dynamic_cast<Visual*>(object.get());
    if (mesh)
    {
        mMeshes.push_back(mesh);
        return;
    }

    Node* node = dynamic_cast<Node*>(object.get());
    if (node)
    {
        for (int i = 0; i < node->GetNumChildren(); ++i)
        {
            auto const& child = node->GetChild(i);
            if (child)
            {
                GetMeshes(child);
            }
        }
    }
}
Example #25
0
//------------------------------------------------------------------------------
void AlphaOrder::Order ()
{
    NodeIterator <Node> n (t->GetRoot());
    Node *q = n.begin();
    while (q)
    {
    	if (q->IsLeaf ())
        	labels[q] = q->GetLabel();
        q = n.next();
    }
	q = n.begin();
    while (q)
    while (q)
    {
    	if (!q->IsLeaf ())
        {
			SortDescendants (q);
            labels[q] = labels[q->GetChild()];
        }

        q = n.next();
    }
}
Example #26
0
//----------------------------------------------------------------------------
void Actor::_CollectAnchor(Movable *mov)
{
	if (!mov) return;

	Node *node = DynamicCast<Node>(mov);
	if (node)
	{
		int anchorId = node->GetAnchorID();
		if (0 != anchorId)
		{
			mAnchorMap[anchorId] = node;
		}

		for (int i = 0; i < node->GetNumChildren(); i++)
		{
			Node *childNode = DynamicCast<Node>(node->GetChild(i));
			if (childNode)
			{
				_CollectAnchor(childNode);
			}
		}
	}
}
//----------------------------------------------------------------------------
void Actor::SetMovable (Movable *movable)
{
	if (mScene && mMovable)
	{
		mScene->GetSceneNode()->DetachChild(mMovable);
	}

	mMovable = movable;

	mMovable->LocalTransform.SetScale(mScale);
	mMovable->LocalTransform.SetRotate(Matrix3f().MakeEulerXYZ(
		mRotation.X(), mRotation.Y(), mRotation.Z()));
	mMovable->LocalTransform.SetTranslate(mPosition);

	mMovable->Show(mIsVisible);

	if (mScene && mMovable)
	{
		mScene->GetSceneNode()->AttachChild(mMovable);
	}

	Node *node = DynamicCast<Node>(mMovable);
	if (node)
	{
		for (int i=0; i<node->GetNumChildren(); i++)
		{
			Renderable *renderable = DynamicCast<Renderable>(node->GetChild(i));
			if (renderable)
			{
				renderable->SetUpdatePriority(-1);
			}
		}
	}

	SetBakeObject(IsBakeObject());
	SetBakeTarget(IsBakeTarget());
}
Example #28
0
vector<string> Trie::allWordsWithPrefix(string word)
{
	vector<string> returnResult;
	
	Node* CurrentNode = root;
	
	// Blank string was entered return all words.
	if(word.length() == 0)
		return this->SearchNode(CurrentNode,"");

	// Move down the trie with the prefix.
	for(unsigned int i = 0; i < word.length(); i++)
	{
		if(CurrentNode != NULL)
			CurrentNode = CurrentNode->GetChild(word[i]);
		else
			break;
	}
	// If the node is not null search the node and the children.
	if(CurrentNode != NULL)
		returnResult = this->SearchNode(CurrentNode, word);
	
	return returnResult;
}
Example #29
0
void Node::SetNetParentAttr(const PODVector<unsigned char>& value)
{
    Scene* scene = GetScene();
    if (!scene)
        return;

    MemoryBuffer buf(value);
    // If nothing in the buffer, parent is the root node
    if (buf.IsEof())
    {
        scene->AddChild(this);
        return;
    }

    unsigned baseNodeID = buf.ReadNetID();
    Node* baseNode = scene->GetNode(baseNodeID);
    if (!baseNode)
    {
        LOGWARNING("Failed to find parent node " + String(baseNodeID));
        return;
    }

    // If buffer contains just an ID, the parent is replicated and we are done
    if (buf.IsEof())
        baseNode->AddChild(this);
    else
    {
        // Else the parent is local and we must find it recursively by name hash
        StringHash nameHash = buf.ReadStringHash();
        Node* parentNode = baseNode->GetChild(nameHash, true);
        if (!parentNode)
            LOGWARNING("Failed to find parent node with name hash " + nameHash.ToString());
        else
            parentNode->AddChild(this);
    }
}
Example #30
0
//----------------------------------------------------------------------------
void Picker::ExecuteRecursive (Movable* object, bool &hasMeshPicked)
{
	if (object)
	{
		if (!object->IsDoPick())
			return;

		if (!object->IsShow() && !object->IsPickIngoreCullingMode())
			return;
	}

	Triangles* mesh = DynamicCast<Triangles>(object);
	if (mesh)
	{
		if (!mesh->GetVertexBuffer())
			return;

		if (mesh->WorldBound.TestIntersection(mOrigin, mDirection, mTMin, mTMax))
		{
			if (mesh->IsUseBoundPick())
			{
				AVector dir = mesh->GetWorldTransform().GetTranslate() - mOrigin;
				float length = dir.Length();

				PickRecord record;
				record.Intersected = mesh;
				record.T = length;
				Records.push_back(record);
			}
			else
			{
				// 将射线从世界坐标系转换到模型坐标系。
				APoint ptmp;
				if (!mesh->IsSkinCtrlSetWroldTrans)
					ptmp = mesh->WorldTransform.Inverse()*mOrigin;
				else
					ptmp = mesh->BoundWorldTransform.Inverse()*mOrigin;
				Vector3f modelOrigin(ptmp[0], ptmp[1], ptmp[2]);

				AVector vtmp;
				if (!mesh->IsSkinCtrlSetWroldTrans)
					vtmp = mesh->WorldTransform.Inverse()*mDirection;
				else
					vtmp = mesh->BoundWorldTransform.Inverse()*mDirection;
				Vector3f modelDirection(vtmp[0], vtmp[1], vtmp[2]);

				Line3f line(modelOrigin, modelDirection);

				// 访问方位数据
				VertexBufferAccessor vba(mesh);

				int numTriangles = mesh->GetNumTriangles();
				for (int i = 0; i < numTriangles; ++i)
				{
					int v0, v1, v2;
					if (!mesh->GetTriangle(i, v0, v1, v2))
					{
						continue;
					}

					Vector3f vertex0 = vba.Position<Vector3f>(v0);
					Vector3f vertex1 = vba.Position<Vector3f>(v1);
					Vector3f vertex2 = vba.Position<Vector3f>(v2);
					Triangle3f triangle(vertex0, vertex1, vertex2);

					IntrLine3Triangle3f calc(line, triangle);
					if (calc.Find())
					{
						float lineParameter = calc.GetLineParameter();
						if (mTMin<=lineParameter && lineParameter<=mTMax)
						{
							PickRecord record;
							record.Intersected = mesh;
							record.T = calc.GetLineParameter();
							record.Triangle = i;
							record.Bary[0] = calc.GetTriBary0();
							record.Bary[1] = calc.GetTriBary1();
							record.Bary[2] = calc.GetTriBary2();

							Vector3f edg1 = vertex1 - vertex0;
							Vector3f edg2 = vertex2 - vertex0;
							Vector3f normal = edg1.UnitCross(edg2);
							float dotVal = line.Direction.Dot(normal);
							if (dotVal > Mathf::ZERO_TOLERANCE)
							{
								normal *= -1.0f;
							}
							record.LocalNormal = normal;
							record.WorldPos = mOrigin + mDirection * record.T;

							Records.push_back(record);

							if (mIsDoMovPickCall)
							{
								hasMeshPicked = true;
								mesh->OnPicked(mPickInfo);
							}
						}
					}
				}
			}
		}
		else
		{
			if (mIsDoMovPickCall)
				mesh->OnNotPicked(mPickInfo);
		}
		return;
	}

	SwitchNode* switchNode = DynamicCast<SwitchNode>(object);
	if (switchNode)
	{
		bool newHasChildPicked = false;

		int activeChild = switchNode->GetActiveChild();
		if (activeChild != SwitchNode::SN_INVALID_CHILD)
		{
			if (switchNode->WorldBound.TestIntersection(mOrigin, mDirection, mTMin, mTMax))
			{
				Movable* child = switchNode->GetChild(activeChild);
				if (child)
				{
					ExecuteRecursive(child, newHasChildPicked);
				}

				if (newHasChildPicked)
				{
					hasMeshPicked = true;
				}

				if (mIsDoMovPickCall)
				{
					if (hasMeshPicked)
					{
						switchNode->OnPicked(mPickInfo);
					}
					else
					{
						switchNode->OnNotPicked(mPickInfo);
					}
				}
			}
			else
			{
				if (mIsDoMovPickCall)
					switchNode->OnNotPicked(mPickInfo);
			}
		}
		return;
	}

	Node* node = DynamicCast<Node>(object);
	if (node)
	{
		bool newHasChildPicked = false;
		if (node->WorldBound.TestIntersection(mOrigin, mDirection, mTMin, mTMax))
		{
			Movable *movPriority = 0;
			if (node->IsDoPickPriority())
			{
				for (int i=0; i<node->GetNumChildren(); i++)
				{
					Movable *mov = node->GetChild(i);
					if (mov && mov->IsNotPickedParentChildrenNotPicked())
						movPriority = mov;
				}
			}

			// 做优先检测
			bool doLastPick = false;
			if (movPriority)
			{
				ExecuteRecursive (movPriority, doLastPick);		
			}
			else
			{
				doLastPick = true;
			}

			if (doLastPick)
			{
				for (int i = 0; i < node->GetNumChildren(); ++i)
				{
					Movable* child = node->GetChild(i);
					if (child && child!=movPriority)
					{
						ExecuteRecursive(child, newHasChildPicked);
					}
				}

				if (newHasChildPicked)
				{
					hasMeshPicked = true;
				}

				if (mIsDoMovPickCall)
				{
					if (newHasChildPicked)
					{
						node->OnPicked(mPickInfo);
					}
					else
					{
						node->OnNotPicked(mPickInfo);
					}
				}
			}
		}
		else
		{
			if (mIsDoMovPickCall)
				node->OnNotPicked(mPickInfo);
		}
	}
}