PDA

View Full Version : Line drawing using mouse



lyric
11-13-2002, 08:58 AM
Can someone give me an example of drawing a line with using mouse?

Thanks in advance

vladk
11-13-2002, 10:54 PM
Hello!

First, lets assume you are working with projection matrix, and have 90deg of viewing cone.

Second, you need to detect the X and Y change of your mouse coordinates.

Third, you have to scale the deltaX and deltaY to your 3D space, which means define how many mouse points is one unit (1.0) in the scene, and scale appropriately.

The rest is simple. For example, compute starting X, Y on MouseClick and store it. For each MouseMove compute new X, Y and draw your line from first to second point. Don't forget to have Z value defined. You can have it changed on MouseWheel event.

On second MouseClick finish the drawing and create the line object (meaning store both ends permanently).

Hope this helps.

Gavin
11-14-2002, 02:06 AM
set up orthographic to the size of your window to give a 1to1 relationship between screen coords and mouse.