Hi!
Ich habe ein Problem mit Picking! Ich möchte aus CAD-Dateien einzelne Punkte per Mouseclick picken! Die Darstellung der CAD-Dateien funktioniert auch problemlos. Jedoch bekomme ich kein Ergebnis beim Picking. Der liefert nichts zurück! Hier die Picking-Funktion:
|
Quellcode
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
if(Button != 0&& Button != 2)
{
//x=0;wy=0;wz=0;
GLuint selectionBuffer[BUFSIZE];
GLint numOfHits;
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
glSelectBuffer(BUFSIZE, selectionBuffer);
(void) glRenderMode(GL_SELECT);
glInitNames();
glPushName(0);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix((GLdouble) X, (GLdouble) (viewport[3] - Y),
5.0f, 5.0f, viewport);
DrawScene(true); //Objekt zeichnen
glMatrixMode (GL_PROJECTION);
glPopMatrix();
glFlush();
numOfHits = glRenderMode(GL_RENDER);
if(numOfHits>0) GetPoint(numOfHits, (int) selectionBuffer);
collisionbool = true;
MyResize();
Manipulate();
}
|
Diese Funktion wird dann aufgerufen, wenn der User die rechte Mousetaste drückt! Die Funktion, in der die Namen mit glLoadName vergeben werden ist DrawScene(bool). Hier diese Funktion:
|
Quellcode
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
void TFrMain::DrawScene(bool select)
{
/*Hier Punkt übergabe*/
glPointSize(pointsize); //Punktdicke
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
pointcount = 0;
for(int r=0; r<zaehler; r++)
{
if(select == true) glLoadName(r);
if(select == true) glPushName(r);
glBegin(GL_POINTS);
if(rotfac!=1) if(MBL||MBM||MBR) r = r + rotfac;
if(CBZCol->Checked) glColor3f((da.sz[r]+colordat1)*colordat2,(da.sz[r]+colordat1)*colordat2,(da.sz[r]+colordat1)*colordat2);
if(BreFileLoaded||diFileLoaded) {colo = da.co[r]*colcon; glColor3f(colo,colo,colo);}
else glColor3f(1.0f,1.0f,1.0f);
if(da.sx[r] == 0 || -0) x = 0.0000000000001; else x = da.sx[r];
if(da.sy[r] == 0 || -0) y = 0.0000000000001; else y = da.sy[r];
if(da.sz[r] == 0 || -0) z = 0.0000000000001; else z = da.sz[r];
if(collisionbool) collision(x,y,z);
x = GetCoord(minx, x, halfdimx);
y = GetCoord(miny, y, halfdimy);
z = GetCoord(minz, z, halfdimz);
glVertex3d(x, y, z);
glEnd();
if(select == true) glPopName();
}
//GetPoint(pointcount);
glPopMatrix();
glFlush();
SwapBuffers(hDC);
}
|
Dann sind vielleicht noch zwei Funktionen wichtig, mit denen ich den Viewport und den MatrixMode einstelle! Hier die beiden:
|
Quellcode
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
//-------------------------------------------------------------------
/* MatrixMode, Viewport einlesen, Objectfunktion aufrufen*/
//-------------------------------------------------------------------
void TFrMain::MyResize()
{
if(!firstload)
{
if (dimx>dimy) dimmax = dimx; else dimmax = dimy;
float sx = FrMain->ClientWidth / dimmax;
float sy = FrMain->ClientHeight / dimmax;
if (sx>sy) sf = sy; else sf = sx;
if (sx>sy) sf = sy; else sf = sx;
sf = sf*1.8;
int w = FrMain->ClientWidth;
int h = FrMain->ClientHeight;
glViewport( 0, 0, w, h );
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(!ortho) {glDepthRange(0,10000); gluPerspective( pangle , (double)w / max( (double)h, 1.0 ), 1.0, 1000.0 );}
if(ortho) glOrtho((-dimmax/sf)*sx,(dimmax/sf)*sx, (-dimmax/sf)*sy, (dimmax/sf)*sy, -10000, 10000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
}
}
//-------------------------------------------------------------------
/*Objekt manipuilieren*/
//-------------------------------------------------------------------
void TFrMain::Manipulate()
{
if(!firstload)
{
pfa = sf;
float m[4][4];
glLoadIdentity();
glPushMatrix();
glTranslatef(xslide/pfa, yslide/pfa, -(2*dimz));
glScalef(yzoom/sdiv, yzoom/sdiv, yzoom/sdiv);
build_rotmatrix(m,quat); //Rotationsmatrix berechnen
glMultMatrixf(&m[0][0]); //Matrizen Multiplizieren
if(CBZCol->Checked)
{
colconst = 255/dimz;
colordat1 = minz*(-colfac);
colordat2 = colconst * colcon;
}
glDrawBuffer(GL_BACK);
DrawScene(GL_RENDER);
}
}
|
Leider bekomme ich einfach kein Ergebnis! Er liefert beim Klicken nichts zurück! Vielleicht sieht ja jemand sofort den Fehler! Ich bin schon seit über einer Woche dabei und eigentlich gehe ich genau nach dem Red Book vor! Sehe wirklich keine Fehler!
Danke sehr
Gruß
Blubbermann