Most visited

Recently visited

Added in API level 3

Visibility

public class Visibility
extends Object

java.lang.Object
   ↳ android.opengl.Visibility


计算三角形网格可见性的实用方法集合。

Summary

Public constructors

Visibility()

Public methods

static void computeBoundingSphere(float[] positions, int positionsOffset, int positionsCount, float[] sphere, int sphereOffset)

计算一组点的边界球。

static int frustumCullSpheres(float[] mvp, int mvpOffset, float[] spheres, int spheresOffset, int spheresCount, int[] results, int resultsOffset, int resultsCapacity)

给定一个OpenGL ES ModelView-Projection矩阵(它隐含地描述一个平截头体)和一个球体列表,确定哪个球体与平截头体相交。

static int visibilityTest(float[] ws, int wsOffset, float[] positions, int positionsOffset, char[] indices, int indicesOffset, int indexCount)

测试给定的三角形网格是否在屏幕上可见。

Inherited methods

From class java.lang.Object

Public constructors

Visibility

Added in API level 3
Visibility ()

Public methods

computeBoundingSphere

Added in API level 3
void computeBoundingSphere (float[] positions, 
                int positionsOffset, 
                int positionsCount, 
                float[] sphere, 
                int sphereOffset)

计算一组点的边界球。 它大约是限定点的轴对齐框的最小边界球。

Parameters
positions float: positions in x, y, z triples
positionsOffset int: offset into positions array
positionsCount int: number of position triples to process
sphere float: array containing the output as (x, y, z, r)
sphereOffset int: offset where the sphere data will be written
Throws
IllegalArgumentException if positions is null, positionsOffset < 0, positionsOffset > positions.length - positionsCount, sphere is null, sphereOffset < 0, sphereOffset > sphere.length - 4.

frustumCullSpheres

Added in API level 3
int frustumCullSpheres (float[] mvp, 
                int mvpOffset, 
                float[] spheres, 
                int spheresOffset, 
                int spheresCount, 
                int[] results, 
                int resultsOffset, 
                int resultsCapacity)

给定一个OpenGL ES ModelView-Projection矩阵(它隐含地描述一个平截头体)和一个球体列表,确定哪个球体与平截头体相交。

模型视图投影矩阵可以通过将投影矩阵乘以模型视图矩阵(按照该顺序)来计算。 有几种可能的方式来获得当前的ModelView和Projection矩阵。 最普遍适用的方法是跟踪应用程序代码中的当前矩阵。 如果这样做不方便,有两个可选的OpenGL ES扩展可用于从OpenGL ES中读取当前矩阵:

  • GL10Ext.glQueryMatrixxOES
  • GL11.GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES and GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS_OES
The problem with reading back the matrices is that your application will only work with devices that support the extension(s) that it uses.

平截头体是一个六边形的截断金字塔,它定义了视图中可见的世界空间部分。

球体在世界空间坐标中被描述为四个浮点值:x,y,z和r。 R是球体的半径。

Parameters
mvp float: a float array containing the mode-view-projection matrix
mvpOffset int: The offset of the mvp data within the mvp array.
spheres float: a float array containing the sphere data.
spheresOffset int: an offset into the sphere array where the sphere data starts
spheresCount int: the number of spheres to cull.
results int: an integer array containing the indices of the spheres that are either contained entirely within or intersect the frustum.
resultsOffset int: an offset into the results array where the results start.
resultsCapacity int: the number of array elements available for storing results.
Returns
int the number of spheres that intersected the frustum. Can be larger than resultsCapacity, in which case only the first resultsCapacity results are written into the results array.
Throws
IllegalArgumentException if mvp is null, mvpOffset < 0, mvpOffset > mvp.length - 16, spheres is null, spheresOffset < 0, spheresOffset > spheres.length - sphereCount, results is null, resultsOffset < 0, resultsOffset > results.length - resultsCapacity.

visibilityTest

Added in API level 3
int visibilityTest (float[] ws, 
                int wsOffset, 
                float[] positions, 
                int positionsOffset, 
                char[] indices, 
                int indicesOffset, 
                int indexCount)

测试给定的三角形网格是否在屏幕上可见。 网格被指定为索引三角形列表。

Parameters
ws float: the world space to screen space transform matrix, as an OpenGL column matrix.
wsOffset int: an index into the ws array where the data starts.
positions float: the vertex positions (x, y, z).
positionsOffset int: the index in the positions array where the data starts.
indices char: the indices of the triangle list. The indices are expressed as chars because they are unsigned 16-bit values.
indicesOffset int: the index in the indices array where the index data starts.
indexCount int: the number of indices in use. Typically a multiple of three. If not a multiple of three, the remaining one or two indices will be ignored.
Returns
int 2 if all of the mesh is visible, 1 if some part of the mesh is visible, 0 if no part is visible.
Throws
IllegalArgumentException if ws is null, wsOffset < 0, positions is null, positionsOffset < 0, indices is null, indicesOffset < 0, indicesOffset > indices.length - indexCount

Hooray!