LongDuZboub
LongDuZboub

Reputation: 1051

Picking/Ray projection with orthographic camera

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:

With normalized direction:

Upvotes: 2

Views: 1277

Answers (0)

Related Questions