Exemplo n.º 1
0
    //returns a ranom ship spawn location
    public Vector3 GetRandomShipSpawnLocation()
    {
        shipFloorLocationList = new List <SpatialLocation>();

        ////Added for quick testing
        //spatialLocationList = new List<SpatialLocation>();
        //if (spatialLocationList.Count ==0)
        //{
        //    return new Vector3(1,-1 ,1); // quick testing.
        //}

        foreach (SpatialLocation curLocation in spatialLocationList)
        {
            if (curLocation.name == "shipFloor")
            {
                shipFloorLocationList.Add(curLocation);
            }
        }

        //Getting a random Location
        System.Random   r           = new System.Random();
        SpatialLocation rndLocation = shipFloorLocationList[r.Next(shipFloorLocationList.Count)];

        Vector3 rndPositon = rndLocation.position;

        return(rndPositon);
    }
        private bool GetHistoricalPose(out Vector3 cameraPosition, out Quaternion cameraRotation)
        {
#if !UNITY_EDITOR && UNITY_WSA
            SpatialCoordinateSystem unityCoordinateSystem = Marshal.GetObjectForIUnknown(WorldManager.GetNativeISpatialCoordinateSystemPtr()) as SpatialCoordinateSystem;
            if (unityCoordinateSystem == null)
            {
                Debug.LogError("Failed to get the native SpatialCoordinateSystem");
                cameraPosition = default(Vector3);
                cameraRotation = default(Quaternion);
                return(false);
            }

            if (timeConversionCalendar == null)
            {
                timeConversionCalendar = new Calendar();
            }

            timeConversionCalendar.SetToNow();

            PerceptionTimestamp perceptionTimestamp = PerceptionTimestampHelper.FromHistoricalTargetTime(timeConversionCalendar.GetDateTime());

            if (perceptionTimestamp != null)
            {
                SpatialLocator locator = SpatialLocator.GetDefault();
                if (locator != null)
                {
                    SpatialLocation headPose = locator.TryLocateAtTimestamp(perceptionTimestamp, unityCoordinateSystem);
                    if (headPose != null)
                    {
                        var systemOrientation = headPose.Orientation;
                        var systemPostion     = headPose.Position;

                        // Convert the orientation and position from Windows to Unity coordinate spaces
                        cameraRotation.x = -systemOrientation.X;
                        cameraRotation.y = -systemOrientation.Y;
                        cameraRotation.z = systemOrientation.Z;
                        cameraRotation.w = systemOrientation.W;

                        cameraPosition.x = systemPostion.X;
                        cameraPosition.y = systemPostion.Y;
                        cameraPosition.z = -systemPostion.Z;
                        return(true);
                    }
                }
            }

            cameraPosition = default(Vector3);
            cameraRotation = default(Quaternion);
            return(false);
#else
            cameraPosition = Camera.main.transform.position;
            cameraRotation = Camera.main.transform.rotation;
            return(true);
#endif
        }
Exemplo n.º 3
0
 public void setSpatialParent(EnumNamespace.Preposition preposition, PhysicalEntity parentEntity)
 {
     spatialParent = new SpatialLocation(this, preposition, parentEntity);
     //TODO add this as a child of parent object to make it a double linked tree
 }
Exemplo n.º 4
0
    //Examples of ways to et locations and store them in location list.
    private IEnumerator GetSpawnLocations()
    {
        yield return(new WaitForSeconds(3));

        //IntPtr resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(resultsTopology);
        //int locationCount = SpatialUnderstandingDllTopology.QueryTopology_FindLargestPositionsOnFloor(
        //    resultsTopology.Length, resultsTopologyPtr);
        //Debug.Log(locationCount);
        //Debug.Log(resultsTopology[0].position);

        //END OF TEST EXAMPLES.. FINDING LOCATIONS FOR THE FLOOR NOW.
        SpatialUnderstandingDllObjectPlacement.Solver_RemoveAllObjects();
        SpaceVisualizer.Instance.ClearGeometry();
        IntPtr resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(resultsTopology);
        int    locationCount      = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsOnFloor(
            GameManager.Instance.shipManager.shipMaxHeight, GameManager.Instance.shipManager.shipMinHeight,
            resultsTopology.Length, resultsTopologyPtr);

        foreach (SpatialUnderstandingDllTopology.TopologyResult potentialShipFloor in resultsTopology)
        {
            SpatialLocation shipFloor = new SpatialLocation();
            shipFloor.position = potentialShipFloor.position;
            shipFloor.normal   = potentialShipFloor.normal;
            shipFloor.name     = "shipFloor"; // this sould be a descriptive name of what positin is.
            spatialLocationList.Add(shipFloor);
        }

        // GETTING SPAWN LOCATION FOR GRID
        //    SpaceVisualizer.Instance.ClearGeometry();
        //    resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(resultsTopology);
        //    locationCount = SpatialUnderstandingDllTopology.QueryTopology_FindLargestPositionsOnFloor(
        //resultsTopology.Length, resultsTopologyPtr);

        //    SpatialLocation gridSittingLoc = new SpatialLocation();
        //    gridSittingLoc.position = resultsTopology[0].position;
        //    gridSittingLoc.normal = resultsTopology[0].normal;
        //    gridSittingLoc.name = "gridSittingLoc"; // this sould be a descriptive name of what positin is.
        //    spatialLocationList.Add(gridSittingLoc);


        //SpatialUnderstandingDllObjectPlacement.Solver_RemoveAllObjects();
        //SpaceVisualizer.Instance.ClearGeometry();
        //float sitMinHeight = 0f;
        //float sitMaxHeight = 1.2f;
        //float sitMinFacingClearance = 2f;
        //SpatialUnderstandingDllObjectPlacement.Solver_RemoveAllObjects();
        //resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(resultsTopology);
        //int locationCount3 = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsSittable(
        //    sitMinHeight, sitMaxHeight, sitMinFacingClearance,
        //    resultsTopology.Length, resultsTopologyPtr);
        //SpatialLocation gridSittingLoc = new SpatialLocation();
        //gridSittingLoc.position = resultsTopology[0].position;
        //gridSittingLoc.normal = resultsTopology[0].normal;
        //gridSittingLoc.name = "gridSittingLoc"; // this sould be a descriptive name of what positin is.
        //spatialLocationList.Add(gridSittingLoc);



        SpatialUnderstandingDllObjectPlacement.Solver_RemoveAllObjects();
        SpaceVisualizer.Instance.ClearGeometry();
        IntPtr resultsShapePtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(resultsShape);
        int    shapeCount      = SpatialUnderstandingDllShapes.QueryShape_FindShapeHalfDims(
            "Grid",
            resultsShape.Length, resultsShapePtr);

        Debug.Log(resultsShape[0].position);
        Debug.Log(resultsShape[0].halfDims);
        SpatialLocation gridSittingLoc = new SpatialLocation();

        gridSittingLoc.position = resultsShape[0].position;
        gridSittingLoc.normal   = resultsShape[0].halfDims;
        gridSittingLoc.name     = "gridSittingLoc"; // this sould be a descriptive name of what positin is.
        spatialLocationList.Add(gridSittingLoc);
        yield return(null);
    }
Exemplo n.º 5
0
 public SpatialLocation(SpatialLocation spatialLocation)
 {
     Value = spatialLocation.Value;
 }