Exemplo n.º 1
0
        internal void GenerateColliders(float playfieldHeight, List <ICollider> colliders, float margin = 0f)
        {
            var vVertex = DragPoint.GetRgVertex <RenderVertex2D, CatmullCurve2DCatmullCurveFactory>(_component.DragPoints);

            var count  = vVertex.Length;
            var rgv3Dt = new float3[count];
            var rgv3Db = _colliderComponent.IsBottomSolid ? new float3[count] : null;

            var bottom = _component.HeightBottom + playfieldHeight - margin;
            var top    = _component.HeightTop + playfieldHeight + margin;

            for (var i = 0; i < count; ++i)
            {
                var pv1 = vVertex[i];
                rgv3Dt[i] = new float3(pv1.X, pv1.Y, top);

                if (rgv3Db != null)
                {
                    rgv3Db[count - 1 - i] = new float3(pv1.X, pv1.Y, bottom);
                }

                var pv2 = vVertex[(i + 1) % count];
                var pv3 = vVertex[(i + 2) % count];
                GenerateLinePolys(pv2, pv3, playfieldHeight, colliders);
            }

            ColliderUtils.Generate3DPolyColliders(in rgv3Dt, _api.GetColliderInfo(), colliders);

            if (rgv3Db != null)
            {
                ColliderUtils.Generate3DPolyColliders(in rgv3Db, _api.GetColliderInfo(), colliders);
            }
        }
Exemplo n.º 2
0
 private void TimelineForm_MouseUp(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         drag = null;
     }
 }
        private void PictureBox1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            var canvasInfo = this.GetCanvasInformation();
            var width      = 0.04;
            var height     = 0.06;

            var x = (e.X - canvasInfo.OffsetX + (width * canvasInfo.ScaledWidth / 2)) / canvasInfo.ScaledWidth;
            var y = (e.Y - canvasInfo.OffsetY + (height * canvasInfo.ScaledHeight / 2)) / canvasInfo.ScaledHeight;

            if (this._annotationImage.BoundingBoxes == null)
            {
                this._annotationImage.BoundingBoxes = new List <AnnotationBoundingBox>();
            }

            var newBoundingBox = new AnnotationBoundingBox
            {
                CenterX = (float)x,
                CenterY = (float)y,
                Height  = (float)height,
                Width   = (float)width
            };

            this._annotationImage.BoundingBoxes.Add(newBoundingBox);
            this._dragPoint = null;
            this.ImageEdited?.Invoke(this._annotationImage);
        }
Exemplo n.º 4
0
		// The base class gathers mouse events and calls AnalyzeGesture()

		protected override bool AddFiltered(Util.WinForms.DragState state_, DragPoint dp)
		{
			DragState state = (DragState)state_;
			if (state.ClickedShape != null && state.ClickedShape.AllowsDrag)
				return false; // gesture recognition is off
			return base.AddFiltered(state, dp);
		}
Exemplo n.º 5
0
        private void TimelineForm_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                drag = dragablepoint.Find(n => n.rect.Contains(e.Location));
                if (drag != null)
                {
                    draglocation = e.Location;
                    switch (drag.dragpoint)
                    {
                    case TimelineType.Interval:
                        dragvalue = drag.skill.adjustment;
                        break;

                    case TimelineType.EffectStart:
                        dragvalue = drag.skill.effect.delay;
                        break;

                    case TimelineType.EffectEnd:
                        dragvalue = drag.skill.effect.duration;
                        break;

                    default:
                        drag = null;
                        break;
                    }
                }
            }
        }
        public RenderVertex3D[] GetCentralCurve(Table.Table table, float acc = -1.0f)
        {
            float accuracy;

            // as solid ramps are rendered into the static buffer, always use maximum precision
            if (acc != -1.0)
            {
                accuracy = acc;                 // used for hit shape calculation, always!
            }
            else
            {
                var mat = table.GetMaterial(_data.Material);
                if (mat == null || !mat.IsOpacityActive)
                {
                    accuracy = 10.0f;
                }
                else
                {
                    accuracy = table.GetDetailLevel();
                }
            }

            // min = 4 (highest accuracy/detail level), max = 4 * 10^(10/1.5) = ~18.000.000 (lowest accuracy/detail level)
            accuracy = 4.0f * MathF.Pow(10.0f, (10.0f - accuracy) * (1.0f / 1.5f));
            return(DragPoint.GetRgVertex <RenderVertex3D, CatmullCurve3DCatmullCurveFactory>(_data.DragPoints, false, accuracy));
        }
        private void CreateBoundingBox(PointF point1, PointF point2)
        {
            var canvasInfo = this.GetCanvasInformation();

            var topLeftCorner     = new PointF(Math.Min(point1.X, point2.X), Math.Min(point1.Y, point2.Y));
            var bottomRightCorner = new PointF(Math.Max(point1.X, point2.X), Math.Max(point1.Y, point2.Y));

            topLeftCorner     = this.ClampPoint(topLeftCorner);
            bottomRightCorner = this.ClampPoint(bottomRightCorner);

            var width  = (bottomRightCorner.X - topLeftCorner.X) / canvasInfo.ScaledWidth;
            var height = (bottomRightCorner.Y - topLeftCorner.Y) / canvasInfo.ScaledHeight;

            var x = (topLeftCorner.X - canvasInfo.OffsetX + (width * canvasInfo.ScaledWidth / 2)) / canvasInfo.ScaledWidth;
            var y = (topLeftCorner.Y - canvasInfo.OffsetY + (height * canvasInfo.ScaledHeight / 2)) / canvasInfo.ScaledHeight;

            if (this._annotationImage.BoundingBoxes == null)
            {
                this._annotationImage.BoundingBoxes = new List <AnnotationBoundingBox>();
            }

            var newBoundingBox = new AnnotationBoundingBox
            {
                CenterX = (float)x,
                CenterY = (float)y,
                Width   = (float)width,
                Height  = (float)height
            };

            this._selectedBoundingBox = newBoundingBox;

            this._annotationImage.BoundingBoxes.Add(newBoundingBox);
            this._dragPoint = null;
            this.ImageEdited?.Invoke(this._annotationImage);
        }
        private HitObject[] GenerateCurvedHitObjects(Table.Table table, IItem item)
        {
            var hitObjects = new List <HitObject>();
            var height     = table.GetSurfaceHeight(_data.Surface, _data.Center.X, _data.Center.Y);
            var vVertex    = DragPoint.GetRgVertex <RenderVertex2D, CatmullCurve2DCatmullCurveFactory>(_data.DragPoints);

            var count = vVertex.Length;
            var rgv   = new RenderVertex2D[count];
            var rgv3D = new Vertex3D[count];

            for (var i = 0; i < count; i++)
            {
                rgv[i]   = vVertex[i];
                rgv3D[i] = new Vertex3D(rgv[i].X, rgv[i].Y, height + (float)(PhysicsConstants.PhysSkin * 2.0));
            }

            for (var i = 0; i < count; i++)
            {
                var pv2 = rgv[i < count - 1 ? i + 1 : 0];
                var pv3 = rgv[i < count - 2 ? i + 2 : i + 2 - count];
                hitObjects.Add(GetLineSeg(pv2, pv3, height, item));
            }

            hitObjects.AddRange(new Hit3DPoly(rgv3D, ItemType.Trigger, item).ConvertToTriangles());

            return(hitObjects.ToArray());
        }
Exemplo n.º 9
0
        // The base class gathers mouse events and calls AnalyzeGesture()

        protected override bool AddFiltered(Util.WinForms.DragState state_, DragPoint dp)
        {
            DragState state = (DragState)state_;

            if (state.ClickedShape != null && state.ClickedShape.AllowsDrag)
            {
                return(false);                // gesture recognition is off
            }
            return(base.AddFiltered(state, dp));
        }
        private void PictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (this._annotationImage?.BoundingBoxes == null)
            {
                return;
            }

            var drawOffset = this._mouseDragElementSize / 2;
            var canvasInfo = this.GetCanvasInformation();

            var boundingBoxes = this._annotationImage?.BoundingBoxes;

            if (boundingBoxes == null)
            {
                return;
            }

            foreach (var boundingBox in boundingBoxes)
            {
                var width  = boundingBox.Width * canvasInfo.ScaledWidth;
                var height = (boundingBox.Height * canvasInfo.ScaledHeight);
                var x      = (boundingBox.CenterX * canvasInfo.ScaledWidth) - (width / 2) + canvasInfo.OffsetX;
                var y      = (boundingBox.CenterY * canvasInfo.ScaledHeight) - (height / 2) + canvasInfo.OffsetY;

                var rectangle = new Rectangle((int)x, (int)y, (int)width, (int)height);

                var startDrag = false;

                var dragPoints = this.GetDragPoints(rectangle, drawOffset);
                foreach (var dragPoint in dragPoints)
                {
                    if (this.PointDistance(this._mousePosition, new Point(dragPoint.Point.X, dragPoint.Point.Y)) < 15)
                    {
                        this._dragPoint = dragPoint;
                        startDrag       = true;
                        break;
                    }
                }

                if (startDrag)
                {
                    this._selectedBoundingBox = boundingBox;
                    break;
                }
                else
                {
                    this._dragPoint           = null;
                    this._selectedBoundingBox = null;
                }
            }

            this._mousePosition = e.Location;
            this.pictureBox1.Invalidate();
        }
Exemplo n.º 11
0
 public void OnMouseDown()
 {
     if (WireSceneController.I.HasWon)
     {
         return;
     }
     m_callback?.Invoke();
     m_puller = Instantiate(m_pullerPrefab, transform.position, Quaternion.identity);
     //m_puller.DropCallback += StartRecursiveInverseBreak;
     StartRecursiveInverseConnect(m_puller.Body);
     SetWireGravity(false);
     m_callback = StartRecursiveInverseBreak;
 }
Exemplo n.º 12
0
        private static RenderVertex2D[] GetCentralCurve(DragPointData[] dragPoints, int tableDetailLevel, float acc, bool staticRendering = true, bool loop = true)
        {
            float accuracy;

            // as solid rubbers are rendered into the static buffer, always use maximum precision
            if (acc != -1.0f)
            {
                accuracy = acc;                 // used for hit shape calculation, always!
            }
            else
            {
                accuracy = staticRendering ? 10.0f : tableDetailLevel;

                // min = 4 (highest accuracy/detail level), max = 4 * 10^(10/1.5) = ~18.000.000 (lowest accuracy/detail level)
                accuracy = 4.0f * MathF.Pow(10.0f, (10.0f - accuracy) * (float)(1.0 / 1.5));
            }

            return(DragPoint.GetRgVertex <RenderVertex2D, CatmullCurve2DCatmullCurveFactory>(dragPoints, loop, accuracy));
        }
Exemplo n.º 13
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (0 <= toolTipTime && drag == null)
            {
                toolTipTime += timer1.Interval;

                if (skillToolTip.AutomaticDelay < toolTipTime)
                {
                    var position = prevPosition;
                    tooltip = dragablepoint.Find(n => n.rect.Contains(position));

                    //                    var mouse = this.PointToClient(System.Windows.Forms.Cursor.Position);
                    if (tooltip != null)
                    {
                        skillToolTip.Show(tooltip.Infomation(), this, position);
                    }
                    toolTipTime = -1;
                }
            }
        }
        private void GenerateCurvedHitObjects(ICollection <ICollider> colliders)
        {
            var height  = _component.PositionZ;
            var vVertex = DragPoint.GetRgVertex <RenderVertex2D, CatmullCurve2DCatmullCurveFactory>(_component.DragPoints);

            var count = vVertex.Length;
            var rgv   = new RenderVertex2D[count];
            var rgv3D = new float3[count];

            for (var i = 0; i < count; i++)
            {
                rgv[i]   = vVertex[i];
                rgv3D[i] = new float3(rgv[i].X, rgv[i].Y, height + (float)(PhysicsConstants.PhysSkin * 2.0));
            }
            ColliderUtils.Generate3DPolyColliders(rgv3D, _api.GetColliderInfo(), colliders);

            for (var i = 0; i < count; i++)
            {
                var pv2 = rgv[i < count - 1 ? i + 1 : 0];
                var pv3 = rgv[i < count - 2 ? i + 2 : i + 2 - count];
                AddLineSeg(pv2.ToUnityFloat2(), pv3.ToUnityFloat2(), height, colliders);
            }
        }
        /// <summary>
        /// Returns all hit objects for the surface.
        /// </summary>
        private HitObject[] Generate3DPolys(Table.Table table, IItem item)
        {
            var hitObjects = new List <HitObject>();

            var vVertex = DragPoint.GetRgVertex <RenderVertex2D, CatmullCurve2DCatmullCurveFactory>(_data.DragPoints);

            var count  = vVertex.Length;
            var rgv3Dt = new Vertex3D[count];
            var rgv3Db = _data.IsBottomSolid ? new Vertex3D[count] : null;

            var bottom = _data.HeightBottom + table.TableHeight;
            var top    = _data.HeightTop + table.TableHeight;

            for (var i = 0; i < count; ++i)
            {
                var pv1 = vVertex[i];
                rgv3Dt[i] = new Vertex3D(pv1.X, pv1.Y, top);

                if (rgv3Db != null)
                {
                    rgv3Db[count - 1 - i] = new Vertex3D(pv1.X, pv1.Y, bottom);
                }

                var pv2 = vVertex[(i + 1) % count];
                var pv3 = vVertex[(i + 2) % count];
                hitObjects.AddRange(GenerateLinePolys(pv2, pv3, table, item));
            }

            hitObjects.AddRange(new Hit3DPoly(rgv3Dt, ItemType.Surface, item).ConvertToTriangles());

            if (rgv3Db != null)
            {
                hitObjects.AddRange(new Hit3DPoly(rgv3Db, ItemType.Surface, item).ConvertToTriangles());
            }

            return(hitObjects.ToArray());
        }
Exemplo n.º 16
0
 public void AddDrag(DragPoint drag)
 {
     lstDragPoints.Add(drag);
 }
        /// <summary>
        /// Construct & display the curve from DragPointsHandler control points
        /// Find the curve traveller position along the curve
        /// </summary>
        ///
        /// <remarks>
        /// Will use the DragPointExposure from the handler's item to display slingshot segments accordingly
        /// Will update handler's curve traveller position and control point base index for point insertion
        /// </remarks>
        private void DisplayCurve()
        {
            List <Vector3>[] controlPointsSegments = new List <Vector3> [_handler.ControlPoints.Count].Select(item => new List <Vector3>()).ToArray();

            // Display Curve & handle curve traveller
            if (_handler.ControlPoints.Count > 1)
            {
                var transformedDPoints = new List <DragPointData>();
                foreach (var controlPoint in _handler.ControlPoints)
                {
                    var newDp = new DragPointData(controlPoint.DragPoint)
                    {
                        Center = controlPoint.WorldPos.ToVertex3D()
                    };
                    transformedDPoints.Add(newDp);
                }

                var vAccuracy = Vector3.one;
                vAccuracy = _handler.Transform.localToWorldMatrix.MultiplyVector(vAccuracy);
                var accuracy = Mathf.Abs(vAccuracy.x * vAccuracy.y * vAccuracy.z);
                accuracy *= HandleUtility.GetHandleSize(_handler.CurveTravellerPosition) * ControlPoint.ScreenRadius;
                var vVertex = DragPoint.GetRgVertex <RenderVertex3D, CatmullCurve3DCatmullCurveFactory>(
                    transformedDPoints.ToArray(), _handler.DragPointInspector.PointsAreLooping, accuracy
                    );

                if (vVertex.Length > 0)
                {
                    // Fill Control points paths
                    ControlPoint currentControlPoint = null;
                    foreach (var v in vVertex)
                    {
                        if (v.IsControlPoint)
                        {
                            if (currentControlPoint != null)
                            {
                                controlPointsSegments[currentControlPoint.Index].Add(v.ToUnityVector3());
                            }
                            currentControlPoint = _handler.ControlPoints.Find(cp => cp.WorldPos == v.ToUnityVector3());
                        }
                        if (currentControlPoint != null)
                        {
                            controlPointsSegments[currentControlPoint.Index].Add(v.ToUnityVector3());
                        }
                    }

                    // close loop if needed
                    if (_handler.DragPointInspector.PointsAreLooping)
                    {
                        controlPointsSegments[_handler.ControlPoints.Count - 1].Add(controlPointsSegments[0][0]);
                    }

                    // construct full path
                    _pathPoints.Clear();
                    const float splitRatio = 0.1f;
                    foreach (var controlPoint in _handler.ControlPoints)
                    {
                        // Split straight segments to avoid HandleUtility.ClosestPointToPolyLine issues
                        ref var segments = ref controlPointsSegments[controlPoint.Index];
                        if (segments.Count == 2)
                        {
                            var dir  = segments[1] - segments[0];
                            var dist = dir.magnitude;
                            dir = Vector3.Normalize(dir);
                            var newPath = new List <Vector3> {
                                segments[0]
                            };
                            for (var splitDist = dist * splitRatio; splitDist < dist; splitDist += dist * splitRatio)
                            {
                                newPath.Add(newPath[0] + dir * splitDist);
                            }
                            newPath.Add(segments[1]);
                            segments = newPath;
                        }
                        _pathPoints.AddRange(segments);
                    }

                    _curveTravellerMoved = false;
                    if (_pathPoints.Count > 1)
                    {
                        var newPos = HandleUtility.ClosestPointToPolyLine(_pathPoints.ToArray());
                        if ((newPos - _handler.CurveTravellerPosition).magnitude >= HandleUtility.GetHandleSize(_handler.CurveTravellerPosition) * ControlPoint.ScreenRadius * CurveTravellerSizeRatio * 0.1f)
                        {
                            _handler.CurveTravellerPosition = newPos;
                            _curveTravellerMoved            = true;
                        }
                    }

                    // Render Curve with correct color regarding drag point properties & find curve section where the curve traveller is
                    _handler.CurveTravellerControlPointIdx = -1;
                    var minDist = float.MaxValue;
                    foreach (var controlPoint in _handler.ControlPoints)
                    {
                        var segments = controlPointsSegments[controlPoint.Index].ToArray();
                        if (segments.Length > 1)
                        {
                            Handles.color = _handler.DragPointInspector.DragPointExposition.Contains(DragPointExposure.SlingShot) && controlPoint.DragPoint.IsSlingshot ? CurveSlingShotColor : CurveColor;
                            Handles.DrawAAPolyLine(CurveWidth, segments);
                            var closestToPath = HandleUtility.ClosestPointToPolyLine(segments);
                            var dist          = (closestToPath - _handler.CurveTravellerPosition).magnitude;
                            if (dist < minDist)
                            {
                                minDist = dist;
                                _handler.CurveTravellerControlPointIdx = controlPoint.Index;
                            }
                        }
                    }
                }
            }
        private void PictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            var startDrag = false;

            this._createBoundingBox = false;

            var boundingBoxes = this._annotationImage?.BoundingBoxes;

            if (boundingBoxes != null)
            {
                var drawOffset = this._mouseDragElementSize / 2;
                var canvasInfo = this.GetCanvasInformation();

                var orderedBoundingBoxes = this.OrderBoundingBoxes(boundingBoxes);

                foreach (var boundingBox in orderedBoundingBoxes)
                {
                    this._draggedBoundingBox = null;
                    this._dragPoint          = null;

                    var width  = boundingBox.Width * canvasInfo.ScaledWidth;
                    var height = (boundingBox.Height * canvasInfo.ScaledHeight);
                    var x      = (boundingBox.CenterX * canvasInfo.ScaledWidth) - (width / 2) + canvasInfo.OffsetX;
                    var y      = (boundingBox.CenterY * canvasInfo.ScaledHeight) - (height / 2) + canvasInfo.OffsetY;

                    var rectangle = new Rectangle((int)x, (int)y, (int)width, (int)height);

                    var biggerRectangle = Rectangle.Inflate(rectangle, 20, 20);
                    if (biggerRectangle.Contains(this._mousePosition))
                    {
                        startDrag = true;

                        this._grabOffsetX = (this._mousePosition.X - rectangle.X) / canvasInfo.ScaledWidth;
                        this._grabOffsetY = (this._mousePosition.Y - rectangle.Y) / canvasInfo.ScaledHeight;
                    }

                    var dragPoints = this.GetDragPoints(rectangle, drawOffset);
                    foreach (var dragPoint in dragPoints)
                    {
                        if (this.PointDistance(this._mousePosition, new Point(dragPoint.Point.X, dragPoint.Point.Y)) < this._maxMouseDistanceToDragPoint)
                        {
                            this._dragPoint = dragPoint;

                            startDrag = true;

                            this._grabOffsetX = (this._dragPoint.Point.X - rectangle.X) / canvasInfo.ScaledWidth;
                            this._grabOffsetY = (this._dragPoint.Point.Y - rectangle.Y) / canvasInfo.ScaledHeight;

                            this._mouseOffsetX = this._dragPoint.Point.X - this._mousePosition.X;
                            this._mouseOffsetY = this._dragPoint.Point.Y - this._mousePosition.Y;

                            break;
                        }
                    }

                    if (startDrag)
                    {
                        this._selectedBoundingBox = boundingBox;
                        this._draggedBoundingBox  = boundingBox;
                        this._selectedObjectRect  = new RectangleF(rectangle.X / (float)canvasInfo.ScaledWidth, rectangle.Y / (float)canvasInfo.ScaledHeight,
                                                                   rectangle.Width / (float)canvasInfo.ScaledWidth, rectangle.Height / (float)canvasInfo.ScaledHeight);

                        break;
                    }
                }
            }

            if (!startDrag)
            {
                this._createBoundingBox = true;
                this._creationPoint     = e.Location;
            }

            this._mousePosition = e.Location;
            this.rotatingPictureBox.Invalidate();
        }
Exemplo n.º 19
0
        private Dictionary <string, Mesh> GenerateMeshes(Table.Table table)
        {
            var meshes   = new Dictionary <string, Mesh>();
            var topMesh  = new Mesh("Top");
            var sideMesh = new Mesh("Side");

            var vVertex    = DragPoint.GetRgVertex <RenderVertex2D, CatmullCurve2DCatmullCurveFactory>(_data.DragPoints);
            var rgTexCoord = DragPoint.GetTextureCoords(_data.DragPoints, vVertex);

            var numVertices = vVertex.Length;
            var rgNormal    = new Vertex2D[numVertices];

            for (var i = 0; i < numVertices; i++)
            {
                var pv1 = vVertex[i];
                var pv2 = vVertex[i < numVertices - 1 ? i + 1 : 0];
                var dx  = pv1.X - pv2.X;
                var dy  = pv1.Y - pv2.Y;

                var invLen = 1.0f / MathF.Sqrt(dx * dx + dy * dy);

                rgNormal[i] = new Vertex2D {
                    X = dy * invLen, Y = dx * invLen
                };
            }

            var bottom = _data.HeightBottom * table.GetScaleZ() + table.TableHeight;
            var top    = _data.HeightTop * table.GetScaleZ() + table.TableHeight;

            var offset = 0;

            // Render side
            sideMesh.Vertices = new Vertex3DNoTex2[numVertices * 4];
            for (var i = 0; i < numVertices; i++)
            {
                var pv1 = vVertex[i];
                var pv2 = vVertex[i < numVertices - 1 ? i + 1 : 0];

                var a = i == 0 ? numVertices - 1 : i - 1;
                var c = i < numVertices - 1 ? i + 1 : 0;

                var vNormal = new [] { new Vertex2D(), new Vertex2D() };
                if (pv1.Smooth)
                {
                    vNormal[0].X = (rgNormal[a].X + rgNormal[i].X) * 0.5f;
                    vNormal[0].Y = (rgNormal[a].Y + rgNormal[i].Y) * 0.5f;
                }
                else
                {
                    vNormal[0].X = rgNormal[i].X;
                    vNormal[0].Y = rgNormal[i].Y;
                }

                if (pv2.Smooth)
                {
                    vNormal[1].X = (rgNormal[i].X + rgNormal[c].X) * 0.5f;
                    vNormal[1].Y = (rgNormal[i].Y + rgNormal[c].Y) * 0.5f;
                }
                else
                {
                    vNormal[1].X = rgNormal[i].X;
                    vNormal[1].Y = rgNormal[i].Y;
                }

                vNormal[0].Normalize();
                vNormal[1].Normalize();

                sideMesh.Vertices[offset]     = new Vertex3DNoTex2();
                sideMesh.Vertices[offset + 1] = new Vertex3DNoTex2();
                sideMesh.Vertices[offset + 2] = new Vertex3DNoTex2();
                sideMesh.Vertices[offset + 3] = new Vertex3DNoTex2();

                sideMesh.Vertices[offset].X     = pv1.X;
                sideMesh.Vertices[offset].Y     = pv1.Y;
                sideMesh.Vertices[offset].Z     = bottom;
                sideMesh.Vertices[offset + 1].X = pv1.X;
                sideMesh.Vertices[offset + 1].Y = pv1.Y;
                sideMesh.Vertices[offset + 1].Z = top;
                sideMesh.Vertices[offset + 2].X = pv2.X;
                sideMesh.Vertices[offset + 2].Y = pv2.Y;
                sideMesh.Vertices[offset + 2].Z = top;
                sideMesh.Vertices[offset + 3].X = pv2.X;
                sideMesh.Vertices[offset + 3].Y = pv2.Y;
                sideMesh.Vertices[offset + 3].Z = bottom;

                if (_data.SideImage != null)
                {
                    sideMesh.Vertices[offset].Tu = rgTexCoord[i];
                    sideMesh.Vertices[offset].Tv = 1.0f;

                    sideMesh.Vertices[offset + 1].Tu = rgTexCoord[i];
                    sideMesh.Vertices[offset + 1].Tv = 0f;

                    sideMesh.Vertices[offset + 2].Tu = rgTexCoord[c];
                    sideMesh.Vertices[offset + 2].Tv = 0f;

                    sideMesh.Vertices[offset + 3].Tu = rgTexCoord[c];
                    sideMesh.Vertices[offset + 3].Tv = 1.0f;
                }

                sideMesh.Vertices[offset].Nx = vNormal[0].X;
                sideMesh.Vertices[offset].Ny = -vNormal[0].Y;
                sideMesh.Vertices[offset].Nz = 0f;

                sideMesh.Vertices[offset + 1].Nx = vNormal[0].X;
                sideMesh.Vertices[offset + 1].Ny = -vNormal[0].Y;
                sideMesh.Vertices[offset + 1].Nz = 0f;

                sideMesh.Vertices[offset + 2].Nx = vNormal[1].X;
                sideMesh.Vertices[offset + 2].Ny = -vNormal[1].Y;
                sideMesh.Vertices[offset + 2].Nz = 0f;

                sideMesh.Vertices[offset + 3].Nx = vNormal[1].X;
                sideMesh.Vertices[offset + 3].Ny = -vNormal[1].Y;
                sideMesh.Vertices[offset + 3].Nz = 0f;

                offset += 4;
            }

            // prepare index buffer for sides
            var offset2 = 0;

            sideMesh.Indices = new int[numVertices * 6];
            for (var i = 0; i < numVertices; i++)
            {
                sideMesh.Indices[i * 6]     = offset2;
                sideMesh.Indices[i * 6 + 1] = offset2 + 1;
                sideMesh.Indices[i * 6 + 2] = offset2 + 2;
                sideMesh.Indices[i * 6 + 3] = offset2;
                sideMesh.Indices[i * 6 + 4] = offset2 + 2;
                sideMesh.Indices[i * 6 + 5] = offset2 + 3;

                offset2 += 4;
            }

            // draw top
            var vPoly = new List <int>(new int[numVertices]);

            for (var i = 0; i < numVertices; i++)
            {
                vPoly[i] = i;
            }

            topMesh.Indices = Mesh.PolygonToTriangles(vVertex, vPoly);

            var numPolys = topMesh.Indices.Length / 3;

            if (numPolys == 0)
            {
                // no polys to render leave vertex buffer undefined
                return(meshes);
            }

            var heightNotDropped = _data.HeightTop * table.GetScaleZ();
            var heightDropped    = _data.HeightBottom * table.GetScaleZ() + 0.1;

            var invTableWidth  = 1.0f / table.Width;
            var invTableHeight = 1.0f / table.Height;

            Vertex3DNoTex2[][] vertsTop = { new Vertex3DNoTex2[numVertices], new Vertex3DNoTex2[numVertices], new Vertex3DNoTex2[numVertices] };
            for (var i = 0; i < numVertices; i++)
            {
                var pv0 = vVertex[i];

                vertsTop[0][i] = new Vertex3DNoTex2 {
                    X  = pv0.X,
                    Y  = pv0.Y,
                    Z  = heightNotDropped + table.TableHeight,
                    Tu = pv0.X * invTableWidth,
                    Tv = pv0.Y * invTableHeight,
                    Nx = 0,
                    Ny = 0,
                    Nz = 1.0f
                };

                vertsTop[1][i] = new Vertex3DNoTex2 {
                    X  = pv0.X,
                    Y  = pv0.Y,
                    Z  = (float)heightDropped,
                    Tu = pv0.X * invTableWidth,
                    Tv = pv0.Y * invTableHeight,
                    Nx = 0,
                    Ny = 0,
                    Nz = 1.0f
                };

                vertsTop[2][i] = new Vertex3DNoTex2 {
                    X  = pv0.X,
                    Y  = pv0.Y,
                    Z  = _data.HeightBottom,
                    Tu = pv0.X * invTableWidth,
                    Tv = pv0.Y * invTableHeight,
                    Nx = 0,
                    Ny = 0,
                    Nz = -1.0f
                };
            }
            topMesh.Vertices = vertsTop[0];

            if (topMesh.Vertices.Length > 0)
            {
                meshes["Top"] = topMesh;
            }
            if (System.Math.Abs(top - bottom) > 0.00001f)
            {
                meshes["Side"] = sideMesh;
            }
            return(meshes);
        }
        private Mesh GenerateSideMesh(Table.Table table)
        {
            var sideMesh = new Mesh("Side");

            var vVertex    = DragPoint.GetRgVertex <RenderVertex2D, CatmullCurve2DCatmullCurveFactory>(_data.DragPoints);
            var rgTexCoord = DragPoint.GetTextureCoords(_data.DragPoints, vVertex);

            var numVertices = vVertex.Length;
            var rgNormal    = new Vertex2D[numVertices];

            for (var i = 0; i < numVertices; i++)
            {
                var pv1 = vVertex[i];
                var pv2 = vVertex[i < numVertices - 1 ? i + 1 : 0];
                var dx  = pv1.X - pv2.X;
                var dy  = pv1.Y - pv2.Y;

                if (dx != 0.0f || dy != 0.0f)
                {
                    var invLen = 1.0f / MathF.Sqrt(dx * dx + dy * dy);
                    rgNormal[i] = new Vertex2D {
                        X = dy * invLen, Y = dx * invLen
                    };
                }
                else
                {
                    rgNormal[i] = new Vertex2D {
                        X = 0.0f, Y = 0.0f
                    };
                }
            }

            var bottom = _data.HeightBottom * table.GetScaleZ() + table.TableHeight;
            var top    = _data.HeightTop * table.GetScaleZ() + table.TableHeight;

            var offset = 0;

            // Render side
            sideMesh.Vertices = new Vertex3DNoTex2[numVertices * 4];
            for (var i = 0; i < numVertices; i++)
            {
                var pv1 = vVertex[i];
                var pv2 = vVertex[i < numVertices - 1 ? i + 1 : 0];

                var a = i == 0 ? numVertices - 1 : i - 1;
                var c = i < numVertices - 1 ? i + 1 : 0;

                var vNormal = new [] { new Vertex2D(), new Vertex2D() };
                if (pv1.Smooth)
                {
                    vNormal[0].X = (rgNormal[a].X + rgNormal[i].X) * 0.5f;
                    vNormal[0].Y = (rgNormal[a].Y + rgNormal[i].Y) * 0.5f;
                }
                else
                {
                    vNormal[0].X = rgNormal[i].X;
                    vNormal[0].Y = rgNormal[i].Y;
                }

                if (pv2.Smooth)
                {
                    vNormal[1].X = (rgNormal[i].X + rgNormal[c].X) * 0.5f;
                    vNormal[1].Y = (rgNormal[i].Y + rgNormal[c].Y) * 0.5f;
                }
                else
                {
                    vNormal[1].X = rgNormal[i].X;
                    vNormal[1].Y = rgNormal[i].Y;
                }

                vNormal[0].Normalize();
                vNormal[1].Normalize();

                sideMesh.Vertices[offset]     = new Vertex3DNoTex2();
                sideMesh.Vertices[offset + 1] = new Vertex3DNoTex2();
                sideMesh.Vertices[offset + 2] = new Vertex3DNoTex2();
                sideMesh.Vertices[offset + 3] = new Vertex3DNoTex2();

                sideMesh.Vertices[offset].X     = pv1.X;
                sideMesh.Vertices[offset].Y     = pv1.Y;
                sideMesh.Vertices[offset].Z     = bottom;
                sideMesh.Vertices[offset + 1].X = pv1.X;
                sideMesh.Vertices[offset + 1].Y = pv1.Y;
                sideMesh.Vertices[offset + 1].Z = top;
                sideMesh.Vertices[offset + 2].X = pv2.X;
                sideMesh.Vertices[offset + 2].Y = pv2.Y;
                sideMesh.Vertices[offset + 2].Z = top;
                sideMesh.Vertices[offset + 3].X = pv2.X;
                sideMesh.Vertices[offset + 3].Y = pv2.Y;
                sideMesh.Vertices[offset + 3].Z = bottom;

                if (_data.SideImage != null)
                {
                    sideMesh.Vertices[offset].Tu = rgTexCoord[i];
                    sideMesh.Vertices[offset].Tv = 1.0f;

                    sideMesh.Vertices[offset + 1].Tu = rgTexCoord[i];
                    sideMesh.Vertices[offset + 1].Tv = 0f;

                    sideMesh.Vertices[offset + 2].Tu = rgTexCoord[c];
                    sideMesh.Vertices[offset + 2].Tv = 0f;

                    sideMesh.Vertices[offset + 3].Tu = rgTexCoord[c];
                    sideMesh.Vertices[offset + 3].Tv = 1.0f;
                }

                sideMesh.Vertices[offset].Nx = vNormal[0].X;
                sideMesh.Vertices[offset].Ny = -vNormal[0].Y;
                sideMesh.Vertices[offset].Nz = 0f;

                sideMesh.Vertices[offset + 1].Nx = vNormal[0].X;
                sideMesh.Vertices[offset + 1].Ny = -vNormal[0].Y;
                sideMesh.Vertices[offset + 1].Nz = 0f;

                sideMesh.Vertices[offset + 2].Nx = vNormal[1].X;
                sideMesh.Vertices[offset + 2].Ny = -vNormal[1].Y;
                sideMesh.Vertices[offset + 2].Nz = 0f;

                sideMesh.Vertices[offset + 3].Nx = vNormal[1].X;
                sideMesh.Vertices[offset + 3].Ny = -vNormal[1].Y;
                sideMesh.Vertices[offset + 3].Nz = 0f;

                offset += 4;
            }

            // prepare index buffer for sides
            var offset2 = 0;

            sideMesh.Indices = new int[numVertices * 6];
            for (var i = 0; i < numVertices; i++)
            {
                sideMesh.Indices[i * 6]     = offset2;
                sideMesh.Indices[i * 6 + 1] = offset2 + 1;
                sideMesh.Indices[i * 6 + 2] = offset2 + 2;
                sideMesh.Indices[i * 6 + 3] = offset2;
                sideMesh.Indices[i * 6 + 4] = offset2 + 2;
                sideMesh.Indices[i * 6 + 5] = offset2 + 3;

                offset2 += 4;
            }

            return(sideMesh);
        }
        private Mesh GenerateTopMesh(Table.Table table)
        {
            var topMesh = new Mesh("Top");
            var vVertex = DragPoint.GetRgVertex <RenderVertex2D, CatmullCurve2DCatmullCurveFactory>(_data.DragPoints);

            var numVertices = vVertex.Length;
            var rgNormal    = new Vertex2D[numVertices];

            for (var i = 0; i < numVertices; i++)
            {
                var pv1 = vVertex[i];
                var pv2 = vVertex[i < numVertices - 1 ? i + 1 : 0];
                var dx  = pv1.X - pv2.X;
                var dy  = pv1.Y - pv2.Y;

                if (dx != 0.0f || dy != 0.0f)
                {
                    var invLen = 1.0f / MathF.Sqrt(dx * dx + dy * dy);
                    rgNormal[i] = new Vertex2D {
                        X = dy * invLen, Y = dx * invLen
                    };
                }
                else
                {
                    rgNormal[i] = new Vertex2D {
                        X = 0.0f, Y = 0.0f
                    };
                }
            }

            // draw top
            var vPoly = new List <int>(new int[numVertices]);

            for (var i = 0; i < numVertices; i++)
            {
                vPoly[i] = i;
            }

            topMesh.Indices = Mesh.PolygonToTriangles(vVertex, vPoly);
            var numPolys = topMesh.Indices.Length / 3;

            if (numPolys == 0)
            {
                // no polys to render leave vertex buffer undefined
                return(null);
            }

            var heightNotDropped = _data.HeightTop * table.GetScaleZ();
            var heightDropped    = _data.HeightBottom * table.GetScaleZ() + 0.1;

            var invTableWidth  = 1.0f / table.Width;
            var invTableHeight = 1.0f / table.Height;

            Vertex3DNoTex2[][] vertsTop = { new Vertex3DNoTex2[numVertices], new Vertex3DNoTex2[numVertices], new Vertex3DNoTex2[numVertices] };
            for (var i = 0; i < numVertices; i++)
            {
                var pv0 = vVertex[i];

                vertsTop[0][i] = new Vertex3DNoTex2 {
                    X  = pv0.X,
                    Y  = pv0.Y,
                    Z  = heightNotDropped + table.TableHeight,
                    Tu = pv0.X * invTableWidth,
                    Tv = pv0.Y * invTableHeight,
                    Nx = 0,
                    Ny = 0,
                    Nz = 1.0f
                };

                vertsTop[1][i] = new Vertex3DNoTex2 {
                    X  = pv0.X,
                    Y  = pv0.Y,
                    Z  = (float)heightDropped,
                    Tu = pv0.X * invTableWidth,
                    Tv = pv0.Y * invTableHeight,
                    Nx = 0,
                    Ny = 0,
                    Nz = 1.0f
                };

                vertsTop[2][i] = new Vertex3DNoTex2 {
                    X  = pv0.X,
                    Y  = pv0.Y,
                    Z  = _data.HeightBottom,
                    Tu = pv0.X * invTableWidth,
                    Tv = pv0.Y * invTableHeight,
                    Nx = 0,
                    Ny = 0,
                    Nz = -1.0f
                };
            }
            topMesh.Vertices = vertsTop[0];

            return(topMesh);
        }
Exemplo n.º 22
0
            public bool MouseMove(MouseEventArgs e)
            {
                float xr = Math.Min(Math.Max((float)(e.X - Bounds.X) / (float)Bounds.Width, 0.0f), 1.0f);

                if(dragSplitterIndex != -1)
                {
                    Vector3 vpos = Vector3.Transform(new Vector3(2.0f * xr - 1.0f, 0.0f, 0.0f), invtransform);
                    xr = vpos.X / 2.0f + 0.5f;

                    ActionManager.Do(MovePinAction, new object[] { dragSplitterIndex, xr });
                }
                else if(colorTableMgr.GetCursor() == CursorType.DragPoint)
                {
                    Vector3 vpos = Vector3.Transform(new Vector3(2.0f * xr - 1.0f, 0.0f, 0.0f), invtransform);
                    xr = vpos.X / 2.0f + 0.5f;

                    xr = (xr - dragPointSection.start.pos) / (dragPointSection.end.pos - dragPointSection.start.pos);
                    xr -= dragOffset;

                    if(dragPoint == DragPoint.Start)
                    {
                        xr = Math.Min(xr, 0.0f);
                        dragPointSection.startValue = xr;
                    }
                    else if(dragPoint == DragPoint.End)
                    {
                        xr = Math.Max(xr, 1.0f);
                        dragPointSection.endValue = xr;
                    }
                    ColormapChanged(dragPointSection.start.pos, dragPointSection.end.pos);
                }
                else if(colorTableMgr.GetCursor() != CursorType.InsertSplitterPin && colorTableMgr.GetCursor() != CursorType.InsertNestedPin)
                {
                    if(colorTableMgr.GetCursor() == CursorType.MoveView)
                    {
                        xr = 1.0f - 2.0f * xr;

                        Matrix4 transform_noscale = transform;
                        transform_noscale.M11 = 1.0f;

                        Vector3 t0, tm0 ;
                        tm0 = Vector3.Transform(new Vector3(xr, 0.0f, 0.0f), transform_noscale);
                        t0 = Vector3.Transform(new Vector3(0.0f, 0.0f, 0.0f), transform_noscale);

                        tm0 = Vector3.Subtract(tmd0, tm0);
                        tm0 = Vector3.Add(tm0, t0);

                        tm0 = Vector3.Transform(tm0, invtransform);

                        transform *= Matrix4.CreateTranslation(tm0);
                        restrictTransform(ref transform);
                        Matrix4.Invert(ref transform, out invtransform);

                        //					repositionHistogramLabels();
                    }
                    else
                    {
                        Vector3 vpos = Vector3.Transform(new Vector3(2.0f * xr - 1.0f, 0.0f, 0.0f), invtransform);
                        xr = vpos.X / 2.0f + 0.5f;

                        dragPointSection = null;
                        dragPoint = DragPoint.None;

                        // Set move mouse cursor if a splitter is close to xr
                        var tolearance = 10.0f * invtransform.M11 / (float)BackbufferSize.Width; // Grab tolerance is +- 10 pixels
                        int splitterIdx;
                        for(splitterIdx = 0; splitterIdx < splitters.Count; ++splitterIdx)
                            if(!splitters[splitterIdx].isfixed && Math.Abs(splitters[splitterIdx].pos - xr) < tolearance)
                                break;

                        if(splitterIdx == splitters.Count)
                        {
                            // Show drag points on section underneath mouse cursor
                            foreach(Section section in sections)
                                if(dragPointSection == null && section.start.pos < xr && xr < section.end.pos)
                                    dragPointSection = section;

                            if(dragPointSection != null)
                            {
                                // Compute visible section width in pixels
                                float sectionwidth = (dragPointSection.end.pos - dragPointSection.start.pos) * (float)BackbufferSize.Width / invtransform.M11;
                                if(sectionwidth >= 56.0f) // 56 = 2 * drag_point_width (16 pixels) + 3 * drag_point_distance (8 pixels)
                                {
                                    float yr = (float)e.Y / (float)BackbufferSize.Height;
                                    float tolearance_x = 16.0f * invtransform.M11 / (float)BackbufferSize.Width, tolearance_y = 16.0f / (2.0f * (float)BackbufferSize.Height); // Grab tolerance is +- 16 pixels

                                    // Set move grab cursor if a drag point is close to xr
                                    if(Math.Abs(dragPointSection.end.pos - xr - 8.0f * invtransform.M11 / (float)BackbufferSize.Width) < tolearance_x && Math.Abs(0.95f - yr) < tolearance_y)
                                    {
                                        dragPoint = DragPoint.End;
                                        colorTableMgr.SetCursor(CursorType.HoverOverPoint);
                                    }
                                    else if(Math.Abs(dragPointSection.start.pos - xr + 8.0f * invtransform.M11 / (float)BackbufferSize.Width) < tolearance_x && Math.Abs(0.95f - yr) < tolearance_y)
                                    {
                                        dragPoint = DragPoint.Start;
                                        colorTableMgr.SetCursor(CursorType.HoverOverPoint);
                                    }
                                    else
                                        colorTableMgr.SetCursor(CursorType.Default);
                                }
                                else
                                {
                                    dragPointSection = null;
                                    colorTableMgr.SetCursor(CursorType.Default);
                                }
                            }
                            else
                                colorTableMgr.SetCursor(CursorType.Default);
                        }
                        else
                            colorTableMgr.SetCursor(CursorType.MovePin);

                        /*if(dragPointSection != oldDragPointSection || dragPoint != oldDragPoint)
                        requestAnimFrame(render);*/
                    }
                }

                return Bounds.Contains(e.Location);
            }