Ejemplo n.º 1
0
 public void SetRoomInfoData(Enums.RoomSizes roomSize, Enums.RoomTypes roomType, Enums.RoomOverUnder roomOverUnder, GridIndex leftMostIndex)
 {
     RoomSize      = roomSize;
     RoomType      = roomType;
     RoomOverUnder = roomOverUnder;
     LeftmostIndex = leftMostIndex;
 }
Ejemplo n.º 2
0
 //Initialise
 public GridCell(GridIndex index, Cell cell)
 {
     this.index      = index;
     this.cell       = cell;
     this.isActive   = false;
     this.isResolved = false;
 }
Ejemplo n.º 3
0
    void Construct(ChessTeam team, GridIndex gridIndex, ChessBoard board)
    {
        this.board = board;
        var mesh = AssetDatabase.LoadAssetAtPath <Mesh>("Assets/Free Low Poly Chess Set/Pawn/Mesh/pawn.fbx");

        base.Construct(mesh, team, gridIndex, board);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// 周辺グリッドの点が範囲内か?
    /// </summary>
    /// <param name="p"></param>
    /// <param name="minDistance"></param>
    /// <returns></returns>
    bool IsInNeighborhood(ref Vector2 p, float minDistance)
    {
        GridIndex idx = GetGridIndex(p.x, p.y);
        const int D   = 2;

        int startX = Mathf.Max(idx.x - D, 0);
        int endX   = Mathf.Min(idx.x + D, gridWidth);
        int startY = Mathf.Max(idx.y - D, 0);
        int endY   = Mathf.Min(idx.y + D, gridHeight);

        //Debug.Log("x " + p.x + " " + p.y + " [" + idx.x + "," + idx.y + "] startX " + startX + " endX " + endX + " startY " + startY + " endY " + endY);
        for (int x = startX; x < endX; x++)
        {
            for (int y = startY; y < endY; y++)
            {
                //if ((x == idx.x) && (y == idx.y)) continue;
                if (!enableGrid[x, y])
                {
                    continue;
                }

                float distance = Vector2.Distance(p, grid[x, y]);
                if (distance < minDistance)
                {
                    //Debug.Log("newPos " + p + " grid[" + x + "," + y + "] " + grid[x, y] + " distance " + distance + " < " + minDistance);
                    return(true);
                }
            }
        }

        //Debug.Log("[" + idx.x + "," + idx.y + "] p " + p.x + " " + p.y);
        return(false);
    }
Ejemplo n.º 5
0
    void AddMove(Pieces from, GridIndex to)
    {
        var seq = from.QueryMovable(MoveType.StandardMove);

        seq.Build(board, MoveType.StandardMove);

        if (seq.ContainsMove(to))
        {
            var fromIndex = from.CellIndex;
            var action    = from.MoveTo(to);

            undoStack.Push(ActionCommand.SimpleMove(action));
            redoStack.Clear();
            GenericAction();
            board.Turnover();
        }


        else if (from is King king)
        {
            AddCastling(king, to);
        }


        else if (from is Pawn pawn)
        {
            AddEnpassant(pawn, to);
        }
    }
Ejemplo n.º 6
0
 public MyActionData(Pieces actor, GridIndex from, GridIndex to, Pieces killActor)
 {
     this.actor     = actor;
     this.from      = from;
     this.to        = to;
     this.killActor = killActor;
 }
Ejemplo n.º 7
0
    private IEnumerator MoveRoutine(GridIndex newIndex, float timeToMove)
    {
        var startPosition      = transform.position;
        var reachedDestination = false;
        var elapsedTime        = 0f;
        var destination        = new Vector3(newIndex.GridX, newIndex.GridY);

        while (!reachedDestination)
        {
            elapsedTime += Time.deltaTime;

            var lerpT = Mathf.Clamp(elapsedTime / timeToMove, 0, 1);
            lerpT = Mathf.Sin(lerpT * Mathf.PI / 2f);

            transform.position = Vector3.Lerp(
                a: startPosition, b: destination, t: lerpT
                );

            reachedDestination = Vector3.Distance(transform.position, destination) < 0.01f;

            yield return(null);
        }

        if (OnMoveComplete != null)
        {
            OnMoveComplete(this, newIndex);
        }

        IsMoving = false;
    }
Ejemplo n.º 8
0
    private void OnDrawGizmos()
    {
        if (showGrid)
        {
            Vector3 p = Camera.main.transform.position;

            float minusX = p.x - 20;
            float plusX  = p.x + 20;
            float minusY = p.y - 20;
            float plusY  = p.y + 20;

            Gizmos.color = Color.yellow;
            GridIndex g     = new GridIndex();
            int       count = 0;

            for (float i = minusX; i <= plusX; i++)
            {
                float j = minusY + count;
                count++;

                g = GetGridIndex(new Vector3(i, j, 0));


                Vector3 p1 = new Vector3((float)(g.x * gridSize) - gridSize / 2, (float)(g.y * gridSize) - gridSize / 2, 0);

                Gizmos.DrawLine(new Vector3(p1.x, p.y - 10, 0),
                                new Vector3(p1.x, p.y + 10, 0));

                Gizmos.DrawLine(new Vector3(p.x - 10, p1.y, 0),
                                new Vector3(p.x + 10, p1.y, 0));
            }
        }
    }
Ejemplo n.º 9
0
    //spawn Player at any cell
    void spawnPacman(GridIndex index)
    {
        GameObject pacSpawn = gridMap[index].spawnObject(pacmanObject);

        pacman = pacSpawn.GetComponent <Pacman>();
        pacman.pacmanInit(index, this);
    }
Ejemplo n.º 10
0
    //Move towards neighbouring cell
    //Continue to next cell
    //Find new target if target reached
    public void MoveGhost(int x, int y)
    {
        nextCell = new GridIndex(index.x + x, index.y + y);
        if (nextCell == target)
        {
            //If the next cell is an active cell, kill the player
            if (!controller.isResolved(nextCell) && controller.isActive(nextCell))
            {
                controller.loseLife();
            }
            target.defined = false;
            StartCoroutine("findTarget");
            return;
        }

        if (!controller.isCellActive(nextCell))
        {
            StartCoroutine("moveGhost", (new Vector2(x, y)));
        }
        else
        {
            target.defined = false;
            StartCoroutine("findTarget");
        }
    }
Ejemplo n.º 11
0
    //Get All neighbouring cells that has walls
    List <GridIndex> getActiveNeighbourCells(GridIndex index)
    {
        List <GridIndex> neighbours = new List <GridIndex>();

        try
        {
            if (gridMap[new GridIndex(index.x + 1, index.y)].isActive)
            {
                neighbours.Add(new GridIndex(index.x + 1, index.y));
            }
            if (gridMap[new GridIndex(index.x - 1, index.y)].isActive)
            {
                neighbours.Add(new GridIndex(index.x - 1, index.y));
            }
            if (gridMap[new GridIndex(index.x, index.y + 1)].isActive)
            {
                neighbours.Add(new GridIndex(index.x, index.y + 1));
            }
            if (gridMap[new GridIndex(index.x, index.y - 1)].isActive)
            {
                neighbours.Add(new GridIndex(index.x, index.y - 1));
            }
        }
        catch
        {
            Debug.Log(index.x + " " + index.y);
        }
        return(neighbours);
    }
Ejemplo n.º 12
0
    //Get the vector distance between two cells
    public Vector2 getVector(GridIndex from, GridIndex to)
    {
        int x = to.x - from.x;
        int y = to.y - from.y;

        return(new Vector2(x, y));
    }
        /// <summary>
        /// Extract a mesh for a single grid index, into a suitable format for Unity Mesh.
        /// </summary>
        /// <returns>
        /// Returns Status.SUCCESS if the mesh is fully extracted and stored in the arrays.  In this case, numVertices
        /// and numTriangles will say how many vertices and triangles are used, the rest of the array is untouched.
        ///
        /// Returns Status.INSUFFICIENT_SPACE if the mesh is partially extracted and stored in the arrays.  numVertices
        /// and numTriangles have the same meaning as if Status.SUCCESS is returned, but in this case the array should
        /// grow.
        ///
        /// Returns Status.ERROR or Status.INVALID if some other error occurs.
        /// </returns>
        /// <param name="gridIndex">Grid index to extract.</param>
        /// <param name="vertices">On successful extraction this will get filled out with the vertex positions.</param>
        /// <param name="normals">On successful extraction this will get filled out whith vertex normals.</param>
        /// <param name="colors">On successful extraction this will get filled out with vertex colors.</param>
        /// <param name="triangles">On succesful extraction this will get filled out with vertex indexes.</param>
        /// <param name="numVertices">Number of vertexes filled out.</param>
        /// <param name="numTriangles">Number of triangles filled out.</param>
        internal Status ExtractMeshSegment(
            GridIndex gridIndex, Vector3[] vertices, Vector3[] normals, Color32[] colors, int[] triangles,
            out int numVertices, out int numTriangles)
        {
            numVertices  = 0;
            numTriangles = 0;
            int result = API.Tango3DR_extractPreallocatedMeshSegment(
                m_context, ref gridIndex, vertices.Length, triangles.Length / 3, vertices, triangles, normals, colors,
                out numVertices, out numTriangles);

            // NOTE: The 3D Reconstruction library does not handle left handed matrices correctly.  For now, transform
            // into the Unity world space after extraction and account for winding order changes.
            for (int it = 0; it < numVertices; ++it)
            {
                vertices[it] = m_unityWorld_T_startService.MultiplyPoint(vertices[it]);
            }

            for (int it = 0; it < numTriangles; ++it)
            {
                int temp = triangles[(it * 3) + 0];
                triangles[(it * 3) + 0] = triangles[(it * 3) + 1];
                triangles[(it * 3) + 1] = temp;
            }

            return((Status)result);
        }
Ejemplo n.º 14
0
    public Vector3 GetWorldPositionFromGridIndexZOffset(GridIndex index, float zOffset)
    {
        Vector3 vPos = GetWorldPositionFromGridIndex(index);

        vPos.z += zOffset;
        return(vPos);
    }
 public List <GemBehaviour> FindVerticalMatches(GridIndex index)
 {
     return(FindAndCombineMatches(
                index, direction1:
                Vector2.down, direction2:
                Vector2.up));
 }
Ejemplo n.º 16
0
    /// <summary>
    /// 周辺グリッドの点が範囲内か?
    /// </summary>
    /// <param name="p"></param>
    /// <param name="minDistance"></param>
    /// <returns></returns>
    protected virtual bool IsInNeighborhood(T p, float minDistance)
    {
        GridIndex idx    = GetGridIndex(p.position.x, p.position.y);
        int       D      = GetSearchGridNum();
        int       startX = Mathf.Max(idx.x - D, 0);
        int       endX   = Mathf.Min(idx.x + D, gridWidth_);
        int       startY = Mathf.Max(idx.y - D, 0);
        int       endY   = Mathf.Min(idx.y + D, gridHeight_);

        for (int x = startX; x < endX; x++)
        {
            for (int y = startY; y < endY; y++)
            {
                if (!grid[x, y].enable)
                {
                    continue;
                }

                if (IsInDistance(p, grid[x, y], minDistance))
                {
                    return(true);
                }
                //float distance = Vector2.Distance(p.position, grid[x, y].position);
                //if (distance < minDistance)
                //{
                //    return true;
                //}
            }
        }

        return(false);
    }
 public List <GemBehaviour> FindHorizontalMatches(GridIndex index)
 {
     return(FindAndCombineMatches(
                index, direction1:
                Vector2.left,
                direction2: Vector2.right));
 }
    public GridTileBehaviour Init(int x, int y, BoardBehaviour board)
    {
        Index      = new GridIndex(x, y);
        this.board = board;

        return(this);
    }
Ejemplo n.º 19
0
 //Initialise Cell
 public GridCell cellInit(GridIndex index, GameController controller)
 {
     this.index      = index;
     this.controller = controller;
     cell            = new GridCell(index, this);
     return(cell);
 }
Ejemplo n.º 20
0
    public override MoveSequence QueryMovable(MoveType type)
    {
        const int MoveCount = 7;

        GridIndex[] sepIndex = new GridIndex[8] {
            new GridIndex(-1, 1),
            new GridIndex(1, 1),
            new GridIndex(1, -1),
            new GridIndex(-1, -1),
            new GridIndex(0, 1),
            new GridIndex(1, 0),
            new GridIndex(0, -1),
            new GridIndex(-1, 0)
        };

        var seq = new MoveSequence(this, CellIndex, sepIndex.Length);

        for (int i = 1; i <= MoveCount; ++i)
        {
            for (int j = 0; j < sepIndex.Length; ++j)
            {
                seq.AddMove(j, sepIndex[j] * i);
            }
        }

        return(seq);
    }
Ejemplo n.º 21
0
    List <Character> FindCharacters()
    {
        //Get the grid the character is currently in
        GridIndex index = WorldGrid.GetGridIndex(character.transform.position);
        GridCell  cell  = WorldGrid.GetTheWorldGridCell(index);

        //check if the cell position is within the search radius
        //bool xSearch = true, ySearch = true;
        //add all characters to a list
        List <Character> proximityCharacters = new List <Character>();

        //TODO: add more intuitive and wider search logic depending on character behavior
        if (character.gridCell != null)
        {
            if (character.gridCell.character.Count > 0)
            {
                //Add the list of characters. This info is withing grid cell
                proximityCharacters.AddRange(character.gridCell.character);
                //Debug.Log("count : " + proximityCharacters.Count);
                //Debug.Log("names: " + proximityCharacters[0].name + "   " + character.name);
                //Remove yourself from the characters list
                for (int i = 0; i < proximityCharacters.Count; i++)
                {
                    if (proximityCharacters[i].gameObject == character.gameObject)
                    {
                        proximityCharacters.RemoveAt(i);
                        //Debug.Log("Removed");
                    }
                }
            }
        }

        //TODO: Filter the characters to find the ones that are withing this character's FOV
        return(proximityCharacters);
    }
Ejemplo n.º 22
0
 //Initialise PowerUp object
 public void powerUpInit(GridIndex index, GameController controller, float lifeDuration)
 {
     this.index        = index;
     this.controller   = controller;
     this.lifeDuration = lifeDuration;
     StartCoroutine("lifetime"); //Start the lifetime clock
 }
Ejemplo n.º 23
0
    // Special procedure to check if access is still ok when a size1 room is to be removed
    public bool CanTilesBeRemovedSafely(GridIndex[] indizes)
    {
        // A temp movement map without the indizes we want to remove
        TileMap tmpMap = new TileMap(_GridMovements);

        tmpMap.ClearMovements(indizes);

        foreach (GridIndex Index in indizes)
        {
            foreach (Enums.MoveDirections Dir in Enum.GetValues(typeof(Enums.MoveDirections)))
            {
                if (_GridMovements.GridTileHasDirection(Index, Dir))
                {
                    GridIndex OtherIndex = Index.GetAdjacent(Dir);
                    if (Array.IndexOf(indizes, OtherIndex) > -1)
                    {
                        continue;
                    }
                    if (HasPathToEntrance(OtherIndex, tmpMap) == false)
                    {
                        return(false);
                    }
                }
            }
        }
        return(true);
    }
        // Complete the printShortestPath function below.
        static void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end)
        {
            // Print the distance along with the sequence of moves.

            // move order [Name] (dx, dy) -  UL (-1,2), UR (1,2), R (2,0), LR (1,-2), LL (-1,-2), L (-2,0)

            var grid = new GridIndex(n);

            var startNode = grid.GetNode(i_start, j_start);

            startNode.Distance = 0;

            var openNodesQueue = new Queue <Node>();

            openNodesQueue.Enqueue(startNode);

            Node endNode = null;

            while (endNode == null && openNodesQueue.Any())
            {
                var activeNode = openNodesQueue.Dequeue();
                foreach (var move in Movements)
                {
                    var nextNode = grid.TryGetNode(activeNode, move);
                    if (nextNode == null)
                    {
                        continue;
                    }
                    if (nextNode.IsVisited)
                    {
                        continue;
                    }

                    nextNode.PreviousNode = activeNode;
                    nextNode.Distance     = activeNode.Distance + 1;
                    nextNode.Move         = move;
                    if (nextNode.IsPosition(i_end, j_end))
                    {
                        endNode = nextNode;
                        break;
                    }

                    openNodesQueue.Enqueue(nextNode);
                }
            }

            if (endNode == null)
            {
                Console.WriteLine("Impossible");
            }
            else
            {
                Console.WriteLine(endNode.Distance);
                var moveHistory = endNode.GetMoveHistory().Reverse()
                                  .Select(m => m.Name)
                                  .Aggregate((hist, mov) => $"{hist} {mov}");
                Console.WriteLine(moveHistory);
            }
        }
 private List <GemBehaviour> FindAndCombineMatches(GridIndex index, Vector2 direction1, Vector2 direction2)
 {
     return
         (FindMatches(index, searchDirection: direction1)
          .Union(
              FindMatches(index, searchDirection: direction2))
          .ToList());
 }
Ejemplo n.º 26
0
 public static int Tango3DR_extractPreallocatedMeshSegment(
     IntPtr context, ref GridIndex gridIndex, ref APIMesh mesh)
 {
     mesh.numVertices = 0;
     mesh.numFaces    = 0;
     mesh.numTextures = 0;
     return((int)Status.SUCCESS);
 }
Ejemplo n.º 27
0
 //Auto move to the current direction
 public void Move()
 {
     nextCell = new GridIndex(index.x + (int)currentDir.x, index.y + (int)currentDir.y);
     if (!controller.isCellActive(nextCell))
     {
         StartCoroutine("move", currentDir);
     }
 }
Ejemplo n.º 28
0
    protected virtual void SetPoint(T point)
    {
        processList_.Add(point);
        sampleList_.Add(point);
        GridIndex newIdx = GetGridIndex(point.position.x, point.position.y);

        grid[newIdx.x, newIdx.y] = point;
    }
 public static int Tango3DR_extractPreallocatedMeshSegment(
     IntPtr context, ref GridIndex gridIndex, Int32 maxNumVertices, Int32 maxNumFaces, Vector3[] veritices,
     int[] faces, Vector3[] normals, Color32[] colors, out Int32 numVertices, out Int32 numFaces)
 {
     numVertices = 0;
     numFaces    = 0;
     return((int)Status.SUCCESS);
 }
Ejemplo n.º 30
0
    public override ActionData MoveTo(GridIndex gridIndex)
    {
        bool bRest = bFirstAction;
        var  data  = base.MoveTo(gridIndex);

        bFirstAction = false;

        return(new MyActionData(data, bRest));
    }
 public static extern int Tango3DR_extractPreallocatedVoxelGridSegment(
     IntPtr context, ref GridIndex gridIndex, Int32 maxNumVoxels, SignedDistanceVoxel[] voxels);
Ejemplo n.º 32
0
        public VectorFieldUnsteady(VectorFieldUnsteady field, VFJFunction function, int outputDim)
        {
            int scalars = outputDim;
            FieldGrid gridCopy = field._scalarsUnsteady[0].TimeSlices[0].Grid.Copy();
            _scalarsUnsteady = new ScalarFieldUnsteady[outputDim];

            // Reserve the space.
            for (int comp = 0; comp < outputDim; ++comp)
            {
                ScalarField[] fields = new ScalarField[field.Size.T]; //(field.Grid);

                for (int t = 0; t < field.Size.T; ++t)

                {
                    fields[t] = new ScalarField(gridCopy);
                }

                _scalarsUnsteady[comp] = new ScalarFieldUnsteady(fields);
                _scalarsUnsteady[comp].TimeOrigin = field[0].TimeOrigin ?? 0;
                _scalarsUnsteady[comp].InvalidValue = field.InvalidValue;
                _scalarsUnsteady[comp].DoNotScale();
            }

            this.InvalidValue = field.InvalidValue;
            this.TimeOrigin = field.TimeOrigin;

            Grid = field.Grid.Copy();

            // Since the time component is in the grid size as well, we do not need to account for time specially.
            GridIndex indexIterator = new GridIndex(field.Size);
            foreach (GridIndex index in indexIterator)
            {
                Vector v = field.Sample((int)index);

                if (v[0] == InvalidValue)
                {
                    for (int dim = 0; dim < Scalars.Length; ++dim)
                        _scalarsUnsteady[dim][(int)index] = (float)InvalidValue;
                    continue;
                }

                SquareMatrix J = field.SampleDerivative(index);
                Vector funcValue = function(v, J);

                for (int dim = 0; dim < Scalars.Length; ++dim)
                {
                    Scalars[dim][(int)index] = funcValue[dim];
                }
            }
        }
 public static int Tango3DR_extractPreallocatedMeshSegment(
     IntPtr context, ref GridIndex gridIndex, ref APIMesh mesh)
 {
     mesh.numVertices = 0;
     mesh.numFaces = 0;
     mesh.numTextures = 0;
     return (int)Status.SUCCESS;
 }
 public static int Tango3DR_extractPreallocatedMeshSegment(
     IntPtr context, ref GridIndex gridIndex, Int32 maxNumVertices, Int32 maxNumFaces, Vector3[] veritices,
     int[] faces, Vector3[] normals, Color32[] colors, out Int32 numVertices, out Int32 numFaces)
 {
     numVertices = 0;
     numFaces = 0;
     return (int)Status.SUCCESS;
 }
        /// <summary>
        /// Extract a mesh for a single grid index, into a suitable format for Unity Mesh.
        /// </summary>
        /// <returns>
        /// Returns Status.SUCCESS if the mesh is fully extracted and stored in the arrays.  In this case, <c>numVertices</c> 
        /// and <c>numTriangles</c> will say how many vertices and triangles are used, the rest of the array is untouched.
        /// 
        /// Returns Status.INSUFFICIENT_SPACE if the mesh is partially extracted and stored in the arrays.  <c>numVertices</c> 
        /// and <c>numTriangles</c> have the same meaning as if Status.SUCCESS is returned, but in this case the array should 
        /// grow.
        /// 
        /// Returns Status.ERROR or Status.INVALID if some other error occurs.
        /// </returns>
        /// <param name="gridIndex">Grid index to extract.</param>
        /// <param name="vertices">On successful extraction this will get filled out with the vertex positions.</param>
        /// <param name="normals">On successful extraction this will get filled out with vertex normals.</param>
        /// <param name="colors">On successful extraction this will get filled out with vertex colors.</param>
        /// <param name="triangles">On successful extraction this will get filled out with vertex indexes.</param>
        /// <param name="numVertices">Number of vertexes filled out.</param>
        /// <param name="numTriangles">Number of triangles filled out.</param>
        internal Status ExtractMeshSegment(
            GridIndex gridIndex, Vector3[] vertices, Vector3[] normals, Color32[] colors, int[] triangles,
            out int numVertices, out int numTriangles)
        {
            APIMeshGCHandles pinnedHandles = APIMeshGCHandles.Alloc(vertices, normals, colors, triangles);
            APIMesh mesh = APIMesh.FromArrays(vertices, normals, colors, triangles);

            int result = API.Tango3DR_extractPreallocatedMeshSegment(m_context, ref gridIndex, ref mesh);
            numVertices = (int)mesh.numVertices;
            numTriangles = (int)mesh.numFaces;
            pinnedHandles.Free();

            return (Status)result;
        }
        /// <summary>
        /// Extract an array of <c>SignedDistanceVoxel</c> objects.
        /// </summary>
        /// <returns>
        /// Returns Status.SUCCESS if the voxels are fully extracted and stared in the array.  In this case, <c>numVoxels</c>
        /// will say how many voxels are used, the rest of the array is untouched.
        /// 
        /// Returns Status.INVALID if the array length does not exactly equal the number of voxels in a single grid
        /// index.  By default, the number of voxels in a grid index is 16*16*16.
        /// 
        /// Returns Status.INVALID if some other error occurs.
        /// </returns>
        /// <param name="gridIndex">Grid index to extract.</param>
        /// <param name="voxels">
        /// On successful extraction this will get filled out with the signed distance voxels.
        /// </param>
        /// <param name="numVoxels">Number of voxels filled out.</param>
        internal Status ExtractSignedDistanceVoxel(
            GridIndex gridIndex, SignedDistanceVoxel[] voxels, out int numVoxels)
        {
            numVoxels = 0;

            int result = API.Tango3DR_extractPreallocatedVoxelGridSegment(m_context, ref gridIndex, voxels.Length, voxels);
            if (result == (int)Status.SUCCESS)
            {
                // This is the current default number of voxels per grid volume.
                numVoxels = 16 * 16 * 16;
            }

            return (Status)result;
        }
        /// <summary>
        /// Extract a mesh for a single grid index, into a suitable format for Unity Mesh.
        /// </summary>
        /// <returns>
        /// Returns Status.SUCCESS if the mesh is fully extracted and stored in the arrays.  In this case, numVertices 
        /// and numTriangles will say how many vertices and triangles are used, the rest of the array is untouched.
        /// 
        /// Returns Status.INSUFFICIENT_SPACE if the mesh is partially extracted and stored in the arrays.  numVertices 
        /// and numTriangles have the same meaning as if Status.SUCCESS is returned, but in this case the array should 
        /// grow.
        /// 
        /// Returns Status.ERROR or Status.INVALID if some other error occurs.
        /// </returns>
        /// <param name="gridIndex">Grid index to extract.</param>
        /// <param name="vertices">On successful extraction this will get filled out with the vertex positions.</param>
        /// <param name="normals">On successful extraction this will get filled out whith vertex normals.</param>
        /// <param name="colors">On successful extraction this will get filled out with vertex colors.</param>
        /// <param name="triangles">On succesful extraction this will get filled out with vertex indexes.</param>
        /// <param name="numVertices">Number of vertexes filled out.</param>
        /// <param name="numTriangles">Number of triangles filled out.</param>
        internal Status ExtractMeshSegment(
            GridIndex gridIndex, Vector3[] vertices, Vector3[] normals, Color32[] colors, int[] triangles,
            out int numVertices, out int numTriangles)
        {
            numVertices = 0;
            numTriangles = 0;
            int result = API.Tango3DR_extractPreallocatedMeshSegment(
                m_context, ref gridIndex, vertices.Length, triangles.Length / 3, vertices, triangles, normals, colors,
                out numVertices, out numTriangles);

            // NOTE: The 3D Reconstruction library does not handle left handed matrices correctly.  For now, transform
            // into the Unity world space after extraction and account for winding order changes.
            for (int it = 0; it < numVertices; ++it)
            {
                vertices[it] = m_unityWorld_T_startService.MultiplyPoint(vertices[it]);
            }

            for (int it = 0; it < numTriangles; ++it)
            {
                int temp = triangles[(it * 3) + 0];
                triangles[(it * 3) + 0] = triangles[(it * 3) + 1];
                triangles[(it * 3) + 1] = temp;
            }

            return (Status)result;
        }
 public static extern int Tango3DR_extractPreallocatedMeshSegment(
     IntPtr context, ref GridIndex gridIndex, Int32 maxNumVertices, Int32 maxNumFaces, Vector3[] veritices,
     int[] faces, Vector3[] normals, Color32[] colors, out Int32 numVertices, out Int32 numFaces);
 public static extern int Tango3DR_extractPreallocatedMeshSegment(
     IntPtr context, ref GridIndex gridIndex, ref APIMesh mesh);
 public static int Tango3DR_extractPreallocatedVoxelGridSegment(
     IntPtr context, ref GridIndex gridIndex, Int32 maxNumVoxels, SignedDistanceVoxel[] voxels)
 {
     return (int)Status.SUCCESS;
 }
Ejemplo n.º 41
0
        public void ComputeStatistics(out float validRegion, out float mean, out float sd)
        {
            int numValidCells = 0;
            mean = 0;
            sd = 0;

            GridIndex range = new GridIndex(Size);
            foreach(GridIndex idx in range)
            {
                float s = this[(int)idx];
                if(s != InvalidValue)
                {
                    numValidCells++;
                    mean += s;
                }
            }
            validRegion = (float)numValidCells / Size.Product();
            mean /= numValidCells;

            // Compute standard derivative.
            range.Reset();
            foreach (GridIndex idx in range)
            {
                float s = this[(int)idx];
                if (s != InvalidValue)
                {
                    float diff = s - mean;
                    sd += diff * diff;
                }
            }
            sd /= numValidCells;
            sd = (float)Math.Sqrt(sd);
        }
Ejemplo n.º 42
0
        public ScalarField(ScalarField field, SGFunction function, bool needJ = true)
        {
            _data = new float[field.Size.Product()];
            Grid = field.Grid;

            this.InvalidValue = field.InvalidValue;

            GridIndex indexIterator = new GridIndex(field.Size);
            foreach (GridIndex index in indexIterator)
            {
                float s = field[(int)index];

                if (s == InvalidValue)
                {
                    this[(int)index] = (float)InvalidValue;
                }
                else
                {
                    Vector g = needJ ? field.SampleDerivative(index) : new Vec2(0, 0);
                    this[(int)index] = function(s, g);
                }
            }
        }