Esempio n. 1
0
        public static void RenderDebugAABB(this WorldView worldView, Graphics2D graphics2D, AxisAlignedBoundingBox bounds)
        {
            Vector3 renderPosition           = bounds.Center;
            Vector2 objectCenterScreenSpace  = worldView.GetScreenPosition(renderPosition);
            Point2D screenPositionOfObject3D = new Point2D((int)objectCenterScreenSpace.X, (int)objectCenterScreenSpace.Y);

            graphics2D.Circle(objectCenterScreenSpace, 5, Color.Magenta);

            for (int i = 0; i < 4; i++)
            {
                graphics2D.Circle(worldView.GetScreenPosition(bounds.GetTopCorner(i)), 5, Color.Magenta);
                graphics2D.Circle(worldView.GetScreenPosition(bounds.GetBottomCorner(i)), 5, Color.Magenta);
            }

            RectangleDouble screenBoundsOfObject3D = RectangleDouble.ZeroIntersection;

            for (int i = 0; i < 4; i++)
            {
                screenBoundsOfObject3D.ExpandToInclude(worldView.GetScreenPosition(bounds.GetTopCorner(i)));
                screenBoundsOfObject3D.ExpandToInclude(worldView.GetScreenPosition(bounds.GetBottomCorner(i)));
            }

            graphics2D.Circle(screenBoundsOfObject3D.Left, screenBoundsOfObject3D.Bottom, 5, Color.Cyan);
            graphics2D.Circle(screenBoundsOfObject3D.Left, screenBoundsOfObject3D.Top, 5, Color.Cyan);
            graphics2D.Circle(screenBoundsOfObject3D.Right, screenBoundsOfObject3D.Bottom, 5, Color.Cyan);
            graphics2D.Circle(screenBoundsOfObject3D.Right, screenBoundsOfObject3D.Top, 5, Color.Cyan);
        }
        public static void RenderAabb(this WorldView world, AxisAlignedBoundingBox bounds, Matrix4X4 matrix, Color color, double width, double extendLineLength = 0)
        {
            GLHelper.PrepareFor3DLineRender(true);

            Frustum frustum = world.GetClippingFrustum();

            for (int i = 0; i < 4; i++)
            {
                Vector3 sideStartPosition = Vector3.Transform(bounds.GetBottomCorner(i), matrix);
                Vector3 sideEndPosition   = Vector3.Transform(bounds.GetTopCorner(i), matrix);

                Vector3 bottomStartPosition = sideStartPosition;
                Vector3 bottomEndPosition   = Vector3.Transform(bounds.GetBottomCorner((i + 1) % 4), matrix);

                Vector3 topStartPosition = sideEndPosition;
                Vector3 topEndPosition   = Vector3.Transform(bounds.GetTopCorner((i + 1) % 4), matrix);

                if (extendLineLength > 0)
                {
                    GLHelper.ExtendLineEnds(ref sideStartPosition, ref sideEndPosition, extendLineLength);
                    GLHelper.ExtendLineEnds(ref topStartPosition, ref topEndPosition, extendLineLength);
                    GLHelper.ExtendLineEnds(ref bottomStartPosition, ref bottomEndPosition, extendLineLength);
                }

                // draw each of the edge lines (4) and their touching top and bottom lines (2 each)
                world.Render3DLineNoPrep(frustum, sideStartPosition, sideEndPosition, color, width);
                world.Render3DLineNoPrep(frustum, topStartPosition, topEndPosition, color, width);
                world.Render3DLineNoPrep(frustum, bottomStartPosition, bottomEndPosition, color, width);
            }

            GL.Enable(EnableCap.Lighting);
        }
Esempio n. 3
0
        private void RenderBounds(AxisAlignedBoundingBox aabb)
        {
            Color color = Color.Red;

            // the bottom
            RenderLine(transform.Peek(), aabb.GetBottomCorner(0), aabb.GetBottomCorner(1), color);
            RenderLine(transform.Peek(), aabb.GetBottomCorner(1), aabb.GetBottomCorner(2), color);
            RenderLine(transform.Peek(), aabb.GetBottomCorner(2), aabb.GetBottomCorner(3), color);
            RenderLine(transform.Peek(), aabb.GetBottomCorner(3), aabb.GetBottomCorner(0), color);

            // the top
            RenderLine(transform.Peek(), aabb.GetTopCorner(0), aabb.GetTopCorner(1), color);
            RenderLine(transform.Peek(), aabb.GetTopCorner(1), aabb.GetTopCorner(2), color);
            RenderLine(transform.Peek(), aabb.GetTopCorner(2), aabb.GetTopCorner(3), color);
            RenderLine(transform.Peek(), aabb.GetTopCorner(3), aabb.GetTopCorner(0), color);

            // the sides
            RenderLine(transform.Peek(),
                       new Vector3(aabb.minXYZ.X, aabb.minXYZ.Y, aabb.minXYZ.Z),
                       new Vector3(aabb.minXYZ.X, aabb.minXYZ.Y, aabb.maxXYZ.Z),
                       color);
            RenderLine(transform.Peek(),
                       new Vector3(aabb.maxXYZ.X, aabb.minXYZ.Y, aabb.minXYZ.Z),
                       new Vector3(aabb.maxXYZ.X, aabb.minXYZ.Y, aabb.maxXYZ.Z),
                       color);
            RenderLine(transform.Peek(),
                       new Vector3(aabb.minXYZ.X, aabb.maxXYZ.Y, aabb.minXYZ.Z),
                       new Vector3(aabb.minXYZ.X, aabb.maxXYZ.Y, aabb.maxXYZ.Z),
                       color);
            RenderLine(transform.Peek(),
                       new Vector3(aabb.maxXYZ.X, aabb.maxXYZ.Y, aabb.minXYZ.Z),
                       new Vector3(aabb.maxXYZ.X, aabb.maxXYZ.Y, aabb.maxXYZ.Z),
                       color);
        }
Esempio n. 4
0
        private void RenderBounds(AxisAlignedBoundingBox aabb)
        {
            RGBA_Bytes color = RGBA_Bytes.Red;

            // the bottom
            RenderLine(transform.Peek(), aabb.GetBottomCorner(0), aabb.GetBottomCorner(1), color);
            RenderLine(transform.Peek(), aabb.GetBottomCorner(1), aabb.GetBottomCorner(2), color);
            RenderLine(transform.Peek(), aabb.GetBottomCorner(2), aabb.GetBottomCorner(3), color);
            RenderLine(transform.Peek(), aabb.GetBottomCorner(3), aabb.GetBottomCorner(0), color);

            // the top
            RenderLine(transform.Peek(), aabb.GetTopCorner(0), aabb.GetTopCorner(1), color);
            RenderLine(transform.Peek(), aabb.GetTopCorner(1), aabb.GetTopCorner(2), color);
            RenderLine(transform.Peek(), aabb.GetTopCorner(2), aabb.GetTopCorner(3), color);
            RenderLine(transform.Peek(), aabb.GetTopCorner(3), aabb.GetTopCorner(0), color);

            // the sides
            RenderLine(transform.Peek(),
                       new Vector3(aabb.minXYZ.x, aabb.minXYZ.y, aabb.minXYZ.z),
                       new Vector3(aabb.minXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.z),
                       color);
            RenderLine(transform.Peek(),
                       new Vector3(aabb.maxXYZ.x, aabb.minXYZ.y, aabb.minXYZ.z),
                       new Vector3(aabb.maxXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.z),
                       color);
            RenderLine(transform.Peek(),
                       new Vector3(aabb.minXYZ.x, aabb.maxXYZ.y, aabb.minXYZ.z),
                       new Vector3(aabb.minXYZ.x, aabb.maxXYZ.y, aabb.maxXYZ.z),
                       color);
            RenderLine(transform.Peek(),
                       new Vector3(aabb.maxXYZ.x, aabb.maxXYZ.y, aabb.minXYZ.z),
                       new Vector3(aabb.maxXYZ.x, aabb.maxXYZ.y, aabb.maxXYZ.z),
                       color);
        }
        public override List <WidgetAndPosition> FindDescendants(IEnumerable <string> namesToSearchFor, List <WidgetAndPosition> foundChildren, RectangleDouble touchingBounds, SearchType seachType, bool allowInvalidItems = true)
        {
            foreach (var child in Scene.Children)
            {
                string object3DName = child.Name;
                if (object3DName == null && child.MeshPath != null)
                {
                    object3DName = Path.GetFileName(child.MeshPath);
                }

                bool nameFound = false;

                foreach (var nameToSearchFor in namesToSearchFor)
                {
                    if (seachType == SearchType.Exact)
                    {
                        if (object3DName == nameToSearchFor)
                        {
                            nameFound = true;
                        }
                    }
                    else
                    {
                        if (nameToSearchFor == "" ||
                            object3DName.Contains(nameToSearchFor))
                        {
                            nameFound = true;
                        }
                    }
                }

                if (nameFound)
                {
                    AxisAlignedBoundingBox bounds = child.GetBVHData().GetAxisAlignedBoundingBox();

                    RectangleDouble screenBoundsOfObject3D = RectangleDouble.ZeroIntersection;
                    for (int i = 0; i < 4; i++)
                    {
                        screenBoundsOfObject3D.ExpandToInclude(this.World.GetScreenPosition(bounds.GetTopCorner(i)));
                        screenBoundsOfObject3D.ExpandToInclude(this.World.GetScreenPosition(bounds.GetBottomCorner(i)));
                    }

                    if (touchingBounds.IsTouching(screenBoundsOfObject3D))
                    {
                        Vector3 renderPosition           = bounds.Center;
                        Vector2 objectCenterScreenSpace  = this.World.GetScreenPosition(renderPosition);
                        Point2D screenPositionOfObject3D = new Point2D((int)objectCenterScreenSpace.X, (int)objectCenterScreenSpace.Y);

                        foundChildren.Add(new WidgetAndPosition(this, screenPositionOfObject3D, object3DName));
                    }
                }
            }

            return(base.FindDescendants(namesToSearchFor, foundChildren, touchingBounds, seachType, allowInvalidItems));
        }
        public override void FindNamedChildrenRecursive(string nameToSearchFor, List <WidgetAndPosition> foundChildren, RectangleDouble touchingBounds, SearchType seachType, bool allowInvalidItems = true)
        {
            foreach (InteractionVolume child in interactionLayer.InteractionVolumes)
            {
                string object3DName = child.Name;

                bool nameFound = false;

                if (seachType == SearchType.Exact)
                {
                    if (object3DName == nameToSearchFor)
                    {
                        nameFound = true;
                    }
                }
                else
                {
                    if (nameToSearchFor == "" ||
                        object3DName.Contains(nameToSearchFor))
                    {
                        nameFound = true;
                    }
                }

                if (nameFound &&
                    child.CollisionVolume != null)
                {
                    AxisAlignedBoundingBox bounds = child.CollisionVolume.GetAxisAlignedBoundingBox();
                    bounds = bounds.NewTransformed(child.TotalTransform);

                    RectangleDouble screenBoundsOfObject3D = RectangleDouble.ZeroIntersection;
                    for (int i = 0; i < 4; i++)
                    {
                        screenBoundsOfObject3D.ExpandToInclude(this.World.GetScreenPosition(bounds.GetTopCorner(i)));
                        screenBoundsOfObject3D.ExpandToInclude(this.World.GetScreenPosition(bounds.GetBottomCorner(i)));
                    }

                    if (touchingBounds.IsTouching(screenBoundsOfObject3D))
                    {
                        Vector3 renderPosition           = bounds.Center;
                        Vector2 objectCenterScreenSpace  = this.World.GetScreenPosition(renderPosition);
                        Point2D screenPositionOfObject3D = new Point2D((int)objectCenterScreenSpace.X, (int)objectCenterScreenSpace.Y);

                        foundChildren.Add(new WidgetAndPosition(this, screenPositionOfObject3D, object3DName, child));
                    }
                }
            }

            foreach (var child in scene.Children)
            {
                string object3DName = child.Name;
                if (object3DName == null && child.MeshPath != null)
                {
                    object3DName = Path.GetFileName(child.MeshPath);
                }

                bool nameFound = false;

                if (seachType == SearchType.Exact)
                {
                    if (object3DName == nameToSearchFor)
                    {
                        nameFound = true;
                    }
                }
                else
                {
                    if (nameToSearchFor == "" ||
                        object3DName.Contains(nameToSearchFor))
                    {
                        nameFound = true;
                    }
                }

                if (nameFound)
                {
                    AxisAlignedBoundingBox bounds = child.TraceData().GetAxisAlignedBoundingBox();

                    RectangleDouble screenBoundsOfObject3D = RectangleDouble.ZeroIntersection;
                    for (int i = 0; i < 4; i++)
                    {
                        screenBoundsOfObject3D.ExpandToInclude(this.World.GetScreenPosition(bounds.GetTopCorner(i)));
                        screenBoundsOfObject3D.ExpandToInclude(this.World.GetScreenPosition(bounds.GetBottomCorner(i)));
                    }

                    if (touchingBounds.IsTouching(screenBoundsOfObject3D))
                    {
                        Vector3 renderPosition           = bounds.Center;
                        Vector2 objectCenterScreenSpace  = this.World.GetScreenPosition(renderPosition);
                        Point2D screenPositionOfObject3D = new Point2D((int)objectCenterScreenSpace.X, (int)objectCenterScreenSpace.Y);

                        foundChildren.Add(new WidgetAndPosition(this, screenPositionOfObject3D, object3DName, child));
                    }
                }
            }

            base.FindNamedChildrenRecursive(nameToSearchFor, foundChildren, touchingBounds, seachType, allowInvalidItems);
        }