如何在Sceneform Android SDK中将相机类型更改为“正交"? [英] How to change camera type to Orthographic in Sceneform Android SDK?
问题描述
在SceneView(不带AR)中展示模型时,我想使用正交摄影机.找不到在API中执行此操作的方法.我是否缺少某些东西或功能缺失?
I'd like to use an Orthographic camera when presenting a model in SceneView (without AR). Couldn't find a way to do so in API. Am I missing something or the feature is missing?
推荐答案
据我所知,相机投影没有 ORTHO
方法(立方体截头圆锥体)现在在ARCore
/Sceneform
中.但是您可以通过4x4矩阵自己制作.因此,您要做的就是使用
As far as I know, there's no ORTHO
method (cube frustum) for camera projection in ARCore
/ Sceneform
at the moment. But you can make it yourself via 4x4 Matrix. So, all you need to do is to calculate left
, right
, top
, bottom
, near
and far
properties using the following principles.
这是您的4x4投影矩阵的外观:
Here is how your projection matrix 4x4 must look like:
希望这会有所帮助.
工作代码,其中scaleFactor
是大约1的值,而height
/width
是SceneView
的属性.
working code where scaleFactor
is a value around 1 and height
/width
are properties of the SceneView
.
private fun buildOrthographicMatrix(right: Float,
top: Float,
far: Float,
near: Float): FloatArray {
val matrix = FloatArray(16)
matrix[0] = 1 / right
matrix[1] = 0f
matrix[2] = 0f
matrix[3] = 0f
matrix[4] = 0f
matrix[5] = 1 / top
matrix[6] = 0f
matrix[7] = 0f
matrix[8] = 0f
matrix[9] = 0f
matrix[10] = -2 / (far - near)
matrix[11] = 0f
matrix[12] = 0f
matrix[13] = 0f
matrix[14] = -(far + near) / (far - near)
matrix[15] = 1f
return matrix
}
val newMatrix = buildOrthographicMatrix(1f / scaleFactor,
1f / scaleFactor * height / width,
30f,
0.01f)
camera.projectionMatrix = Matrix(newMatrix)
这篇关于如何在Sceneform Android SDK中将相机类型更改为“正交"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!