public Bounds GetVisualBounds()
        {
            var transform = Transform.Value;
            var pos       = transform.Position;
            var rot       = transform.Rotation;

            var bounds = new Bounds(pos);

            double aspectRatio = AspectRatio;

            if (aspectRatio == 0)
            {
                aspectRatio = 1;
            }

            double halfWidth;
            double halfHeight;

            if (Projection.Value == ProjectionType.Perspective)
            {
                double tan = Math.Tan(FieldOfView.Value.InRadians() / 2);
                halfWidth  = tan * FarClipPlane.Value * aspectRatio;
                halfHeight = tan * FarClipPlane.Value;
            }
            else
            {
                halfWidth  = Height * .5 * aspectRatio;
                halfHeight = Height * .5;
            }
            var frustum       = new Frustum(true, Projection.Value, pos, rot, NearClipPlane.Value, FarClipPlane.Value, halfWidth, halfHeight);
            var frustumPoints = frustum.Points;

            switch (Projection.Value)
            {
            case ProjectionType.Perspective:
            {
                var points = new Vector3[8];
                {
                    for (int n = 4; n < 8; n++)
                    {
                        double distance = GetVisualLength();
                        var    dir      = (frustumPoints[n] - pos).GetNormalize() * distance;
                        var    p        = pos + dir * distance;
                        points[n] = p;
                    }
                }

                for (int n = 4; n < 8; n++)
                {
                    bounds.Add(points[n]);
                }
            }
            break;

            case ProjectionType.Orthographic:
            {
                //!!!!
            }
            break;
            }

            return(bounds);
        }
Beispiel #2
0
        static unsafe bool BoundsCullLocalFrustum(ref Bounds bounds, Frustum localFrustum, Vector3 *indexPoints, Vector3 *cornerVecs)
        {
            int    index;
            double dx, dy, dz;

            dy     = -localFrustum._axis.Item1.X;
            dz     = -localFrustum._axis.Item2.X;
            index  = (FLOATSIGNBITSET(dy) << 1) | FLOATSIGNBITSET(dz);
            dx     = -cornerVecs[index].X;
            index |= (FLOATSIGNBITSET(dx) << 2);

            if (indexPoints[index].X < bounds.Minimum.X)
            {
                return(true);
            }

            dy     = localFrustum._axis.Item1.X;
            dz     = localFrustum._axis.Item2.X;
            index  = (FLOATSIGNBITSET(dy) << 1) | FLOATSIGNBITSET(dz);
            dx     = cornerVecs[index].X;
            index |= (FLOATSIGNBITSET(dx) << 2);

            if (indexPoints[index].X > bounds.Maximum.X)
            {
                return(true);
            }

            dy     = -localFrustum._axis.Item1.Y;
            dz     = -localFrustum._axis.Item2.Y;
            index  = (FLOATSIGNBITSET(dy) << 1) | FLOATSIGNBITSET(dz);
            dx     = -cornerVecs[index].Y;
            index |= (FLOATSIGNBITSET(dx) << 2);

            if (indexPoints[index].Y < bounds.Minimum.Y)
            {
                return(true);
            }

            dy     = localFrustum._axis.Item1.Y;
            dz     = localFrustum._axis.Item2.Y;
            index  = (FLOATSIGNBITSET(dy) << 1) | FLOATSIGNBITSET(dz);
            dx     = cornerVecs[index].Y;
            index |= (FLOATSIGNBITSET(dx) << 2);

            if (indexPoints[index].Y > bounds.Maximum.Y)
            {
                return(true);
            }

            dy     = -localFrustum._axis.Item1.Z;
            dz     = -localFrustum._axis.Item2.Z;
            index  = (FLOATSIGNBITSET(dy) << 1) | FLOATSIGNBITSET(dz);
            dx     = -cornerVecs[index].Z;
            index |= (FLOATSIGNBITSET(dx) << 2);

            if (indexPoints[index].Z < bounds.Minimum.Z)
            {
                return(true);
            }

            dy     = localFrustum._axis.Item1.Z;
            dz     = localFrustum._axis.Item2.Z;
            index  = (FLOATSIGNBITSET(dy) << 1) | FLOATSIGNBITSET(dz);
            dx     = cornerVecs[index].Z;
            index |= (FLOATSIGNBITSET(dx) << 2);

            if (indexPoints[index].Z > bounds.Maximum.Z)
            {
                return(true);
            }

            return(false);
        }
        public void DebugDraw(Viewport viewport)
        {
            var transform = Transform.Value;
            var pos       = transform.Position;
            var rot       = transform.Rotation;

            //direction
            {
                var    toolSize   = viewport.Simple3DRenderer.GetThicknessByPixelSize(pos, ProjectSettings.Get.TransformToolSizeScaled);
                double thickness  = viewport.Simple3DRenderer.GetThicknessByPixelSize(pos, ProjectSettings.Get.TransformToolLineThicknessScaled);
                var    length     = toolSize / 1.5;
                var    headHeight = length / 4;
                viewport.Simple3DRenderer.AddArrow(pos, pos + rot * new Vector3(length, 0, 0), headHeight, 0, true, thickness);
            }

            double aspectRatio = AspectRatio;

            if (aspectRatio == 0)
            {
                aspectRatio = 1;
            }

            double halfWidth;
            double halfHeight;

            if (Projection.Value == ProjectionType.Perspective)
            {
                double tan = Math.Tan(FieldOfView.Value.InRadians() / 2);
                halfWidth  = tan * FarClipPlane.Value * aspectRatio;
                halfHeight = tan * FarClipPlane.Value;
            }
            else
            {
                halfWidth  = Height * .5 * aspectRatio;
                halfHeight = Height * .5;
            }
            var frustum       = new Frustum(true, Projection.Value, pos, rot, NearClipPlane.Value, FarClipPlane.Value, halfWidth, halfHeight);
            var frustumPoints = frustum.Points;

            switch (Projection.Value)
            {
            case ProjectionType.Perspective:
            {
                var points = new Vector3[8];
                {
                    for (int n = 4; n < 8; n++)
                    {
                        double distance = GetVisualLength();
                        var    dir      = (frustumPoints[n] - pos).GetNormalize() * distance;
                        var    p        = pos + dir * distance;
                        points[n] = p;
                    }
                }

                for (int n = 4; n < 8; n++)
                {
                    viewport.Simple3DRenderer.AddLine(pos, points[n]);
                }
                viewport.Simple3DRenderer.AddLine(points[4], points[5]);
                viewport.Simple3DRenderer.AddLine(points[5], points[6]);
                viewport.Simple3DRenderer.AddLine(points[6], points[7]);
                viewport.Simple3DRenderer.AddLine(points[7], points[4]);
            }
            break;

            case ProjectionType.Orthographic:
            {
                //!!!!
            }
            break;
            }
        }
Beispiel #4
0
 public GetObjectsInSpaceItem(CastTypeEnum castType, Metadata.TypeInfo selectedTypeOnly, bool visibleOnly, Frustum frustum)
 {
     this.CastType         = castType;
     this.SelectedTypeOnly = selectedTypeOnly;
     this.VisibleOnly      = visibleOnly;
     this.Frustum          = frustum;
 }