- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为 Windows Phone 7.1 (Mango) 编写一个小型示例应用程序,并希望使用 Combined Motion API 来显示设备的运动。我需要编写模拟类才能在使用不支持设备所有传感器的模拟器时测试我的应用程序。
我已经编写了一个简单的模拟类来模拟指南针(它只是模拟旋转设备)和模拟器中实际可用的加速度计。
现在我必须为 Motion API 编写一个新的模拟对象,但我希望我可以使用罗盘和加速度计的值来计算用于 Motion 对象的值。不幸的是,我没有找到已经执行此操作的简单转换示例。
有人知道执行此转换的代码示例吗?如果已经有解决方案,那么我不想自己做这件事。
最佳答案
现在我又遇到了同样的问题,因为 Windows Phone 8 已经发布,而且我还没有手机可以测试。
很像 WP7 Mock Microsoft.Devices.Sensors.Compass when using the emulator 的答案, 我创建了 a wrapper class with the same methods as the Motion API .当支持实际的 Motion API 时,将使用它。否则,在 Debug模式下,将返回模拟数据以改变滚动、俯仰和偏航。
运动包裹
/// <summary>
/// Provides Windows Phone applications information about the device’s orientation and motion.
/// </summary>
public class MotionWrapper //: SensorBase<MotionReading> // No public constructors, nice one.
{
private Motion motion;
public event EventHandler<SensorReadingEventArgs<MockMotionReading>> CurrentValueChanged;
#region Properties
/// <summary>
/// Gets or sets the preferred time between Microsoft.Devices.Sensors.SensorBase<TSensorReading>.CurrentValueChanged events.
/// </summary>
public virtual TimeSpan TimeBetweenUpdates
{
get
{
return motion.TimeBetweenUpdates;
}
set
{
motion.TimeBetweenUpdates = value;
}
}
/// <summary>
/// Gets or sets whether the device on which the application is running supports the sensors required by the Microsoft.Devices.Sensors.Motion class.
/// </summary>
public static bool IsSupported
{
get
{
#if(DEBUG)
return true;
#else
return Motion.IsSupported;
#endif
}
}
#endregion
#region Constructors
protected MotionWrapper()
{
}
protected MotionWrapper(Motion motion)
{
this.motion = motion;
this.motion.CurrentValueChanged += motion_CurrentValueChanged;
}
#endregion
/// <summary>
/// Get an instance of the MotionWrappper that supports the Motion API
/// </summary>
/// <returns></returns>
public static MotionWrapper Instance()
{
#if(DEBUG)
if (!Motion.IsSupported)
{
return new MockMotionWrapper();
}
#endif
return new MotionWrapper(new Motion());
}
/// <summary>
/// The value from the underlying Motion API has changed. Relay it on within a MockMotionReading.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void motion_CurrentValueChanged(object sender, SensorReadingEventArgs<MotionReading> e)
{
var f = new SensorReadingEventArgs<MockMotionReading>();
f.SensorReading = new MockMotionReading(e.SensorReading);
RaiseValueChangedEvent(sender, f);
}
protected void RaiseValueChangedEvent(object sender, SensorReadingEventArgs<MockMotionReading> e)
{
if (CurrentValueChanged != null)
{
CurrentValueChanged(this, e);
}
}
/// <summary>
/// Starts acquisition of data from the sensor.
/// </summary>
public virtual void Start()
{
motion.Start();
}
/// <summary>
/// Stops acquisition of data from the sensor.
/// </summary>
public virtual void Stop()
{
motion.Stop();
}
}
MockMotionWrapper
/// <summary>
/// Provides Windows Phone applications mock information about the device’s orientation and motion.
/// </summary>
public class MockMotionWrapper : MotionWrapper
{
/// <summary>
/// Use a timer to trigger simulated data updates.
/// </summary>
private DispatcherTimer timer;
private MockMotionReading lastCompassReading = new MockMotionReading(true);
#region Properties
/// <summary>
/// Gets or sets the preferred time between Microsoft.Devices.Sensors.SensorBase<TSensorReading>.CurrentValueChanged events.
/// </summary>
public override TimeSpan TimeBetweenUpdates
{
get
{
return timer.Interval;
}
set
{
timer.Interval = value;
}
}
#endregion
#region Constructors
public MockMotionWrapper()
{
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(30);
timer.Tick += new EventHandler(timer_Tick);
}
#endregion
void timer_Tick(object sender, EventArgs e)
{
var reading = new Microsoft.Devices.Sensors.SensorReadingEventArgs<MockMotionReading>();
lastCompassReading = new MockMotionReading(lastCompassReading);
reading.SensorReading = lastCompassReading;
//if (lastCompassReading.HeadingAccuracy > 20)
//{
// RaiseValueChangedEvent(this, new CalibrationEventArgs());
//}
RaiseValueChangedEvent(this, reading);
}
/// <summary>
/// Starts acquisition of data from the sensor.
/// </summary>
public override void Start()
{
timer.Start();
}
/// <summary>
/// Stops acquisition of data from the sensor.
/// </summary>
public override void Stop()
{
timer.Stop();
}
}
模拟阅读
//Microsoft.Devices.Sensors.MotionReading
/// <summary>
/// Contains information about the orientation and movement of the device.
/// </summary>
public struct MockMotionReading : Microsoft.Devices.Sensors.ISensorReading
{
public static bool RequiresCalibration = false;
#region Properties
/// <summary>
/// Gets the attitude (yaw, pitch, and roll) of the device, in radians.
/// </summary>
public MockAttitudeReading Attitude { get; internal set; }
/// <summary>
/// Gets the linear acceleration of the device, in gravitational units.
/// </summary>
public Vector3 DeviceAcceleration { get; internal set; }
/// <summary>
/// Gets the rotational velocity of the device, in radians per second.
/// </summary>
public Vector3 DeviceRotationRate { get; internal set; }
/// <summary>
/// Gets the gravity vector associated with the Microsoft.Devices.Sensors.MotionReading.
/// </summary>
public Vector3 Gravity { get; internal set; }
/// <summary>
/// Gets a timestamp indicating the time at which the accelerometer reading was
/// taken. This can be used to correlate readings across sensors and provide
/// additional input to algorithms that process raw sensor data.
/// </summary>
public DateTimeOffset Timestamp { get; internal set; }
#endregion
#region Constructors
/// <summary>
/// Initialize an instance from an actual MotionReading
/// </summary>
/// <param name="cr"></param>
public MockMotionReading(MotionReading cr)
: this()
{
this.Attitude = new MockAttitudeReading(cr.Attitude);
this.DeviceAcceleration = cr.DeviceAcceleration;
this.DeviceRotationRate = cr.DeviceRotationRate;
this.Gravity = cr.Gravity;
this.Timestamp = cr.Timestamp;
}
/// <summary>
/// Create an instance initialized with testing data
/// </summary>
/// <param name="test"></param>
public MockMotionReading(bool test)
: this()
{
float pitch = 0.01f;
float roll = 0.02f;
float yaw = 0.03f;
this.Attitude = new MockAttitudeReading()
{
Pitch = pitch,
Roll = roll,
Yaw = yaw,
RotationMatrix = Matrix.CreateFromYawPitchRoll(yaw, pitch, roll),
Quaternion = Quaternion.CreateFromYawPitchRoll(yaw, pitch, roll),
Timestamp = DateTimeOffset.Now
};
// TODO: pull data from the Accelerometer
this.Gravity = new Vector3(0, 0, 1f);
}
/// <summary>
/// Create a new mock instance based on the previous mock instance
/// </summary>
/// <param name="lastCompassReading"></param>
public MockMotionReading(MockMotionReading lastCompassReading)
: this()
{
// Adjust the pitch, roll, and yaw as required.
// -90 to 90 deg
float pitchDegrees = MathHelper.ToDegrees(lastCompassReading.Attitude.Pitch) - 0.5f;
//pitchDegrees = ((pitchDegrees + 90) % 180) - 90;
// -90 to 90 deg
float rollDegrees = MathHelper.ToDegrees(lastCompassReading.Attitude.Roll);
//rollDegrees = ((rollDegrees + 90) % 180) - 90;
// 0 to 360 deg
float yawDegrees = MathHelper.ToDegrees(lastCompassReading.Attitude.Yaw) + 0.5f;
//yawDegrees = yawDegrees % 360;
float pitch = MathHelper.ToRadians(pitchDegrees);
float roll = MathHelper.ToRadians(rollDegrees);
float yaw = MathHelper.ToRadians(yawDegrees);
this.Attitude = new MockAttitudeReading()
{
Pitch = pitch,
Roll = roll,
Yaw = yaw,
RotationMatrix = Matrix.CreateFromYawPitchRoll(yaw, pitch, roll),
Quaternion = Quaternion.CreateFromYawPitchRoll(yaw, pitch, roll),
Timestamp = DateTimeOffset.Now
};
this.DeviceAcceleration = lastCompassReading.DeviceAcceleration;
this.DeviceRotationRate = lastCompassReading.DeviceRotationRate;
this.Gravity = lastCompassReading.Gravity;
Timestamp = DateTime.Now;
}
#endregion
}
模拟态度阅读
public struct MockAttitudeReading : ISensorReading
{
public MockAttitudeReading(AttitudeReading attitudeReading) : this()
{
Pitch = attitudeReading.Pitch;
Quaternion = attitudeReading.Quaternion;
Roll = attitudeReading.Roll;
RotationMatrix = attitudeReading.RotationMatrix;
Timestamp = attitudeReading.Timestamp;
Yaw = attitudeReading.Yaw;
}
/// <summary>
/// Gets the pitch of the attitude reading in radians.
/// </summary>
public float Pitch { get; set; }
/// <summary>
/// Gets the quaternion representation of the attitude reading.
/// </summary>
public Quaternion Quaternion { get; set; }
/// <summary>
/// Gets the roll of the attitude reading in radians.
/// </summary>
public float Roll { get; set; }
/// <summary>
/// Gets the matrix representation of the attitude reading.
/// </summary>
public Matrix RotationMatrix { get; set; }
/// <summary>
/// Gets a timestamp indicating the time at which the accelerometer reading was
/// taken. This can be used to correlate readings across sensors and provide
/// additional input to algorithms that process raw sensor data.
/// </summary>
public DateTimeOffset Timestamp { get; set; }
/// <summary>
/// Gets the yaw of the attitude reading in radians.
/// </summary>
public float Yaw { get; set; }
}
关于windows-phone-7 - WP7 : Convert Accelometer and Compass data to mock Motion API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7629453/
我正在使用SpringBoot和JPA来调用db,我遇到异常 org.springframework.core.convert.ConverterNotFoundException: No conve
我尝试实现 Spring Converter,但在单元测试中出现错误: Kotlin: Null can not be a value of a non-null type TodoItem 如果我尝
我在 Spring Boot 2.0 示例中使用 Spring Data Redis。在此示例中,我尝试将客户数据 + 学生数据保存在一起。我不太确定这里的数据建模是如何发生的,但假设它与 Mongo
我在 Spring 的 XML 配置文件之一中有以下代码:
我们正在尝试使用 hibernate Converter 来加密/解密通过 hibernate 存储的几列数据 @Convert(attributeName="myattr",converter=Da
我有this我必须实现的功能: protected override ValidationResult IsValid( Object value, ValidationContext
我看到了 std::convert::Into有任何实现 std::convert::From 的实现: impl Into for T where U: From, 在Rust 1.0标准库
Convert.ChangeType 或 Convert.ToInt32 或 int.Parse 之间是否存在性能优势 最佳答案 如果您知道要将 string 转换为 Int32,使用 Convert
我会定期浏览我的家庭作业以供上课。我的扫描仪将原始 jpg 文件导出到 USB,然后我可以从那里使用 gimp 编辑文件并将其另存为 pdf。我发现一种节省时间的方法是将我的多页作业导出为 .mng
Grails版本:2.3.8我在BootStrap.groovy中注册了一个自定义日期编码器,但是当我使用日期填充为Json的Object时,它将引发异常:Exception message is C
我会定期浏览我的家庭作业以供上课。我的扫描仪将原始 jpg 文件导出到 USB,然后我可以从那里使用 gimp 编辑文件并将其另存为 pdf。我发现一种节省时间的方法是将我的多页作业导出为 .mng
我正在尝试制作一个 SKAction,以便我的玩家慢慢地被拉向一个要杀死他的敌人。实际上,问题在于玩家和敌人处于不同的节点,遵循以下层次结构: 场景(SKScene)-PARENT->播放器(SKNo
我通过 xml 设置了 spring data mongo 自定义转换器,如下所示 在自定义读/写转换器中,我想
我正在尝试使用名为 Simple Captcha 的 gem 这需要在机器上安装 ImageMagick。我已经安装了它并且 convert --version 显示了这个 Version: Imag
我正在尝试使用名为 Simple Captcha 的 gem 这需要在机器上安装 ImageMagick。我已经安装了它并且 convert --version 显示了这个 Version: Imag
我正在使用 Spring JPA,我需要有一个 native 查询来调用存储过程。从结果中,我只需要获取两个字段,即代码和消息。我创建了一个包含两个字段代码和消息的类。它不起作用,这是我收到的错误:
我首先有多部分文件,我想将其发送到camel管道并使用原始名称保存该文件。 我的代码: @Autowired ProducerTemplate producerTemplate; ...
我的maven项目使用了spring、hibernate。我得到“没有这样的方法错误”。我相信这是由于依赖项中的版本冲突造成的,但不知道是什么。构建成功。但是在“NetBeans:在 GlassFis
TL;DR:Vaadin 8 中是否有类似于 Vaadin 7 的转换器来更新 UI 中输入字段的表示? IE。在输入字段失去焦点后立即从用户输入中删除所有非数字,或将小数转换为货币? Vaadin
我昨天问了一个问题here关于从匿名对象读取属性并将它们写入类的私有(private)字段。问题解决了。这是一个小故事: 我有一些 json 格式的数据。我将它们反序列化为 ExpandoObject
我是一名优秀的程序员,十分优秀!