コード例 #1
0
ファイル: SFBool.cpp プロジェクト: lukfugl/raytracer
bool SFBool::equals(Field *field) 
{
	SFBool *boolField = (SFBool *)field;
	if (getValue() == boolField->getValue())
		return true;
	else
		return false;
}
コード例 #2
0
ファイル: Test_BoxNode.cpp プロジェクト: Aharobot/Client
void Test_printFieldsOfBoxNode(CX3DParser& parser, char *vrmlFile)
{
	// ---------------------------------------------
	// ---------------------------------------------
	if (!parser.parse(vrmlFile))
	{
		fprintf(stderr, "%s parse failed\n", vrmlFile);
		return;
	}

	CX3DParser::printLog("**** Fields of BoxNode ****\n");

	// ---------------------------------------------
	// ---------------------------------------------
	MFNode *pShapeNodes = parser.searchNodesFromAllChildrenOfRoot("Shape");
	if (pShapeNodes)
	{
		for (int i=0; i<pShapeNodes->count(); i++)
		{
			CX3DShapeNode *pShape = (CX3DShapeNode *)(pShapeNodes->getNode(i));

			if (pShape)
			{
				// --------------------------------------------------------
				//
				// --------------------------------------------------------
				SFNode *geometry = pShape->getGeometry();
				CX3DNode *pNode = geometry->getNode();

				// ---------------------------------------------
				// ---------------------------------------------
				if (pNode && pNode->getNodeType() == BOX_NODE)
				{
					CX3DBoxNode *pBoxNode = (CX3DBoxNode *)pNode;

					// ---------------------------------------------
					// ---------------------------------------------

					SFVec3f *sz = pBoxNode->getSize();
					printf("size : (%f, %f, %f)\n", sz->x(), sz->y(), sz->z());

					// solid
					SFBool *solid = pBoxNode->getSolid();
					printf("solid : %s\n", solid->getValue() ? "TRUE" : "FALSE");
				}
			}
		}

		delete pShapeNodes;
		pShapeNodes = NULL;
	}
}
コード例 #3
0
ファイル: PickSelector.cpp プロジェクト: 4og/avango
const av::tools::MFTargetHolder::ContainerType&
av::tools::PickSelector::pick()
{
  mSelectedTargets.clear();

  if (RootNode.getValue().isValid())
  {
    // initialize line segment
    const ::osg::Vec3 start_pos = PickRayTransform.getValue().getTrans();
    const ::osg::Vec3 end_pos =
      (PickRayDirection.getValue() * PickRayLength.getValue()) * PickRayTransform.getValue();
    const ::osg::Vec3 pick_dir = end_pos - start_pos;
    mIntersector->setStart(start_pos);
    mIntersector->setEnd(end_pos);

    // compute intersections. check type of root node because apply is type dependent.
    ::osg::Node *root = RootNode.getValue()->getOsgNode();
    ::osg::Transform *root_transform = dynamic_cast< ::osg::Transform*>(root);
    if (root_transform != 0)
      mVisitor->apply(*root_transform);
    else
      mVisitor->apply(*root);

    if(mIntersector->containsIntersections())
    {
      MFContainer::ContainerType targets;
      const bool create_node_paths = CreateNodePaths.getValue();
      const bool create_intersections = CreateIntersections.getValue();
      const ::osgUtil::LineSegmentIntersector::Intersections &intersections =
        mIntersector->getIntersections();
      const unsigned int node_mask = NodePickMask.getValue();
      const unsigned int subtree_mask = SubtreePickMask.getValue();
      const bool pick_no_mask = PickNodesWithoutPickMask.getValue();

      for (::osgUtil::LineSegmentIntersector::Intersections::const_iterator intersection =
           intersections.begin(); intersection != intersections.end(); ++intersection)
      {
        av::Link<av::FieldContainer> target;
        std::list<av::Link<av::osg::Node> > node_path_list;

        // iterate over the node path from the intersected node to the root node,
        // check the pick masks and find the first Avango node.
        for (::osg::NodePath::const_reverse_iterator node = intersection->nodePath.rbegin();
             node != intersection->nodePath.rend(); ++node)
        {
          av::Link<av::osg::Node> av_node = av::osg::get_from_osg_object<av::osg::Node>(*node);
          if (av_node.isValid())
          {
            SFBool *ignore = dynamic_cast<SFBool*>(av_node->getField("PickIgnore"));
            if (ignore == 0 || !ignore->getValue())
            {
              SFUInt *mask = dynamic_cast<SFUInt*>(av_node->getField("PickMask"));
              if (!target.isValid())
              {
                if ((mask == 0 && pick_no_mask) ||
                    (mask != 0 && (node_mask & mask->getValue()) != 0u))
                {
                  target = av_node;
                  node_path_list.push_back(av_node);
                }
                else
                  break;
              }
              else
              {
                if ((mask == 0 && pick_no_mask) ||
                    (mask != 0 && (subtree_mask & mask->getValue()) != 0u))
                {
                  node_path_list.push_front(av_node);
                }
                else
                {
                  target.clear();
                  break;
                }
              }
            }
			else
				break;
          }
        }

        // check if we want to pick front or back face
        if (target.isValid())
        {
          if (intersection->getWorldIntersectNormal() * pick_dir < 0.0)
          {
            SFBool *pick_front = dynamic_cast<SFBool*>(target->getField("PickFrontFace"));
            if (pick_front != 0 && !pick_front->getValue())
              target.clear();
          }
          else
          {
            SFBool *pick_back = dynamic_cast<SFBool*>(target->getField("PickBackFace"));
            if (pick_back != 0 && !pick_back->getValue())
              target.clear();
          }
        }

        // add node to output list, if we don't have it already
        if (target.isValid() && !hasObject(targets, target))
        {
          targets.push_back(target);
          Link<TargetHolder> holder;

          if (create_node_paths || create_intersections)
          {
            std::vector<av::Link<av::osg::Node> > node_path;
            node_path.reserve(node_path_list.size());
            node_path.insert(node_path.begin(), node_path_list.begin(), node_path_list.end());
            Link<NodePathTargetHolder> path_holder;

            if (create_intersections)
            {
              // create IntersectionTargetHolder
              Link<av::osg::Intersection> av_intersection = new av::osg::Intersection;
              av_intersection->NodePath.setValue(node_path);
              av_intersection->Point.setValue(intersection->getWorldIntersectPoint());
              av_intersection->Normal.setValue(intersection->getWorldIntersectNormal());

              av_intersection->IndexList.setValue(intersection->indexList);
              av_intersection->RatioList.setValue(intersection->ratioList);

              Link<IntersectionTargetHolder> intersection_holder = new IntersectionTargetHolder;
              intersection_holder->Intersection.setValue(av_intersection);
              path_holder = intersection_holder;

            }
            else
              path_holder = new NodePathTargetHolder;

            path_holder->NodePath.setValue(node_path);
            holder = path_holder;
          }
          else
            holder = new TargetHolder;

          holder->Target.setValue(target);

          if (SetCreator.getValue())
            holder->Creator.setValue(this);

          mSelectedTargets.push_back(holder);
        }

        // stop if we only consider the first hit
        if (!mSelectedTargets.empty() && FirstHitOnly.getValue())
          break;
      }
    }

    mIntersector->reset();
  }

  return mSelectedTargets;
}