PDA

View Full Version : using mouse cursor to draw lines



fox
04-25-2001, 05:07 AM
Hi I wonder how I could use the mouse cursor to draw lines - I know you have to use the gdi to implement this but how could I incorporate this in an opengl program - has anyone done anything like this - any example programs

cheers

chennes
04-25-2001, 06:50 AM
YOu can certainyl use OpenGl to draw lines. All you have to do is tell it where to draw them http://www.opengl.org/discussion_boards/ubb/smile.gif. Get the location of the mouse, convert it into whatever coordinate system you are using, and draw away.

Chris

fox
04-25-2001, 10:59 PM
Originally posted by chennes:
YOu can certainyl use OpenGl to draw lines. All you have to do is tell it where to draw them http://www.opengl.org/discussion_boards/ubb/smile.gif. Get the location of the mouse, convert it into whatever coordinate system you are using, and draw away.

Chris

Would this be interactive? also any code samples of how I can set up the mouse to draw lines - I know how to do it using the gdi but I need to know how to do it in opengl

thanx

GoatNat
04-26-2001, 07:41 AM
The problem you're having (im fairly certain) is converting the 2d points that your mouse is at to 3d points in your world (with ajustments for different panning, view angles, etc).. below is a good peice of code to get started, the idea all lies behind the glUnproject() function.. its tricky but with tinkering you can get the desired effect.
http://www.codeguru.com/opengl/zooming.shtml

Nat

LordKronos
04-26-2001, 12:09 PM
or you can just set up an ortho projection matrix that maps window coords to opengl coords.

fox
05-02-2001, 12:43 AM
GoatNat: How would this work with perspective view?

cheers

fox
05-11-2001, 06:01 AM
Hi

I've used the example above - I can get lines to show up but not where I'm drawing them - also the lines disappear, how can I get then to stay - and if I wanted to delete say the last line how would I do this?

cheers

ScottManDeath
05-12-2001, 07:15 AM
Originally posted by fox:
Hi

I've used the example above - I can get lines to show up but not where I'm drawing them - also the lines disappear, how can I get then to stay - and if I wanted to delete say the last line how would I do this?

cheers

You have to store the coordinates of the edge points in a data structure e.g. a list or an array. Then when you draw the scene in the main app, loop through the points and draw them using glBegin(GL_LINE_LOOP).

If you want to delete a line, just remove the last point from your data storage and wait for redrawing.

You can use gluUnProject(...) to convert mouse coordinates into world coordinates when a mouse click occurs.

If you are interested, I did a program with a similar problem of getting mouse coordinates into points and drawing lines. You can mail me, and I will send you the program and the code.

Bye

fox
05-14-2001, 02:23 AM
yes, i've e-mailed you scott