0
\$\begingroup\$

I am trying to implement a 2d line drawing effect on a 3d mesh using Ogre. In order to do so, I perform silhouette detection on the lines of the object (this works) and then project these lines from world to screen coordinates.

Here is the code I use for converting the coordinates:

            bool toDeviceCoordinates(Ogre::Vector3 &result, Ogre::Vector3 &point,Ogre::Camera *camera)
            {
                if(!camera->isVisible(point))
                {
                    return false;
                }
                Ogre::Vector4 p(point.x,point.y,point.z,1);

                p = camera->getViewMatrix()*p;
                p = camera->getProjectionMatrix()*p;

                result = Ogre::Vector3(p.x,p.y,p.z);
                result /= p.w;

                return true;
            }

To draw these points to the screen I just pass them through the shader like so:

            gl_Position = gl_Vertex;

This works fine except when the origin of the scene is not visible.

Any idea where I am going wrong?

\$\endgroup\$
0
\$\begingroup\$

Solved the problem:

The shader was the culprit - seems it didn't like me skipping the application of the modelviewprojection matrix.

Instead, I applied the above function to convert my points to screen space. I then did my calculations on it - extruding more vertices from it etc. I then applied the inverse matrix operations to those points to return them to world space. These points were then passed to the shader and instead of:

gl_Position = gl_Vertex;

I use the more correct:

gl_Position = modelViewProjectionMatrix*gl_Vertex;

So in essence here is my process: world -> screen -> extrude points -> world -> screen

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.