public bool Visit(ShapeNode node) { if (node.Enabled) { TestIntersects(node); } return(true); }
public override IDAEShapeNode CreateShapeNode(string name, IDAEMaterial material, IDAEGeometry geometry) { var shape = new ShapeNode(); shape.Name = name; shape.Material = material as Material; shape.Geometry = geometry as IGeometry; return(shape); }
private bool TestIntersects(SceneNode node) { if (!(node is ShapeNode) && (node.BoundingBox == null || !node.BoundingBox.IsValid)) { return(true); } Matrix4 trans = node.GetWorldTransform(_root).Value; Vector3 max = (trans * new Vector4(node.BoundingBox.Max.Value, 1.0f)).DivW.XYZ; Vector3 center = (trans * new Vector4(node.BoundingBox.Center.Value, 1.0f)).DivW.XYZ; float radius = (center - max).Length; // plane equation float d = _pickRay.Direction.Dot(center); // intersection point on plane float s = (d - _pickRay.Direction.Dot(_pickRay.Origin)) / _pickRay.Direction.Dot(_pickRay.Direction); if (s >= 0 || (_pickRay.Origin - center).Length < radius) { Vector3 f = _pickRay.Origin + (_pickRay.Direction * s); float dist = (f - center).Length; // distance of ray from sphere center if (dist < radius) // ray intersects bounding sphere { if (node is ShapeNode) { ShapeNode shapeNode = node as ShapeNode; // transform pick ray to object space Matrix4 invTrans = node.GetInverseWorldTransform(_root).Value; PickRay localPickRay = new PickRay(); localPickRay.Origin = (invTrans * new Vector4(_pickRay.Origin, 1)).XYZ; localPickRay.Direction = (invTrans * new Vector4(_pickRay.Direction, 0)).XYZ; // pick triangles in geometry Vector3?localPickPoint = shapeNode.Geometry.Pick(localPickRay); if (localPickPoint != null) { Vector3 pickPoint = (trans * new Vector4(localPickPoint.Value, 1)).DivW.XYZ; float zDist = (_pickRay.Origin - pickPoint).Length; if (_closestNode == null || zDist < _closestZDist) { _closestZDist = zDist; _closestNode = shapeNode; _pickPoint = pickPoint; } } } return(true); // is in bounding sphere } } return(false); }
public void Add(ShapeNode node) { List <ShapeNode> shapeList; if (MaterialGroups.ContainsKey(node.Material)) { shapeList = MaterialGroups[node.Material]; } else { shapeList = GetOrCreateShapeList(); MaterialGroups.Add(node.Material, shapeList); } shapeList.Add(node); }
private PickingResult?Pick(SceneNode root, PickRay ray) { _pickRay = ray; _root = root; _closestNode = null; _closestZDist = 0; root.Accept(this); if (_closestNode != null) { PickingResult result = new PickingResult(); result.PickedNode = _closestNode; result.PickingPoint = _pickPoint; return(result); } return(null); }
public bool Visit(ShapeNode node) { node.Preload(_renderer); return(true); }
public bool Visit(ShapeNode node) { CheckNode(node); return(_continue); }