Example #1
0
        public void AddPoint(PointD3D point, bool isNextTransitionSharp)
        {
            var idx = _points.Count;

            _points.Add(point);

            var count = _isSharpTransition.Count;

            if (idx == count)
            {
                _isSharpTransition.Add(isNextTransitionSharp);
            }
            else if (idx < count)
            {
                _isSharpTransition[idx] = isNextTransitionSharp;
            }
            else
            {
                for (int i = count; i < idx; ++i)
                {
                    _isSharpTransition.Add(false);
                }
                _isSharpTransition[idx] = isNextTransitionSharp;
            }
        }
Example #2
0
		/// <summary>
		/// Handles the click event by opening the text tool dialog.
		/// </summary>
		/// <param name="e">EventArgs.</param>
		/// <param name="position">Mouse position.</param>
		/// <returns>The mouse state handler for handling the next mouse events.</returns>
		public override void OnClick(PointD3D position, MouseButtonEventArgs e)
		{
			base.OnClick(position, e);

			_cachedActiveLayer = _grac.ActiveLayer;
			_cachedActiveLayerTransformation = _cachedActiveLayer.TransformationFromRootToHere();

			PointD3D hitPointOnLayerPlaneInLayerCoordinates;
			VectorD3D rotationsRadian;
			GetHitPointOnActiveLayerPlaneFacingTheCamera(_grac.Doc, _grac.ActiveLayer, position, out hitPointOnLayerPlaneInLayerCoordinates, out rotationsRadian);

			TextGraphic tgo = new TextGraphic(_grac.Doc.GetPropertyContext());
			tgo.SetParentSize(_cachedActiveLayer.Size, false);
			tgo.Position = hitPointOnLayerPlaneInLayerCoordinates;

			tgo.RotationX = (rotationsRadian.X / Math.PI) * 180;
			tgo.RotationY = (rotationsRadian.Y / Math.PI) * 180;
			tgo.RotationZ = (rotationsRadian.Z / Math.PI) * 180;

			tgo.ParentObject = _grac.ActiveLayer;

			// deselect the text tool
			_grac.SetGraphToolFromInternal(GraphToolType.ObjectPointer);

			object tgoo = tgo;
			if (Current.Gui.ShowDialog(ref tgoo, "Text", false))
			{
				tgo = (TextGraphic)tgoo;
				if (tgo != null && !tgo.Empty)
				{
					_grac.ActiveLayer.GraphObjects.Add(tgo);
				}
			}
		}
Example #3
0
        public void DrawTriangle(IMaterial material, PointD3D p0, PointD3D p1, PointD3D p2)
        {
            var buffers = GetPositionNormalIndexedTriangleBuffer(Materials.GetSolidMaterialWithoutColorOrTexture());

            var offset = buffers.IndexedTriangleBuffer.VertexCount;

            if (null != buffers.PositionNormalColorIndexedTriangleBuffer)
            {
                var buf   = buffers.PositionNormalColorIndexedTriangleBuffer;
                var color = material.Color.Color;
                var r     = color.ScR;
                var g     = color.ScG;
                var b     = color.ScB;
                var a     = color.ScA;

                buf.AddTriangleVertex(p0.X, p0.Y, p0.Z, 0, 0, 1, r, g, b, a);
                buf.AddTriangleVertex(p1.X, p1.Y, p1.Z, 0, 0, 1, r, g, b, a);
                buf.AddTriangleVertex(p2.X, p2.Y, p2.Z, 0, 0, 1, r, g, b, a);

                buf.AddTriangleIndices(0, 1, 2);
                buf.AddTriangleIndices(0, 2, 1);
            }
            else
            {
                throw new NotImplementedException("Unexpected type of buffer: " + buffers.IndexedTriangleBuffer.GetType().ToString());
            }
        }
Example #4
0
 public virtual void PaintLine(IGraphicsContext3D g, PointD3D beg, PointD3D end)
 {
     if (null != _linePen)
     {
         g.DrawLine(_linePen, beg, end);
     }
 }
		/// <summary>
		/// Handles the drawing of a straight single line.
		/// </summary>
		/// <param name="position">Mouse position.</param>
		/// <param name="e">EventArgs.</param>
		/// <returns>The mouse state handler for handling the next mouse events.</returns>
		public override void OnClick(PointD3D position, MouseButtonEventArgs e)
		{
			base.OnClick(position, e);

			if (0 == _currentPoint)
			{
				_cachedActiveLayer = _grac.ActiveLayer;
				_cachedActiveLayerTransformation = _cachedActiveLayer.TransformationFromRootToHere();
			}

			PointD3D hitPointOnLayerPlaneInLayerCoordinates;
			VectorD3D rotationsRadian;
			GetHitPointOnActiveLayerPlaneFacingTheCamera(_grac.Doc, _grac.ActiveLayer, position, out hitPointOnLayerPlaneInLayerCoordinates, out rotationsRadian);
			_positionCurrentMouseInActiveLayerCoordinates = hitPointOnLayerPlaneInLayerCoordinates;

			_Points[_currentPoint] = _positionCurrentMouseInActiveLayerCoordinates;
			_currentPoint++;

			if (2 == _currentPoint)
			{
				FinishDrawing();
				_currentPoint = 0;
				_grac.SetGraphToolFromInternal(NextMouseHandlerType);
			}
		}
Example #6
0
		public static void DrawLine(PositionNormalIndexedTriangleBuffers buffers, PenX3D pen, PointD3D p0, PointD3D p1)
		{
			var vertexIndexOffset = buffers.IndexedTriangleBuffer.VertexCount;

			if (null != buffers.PositionNormalIndexedTriangleBuffer)
			{
				var buf = buffers.PositionNormalIndexedTriangleBuffer;
				/*
				if (pen.Color.Name == "Beige")
				{
				*/
				var solid = new SolidStraightLine();
				solid.AddGeometry(
					(position, normal) => buf.AddTriangleVertex(position.X, position.Y, position.Z, normal.X, normal.Y, normal.Z),
					(i0, i1, i2, isLeft) => buf.AddTriangleIndices(i0, i1, i2, isLeft),
					ref vertexIndexOffset,
					pen,
					new LineD3D(p0, p1));

				/*
			}
			else
			{
						var polylinePoints = new[] { p0, p1 };
				SolidPolyline.AddWithNormals(
				(position, normal) => buf.AddTriangleVertex(position.X, position.Y, position.Z, normal.X, normal.Y, normal.Z),
				(i0, i1, i2) => buf.AddTriangleIndices(i0, i1, i2),
				ref vertexIndexOffset,
				pen,
				polylinePoints);
			}
			*/
			}
			else if (null != buffers.PositionNormalColorIndexedTriangleBuffer)
			{
				var polylinePoints = new[] { p0, p1 };
				var buf = buffers.PositionNormalColorIndexedTriangleBuffer;
				var color = pen.Color.Color;
				var r = color.ScR;
				var g = color.ScG;
				var b = color.ScB;
				var a = color.ScA;

				var solidPolyline = new SolidPolyline();
				solidPolyline.AddWithNormals(
				(position, normal) => buf.AddTriangleVertex(position.X, position.Y, position.Z, normal.X, normal.Y, normal.Z, r, g, b, a),
				(i0, i1, i2, isLeftCOS) => buf.AddTriangleIndices(i0, i1, i2, isLeftCOS),
				ref vertexIndexOffset,
				pen,
				polylinePoints);
			}
			else if (null != buffers.PositionNormalUVIndexedTriangleBuffer)
			{
				throw new NotImplementedException("Texture on a line is not supported yet");
			}
			else
			{
				throw new NotImplementedException("Unexpected type of buffer: " + buffers.IndexedTriangleBuffer.GetType().ToString());
			}
		}
Example #7
0
        /// <summary>
        /// Determines whether the provided plane is hit by the ray (this is almost ever the case except if the plane's normal is perpendicular to the hit ray),
        /// and determines the point on the plane that is hit.
        /// </summary>
        /// <param name="plane">The plane.</param>
        /// <param name="planePointHit">The point on the plane that is hit (if the return value is true).</param>
        /// <returns>True if the plane is hit; otherwise false.</returns>
        public bool IsPlaneHitByRay(PlaneD3D plane, out PointD3D planePointHit)
        {
            plane = plane.Normalized;

            double pnX = plane.X;
            double pnY = plane.Y;
            double pnZ = plane.Z;

            var l = _hitTransformation;

            double denom = pnX * (l.M21 * l.M32 - l.M22 * l.M31) + pnY * (l.M12 * l.M31 - l.M11 * l.M32) + pnZ * (l.M11 * l.M22 - l.M12 * l.M21);

            if (0 == denom)
            {
                planePointHit = PointD3D.Empty;
                return(false);
            }

            // Point on the plane that is closest to orgin
            double ppX = plane.W * pnX;
            double ppY = plane.W * pnY;
            double ppZ = plane.W * pnZ;

            double numX = pnX * (-(l.M22 * l.M31 * ppX) + l.M21 * l.M32 * ppX) + pnY * (l.M32 * l.M41 - l.M31 * l.M42 - l.M22 * l.M31 * ppY + l.M21 * l.M32 * ppY) + pnZ * (-(l.M22 * l.M41) + l.M21 * l.M42 - l.M22 * l.M31 * ppZ + l.M21 * l.M32 * ppZ);
            double numY = pnX * (-(l.M32 * l.M41) + l.M31 * l.M42 + l.M12 * l.M31 * ppX - l.M11 * l.M32 * ppX) + pnY * (l.M12 * l.M31 * ppY - l.M11 * l.M32 * ppY) + pnZ * (l.M12 * l.M41 - l.M11 * l.M42 + l.M12 * l.M31 * ppZ - l.M11 * l.M32 * ppZ);
            double numZ = pnX * (l.M22 * l.M41 - l.M21 * l.M42 - l.M12 * l.M21 * ppX + l.M11 * l.M22 * ppX) + pnY * (-(l.M12 * l.M41) + l.M11 * l.M42 - l.M12 * l.M21 * ppY + l.M11 * l.M22 * ppY) + pnZ * (-(l.M12 * l.M21 * ppZ) + l.M11 * l.M22 * ppZ);

            planePointHit = new PointD3D(numX / denom, numY / denom, numZ / denom);
            return(true);
        }
Example #8
0
        public virtual bool CopyFrom(object obj)
        {
            if (object.ReferenceEquals(this, obj))
            {
                return(true);
            }
            var from = obj as GraphicBase;

            if (null == from)
            {
                return(false);
            }

            using (var suspendToken = SuspendGetToken())
            {
                _cachedParentSize = from._cachedParentSize;
                _location.CopyFrom(from._location);
                bool wasUsed = (null != _parent);
                //this._parent = from._parent;
                UpdateTransformationMatrix();

                if (wasUsed)
                {
                    _accumulatedEventData = EventArgs.Empty;
                    suspendToken.Resume();
                }
                else
                {
                    suspendToken.ResumeSilently();
                }
            }

            return(true);
        }
Example #9
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);
        }
Example #10
0
        /// <summary>
        /// Gets a matrix for a hit point on the screen. The hit point is given in relative screen coordinates (X and Y component, 0..1). The screen's aspect ratio is given in the Z component.
        /// The result is a matrix which transforms world coordinates in that way that the hit ray in world coordinates is transformed to x=0 and y=0 and z being the distance to the camera.
        /// </summary>
        /// <param name="relativeScreenPosition">The relative screen position (X and Y component), as well as the screen's aspect ratio (Z component).</param>
        /// <returns>
        /// Matrix which transforms world coordinates in that way that the hit ray in world coordinates is transformed to x=0 and y=0 and z being the distance to the camera.
        /// </returns>
        public override Matrix4x4 GetHitRayMatrix(PointD3D relativeScreenPosition)
        {
            double relX = relativeScreenPosition.X * 2 - 1; // relative Screen Position from -1..1
            double relY = relativeScreenPosition.Y * 2 - 1; // relative Screen Position from -1..1

            return(GetViewProjectionMatrix(relativeScreenPosition.Z, ZNear, ZFar, -relX, -relY));
        }
Example #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;
        }
Example #12
0
 /// <summary>
 /// Verifies the validity of the position value.
 /// </summary>
 /// <param name="value">The position of the light.</param>
 /// <param name="valueName">The name of the parameter.</param>
 /// <exception cref="ArgumentOutOfRangeException">
 /// </exception>
 private void VerifyPosition(PointD3D value, string valueName)
 {
     if (value.IsNaN)
     {
         throw new ArgumentOutOfRangeException(valueName + " is a struct with invalid elements");
     }
 }
Example #13
0
        /// <summary>
        /// 返回将 ColorX 结构表示的两种颜色在 HSL 色彩空间按指定比例线性混合得到的颜色。
        /// </summary>
        /// <param name="color1">ColorX 结构表示的第一种颜色。</param>
        /// <param name="color2">ColorX 结构表示的第二种颜色。</param>
        /// <param name="proportion">第一种颜色所占的比例,取值范围为 [0, 1] 或 (1, 100]。</param>
        /// <returns>ColorX 结构,表示将两种颜色在 HSL 色彩空间按指定比例线性混合得到的颜色。</returns>
        public static ColorX BlendByHSL(ColorX color1, ColorX color2, double proportion)
        {
            proportion = _CheckProportion(proportion);

            PointD3D hsl1 = color1.HSL;
            PointD3D hsl2 = color2.HSL;

            double deltaHue = hsl1.X - hsl2.X;

            if (deltaHue < -180)
            {
                deltaHue += 360;
            }
            else if (deltaHue > 180)
            {
                deltaHue -= 360;
            }

            double newHue = hsl2.X + deltaHue * proportion;

            if (newHue < 0)
            {
                newHue += 360;
            }
            else if (newHue >= 360)
            {
                newHue -= 360;
            }

            return(ColorX.FromHSL(newHue, hsl1.Y * proportion + hsl2.Y * (1 - proportion), hsl1.Z * proportion + hsl2.Z * (1 - proportion), color1.Opacity * proportion + color2.Opacity * (1 - proportion)));
        }
Example #14
0
            public override void Draw(IGraphicsContext3D g, DrawContext dc, double xbase, double ybase, double zbase)
            {
                var mylayer = (HostLayer)dc.LinkedObject;

                var layer = mylayer as XYZPlotLayer;

                if (_layerNumber >= 0 && mylayer.SiblingLayers != null && _layerNumber < mylayer.SiblingLayers.Count)
                {
                    layer = mylayer.SiblingLayers[_layerNumber] as XYZPlotLayer;
                }

                if (null == layer)
                {
                    return;
                }

                if (_plotNumber < layer.PlotItems.Flattened.Length)
                {
                    var        fontInfo = dc.FontCache.GetFontInfo(Style.FontId);
                    IGPlotItem pa       = layer.PlotItems.Flattened[_plotNumber];

                    var symbolpos  = new PointD3D(xbase, (ybase + 0.5 * fontInfo.cyDescent - 0.5 * fontInfo.cyAscent), 0);
                    var symbolRect = new RectangleD3D(symbolpos, new VectorD3D(SizeX, 0, 0));
                    symbolRect = symbolRect.WithPadding(0, fontInfo.Size, 0);
                    pa.PaintSymbol(g, symbolRect);

                    if (!dc.bForPreview)
                    {
                        var volume = new RectangleTransformedD3D(
                            new RectangleD3D(symbolpos.X, symbolpos.Y - 0.5 * fontInfo.cyLineSpace, 0, SizeX, fontInfo.cyLineSpace, 0), dc.transformMatrix);
                        dc._cachedSymbolPositions.Add(volume, pa);
                    }
                }
            }
Example #15
0
		public EmbeddedImageGraphic(PointD3D graphicPosition, ImageProxy startingImage)
			:
			this()
		{
			this.SetPosition(graphicPosition, Main.EventFiring.Suppressed);
			this.Image = startingImage;
		}
Example #16
0
 public EmbeddedImageGraphic(PointD3D graphicPosition, ImageProxy startingImage)
     :
     this()
 {
     SetPosition(graphicPosition, Main.EventFiring.Suppressed);
     Image = startingImage;
 }
Example #17
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);
        }
Example #18
0
        /// <summary>
        /// Handles the click event by opening the text tool dialog.
        /// </summary>
        /// <param name="e">EventArgs.</param>
        /// <param name="position">Mouse position.</param>
        /// <returns>The mouse state handler for handling the next mouse events.</returns>
        public override void OnClick(PointD3D position, MouseButtonEventArgs e)
        {
            base.OnClick(position, e);

            _cachedActiveLayer = _grac.ActiveLayer;
            _cachedActiveLayerTransformation = _cachedActiveLayer.TransformationFromRootToHere();
            GetHitPointOnActiveLayerPlaneFacingTheCamera(_grac.Doc, _grac.ActiveLayer, position, out var hitPointOnLayerPlaneInLayerCoordinates, out var rotationsRadian);

            var tgo = new TextGraphic(_grac.Doc.GetPropertyContext());

            tgo.SetParentSize(_cachedActiveLayer.Size, false);
            tgo.Position = hitPointOnLayerPlaneInLayerCoordinates;

            tgo.RotationX = (rotationsRadian.X / Math.PI) * 180;
            tgo.RotationY = (rotationsRadian.Y / Math.PI) * 180;
            tgo.RotationZ = (rotationsRadian.Z / Math.PI) * 180;

            tgo.ParentObject = _grac.ActiveLayer;

            // deselect the text tool
            _grac.CurrentGraphTool = GraphToolType.ObjectPointer;

            object tgoo = tgo;

            if (Current.Gui.ShowDialog(ref tgoo, "Text", false))
            {
                tgo = (TextGraphic)tgoo;
                if (tgo != null && !tgo.Empty)
                {
                    _grac.ActiveLayer.GraphObjects.Add(tgo);
                }
            }
        }
Example #19
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);
		}
Example #20
0
        // return index of point in the middle of p1 and p2
        private int GetMiddlePoint(int p1, int p2)
        {
            // first check if we have it already
            bool  firstIsSmaller = p1 < p2;
            long  smallerIndex   = firstIsSmaller ? p1 : p2;
            long  greaterIndex   = firstIsSmaller ? p2 : p1;
            Int64 key            = (smallerIndex << 32) + greaterIndex;

            if (_middlePointIndexCache.TryGetValue(key, out var ret))
            {
                return(ret);
            }

            // not in cache, calculate it
            PointD3D point1 = _geometry_Positions[p1];
            PointD3D point2 = _geometry_Positions[p2];
            var      middle = new PointD3D(
                (point1.X + point2.X) / 2.0,
                (point1.Y + point2.Y) / 2.0,
                (point1.Z + point2.Z) / 2.0);

            // add vertex makes sure point is on unit sphere
            int i = AddVertex(middle);

            // store it, return index
            _middlePointIndexCache.Add(key, i);
            return(i);
        }
Example #21
0
        // add vertex to mesh, fix position to be on unit sphere, return index
        private int AddVertex(PointD3D p)
        {
            double length = Math.Sqrt(p.X * p.X + p.Y * p.Y + p.Z * p.Z);

            _geometry_Positions.Add(new PointD3D(p.X / length, p.Y / length, p.Z / length));
            return(_index++);
        }
Example #22
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);
        }
Example #23
0
        /// <summary>
        /// Creates a new camera with provided  eyePosition and targetPosition;
        /// </summary>
        /// <param name="eyePosition">The eye position.</param>
        /// <param name="targetPosition">The target position.</param>
        /// <returns>New camera with the provided parameters.</returns>
        public CameraBase WithEyeTarget(PointD3D eyePosition, PointD3D targetPosition)
        {
            var result = (CameraBase)MemberwiseClone();

            result._eyePosition    = eyePosition;
            result._targetPosition = targetPosition;
            return(result);
        }
Example #24
0
		public LineShape(PointD3D startPosition, PointD3D endPosition, Altaxo.Main.Properties.IReadOnlyPropertyBag context)
			:
			this(startPosition, context)
		{
			this._location.SizeX = RADouble.NewAbs(endPosition.X - startPosition.X);
			this._location.SizeY = RADouble.NewAbs(endPosition.Y - startPosition.Y);
			this._location.SizeZ = RADouble.NewAbs(endPosition.Z - startPosition.Z);
		}
Example #25
0
 public LineShape(PointD3D startPosition, PointD3D endPosition, Altaxo.Main.Properties.IReadOnlyPropertyBag context)
     :
     this(startPosition, context)
 {
     _location.SizeX = RADouble.NewAbs(endPosition.X - startPosition.X);
     _location.SizeY = RADouble.NewAbs(endPosition.Y - startPosition.Y);
     _location.SizeZ = RADouble.NewAbs(endPosition.Z - startPosition.Z);
 }
Example #26
0
 /// <summary>
 /// Sets the position of the object's pivot point.
 /// </summary>
 /// <param name="value">The position to set (the object's pivot point) with reference to the parent's reference point).</param>
 /// <param name="eventFiring">Designates whether or not the change event should be fired if the value has changed.</param>
 protected virtual void SetPosition(PointD3D value, Main.EventFiring eventFiring)
 {
     _location.SetAbsolutePivotPosition(value, eventFiring);
     if (eventFiring == Main.EventFiring.Suppressed)
     {
         UpdateTransformationMatrix(); // even if events are suppressed - update at least the transformation matrix
     }
 }
Example #27
0
 public TextGraphic(PointD3D graphicPosition, string text, FontX3D textFont, NamedColor textColor)
     : base(new ItemLocationDirectAutoSize())
 {
     SetPosition(graphicPosition, Main.EventFiring.Suppressed);
     Font  = textFont;
     Text  = text;
     Color = textColor;
 }
Example #28
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;
 }
Example #29
0
 public LineShape(PointD3D startPosition, PointD3D endPosition, double lineWidth, NamedColor lineColor)
     :
     this(startPosition, null)
 {
     _location.SizeX = RADouble.NewAbs(endPosition.X - startPosition.X);
     _location.SizeY = RADouble.NewAbs(endPosition.Y - startPosition.Y);
     _location.SizeZ = RADouble.NewAbs(endPosition.Z - startPosition.Z);
     _linePen        = _linePen.WithUniformThickness(lineWidth).WithColor(lineColor);
 }
Example #30
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;
		}
Example #31
0
        /// <summary>
        /// Creates a new camera with provided  eyePosition and targetPosition;
        /// </summary>
        /// <param name="eyePosition">The eye position.</param>
        /// <param name="targetPosition">The target position.</param>
        /// <param name="widthAtZNear">The width of the view field at <see cref="CameraBase.ZNear"/>. (Since this is an orthographic camera, the width it constant for all distances, thus this is also the width for <see cref="CameraBase.ZFar"/>).</param>
        /// <returns>New camera with the provided parameters.</returns>
        public OrthographicCamera WithEyeTargetWidth(PointD3D eyePosition, PointD3D targetPosition, double widthAtZNear)
        {
            var result = (OrthographicCamera)MemberwiseClone();

            result._eyePosition    = eyePosition;
            result._targetPosition = targetPosition;
            result._widthAtZNear   = widthAtZNear;
            return(result);
        }
			/// <summary>
			/// Activates this grip, providing the initial position of the mouse.
			/// </summary>
			/// <param name="initialPosition">Initial position of the mouse.</param>
			/// <param name="isActivatedUponCreation">If true the activation is called right after creation of this handle. If false,
			/// thie activation is due to a regular mouse click in this grip.</param>
			public void Activate(HitTestPointData initialPosition, bool isActivatedUponCreation)
			{
				if (null == initialPosition)
					throw new ArgumentNullException(nameof(initialPosition));

				_wasActivatedUponCreation = isActivatedUponCreation;
				_initialMousePosition = initialPosition;
				_initialObjectPosition = ((GraphicBase)_parent.HittedObject).Position;
				_hasMoved = false;
			}
			/// <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;
			}
            /// <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;
            }
Example #35
0
 private void EhSphericalValueChanged(object sender, EventArgs e)
 {
     _lock.ExecuteLockedButOnlyIfNotLockedBefore(
         () =>
     {
         _position = _guiSpherical.SelectedValue;
         _guiCartesian.SelectedValue = _position;
     },
         () => SelectedValueChanged?.Invoke(this, EventArgs.Empty)
         );
 }
Example #36
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);
        }
Example #37
0
        public void Paint(IGraphicsContext3D g, IPlotArea layer, Processed3DPlotData pdata, Processed3DPlotData prevItemData, Processed3DPlotData nextItemData)
        {
            PlotRangeList rangeList = pdata.RangeList;
            var           ptArray   = pdata.PlotPointsInAbsoluteLayerCoordinates;

            // adjust the skip frequency if it was not set appropriate
            if (_skipFreq <= 0)
            {
                _skipFreq = 1;
            }

            // paint the scatter style
            if (!ScatterSymbols.NoSymbol.Instance.Equals(_symbolShape))
            {
                PointD3D pos = PointD3D.Empty;

                if (null == _cachedSymbolSizeForIndexFunction && null == _cachedColorForIndexFunction) // using a constant symbol size
                {
                    for (int r = 0; r < rangeList.Count; r++)
                    {
                        var range = rangeList[r];
                        int lower = range.LowerBound;
                        int upper = range.UpperBound;
                        for (int j = lower; j < upper; j += _skipFreq)
                        {
                            _symbolShape.Paint(g, _material, ptArray[j], _symbolSize);
                        } // end for all points in range
                    }     // end for all ranges
                }
                else      // using a variable symbol size or variable symbol color
                {
                    for (int r = 0; r < rangeList.Count; r++)
                    {
                        int lower  = rangeList[r].LowerBound;
                        int upper  = rangeList[r].UpperBound;
                        int offset = rangeList[r].OffsetToOriginal;
                        for (int j = lower; j < upper; j += _skipFreq)
                        {
                            if (null == _cachedColorForIndexFunction)
                            {
                                double customSymbolSize = _cachedSymbolSizeForIndexFunction(j + offset);
                                _symbolShape.Paint(g, _material, ptArray[j], customSymbolSize);
                            }
                            else
                            {
                                double customSymbolSize  = null == _cachedSymbolSizeForIndexFunction ? _symbolSize : _cachedSymbolSizeForIndexFunction(j + offset);
                                var    customSymbolColor = _cachedColorForIndexFunction(j + offset);
                                _symbolShape.Paint(g, _material.WithColor(NamedColor.FromArgb(customSymbolColor.A, customSymbolColor.R, customSymbolColor.G, customSymbolColor.B)), ptArray[j], customSymbolSize);
                            }
                        }
                    }
                }
            }
        }
Example #38
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 virtual void Draw(IGraphicsContext3D g, IMaterial brush, PointD3D point)
            {
                g.DrawString(_firstpart, _font1, brush, point);

                point = point.WithXPlus(_size1.X);

                g.DrawString(_exponent, _font2, brush, point.WithYPlus(_size1.Y - _size2.Y));

                point = point.WithXPlus(_size2.X);

                g.DrawString(_lastpart, _font1, brush, point);
            }
Example #40
0
		public override void Paint(IGraphicsContext3D g, IMaterial material, PointD3D centerLocation, double symbolSize)
		{
			// Note: the symbolSize provided in the argument is the diameter of an imaginary sphere in which the cube has to fit in
			// thus the cube's diagonal should be equal to the sphere's diameter

			var size = symbolSize * Sqrt1By3; // size of the cube
			var sizeBy2 = size * 0.5;
			var buffers = g.GetPositionNormalIndexedTriangleBuffer(material);
			if (null != buffers.PositionNormalIndexedTriangleBuffer)
			{
				var buf = buffers.PositionNormalIndexedTriangleBuffer;
				var voffs = buffers.PositionNormalIndexedTriangleBuffer.VertexCount;
				SolidCube.Add(
					centerLocation.X - sizeBy2, centerLocation.Y - sizeBy2, centerLocation.Z - sizeBy2,
					size, size, size,
					(point, normal) => buf.AddTriangleVertex(point.X, point.Y, point.Z, normal.X, normal.Y, normal.Z),
					(i1, i2, i3) => buf.AddTriangleIndices(i1 + voffs, i2 + voffs, i3 + voffs),
					ref voffs);
			}
		}
Example #41
0
		public override void Paint(IGraphicsContext3D g, IMaterial material, PointD3D centerLocation, double symbolSize)
		{
			var radius = symbolSize / 2;
			var buffers = g.GetPositionNormalIndexedTriangleBuffer(material);

			if (null != buffers.PositionNormalIndexedTriangleBuffer)
			{
				var buffer = buffers.PositionNormalIndexedTriangleBuffer;
				var offs = buffer.VertexCount;

				foreach (var entry in GetVerticesAndNormals())
				{
					var pt = centerLocation + radius * entry.Item1;
					var nm = entry.Item2;
					buffer.AddTriangleVertex(pt.X, pt.Y, pt.Z, nm.X, nm.Y, nm.Z);
				}
				foreach (var idx in GetTriangleIndices())
				{
					buffer.AddTriangleIndices(idx.Item1 + offs, idx.Item2 + offs, idx.Item3 + offs);
				}
			}
		}
Example #42
0
		public void AddPoint(PointD3D point, bool isNextTransitionSharp)
		{
			var idx = _points.Count;

			_points.Add(point);

			var count = _isSharpTransition.Count;
			if (idx == count)
			{
				_isSharpTransition.Add(isNextTransitionSharp);
			}
			else if (idx < count)
			{
				_isSharpTransition[idx] = isNextTransitionSharp;
			}
			else
			{
				for (int i = count; i < idx; ++i)
					_isSharpTransition.Add(false);
				_isSharpTransition[idx] = isNextTransitionSharp;
			}
		}
		/// <summary>
		/// Handles the click event by opening the text tool dialog.
		/// </summary>
		/// <param name="e">EventArgs.</param>
		/// <param name="position">Mouse position.</param>
		/// <returns>The mouse state handler for handling the next mouse events.</returns>
		public override void OnClick(PointD3D position, MouseButtonEventArgs e)
		{
			base.OnClick(position, e);

			_cachedActiveLayer = _grac.ActiveLayer;
			_cachedActiveLayerTransformation = _cachedActiveLayer.TransformationFromRootToHere();

			PointD3D hitPointOnLayerPlaneInLayerCoordinates;
			VectorD3D rotationsRadian;
			GetHitPointOnActiveLayerPlaneFacingTheCamera(_grac.Doc, _grac.ActiveLayer, position, out hitPointOnLayerPlaneInLayerCoordinates, out rotationsRadian);

			double sphereDiameter = _cachedActiveLayer.Size.Length / 10;
			Ellipsoid tgo = new Ellipsoid();
			tgo.SetParentSize(_cachedActiveLayer.Size, false);
			tgo.Size = new VectorD3D(sphereDiameter, sphereDiameter, sphereDiameter);
			tgo.Position = hitPointOnLayerPlaneInLayerCoordinates;
			tgo.ParentObject = _grac.ActiveLayer;

			// deselect the text tool
			_grac.SetGraphToolFromInternal(GraphToolType.ObjectPointer);

			_grac.ActiveLayer.GraphObjects.Add(tgo);
		}
Example #44
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);
		}
			/// <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;
			}
Example #46
0
		public void TestZoom1_XY()
		{
			double aspectRatio = 1.0;
			double cameraDistanceOriginal = 1000;
			double zNear = 100;
			double zFar = 10000;
			double widthByZNear = 0.5;
			double distanceFactor = 0.75;
			PointD3D cameraPosition = new PointD3D(0, 0, cameraDistanceOriginal);
			PointD3D targetPosition = new PointD3D(0, 0, 0);
			PointD3D worldPoint = new PointD3D(200, 200, 0);

			var cameraO = new PerspectiveCamera(new VectorD3D(0, 1, 0), cameraPosition, targetPosition, zNear, zFar, widthByZNear * zNear);

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

			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);
		}
Example #47
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);
		}
Example #48
0
		public OrthographicCamera(VectorD3D upVector, PointD3D eyePosition, PointD3D targetPosition, double zNear, double zFar, double widthAtZNear)
						: base(upVector, eyePosition, targetPosition, zNear, zFar, widthAtZNear)
		{
		}
Example #49
0
		/// <summary>
		/// Gets a matrix for a hit point on the screen. The hit point is given in relative screen coordinates (X and Y component, 0..1). The screen's aspect ratio is given in the Z component.
		/// The result is a matrix which transforms world coordinates in that way that the hit ray in world coordinates is transformed to x=0 and y=0 and z being the distance to the camera.
		/// </summary>
		/// <param name="relativeScreenPosition">The relative screen position (X and Y component), as well as the screen's aspect ratio (Z component).</param>
		/// <returns>
		/// Matrix which transforms world coordinates in that way that the hit ray in world coordinates is transformed to x=0 and y=0 and z being the distance to the camera.
		/// </returns>
		public override Matrix4x4 GetHitRayMatrix(PointD3D relativeScreenPosition)
		{
			double relX = relativeScreenPosition.X * 2 - 1; // relative Screen Position from -1..1
			double relY = relativeScreenPosition.Y * 2 - 1; // relative Screen Position from -1..1
			return GetViewProjectionMatrix(relativeScreenPosition.Z, ZNear, ZFar, -relX, -relY);
		}
Example #50
0
		/// <summary>
		/// Creates a new camera with provided  eyePosition and targetPosition;
		/// </summary>
		/// <param name="eyePosition">The eye position.</param>
		/// <param name="targetPosition">The target position.</param>
		/// <param name="widthAtZNear">The width of the view field at <see cref="CameraBase.ZNear"/>. (Since this is an orthographic camera, the width it constant for all distances, thus this is also the width for <see cref="CameraBase.ZFar"/>).</param>
		/// <returns>New camera with the provided parameters.</returns>
		public OrthographicCamera WithEyeTargetWidth(PointD3D eyePosition, PointD3D targetPosition, double widthAtZNear)
		{
			var result = (OrthographicCamera)this.MemberwiseClone();
			result._eyePosition = eyePosition;
			result._targetPosition = targetPosition;
			result._widthAtZNear = widthAtZNear;
			return result;
		}
Example #51
0
		public PointD3D TransformPoint(PointD3D p)
		{
			return Transform(p);
		}
Example #52
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;
		}
Example #53
0
		/// <summary>
		/// Inverse transform a point p in such a way that the result will fullfill the relation p = result * matrix ( the * operator being the prepend transformation for points).
		/// </summary>
		/// <param name="p">The point p to inverse transform.</param>
		/// <returns>The inverse transformation of point <paramref name="p"/>.</returns>
		public PointD3D InverseTransform(PointD3D p)
		{
			return new PointD3D(
					(M23 * (M32 * (M41 - p.X) + M31 * (-M42 + p.Y)) + M22 * (-(M33 * M41) + M31 * M43 + M33 * p.X - M31 * p.Z) + M21 * (M33 * M42 - M32 * M43 - M33 * p.Y + M32 * p.Z)) / Determinant,

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

					(M13 * (M22 * (M41 - p.X) + M21 * (-M42 + p.Y)) + M12 * (-(M23 * M41) + M21 * M43 + M23 * p.X - M21 * p.Z) + M11 * (M23 * M42 - M22 * M43 - M23 * p.Y + M22 * p.Z)) / Determinant
					);
		}
Example #54
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;
		}
Example #55
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;
		}
Example #56
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);
		}
Example #57
0
		/// <summary>
		/// Creates a new camera with provided  eyePosition and targetPosition;
		/// </summary>
		/// <param name="eyePosition">The eye position.</param>
		/// <param name="targetPosition">The target position.</param>
		/// <returns>New camera with the provided parameters.</returns>
		public CameraBase WithEyeTarget(PointD3D eyePosition, PointD3D targetPosition)
		{
			var result = (CameraBase)this.MemberwiseClone();
			result._eyePosition = eyePosition;
			result._targetPosition = targetPosition;
			return result;
		}
Example #58
0
		/// <summary>
		/// Transforms the specified point <paramref name="p"/>. For a point transform, the offset elements M41..M43 are used.
		/// The transformation is carried out as a prepend transformation, i.e. result = p * matrix (p considered as horizontal vector).
		/// </summary>
		/// <param name="p">The point to transform.</param>
		/// <returns>The transformed point.</returns>
		public PointD3D Transform(PointD3D p)
		{
			double x = p.X;
			double y = p.Y;
			double z = p.Z;
			return new PointD3D(
			x * M11 + y * M21 + z * M31 + M41,
			x * M12 + y * M22 + z * M32 + M42,
			x * M13 + y * M23 + z * M33 + M43
			);
		}
Example #59
0
		/// <summary>
		/// Gets a matrix for a hit point on the screen. The hit point is given in relative coordinates (X and Y component). The screen's aspect ratio is given in the Z component.
		/// The result is a matrix which transforms world coordinates in that way that the hit ray in world coordinates is transformed to x=0 and y=0 and z being the distance to the camera.
		/// </summary>
		/// <param name="relativeScreenPosition">The relative screen position (X and Y component), as well as the screen's aspect ratio (Z component).</param>
		/// <returns>Matrix which transforms world coordinates in that way that the hit ray in world coordinates is transformed to x=0 and y=0 and z being the distance to the camera.</returns>
		public abstract Matrix4x4 GetHitRayMatrix(PointD3D relativeScreenPosition);
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="layerCoordinates"></param>
		/// <param name="rowIndex"></param>
		/// <param name="plotIndex"></param>
		public XYZScatterPointInformation(PointD3D layerCoordinates, int rowIndex, int plotIndex)
		{
			_layerCoordinates = layerCoordinates;
			_rowIndex = rowIndex;
			_plotIndex = plotIndex;
		}