Changeset a5b5e95 in opengl-game


Ignore:
Timestamp:
Mar 7, 2018, 2:13:27 AM (7 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
64a70f4
Parents:
0424bd8
Message:

Make mouse click object detection work with a non-identity view matrix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • new-game.cpp

    r0424bd8 ra5b5e95  
    160160
    161161      //x = -.1f;
    162       x = -.25f;
     162      //x = -.25f;
    163163      //x = -.5f;
    164164
    165       y = .1f;
     165      //y = .1f;
    166166
    167167      cout << "x: " << x << ", y: " << y << endl;
     
    181181
    182182      //vec4 ray_clip = vec4(0.0f, 0.0f, NEAR_CLIP, 1.0f); // this should have a z equal to the near clipping plane
    183       vec4 ray_clip = vec4(x, y, 0.0f, 1.0f); // this should have a z equal to the near clipping plane
     183      vec4 ray_clip = vec4(x, y, NEAR_CLIP, 1.0f); // this should have a z equal to the near clipping plane
    184184      vec4 ray_eye = ray_clip;
    185185      vec3 ray_world = (inverse(view_mat) * ray_eye).xyz();
     
    189189       * Normalizing the world ray caused issues, although it should make sense with the projection
    190190       * matrix, since the z coordinate has meaning there.
    191        *
    192        * Now, I need to figure out the correct intersection test in 2D space
    193        * Also, need to check that the global triangle points are correct
    194191       */
    195192
    196193      printVector("Initial world ray:", ray_world);
    197194
    198       // Theoretically, I should be able to change the z of the camera to whatever I want.
    199       // Figure out why I can't.
    200       // Remember that ray_world has to be a ray along the click line, not any point along it
    201       // vec3 cam_pos_temp = ray_world;
    202       // ray_world = vec3(0.0f, 0.0f, 1.0f);
    203 
    204       vec3 cam_pos_temp = vec3(ray_world.xy(), 0.0f);
     195      vec4 cam_pos_origin = vec4(x, y, 0.0f, 1.0f);
     196      vec3 cam_pos_temp = (inverse(view_mat) * cam_pos_origin).xyz();
     197
    205198      ray_world = ray_world-cam_pos_temp;
    206 
    207       // upper right corner is 1, 1 in opengl
    208199
    209200      cout << "Ray clip -> (" << ray_clip.x << "," << ray_clip.y << "," << ray_clip.z << ")" << endl << endl;;
     
    484475
    485476   //cam_pos = vec3(0.0f, 0.0f, 2.0f);
    486    cam_pos = vec3(0.0f, 0.0f, 0.0f);
     477   cam_pos = vec3(0.3f, 0.0f, 0.3f);
    487478   float cam_yaw = 45.0f * 2.0f * 3.14159f / 360.0f;
    488479
Note: See TracChangeset for help on using the changeset viewer.