Пример #1
0
    private void UpdateAxis(AxisDetails details)
    {
        if (!details.Active)
        {
            return;
        }
        var isPositiveTrend = details.AxisTrend > details.OriginalAxis;
        var velocityChange  = MoveSpeed * Time.deltaTime;

        if (!DoesPassAxisTrend(isPositiveTrend, details.GetPosition() + details.Velocity, details.AxisTrend))
        {
            details.Velocity += isPositiveTrend ? velocityChange : -velocityChange;
        }
        else if (DoesPassAxisTrend(isPositiveTrend, details.GetPosition() + details.Velocity - velocityChange, details.AxisTrend))
        {
            details.Velocity += isPositiveTrend ? -velocityChange : velocityChange;
        }
        details.SetPosition(details.Velocity);
        if (DoesPassAxisTrend(isPositiveTrend, details.GetPosition(), details.AxisTrend))
        {
            details.AxisTrend = isPositiveTrend
                ? details.OriginalAxis - (float)_random.NextDouble() * MoveVariance / 2
                : details.OriginalAxis + (float)_random.NextDouble() * MoveVariance / 2;
        }
    }
Пример #2
0
        public MainViewModel()
        {
            _scale    = 1.0;
            _rotation = new Vector(0, 0);

            StartAxis = new AxisDetails(new Vector3(-20, 0, 0), new Vector3(0, 0, 0));
            EndAxis   = new AxisDetails(new Vector3(20, 0, -10), new Vector3(0, 0, 0));

            _quaternionAxis = new QuaternionAxis(StartAxis.Position, StartAxis.QuaternionRotation, EndAxis.Position, EndAxis.QuaternionRotation);
            _eulerAxis      = new EulerAxis(StartAxis.Position, StartAxis.Rotation, EndAxis.Position, EndAxis.Rotation);

            _timer = new DispatcherTimer {
                Interval = new TimeSpan(0, 0, 0, 0, 10)
            };
            _timer.Tick    += _timer_Tick;
            AnimationLength = 7;

            FrameCount = 13;
        }
Пример #3
0
 public void Start()
 {
     _xAxisDetails = new AxisDetails(XAxis,
                                     x => transform.position = new Vector3(transform.position.x + x, transform.position.y, transform.position.z),
                                     () => transform.position.x);
     _yAxisDetails = new AxisDetails(YAxis,
                                     y => transform.position = new Vector3(transform.position.x, transform.position.y + y, transform.position.z),
                                     () => transform.position.y);
     _zAxisDetails = new AxisDetails(ZAxis,
                                     z => transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + z),
                                     () => transform.position.z);
     _xRotationDetails = new RotationDetails(XRotation, new List <bool> {
         true, false
     }.Random(), () => transform.eulerAngles.x);
     _yRotationDetails = new RotationDetails(YRotation, new List <bool> {
         true, false
     }.Random(), () => transform.eulerAngles.y);
     _zRotationDetails = new RotationDetails(ZRotation, new List <bool> {
         true, false
     }.Random(), () => transform.eulerAngles.z);
     _random = new Random(Guid.NewGuid().GetHashCode());
 }
Пример #4
0
        /// <summary>
        /// Resolves the device.
        /// </summary>
        /// <returns>returns JoystickDevice if driver is for this device or null</returns>
        /// <param name="info">Info.</param>
        /// <param name="hidDevice">Hid device.</param>
        public IDevice ResolveDevice(IHIDDevice hidDevice)
        {
            this._hidInterface = hidDevice.hidInterface;

            IntPtr deviceRef = hidDevice.deviceHandle;

            JoystickDevice device;
            int            axisIndex   = 0;
            int            buttonIndex = 0;

            Native.CFArray   elements = new Native.CFArray();
            IOHIDElementRef  element;
            IOHIDElementType type;

            //copy all matched
            elements.typeRef = Native.IOHIDDeviceCopyMatchingElements(deviceRef, IntPtr.Zero, (int)Native.IOHIDOptionsType.kIOHIDOptionsTypeNone);

            int numButtons = 0;

            int numPov = 0;

            int numElements    = elements.Length;
            int HIDElementType = Native.IOHIDElementGetTypeID();

            //check for profile
            DeviceProfile profile = hidDevice.loadProfile();



            IAxisDetails axisDetailsPovX = null;
            IAxisDetails axisDetailsPovY = null;

            List <IAxisDetails> axisDetailsList = new List <IAxisDetails>();


            IAxisDetails axisDetails;

            for (int elementIndex = 0; elementIndex < numElements; elementIndex++)
            {
                element = elements[elementIndex].typeRef;


                if (element != IntPtr.Zero && Native.CFGetTypeID(element) == HIDElementType)
                {
                    type = Native.IOHIDElementGetType(element);


                    // All of the axis elements I've ever detected have been kIOHIDElementTypeInput_Misc. kIOHIDElementTypeInput_Axis is only included for good faith...
                    if (type == IOHIDElementType.kIOHIDElementTypeInput_Misc ||
                        type == IOHIDElementType.kIOHIDElementTypeInput_Axis)
                    {
                        axisDetails = new AxisDetails();

                        axisDetails.uid        = Native.IOHIDElementGetCookie(element);
                        axisDetails.min        = (int)Native.IOHIDElementGetLogicalMin(element);
                        axisDetails.max        = (int)Native.IOHIDElementGetLogicalMax(element);
                        axisDetails.isNullable = Native.IOHIDElementHasNullState(element);



                        if (Native.IOHIDElementGetUsage(element) == (uint)Native.HIDUsageGD.Hatswitch)
                        {
                            axisDetails.isHat = true;
                            axisDetailsPovX   = axisDetails;

                            axisDetailsPovY = new AxisDetails();

                            axisDetailsPovY.uid        = Native.IOHIDElementGetCookie(element);
                            axisDetailsPovY.min        = (int)Native.IOHIDElementGetLogicalMin(element);
                            axisDetailsPovY.max        = (int)Native.IOHIDElementGetLogicalMax(element);
                            axisDetailsPovY.isNullable = Native.IOHIDElementHasNullState(element);
                            axisDetailsPovY.isHat      = true;

                            numPov++;
                        }
                        else
                        {
                            if (axisDetails.min == 0)
                            {
                                axisDetails.isTrigger = true;
                            }
                            axisDetailsList.Add(axisDetails);
                        }
                    }
                    else if (type == IOHIDElementType.kIOHIDElementTypeInput_Button)
                    {
                        numButtons++;
                    }
                }
            }


            if (axisDetailsPovX != null)
            {
                int diff;

                diff = axisDetailsList.Count - 8;
                //need 2 slots for Pov X,Y
                if (diff >= 0)
                {
                    //just insert them
                    axisDetailsList.Insert((int)JoystickAxis.AxisPovX, axisDetailsPovX);
                    axisDetailsList.Insert((int)JoystickAxis.AxisPovY, axisDetailsPovY);
                }
                else if (diff < -1)
                {
                    diff = diff + 2;
                    while (diff < 0)
                    {
                        axisDetailsList.Add(null);
                        diff += 1;
                    }

                    axisDetailsList.Add(axisDetailsPovX);
                    axisDetailsList.Add(axisDetailsPovY);
                }
                else                  //=-1
                {
                    axisDetailsList.Resize(9);
                    axisDetailsList[(int)JoystickAxis.AxisPovX] = axisDetailsPovX;
                    axisDetailsList[(int)JoystickAxis.AxisPovY] = axisDetailsPovY;
                }
            }


            device         = new JoystickDevice(hidDevice.index, hidDevice.PID, hidDevice.VID, hidDevice.ID, axisDetailsList.Count, numButtons, this);
            device.Name    = hidDevice.Name;
            device.numPOV  = numPov;
            device.profile = profile;

            for (; axisIndex < device.Axis.Count; axisIndex++)
            {
                device.Axis[(JoystickAxis)axisIndex] = axisDetailsList[axisIndex];
                if (profile != null && profile.axisNaming.Length > axisIndex && device.Axis[axisIndex] != null)
                {
                    device.Axis[axisIndex].name = profile.axisNaming [axisIndex];
                }
            }



            for (int elementIndex = 0; elementIndex < numElements; elementIndex++)
            {
                element = elements[elementIndex].typeRef;

                if (element != IntPtr.Zero && Native.CFGetTypeID(element) == HIDElementType)
                {
                    type = Native.IOHIDElementGetType(element);
                    if (type == IOHIDElementType.kIOHIDElementTypeInput_Button)
                    {
                        //
                        device.Buttons[buttonIndex] = new ButtonDetails(Native.IOHIDElementGetCookie(element));


                        if (profile != null && profile.buttonNaming.Length > buttonIndex)
                        {
                            device.Buttons[buttonIndex].name = profile.buttonNaming [buttonIndex];
                        }
                        buttonIndex++;
                    }
                }
            }



            //joystick.isReady = false;

            device.Extension = new OSXDefaultExtension();



            return(device);
        }
Пример #5
0
		/// <summary>
		/// Resolves the device.
		/// </summary>
		/// <returns>returns JoystickDevice if driver is for this device or null</returns>
		/// <param name="info">Info.</param>
		/// <param name="hidDevice">Hid device.</param>
		public IDevice ResolveDevice (IHIDDevice hidDevice)
		{
	
			this._hidInterface = hidDevice.hidInterface;

			IntPtr deviceRef=hidDevice.deviceHandle;

			JoystickDevice device;
			int axisIndex=0;
			int buttonIndex=0;

			Native.CFArray elements=new Native.CFArray();
			IOHIDElementRef element;
			IOHIDElementType type;

			//copy all matched 
			elements.typeRef=Native.IOHIDDeviceCopyMatchingElements(deviceRef, IntPtr.Zero,(int)Native.IOHIDOptionsType.kIOHIDOptionsTypeNone );
			
			int numButtons=0;
		
			int numPov=0;

			int numElements=elements.Length;
			int HIDElementType=Native.IOHIDElementGetTypeID();

			//check for profile
			DeviceProfile profile = hidDevice.loadProfile();




					




			IAxisDetails axisDetailsPovX=null;
			IAxisDetails axisDetailsPovY=null;

			List<IAxisDetails> axisDetailsList = new List <IAxisDetails>();
		

			IAxisDetails axisDetails;
			
							for (int elementIndex = 0; elementIndex < numElements; elementIndex++){

									element =  elements[elementIndex].typeRef;


								if(element!=IntPtr.Zero && Native.CFGetTypeID(element) == HIDElementType){
												
												type = Native.IOHIDElementGetType(element);
							
							
												// All of the axis elements I've ever detected have been kIOHIDElementTypeInput_Misc. kIOHIDElementTypeInput_Axis is only included for good faith...
												if (type == IOHIDElementType.kIOHIDElementTypeInput_Misc ||
												    type == IOHIDElementType.kIOHIDElementTypeInput_Axis) {
												


													axisDetails=new AxisDetails();
													
													axisDetails.uid=Native.IOHIDElementGetCookie(element);
													axisDetails.min=(int)Native.IOHIDElementGetLogicalMin(element);
													axisDetails.max=(int)Native.IOHIDElementGetLogicalMax(element);
													axisDetails.isNullable=Native.IOHIDElementHasNullState(element);

													

					

										            
													if(Native.IOHIDElementGetUsage(element)==(uint)Native.HIDUsageGD.Hatswitch){
												
														axisDetails.isHat=true;
														axisDetailsPovX=axisDetails;
		
														axisDetailsPovY=new AxisDetails();
														
														axisDetailsPovY.uid=Native.IOHIDElementGetCookie(element);
														axisDetailsPovY.min=(int)Native.IOHIDElementGetLogicalMin(element);
														axisDetailsPovY.max=(int)Native.IOHIDElementGetLogicalMax(element);
														axisDetailsPovY.isNullable=Native.IOHIDElementHasNullState(element);
														axisDetailsPovY.isHat=true;

							numPov++;


													}else{
							if(axisDetails.min==0) axisDetails.isTrigger=true;
							axisDetailsList.Add(axisDetails);

						}

										          
											
												} else if (type == IOHIDElementType.kIOHIDElementTypeInput_Button) {
													numButtons++;
												}
								}
			
						}


			if (axisDetailsPovX != null) {
				int diff;

				diff=axisDetailsList.Count -8;
				//need 2 slots for Pov X,Y
				if(diff>=0){
					//just insert them
					axisDetailsList.Insert((int)JoystickAxis.AxisPovX,axisDetailsPovX);
					axisDetailsList.Insert((int)JoystickAxis.AxisPovY,axisDetailsPovY);
				}else if(diff<-1){
					diff=diff+2;
					while(diff<0){
						axisDetailsList.Add(null);
						diff+=1;
					}

					axisDetailsList.Add(axisDetailsPovX);
					axisDetailsList.Add(axisDetailsPovY);

				}else{//=-1
					axisDetailsList.Resize (9);
					axisDetailsList[(int)JoystickAxis.AxisPovX]=axisDetailsPovX;
					axisDetailsList[(int)JoystickAxis.AxisPovY]=axisDetailsPovY;
				}

								
								
			}


			device=new JoystickDevice(hidDevice.index,hidDevice.PID,hidDevice.VID,hidDevice.ID,axisDetailsList.Count,numButtons,this);
			device.Name = hidDevice.Name;
			device.numPOV = numPov;
			device.profile = profile;

			for(;axisIndex<device.Axis.Count;axisIndex++)
			{
				
				device.Axis[(JoystickAxis)axisIndex]=axisDetailsList[axisIndex];
				if (profile != null && profile.axisNaming.Length > axisIndex && device.Axis[axisIndex]!=null) {
					device.Axis[axisIndex].name = profile.axisNaming [axisIndex];
					
				}

			}
			

			
			
			
			for (int elementIndex = 0; elementIndex < numElements; elementIndex++){
				element = elements[elementIndex].typeRef;

				if(element!=IntPtr.Zero && Native.CFGetTypeID(element) == HIDElementType){
				type = Native.IOHIDElementGetType(element);
				 if (type == IOHIDElementType.kIOHIDElementTypeInput_Button) {
								//
								device.Buttons[buttonIndex]=new ButtonDetails(Native.IOHIDElementGetCookie(element));


						if (profile != null && profile.buttonNaming.Length > buttonIndex) {
							device.Buttons[buttonIndex].name = profile.buttonNaming [buttonIndex];
						}
						buttonIndex++;
							
				}
			}
				
		}







			//joystick.isReady = false;

						device.Extension=new OSXDefaultExtension();








             return device;

		}
Пример #6
0
        public IDevice ResolveDevice(IHIDDevice hidDevice)
        {
            _hidInterface = hidDevice.hidInterface;

            JoystickDevice device;

            //Get jostick capabilities
            Native.JoyCaps       caps;
            Native.JoystickError result = Native.JoystickError.InvalidParameters;



            DeviceProfile profile;



            int i;

            for (i = 0; i < 16; i++)
            {
                result = Native.joyGetDevCaps(i, out caps, Native.JoyCaps.SizeInBytes);


                if (result == Native.JoystickError.NoError && caps.PID == hidDevice.PID && hidDevice.VID == caps.VID)
                {
                    //UnityEngine.Debug.Log("ID:"+i+" on PID:"+info.PID+" VID:"+info.VID+" info:"+info.DevicePath+"Bts"+caps.NumButtons.ToString()+"axes"+caps.NumAxes
                    //  +"ProdID"+caps.PID+" name:"+caps.ProductName+" regkey"+caps.RegKey+"Man:"+caps.VID);



                    int num_axes = caps.NumAxes;

                    //!!! save ordNumber(I don't have still function that would return ordNum for WinMM from PID);
                    ((GenericHIDDevice)hidDevice).ord = i;

                    profile = hidDevice.loadProfile();

                    device           = new JoystickDevice(hidDevice.index, hidDevice.PID, hidDevice.VID, hidDevice.ID, 8, caps.NumButtons, this);
                    device.Extension = new WinDefaultExtension();
                    device.Name      = hidDevice.Name;
                    device.profile   = profile;

                    int buttonIndex = 0;
                    for (; buttonIndex < caps.NumButtons; buttonIndex++)
                    {
                        device.Buttons[buttonIndex] = new ButtonDetails();

                        if (profile != null && profile.buttonNaming.Length > buttonIndex)
                        {
                            device.Buttons[buttonIndex].name = profile.buttonNaming[buttonIndex];
                        }
                    }


                    // Make sure to reverse the vertical axes, so that +1 points up and -1 points down.
                    int         axis = 0;
                    AxisDetails axisDetails;
                    if (axis < num_axes)
                    {
                        axisDetails       = new AxisDetails();
                        axisDetails.max   = caps.XMax;
                        axisDetails.min   = caps.XMin;
                        device.Axis[axis] = axisDetails;
                        //if(axisDetails.min==0 && axisDetails.max==255) axisDetails.isTrigger=true;

                        if (profile != null && profile.axisNaming.Length > axis)
                        {
                            axisDetails.name = profile.axisNaming[axis];
                        }

                        axis++;
                    }
                    if (axis < num_axes)
                    {
                        axisDetails     = new AxisDetails();
                        axisDetails.max = caps.YMax;
                        axisDetails.min = caps.YMin;
                        // if (axisDetails.min == 0 && axisDetails.max == 32767) axisDetails.isTrigger = true;
                        device.Axis[axis] = axisDetails;


                        if (profile != null && profile.axisNaming.Length > axis)
                        {
                            axisDetails.name = profile.axisNaming[axis];
                        }

                        //	stick.Details.Min[axis] = caps.YMin; stick.Details.Max[axis] = caps.YMax;
                        axis++;
                    }
                    if (axis < num_axes)
                    {
                        axisDetails     = new AxisDetails();
                        axisDetails.max = caps.ZMax;
                        axisDetails.min = caps.ZMin;
                        //if(axisDetails.min==0) axisDetails.isTrigger=true;
                        device.Axis[axis] = axisDetails;

                        if (profile != null && profile.axisNaming.Length > axis)
                        {
                            axisDetails.name = profile.axisNaming[axis];
                        }

                        axis++;
                    }

                    if (axis < num_axes)
                    {
                        axisDetails     = new AxisDetails();
                        axisDetails.min = caps.RMin;
                        axisDetails.max = caps.RMax;
                        //    if (axisDetails.min == 0 && axisDetails.max == 255) axisDetails.isTrigger = true;
                        device.Axis[axis] = axisDetails;

                        if (profile != null && profile.axisNaming.Length > axis)
                        {
                            axisDetails.name = profile.axisNaming[axis];
                        }

                        axis++;
                    }

                    if (axis < num_axes)
                    {
                        axisDetails     = new AxisDetails();
                        axisDetails.min = caps.UMin;
                        axisDetails.max = caps.UMax;
                        //     if (axisDetails.min == 0 && axisDetails.max == 255) axisDetails.isTrigger = true;
                        device.Axis[axis] = axisDetails;
                        if (profile != null && profile.axisNaming.Length > axis)
                        {
                            axisDetails.name = profile.axisNaming[axis];
                        }
                        axis++;
                    }

                    if (axis < num_axes)
                    {
                        axisDetails     = new AxisDetails();
                        axisDetails.max = caps.VMax;
                        axisDetails.min = caps.VMin;
                        //     if (axisDetails.min == 0 && axisDetails.max == 255) axisDetails.isTrigger = true;
                        device.Axis[axis] = axisDetails;

                        if (profile != null && profile.axisNaming.Length > axis)
                        {
                            axisDetails.name = profile.axisNaming[axis];
                        }
                        axis++;
                    }

                    if ((caps.Capabilities & Native.JoystCapsFlags.HasPov) != 0)
                    {
                        device.Axis[JoystickAxis.AxisPovX] = new AxisDetails();
                        device.Axis[JoystickAxis.AxisPovY] = new AxisDetails();

                        if (profile != null && profile.axisNaming.Length > (int)JoystickAxis.AxisPovX)
                        {
                            device.Axis[JoystickAxis.AxisPovX].name = profile.axisNaming[(int)JoystickAxis.AxisPovX];
                        }

                        if (profile != null && profile.axisNaming.Length > (int)JoystickAxis.AxisPovY)
                        {
                            device.Axis[JoystickAxis.AxisPovY].name = profile.axisNaming[(int)JoystickAxis.AxisPovY];
                        }


                        device.numPOV = 1;

                        //                        WinDefaultExtension extension = joystick.Extension as WinDefaultExtension;
                        //
                        //                        extension.PovType = Native.PovType.Exists;
                        //                        if ((caps.Capabilities & Native.JoystCapsFlags.HasPov4Dir) != 0)
                        //                            extension.PovType |= Native.PovType.Discrete;
                        //                        if ((caps.Capabilities & Native.JoystCapsFlags.HasPovContinuous) != 0)
                        //                            extension.PovType |= Native.PovType.Continuous;
                    }



                    //  UnityEngine.Debug.Log(" max:" + caps.YMax + " min:" + caps.YMin + " max:" + caps.ZMax + " min:" + caps.ZMin);

                    //    UnityEngine.Debug.Log(" max:" + caps.RMax + " min:" + caps.RMin + " max:" + caps.UMax + " min:" + caps.UMin);

                    return(device);
                }
            }


            return(null);

            //return (IDevice<IAxisDetails, IButtonDetails, IDeviceExtension>)joystick;
        }