Original Post
Hi all, I am struggling to develop an application in openGL that allows me to pick a particular point at a time , change its color and drag it to a new position with respect to other points. With my understanding and hard efforts I have been able to draw all points but not getting the desired results. Following is the relevant portion of my code concerning the above described function:
//This function is responsible for dragging.
void Drag(int iPos_X , int iPos_Y)
{
int i = iEle;
int iIndex;
//Var declarations for picking and selection.
GLuint selectBuf[BUF_SIZE];
GLint ViewPort[FOUR] ;
GLint iHits = 0;
memset(selectBuf,0,BUF_SIZE); //clear
if(bMiddleButton) //If middle mouse button is pressed.
{
MarkPointOnScreen(iPos_X,iPos_Y, WINHEIGHT , WINWIDTH, NULL, pfTemp);
// Commented for temporarily.Using selection and picking for selection..This works only for the last point.
//pfArray[i - THREE] = pfTemp[0];
//pfArray[i - TWO] = pfTemp[1];
//pfArray[i - ONE] = pfTemp[2];
//Modification required.Indexing of points neccessary.
glGetIntegerv(GL_VIEWPORT,ViewPort);
glSelectBuffer(BUF_SIZE,selectBuf);
//Entering SELECT mode.
(void)glRenderMode(GL_SELECT);
//Initialising name stack.
glInitNames();
glPushName(0);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
//createpickmatrix.that is draw a viewing mode of size 1 * 1 pixel.
gluPickMatrix((GLdouble)iPos_X , (GLdouble)(ViewPort[3] - iPos_Y) , 1.0 , 1.0 , ViewPort);
glOrtho(LEFT , RIGHT , BOTTOM, TOP ,MIN_LIMIT, MAX_LIMIT);
//Pick a point and turn its color as blue.
drawPoint(GL_SELECT);//When mode is GL_SELECT then works as a Point picker.Aim is to return the index of the point picked.
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glFlush();
//Exiting from SELECT mode and entering NORMAL mode.
iHits = glRenderMode(GL_RENDER);
processHits(iHits, selectBuf);
}
glutPostRedisplay();
}//End of function
And the code underneath is for drawPoint() that actually draws points and displays them.Moreover, when draggin is performed, th aim of the function is to continuously display the changing positions of the point being dragged.
void drawPoint(GLenum mode)
{
int i =0, j = 0, k = 0 ;
static iVar = 0;
int iIndex = 0;
//if( mode != GL_SELECT)
SHIFT_COORD_SIGN = SIGN(5.0 , 0.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LINE_STIPPLE);
// Set the material color to follow the current color
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); // ...Deleting it gives weired effects.
glPushMatrix();
glRotatef(fAngle_Y , 0.0 , 1.0 , 0.0); //Move left
glRotatef(fAngle_X , 1.0 , 0.0 , 0.0); //Move above
glRotatef(fAngle_Z , 0.0 , 0.0 , 1.0); //Move above
glPointSize(POINT_SIZE);
while( j < iNumOfClicks)
{
//SHIIFT_COOR_SIGN is used on assumption that camera moves along Z axis.
//glVertex3f(SHIFT_COORD_SIGN * pfArray, pfArray[i + 1], pfArray[i + 2] );
if(bMiddleButton) // && mode == GL_SELECT)
{
glColor3f(0.0 ,1.0 ,0.0);
//Section added w.ref to GameDev forum post.
if (mode == GL_SELECT)
glLoadName(j); //j is the point index here.
glBegin(GL_POINTS);
glVertex3f(SHIFT_COORD_SIGN * pfArray, pfArray[i + 1], pfArray[i + 2] );
glEnd();
// if(mode == GL_SELECT)
// glPopName();
}
else
{
glColor3f(1.0, 0.0, 1.0);
glBegin(GL_POINTS);
glVertex3f(SHIFT_COORD_SIGN * pfArray * fZoom_X, pfArray[i + 1] * fZoom_Y, pfArray[i + 2] *fZoom_Z);
glEnd();
}
bDefault = TRUE; //Reset Flag.
i += 3;
++j;
}//End of While Loop
glPopMatrix();
i = 0; //Reset counter.
j = 0; //Reset counter.
glutSwapBuffers();
}//End of function drawPoint.
Problem is: When I press middle button of mouse, the color of each vertex turns green from original color purple.But when I drag a point, , I observe that number of Hits remains 0. With more efforts , I was able to drag the last drawn point only by supplying to current mouse cursor position to glVertex3f function. I need a sceneario where , if I draw 4 points and I pick the 2nd point or 3rd and drag it, the point must move with respect to other points. ( i.e position of other points must not change and after dragging operation, all points should be displayed. Help is appreciated.