2

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
Olivier Moindrot
  • 27,908
  • 11
  • 92
  • 91
LongDuZboub
  • 1,041
  • 2
  • 12
  • 18
  • Off the top of my head: in an orthographic projection, a point at (x,y,near) and (x,y,far) will project to the same screen space location. Thus, (end - start) will be 0. – Andon M. Coleman Aug 29 '13 at 11:02
  • 1
    Also, your problem description states the same results **with** and **without**, you just reversed the bullet points. – Andon M. Coleman Aug 29 '13 at 11:11

0 Answers0