選択した処理ヒット

5424 ワード

Picking Tutorial Pickingチュートリアル
Processing the Hit Records処理ヒットレコード
In order to process the hit records the application must first return to the normal rendering mode. This is done calling glRenderMode with GL_RENDER. This function returns the number of hit records that were created during rendering in the selection mode. After this step the application can process the selection buffer. Note that before calling glRender with GL_RENDER there is no guarantee that the hit records have been saved into the selection buffer.
ヒットレコードを処理するには、アプリケーションが最初にペイントモードに戻る必要があります.glRenderModeを呼び出すと、パラメータはGL_になります.RENDERで、描画モードに戻ります.この関数は、選択モードペイント時にヒットレコードが生成した数を返します.このステップの後、アプリケーションは選択バッファを処理できます.なお、パラメータGL_の使用についてはRENDERがglRenderModeを呼び出す前に、ヒットレコードが選択バッファ内にあることは保証されません.
Furthermore, it is necessary to restore the original projection matrix. Since this matrix was saved when entering the selection mode with glPushMatrix, all that is required is to pop the matrix. The following excerpt of code shows the required steps: 
また、元の投影マトリクスも復元する必要があります.選択モードに入るとglPushMatrixを使うので、元の行列が保存されているので、この行列をポップアップするだけです.次のコードは、必要な手順を示しています.
    
void stopPicking() {

	int hits;
	
	// restoring the original projection matrix
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glFlush();
	
	// returning to normal rendering mode
	hits = glRenderMode(GL_RENDER);
	
	// if there are hits process them
	if (hits != 0)
		processHits(hits,selectBuf);
}

So the final issue is related to the selection buffer structure. The selection buffer stores the hit records sequentially by the order they occurred, i.e. by the order that the primitives we're drawn. Note that primitives that wouldn't be drawn due to Z buffer depth culling still produce hit records.
最後の問題は、バッファを選択する構造についてです.バッファを選択して、ヒットレコードが生成された順序で保存します.たとえば、エンティティの順序を描画します.なお、Z深度クリップにより描画されないエンティティでもヒットレコードが生成される.
The hit records are potentially variable size records due to the number of names they contain.
ヒットレコードは、名前の数が含まれているため、可変サイズのレコードである可能性があります.
  • The first field of the hit record is the number of names it contains.
  • ヒット記録の第1部は、名前の数です.
  • The second and third fields represent the minimum and maximum depth of the hit. Note that only the vertices of the primitives that intersect the viewing volume are taken into account. For polygons that get clipped OpenGL reconstructs the vertices. So basically you get the maximum and minimum depths of the rendered segment of the primitives that intersects the viewing volume, not the minimum and maximum depths of the entire primitive. The depth is taken from the Z buffer (where it lies in the range [0,1]), it gets multiplied by 2^32 -1 and it is rounded to the nearest integer. Note that the depths you get are not linearly proportional to the distance to the viewpoint due to the nonlinear nature of the z buffer.
  • 第2、第3の部分は、最大、最小ヒット深さを表す.エンティティの頂点がテーパと交差している場合にのみ記録されます.クリップされたポリゴンの場合、OpenGLは頂点を再構築します.したがって、基本的には、エンティティ全体の最大、最小の深さ値ではなく、テーパと交差するペイントセグメントの最大、最小の深さが得られます.深さ値はZバッファから取り出し(その中で、その範囲は0-1)、2^32-1を乗じて、最も近い整数を取ります.Zバッファも線形ではないので、得られた深さ値は線形ではありません.viewportの距離に比例します.
  • The sequence of names recorded for the hit. These names are the contents of the name stack when the hit was recorded. Note that since the number of names can be zero this sequence can be the empty sequence.
  • ヒットした名前のシーケンスも記録されています.それらの名前はヒットが記録されたときの名前スタックの内容です.名前の数は0である可能性があるため、名前のシーケンスは空のシーケンスである可能性があります.

  • An example of a selection buffer with 3 hit records is presented next:
    3つのヒットレコードの選択バッファの例:
    Hit Record Contents
    Description
    0
    No names have been stored for the first hit
    4.2822e+009
    Minimum depth for first hit
    4.28436e+009
    Maximum depth for first hit
    1
    Number of names for the second hit
    4.2732e+009
    Minimum depth for second hit
    4.27334e+009
    Maximum depth for second hit
    6
    A single name for the second hit
    2
    Number of names for the third hit
    4.27138e+009
    Minimum depth for third hit
    4.27155e+009
    Maximum depth for third hit
    2
    First name for third hit
    5
    Second name for third hit
    In order to detect which object was closest to the viewpoint you use the depth information. For instance you can select the object with the smalest minimum depth has the one which the user intended to click on. In the above example the relevant hit is the third one. The following function, adapted from the one in the Red Book, prints out the names for the closest object. 
    ビューポートに最も近いオブジェクトのために、深度情報を使用します.たとえば、ユーザーがクリックしようとするオブジェクトである最小深さ値を選択できます.上記の例では、関連するヒットは3番目です.次の関数は赤宝書から来て、最近のオブジェクトの名前を印刷します.
        
    void processHits2 (GLint hits, GLuint buffer[])
    {
       unsigned int i, j;
       GLuint names, *ptr, minZ,*ptrNames, numberOfNames;
    
       printf ("hits = %d
    ", hits); ptr = (GLuint *) buffer; minZ = 0xffffffff; for (i = 0; i < hits; i++) { names = *ptr; ptr++; if (*ptr < minZ) { numberOfNames = names; minZ = *ptr; ptrNames = ptr+2; } ptr += names+2; } printf ("The closest hit names are "); ptr = ptrNames; for (j = 0; j < numberOfNames; j++,ptr++) { printf ("%d ", *ptr); } printf ("
    "); }