Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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