Mctittles
07-19-2011, 04:55 PM
Hello. I'd like to show some particles on the screen that are a random distance and x/y position from the user. The problem I'm running into is determining what the edges of the screen are for different resolutions and aspect.
I use the following code to set my screen up:
void glPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) {
GLdouble xmin, xmax, ymin, ymax;
ymax = zNear * tan(fovy * M_PI / 360.0);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
}
//...
glViewport(0,0,(GLsizei)currentWidth,(GLsizei)curr entHeight);
glPerspective(60,(GLfloat)currentWidth/(GLfloat)currentHeight,0.4f,1000);
By trial and error I can determine that say the screen is 1680x1050 and the Z is -3 the mzximum X is around 5.7 to -5.7.
I haven't been able to calculate a formula that given a width, height, and Z coordinate I can find the max X and Y so to make sure are particles drawn are visible to the user. Anyone have any experience with this?
I use the following code to set my screen up:
void glPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) {
GLdouble xmin, xmax, ymin, ymax;
ymax = zNear * tan(fovy * M_PI / 360.0);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
}
//...
glViewport(0,0,(GLsizei)currentWidth,(GLsizei)curr entHeight);
glPerspective(60,(GLfloat)currentWidth/(GLfloat)currentHeight,0.4f,1000);
By trial and error I can determine that say the screen is 1680x1050 and the Z is -3 the mzximum X is around 5.7 to -5.7.
I haven't been able to calculate a formula that given a width, height, and Z coordinate I can find the max X and Y so to make sure are particles drawn are visible to the user. Anyone have any experience with this?