如何在 Sceneform Android SDK 中将相机类型更改为正交? [英] How to change camera type to Orthographic in Sceneform Android SDK?
问题描述
在 SceneView(无 AR)中展示模型时,我想使用正交相机.在 API 中找不到这样做的方法.我是否遗漏了什么或缺少该功能?
据我所知,没有 ORTHO
方法(cube frustum>) 用于当前 ARCore
/Sceneform
中的相机投影.但是您可以通过 4x4 Matrix 自己制作.所以,你需要做的就是计算left
、right
、top
、bottom
、near
和 far
属性使用
您的投影矩阵 4x4 必须如下所示:
工作代码,其中 scaleFactor
是一个大约 1.3 的值,height
/width
是 SceneView
.
private fun buildOrthographicMatrix(right: Float,顶部:浮动,远:漂浮,附近:浮动):FloatArray {val 矩阵 = FloatArray(16)矩阵[0] = 1/右矩阵[1] = 0f矩阵[2] = 0f矩阵[3] = 0f矩阵[4] = 0f矩阵[5] = 1/顶部矩阵[6] = 0f矩阵[7] = 0f矩阵[8] = 0f矩阵[9] = 0f矩阵[10] = -2/(远-近)矩阵[11] = 0f矩阵[12] = 0f矩阵[13] = 0f矩阵[14] = -(远+近)/(远-近)矩阵[15] = 1f返回矩阵}val newMatrix = buildOrthographicMatrix(1f/scaleFactor,1f/scaleFactor * 高度/宽度,30楼,0.01f)camera.projectionMatrix = Matrix(newMatrix)
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?
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.
Here is how your projection matrix 4x4 must look like:
Edit: working code where scaleFactor
is a value around 1.3 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屋!