OpenGL Custom Locator always face camera Maya API

394 views
Skip to first unread message

Dilen Shah

unread,
Jan 22, 2014, 4:55:14 AM1/22/14
to python_in...@googlegroups.com
Hey guys,

I am trying to learn how to create a shape that always faces the camera. I have created before a locator which has its name facing the camera always but how can i do it with the whole shape itself?

Any ideas?

D.

Serge Scherbakov

unread,
Jan 22, 2014, 2:45:03 PM1/22/14
to python_in...@googlegroups.com
Hi,
To achieve it, you can multiply locator transforms on M3dView.modelViewMatrix().inverse()

I use the following to keep my MPxManipulatorNode (circle) oriented on camera (partial copy/paste from draw() method) It's c# but on python workflow the same.
        public override void draw(M3dView view, MDagPath path, M3dView.DisplayStyle style, M3dView.DisplayStatus status)
        {
            .....
            MMatrix modelViewMatrix = new MMatrix();
            view.modelViewMatrix(modelViewMatrix);
            .....
      
            OpenGL.glLineWidth(3);
            OpenGL.glBegin(type);
            for (double i = 0; i < 2 * M_PI; i += M_PI / CIRCLE_SIDES_NUM)
            {
                MPoint circlePoint = new MPoint(Math.Cos(i) * radius, Math.Sin(i) * radius, 0.0);
                MVector circlePointVector = new MVector(circlePoint);
                circlePointVector = circlePointVector.multiply(modelViewMatrix.inverse);

                OpenGL.glVertex3d(circlePointVector.x + center.x, circlePointVector.y + center.y, circlePointVector.z + center.z);
            }
            OpenGL.glEnd();
         }

I hope this will help.

Best Regards,
Serge Scherbakov


среда, 22 января 2014 г., 13:55:14 UTC+4 пользователь Dilen Shah написал:
Reply all
Reply to author
Forward
0 new messages