Jaws's picture

How to zoom, move and rotate the moedl by mouse?/Comment on peut faire le zoom, translation et rotation par le souris?

hello guys, dose somebody kown how to move ,zoom and rotate the model that we paint by using the mouse?

Thank avance!

Salut à tout le monde, est-ce que quelqu'un sait comment faire le zoom, translation et rotation par le souris?

Merci avance!


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
szamil's picture

You have to capture mouse events just by attaching mouse events and then apply the transformation to the object you want.
These are the events I've made to rotate my view around the object. Should be easy to rewrite it to your needs.

#region GLControl. Mouse event handlers
        private int _mouseStartX = 0;
        private int _mouseStartY = 0;
        private float angleX = 0;
        private float angleY = 0;
        private float angleXS = 0;
        private float angleYS = 0;
        private float distance = 5;
        private float distanceS = 5;
        private void glControl_MouseDown(object sender, EventArgs e)
        {
            MouseEventArgs ev = (e as MouseEventArgs);
            _mouseStartX = ev.X;
            _mouseStartY = ev.Y;
 
 
        }
        private void glControl_MouseUp(object sender, EventArgs e)
        {
            MouseEventArgs ev = (e as MouseEventArgs);
 
            angleXS = angleX;
            angleYS = angleY;
            distanceS = distance;
 
        }
        private void glControl_MouseMove(object sender, EventArgs e)
        {
            MouseEventArgs ev = (e as MouseEventArgs);
            if (ev.Button == MouseButtons.Left)
            {
                angleX = angleXS + (ev.X - _mouseStartX) * rotSpeed;
                angleY = angleYS + (ev.Y - _mouseStartY) * rotSpeed;
            }
            if (ev.Button == MouseButtons.Right)
            {
                distance = Math.Max(2.9f,distanceS + (ev.Y - _mouseStartY) / 10.0f);
            }
        }
        #endregion

Now you need to attach them to e.g. glControl:

            glControl.MouseMove += new MouseEventHandler(glControl_MouseMove);
            glControl.MouseDown += new MouseEventHandler(glControl_MouseDown);
            glControl.MouseUp += new MouseEventHandler(glControl_MouseUp);

Similar with moving objects...

Then you should apply the transforms for every object you want, of course with Push & Pop matrices of transforms...
This should help. Most of it I have taken from the examples, so try to read them for yourself.

Jaws's picture

Thank you very much szamil!!

i have the question yet, beacause i use the windows forms application, i don't kown how to change you code in the windows forms application.

for exemple, the windows forms application cannot kows the key word "as", how can i do?

Jaws's picture

Thank you very much szamil!!
I make it!