Android ArCore OpenGL 世界到屏幕坐标

时间:2021-06-29 12:37:51

标签: android opengl-es arcore

在增强面部跟踪项目中,我需要获取具有网格顶点、网格法线的面部特定点的屏幕坐标。我知道使用sceneform sdk 的解决方案,但我不想使用它,因为它在Samsung Galaxy S9 上有一个错误(检测到面部向左和向上转移)。我尝试以这种方式获取增强面点的屏幕坐标,但得到错误的结果

        val x1 = face.meshVertices.get(FACE_UPPER_CENTRAL_POINT * 3)
        val y1 = face.meshVertices.get(FACE_UPPER_CENTRAL_POINT * 3 + 1)
        val z1 = face.meshVertices.get(FACE_UPPER_CENTRAL_POINT * 3 + 2)
        val x2 = face.meshVertices.get(FACE_LOWER_CENTRAL_POINT * 3)
        val y2 = face.meshVertices.get(FACE_LOWER_CENTRAL_POINT * 3 + 1)
        val z2 = face.meshVertices.get(FACE_LOWER_CENTRAL_POINT * 3 + 2)

        val point1 = getScreenCoordinates(Vector3(x1, y1, z1), viewMatrix, projectionMatrix)
        val point2 = getScreenCoordinates(Vector3(x2, y2, z2), viewMatrix, projectionMatrix)

有趣的 getScreenCoordinates(coord: Vector3, viewMatrix: FloatArray, projectionMatrix: FloatArray): Vector2 {

val view = IntArray(4)
view[0] = 0
view[1] = 0
view[2] = App.helper.getDisplayWidth()
view[3] = App.helper.getDisplayHeight()
val pos = FloatArray(4)
GLU.gluProject(coord.x, coord.y, coord.z, viewMatrix, 0, projectionMatrix, 0, view, 0 , pos, 0)


return Vector2(pos[0], pos[1])

}

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

在此处查看示例:Sceneform - Maintained - ImageTexture Sample

只需替换这一行:

modelInstance.getMaterial().setTexture("baseColorMap", texture);

有了这个

modelInstance.getMaterial().setFloat4("baseColorMap", new Color(android.graphics.Color.RED));
相关问题