Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Oblique near clipping on perspective matrix

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2012
    Posts
    16

    Oblique near clipping on perspective matrix

    Hello all,

    I try to use the sample from Eric Lengyel without success,

    I think my problem is related to the clip plane, since my plane is from world coordinate, it say it need to be in camera eye coord,
    Do I need transform my plane (world space) before using it?

    The perspective matrix is build using glm:erspective, my matrix are basically glm::mat4...

    Code :
        matrix4 oblique = projection;
        vector4 plane(normal, distance);
        vector4 q;
        q.x = (sign(plane.x) + projection[0][2]) / projection[0][0];
        q.y = (sign(plane.y) + projection[1][2]) / projection[1][1];
        q.z = -1.0f;
        q.w = (1.0f + projection[2][2]) / projection[2][3];
        vector4 c = plane * (2.0f / glm::dot(plane, q));
     
        oblique[0][2] = c.x;
        oblique[1][2] = c.y;
        oblique[2][2] = c.z + 1.0f;
        oblique[3][2] = c.w;

    Here the shot using the projection without the oblique. The second shot show the issue I try to resolve with oblique near clip plane.

    If I am using this code, I am jumping out of the map, I just see the sky
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	oblique0.jpg 
Views:	127 
Size:	15.8 KB 
ID:	1072   Click image for larger version. 

Name:	oblique1.jpg 
Views:	141 
Size:	13.4 KB 
ID:	1073  

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,190
    By oblique perspective, I assume you mean a case where it is not symmetric perspective but rather asymmetric perspective.

    Simplest thing is to just use glFrustum() to cook this PROJECTION matrix and gluLookAt to cook your VIEWING matrix (or use work-alikes, in the now-common case where you aren't using GL built in matrix math).

    In WORLD-SPACE, define your eyepoint and near clip plane. Draw a vector from the eyepoint through and perpendicular to the near clip plane. This is your EYE-SPACE -Z axis. You can define your up-vector as well, and then (incidentally) you have enough to completely define your VIEWING transform -- just call gluLookAt to get it.

    Now back to that PROJECTION transform. Take that vector you drew from the eyepoint orthogonal to the near clip plane. Take the distance between the eyepoint and the point where it hits the near clip plane. That is your "near" distance for glFrustum(). Now look at the sides of your frustum and where they hit the near clip plane. Those provide your l,r,b,t values. Finally, just pick your "far" value and you've just finished collecting all the parameters to pass glFrustum() to build your projection matrix.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2012
    Posts
    16
    By oblique i mean, when you are not in front of a mirror, but on the side, look my image from my app, I use q3dm0 map to test the mirror and portal. see the images, you will understand when you compare both of them.

    It's just i need to transform my plane before using it, I did not find the right transformation to make my oblique work so far.

    I try to accomplish this:
    http://www.terathon.com/code/oblique.html

  4. #4
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    490
    Quote Originally Posted by Sylvain Rochette View Post

    I think my problem is related to the clip plane, since my plane is from world coordinate, it say it need to be in camera eye coord,
    Do I need transform my plane (world space) before using it?
    Yes.

    Note that, with a projection matrix generated by gluPerspective(), setting clipPlane to [0,0,-1,-zNear] leaves the projection matrix unchanged.

  5. #5
    Junior Member Newbie
    Join Date
    Feb 2012
    Posts
    16
    So the solution is to change the plane distance for the distance between the camera pos and face origin i guess

    I will try that tomorow i am outside for 2 days

  6. #6
    Junior Member Newbie
    Join Date
    Feb 2012
    Posts
    16
    Ok I resolved my issues,

    I needed to transform my plane in order to use it

    matrix4 reflection = plane.reflection();
    vector4 q(plane.normal, plane.distance);
    q = glm::transpose(glm::inverse(parent.view() * reflection)) * q;
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	oblique2.jpg 
Views:	69 
Size:	13.8 KB 
ID:	1074  
    Last edited by Sylvain Rochette; 07-15-2013 at 05:25 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •