Esempio n. 1
0
            public ItemData(Term constraint)
            {
                ComponentId = NoComponentId;
                OrderId     = NoOrderId;
                Kind        = ItemKind.Constraint;
                Item        = constraint;

                Variables = new Set <Term>(Term.Compare);
                //// A constraint can only orient variables if it is an equality.
                if (constraint.Symbol != constraint.Owner.SymbolTable.GetOpSymbol(RelKind.Eq))
                {
                    EqData = null;
                    foreach (var t in constraint.Enumerate(x => x.Groundness == Groundness.Variable ? x.Args : null))
                    {
                        if (t.Symbol.IsVariable)
                        {
                            Variables.Add(t);
                        }
                    }
                    return;
                }

                EqData = new OrientationData();
                FindOrientedVars(constraint.Args[0], Variables, EqData.LHSVars, EqData.LHSOriented);
                FindOrientedVars(constraint.Args[1], Variables, EqData.RHSVars, EqData.RHSOriented);
            }
Esempio n. 2
0
        public AppModel()
        {
            CubeTransform = InitializeCubeTransform();

            var inclinometer = Inclinometer.GetDefault();

            if (inclinometer != null)
            {
                inclinometer.ReportInterval  = 200;
                inclinometer.ReadingChanged += (o, e) => InclinationData.Value = e.Reading;
            }

            var orientationSensor = OrientationSensor.GetDefault();

            if (orientationSensor != null)
            {
                orientationSensor.ReportInterval  = 200;
                orientationSensor.ReadingChanged += (o, e) => OrientationData.Value = e.Reading;
            }

            RotationQuaternion       = OrientationData.Select(d => d.Quaternion.ToQuaternion()).ToReadOnlyReactiveProperty();
            RotationQuaternionString = RotationQuaternion.Select(q => $"{q.W:F2}; ({q.X:F2}, {q.Y:F2}, {q.Z:F2})").ToReadOnlyReactiveProperty();

            // Rotation is represented by a matrix, a quaternion or Euler angles (roll, pitch and yaw).
            RotationMatrix = OrientationData.Select(d => d.RotationMatrix.ToMatrix3D()).ToReadOnlyReactiveProperty();
            //RotationMatrix = RotationQuaternion.Select(q => q.ToMatrix3D()).ToReadOnlyReactiveProperty();
            //RotationMatrix = InclinationData.Select(i => i.ToMatrix3D()).ToReadOnlyReactiveProperty();

            // An inverse matrix represents the inverse rotation.
            RotationMatrix
            .ObserveOn(SynchronizationContext.Current)
            //.Subscribe(m => matrixTransform.Matrix = m);
            .Subscribe(m => { m.Invert(); matrixTransform.Matrix = m; });
        }
Esempio n. 3
0
        /// <summary>
        /// Updates the Emitter's Position and Orientation according to its Velocities and Accelerations, and returns how many Particles should be emitted this frame.
        /// </summary>
        /// <param name="fElapsedTimeInSeconds">How long (in seconds) it has been since this function was called.</param>
        /// <returns>Returns the number of Particles that should be emitted.</returns>
        public int UpdateAndGetNumberOfParticlesToEmit(float fElapsedTimeInSeconds)
        {
            // Update the Emitter's Positional, Rotational, and Pivotal Data
            PositionData.Update(fElapsedTimeInSeconds);
            OrientationData.Update(fElapsedTimeInSeconds);
            PivotPointData.Update(fElapsedTimeInSeconds);

            // Calculate how many Particles should be generated

            // If Particles should be emitted
            int iNumberOfParticlesToEmit = 0;

            if (_particlesPerSecond > 0.0f && Enabled)
            {
                // If the Emitter is emitting Particles Automatically
                if (EmitParticlesAutomatically)
                {
                    // Get how many Particles should be emitted
                    iNumberOfParticlesToEmit = CalculateHowManyParticlesToEmit(fElapsedTimeInSeconds);
                }
                // Else if Burst Particles should be emitted for a specific amount of Time
                else if (_burstTimeInSeconds > 0.0f)
                {
                    // Make sure we do not emit Particles for too long
                    float fModifiedElapsedTime = fElapsedTimeInSeconds;
                    if (fModifiedElapsedTime > _burstTimeInSeconds)
                    {
                        // Only emit Particles for as long as the Burst lasts
                        fModifiedElapsedTime = _burstTimeInSeconds;
                    }

                    // Get how many Particles should be emitted
                    iNumberOfParticlesToEmit = CalculateHowManyParticlesToEmit(fModifiedElapsedTime);

                    // Subtract the Elapsed Time from the Burst Time
                    BurstTime -= fModifiedElapsedTime;
                }
                // Else if a specific Number Of Burst Particles should be emitted
                else if (_burstNumberOfParticles > 0)
                {
                    // Get how many Particles should be emitted
                    iNumberOfParticlesToEmit = CalculateHowManyParticlesToEmit(fElapsedTimeInSeconds);

                    // If we are emitting too many Particles
                    if (iNumberOfParticlesToEmit > _burstNumberOfParticles)
                    {
                        iNumberOfParticlesToEmit = _burstNumberOfParticles;
                    }

                    // Subtract the Number Of Particles being Emitted from the Number Of Particles that still need to be Emitted
                    BurstParticles -= iNumberOfParticlesToEmit;
                }
            }

            // Return how many Particles should be emitted
            return(iNumberOfParticlesToEmit);
        }
Esempio n. 4
0
        public static DeviceInfo GetDeviceWithSupportedOrientations(ScreenOrientation[] orientations, int screenWidth = 500, int screenHeight = 1000, Rect portraitSafeArea = default, float screenDpi = 200)
        {
            if (portraitSafeArea == default)
            {
                portraitSafeArea = new Rect(0, 0, 500, 1000);
            }

            if (orientations.Length > 4)
            {
                throw new ArgumentException("There are 4 possible screen orientations");
            }

            var screen = new ScreenData()
            {
                dpi          = screenDpi,
                width        = screenWidth,
                height       = screenHeight,
                orientations = new OrientationData[orientations.Length]
            };

            for (int i = 0; i < orientations.Length; i++)
            {
                var orientationData = new OrientationData();
                orientationData.orientation = orientations[i];

                switch (orientations[i])
                {
                case ScreenOrientation.Portrait:
                    orientationData.safeArea = portraitSafeArea;
                    break;

                case ScreenOrientation.PortraitUpsideDown:
                    orientationData.safeArea = new Rect(screenWidth - portraitSafeArea.x - portraitSafeArea.width, screenHeight - portraitSafeArea.y - portraitSafeArea.height, portraitSafeArea.width, portraitSafeArea.height);
                    break;

                case ScreenOrientation.LandscapeLeft:
                    orientationData.safeArea = new Rect(screenWidth - portraitSafeArea.y - portraitSafeArea.height, portraitSafeArea.x, portraitSafeArea.height, portraitSafeArea.width);
                    break;

                case ScreenOrientation.LandscapeRight:
                    orientationData.safeArea = new Rect(portraitSafeArea.y, screenWidth - portraitSafeArea.x - portraitSafeArea.width, portraitSafeArea.height, portraitSafeArea.width);
                    break;
                }

                orientationData.cutouts = null;
                screen.orientations[i]  = orientationData;
            }

            var device = new DeviceInfo()
            {
                Screens = new[] { screen }
            };

            return(device);
        }
    private unsafe void PacketReceived(Packet.Header *header)
    {
        switch (header->Type)
        {
        case (byte)CustomPackets.Type.OrientationData:
        {
            Orientation = *((CustomPackets.OrientationDataPacket *)header);

            DebugTools.Print($"DATA: {Orientation}");
            break;
        }

        case (byte)CustomPackets.Type.ProximityData:
        {
            ProximityData data = *((CustomPackets.ProximityDataPacket *)header);
            DebugTools.Print($"DATA: {data}");

            if (data.ID < 0 || data.ID >= ProximityContent.Length)
            {
                DebugTools.Print($"Invalid sensor index ID: {data.ID}");
                return;
            }

            int count = ProximityContent[data.ID].Count;
            int cap   = m_ContentCapacity - 1;
            for (; count-- > cap;)
            {
                ProximityContent[data.ID].RemoveAt(0);
            }

            ProximityContent[data.ID].Add(data);

            break;
        }

        default:
        {
            DebugTools.Print($"Unknown packet type: {header->Type}");
            break;
        }
        }
    }
Esempio n. 6
0
            /// <summary>
            /// W.R.T. orientations, comprehension variables are simulated as an equality whose LHS can never orient
            /// the variables on the RHS.
            /// </summary>
            public ItemData(Term comprVar, ComprehensionData comprData)
            {
                ComponentId = NoComponentId;
                Item        = comprVar;
                OrderId     = NoOrderId;
                Kind        = ItemKind.Compr;

                Variables = new Set <Term>(Term.Compare, comprData.ReadVars.Keys);
                Variables.Add(comprVar);

                //// A compr var is oriented if its reads are oriented, but a compr var
                //// cannot orient its reads.
                EqData = new OrientationData();
                EqData.LHSVars.Add(comprVar);
                EqData.LHSOriented.Add(comprVar);
                foreach (var v in comprData.ReadVars.Keys)
                {
                    EqData.RHSVars.Add(v);
                }
            }
Esempio n. 7
0
            public ItemData(Term findVar, Term pattern)
            {
                ComponentId = NoComponentId;
                OrderId     = NoOrderId;
                Item        = findVar;
                Kind        = ItemKind.Find;

                Variables = new Set <Term>(Term.Compare);
                Variables.Add(findVar);
                EqData = new OrientationData();
                EqData.LHSVars.Add(findVar);
                EqData.LHSOriented.Add(findVar);
                foreach (var t in pattern.Enumerate(x => x.Groundness == Groundness.Variable ? x.Args : null))
                {
                    if (t.Symbol.IsVariable)
                    {
                        EqData.RHSVars.Add(t);
                        EqData.RHSOriented.Add(t);
                        Variables.Add(t);
                    }
                }
            }
Esempio n. 8
0
        /**
         * @return <code>true</code> when the sensor was successfully enabled, <code>false</code> otherwise.
         */
        public bool EnableOrientationSensor(/* final */ Context pContext, /* final */ IOrientationListener pOrientationListener, /* final */ OrientationSensorOptions pOrientationSensorOptions)
        {
            /* final */
            SensorManager sensorManager = (SensorManager)pContext.GetSystemService(Context.SensorService);

            if (this.IsSensorSupported(sensorManager, SensorType.Orientation))
            {
                this.mOrientationListener = pOrientationListener;

                if (this.mOrientationData == null)
                {
                    this.mOrientationData = new OrientationData();
                }

                this.RegisterSelfAsSensorListener(sensorManager, SensorType.Orientation, pOrientationSensorOptions.getSensorDelay());

                return(true);
            }
            else
            {
                return(false);
            }
        }