Beispiel #1
0
        protected override void OnSpaceBoundsUpdate(ref SpaceBounds newBounds)
        {
            base.OnSpaceBoundsUpdate(ref newBounds);

            //!!!!bounding sphere

            switch (Shape.Value)
            {
            case ShapeEnum.Box:
                newBounds = new SpaceBounds(GetBox().ToBounds());
                break;

            case ShapeEnum.Sphere:
                newBounds = new SpaceBounds(GetSphere());
                break;

            case ShapeEnum.Ray:
            {
                var    ray = GetRay();
                Bounds b   = new Bounds(ray.Origin);
                b.Add(ray.GetEndPoint());
                newBounds = new SpaceBounds(b);
            }
            break;
            }
        }
Beispiel #2
0
        protected override void OnSpaceBoundsUpdate(ref SpaceBounds newBounds)
        {
            base.OnSpaceBoundsUpdate(ref newBounds);

            //!!!!bounding sphere

            //switch( Shape.Value )
            //{
            //case ShapeEnum.Box:
            newBounds = new SpaceBounds(GetBox().ToBounds());
            //	break;

            //case ShapeEnum.Sphere:
            //	newBounds = new SpaceBounds( GetSphere() );
            //	break;

            //case ShapeEnum.Ray:
            //	{
            //		var ray = GetRay();
            //		Bounds b = new Bounds( ray.Origin );
            //		b.Add( ray.GetEndPoint() );
            //		newBounds = new SpaceBounds( b );
            //	}
            //	break;
            //}
        }
Beispiel #3
0
        protected override void OnSpaceBoundsUpdate(ref SpaceBounds newBounds)
        {
            base.OnSpaceBoundsUpdate(ref newBounds);

            var    scale = TransformV.Scale.MaxComponent();
            double far   = AttenuationFar * scale;

            newBounds = new SpaceBounds(new Sphere(TransformV.Position, far));
        }
        protected override void OnSpaceBoundsUpdate(ref SpaceBounds newBounds)
        {
            base.OnSpaceBoundsUpdate(ref newBounds);

            var tr             = Transform.Value;
            var attenuationFar = tr.Scale.MaxComponent();

            newBounds = new SpaceBounds(new Sphere(tr.Position, attenuationFar));
        }
        protected override void OnSpaceBoundsUpdate(ref SpaceBounds newBounds)
        {
            base.OnSpaceBoundsUpdate(ref newBounds);

            var b = new Bounds(TransformV.Position);

            b.Expand(0.05);
            ////add arrows thickness
            //b.Expand( Thickness );
            newBounds = new SpaceBounds(b);
        }
        protected override void OnSpaceBoundsUpdate(ref SpaceBounds newBounds)
        {
            base.OnSpaceBoundsUpdate(ref newBounds);

            var cylinder = GetCylinder();
            var b        = cylinder.ToBounds();

            //add arrows thickness
            b.Expand(Thickness);
            newBounds = new SpaceBounds(b);
        }
Beispiel #7
0
        /////////////////////////////////////////

        protected override void OnSpaceBoundsUpdate(ref SpaceBounds newBounds)
        {
            base.OnSpaceBoundsUpdate(ref newBounds);

            var tr = Transform.Value;

            tr.Rotation.ToMatrix3(out var rot);
            var box = new Box(tr.Position, new Vector3(tr.Scale.X, tr.Scale.Y, tr.Scale.Z) * 0.5, rot);

            newBounds = new SpaceBounds(box.ToBounds());
        }
Beispiel #8
0
        /////////////////////////////////////////

        protected override void OnSpaceBoundsUpdate(ref SpaceBounds newBounds)
        {
            base.OnSpaceBoundsUpdate(ref newBounds);

            var tr       = Transform.Value;
            var halfSize = Size.Value * tr.Scale.MaxComponent() * 0.5;
            var r        = Math.Sqrt(halfSize.X * halfSize.X + halfSize.Y * halfSize.Y);

            var bounds = new Bounds(tr.Position);

            bounds.Expand(r);
            newBounds = new SpaceBounds(bounds, new Sphere(tr.Position, r));
        }
Beispiel #9
0
        protected override void OnSpaceBoundsUpdate(ref SpaceBounds newBounds)
        {
            base.OnSpaceBoundsUpdate(ref newBounds);

            var bounds = Bounds.Cleared;

            foreach (var p in GetPoints())
            {
                bounds.Add(p.TransformV.Position);
            }
            if (!bounds.IsCleared())
            {
                newBounds = new SpaceBounds(bounds);
            }
        }
Beispiel #10
0
        public static SpaceBounds Merge(SpaceBounds a, SpaceBounds b)
        {
            if (a == null)
            {
                return(b);
            }
            if (b == null)
            {
                return(a);
            }

            Bounds?bounds = null;

            if (a.boundingBox != null && b.boundingBox != null)
            {
                bounds = Bounds.Merge(a.boundingBox.Value, b.boundingBox.Value);
            }
            else if (a.boundingBox != null)
            {
                bounds = a.boundingBox.Value;
            }
            else if (b.boundingBox != null)
            {
                bounds = b.boundingBox.Value;
            }

            Sphere?sphere = null;

            if (a.boundingSphere != null && b.boundingSphere != null)
            {
                sphere = Sphere.Merge(a.boundingSphere.Value, b.boundingSphere.Value);
            }
            else if (a.boundingSphere != null)
            {
                sphere = a.boundingSphere.Value;
            }
            else if (b.boundingSphere != null)
            {
                sphere = b.boundingSphere.Value;
            }

            return(new SpaceBounds(bounds, sphere));
        }
Beispiel #11
0
        protected override void OnSpaceBoundsUpdate(ref SpaceBounds newBounds)
        {
            base.OnSpaceBoundsUpdate(ref newBounds);

            switch (Shape.Value)
            {
            case ShapeEnum.Box:
                newBounds = new SpaceBounds(GetBox().ToBounds());
                break;

            case ShapeEnum.Sphere:
                newBounds = new SpaceBounds(GetSphere());
                break;

            case ShapeEnum.Cylinder:
                newBounds = new SpaceBounds(GetCylinder().ToBounds());
                break;
            }
        }
Beispiel #12
0
        public static SpaceBounds Multiply(Transform transform, SpaceBounds spaceBounds)
        {
            Bounds?b = null;
            Sphere?s = null;

            //!!!!!slowly
            //!!!!а может еще как-то смешивать сферу и bounds
            //!!!еще в конце расчета может еще как-то оптимизировать/уменьшить

            if (spaceBounds.boundingBox != null)
            {
                b = transform * spaceBounds.boundingBox.Value;
            }
            if (spaceBounds.boundingSphere != null)
            {
                s = transform * spaceBounds.boundingSphere.Value;
            }

            return(new SpaceBounds(b, s));
        }
        protected override void OnSpaceBoundsUpdate(ref SpaceBounds newBounds)
        {
            base.OnSpaceBoundsUpdate(ref newBounds);

            if (rigidBody != null)
            {
                var tr        = Transform.Value;
                var trNoScale = new Transform(tr.Position, tr.Rotation);

                Bounds bounds = Bounds.Cleared;
                foreach (var p in rigidBodyLocalPoints)
                {
                    bounds.Add(trNoScale * new Vector3(p, 0));
                }

                if (!bounds.IsCleared())
                {
                    bounds.Expand(new Vector3(0, 0, 0.001));

                    var b = new SpaceBounds(bounds);
                    newBounds = SpaceBounds.Merge(newBounds, b);
                }
            }
        }
Beispiel #14
0
        protected override void OnSpaceBoundsUpdate(ref SpaceBounds newBounds)
        {
            base.OnSpaceBoundsUpdate(ref newBounds);

            newBounds = new SpaceBounds(new Sphere(TransformV.Position, BoundingRadius));
        }
        /////////////////////////////////////////

        public static float GetCameraDistanceMinSquared(Viewport.CameraSettingsClass cameraSettings, SpaceBounds objectBounds)
        {
            objectBounds.GetCalculatedBoundingBox(out var objBounds);

            var nearestInBounds = cameraSettings.Position;

            MathEx.Clamp(ref nearestInBounds.X, objBounds.Minimum.X, objBounds.Maximum.X);
            MathEx.Clamp(ref nearestInBounds.Y, objBounds.Minimum.Y, objBounds.Maximum.Y);
            MathEx.Clamp(ref nearestInBounds.Z, objBounds.Minimum.Z, objBounds.Maximum.Z);

            return((float)(cameraSettings.Position - nearestInBounds).LengthSquared());
        }
Beispiel #16
0
        protected override void OnSpaceBoundsUpdate(ref SpaceBounds newBounds)
        {
            base.OnSpaceBoundsUpdate(ref newBounds);

            newBounds = new SpaceBounds(GetBox().ToBounds());
        }
        public static float GetCameraDistanceMax(Viewport.CameraSettingsClass cameraSettings, SpaceBounds objectBounds)
        {
            objectBounds.GetCalculatedBoundingSphere(out var objSphere);

            var centerDistance = (cameraSettings.Position - objSphere.Origin).Length();
            var max            = centerDistance + objSphere.Radius;

            return((float)max);
        }