예제 #1
0
        public void StandardMapYAxisScheduled()
        {
            NativeArray <Vector3> targetPositions = new NativeArray <Vector3>(targets, Allocator.TempJob);
            NativeArray <float>   Weights         = new NativeArray <float>(_weights, Allocator.TempJob);

            DotToVecJob job = new DotToVecJob()
            {
                targets     = targetPositions,
                scaled      = scaled,
                my_position = position,
                range       = range,
                weight      = weight,
                angle       = angle,
                invertScale = invertScale,
                axis        = axis,
                Weights     = Weights,
                direction   = direction
            };

            // compute
            JobHandle handle = job.Schedule();

            handle.Complete();

            // check result
            float[] expected = { 1f, 0f, -1f, 0f };

            Assert.AreEqual(expected[0], Weights[0], TestUtilities.DOTPRODTOLERANCE);
            Assert.AreEqual(expected[1], Weights[1], TestUtilities.DOTPRODTOLERANCE);
            Assert.AreEqual(expected[2], Weights[2], TestUtilities.DOTPRODTOLERANCE);
            Assert.AreEqual(expected[3], Weights[3], TestUtilities.DOTPRODTOLERANCE);

            targetPositions.Dispose();
            Weights.Dispose();
        }
예제 #2
0
        public void XAxis()
        {
            axis = RotationAxis.XAxis;

            NativeArray <Vector3> targetPositions = new NativeArray <Vector3>(targets, Allocator.Temp);
            NativeArray <float>   Weights         = new NativeArray <float>(_weights, Allocator.Temp);

            DotToVecJob job = new DotToVecJob()
            {
                targets     = targetPositions,
                scaled      = scaled,
                my_position = position,
                range       = range,
                weight      = weight,
                angle       = angle,
                invertScale = invertScale,
                axis        = axis,
                Weights     = Weights,
                direction   = direction
            };

            // compute
            job.Execute();

            // check result
            float[] expected = { 1f, 0f, -1f, 0f };

            Assert.AreEqual(expected[0], Weights[0], TestUtilities.DOTPRODTOLERANCE);
            Assert.AreEqual(expected[1], Weights[1], TestUtilities.DOTPRODTOLERANCE);
            Assert.AreEqual(expected[2], Weights[2], TestUtilities.DOTPRODTOLERANCE);
            Assert.AreEqual(expected[3], Weights[3], TestUtilities.DOTPRODTOLERANCE);

            targetPositions.Dispose();
            Weights.Dispose();
        }
예제 #3
0
        public void TargetPositionsDisposed()
        {
            NativeArray <Vector3> targetPositions = new NativeArray <Vector3>(targets, Allocator.Temp);
            NativeArray <float>   Weights         = new NativeArray <float>(_weights, Allocator.Temp);

            DotToVecJob job = new DotToVecJob()
            {
                targets     = targetPositions,
                scaled      = scaled,
                my_position = position,
                range       = range,
                weight      = weight,
                angle       = angle,
                invertScale = invertScale,
                axis        = axis,
                Weights     = Weights,
                direction   = direction
            };

            // compute
            job.Execute();

            targetPositions.Dispose();
            // check result
            Assert.AreEqual(false, targetPositions.IsCreated);

            Weights.Dispose();
        }
        /// <summary>
        /// Get all the jobs from the steering behaviours, includes both behaviours and masks.
        /// </summary>
        /// <returns></returns>
        public DotToVecJob[] GetJobs()
        {
            DotToVecJob[] jobs = new DotToVecJob[SteeringBehaviours.Length + SteeringMasks.Length];
            for (int i = 0; i < SteeringBehaviours.Length; i++)
            {
                jobs[i] = SteeringBehaviours[i].GetJob();
            }
            for (int i = SteeringBehaviours.Length; i < SteeringBehaviours.Length + SteeringMasks.Length; i++)
            {
                jobs[i] = SteeringMasks[i - SteeringBehaviours.Length].GetJob();
            }

            return(jobs);
        }
예제 #5
0
        public void RangeYAxis()
        {
            // ------------------- Out of Range -------------------
            range   = 10;
            targets = new Vector3[] { new Vector3(0, 0, 15) };

            NativeArray <Vector3> targetPositions = new NativeArray <Vector3>(targets, Allocator.Temp);
            NativeArray <float>   Weights         = new NativeArray <float>(_weights, Allocator.Temp);

            DotToVecJob job = new DotToVecJob()
            {
                targets     = targetPositions,
                scaled      = scaled,
                my_position = position,
                range       = range,
                weight      = weight,
                angle       = angle,
                invertScale = invertScale,
                axis        = axis,
                Weights     = Weights,
                direction   = direction
            };

            // compute
            job.Execute();

            // check result
            float[] expected = { 0f, 0f, 0f, 0f };

            Assert.AreEqual(expected[0], Weights[0], TestUtilities.DOTPRODTOLERANCE);
            Assert.AreEqual(expected[1], Weights[1], TestUtilities.DOTPRODTOLERANCE);
            Assert.AreEqual(expected[2], Weights[2], TestUtilities.DOTPRODTOLERANCE);
            Assert.AreEqual(expected[3], Weights[3], TestUtilities.DOTPRODTOLERANCE);

            targetPositions.Dispose();

            // ------------------- In Range -------------------
            targets = new Vector3[] { new Vector3(0, 0, 8) };

            NativeArray <Vector3> newTargetPositions = new NativeArray <Vector3>(targets, Allocator.Temp);

            job = new DotToVecJob()
            {
                targets     = newTargetPositions,
                scaled      = scaled,
                my_position = position,
                range       = range,
                weight      = weight,
                angle       = angle,
                invertScale = invertScale,
                axis        = axis,
                Weights     = Weights,
                direction   = direction
            };

            // compute
            job.Execute();

            // check result
            expected = new float[] { 1f, 0f, -1f, 0f };


            //Assert.AreEqual(expected[0], Weights[0], TestUtilities.DOTPRODTOLERANCE));
            Assert.AreEqual(expected[0], Weights[0]);
            Assert.AreEqual(expected[1], Weights[1], TestUtilities.DOTPRODTOLERANCE);
            Assert.AreEqual(expected[2], Weights[2], TestUtilities.DOTPRODTOLERANCE);
            Assert.AreEqual(expected[3], Weights[3], TestUtilities.DOTPRODTOLERANCE);

            newTargetPositions.Dispose();

            // ------------------- Same Position -------------------
            targets = new Vector3[] { new Vector3(0, 0, 0) };
            NativeArray <Vector3> targetOnMe = new NativeArray <Vector3>(targets, Allocator.Temp);

            job = new DotToVecJob()
            {
                targets     = targetOnMe,
                scaled      = scaled,
                my_position = position,
                range       = range,
                weight      = weight,
                angle       = angle,
                invertScale = invertScale,
                axis        = axis,
                Weights     = Weights,
                direction   = direction
            };

            job.Execute();

            expected = new float[] { 0, 0, 0, 0 };
            Assert.AreEqual(expected[0], Weights[0], TestUtilities.DOTPRODTOLERANCE);
            Assert.AreEqual(expected[1], Weights[1], TestUtilities.DOTPRODTOLERANCE);
            Assert.AreEqual(expected[2], Weights[2], TestUtilities.DOTPRODTOLERANCE);
            Assert.AreEqual(expected[3], Weights[3], TestUtilities.DOTPRODTOLERANCE);

            targetOnMe.Dispose();
            Weights.Dispose();
        }