Projection matrix issue

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Papaew
Prole
Posts: 2
Joined: Fri Jan 25, 2019 9:00 pm

Projection matrix issue

Post by Papaew » Fri Aug 30, 2019 3:02 am

Hello! I'm trying to create simple 3d render engine, but i'm stuck on projection matrix.
I don't know why but it do not give a result (i tried several examples from different sources)
Can someone help me with it?

p.s. I use my own vector and matrix libraries. They are works fine (i guess)
Attachments
uneven 3dlib.zip
(38.69 KiB) Downloaded 30 times

Papaew
Prole
Posts: 2
Joined: Fri Jan 25, 2019 9:00 pm

Re: Projection matrix issue

Post by Papaew » Fri Aug 30, 2019 10:11 pm

Okay, some good people helped me on love's discord server (thank you again ^^)

As expected problem was in my perspective matrix. It was column-major, not row-major.
There is a multiple variants to resolve this priblem:
a) In shader:send use "column" parameter instead "row"
b) Use row-major perspective projection matrix:

Code: Select all

function perspective_projection(fov, aspect, near, far)
local t = tan(rad(fov)/2)
return mat4(1/(aspect*t),0,0,0,
            0,1/t,0,0,
            0,0,-(far+near)/(far-near),-(2*far*near)/(far-near),
            0,0,-1,0)
end
c) Convert matrix from column-major to row-major like this:

Code: Select all

projection = columnToRow(projection:unpack())
shader:send("proj", projection)

function columnToRow(matrix)
    -- Column -> Row major
    if love._version_major > 0 then
        matrix[2], matrix[5] = matrix[5], matrix[2]
        matrix[3], matrix[9] = matrix[9], matrix[3]
        matrix[4], matrix[13] = matrix[13], matrix[4]
        matrix[7], matrix[10] = matrix[10], matrix[7]
        matrix[8], matrix[14] = matrix[14], matrix[8]
        matrix[12], matrix[15] = matrix[15], matrix[12]
    end
    return matrix
end
And also need to change model position -10 units by z-axis to make sure it's in front of the camera
uneven 3dlib.zip
There is a fixed code here
(38.71 KiB) Downloaded 37 times

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests