示例#1
0
 public override bool DrawShape(GraphicsPath zPath, Rectangle zTargetRect, ShapeInfo zInfo)
 {
     var arrayPoints = new PointF[3];
     switch (Corner)
     {
         default:
             arrayPoints[0] = new PointF(zTargetRect.X, zTargetRect.Y);
             arrayPoints[1] = new PointF(zTargetRect.Right, zTargetRect.Y);
             arrayPoints[2] = new PointF(zTargetRect.X, zTargetRect.Bottom);
             break;
         case 1:
             arrayPoints[0] = new PointF(zTargetRect.X, zTargetRect.Y);
             arrayPoints[1] = new PointF(zTargetRect.Right, zTargetRect.Y);
             arrayPoints[2] = new PointF(zTargetRect.Right, zTargetRect.Bottom);
             break;
         case 2:
             arrayPoints[0] = new PointF(zTargetRect.Right, zTargetRect.Y);
             arrayPoints[1] = new PointF(zTargetRect.Right, zTargetRect.Bottom); 
             arrayPoints[2] = new PointF(zTargetRect.X, zTargetRect.Bottom);
             break;
         case 3:
             arrayPoints[0] = new PointF(zTargetRect.Right, zTargetRect.Bottom); 
             arrayPoints[1] = new PointF(zTargetRect.X, zTargetRect.Bottom);
             arrayPoints[2] = new PointF(zTargetRect.X, zTargetRect.Y);
             break;
     }
     zPath.AddPolygon(arrayPoints);
     return true;
 }
示例#2
0
 public Rectangle(string info, int top, int left, int bottom, int right)
 {
     rectInfo   = new ShapeInfo(info);
     RectTop    = top;
     RectLeft   = left;
     RectBottom = bottom;
     RectRight  = right;
 }
示例#3
0
 public bool RemoveShape(ShapeInfo shape)
 {
     if (shape == null)
     {
         return(false);
     }
     return(RemoveShape(shape.Index));
 }
示例#4
0
 public ShapeInfo(ShapeInfo anotherInfo)
 {
     shapeId          = anotherInfo.shapeId;
     shapeType        = anotherInfo.shapeType;
     shapePosition    = anotherInfo.shapePosition;
     shapePositionIds = anotherInfo.shapePositionIds;
     shapeRotation    = anotherInfo.shapeRotation;
     shapeRotationId  = anotherInfo.shapeRotationId;
 }
        /// <summary>
        /// 修改Shape的颜色
        /// </summary>
        /// <param name="key"></param>
        /// <param name="color"></param>
        public void ChangeShapeColor(Guid key, System.Windows.Media.Color color)
        {
            Shape shape = ShapeInfo.GetShape(key, allDisplayShapes);

            if (shape != null)
            {
                shape.Color = FromWindowColor(color);
            }
        }
示例#6
0
    //create shape from info method
    public GameObject ShapeFromInfo(ShapeInfo info, bool pathFinding)
    {
        GameObject shape;
        Vector3    position = new Vector3(info.px, info.py, info.pz);

        //if load map, change waypoint to arrow
        if (pathFinding && info.shapeType == 0)
        {
            shape = Instantiate(ShapePrefabs[2]);
        }
        else
        {
            shape = Instantiate(ShapePrefabs[info.shapeType]);
        }

        if (shape.GetComponent <Node>() != null)
        {
            shape.GetComponent <Node>().pos = position;            // set the node vector3 to the metadata position so it could find neighbour
            Debug.Log(position);
        }
        shape.tag = "waypoint";
        shape.transform.position   = position;       // transform the created shape to the metadata position
        shape.transform.rotation   = new Quaternion(info.qx, info.qy, info.qz, info.qw);
        shape.transform.localScale = new Vector3(.3f, .3f, .3f);
        var _temptShape = shape.GetComponent <DestinationTarget>();

        if (_temptShape != null)
        {
            _temptShape.DestinationName  = info.name;
            _temptShape.DestinationIndex = info.infoIndex;
            _temptShape.linkMapID        = info.linkMapID;
            _temptShape.name             = info.name;
            destinationList.Add(_temptShape);
        }

        if (mapManager.IsMapping)         // if mapping see every thing
        {
            if (_temptShape != null)
            {
                _temptShape.Activate(true);
            }
        }
        else if (mapManager.IsInitialized)        //if running map everything to false
        {
            if (_temptShape != null)
            {
                _temptShape.Activate(false);
            }

            if (shape.GetComponent <Waypoint>() != null)
            {
                shape.GetComponent <Waypoint>().Activate(false);
            }
        }
        return(shape);
    }
示例#7
0
        /// <summary>
        /// Gets a handle to a convex mesh description that describes the given capsule.
        /// </summary>
        public INTERACTION_SHAPE_DESCRIPTION_HANDLE GetCapsule(Vector3 p0, Vector3 p1, float radius)
        {
            INTERACTION_SHAPE_DESCRIPTION_HANDLE handle;
            IntPtr capsulePtr = allocateCapsule(p0, p1, radius);

            InteractionC.AddShapeDescription(ref _scene, capsulePtr, out handle);
            StructAllocator.CleanupAllocations();
            _allHandles[handle] = new ShapeInfo(isCached: false);
            return(handle);
        }
 void OnTriggerEnter(Collider col)
 {
     if (ShapeInfo.getShapeTags().Contains(col.gameObject.tag))
     {
         string tag = col.gameObject.tag;
         shapeSpawner.DestroyShape();
         Debug.Log("destroyed shape, now calling event");
         OnShapeCollidedIsCorrectHit(tag.Equals(tagToCheckFor));
     }
 }
        /// <summary>
        /// 移除一个形状
        /// </summary>
        /// <param name="key"></param>
        public void RemoveShape(Guid key)
        {
            ShapeInfo shape = allDisplayShapes.FirstOrDefault(p => p.key == key);

            if (shape != null && shape.shape != null)
            {
                dataChart.Scene.Graph.Remove(shape.shape);
                allDisplayShapes.Remove(shape);
            }
        }
示例#10
0
        public override void OnActionKeyReleased(MouseButtons mouseButton)
        {
            base.OnActionKeyReleased(mouseButton);

            this.activeShape  = null;
            this.activeVertex = -1;
            this.activeEdge   = -1;

            this.Environment.EndToolAction();
        }
示例#11
0
    private GameObject ShapeFromInfo(ShapeInfo info)
    {
        GameObject shape = GameObject.CreatePrimitive((PrimitiveType)info.shapeType);

        shape.transform.position   = new Vector3(info.px, info.py, info.pz);
        shape.transform.rotation   = new Quaternion(info.qx, info.qy, info.qz, info.qw);
        shape.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f);

        return(shape);
    }
示例#12
0
    public void AddShapeInfo(ShapeInfo info)
    {
        ShapeIndex index = ShapeIndexToBlockIndex(info.Index);
        MapBlock   block = CreateOrGetBlock(info.SpaceType, index);

        if (block != null)
        {
            block.AddShape(info);
        }
    }
示例#13
0
    //create shape from info method
    public GameObject ShapeFromInfo(ShapeInfo info, bool pathFinding)
    {
        GameObject shape;
        Vector3    position = new Vector3(info.px, info.py, info.pz);

        //if loading map, change waypoint to arrow
        if (pathFinding && info.shapeType == 0)
        {
            shape = Instantiate(ShapePrefabs[2]);
        }
        else
        {
            shape = Instantiate(ShapePrefabs[info.shapeType]);
        }
        if (shape.GetComponent <Node>() != null)
        {
            shape.GetComponent <Node>().pos = position;            // set the node vector3 to the metadata position so it could find neighbour
            Debug.Log(position);
        }
        shape.tag = "waypoint";
        shape.transform.position   = position;       // transform the created shape to the metadata position
        shape.transform.rotation   = new Quaternion(info.qx, info.qy, info.qz, info.qw);
        shape.transform.localScale = new Vector3(.3f, .3f, .3f);

        if (CreateMapSample.mapStatus == CreateMapSample.Status.Mapping)
        {
            if (shape.GetComponent <DestinationTarget>() != null)
            {
                var temptShape = shape.GetComponent <DestinationTarget>();
                temptShape.DestinationName  = info.name;
                temptShape.DestinationIndex = info.infoIndex;
                temptShape.linkMapID        = info.linkMapID;
                shape.name = info.name;
                temptShape.Activate(true);
            }
        }
        else if (CreateMapSample.mapStatus == CreateMapSample.Status.Running)
        {
            if (shape.GetComponent <DestinationTarget>() != null)
            {
                var temptShape = shape.GetComponent <DestinationTarget>();
                temptShape.DestinationName  = info.name;
                temptShape.DestinationIndex = info.infoIndex;
                temptShape.linkMapID        = info.linkMapID;
                shape.name = info.name;
                shape.GetComponent <DestinationTarget>().Activate(false);
            }
            else if (shape.GetComponent <Waypoint>() != null)
            {
                shape.GetComponent <Waypoint>().Activate(false);
            }
        }
        return(shape);
    }
    public GameObject ShapeFromInfo(ShapeInfo info)
    {
        GameObject shape = Instantiate(ShapePrefabs[info.shapeType]); //get relevant shape to place

        //Place shape with position,rotation and scale
        shape.transform.position   = new Vector3(info.px, info.py, info.pz);
        shape.transform.rotation   = new Quaternion(info.qx, info.qy, info.qz, info.qw);
        shape.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);

        return(shape);
    }
示例#15
0
    private GameObject ShapeFromInfo(ShapeInfo info)
    {
        GameObject shape = GameObject.CreatePrimitive((PrimitiveType)info.shapeType);

        shape.transform.position   = new Vector3(info.px, info.py, info.pz);
        shape.transform.rotation   = new Quaternion(info.qx, info.qy, info.qz, info.qw);
        shape.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f);
        shape.GetComponent <MeshRenderer> ().material = mShapeMaterial;

        return(shape);
    }
示例#16
0
    public ShapeInfo GetMapInfo(int x, int z)
    {
        int y          = GetShapeHeight(x, z);
        var shape_info = new ShapeInfo();

        shape_info.SpaceType = GetShapeSpaceType(new Vector3(x, y, z));
        shape_info.Index.x   = x;
        shape_info.Index.y   = y;
        shape_info.Index.z   = z;

        return(shape_info);
    }
示例#17
0
        public override void BeginAction(MouseButtons mouseButton)
        {
            base.BeginAction(mouseButton);

            // Deselect any potentially selected shapes so the overlay rendering
            // is less cluttered with shape transform areas.
            this.Environment.SelectShapes(null);
            this.isMovingVertex = true;

            if (this.activeShape is CircleShapeInfo)
            {
                this.backedUpShape    = null;
                this.backedUpVertices = null;
            }
            else
            {
                VertexBasedShapeInfo vertexShape         = this.activeShape as VertexBasedShapeInfo;
                Vector2[]            activeShapeVertices = vertexShape.Vertices;

                // Create a backup of the polygons vertices before our edit operation,
                // so we can go back via Undo later.
                this.backedUpShape    = this.activeShape;
                this.backedUpVertices = (Vector2[])activeShapeVertices.Clone();

                // Create a new vertex when hovering the polygon edge where none exists yet
                if (mouseButton == MouseButtons.Left)
                {
                    if (this.activeEdge != -1)
                    {
                        int            newIndex    = this.activeEdge + 1;
                        List <Vector2> newVertices = activeShapeVertices.ToList();
                        newVertices.Insert(newIndex, this.Environment.ActiveBodyPos);

                        vertexShape.Vertices = newVertices.ToArray();
                        this.activeVertex    = newIndex;
                    }
                }
                // Remove an existing vertex when right-clicking on it
                else if (mouseButton == MouseButtons.Right)
                {
                    if (this.activeVertex != -1 && activeShapeVertices.Length > 3)
                    {
                        List <Vector2> newVertices = activeShapeVertices.ToList();
                        newVertices.RemoveAt(this.activeVertex);

                        vertexShape.Vertices = newVertices.ToArray();
                        this.activeVertex    = -1;
                    }
                }
            }
        }
示例#18
0
        private void decompileFlow(ShapeInfo info, ref DebugTrace trace)
        {
            DebugShape shape = new DebugShape();

            shape.shapeText = info.shapeText;
            shape.ShapeID   = info.ShapeID;
            shape.shapeType = info.shapeType;
            trace.TraceDetails.Add(shape);

            foreach (ShapeInfo child in info.children)
            {
                this.decompileFlow(child, ref trace);
            }
        }
示例#19
0
        public override bool DrawShape(GraphicsPath zPath, Rectangle zTargetRect, ShapeInfo zInfo)
        {
            int nWidth  = zTargetRect.Width;
            int nHeight = zTargetRect.Height;
            int nDesiredCornerSize;

            if ((int)RoundedRectVariables.VariablesLength > zInfo.Arguments.Length)
            {
                return(false);
            }

            if (!int.TryParse(zInfo.Arguments[(int)RoundedRectVariables.CornerSize], out nDesiredCornerSize))
            {
                return(false);
            }

            int nSmallerSide = Math.Min(nWidth, nHeight);

            if (nDesiredCornerSize > (nSmallerSide >> 1))
            {
                nDesiredCornerSize = nSmallerSide >> 1;
            }

            if (0 >= nDesiredCornerSize)
            {
                return(false); // get out!
            }

            int nArcSize = nDesiredCornerSize * 2;

            int nXSlide = nWidth - nArcSize;
            int nYSlide = nHeight - nArcSize;

            int nWidthLine  = Math.Max(0, nWidth - (nDesiredCornerSize * 2));
            int nHeightLine = Math.Max(0, nHeight - (nDesiredCornerSize * 2));

            zPath.AddLine(nDesiredCornerSize, 0, nDesiredCornerSize + nWidthLine, 0);
            zPath.AddArc(nXSlide, 0, nArcSize, nArcSize, 270, 90);

            zPath.AddLine(nWidth, nDesiredCornerSize, nWidth, nHeightLine + nDesiredCornerSize);
            zPath.AddArc(nXSlide, nYSlide, nArcSize, nArcSize, 0, 90);

            zPath.AddLine(nDesiredCornerSize + nWidthLine, nHeight, nDesiredCornerSize, nHeight);
            zPath.AddArc(0, nYSlide, nArcSize, nArcSize, 90, 90);

            zPath.AddLine(0, nDesiredCornerSize + nHeightLine, 0, nDesiredCornerSize);
            zPath.AddArc(0, 0, nArcSize, nArcSize, 180, 90);
            zPath.CloseFigure();
            return(true);
        }
示例#20
0
    public void AddDestinationShape()
    {
        //change last waypoint to diamond
        ShapeInfo lastInfo = shapeInfoList [shapeInfoList.Count - 1];

        lastInfo.shapeType = 1.GetHashCode ();
        GameObject shape = ShapeFromInfo(lastInfo);

        shape.GetComponent <DiamondBehavior> ().Activate(true);
        //destroy last shape
        Destroy(shapeObjList [shapeObjList.Count - 1]);
        //add new shape
        shapeObjList.Add(shape);
    }
    /// <summary>
    /// Gets a handle to a sphere shape description of the given radius
    /// </summary>
    public INTERACTION_SHAPE_DESCRIPTION_HANDLE GetSphere(float radius) {
      float roundedRadius = (int)(radius * DECIMAL_CACHING_PRECISION);

      INTERACTION_SHAPE_DESCRIPTION_HANDLE handle;
      if (!_sphereDescMap.TryGetValue(roundedRadius, out handle)) {
        IntPtr spherePtr = allocateSphere(radius);
        InteractionC.AddShapeDescription(ref _scene, spherePtr, out handle);
        StructAllocator.CleanupAllocations();

        _sphereDescMap[roundedRadius] = handle;
        _allHandles[handle] = new ShapeInfo(isCached: true);
      }

      return handle;
    }
示例#22
0
 public virtual void StartDrawing(ShapeInfo shapeInfo)
 {
     if (this.imageEditorElement.CurrentBitmap == null)
     {
         return;
     }
     this.StopAllOperations();
     this.IsDrawing = true;
     this.shapeInfo = shapeInfo;
     if (this.shapeInfo.ShapeType != ShapeType.Freeflow)
     {
         return;
     }
     this.drawPath = new List <Point>();
 }
示例#23
0
 private void DrawShape(Canvas canvas, Transform transform, ShapeInfo shape, ColorRgba fillColor, ColorRgba outlineColor)
 {
     if (shape is CircleShapeInfo)
     {
         this.DrawShape(canvas, transform, shape as CircleShapeInfo, fillColor, outlineColor);
     }
     else if (shape is PolyShapeInfo)
     {
         this.DrawShape(canvas, transform, shape as PolyShapeInfo, fillColor, outlineColor);
     }
     else if (shape is VertexBasedShapeInfo)
     {
         this.DrawShape(canvas, transform, shape as VertexBasedShapeInfo, fillColor, outlineColor);
     }
 }
示例#24
0
        private void AddBox(Vector3I minPos, Vector3I maxPos, ref Vector3 min, ref Vector3 max)
        {
            Vector3                translation = (min + max) * 0.5f;
            HkBoxShape             shape       = new HkBoxShape((max - translation) - 0f, MyPerGameSettings.PhysicsConvexRadius);
            HkConvexTranslateShape shape2      = new HkConvexTranslateShape((HkConvexShape)shape, translation, HkReferencePolicy.TakeOwnership);

            this.Shapes.Add((HkShape)shape2);
            ShapeInfo item = new ShapeInfo {
                Count = 1,
                Min   = minPos,
                Max   = maxPos
            };

            this.ShapeInfos.Add(item);
        }
示例#25
0
        private static double CalculateAreaForChosenShape(ShapeInfo chosenShape)
        {
            var shapeName = chosenShape.Name;
            var ctorInfos = chosenShape.ConstructorInfos;

            Console.WriteLine($"You choose {shapeName}");
            Console.WriteLine($"There are {ctorInfos.Length} variant(s) of parameters of the {shapeName}");
            var ctorInfo = ChooseConstructor(ctorInfos);
            var ctorArgs = BuildConstructorArguments(ctorInfo);
            var s        = ctorInfo.Invoke(ctorArgs);
            var shape    = (IShape)s;

            Console.WriteLine("Congratulations!!!");
            Console.WriteLine($"The area of the {shapeName} equals to {Calculator.Area(shape)}");
        }
示例#26
0
    public void AddDestinationShape()
    {
        //change last waypoint to destination
        ShapeInfo lastInfo = shapeInfoList [shapeInfoList.Count - 1];

        lastInfo.shapeType = ((int)ShapeType.Destination).GetHashCode();
        GameObject shape = ShapeFromInfo(lastInfo);

        shape.GetComponent <Node>().Activate(true);
        //destroy last shape
        Destroy(shapeObjList [shapeObjList.Count - 1]);
        //add new shape
        shapeObjList.Add(shape);
        Log(string.Format("set destination({0}) type={1}", shapeObjList.Count - 1, lastInfo.shapeType));
    }
示例#27
0
 public static RigidBodyEditorSelShape Create(ShapeInfo shape)
 {
     if (shape is CircleShapeInfo)
     {
         return(new RigidBodyEditorSelCircleShape(shape as CircleShapeInfo));
     }
     else if (shape is VertexBasedShapeInfo)
     {
         return(new RigidBodyEditorSelVertexShape(shape as VertexBasedShapeInfo));
     }
     else
     {
         return(null);
     }
 }
示例#28
0
 private void DrawShapeOutline(Canvas canvas, Transform transform, ShapeInfo shape)
 {
     canvas.PushState();
     if (shape is CircleShapeInfo)
     {
         this.DrawShapeOutline(canvas, transform, shape as CircleShapeInfo);
     }
     else if (shape is VertexBasedShapeInfo)
     {
         VertexBasedShapeInfo vertexShape = shape as VertexBasedShapeInfo;
         bool isLoop = (vertexShape.ShapeTraits & VertexShapeTrait.IsLoop) != VertexShapeTrait.None;
         this.DrawShapeOutline(canvas, transform, vertexShape.Vertices, isLoop);
     }
     canvas.PopState();
 }
示例#29
0
 public void RemoveShape()
 {
     animator.SetTrigger("goRun");
     currentShapInfo = new ShapeInfo();
     hasBuild        = false;
     PickUpTri[] pickups = transform.Find("TriContainer").GetComponentsInChildren <PickUpTri>();
     foreach (var pickup in pickups)
     {
         pickup.HideTri();
     }
     foreach (var leg in legObjs)
     {
         HidePlayerLeg(leg);
     }
 }
示例#30
0
    private GameObject ShapeFromInfo(ShapeInfo info)
    {
        GameObject shape = GameObject.CreatePrimitive((PrimitiveType)info.shapeType);

        //UnityEngine.Object prefab = Resources.Load<UnityEngine.Object>("Character_Monster/Prefab/Monster");

        shape.transform.position = new Vector3(info.px, info.py, info.pz);
        //shape.transform.rotation = new Quaternion(info.qx, info.qy, info.qz, info.qw);
        shape.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
        //shape.GetComponent<MeshRenderer> ().material = mShapeMaterial;
        shape.AddComponent <BoxCollider>();
        BoxCollider boxCollider = shape.GetComponent <BoxCollider>();

        boxCollider.isTrigger = false;
        return(shape);
    }
示例#31
0
        public override List <CamViewState.SelObj> PickSelObjIn(int x, int y, int w, int h)
        {
            List <CamViewState.SelObj> result = new List <SelObj>();

            RigidBody pickedCollider = null;
            ShapeInfo pickedShape    = null;

            RigidBody[] visibleColliders = this.QueryVisibleColliders()
                                           .Where(r => !DesignTimeObjectData.Get(r.GameObj).IsLocked)
                                           .ToArray();
            visibleColliders.StableSort(delegate(RigidBody c1, RigidBody c2)
            {
                return(MathF.RoundToInt(1000.0f * (c1.GameObj.Transform.Pos.Z - c2.GameObj.Transform.Pos.Z)));
            });

            // Pick a collider
            foreach (RigidBody c in visibleColliders)
            {
                Vector3 worldCoord = this.GetSpaceCoord(new Vector3(x, y, c.GameObj.Transform.Pos.Z));
                float   scale      = this.GetScaleAtZ(c.GameObj.Transform.Pos.Z);
                pickedShape = this.PickShapes(c, worldCoord.Xy, new Vector2(w / scale, h / scale)).FirstOrDefault();
                if (pickedShape != null)
                {
                    pickedCollider = c;
                    result.Add(new SelBody(pickedCollider));
                    break;
                }
                else
                {
                    pickedShape = null;
                }
            }

            // Pick shapes
            if (pickedCollider != null)
            {
                Vector3          worldCoord = this.GetSpaceCoord(new Vector3(x, y, pickedCollider.GameObj.Transform.Pos.Z));
                float            scale      = this.GetScaleAtZ(pickedCollider.GameObj.Transform.Pos.Z);
                List <ShapeInfo> picked     = this.PickShapes(pickedCollider, worldCoord.Xy, new Vector2(w / scale, h / scale));
                if (picked.Count > 0)
                {
                    result.AddRange(picked.Select(s => SelShape.Create(s) as SelObj));
                }
            }

            return(result);
        }
示例#32
0
        public override void EndAction()
        {
            base.EndAction();
            if (this.actionShape != null)
            {
                Vector2[] vertices = this.GetVertices(this.actionShape);

                // If we're in the process of placing another vertex, remove that unplaced one
                if (!this.pendingAdvance)
                {
                    List <Vector2> prevVertices = vertices.ToList();
                    prevVertices.RemoveAt(this.currentVertex);
                    vertices = prevVertices.ToArray();
                }

                // Apply the new polygon and force an immediate body update / sync, so
                // we can get a useful result from the shape's IsValid method.
                this.SetVertices(this.actionShape, vertices);
                this.Environment.ActiveBody.SynchronizeBodyShape();

                // Check if we have a fully defined, valid polygon to apply
                bool isValidShape            = this.actionShape != null && this.actionShape.IsValid;
                bool isMinVertexCountReached =
                    vertices.Length >= this.initialVertexCount &&
                    this.currentVertex >= this.initialVertexCount - 1;
                if (isValidShape && isMinVertexCountReached)
                {
                    // Remove the shape and re-add it properly using an UndoRedoAction.
                    // Now that we're sure the shape is valid, we want its creation to
                    // show up in the UndoRedo stack.
                    this.Environment.ActiveBody.RemoveShape(this.actionShape);
                    UndoRedoManager.Do(new CreateRigidBodyShapeAction(this.Environment.ActiveBody, this.actionShape));
                    this.Environment.SelectTool(typeof(VertexRigidBodyEditorTool));
                }
                else
                {
                    this.Environment.SelectShapes(null);
                    this.Environment.ActiveBody.RemoveShape(this.actionShape);
                }

                DualityEditorApp.NotifyObjPropChanged(this,
                                                      new ObjectSelection(this.Environment.ActiveBody),
                                                      ReflectionInfo.Property_RigidBody_Shapes);
                this.actionShape = null;
            }
        }
示例#33
0
        public override bool DrawShape(GraphicsPath zPath, Rectangle zTargetRect, ShapeInfo zInfo)
        {
            int nWidth = zTargetRect.Width;
            int nHeight = zTargetRect.Height;
            int nDesiredCornerSize;

            if ((int)RoundedRectVariables.VariablesLength > zInfo.Arguments.Length)
                return false;

            if (!int.TryParse(zInfo.Arguments[(int)RoundedRectVariables.CornerSize], out nDesiredCornerSize))
                return false;

            int nSmallerSide = Math.Min(nWidth, nHeight);

            if (nDesiredCornerSize > (nSmallerSide >> 1))
            {
                nDesiredCornerSize = nSmallerSide >> 1;
            }

            if (0 >= nDesiredCornerSize)
            {
                return false; // get out!
            }

            int nArcSize = nDesiredCornerSize * 2;

            int nXSlide = nWidth - nArcSize;
            int nYSlide = nHeight - nArcSize;

            int nWidthLine = Math.Max(0, nWidth - (nDesiredCornerSize * 2));
            int nHeightLine = Math.Max(0, nHeight - (nDesiredCornerSize * 2));

            zPath.AddLine(nDesiredCornerSize, 0, nDesiredCornerSize + nWidthLine, 0);
            zPath.AddArc(nXSlide, 0, nArcSize, nArcSize, 270, 90);

            zPath.AddLine(nWidth, nDesiredCornerSize, nWidth, nHeightLine + nDesiredCornerSize);
            zPath.AddArc(nXSlide, nYSlide, nArcSize, nArcSize, 0, 90);

            zPath.AddLine(nDesiredCornerSize + nWidthLine, nHeight, nDesiredCornerSize, nHeight);
            zPath.AddArc(0, nYSlide, nArcSize, nArcSize, 90, 90);

            zPath.AddLine(0, nDesiredCornerSize + nHeightLine, 0, nDesiredCornerSize);
            zPath.AddArc(0, 0, nArcSize, nArcSize, 180, 90);
            zPath.CloseFigure();
            return true;
        }        
示例#34
0
        public override bool DrawShape(GraphicsPath zPath, Rectangle zTargetRect, ShapeInfo zInfo)
        {
            int nTotalWidth = zTargetRect.Width;
            int nTotalHeight = zTargetRect.Height;

            if ((int)GridShapeVariables.VariablesLength > zInfo.Arguments.Length)
                return false;

            int nGridRectWidth;
            int nGridRectHeight;

            var bParse = true;
            var bAllowPartialGrid = zInfo.Arguments[(int)GridShapeVariables.AllowPartialGrid].Equals("1");
            bParse &= int.TryParse(zInfo.Arguments[(int)GridShapeVariables.GridRectWidth], out nGridRectWidth);
            bParse &= int.TryParse(zInfo.Arguments[(int)GridShapeVariables.GridRectHeight], out nGridRectHeight);

            if (!bParse)
                return false;

            if (0 == nGridRectWidth || 0 == nGridRectHeight)
                return false;

            if (!bAllowPartialGrid)
            {
                nTotalWidth = zTargetRect.Width - (zTargetRect.Width % nGridRectWidth);
                nTotalHeight = zTargetRect.Height - (zTargetRect.Height % nGridRectHeight);
            }

            int nVerticalLineOffset = 0;
            int nHorizontalLineOffset = 0;

            // draw the horizontal lines
            while (nHorizontalLineOffset < zTargetRect.Height)
            {
                zPath.AddLine(
                    new Point(zTargetRect.X, nHorizontalLineOffset),
                    new Point(zTargetRect.X + nTotalWidth, nHorizontalLineOffset));
                zPath.CloseFigure();
                nHorizontalLineOffset += nGridRectHeight;
            }
            // draw the vertical lines
            while (nVerticalLineOffset < zTargetRect.Width)
            {
                zPath.AddLine(
                    new Point(nVerticalLineOffset, zTargetRect.Y),
                    new Point(nVerticalLineOffset, zTargetRect.Y + nTotalHeight));
                zPath.CloseFigure();
                nVerticalLineOffset += nGridRectWidth;
            }

            return true;
        }
    /// <summary>
    /// Gets a handle to a convex mesh description of the provided mesh.  Any changes
    /// to the mesh will not be reflected in the description once it is generated.
    /// This version always allocates a new handle for the transformed data.
    /// </summary>
    public INTERACTION_SHAPE_DESCRIPTION_HANDLE GetConvexPolyhedron(MeshCollider meshCollider, Matrix4x4 transform) {
      if (meshCollider.sharedMesh == null) { throw new NotImplementedException("MeshCollider missing sharedMesh."); }

      INTERACTION_SHAPE_DESCRIPTION_HANDLE handle;
      IntPtr meshPtr = allocateConvex(meshCollider, transform);
      InteractionC.AddShapeDescription(ref _scene, meshPtr, out handle);
      StructAllocator.CleanupAllocations();

      _allHandles[handle] = new ShapeInfo(isCached: false);

      return handle;
    }
示例#36
0
 public Rectangle(String info, int top, int left, int bottom, int right)
 {
     rectInfo = new ShapeInfo(info);
     Top = top;
     Left = left;
     Bottom = bottom;
     Right = right;
 }
    public INTERACTION_SHAPE_DESCRIPTION_HANDLE GetCollision(GameObject parentObject) {
      parentObject.GetComponentsInChildren<Collider>(_tempColliderList);

      // Remove Colliders that are children of other IInteractionBehaviour.
      Transform parentTransform = parentObject.transform;
      for (int i = _tempColliderList.Count; i-- > 0; ) {
        Transform it = _tempColliderList[i].transform;
        while (it != parentTransform) {
          if (it.GetComponent<IInteractionBehaviour>() != null) {
            _tempColliderList.RemoveAt(i);
            break;
          }
          it = it.parent;
        }
      }

      if (_tempColliderList.Count == 0) {
        throw new InvalidOperationException("The GameObject " + parentObject + " did not have any colliders.");
      }

      INTERACTION_SHAPE_DESCRIPTION_HANDLE handle = new INTERACTION_SHAPE_DESCRIPTION_HANDLE();

      // Try optimized encodings for a single collider.  Everything else is a compound.
      if (_tempColliderList.Count == 1) {
        if (getCollisionSingleInternal(parentObject, ref handle)) {
          return handle;
        }
      }

      INTERACTION_COMPOUND_DESCRIPTION compoundDesc = new INTERACTION_COMPOUND_DESCRIPTION();
      compoundDesc.shape.type = ShapeType.Compound;
      compoundDesc.nShapes = (uint)_tempColliderList.Count;
      compoundDesc.pShapes = StructAllocator.AllocateArray<IntPtr>(_tempColliderList.Count);
      compoundDesc.pTransforms = new INTERACTION_TRANSFORM[_tempColliderList.Count];

      // The parent's relative pose is a components of the parents transform that
      // child transforms are considered to be relative two.  In this case scale
      // and shear are not considered a property of the parents relative pose and
      // therefore these calcualtions will allow the child to inherit the parents
      // scale.

      Matrix4x4 parentRelativePose = Matrix4x4.TRS(parentObject.transform.position, parentObject.transform.rotation, Vector3.one);
      Matrix4x4 inverseParentRelativePose = parentRelativePose.inverse;

      for (int i = 0; i < _tempColliderList.Count; i++) {
        Collider collider = _tempColliderList[i];

        // Transform to apply to collision shape.
        Matrix4x4 localToParentRelative = inverseParentRelativePose * collider.transform.localToWorldMatrix;

        // Values used to construct INTERACTION_TRANSFORM.
        Vector3 parentRelativePos = Vector3.zero;
        Quaternion parentRelativeRot = Quaternion.identity;

        IntPtr shapePtr;
        if (collider is MeshCollider) {
          // Mesh always has an identity associated transform that can be baked into the verts.
          MeshCollider meshCollider = collider as MeshCollider;
          shapePtr = allocateConvex(meshCollider, localToParentRelative);
        } else {
          //  Rotation and scale are lossy when shear is involved.
          parentRelativeRot = Quaternion.Inverse(parentObject.transform.rotation) * collider.transform.rotation;

          Vector3 scaleAlongLocalToParentAxes = new Vector3(localToParentRelative.GetColumn(0).magnitude,
                                                            localToParentRelative.GetColumn(1).magnitude,
                                                            localToParentRelative.GetColumn(2).magnitude);
          if (collider is SphereCollider) {
            SphereCollider sphereCollider = collider as SphereCollider;
            parentRelativePos = localToParentRelative.MultiplyPoint(sphereCollider.center);

            float aproximateScale = Mathf.Max(scaleAlongLocalToParentAxes.x, Mathf.Max(scaleAlongLocalToParentAxes.y, scaleAlongLocalToParentAxes.z));
            shapePtr = allocateSphere(sphereCollider.radius * aproximateScale);
          } else if (collider is BoxCollider) {
            BoxCollider boxCollider = collider as BoxCollider;
            parentRelativePos = localToParentRelative.MultiplyPoint(boxCollider.center);

            Vector3 extents = boxCollider.size * 0.5f;
            extents.Scale(scaleAlongLocalToParentAxes);
            shapePtr = allocateObb(extents);
          } else if (collider is CapsuleCollider) {
            CapsuleCollider capsuleCollider = collider as CapsuleCollider;
            if ((uint)capsuleCollider.direction >= 3u)
              throw new InvalidOperationException("Unexpected capsule direction " + capsuleCollider.direction);

            parentRelativePos = localToParentRelative.MultiplyPoint(capsuleCollider.center);

            Vector3 primaryAxis = new Vector3((capsuleCollider.direction == 0) ? 1 : 0, (capsuleCollider.direction == 1) ? 1 : 0, (capsuleCollider.direction == 2) ? 1 : 0);
            float primaryAxisScale = scaleAlongLocalToParentAxes[capsuleCollider.direction];
            float perpendicularScale = Mathf.Max(scaleAlongLocalToParentAxes[(capsuleCollider.direction + 1) % 3], scaleAlongLocalToParentAxes[(capsuleCollider.direction + 2) % 3]);

            float scaledHeight = capsuleCollider.height * primaryAxisScale;
            float scaledRadius = capsuleCollider.radius * perpendicularScale;
            float interiorExtent = (scaledHeight * 0.5f) - scaledRadius;

            Vector3 p0 = primaryAxis * interiorExtent;
            shapePtr = allocateCapsule(p0, -p0, scaledRadius);
          } else {
            throw new InvalidOperationException("Unsupported collider type " + collider.GetType());
          }
        }

        StructMarshal<IntPtr>.CopyIntoArray(compoundDesc.pShapes, ref shapePtr, i);

        INTERACTION_TRANSFORM ieTransform = new INTERACTION_TRANSFORM();
        ieTransform.position = parentRelativePos.ToCVector();
        ieTransform.rotation = parentRelativeRot.ToCQuaternion();
        compoundDesc.pTransforms[i] = ieTransform;
      }

      IntPtr compoundPtr = StructAllocator.AllocateStruct(ref compoundDesc);
      InteractionC.AddShapeDescription(ref _scene, compoundPtr, out handle);
      StructAllocator.CleanupAllocations();

      _tempColliderList.Clear();
      _allHandles[handle] = new ShapeInfo(isCached: false);

      return handle;
    }
示例#38
0
 public override bool DrawShape(GraphicsPath zPath, Rectangle zTargetRect, ShapeInfo zInfo)
 {
     zPath.AddRectangle(zTargetRect);
     return true;
 }
    /// <summary>
    /// Gets a handle to an OBB description of the given extents
    /// </summary>
    public INTERACTION_SHAPE_DESCRIPTION_HANDLE GetOBB(Vector3 extents) {
      Vector3 roundedExtents = new Vector3();
      roundedExtents.x = (int)(extents.x * DECIMAL_CACHING_PRECISION);
      roundedExtents.y = (int)(extents.y * DECIMAL_CACHING_PRECISION);
      roundedExtents.z = (int)(extents.z * DECIMAL_CACHING_PRECISION);

      INTERACTION_SHAPE_DESCRIPTION_HANDLE handle;
      if (!_obbDescMap.TryGetValue(roundedExtents, out handle)) {
        IntPtr obbPtr = allocateObb(extents);
        InteractionC.AddShapeDescription(ref _scene, obbPtr, out handle);
        StructAllocator.CleanupAllocations();

        _obbDescMap[roundedExtents] = handle;
        _allHandles[handle] = new ShapeInfo(isCached: true);
      }

      return handle;
    }
 /// <summary>
 /// Gets a handle to a convex mesh description that describes the given capsule.
 /// </summary>
 public INTERACTION_SHAPE_DESCRIPTION_HANDLE GetCapsule(Vector3 p0, Vector3 p1, float radius) {
   INTERACTION_SHAPE_DESCRIPTION_HANDLE handle;
   IntPtr capsulePtr = allocateCapsule(p0, p1, radius);
   InteractionC.AddShapeDescription(ref _scene, capsulePtr, out handle);
   StructAllocator.CleanupAllocations();
   _allHandles[handle] = new ShapeInfo(isCached: false);
   return handle;
 }
示例#41
0
 public Rectangle(string info, int top, int left, int bottom, int right)
 {
     rectInfo = new ShapeInfo(info);
     rectTop = top; rectBottom = bottom;
     rectLeft = left; rectRight = right;
 }