- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一个应用程序,我想在其中访问绝对垂直轴(即从地面到地板)的加速度数据,但是使用 CoreMotion 我只能从设备的相对轴检索加速度.例如,如果设备平放在 table 上,它的垂直轴实际上与绝对垂直轴成 90º。
我一直在研究陀螺仪数据试图解决这个问题,但数据没有意义。
// Make sure the accelerometer hardware is available.
if self.motion.isAccelerometerAvailable && self.motion.isDeviceMotionAvailable {
self.motion.accelerometerUpdateInterval = 1.0 / Double(slider.value) // Hz managed by slider
self.motion.startAccelerometerUpdates()
self.motion.startDeviceMotionUpdates(using: self.motion.attitudeReferenceFrame)
self.motion.deviceMotionUpdateInterval = 1.0 / Double(slider.value)
// Configure a timer to fetch the data.
self.timer = Timer(fire: Date(), interval: (1.0/Double(slider.value)),
repeats: true, block: { (timer) in
// Get the gyroscope data.
if let data = self.motion.deviceMotion {
//Angles: pitch
pitch = data.attitude.pitch
print("Pitch angle: \(self.degrees(radians: pitch))")
//Angles: yaw
yaw = data.attitude.yaw
print("Yaw angle: \(self.degrees(radians: yaw))")
}
//Get the accelerometer data
if let data = self.motion.accelerometerData {
let x = data.acceleration.x
//let y = data.acceleration.y
//let z = data.acceleration.z
// Use the accelerometer data in your app.
self.label.text = "x: \(x)"
let xCorrectedWithPitch = cos(self.degrees(radians: pitch)) * x
print("x: \(x)\nPitch: \(pitch)\nxCorrectedWithPitch: \(xCorrectedWithPitch)")
let xCorrectedWithYaw = cos(self.degrees(radians: yaw)) * xCorrectedWithPitch
print("x: \(x)\nYaw: \(yaw)\nxCorrectedWithYaw: \(xCorrectedWithYaw)")
// Use the accelerometer data in your app.
self.accelArrayY.append(xCorrectedWithYaw*9.81)
time = time + timer.timeInterval
self.timeArrayY.append(time)
}
任何人的帮助将不胜感激
最佳答案
CMMotionMagager 为您提供关于 iPhone 轴的加速度以及重力方向。通过将这两个相乘,您可以计算出来自/到地球的加速度。这是乘法结果的长度。我正在使用 Ray Wenderlich 的 3D Vector utils。
在你的 GameViewController 中:
var motionManager: CMMotionManager!
在 GameViewController.viewDidLoad 中:
motionManager = CMMotionManager()
motionManager.startDeviceMotionUpdates()
在游戏场景中:
override func update(_ currentTime: TimeInterval) {
if let deviceMotion = motionManager.deviceMotion {
let gravityVector = Vector3(x: CGFloat(deviceMotion.gravity.x),
y: CGFloat(deviceMotion.gravity.y),
z: CGFloat(deviceMotion.gravity.z))
let userAccelerationVector = Vector3(x: CGFloat(deviceMotion.userAcceleration.x),
y: CGFloat(deviceMotion.userAcceleration.y),
z: CGFloat(deviceMotion.userAcceleration.z))
// Acceleration to/from earth
let zVector = gravityVector * userAccelerationVector
let zAcceleration = zVector.length()
}
要知道运动的方向:
sign(Double(zVector.x * zVector.y * zVector.z))
不要忘记在不再需要时调用 .stopDeviceMotionUpdates()。
关于swift - 检测绝对垂直轴上的加速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47073389/
我想要做的是在每个框的蓝色标题之后获取红色文本。 看来我必须添加另一个 div?我已经添加并修改了 .card-indus img 的位置,但结果永远不是我想要的。 你知道为什么即使我将 positi
所以我一直在努力掌握绝对和相对定位的诀窍。关于这个主题有很多教程和问题,我已尽力理解它们。除了这一点,我大部分时间都很好。我正在创建一个页面,其中有较小的缩略图图像,用户可以选择单击并展开图像。为此,
下面是我正在处理的代码。如您所见,有一个“#parent”div 和一个“#child”div。 '#child' div 有一个未定义的高度,这是因为有时,'#child' 的高度小于或长于它的父级
我目前正在创建一个看起来有点像这样的固定 header 。 https://gyazo.com/e0bab8ba195e33110b19123c7fc3c568 Logo 始终位于左侧,小按钮始终位于
我怎样才能得到一个绝对定位的子 div,当它放在父 div 的范围之外时不显示? https://jsfiddle.net/knp9ebys/9/ .papa { background:red;
如果我对 CSS 显得相当“菜鸟”,我深表歉意。我一直在尝试设置以下... #0 { width: 100%; height: y; border: 1px solid black; } #
很长一段时间以来,我一直在摆弄一个特定的布局问题,但我显然采用了错误的方式。 以下是分解为基本组成部分的方法: SOME HEADER
我创建了几个虚拟 Controller ,我希望能够从当前的 http 请求中获取 url。 例如: http://www.site.com/app_1/default.aspx ===> http:
我创建了几个虚拟 Controller ,我希望能够从当前的 http 请求中获取 url。 例如: http://www.site.com/app_1/default.aspx ===> http:
我想知道是否有一个库在某处提供受新类型保护的 FilePath 类型。我找到了我想要的http://hackage.haskell.org/package/darcs-2.8.4/docs/src/D
如果我尝试使用以下方式连接到我的嵌入式数据库: private static String url = "jdbc:sqlite:~/hr4413/pkg/sqlite/Models_R_US.db"
所以我是 django 的新手,我一直在研究 PHP CodeIgniter,其中将绝对 URL 放入 href 我通过调用 URL 帮助程序使用了一个名为 base_url 的函数 它给出的输出类
我有一个小问题。 我在其他 div 中有一些图像元素的容器 div。像这样的东西: 我需要将容器垂直居中,但我不能使用顶部:-healfHeight; mar
我有一个带有 inline-block css 位置的列表(div)。里面有一个 relative 定位的 ul 是隐藏的。所以我试图通过添加一些类将这个 div 转换为 absolute 。通常,当
我正在尝试设置一个卡住列,唯一需要解决的问题是同一行上其他 td 的高度不会扩展以匹配绝对定位 td 的高度。由于卡住标题中的文本是任意的,它可以跨越多行。 如果它不是绝对定位的,那么这将迫使同一行中
这个问题在这里已经有了答案: Centering text vertically and horizontally in a div (1 个回答) 关闭 5 年前。
当它的位置绝对时,我试图使一个框宽度为 100%? 下图是我想要做的 https://i.imgur.com/qMaT361.gif float .box1 { position:re
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and t
我有 3 个 div,都是 positioned: absolute,但是我想要填充窗口宽度的 div 只会适应其中文本的长度。我希望黄色 div #help 填充窗口的其余部分。 我知道这听起来很菜
这个问题在这里已经有了答案: Retrieve the position (X,Y) of an HTML element (32 个答案) 关闭 8 年前。 有时候,当我请求某个对象的.posit
我是一名优秀的程序员,十分优秀!