Adjust 3D aspect ratio for non square resolutions
Posted: June 24th, 2016, 1:29 pm
Hello! I'm a new member, but I've been lurking for a while here.
Recently I decided to get serious about making a small game for the PS1, and a 3D game at that.
I have experience working with Direct3D and OpenGL, but working on PS1 is quite different! Lots of things are done differently and I can't wrap my head around a few things...
So, the problem I'm having here is that I want to render my game at 512x240, but keep the 4:3 aspect ratio without using LibGS.
Differently from how it is done on PC (this is set up at the projection matrix) I can't find a way to change that.
When you use LibGTE/LibGPU to render, you have to do that by yourself, if not, the results will be stretched thin on screen which does not look good. But they never explain how it is done in LibGS.
I tried to use ScaleMatrixL() to my camera matrix, but it works only when the camera is at the origin, if I try to translate the camera in any directions it will glitch out.
Here's the code I'm using to generate the camera matrix:
(by the way, the camera is always offset by a certain defined vector, so it orbits around the target)
[C]
RotMatrix(&cam->rotation, &cam->view_matrix);
TransposeMatrix(&cam->view_matrix, &temp);
ApplyMatrixLV(&temp, &cam->offset, &f_pos_t);
f_pos_t2 = cam->position;
f_pos_t2.vx -= f_pos_t.vx;
f_pos_t2.vy -= f_pos_t.vy;
f_pos_t2.vz -= f_pos_t.vz;
ApplyMatrixLV(&cam->view_matrix, &f_pos_t2, &f_pos);
f_pos.vx = -f_pos.vx;
f_pos.vy = -f_pos.vy;
f_pos.vz = -f_pos.vz;
TransMatrix(&cam->view_matrix, &f_pos);
ScaleMatrixL(&cam->view_matrix,&cam->aspect);
[/C]
What happens is, it renders correctly while the camera position is 0 or close to it, once it starts to get away from the center, when rotating it will start rotating in weird patterns making an 8 like figure, and it grows as you get farther from the origin point.
My guess is that it's probably the order I'm applying the scaling, but I can't figure out where it should be.
Thanks!
Recently I decided to get serious about making a small game for the PS1, and a 3D game at that.
I have experience working with Direct3D and OpenGL, but working on PS1 is quite different! Lots of things are done differently and I can't wrap my head around a few things...
So, the problem I'm having here is that I want to render my game at 512x240, but keep the 4:3 aspect ratio without using LibGS.
Differently from how it is done on PC (this is set up at the projection matrix) I can't find a way to change that.
When you use LibGTE/LibGPU to render, you have to do that by yourself, if not, the results will be stretched thin on screen which does not look good. But they never explain how it is done in LibGS.
I tried to use ScaleMatrixL() to my camera matrix, but it works only when the camera is at the origin, if I try to translate the camera in any directions it will glitch out.
Here's the code I'm using to generate the camera matrix:
(by the way, the camera is always offset by a certain defined vector, so it orbits around the target)
[C]
RotMatrix(&cam->rotation, &cam->view_matrix);
TransposeMatrix(&cam->view_matrix, &temp);
ApplyMatrixLV(&temp, &cam->offset, &f_pos_t);
f_pos_t2 = cam->position;
f_pos_t2.vx -= f_pos_t.vx;
f_pos_t2.vy -= f_pos_t.vy;
f_pos_t2.vz -= f_pos_t.vz;
ApplyMatrixLV(&cam->view_matrix, &f_pos_t2, &f_pos);
f_pos.vx = -f_pos.vx;
f_pos.vy = -f_pos.vy;
f_pos.vz = -f_pos.vz;
TransMatrix(&cam->view_matrix, &f_pos);
ScaleMatrixL(&cam->view_matrix,&cam->aspect);
[/C]
What happens is, it renders correctly while the camera position is 0 or close to it, once it starts to get away from the center, when rotating it will start rotating in weird patterns making an 8 like figure, and it grows as you get farther from the origin point.
My guess is that it's probably the order I'm applying the scaling, but I can't figure out where it should be.
Thanks!