Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8262699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:50:33+00:00 2026-06-08T03:50:33+00:00

I have some code for transformation matrices and I added some functions that deal

  • 0

I have some code for transformation matrices and I added some functions that deal with Frustum and Perspective.

The thing is that when I call the perspective everything looks as if I have a really big field of view (ok in the middle of the screen while very stretched at the edges).
This effect is worse when I increase the near value.

    void Frustum(T left, T right, T bottom, T top, T zNear, T zFar)
    {
        m[0][0]=2.0f*zNear/(right-left);
        m[1][0]=0.0f;
        m[2][0]=(right+left)/(right-left);
        m[3][0]=0.0f;
        m[0][1]=0.0f;
        m[1][1]=2.0f*zNear/(top-bottom);
        m[2][1]=(top+bottom)/(top-bottom);
        m[3][1]=0.0f;
        m[0][2]=0.0f;
        m[1][2]=0.0f;
        m[2][2]=-(zFar+zNear)/(zFar-zNear);
        m[3][2]=-2.0f*zFar*zNear/(zFar-zNear);
        m[0][3]=0.0f;
        m[1][3]=0.0f;
        m[2][3]=-1.0f;
        m[3][3]=0.0f;
    }

    void Perspective(T fovy,T aspectRatio,T zNear,T zFar)
    {
        T xmin,xmax,ymin,ymax;
        ymax= zNear* tan(fovy*Math<T>::PI/360.0);
        ymin= -ymax;
        xmin= ymin*aspectRatio;
        xmax= ymax*aspectRatio;
        Frustum(xmin,xmax,ymin,ymax,zNear,zFar);
    }

T is a float or a double as the class is templated (for the test I only used floats).

The test values I use are fovy="60" znear="1.0" zfar="1000.0" and when I change them to fovy="60" znear="10.0" zfar="1000.0" it get’s a lot worse.

Note that the matrices are DirectX style yet I use them in OpenGL and thus I have change the order of multiplication in the shader.

Do you guys see anything wrong with my code?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:50:36+00:00Added an answer on June 8, 2026 at 3:50 am

    The problem was that when I started using the matrices that were transposed (DirectX style) I figured I must also transpose the frustum math which isn’t a good idea.

    This is how the Frustum function should look like:

        void Frustum(T left, T right, T bottom, T top, T zNear, T zFar)
        {
            T zDelta = (zFar-zNear);
            T dir = (right-left);
            T height = (top-bottom);
            T zNear2 = 2*zNear;
    
            m[0][0]=2.0f*zNear/dir;
            m[0][1]=0.0f;
            m[0][2]=(right+left)/dir;
            m[0][3]=0.0f;
            m[1][0]=0.0f;
            m[1][1]=zNear2/height;
            m[1][2]=(top+bottom)/height;
            m[1][3]=0.0f;
            m[2][0]=0.0f;
            m[2][1]=0.0f;
            m[2][2]=-(zFar+zNear)/zDelta;
            m[2][3]=-zNear2*zFar/zDelta;
            m[3][0]=0.0f;
            m[3][1]=0.0f;
            m[3][2]=-1.0f;
            m[3][3]=0.0f;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that will change the background color of a specific label
I have some code here that uses bitsets to store many 1 bit values
I have some code that is supposed to return an NSString. Instead it is
I have some code that generates Visio masters for me, and some masters have
I have some code that causes the box2d physics simulation to stutter forever after
I have some code that runs a model in a loop. Each iteration of
I have some code that shows results in a table Right now it will
Currently I have some legacy ASP.NET 2.0 code that uses the ASP Xml web
I have some performance-heavy code that performs bit manipulations. It can be reduced to
I have some existing code in C# that I'm trying to move to an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.