I’m currently attempting to use a MatrixLens to produce an “oblique projection”. And I think that I have this largely working–but there are some aspects that are eluding me, and on which I would like to ask for help…
To start with, my MatrixLens is being set up like so:
self.matrixLens = MatrixLens()
row1 = Vec4(0.025, 0, 0, 0)
row2 = Vec4(0, 0.00625, 0.025, 0)
row3 = Vec4(0, 0.025, 0, 0)
row4 = Vec4(0, 0, 0, 1)
mat = Mat4(row1, row2, row3, row4)
self.matrixLens.setUserMat(mat)
But with any lens, I think, I find that if I don’t make adjustments to account for the game-window’s aspect-ratio, things may become distorted; the MatrixLens constructed above is no exception. To that end I have a window-event that adjusts the film-size. In short, it gets the new aspect ratio, specifies a base film-size, uses the aspect-ratio to adjust that film-size, and then applies the new values to the current lens. Something like so:
def windowUpdated(self, graphicsWindow):
aspectRatio = self.getAspectRatio()
lens = self.camNode.getLens()
xSize = 40
ySize = 40
if aspectRatio < 1:
ySize /= aspectRatio
else:
xSize *= aspectRatio
lens.setFilmSize(xSize, ySize)
For an OrthographicLens, this works. However, for my MatrixLens as constructed above, I find that a base film-size of 1 (instead of 40) instead produces the desired effect.
The camera, meanwhile, is placed at (0, -20, 20), and given a pitch-angle of -45. (Which for an OrthographicLens produces a view looking downwards, such that the origin is centred in the render.)
Which brings me to my two questions:
First, the resultant render is offset upwards on the y-axis. Can anyone tell me what I’m doing wrong there, and what I might do about it?
And second, I’ve tried to use the larger base film-size of 40 with my MatrixLens and then adjust the matrix to compensate, but it doesn’t seem to work. For example, the following matrix:
row1 = Vec4(0.5, 0, 0, 0)
row2 = Vec4(0, 0.125, 0.5, 0)
row3 = Vec4(0, 0.5, 0, 0)
row4 = Vec4(0, 0, 0, 1)
(i.e. scaled up by a similar amount)
Produces no visible output from my test-scene; I don’t know what space it’s trying to render.
So, any thoughts? (And if I’m doing something completely incorrectly, please tell me!)