1

So I'm trying to make 3d engine and I'm getting pretty close to making it work but, the project formula I'm using which looks like this: ( axis = axis / (z / 10 * tan(fov * 0.0175) + 0) * 40; isn't cutting it.

I tried to implement a projection matrix in hopes of making the projection look right, but it does not work as intended, I've printed the screen x and y values of a point of a triangle I'm trying to render but it seems to be just of my screen. Here is the projection matrix code.

Vector2f proj()
{

    float nx = x;
    float ny = y;

    float nz = z;
    float nw = 0;

    float pmat[4][4] = {type here

    { (1 / tan(45*180/3.1415)), 0, 0, 0 },
    {0, 1 / tan(45*180/3.1415),  0, 0},
    {0, zfar / (zfar - znear), (-zfar * znear) / (zfar - znear) , 0},
    {0, 0, 1, 0}
    };

    nx = x * pmat[0][0] + y * pmat[1][0] + z * pmat[2][0] + pmat[3][0];
    ny = x * pmat[0][1] + y * pmat[1][1] + z * pmat[2][1] + pmat[3][1];
    nz = x * pmat[0][2] + y * pmat[1][2] + z * pmat[2][2] + pmat[3][2];
    nw = x * pmat[0][3] + y * pmat[1][3] + z * pmat[2][3] + pmat[3][2];

    nx /= nw; ny /= nw; nz /= nw;


    //nx = x / (z / 10 * tan(fov * 0.0175) + 0) * 40;
    //ny = y / (z / 10 * tan(fov * 0.0175) + 0) * 40;
    //float div = (z / 10 * tan(fov * 0.0175) + 0.5);


    return Vector2f(nx, ny);
}
PaulMcKenzie
  • 34,698
  • 4
  • 24
  • 45
  • What is the 45*180/3.1415 supposed to do? If it’s attempting to convert degrees to radians then the multiplier is the wrong way up. Also, tan(45 degrees) is just 1. – lastchance Jun 08 '23 at 03:31

0 Answers0