Picking/Ray projection with orthographic camera

1.2k views Asked by At

I've got a "simple" problem in my code, picking work perfectly when my camera is in perspective mode but result are strange when I'm in orthographic mode.

Here is what I've done:

void Ray::computeFromCamera(    const glm::vec3& position,
                                    const glm::mat4& modelView,
                                    const glm::mat4& projection,
                                    const glm::vec4& viewPort,
                                    float near,
                                    float far )
    {
        this->origin.computeFromCamera( glm::vec3( position.x, position.y, near ),
                                        modelView,
                                        projection,
                                        viewPort );

        this->direction.computeFromCamera(  glm::vec3( position.x, position.y, far ),
                                            modelView,
                                            projection,
                                            viewPort );
    }

Ray computing sounds good because I can select object.

Here is what I do with results:

glm::vec3 start = interfactionCamera->ray.getOrigin();
glm::vec3 end   = interfactionCamera->ray.getDirection();

// Normalize direction.
glm::vec3 endNormalized(end - start);
endNormalized = glm::normalize(endNormalized);

When I do the last step, here is what I have:

Without normalized direction:

  • ok in orthographic camera
  • don't work in perspective camera

With normalized direction:

  • don't work in perspective camera
  • ok in orthographic camera
0

There are 0 answers