Exemplo n.º 1
0
        public static IEnumerable <Tuple <VectorD3D, VectorD3D> > GetVerticesAndNormals()
        {
            var pt0 = new VectorD3D(0, -SinArcCos1By3, MinusOneBy3);
            var pt1 = new VectorD3D(SinArcCos1By3 * Sin120, -SinArcCos1By3 * Cos120, MinusOneBy3);
            var pt2 = new VectorD3D(-SinArcCos1By3 * Sin120, -SinArcCos1By3 * Cos120, MinusOneBy3);
            var pt3 = new VectorD3D(0, 0, 1);

            // note: the normals are the negative vectors of the points

            // Bottom
            yield return(new Tuple <VectorD3D, VectorD3D>(-pt0, pt3));

            yield return(new Tuple <VectorD3D, VectorD3D>(-pt1, pt3));

            yield return(new Tuple <VectorD3D, VectorD3D>(-pt2, pt3));

            yield return(new Tuple <VectorD3D, VectorD3D>(-pt0, pt2));

            yield return(new Tuple <VectorD3D, VectorD3D>(-pt3, pt2));

            yield return(new Tuple <VectorD3D, VectorD3D>(-pt1, pt2));

            yield return(new Tuple <VectorD3D, VectorD3D>(-pt1, pt0));

            yield return(new Tuple <VectorD3D, VectorD3D>(-pt3, pt0));

            yield return(new Tuple <VectorD3D, VectorD3D>(-pt2, pt0));

            yield return(new Tuple <VectorD3D, VectorD3D>(-pt2, pt1));

            yield return(new Tuple <VectorD3D, VectorD3D>(-pt3, pt1));

            yield return(new Tuple <VectorD3D, VectorD3D>(-pt0, pt1));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HemisphericAmbientLight"/> class with default values.
 /// </summary>
 public HemisphericAmbientLight()
 {
     _colorBelow            = NamedColors.White;
     _colorAbove            = NamedColors.White;
     _lightAmplitude        = 1;
     _directionBelowToAbove = new VectorD3D(0, 0, 1);
 }
            /// <summary>
            /// Determines whether the grip is hit by the current mouse position.
            /// </summary>
            /// <param name="mousePosition">The mouse position (hit ray).</param>
            /// <returns></returns>
            public bool IsGripHit(HitTestPointData mousePosition)
            {
                var vec  = new VectorD3D(_gripRadius, _gripRadius, _gripRadius);
                var rect = new RectangleD3D(_gripCenter - vec, 2 * vec);

                return(mousePosition.IsHit(rect, out var z));
            }
Exemplo n.º 4
0
        public void Initialize(
            ICrossSectionOfLine crossSection,
            double thickness1,
            double thickness2,
            ILineCap startCap,
            ILineCap endCap,
            VectorD3D westVector,
            VectorD3D northVector,
            LineD3D line)
        {
            _crossSection                  = crossSection;
            _crossSectionVertexCount       = crossSection.NumberOfVertices;
            _crossSectionNormalCount       = crossSection.NumberOfNormals;
            _dashStartCap                  = startCap;
            _dashStartCapBaseInsetAbsolute = null == _dashStartCap ? 0 : _dashStartCap.GetAbsoluteBaseInset(thickness1, thickness2);
            _dashEndCap = endCap;
            _dashEndCapBaseInsetAbsolute = null == _dashEndCap ? 0 : _dashEndCap.GetAbsoluteBaseInset(thickness1, thickness2);
            _westVector                    = westVector;
            _northVector                   = northVector;
            _forwardVector                 = line.LineVectorNormalized;
            _lastNormalsTransformed        = new VectorD3D[_crossSectionNormalCount];
            _lastPositionsTransformedStart = new PointD3D[_crossSectionVertexCount];
            _lastPositionsTransformedEnd   = new PointD3D[_crossSectionVertexCount];

            // Get the matrix for the start plane
            var matrix = Math3D.Get2DProjectionToPlane(westVector, northVector, PointD3D.Empty);

            // note: for a single line segment, the normals need to be calculated only once

            for (int i = 0; i < _lastNormalsTransformed.Length; ++i)
            {
                _lastNormalsTransformed[i] = matrix.Transform(crossSection.Normals(i));
            }
        }
Exemplo n.º 5
0
        public override bool InitializeDocument(params object[] args)
        {
            if (args.Length < 2)
            {
                return(false);
            }
            if (!(args[0] is GridPartitioning))
            {
                return(false);
            }

            if (args[1] is VectorD3D)
            {
                _parentLayerSize = (VectorD3D)args[1];
            }
            else if (args[1] is HostLayer)
            {
                _parentLayerSize = ((HostLayer)args[1]).Size;
            }
            else
            {
                _parentLayerSize = new VectorD3D(600, 400, 400);
            }

            return(base.InitializeDocument(args));
        }
Exemplo n.º 6
0
		/// <summary>
		/// Gets the west and north vector for a single straight line.
		/// </summary>
		/// <param name="forward">The line forward vector. Not required to be normalized.</param>
		/// <returns>The west and the north vector (Item1=west vector, Item2 = north vector).</returns>
		public static Tuple<VectorD3D, VectorD3D> GetWestNorthVectors(VectorD3D forward)
		{
			var n = GetRawNorthVectorAtStart(forward);
			var w = VectorD3D.CrossProduct(n, forward).Normalized;
			n = VectorD3D.CrossProduct(forward, w).Normalized;
			return new Tuple<VectorD3D, VectorD3D>(w, n);
		}
Exemplo n.º 7
0
		public void TestZoom1_XOnly_XDirection()
		{
			double aspectRatio = 1.0;
			double cameraDistanceOriginal = 1000;
			double zNear = 100;
			double zFar = 10000;
			double widthByZNear = 0.5;
			double distanceFactor = 0.75;
			PointD3D targetPosition = new PointD3D(0, 0, 0);
			VectorD3D targetToEye = new VectorD3D(cameraDistanceOriginal, 0, 0);
			VectorD3D cameraUpVector = new VectorD3D(0, 0, 1);
			VectorD3D targetToWorldPoint = new VectorD3D(0, 200, 0);

			PointD3D cameraPosition = targetPosition + targetToEye;
			PointD3D worldPoint = targetPosition + targetToWorldPoint;

			Assert.AreEqual(0, VectorD3D.DotProduct(targetToEye, targetToWorldPoint), "The test must be set up in a way that targetToEye and targetToWorldPoint are perpendicular to each other");

			var cameraO = new PerspectiveCamera(cameraUpVector, cameraPosition, targetPosition, zNear, zFar, widthByZNear * zNear);

			var screenO = cameraO.GetViewProjectionMatrix(aspectRatio).Transform(worldPoint);

			Assert.AreEqual(0.0, screenO.Y, "Test must be set up so that screen.Y is always zero");

			var cameraN = cameraO.ZoomByGettingCloserToTarget(distanceFactor, screenO.X, screenO.Y, aspectRatio);

			var screenN = cameraN.GetViewProjectionMatrix(aspectRatio).Transform(worldPoint);

			Assert.AreEqual(screenO.X, screenN.X, 1E-3);
			Assert.AreEqual(screenO.Y, screenN.Y, 1E-3);
		}
Exemplo n.º 8
0
        /// <inheritdoc />
        public void AddGeometry(
            Action <PointD3D, VectorD3D> AddPositionAndNormal,
            Action <int, int, int, bool> AddIndices,
            ref int vertexIndexOffset,
            bool isStartCap,
            PointD3D basePoint,
            VectorD3D eastVector,
            VectorD3D northVector,
            VectorD3D forwardVectorNormalized,
            ICrossSectionOfLine lineCrossSection,
            PointD3D[] baseCrossSectionPositions,
            VectorD3D[] baseCrossSectionNormals,
            ref object temporaryStorageSpace)
        {
            var crossSectionVertexCount = lineCrossSection.NumberOfVertices;
            var crossSectionNormalCount = lineCrossSection.NumberOfNormals;

            var capCrossSectionPositions = baseCrossSectionPositions ?? (PointD3D[])temporaryStorageSpace ?? (PointD3D[])(temporaryStorageSpace = new PointD3D[crossSectionVertexCount]);

            if (null == baseCrossSectionPositions) // if null the positions were not provided
            {
                var matrix = Math3D.Get2DProjectionToPlane(eastVector, northVector, basePoint);
                for (int i = 0, j = 0; i < crossSectionVertexCount; ++i, ++j)
                {
                    capCrossSectionPositions[i] = matrix.Transform(lineCrossSection.Vertices(i));
                }
            }

            AddGeometry(AddPositionAndNormal, AddIndices, ref vertexIndexOffset, isStartCap, basePoint, forwardVectorNormalized, capCrossSectionPositions);
        }
Exemplo n.º 9
0
        public static CrossSectionOfLine GetStarShapedPolygon(double innerRadius, double outerRadius, int starArms)
        {
            var result = new CrossSectionOfLine();

            int numVertices = starArms * 2;
            int numNormals  = 2 * numVertices;

            result._vertices      = new PointD2D[numVertices];
            result._isVertexSharp = new bool[numVertices];
            result._normals       = new VectorD2D[numNormals];

            for (int i = 0; i < numVertices; ++i)
            {
                double phi    = (Math.PI * (2 * i)) / numVertices;
                double radius = 0 == (i % 2) ? outerRadius : innerRadius;
                result._vertices[i]      = new PointD2D(radius * Math.Cos(phi), radius * Math.Sin(phi));
                result._isVertexSharp[i] = true;
            }

            // now the normals, we calculate them using the cross product with the z-axis
            var zaxis = new VectorD3D(0, 0, 1);

            for (int i = 0; i < numVertices; ++i)
            {
                var       line  = (VectorD2D)(result._vertices[(i + 1) % numVertices] - result._vertices[i]);
                VectorD2D cross = new VectorD2D(line.Y, line.X).Normalized;
                result._normals[(2 * i + 1) % numNormals] = cross;
                result._normals[(2 * i + 2) % numNormals] = cross;
            }

            // normals
            return(result);
        }
Exemplo n.º 10
0
        public void TestZoom1_XOnly_XDirection()
        {
            double aspectRatio            = 1.0;
            double cameraDistanceOriginal = 1000;
            double zNear              = 100;
            double zFar               = 10000;
            double widthByZNear       = 0.5;
            double distanceFactor     = 0.75;
            var    targetPosition     = new PointD3D(0, 0, 0);
            var    targetToEye        = new VectorD3D(cameraDistanceOriginal, 0, 0);
            var    cameraUpVector     = new VectorD3D(0, 0, 1);
            var    targetToWorldPoint = new VectorD3D(0, 200, 0);

            PointD3D cameraPosition = targetPosition + targetToEye;
            PointD3D worldPoint     = targetPosition + targetToWorldPoint;

            Assert.AreEqual(0, VectorD3D.DotProduct(targetToEye, targetToWorldPoint), "The test must be set up in a way that targetToEye and targetToWorldPoint are perpendicular to each other");

            var cameraO = new PerspectiveCamera(cameraUpVector, cameraPosition, targetPosition, zNear, zFar, widthByZNear * zNear);

            var screenO = cameraO.GetViewProjectionMatrix(aspectRatio).Transform(worldPoint);

            Assert.AreEqual(0.0, screenO.Y, "Test must be set up so that screen.Y is always zero");

            var cameraN = cameraO.ZoomByGettingCloserToTarget(distanceFactor, screenO.X, screenO.Y, aspectRatio);

            var screenN = cameraN.GetViewProjectionMatrix(aspectRatio).Transform(worldPoint);

            Assert.AreEqual(screenO.X, screenN.X, 1E-3);
            Assert.AreEqual(screenO.Y, screenN.Y, 1E-3);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SpotLight"/> class.
        /// </summary>
        /// <param name="lightAmplitude">The light amplitude.</param>
        /// <param name="color">The color of light.</param>
        /// <param name="position">The position of the light.</param>
        /// <param name="directionToLight">The direction from the scene to the light.</param>
        /// <param name="range">The range of the light.</param>
        /// <param name="outerConeAngle">The outer cone angle in radians.</param>
        /// <param name="innerConeAngle">The inner cone angle in radians.</param>
        /// <param name="isAffixedToCamera">Value indicating whether the light source is affixed to the camera coordinate system or the world coordinate system.</param>
        public SpotLight(double lightAmplitude, NamedColor color, PointD3D position, VectorD3D directionToLight, double range, double outerConeAngle, double innerConeAngle, bool isAffixedToCamera)
        {
            _isAffixedToCamera = isAffixedToCamera;

            VerifyLightAmplitude(lightAmplitude, nameof(lightAmplitude));
            _lightAmplitude = lightAmplitude;

            _color = color;

            VerifyPosition(position, nameof(position));
            _position = position;

            var dlen = VerifyDirection(directionToLight, nameof(directionToLight));

            _directionToLight = directionToLight / dlen;

            VerifyRange(range, nameof(range));
            _range = range;

            VerifyAngle(outerConeAngle, nameof(outerConeAngle));
            _outerConeAngle = outerConeAngle;

            VerifyAngle(innerConeAngle, nameof(innerConeAngle));
            _innerConeAngle = innerConeAngle;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Make the views to look at the root layer center. The scale is choosen so that the size of the plot will be maximal.
        /// </summary>
        /// <param name="toEyeVector">The To-Eye vector (vector from the target to the camera position).</param>
        /// <param name="cameraUpVector">The camera up vector.</param>
        /// <param name="aspectRatio">The aspect ratio of the view port. If in doubt, use 1.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        public void ViewToRootLayerCenter(VectorD3D toEyeVector, VectorD3D cameraUpVector, double aspectRatio)
        {
            var upVector       = cameraUpVector.Normalized;
            var targetPosition = (PointD3D)(0.5 * RootLayer.Size);
            var cameraDistance = 10 * RootLayer.Size.Length;
            var eyePosition    = cameraDistance * toEyeVector.Normalized + targetPosition;

            var newCamera = _camera.WithUpEyeTargetZNearZFar(upVector, eyePosition, targetPosition, cameraDistance / 8, cameraDistance * 2);

            var orthoCamera = newCamera as Camera.OrthographicCamera;

            if (null != orthoCamera)
            {
                orthoCamera = (Camera.OrthographicCamera)orthoCamera.WithWidthAtZNear(1);

                var mx = orthoCamera.GetViewProjectionMatrix(aspectRatio);
                // to get the resulting scale, we transform all vertices of the root layer (the destination range would be -1..1, but now is not in range -1..1)
                // then we search for the maximum of the absulute value of x and y. This is our scale.
                double absmax = 0;
                foreach (var p in new RectangleD3D(RootLayer.Position, RootLayer.Size).Vertices)
                {
                    var ps = mx.Transform(p);
                    absmax = Math.Max(absmax, Math.Abs(ps.X));
                    absmax = Math.Max(absmax, Math.Abs(ps.Y));
                }
                newCamera = orthoCamera.WithWidthAtZNear(absmax);
            }
            else
            {
                throw new NotImplementedException();
            }

            Camera = newCamera;
        }
Exemplo n.º 13
0
 private static string GetAxisSideNameFromVector(VectorD3D v)
 {
     if (v.X == 1)
     {
         return("right");
     }
     else if (v.X == -1)
     {
         return("left");
     }
     else if (v.Y == 1)
     {
         return("back");
     }
     else if (v.Y == -1)
     {
         return("front");
     }
     else if (v.Z == 1)
     {
         return("up");
     }
     else if (v.Z == -1)
     {
         return("down");
     }
     else
     {
         throw new ArgumentOutOfRangeException("The vector v was expected to have only one element either being +1 or -1");
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// Converts logical coordinates along an isoline to layer coordinates and returns the direction of the isoline at this point.
        /// </summary>
        /// <param name="r0">Logical coordinates of starting point of the isoline.</param>
        /// <param name="r1">Logical coordinates of end point of the isoline.</param>
        /// <param name="t">Parameter between 0 and 1 that determines the point on the isoline.
        /// A value of 0 denotes the starting point of the isoline, a value of 1 the end point. The logical
        /// coordinates are linear interpolated between starting point and end point.</param>
        /// <param name="angle">Angle between direction of the isoline and returned normalized direction vector.</param>
        /// <param name="normalizeddirection">Returns the normalized direction vector,i.e. a vector of norm 1, that
        /// has the angle <paramref name="angle"/> to the tangent of the isoline. </param>
        /// <returns>The location (in layer coordinates) of the isoline point.</returns>
        public PointD3D GetNormalizedDirection(
            Logical3D r0, Logical3D r1,
            double t,
            double angle,
            out VectorD3D normalizeddirection)
        {
            LogicalToLayerCoordinatesAndDirection(
                r0, r1,
                t,
                out var position, out var direction);

            if (angle != 0)
            {
                throw new NotImplementedException("We need here two angles instead of one");

                /*
                 *                      double phi = Math.PI * angle / 180;
                 *                      double hdx = adx * Math.Cos(phi) + ady * Math.Sin(phi);
                 *                      ady = -adx * Math.Sin(phi) + ady * Math.Cos(phi);
                 *                      adx = hdx;
                 */
            }

            normalizeddirection = direction.Normalized;

            return(position);
        }
Exemplo n.º 15
0
        protected override void Initialize(bool initData)
        {
            base.Initialize(initData);

            if (initData)
            {
                _parentSize = _doc.ParentSize;
                _percentLayerXSizeUnit.ReferenceQuantity = new DimensionfulQuantity(_parentSize.X, AUL.Point.Instance);
                _percentLayerYSizeUnit.ReferenceQuantity = new DimensionfulQuantity(_parentSize.Y, AUL.Point.Instance);
                _percentLayerZSizeUnit.ReferenceQuantity = new DimensionfulQuantity(_parentSize.Z, AUL.Point.Instance);

                _xSizeEnvironment = new QuantityWithUnitGuiEnvironment(SizeEnvironment.Instance, new IUnit[] { _percentLayerXSizeUnit });
                _ySizeEnvironment = new QuantityWithUnitGuiEnvironment(SizeEnvironment.Instance, new IUnit[] { _percentLayerYSizeUnit });
                _zSizeEnvironment = new QuantityWithUnitGuiEnvironment(SizeEnvironment.Instance, new IUnit[] { _percentLayerZSizeUnit });

                _xPositionEnvironment = new QuantityWithUnitGuiEnvironment(PositionEnvironment.Instance, new IUnit[] { _percentLayerXSizeUnit });
                _yPositionEnvironment = new QuantityWithUnitGuiEnvironment(PositionEnvironment.Instance, new IUnit[] { _percentLayerYSizeUnit });
                _zPositionEnvironment = new QuantityWithUnitGuiEnvironment(PositionEnvironment.Instance, new IUnit[] { _percentLayerZSizeUnit });
            }

            if (null != _view)
            {
                _view.ShowSizeElements(!_doc.IsAutoSized, true);

                if (!_doc.IsAutoSized)
                {
                    var xSize = _doc.SizeX.IsAbsolute ? new DimensionfulQuantity(_doc.SizeX.Value, AUL.Point.Instance) : new DimensionfulQuantity(_doc.SizeX.Value * 100, _percentLayerXSizeUnit);
                    _view.InitializeXSize(xSize, _xSizeEnvironment);
                    var ySize = _doc.SizeY.IsAbsolute ? new DimensionfulQuantity(_doc.SizeY.Value, AUL.Point.Instance) : new DimensionfulQuantity(_doc.SizeY.Value * 100, _percentLayerYSizeUnit);
                    _view.InitializeYSize(ySize, _ySizeEnvironment);
                    var zSize = _doc.SizeZ.IsAbsolute ? new DimensionfulQuantity(_doc.SizeZ.Value, AUL.Point.Instance) : new DimensionfulQuantity(_doc.SizeZ.Value * 100, _percentLayerZSizeUnit);
                    _view.InitializeZSize(zSize, _zSizeEnvironment);
                }

                var xPos = _doc.PositionX.IsAbsolute ? new DimensionfulQuantity(_doc.PositionX.Value, AUL.Point.Instance) : new DimensionfulQuantity(_doc.PositionX.Value * 100, _percentLayerXSizeUnit);
                _view.InitializeXPosition(xPos, _xPositionEnvironment);
                var yPos = _doc.PositionY.IsAbsolute ? new DimensionfulQuantity(_doc.PositionY.Value, AUL.Point.Instance) : new DimensionfulQuantity(_doc.PositionY.Value * 100, _percentLayerYSizeUnit);
                _view.InitializeYPosition(yPos, _yPositionEnvironment);
                var zPos = _doc.PositionZ.IsAbsolute ? new DimensionfulQuantity(_doc.PositionZ.Value, AUL.Point.Instance) : new DimensionfulQuantity(_doc.PositionZ.Value * 100, _percentLayerZSizeUnit);
                _view.InitializeZPosition(zPos, _zPositionEnvironment);

                _view.RotationX = _doc.RotationX;
                _view.RotationY = _doc.RotationY;
                _view.RotationZ = _doc.RotationZ;
                _view.ShearX    = _doc.ShearX;
                _view.ShearY    = _doc.ShearY;
                _view.ShearZ    = _doc.ShearZ;
                _view.ScaleX    = _doc.ScaleX;
                _view.ScaleY    = _doc.ScaleY;
                _view.ScaleZ    = _doc.ScaleZ;
                _view.InitializePivot(_doc.LocalAnchorX, _doc.LocalAnchorY, _doc.LocalAnchorZ, _doc.AbsoluteSize);
                _view.InitializeReference(_doc.ParentAnchorX, _doc.ParentAnchorY, _doc.ParentAnchorZ, _doc.ParentSize);

                _view.ShowPositionElements(_showPositionElements_IsVisible, _showPositionElements_Enabled);
                _view.ShowSizeElements(_showSizeElements_IsVisible, _showSizeElements_Enabled);
                _view.ShowScaleElements(_showScaleElements_IsVisible, _showSizeElements_Enabled);
                _view.ShowAnchorElements(_showAnchorElements_IsVisible, _showAnchorElements_Enabled);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Creates a new camera with provided upVector and eyePosition.
        /// </summary>
        /// <param name="upVector">Up vector.</param>
        /// <param name="eyePosition">The eye position.</param>
        /// <returns>New camera with the provided parameters.</returns>
        public CameraBase WithUpEye(VectorD3D upVector, PointD3D eyePosition)
        {
            var result = (CameraBase)MemberwiseClone();

            result._upVector    = upVector;
            result._eyePosition = eyePosition;
            return(result);
        }
Exemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SpotLight"/> class with default values.
 /// </summary>
 public SpotLight()
 {
     _lightAmplitude   = 1;
     _color            = NamedColors.White;
     _range            = 1;
     _directionToLight = new VectorD3D(0, 0, -1);
     _outerConeAngle   = Math.PI / 2;
 }
Exemplo n.º 18
0
            public RectangleD3D GetBounds()
            {
                var lx = new VectorD3D(_transformation.M11, _transformation.M21, _transformation.M31).Length;
                var ly = new VectorD3D(_transformation.M12, _transformation.M22, _transformation.M32).Length;
                var lz = new VectorD3D(_transformation.M13, _transformation.M23, _transformation.M33).Length;

                return(new RectangleD3D(new PointD3D(_transformation.M41 - lx, _transformation.M42 - ly, _transformation.M43 - lz), new VectorD3D(2 * lx, 2 * ly, 2 * lz)));
            }
Exemplo n.º 19
0
        protected virtual bool InternalSetScaleSilent(VectorD3D value)
        {
            bool chg = _scaleX != value.X || _scaleY != value.Y || _scaleZ != value.Z;

            _scaleX = value.X;
            _scaleY = value.Y;
            _scaleZ = value.Z;
            return(chg);
        }
Exemplo n.º 20
0
 protected CameraBase(VectorD3D upVector, PointD3D eyePosition, PointD3D targetPosition, double zNear, double zFar, double widthAtZNear)
 {
     _upVector       = upVector;
     _eyePosition    = eyePosition;
     _targetPosition = targetPosition;
     _zNear          = zNear;
     _zFar           = zFar;
     _widthAtZNear   = widthAtZNear;
 }
Exemplo n.º 21
0
		public RectangleD3D(PointD3D position, VectorD3D size)
		{
			_x = position.X;
			_y = position.Y;
			_z = position.Z;
			_sizeX = size.X;
			_sizeY = size.Y;
			_sizeZ = size.Z;
		}
Exemplo n.º 22
0
        public RectangleD3D PaintSymbol(IGraphicsContext3D g, RectangleD3D bounds)
        {
            bounds = bounds.WithPadding(0, 0, -bounds.SizeZ / 4);
            var heightBy2 = new VectorD3D(0, 0, bounds.SizeZ / 4);

            g.DrawLine(_pen, bounds.Center - heightBy2, bounds.Center + heightBy2);

            return(bounds);
        }
Exemplo n.º 23
0
 /// <summary>
 /// Calculates the normal to a extruded contour. Here the extrusion direction is fixed to z-direction.
 /// </summary>
 /// <param name="crossSectionPoint">Original cross section point coordinates.</param>
 /// <param name="crossSectionNormal">Original cross section normal.</param>
 /// <param name="contourNormal">Original contour normal.</param>
 /// <param name="contourZScale">Factor that is multiplied with the x-coordinate of the contour point to return the z-coordinate of the resulting contour.</param>
 /// <returns>The normal of the extruded contour (x-y is the cross section plane, z the extrusion direction). This vector has then to be transformed into the 3D-space of the body.</returns>
 protected static VectorD3D GetNormalVector(PointD2D crossSectionPoint, VectorD2D crossSectionNormal, VectorD2D contourNormal, double contourZScale)
 {
     return(VectorD3D.CreateNormalized
            (
                contourNormal.Y * crossSectionNormal.X * contourZScale,
                contourNormal.Y * crossSectionNormal.Y * contourZScale,
                contourNormal.X * (crossSectionNormal.X * crossSectionPoint.X + crossSectionNormal.Y * crossSectionPoint.Y)
            ));
 }
Exemplo n.º 24
0
            public RectangleD3D GetBounds(Matrix3x3 additionalTransformation)
            {
                var t = _transformation.WithAppendedTransformation(additionalTransformation);

                var lx = new VectorD3D(t.M11, t.M21, t.M31).Length;
                var ly = new VectorD3D(t.M12, t.M22, t.M32).Length;
                var lz = new VectorD3D(t.M13, t.M23, t.M33).Length;

                return(new RectangleD3D(new PointD3D(t.M41 - lx, t.M42 - ly, t.M43 - lz), new VectorD3D(2 * lx, 2 * ly, 2 * lz)));
            }
Exemplo n.º 25
0
            /// <summary>
            /// Calculates a difference vector for moving a handle or an object.
            /// </summary>
            /// <param name="initialMousePosition">The initial mouse position at begin of the move operation.</param>
            /// <param name="currentMousePosition">The current mouse position.</param>
            /// <param name="initialObjectHitPositionLocalCoordinates">The initial position in local coordinates where the object or the handle was hit.</param>
            /// <returns>A difference vector (in world coordinates) that can be used to move the object or handle around.</returns>
            /// <exception cref="System.ArgumentOutOfRangeException"></exception>
            public static VectorD3D GetMoveVectorInWorldCoordinates(HitTestPointData initialMousePosition, HitTestPointData currentMousePosition, PointD3D initialObjectHitPositionLocalCoordinates)
            {
                var m = initialMousePosition.HitTransformation; // initial ray position
                var n = currentMousePosition.HitTransformation; // current ray position

                double x = initialObjectHitPositionLocalCoordinates.X;
                double y = initialObjectHitPositionLocalCoordinates.Y;
                double z = initialObjectHitPositionLocalCoordinates.Z;

                // For the mathematics behind the following, see internal document "3D_MoveObjectByMovingRay"

                double denom = m.M33 * n.M12 * n.M21 - m.M33 * n.M11 * n.M22 - m.M23 * n.M12 * n.M31 +
                               m.M13 * n.M22 * n.M31 + m.M23 * n.M11 * n.M32 - m.M13 * n.M21 * n.M32;

                if (0 == denom)
                {
                    throw new ArgumentOutOfRangeException();
                }

                double dx = m.M23 * (-(m.M42 * n.M31) +
                                     n.M32 * (m.M41 - n.M41 + m.M11 * x - n.M11 * x + m.M21 * y -
                                              n.M21 * y + m.M31 * z) +
                                     n.M31 * (n.M42 - m.M12 * x + n.M12 * x - m.M22 * y +
                                              n.M22 * y - m.M32 * z)) +
                            m.M33 * (m.M42 * n.M21 -
                                     n.M22 * (m.M41 - n.M41 + m.M11 * x - n.M11 * x + m.M21 * y) -
                                     (m.M31 * n.M22 - n.M22 * n.M31 + n.M21 * n.M32) * z +
                                     n.M21 * (-n.M42 + m.M12 * x - n.M12 * x + m.M22 * y + m.M32 * z));

                double dy = m.M13 * (m.M42 * n.M31 - n.M32 *
                                     (m.M41 - n.M41 + m.M11 * x - n.M11 * x + m.M21 * y -
                                      n.M21 * y + m.M31 * z) +
                                     n.M31 * (-n.M42 + m.M12 * x - n.M12 * x + m.M22 * y -
                                              n.M22 * y + m.M32 * z)) +
                            m.M33 * (-(m.M42 * n.M11) + n.M12 * (m.M41 - n.M41) +
                                     n.M12 * (m.M11 * x + m.M21 * y - n.M21 * y + m.M31 * z -
                                              n.M31 * z) + n.M11 *
                                     (n.M42 - m.M12 * x - m.M22 * y + n.M22 * y - m.M32 * z +
                                      n.M32 * z));

                double dz = m.M13 * (-(m.M42 * n.M21) +
                                     n.M22 * (m.M41 - n.M41 + m.M11 * x - n.M11 * x + m.M21 * y) +
                                     (m.M31 * n.M22 - n.M22 * n.M31 + n.M21 * n.M32) * z +
                                     n.M21 * (n.M42 - m.M12 * x + n.M12 * x - m.M22 * y - m.M32 * z))
                            + m.M23 * (m.M42 * n.M11 + n.M12 * (-m.M41 + n.M41) -
                                       n.M12 * (m.M11 * x + m.M21 * y - n.M21 * y + m.M31 * z -
                                                n.M31 * z) + n.M11 *
                                       (-n.M42 + m.M12 * x + m.M22 * y - n.M22 * y + m.M32 * z -
                                        n.M32 * z));

                var diff = new VectorD3D(dx / denom, dy / denom, dz / denom);

                return(diff);
            }
Exemplo n.º 26
0
        public virtual void SetParentSize(VectorD3D parentSize, bool shouldTriggerChangedEvent)
        {
            var oldValue = _parentSize;

            _parentSize = parentSize;

            if (shouldTriggerChangedEvent && oldValue != _parentSize)
            {
                EhSelfChanged();
            }
        }
Exemplo n.º 27
0
			/// <summary>
			/// Initializes a new instance of the <see cref="PathNodeGripHandle"/> class.
			/// </summary>
			/// <param name="parent">The object that was hit.</param>
			/// <param name="movePointRelativePosition">The relative position of the node that should be moved. For instance, (0,0,0) is at the origin of the object, (1,1,1) on the other side of the object, (0.5, 0.5, 0.5) at the center of the object.</param>
			/// <param name="gripCenter">The grip center in local (layer) coordinates.</param>
			/// <param name="gripRadius">The grip radius.</param>
			public PathNodeGripHandle(IHitTestObject parent, VectorD3D movePointRelativePosition, PointD3D gripCenter, double gripRadius)
			{
				_parent = parent;
				_initialObjectSize = GraphObject.Size;
				_movePointRelativePosition = movePointRelativePosition;
				_fixPointRelativePosition = new VectorD3D(movePointRelativePosition.X == 0 ? 1 : 0, movePointRelativePosition.Y == 0 ? 1 : 0, movePointRelativePosition.Z == 0 ? 1 : 0);
				_fixPointAbsolutePosition = GraphObject.RelativeLocalToAbsoluteParentCoordinates(_fixPointRelativePosition);

				_gripCenter = gripCenter;
				_gripRadius = gripRadius;
			}
Exemplo n.º 28
0
        /// <summary>
        /// Creates a new camera with provided upVector, eyePosition, targetPosition, znear and  zfar distance..
        /// </summary>
        /// <param name="upVector">Up vector.</param>
        /// <param name="eyePosition">The eye position.</param>
        /// <param name="targetPosition">The target position.</param>
        /// <param name="zNear">The z near distance.</param>
        /// <param name="zFar">The z far distance.</param>
        /// <returns>New camera with the provided parameters.</returns>
        public CameraBase WithUpEyeTargetZNearZFar(VectorD3D upVector, PointD3D eyePosition, PointD3D targetPosition, double zNear, double zFar)
        {
            var result = (CameraBase)MemberwiseClone();

            result._upVector       = upVector;
            result._eyePosition    = eyePosition;
            result._targetPosition = targetPosition;
            result._zNear          = zNear;
            result._zFar           = zFar;
            return(result);
        }
Exemplo n.º 29
0
 private void EhCartesianValueChanged(object sender, EventArgs e)
 {
     _lock.ExecuteLockedButOnlyIfNotLockedBefore(
         () =>
     {
         _direction = _guiCartesian.SelectedValue;
         _guiSpherical.SelectedValue = _direction;
     },
         () => SelectedValueChanged?.Invoke(this, EventArgs.Empty)
         );
 }
Exemplo n.º 30
0
            /// <summary>
            /// Initializes a new instance of the <see cref="PathNodeGripHandle"/> class.
            /// </summary>
            /// <param name="parent">The object that was hit.</param>
            /// <param name="movePointRelativePosition">The relative position of the node that should be moved. For instance, (0,0,0) is at the origin of the object, (1,1,1) on the other side of the object, (0.5, 0.5, 0.5) at the center of the object.</param>
            /// <param name="gripCenter">The grip center in local (layer) coordinates.</param>
            /// <param name="gripRadius">The grip radius.</param>
            public PathNodeGripHandle(IHitTestObject parent, VectorD3D movePointRelativePosition, PointD3D gripCenter, double gripRadius)
            {
                _parent                    = parent;
                _initialObjectSize         = GraphObject.Size;
                _movePointRelativePosition = movePointRelativePosition;
                _fixPointRelativePosition  = new VectorD3D(movePointRelativePosition.X == 0 ? 1 : 0, movePointRelativePosition.Y == 0 ? 1 : 0, movePointRelativePosition.Z == 0 ? 1 : 0);
                _fixPointAbsolutePosition  = GraphObject.RelativeLocalToAbsoluteParentCoordinates(_fixPointRelativePosition);

                _gripCenter = gripCenter;
                _gripRadius = gripRadius;
            }
Exemplo n.º 31
0
            /// <summary>Draws the grip in the graphics context.</summary>
            /// <param name="g">Graphics context.</param>
            public void Show(IOverlayContext3D g)
            {
                var buf = g.PositionColorLineListBuffer;

                var vec  = new VectorD3D(_gripRadius, _gripRadius, _gripRadius);
                var rect = new RectangleD3D(_gripCenter - vec, 2 * vec);

                foreach (var line in rect.Edges)
                {
                    buf.AddLine(line.P0.X, line.P0.Y, line.P0.Z, line.P1.X, line.P1.Y, line.P1.Z, 1, 0, 0, 1);
                }
            }
Exemplo n.º 32
0
        public void PaintBackground(IGraphicsContext3D g, IPlotArea layer)
        {
            if (null == _background)
            {
                return;
            }

            var cs = layer.CoordinateSystem;

            if (layer.CoordinateSystem is CS.G3DCartesicCoordinateSystem)
            {
                var p = new PointD3D[4];
                p[0] = cs.GetPointOnPlane(_planeID, 0, 0);
                p[1] = cs.GetPointOnPlane(_planeID, 0, 1);
                p[2] = cs.GetPointOnPlane(_planeID, 1, 0);
                p[3] = cs.GetPointOnPlane(_planeID, 1, 1);

                var normal = VectorD3D.CrossProduct(p[1] - p[0], p[2] - p[0]).Normalized;

                var buffer = g.GetPositionNormalIndexedTriangleBuffer(_background);

                if (null != buffer.PositionNormalIndexedTriangleBuffer)
                {
                    // front faces
                    var offs = buffer.IndexedTriangleBuffer.VertexCount;
                    for (int i = 0; i < 4; ++i)
                    {
                        buffer.PositionNormalIndexedTriangleBuffer.AddTriangleVertex(p[i].X, p[i].Y, p[i].Z, normal.X, normal.Y, normal.Z);
                    }

                    buffer.IndexedTriangleBuffer.AddTriangleIndices(0 + offs, 1 + offs, 3 + offs);
                    buffer.IndexedTriangleBuffer.AddTriangleIndices(2 + offs, 0 + offs, 3 + offs);

                    // back faces
                    offs = buffer.IndexedTriangleBuffer.VertexCount;
                    for (int i = 0; i < 4; ++i)
                    {
                        buffer.PositionNormalIndexedTriangleBuffer.AddTriangleVertex(p[i].X, p[i].Y, p[i].Z, -normal.X, -normal.Y, -normal.Z);
                    }

                    buffer.IndexedTriangleBuffer.AddTriangleIndices(0 + offs, 3 + offs, 1 + offs);
                    buffer.IndexedTriangleBuffer.AddTriangleIndices(2 + offs, 3 + offs, 0 + offs);
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
 public MeasuredLabelItem(IGraphicsContext3D g, FontX3D font1, FontX3D font2, string firstpart, string exponent, string lastpart, double maxexposize)
 {
     _firstpart    = firstpart;
     _exponent     = exponent;
     _lastpart     = lastpart;
     _font1        = font1;
     _font2        = font2;
     _size1        = g.MeasureString(_firstpart, _font1, PointD3D.Empty);
     _size2        = g.MeasureString(_exponent, _font2, new PointD3D(_size1.X, 0, 0));
     _size3        = g.MeasureString(_lastpart, _font1, PointD3D.Empty);
     _rightPadding = maxexposize - _size2.X;
 }
Exemplo n.º 34
0
		/// <summary>
		/// Gets a raw north vector for a straight line. Raw means that the returned vector is neither normalized, nor does it is forced to be perpendicular to the forward vector.
		/// It is only guaranteed that the returned vector is not colinear with the provided forward vector.
		/// </summary>
		/// <param name="forward">The line forward vector. Can be unnormalized.</param>
		/// <returns>The raw north vector.</returns>
		public static VectorD3D GetRawNorthVectorAtStart(VectorD3D forward)
		{
			double vLength = forward.Length;
			if (!(vLength > 0))
				throw new ArgumentException("Start vector of the line is invalid or empty", nameof(forward));
			forward = forward / vLength;

			if (Math.Abs(forward.Z) < _northVectorMaxZComponent)
				return new VectorD3D(0, 0, 1);
			else
				return new VectorD3D(0, -Math.Sign(forward.Z), 0);
		}
Exemplo n.º 35
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DirectionalLight"/> class.
        /// </summary>
        /// <param name="lightAmplitude">The light amplitude.</param>
        /// <param name="color">The color of light.</param>
        /// <param name="directionToLight">The direction from the scene to the light.</param>
        /// <param name="isAffixedToCamera">Value indicating whether the light source is affixed to the camera coordinate system or the world coordinate system.</param>
        public DirectionalLight(double lightAmplitude, NamedColor color, VectorD3D directionToLight, bool isAffixedToCamera)
        {
            _isAffixedToCamera = isAffixedToCamera;

            VerifyLightAmplitude(lightAmplitude, nameof(lightAmplitude));
            _lightAmplitude = lightAmplitude;

            _color = color;

            var len = VerifyDirection(directionToLight, nameof(directionToLight));

            _directionToLight = directionToLight / len;
        }
Exemplo n.º 36
0
		/// <summary>
		/// Initialization that is needed only once per straigth line (not once per dash).
		/// </summary>
		/// <param name="pen">The pen that is used to draw the line.</param>
		/// <param name="west">The west vector.</param>
		/// <param name="north">The north vector.</param>
		/// <param name="line">The global line to draw. This argument is needed to extract the line vector, which for a straight line is also the line vector for each individual dash segment.</param>
		public void Initialize(
			PenX3D pen,
			VectorD3D west,
			VectorD3D north,
			LineD3D line)
		{
			Initialize(
				pen.CrossSection,
				pen.Thickness1,
				pen.Thickness2,
				pen.DashStartCap,
				pen.DashEndCap,
				west,
				north,
				line
				);
		}
Exemplo n.º 37
0
		/// <summary>
		/// Converts logical coordinates along an isoline to layer coordinates and returns the direction of the isoline at this point.
		/// </summary>
		/// <param name="r0">Logical coordinates of starting point of the isoline.</param>
		/// <param name="r1">Logical coordinates of end point of the isoline.</param>
		/// <param name="t">Parameter between 0 and 1 that determines the point on the isoline.
		/// A value of 0 denotes the starting point of the isoline, a value of 1 the end point. The logical
		/// coordinates are linear interpolated between starting point and end point.</param>
		/// <param name="angle">Angle between direction of the isoline and returned normalized direction vector.</param>
		/// <param name="normalizeddirection">Returns the normalized direction vector,i.e. a vector of norm 1, that
		/// has the angle <paramref name="angle"/> to the tangent of the isoline. </param>
		/// <returns>The location (in layer coordinates) of the isoline point.</returns>
		public PointD3D GetNormalizedDirection(
			Logical3D r0, Logical3D r1,
			double t,
			double angle,
			out VectorD3D normalizeddirection)
		{
			//double ax, ay, adx, ady;
			PointD3D position;
			VectorD3D direction;
			this.LogicalToLayerCoordinatesAndDirection(
				r0, r1,
				t,
				out position, out direction);

			if (angle != 0)
			{
				throw new NotImplementedException("We need here two angles instead of one");
				/*
				double phi = Math.PI * angle / 180;
				double hdx = adx * Math.Cos(phi) + ady * Math.Sin(phi);
				ady = -adx * Math.Sin(phi) + ady * Math.Cos(phi);
				adx = hdx;
				*/
			}

			normalizeddirection = direction.Normalized;

			return position;
		}
Exemplo n.º 38
0
		/// <summary>
		/// Inverse transform a vector p in such a way that the result will fullfill the relation p = result * matrix ( the * operator being the prepend transformation for vectors).
		/// </summary>
		/// <param name="p">The point p to inverse transform.</param>
		/// <returns>The inverse transformation of point <paramref name="p"/>.</returns>
		public VectorD3D InverseTransform(VectorD3D p)
		{
			return new VectorD3D(
					(-(M23 * M32 * p.X) + M22 * M33 * p.X + M23 * M31 * p.Y - M21 * M33 * p.Y - M22 * M31 * p.Z + M21 * M32 * p.Z) / Determinant,

					(M13 * M32 * p.X - M12 * M33 * p.X - M13 * M31 * p.Y + M11 * M33 * p.Y + M12 * M31 * p.Z - M11 * M32 * p.Z) / Determinant,

					(-(M13 * M22 * p.X) + M12 * M23 * p.X + M13 * M21 * p.Y - M11 * M23 * p.Y - M12 * M21 * p.Z + M11 * M22 * p.Z) / Determinant

					);
		}
Exemplo n.º 39
0
		/// <summary>
		/// Transforms the specified vector <paramref name="v"/>. For a vector transform, the offset elements M41..M43 are ignored.
		/// The transformation is carried out as a prepend transformation, i.e. result = v * matrix (v considered as horizontal vector).
		/// </summary>
		/// <param name="v">The vector to transform.</param>
		/// <returns>The transformed vector.</returns>
		public VectorD3D Transform(VectorD3D v)
		{
			double x = v.X;
			double y = v.Y;
			double z = v.Z;
			return new VectorD3D(
			x * M11 + y * M21 + z * M31,
			x * M12 + y * M22 + z * M32,
			x * M13 + y * M23 + z * M33
			);
		}
Exemplo n.º 40
0
			public MeasuredLabelItem(IGraphicsContext3D g, FontX3D font, string itemtext, double lineSpacing, Alignment horizontalAlignment, Alignment verticalAlignment, Alignment textBlockAligment)
			{
				_text = itemtext.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
				_stringSize = new VectorD3D[_text.Length];
				_font = font;
				_horizontalAlignment = horizontalAlignment;
				_verticalAlignment = verticalAlignment;
				_textBlockAligment = textBlockAligment;
				_lineSpacing = lineSpacing;
				_size = VectorD3D.Empty;
				var bounds = RectangleD3D.Empty;
				var position = PointD3D.Empty;
				for (int i = 0; i < _text.Length; ++i)
				{
					_stringSize[i] = g.MeasureString(_text[i], _font, PointD3D.Empty);
					bounds = bounds.WithRectangleIncluded(new RectangleD3D(position, _stringSize[i]));
					position = position.WithYPlus(-_stringSize[i].Y * _lineSpacing);
				}
				_size = bounds.Size;
			}
Exemplo n.º 41
0
		/// <summary>
		/// Initializes a new instance of the <see cref="DirectionalLight"/> class with default values.
		/// </summary>
		public DirectionalLight()
		{
			_lightAmplitude = 1;
			_color = NamedColors.White;
			_directionToLight = new VectorD3D(-Math.Sqrt(0.25), -Math.Sqrt(0.25), Math.Sqrt(0.5));
		}
Exemplo n.º 42
0
		/// <summary>
		/// Converts logical coordinates along an isoline to layer coordinates and returns the direction of the isoline at this point.
		/// </summary>
		/// <param name="r0">Logical starting point of the isoline.</param>
		/// <param name="r1">Logical end point of the isoline.</param>
		/// <param name="t">Parameter between 0 and 1 that determines the point on the isoline.
		/// A value of 0 denotes the starting point of the isoline, a value of 1 the end point. The logical
		/// coordinates are linear interpolated between starting point and end point.</param>
		/// <param name="direction">Logical direction vector.</param>
		/// <param name="normalizeddirection">Returns the normalized direction vector,i.e. a vector of norm 1, that
		/// goes in the logical direction provided by the previous argument. </param>
		/// <returns>The location (in layer coordinates) of the isoline point.</returns>
		public virtual PointD3D GetPositionAndNormalizedDirection(
				Logical3D r0, Logical3D r1,
				double t,
				Logical3D direction,
				out VectorD3D normalizeddirection)
		{
			PointD3D pos;
			VectorD3D dir;
			Logical3D rn0 = Logical3D.Interpolate(r0, r1, t);
			Logical3D rn1 = rn0 + direction;
			this.LogicalToLayerCoordinatesAndDirection(rn0, rn1, 0, out pos, out dir);
			double hypot = dir.Length;
			if (0 == hypot)
			{
				// then we look a little bit displaced - we might be at the midpoint where the directions are undefined
				double displT = t;
				if (displT < 0.5)
					displT += 1E-6;
				else
					displT -= 1E-6;

				Logical3D displR = Logical3D.Interpolate(r0, r1, displT);
				Logical3D displD = displR + direction;
				PointD3D dummyx;
				LogicalToLayerCoordinatesAndDirection(displR, displD, 0, out dummyx, out dir);
				hypot = dir.Length;
			}

			// Normalize the vector
			if (hypot > 0)
			{
				dir /= hypot;
			}

			normalizeddirection = dir;

			return pos;
		}
Exemplo n.º 43
0
		/// <summary>
		/// Creates the rotation matrix from axis and angle radian.
		/// </summary>
		/// <param name="u">The axis about which the rotation takes place.</param>
		/// <param name="angleRadian">The rotation angle in radian.</param>
		/// <returns>Matrix that describes the drotation.</returns>
		public static Matrix3x3 CreateRotationMatrixFromAxisAndAngleRadian(VectorD3D u, double angleRadian)
		{
			double cosTheta = Math.Cos(angleRadian);
			double oMCosTheta = 1 - cosTheta;
			double sinTheta = Math.Sin(angleRadian);

			double m11 = cosTheta + u.X * u.X * oMCosTheta;
			double m12 = u.X * u.Y * oMCosTheta + u.Z * sinTheta;
			double m13 = u.Z * u.X * oMCosTheta - u.Y * sinTheta;

			double m21 = u.X * u.Y * oMCosTheta - u.Z * sinTheta;
			double m22 = cosTheta + u.Y * u.Y * oMCosTheta;
			double m23 = u.Z * u.Y * oMCosTheta + u.X * sinTheta;

			double m31 = u.X * u.Z * oMCosTheta + u.Y * sinTheta;
			double m32 = u.Y * u.Z * oMCosTheta - u.X * sinTheta;
			double m33 = cosTheta + u.Z * u.Z * oMCosTheta;

			return new Matrix3x3(m11, m12, m13, m21, m22, m23, m31, m32, m33);
		}
Exemplo n.º 44
0
		/// <summary>
		/// Creates a transformation matrix that uses three basis vectors to construct the matrix that transform points expressed in the three basis vectors to points in
		/// the coordinate system.
		/// </summary>
		/// <param name="xBasis">Basis vector for the x-direction.</param>
		/// <param name="yBasis">Basis vector for the y-direction.</param>
		/// <param name="zBasis">Basis vector for the z-direction.</param>
		/// <returns>A transformation matrix that uses the three basis vectors, and a location</returns>
		public static Matrix3x3 NewFromBasisVectors(VectorD3D xBasis, VectorD3D yBasis, VectorD3D zBasis)
		{
			return new Matrix3x3(
				xBasis.X, xBasis.Y, xBasis.Z,
				yBasis.X, yBasis.Y, yBasis.Z,
				zBasis.X, zBasis.Y, zBasis.Z);
		}
Exemplo n.º 45
0
		/// <summary>
		/// Converts logical coordinates along an isoline to layer coordinates and the appropriate derivative.
		/// </summary>
		/// <param name="r0">Logical position of starting point of the isoline.</param>
		/// <param name="r1">Logical position of end point of the isoline.</param>
		/// <param name="t">Parameter between 0 and 1 that determines the point on the isoline.
		/// A value of 0 denotes the starting point of the isoline, a value of 1 the end point. The logical
		/// coordinates are linear interpolated between starting point and end point.</param>
		/// <param name="position">Layer coordinate of the isoline point.</param>
		/// <param name="direction">Derivative of layer coordinate with respect to parameter t at the point <paramref name="position"/>.</param>
		/// <returns>True if the conversion was sucessfull, otherwise false.</returns>
		public abstract bool LogicalToLayerCoordinatesAndDirection(
			Logical3D r0, Logical3D r1,
			double t,
			out PointD3D position, out VectorD3D direction);
Exemplo n.º 46
0
		private void EhSphericalValueChanged(object sender, EventArgs e)
		{
			_lock.ExecuteLockedButOnlyIfNotLockedBefore(
				() =>
				{
					_direction = _guiSpherical.SelectedValue;
					_guiCartesian.SelectedValue = _direction;
				},
				() => SelectedValueChanged?.Invoke(this, EventArgs.Empty)
				);
		}
Exemplo n.º 47
0
		public RectangleD3D GetAbsolute(GridPartitioning partition, VectorD3D parentSize)
		{
			return partition.GetTileRectangle(_gridPosX, _gridPosY, _gridPosZ, _gridSpanX, _gridSpanY, _gridSpanZ, parentSize);
		}
Exemplo n.º 48
0
		/// <summary>
		/// Verifies the validity of the vector and returns the vector length.
		/// </summary>
		/// <param name="value">The direction from light to scene.</param>
		/// <param name="valueName">The name of the parameter.</param>
		/// <returns>Vector length.</returns>
		/// <exception cref="ArgumentOutOfRangeException">
		/// </exception>
		private double VerifyDirection(VectorD3D value, string valueName)
		{
			if (value == VectorD3D.Empty)
				throw new ArgumentOutOfRangeException(valueName + " must not be an empty vector");
			var len = value.Length;
			if (!(len >= 0))
				throw new ArgumentOutOfRangeException(valueName + " is a vector with invalid elements");

			return len;
		}
Exemplo n.º 49
0
		/// <summary>
		/// Creates a transformation matrix that uses three basis vectors, and a location to construct the matrix that transform points expressed in the three basis vectors to points in
		/// the coordinate system.
		/// </summary>
		/// <param name="xBasis">Basis vector for the x-direction.</param>
		/// <param name="yBasis">Basis vector for the y-direction.</param>
		/// <param name="zBasis">Basis vector for the z-direction.</param>
		/// <param name="origin">The origin of the coordinate system.</param>
		/// <returns>A transformation matrix that uses the three basis vectors, and a location</returns>
		public static Matrix4x3 NewFromBasisVectorsAndLocation(VectorD3D xBasis, VectorD3D yBasis, VectorD3D zBasis, PointD3D origin)
		{
			return new Matrix4x3(
				xBasis.X, xBasis.Y, xBasis.Z,
				yBasis.X, yBasis.Y, yBasis.Z,
				zBasis.X, zBasis.Y, zBasis.Z,
				origin.X, origin.Y, origin.Z);
		}
Exemplo n.º 50
0
		public static Matrix4x3 NewTranslation(VectorD3D d)
		{
			return new Matrix4x3(
				1, 0, 0,
				0, 1, 0,
				0, 0, 1,
				d.X, d.Y, d.Z,
				1
				);
		}
Exemplo n.º 51
0
		public OrthographicCamera(VectorD3D upVector, PointD3D eyePosition, PointD3D targetPosition, double zNear, double zFar, double widthAtZNear)
						: base(upVector, eyePosition, targetPosition, zNear, zFar, widthAtZNear)
		{
		}
Exemplo n.º 52
0
		/// <summary>
		/// Creates the rotation matrix from axis and angle radian.
		/// </summary>
		/// <param name="u">The axis about which the rotation takes place.</param>
		/// <param name="angleRadian">The rotation angle in radian.</param>
		/// <param name="center">The center of rotation.</param>
		/// <returns>Matrix that describes the drotation.</returns>
		public static Matrix4x3 NewRotationFromAxisAndAngleRadian(VectorD3D u, double angleRadian, PointD3D center)
		{
			double cosTheta = Math.Cos(angleRadian);
			double oMCosTheta = 1 - cosTheta;
			double sinTheta = Math.Sin(angleRadian);

			double m11 = cosTheta + u.X * u.X * oMCosTheta;
			double m12 = u.X * u.Y * oMCosTheta + u.Z * sinTheta;
			double m13 = u.Z * u.X * oMCosTheta - u.Y * sinTheta;

			double m21 = u.X * u.Y * oMCosTheta - u.Z * sinTheta;
			double m22 = cosTheta + u.Y * u.Y * oMCosTheta;
			double m23 = u.Z * u.Y * oMCosTheta + u.X * sinTheta;

			double m31 = u.X * u.Z * oMCosTheta + u.Y * sinTheta;
			double m32 = u.Y * u.Z * oMCosTheta - u.X * sinTheta;
			double m33 = cosTheta + u.Z * u.Z * oMCosTheta;

			double offsetX = 0, offsetY = 0, offsetZ = 0;

			if (center.X != 0.0 || center.Y != 0.0 || center.Z != 0.0)
			{
				offsetX = -center.X * m11 - center.Y * m21 - center.Z * m31 + center.X;
				offsetY = -center.X * m12 - center.Y * m22 - center.Z * m32 + center.Y;
				offsetZ = -center.X * m13 - center.Y * m23 - center.Z * m33 + center.Z;
			}

			return new Matrix4x3(m11, m12, m13, m21, m22, m23, m31, m32, m33, offsetX, offsetY, offsetZ);
		}
Exemplo n.º 53
0
		protected CameraBase(VectorD3D upVector, PointD3D eyePosition, PointD3D targetPosition, double zNear, double zFar, double widthAtZNear)
		{
			this._upVector = upVector;
			this._eyePosition = eyePosition;
			this._targetPosition = targetPosition;
			this._zNear = zNear;
			this._zFar = zFar;
			this._widthAtZNear = widthAtZNear;
		}
Exemplo n.º 54
0
			/// <summary>
			/// Calculates a difference vector for moving a handle or an object.
			/// </summary>
			/// <param name="initialMousePosition">The initial mouse position at begin of the move operation.</param>
			/// <param name="currentMousePosition">The current mouse position.</param>
			/// <param name="initialObjectHitPositionLocalCoordinates">The initial position in local coordinates where the object or the handle was hit.</param>
			/// <returns>A difference vector (in world coordinates) that can be used to move the object or handle around.</returns>
			/// <exception cref="System.ArgumentOutOfRangeException"></exception>
			public static VectorD3D GetMoveVectorInWorldCoordinates(HitTestPointData initialMousePosition, HitTestPointData currentMousePosition, PointD3D initialObjectHitPositionLocalCoordinates)
			{
				var m = initialMousePosition.HitTransformation; // initial ray position
				var n = currentMousePosition.HitTransformation;           // current ray position

				double x = initialObjectHitPositionLocalCoordinates.X;
				double y = initialObjectHitPositionLocalCoordinates.Y;
				double z = initialObjectHitPositionLocalCoordinates.Z;

				// For the mathematics behind the following, see internal document "3D_MoveObjectByMovingRay"

				double denom = m.M33 * n.M12 * n.M21 - m.M33 * n.M11 * n.M22 - m.M23 * n.M12 * n.M31 +
	 m.M13 * n.M22 * n.M31 + m.M23 * n.M11 * n.M32 - m.M13 * n.M21 * n.M32;

				if (0 == denom)
					throw new ArgumentOutOfRangeException();

				double dx = m.M23 * (-(m.M42 * n.M31) +
			n.M32 * (m.M41 - n.M41 + m.M11 * x - n.M11 * x + m.M21 * y -
				 n.M21 * y + m.M31 * z) +
			n.M31 * (n.M42 - m.M12 * x + n.M12 * x - m.M22 * y +
				 n.M22 * y - m.M32 * z)) +
	 m.M33 * (m.M42 * n.M21 -
			n.M22 * (m.M41 - n.M41 + m.M11 * x - n.M11 * x + m.M21 * y) -
			(m.M31 * n.M22 - n.M22 * n.M31 + n.M21 * n.M32) * z +
			n.M21 * (-n.M42 + m.M12 * x - n.M12 * x + m.M22 * y + m.M32 * z));

				double dy = m.M13 * (m.M42 * n.M31 - n.M32 *
			 (m.M41 - n.M41 + m.M11 * x - n.M11 * x + m.M21 * y -
				 n.M21 * y + m.M31 * z) +
			n.M31 * (-n.M42 + m.M12 * x - n.M12 * x + m.M22 * y -
				 n.M22 * y + m.M32 * z)) +
	 m.M33 * (-(m.M42 * n.M11) + n.M12 * (m.M41 - n.M41) +
			n.M12 * (m.M11 * x + m.M21 * y - n.M21 * y + m.M31 * z -
				 n.M31 * z) + n.M11 *
			 (n.M42 - m.M12 * x - m.M22 * y + n.M22 * y - m.M32 * z +
				 n.M32 * z));

				double dz = m.M13 * (-(m.M42 * n.M21) +
			n.M22 * (m.M41 - n.M41 + m.M11 * x - n.M11 * x + m.M21 * y) +
			(m.M31 * n.M22 - n.M22 * n.M31 + n.M21 * n.M32) * z +
			n.M21 * (n.M42 - m.M12 * x + n.M12 * x - m.M22 * y - m.M32 * z))
		 + m.M23 * (m.M42 * n.M11 + n.M12 * (-m.M41 + n.M41) -
			n.M12 * (m.M11 * x + m.M21 * y - n.M21 * y + m.M31 * z -
				 n.M31 * z) + n.M11 *
			 (-n.M42 + m.M12 * x + m.M22 * y - n.M22 * y + m.M32 * z -
				 n.M32 * z));

				var diff = new VectorD3D(dx / denom, dy / denom, dz / denom);
				return diff;
			}
Exemplo n.º 55
0
		public RectangleD3D GetTileRectangle(double columnPosX, double columnPosY, double columnPosZ,
			double columnSpanX, double columnSpanY, double columnSpanZ, VectorD3D totalSize)
		{
			double xstart, xsize;
			double ystart, ysize;
			double zstart, zsize;
			_xPartitioning.GetAbsolutePositionAndSizeFromGridIndexAndSpan(totalSize.X, columnPosX, columnSpanX, out xstart, out xsize);
			_yPartitioning.GetAbsolutePositionAndSizeFromGridIndexAndSpan(totalSize.Y, columnPosY, columnSpanY, out ystart, out ysize);
			_zPartitioning.GetAbsolutePositionAndSizeFromGridIndexAndSpan(totalSize.Z, columnPosZ, columnSpanZ, out zstart, out zsize);
			return new RectangleD3D(xstart, ystart, zstart, xsize, ysize, zsize);
		}
Exemplo n.º 56
0
		/// <summary>
		/// Creates a new camera with provided upVector and eyePosition.
		/// </summary>
		/// <param name="upVector">Up vector.</param>
		/// <param name="eyePosition">The eye position.</param>
		/// <returns>New camera with the provided parameters.</returns>
		public CameraBase WithUpEye(VectorD3D upVector, PointD3D eyePosition)
		{
			var result = (CameraBase)this.MemberwiseClone();
			result._upVector = upVector;
			result._eyePosition = eyePosition;
			return result;
		}
Exemplo n.º 57
0
		/// <summary>
		/// Creates a new camera with provided upVector, eyePosition, targetPosition, znear and  zfar distance..
		/// </summary>
		/// <param name="upVector">Up vector.</param>
		/// <param name="eyePosition">The eye position.</param>
		/// <param name="targetPosition">The target position.</param>
		/// <param name="zNear">The z near distance.</param>
		/// <param name="zFar">The z far distance.</param>
		/// <returns>New camera with the provided parameters.</returns>
		public CameraBase WithUpEyeTargetZNearZFar(VectorD3D upVector, PointD3D eyePosition, PointD3D targetPosition, double zNear, double zFar)
		{
			var result = (CameraBase)this.MemberwiseClone();
			result._upVector = upVector;
			result._eyePosition = eyePosition;
			result._targetPosition = targetPosition;
			result._zNear = zNear;
			result._zFar = zFar;
			return result;
		}
Exemplo n.º 58
0
		/// <summary>
		/// Initializes a new instance of the <see cref="DirectionalLight"/> class.
		/// </summary>
		/// <param name="lightAmplitude">The light amplitude.</param>
		/// <param name="color">The color of light.</param>
		/// <param name="directionToLight">The direction from the scene to the light.</param>
		/// <param name="isAffixedToCamera">Value indicating whether the light source is affixed to the camera coordinate system or the world coordinate system.</param>
		public DirectionalLight(double lightAmplitude, NamedColor color, VectorD3D directionToLight, bool isAffixedToCamera)
		{
			_isAffixedToCamera = isAffixedToCamera;

			VerifyLightAmplitude(lightAmplitude, nameof(lightAmplitude));
			_lightAmplitude = lightAmplitude;

			_color = color;

			var len = VerifyDirection(directionToLight, nameof(directionToLight));
			_directionToLight = directionToLight / len;
		}
Exemplo n.º 59
0
		/// <summary>
		/// Creates a new camera which has the LookAtRH matrix as provided in the argument. Up and eye vector as well as eye position are calculated from the provided matrix, the target position is calculated from the eye vector and the provided <paramref name="newDistance"/> value.
		/// </summary>
		/// <param name="l">The LookAtRH matrix. This matrix must have a determinant of 1, and each of the vectors {M11, M21, M31}, {M12, M22, M32}, {M13, M23, M33} must have a length of 1.</param>
		/// <param name="newDistance">The distance between camera eye and target of the new camera.</param>
		/// <returns>A new camera which has the LookAtRH matrix as provided in the argument. Up and eye vector as well as eye position are calculated from the provided matrix, the target position is calculated from the eye vector and the provided <paramref name="newDistance"/> value.</returns>
		/// <exception cref="ArgumentOutOfRangeException"></exception>
		public CameraBase WithLookAtRHMatrix(Matrix4x3 l, double newDistance)
		{
			double determinant = l.Determinant;

			if (!(determinant > 0.9 && determinant < 1.1))
				throw new ArgumentOutOfRangeException(nameof(l) + " seems not to be a LookAtRH matrix because its determinant is not 1");

			// get position
			var eyePos = new PointD3D(
			(l.M23 * l.M32 * l.M41 - l.M22 * l.M33 * l.M41 - l.M23 * l.M31 * l.M42 + l.M21 * l.M33 * l.M42 + l.M22 * l.M31 * l.M43 - l.M21 * l.M32 * l.M43) / determinant,
			(-(l.M13 * l.M32 * l.M41) + l.M12 * l.M33 * l.M41 + l.M13 * l.M31 * l.M42 - l.M11 * l.M33 * l.M42 - l.M12 * l.M31 * l.M43 + l.M11 * l.M32 * l.M43) / determinant,
			(l.M13 * l.M22 * l.M41 - l.M12 * l.M23 * l.M41 - l.M13 * l.M21 * l.M42 + l.M11 * l.M23 * l.M42 + l.M12 * l.M21 * l.M43 - l.M11 * l.M22 * l.M43) / determinant
			);

			var upVector = new VectorD3D(l.M12, l.M22, l.M32);
			var eyeVector = new VectorD3D(l.M13, l.M23, l.M33);

			return WithUpEyeTarget(upVector, eyePos, eyePos - eyeVector * newDistance);
		}
Exemplo n.º 60
0
		/// <summary>
		/// Gets a new instance of <see cref="DirectionalLight"/> with the provided value for <see cref="DirectionToLight"/>.
		/// </summary>
		/// <param name="directionToLight">The new value for <see cref="DirectionToLight"/>.</param>
		/// <returns>New instance of <see cref="DirectionalLight"/> with the provided value for <see cref="DirectionToLight"/></returns>
		public DirectionalLight WithDirectionToLight(VectorD3D directionToLight)
		{
			if (!(directionToLight == _directionToLight))
			{
				var len = VerifyDirection(directionToLight, nameof(directionToLight));

				var result = (DirectionalLight)this.MemberwiseClone();
				result._directionToLight = directionToLight / len;
				return result;
			}
			else
			{
				return this;
			}
		}