Ejemplo n.º 1
0
void BestPoint(std::size_t count, Vector4 clipped[9], SelectionIntersection& best, clipcull_t cull) {
  Vector3 normalised[9];

  {
    for(std::size_t i=0; i<count; ++i)
    {
      normalised[i][0] = clipped[i][0] / clipped[i][3];
      normalised[i][1] = clipped[i][1] / clipped[i][3];
      normalised[i][2] = clipped[i][2] / clipped[i][3];
    }
  }

  if(cull != eClipCullNone && count > 2)
  {
    double signed_area = triangle_signed_area_XY(normalised[0], normalised[1], normalised[2]);

    if((cull == eClipCullCW && signed_area > 0)
      || (cull == eClipCullCCW && signed_area < 0))
      return;
  }

  if(count == 2)
  {
    Segment3D segment(normalised[0], normalised[1]);
    Point3D point = segment_closest_point_to_point(segment, Vector3(0, 0, 0));
    assign_if_closer(best, SelectionIntersection(point.z(), 0));
  }
  else if(count > 2 && !point_test_polygon_2d(Vector3(0, 0, 0), normalised, normalised + count))
  {
    point_iterator_t end = normalised + count;
    for(point_iterator_t previous = end-1, current = normalised; current != end; previous = current, ++current)
    {
      Segment3D segment(*previous, *current);
      Point3D point = segment_closest_point_to_point(segment, Vector3(0, 0, 0));
      double depth = point.z();
      point.z() = 0;
      double distance = point.getLengthSquared();

      assign_if_closer(best, SelectionIntersection(depth, distance));
    }
  }
  else if(count > 2)
  {
    assign_if_closer(
      best,
      SelectionIntersection(
      static_cast<float>(
		  Ray(Vector3(0, 0, 0), Vector3(0, 0, 1)).getDistance(
			Plane3(normalised[0], normalised[1], normalised[2])
		  )),
        0
      )
    );
  }
}
Ejemplo n.º 2
0
void DragManipulator::testSelect(const View& view, const Matrix4& pivot2world) {
    SelectionPool selector;

    SelectionVolume test(view);

    if (GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive) {
        BooleanSelector booleanSelector;

        Scene_TestSelect_Primitive(booleanSelector, test, view);

        if (booleanSelector.isSelected()) {
            selector.addSelectable(SelectionIntersection(0, 0), &_dragSelectable);
            _selected = false;
        } else {
            _selected = Scene_forEachPlaneSelectable_selectPlanes(GlobalSceneGraph(), selector, test);
        }
    }
    // Check for entities that can be selected
    else if (GlobalSelectionSystem().Mode() == SelectionSystem::eEntity) {
        // Create a boolean selection pool (can have exactly one selectable or none)
        BooleanSelector booleanSelector;

        // Find the visible entities
        Scene_forEachVisible(GlobalSceneGraph(), view, testselect_entity_visible(booleanSelector, test));

        // Check, if an entity could be found
        if (booleanSelector.isSelected()) {
            selector.addSelectable(SelectionIntersection(0, 0), &_dragSelectable);
            _selected = false;
        }
    } else {
        BestSelector bestSelector;
        Scene_TestSelect_Component_Selected(bestSelector, test, view, GlobalSelectionSystem().ComponentMode());
        for (std::list<Selectable*>::iterator i = bestSelector.best().begin(); i != bestSelector.best().end(); ++i) {
            if (!(*i)->isSelected()) {
                GlobalSelectionSystem().setSelectedAllComponents(false);
            }
            _selected = false;
            selector.addSelectable(SelectionIntersection(0, 0), (*i));
            _dragSelectable.setSelected(true);
        }
    }

    for (SelectionPool::iterator i = selector.begin(); i != selector.end(); ++i) {
        (*i).second->setSelected(true);
    }
}
void TranslateManipulator::testSelect(const render::View& view, const Matrix4& pivot2world) {
    _pivot.update(pivot2world, view.GetModelview(), view.GetProjection(), view.GetViewport());

    SelectionPool selector;

    Vector3 x = _pivot._worldSpace.x().getVector3().getNormalised();
    bool show_x = manipulator_show_axis(_pivot, x);

    Vector3 y = _pivot._worldSpace.y().getVector3().getNormalised();
    bool show_y = manipulator_show_axis(_pivot, y);

    Vector3 z = _pivot._worldSpace.z().getVector3().getNormalised();
    bool show_z = manipulator_show_axis(_pivot, z);

    {
		Matrix4 local2view(view.GetViewMatrix().getMultipliedBy(_pivot._viewpointSpace));

      {
        SelectionIntersection best;
        Quad_BestPoint(local2view, eClipCullCW, &_quadScreen.front(), best);
        if(best.valid())
        {
          best = SelectionIntersection(0, 0);
          selector.addSelectable(best, &_selectableScreen);
        }
      }
    }

    {
		Matrix4 local2view(view.GetViewMatrix().getMultipliedBy(_pivot._worldSpace));

      if(show_x)
      {
        SelectionIntersection best;
        Line_BestPoint(local2view, &_arrowX.front(), best);
        Triangles_BestPoint(local2view, eClipCullCW, &_arrowHeadX._vertices.front(), &*(_arrowHeadX._vertices.end()-1)+1, best);
        selector.addSelectable(best, &_selectableX);
      }

      if(show_y)
      {
        SelectionIntersection best;
        Line_BestPoint(local2view, &_arrowY.front(), best);
        Triangles_BestPoint(local2view, eClipCullCW, &_arrowHeadY._vertices.front(), &*(_arrowHeadY._vertices.end()-1)+1, best);
        selector.addSelectable(best, &_selectableY);
      }

      if(show_z)
      {
        SelectionIntersection best;
        Line_BestPoint(local2view, &_arrowZ.front(), best);
        Triangles_BestPoint(local2view, eClipCullCW, &_arrowHeadZ._vertices.front(), &*(_arrowHeadZ._vertices.end()-1)+1, best);
        selector.addSelectable(best, &_selectableZ);
      }
    }

	// greebo: If any of the above arrows could be selected, select the first in the SelectionPool
    if(!selector.failed()) {
      (*selector.begin()).second->setSelected(true);
    } else {
    	Selectable* selectable = NULL;

    	if (registry::getValue<bool>(RKEY_TRANSLATE_CONSTRAINED)) {
	    	// None of the shown arrows (or quad) has been selected, select an axis based on the precedence
	    	Matrix4 local2view(view.GetViewMatrix().getMultipliedBy(_pivot._worldSpace));

	    	// Get the (relative?) distance from the mouse pointer to the manipulator
	    	Vector3 delta = local2view.t().getProjected();

	    	// Get the precedence (which axis has the absolute largest value in it)
	    	bool xGreaterY = (fabs(delta.x()) > fabs(delta.y()));

	    	// The precedence has to be interpreted according to which axes are visible
	    	if (show_z) {
	    		// Either XZ or YZ
	    		if (show_y) {
	    			// YZ
	    			selectable = (xGreaterY) ? &_selectableY : &_selectableZ;
	    		}
	    		else {
	    			// XZ
	    			selectable = (xGreaterY) ? &_selectableX : &_selectableZ;
	    		}
	    	}
	    	else {
	    		// XY
	    		selectable = (xGreaterY) ? &_selectableX : &_selectableY;
	    	}
    	}
    	else {
    		// Don't constrain to axis, choose the freemove translator
    		selectable = &_selectableScreen;
    	}

		// If everything went ok, there is a selectable available, add it
    	if (selectable != NULL) {
    		selector.addSelectable(SelectionIntersection(0,0), selectable);
    		selectable->setSelected(true);
    	}
    }
}
Ejemplo n.º 4
0
void TranslateManipulator::testSelect (const View& view, const Matrix4& pivot2world)
{
    m_pivot.update(pivot2world, view.GetModelview(), view.GetProjection(), view.GetViewport());

    SelectionPool selector;

    Vector3 x = m_pivot.m_worldSpace.x().getVector3().getNormalised();
    bool show_x = manipulator_show_axis(m_pivot, x);

    Vector3 y = m_pivot.m_worldSpace.y().getVector3().getNormalised();
    bool show_y = manipulator_show_axis(m_pivot, y);

    Vector3 z = m_pivot.m_worldSpace.z().getVector3().getNormalised();
    bool show_z = manipulator_show_axis(m_pivot, z);

    {
        Matrix4 local2view(matrix4_multiplied_by_matrix4(view.GetViewMatrix(), m_pivot.m_viewpointSpace));

        {
            SelectionIntersection best;
            Quad_BestPoint(local2view, eClipCullCW, m_quad_screen.m_quad, best);
            if (best.valid()) {
                best = SelectionIntersection(0, 0);
                selector.addSelectable(best, &m_selectable_screen);
            }
        }
    }

    {
        Matrix4 local2view(matrix4_multiplied_by_matrix4(view.GetViewMatrix(), m_pivot.m_worldSpace));

#if defined(DEBUG_SELECTION)
        g_render_clipped.construct(view.GetViewMatrix());
#endif

        if (show_x) {
            SelectionIntersection best;
            Line_BestPoint(local2view, m_arrow_x.m_line, best);
            Triangles_BestPoint(local2view, eClipCullCW, m_arrow_head_x.m_vertices.begin(),
                                m_arrow_head_x.m_vertices.end(), best);
            selector.addSelectable(best, &m_selectable_x);
        }

        if (show_y) {
            SelectionIntersection best;
            Line_BestPoint(local2view, m_arrow_y.m_line, best);
            Triangles_BestPoint(local2view, eClipCullCW, m_arrow_head_y.m_vertices.begin(),
                                m_arrow_head_y.m_vertices.end(), best);
            selector.addSelectable(best, &m_selectable_y);
        }

        if (show_z) {
            SelectionIntersection best;
            Line_BestPoint(local2view, m_arrow_z.m_line, best);
            Triangles_BestPoint(local2view, eClipCullCW, m_arrow_head_z.m_vertices.begin(),
                                m_arrow_head_z.m_vertices.end(), best);
            selector.addSelectable(best, &m_selectable_z);
        }
    }

    if (!selector.failed()) {
        (*selector.begin()).second->setSelected(true);
    }
}
Ejemplo n.º 5
0
void DragManipulator::testSelect(const render::View& view, const Matrix4& pivot2world)
{
    SelectionPool selector;

    SelectionVolume test(view);

    if (GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive)
	{
		// Find all entities
		BooleanSelector entitySelector;

		EntitySelector selectionTester(entitySelector, test);
		GlobalSceneGraph().foreachVisibleNodeInVolume(view, selectionTester);

    	if (entitySelector.isSelected())
		{
			// Found a selectable entity
			selector.addSelectable(SelectionIntersection(0, 0), &_dragSelectable);
			_selected = false;
		}
		else
		{
			// Find all primitives that are selectable
			BooleanSelector primitiveSelector;

			PrimitiveSelector primitiveTester(primitiveSelector, test);
			GlobalSceneGraph().foreachVisibleNodeInVolume(view, primitiveTester);

			if (primitiveSelector.isSelected())	
			{
				// Found a selectable primitive
				selector.addSelectable(SelectionIntersection(0, 0), &_dragSelectable);
				_selected = false;
			}
			else
			{
				// Entities and worldspawn primitives failed, so check for group children too
				// Find all group child primitives that are selectable
				BooleanSelector childPrimitiveSelector;

				GroupChildPrimitiveSelector childPrimitiveTester(childPrimitiveSelector, test);
				GlobalSceneGraph().foreachVisibleNodeInVolume(view, childPrimitiveTester);

				if (childPrimitiveSelector.isSelected())	
				{
					// Found a selectable group child primitive
					selector.addSelectable(SelectionIntersection(0, 0), &_dragSelectable);
					_selected = false;
				}
				else
				{
					// all direct hits failed, check for drag-selectable faces
					_selected = Scene_forEachPlaneSelectable_selectPlanes(selector, test);
				}
			}
		}
	}
	else if (GlobalSelectionSystem().Mode() == SelectionSystem::eGroupPart)
    {
    	// Find all primitives that are selectable
		BooleanSelector booleanSelector;

		GroupChildPrimitiveSelector childPrimitiveTester(booleanSelector, test);
		GlobalSceneGraph().foreachVisibleNodeInVolume(view, childPrimitiveTester);

		if (booleanSelector.isSelected())
		{
			// Found a selectable primitive
			selector.addSelectable(SelectionIntersection(0, 0), &_dragSelectable);
			_selected = false;
		}
		else
		{
			// Check for selectable faces
			_selected = Scene_forEachPlaneSelectable_selectPlanes(selector, test);
		}
    }
    // Check for entities that can be selected
    else if (GlobalSelectionSystem().Mode() == SelectionSystem::eEntity)
	{
    	// Create a boolean selection pool (can have exactly one selectable or none)
		BooleanSelector booleanSelector;

		// Find the visible entities
		EntitySelector selectionTester(booleanSelector, test);
		GlobalSceneGraph().foreachVisibleNodeInVolume(view, selectionTester);

		// Check, if an entity could be found
      	if (booleanSelector.isSelected()) {
        	selector.addSelectable(SelectionIntersection(0, 0), &_dragSelectable);
        	_selected = false;
		}
    }
    else
    {
		BestSelector bestSelector;

		ComponentSelector selectionTester(bestSelector, test, GlobalSelectionSystem().ComponentMode());
		GlobalSelectionSystem().foreachSelected(selectionTester);

		for (std::list<Selectable*>::iterator i = bestSelector.best().begin();
			 i != bestSelector.best().end(); ++i)
		{
			// greebo: Disabled this, it caused the currently selected patch vertices being deselected.
			if (registry::getValue<bool>(RKEY_TRANSIENT_COMPONENT_SELECTION))
			{
				if (!(*i)->isSelected())
				{
					GlobalSelectionSystem().setSelectedAllComponents(false);
				}
			}

			_selected = false;
			selector.addSelectable(SelectionIntersection(0, 0), (*i));
			_dragSelectable.setSelected(true);
		}
	}

	for (SelectionPool::iterator i = selector.begin(); i != selector.end(); ++i)
	{
		i->second->setSelected(true);
	}
}