any other suggestions for real-time? thanks a lot.
Main Topics
Browse All Topicshi,
I have a line connect those points like ABCDEF after rendering. When user click on B and drag it to a new coordinate and release mouse. Then user release mouse. I want line ABCDEF will update the new shape. I want to see real-time changing when user drag point B. Please adivse. Thanks a lot.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>> It doesn't look like OpenGL gives you a GLUT_MOVE event
OpenGL does not give any mouse or GUI-events, but glut does. The asker already uses glut in his/her code. There is a mouse-motion function callback too in glut, that gives you the mouse-motion events.
>> any other suggestion
But more important in your case than a mouse-move-event is button-down and button-up. You have to check in the button-down function, if the mouse is over one of your points. You should add a little radius for that check-range, so it will not be that hard for your user to click the line-end-point.
I would not use the same mouse-button for that action, that you use for adding a point, you can use the middle-button or the right mouse button.
When the user releases this button replace the point with the new point.
When that works you can add some convinience-stuff, i.e. when the mouse is over one of your points, you could render a circle around that point, meaning that the user can select that point now. But first make the basic selection work.
ike
hi ike,
FIrst of all, i update my code a little bit to make sure no duplicate point in vector. Done.
now i try to use the glutMotionFunc with active motion in order to get new point. However, glutMotionFunc give a lot of points as long as drag the mouse. Am i on the right track?
PS: do u i know left mouse or right mouse? in processMouse, we didn't indicate left or right mouse!!!
>> now i try to use the glutMotionFunc with active motion in order to get new point. However, glutMotionFunc give a lot of points as long as drag the mouse. Am i on the right track?
Start with moust button up and down. You dont need glutMotionFunc for that. Just pick the point where the mouse was down and see if there is one of your points nearby. If there is a point catch the mouse up and its x & y for the selected point.
The mouse-button identifier is the first param of your mouse callback function processMouse, called button. The Ids are defined in glut.h you can check it like this:
void processMouse(int button, int state, int x, int y) {
switch(button)
{
case GLUT_LEFT_BUTTON:
// put code for left button here
break;
case GLUT_MIDDLE_BUTTON:
// put code for middle button here
break;
case GLUT_RIGHT_BUTTON:
// put code for right button here
break;
}
Ok, similar to the check for duplicate elements in vector for GLUT_LEFT_BUTTON, add a block for the right button and check there if user clicked a point (if x & y is already in the vector), if yes, store the index of the point in a global variable and in mouse button up replace the point at that index with the new x & y
add a global variable like:
int selectedPointIndex = -1;
Use -1 to indicate if a point is selected, if selectedPointIndex == -1, it means no point is selected, otherwise it is the index of the currently selected point
let me try to paste my code in here,not using attach code snippet. I hope indention is not damaged.
==================
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include <vector>
struct point
{
int x;
int y;
};
std::vector <point> points;
point OnePoint;
point TempPoint;
point FinalPoint;
int selectedPointIndex = -1;
void init (void)
{
glClearColor (1.0,1.0,1.0,0.0);
}
void lineSegment (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_STRIP);
for(int i =0; i < points.size();i++)
{
glVertex2i(points[i].x, points[i].y);
}
glEnd();
glFlush();
}
void processMouse(int button, int state, int x, int y)
{
if (state == GLUT_DOWN)
{
if(button == GLUT_LEFT_BUTTON)
{
// check to avoid duplicate elements in vector
bool _bfound = false;
for (int ii = 0; ii < points.size(); ii++)
{
if( points[ii].x == x && points[ii].y == y)
{
_bfound = true;
printf("Duplicate element!!!\n");
break;
}
}
if( _bfound == false)
{
OnePoint.x= x;
OnePoint.y= y;
points.push_back(OnePoint)
}
}
if(button == GLUT_RIGHT_BUTTON)
{
printf("Right click on mouse\n");
printf("PRESSMOUSE x is %d\n",x);
printf("PRESSMOUSE y is %d\n",y);
TempPoint.x= x;
TempPoint.y= y;
}
}
if( state == GLUT_UP)
{
if(button == GLUT_RIGHT_BUTTON)
{
printf("RELEASEMOUSE x is %d\n",x);
printf("RELEASEMOUSE y is %d\n",y);
FinalPoint.x = x;
FinalPoint.y = y;
}
}
//check to see it TempPoint is in vector or not
for (int iii = 0; iii < points.size(); iii++)
{
// use approximately difference is 0.005. Need advise on difference value !!!
if( abs(points[iii].x- TempPoint.x) <= 0.005 && abs(points[iii].y - TempPoint.y) <=0.005 )
{
selectedPointIndex = iii;
printf("Found point in vector!!!\n");
break;
}
}
// upgrade vector at selectedPointIndex with FinalPoint when right mouse Release
if ( selectedPointIndex > -1)
{
points[selectedPointIndex]
points[selectedPointIndex]
}
//
for (int i =0; i <= points.size() -1; i++)
{
printf("OnePoint is %d %d\n",points[i].x, points[i].y);
}
printf("*****\n");
glutPostRedisplay(); // << has to be here to render the scene with the new data
}
void resize(int width, int height)
{
glViewport( 0, 0, (GLint)width, (GLint)height );
glMatrixMode( GL_PROJECTION);
//gluOrtho2D(0.0, width,0.0, height);
gluOrtho2D(0.0, width, height, 0.0);
glMatrixMode(GL_MODELVIEW)
}
void main(int argc, char ** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_S
glutInitWindowPosition(50,
glutInitWindowSize(512,512
glutCreateWindow("Drawing polyline with mouse interactive");
init();
//adding here the mouse processing callbacks
glutMouseFunc(processMouse
glutDisplayFunc(lineSegmen
//glutMotionFunc(processMo
glutReshapeFunc(resize);
//glutMotionFunc(processMo
//glutPassiveMotionFunc(pr
//glutEntryFunc(processMou
glutMainLoop();
}
right now you do it, whenever processMouse is called, there is no "if" around it, you dont check the button or the state for this block:
//check to see it TempPoint is in vector or not
for (int iii = 0; iii < points.size(); iii++)
{
// use approximately difference is 0.005. Need advise on difference value !!!
if( abs(points[iii].x- TempPoint.x) <= 0.005 && abs(points[iii].y - TempPoint.y) <=0.005 )
{
selectedPointIndex = iii;
printf("Found point in vector!!!\n");
break;
}
}
if (state == GLUT_DOWN)
{
if(button == GLUT_RIGHT_BUTTON)
{
for (int iii = 0; iii < points.size(); iii++)
{
if( abs(points[iii].x- x) <= 3 && abs(points[iii].y - y) <= 3 )
{
selectedPointIndex = iii;
printf("Found point in vector!!!\n");
break;
}
}
}
}
>> // use approximately difference is 0.005. Need advise on difference value !!!
where do you have that code from, you better take a bigger value like e points
Sorry, got no time to elabporate, gonna go to sleep now. Just give it a try, I'm sure you gonna make it ;)
i declare
glPointSize(3);
glLineWidth(2);
as global variables and this code
glBegin(GL_POINTS);
for(int ii =0; ii < points.size();ii++)
{
glVertex2i(points[ii].x, points[ii].y);
}
glEnd();
right now i have errors:
C2373: 'glPointSize' : redefinition; different type modifiers
c:\program files\microsoft visual studio\vc98\include\gl\gl.
D:\OPENGL\Cpp2.cpp(21) : error C2501: 'glLineWidth' : missing storage-class or type specifiers
D:\OPENGL\Cpp2.cpp(21) : error C2373: 'glLineWidth' : redefinition; different type modifiers
c:\program files\microsoft visual studio\vc98\include\gl\gl.
Error executing cl.exe.
Business Accounts
Answer for Membership
by: SyntacticsPosted on 2009-08-30 at 10:28:05ID: 25218432
You need to process the Mouse Move event in your mouse handler. Then update the points[i].x, points[i].y value for the vertice you grabbing in the down event. Then redraw the whole scene. It doesn't look like OpenGL gives you a GLUT_MOVE event, so you may have to write a WM_MOUSE_MOVE handler in the main Windows pump. Been a while since I did any openGL.
erence/art icles/arti cle539.asp .com/2008/ 04/playing -with-open gl- mouse-i nteraction .html
http://www.gamedev.net/ref
http://lukerymarz.blogspot