1
QB64 Discussion / Re: _MAPTRIANGLE 3D ----> 2D ?
« on: March 01, 2022, 06:35:27 am »
I believe this is the C code used to setup the Open GL 3d viewport. Someone familiar with how Open GL calculates the 2D location of a 3D point should be able to help your further regardless of whether they are familiar with QB64 or not.
qb64\internal\c\libqb\gui.cpp
---------------------------------------------------
void set_view(int32 new_mode)
---------------------------------------------------
static int32 dst_w,dst_h;
dst_w=environment__window_width;
dst_h=environment__window_height;
glViewport(0, 0, (GLsizei)dst_w, (GLsizei)dst_h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//note: the max FOV is 90-degrees (this maximum applies to the longest screen dimension)
float fov;
if (environment_2d__screen_scaled_width>environment_2d__screen_scaled_height){
fov=90.0f*((float)environment__window_width/(float)environment_2d__screen_scaled_width);
//convert fov from horizontal to vertical
fov=fov*((float)dst_h/(float)dst_w);
}else{
fov=90.0f*((float)environment__window_height/(float)environment_2d__screen_scaled_height);
}
gluPerspective(fov, (GLfloat)dst_w / (GLfloat)dst_h, 0.1, 10000.0); // Set the Field of view angle (in degrees), the aspect ratio of our window, and the new and far planes
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
---------------------------------------------------
FYI - If undefined by the underlying library (depends on implementation/platform), gluPerspective is implemented manually by QB64 code as...
------------------------------------
double pi_as_double=3.14159265358979;
void gluPerspective(double fovy, double aspect, double zNear, double zFar)
{
double xmin, xmax, ymin, ymax;
ymax = zNear * tan(fovy * pi_as_double / 360.0);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
}
------------------------------------
qb64\internal\c\libqb\gui.cpp
---------------------------------------------------
void set_view(int32 new_mode)
---------------------------------------------------
static int32 dst_w,dst_h;
dst_w=environment__window_width;
dst_h=environment__window_height;
glViewport(0, 0, (GLsizei)dst_w, (GLsizei)dst_h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//note: the max FOV is 90-degrees (this maximum applies to the longest screen dimension)
float fov;
if (environment_2d__screen_scaled_width>environment_2d__screen_scaled_height){
fov=90.0f*((float)environment__window_width/(float)environment_2d__screen_scaled_width);
//convert fov from horizontal to vertical
fov=fov*((float)dst_h/(float)dst_w);
}else{
fov=90.0f*((float)environment__window_height/(float)environment_2d__screen_scaled_height);
}
gluPerspective(fov, (GLfloat)dst_w / (GLfloat)dst_h, 0.1, 10000.0); // Set the Field of view angle (in degrees), the aspect ratio of our window, and the new and far planes
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
---------------------------------------------------
FYI - If undefined by the underlying library (depends on implementation/platform), gluPerspective is implemented manually by QB64 code as...
------------------------------------
double pi_as_double=3.14159265358979;
void gluPerspective(double fovy, double aspect, double zNear, double zFar)
{
double xmin, xmax, ymin, ymax;
ymax = zNear * tan(fovy * pi_as_double / 360.0);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);
}
------------------------------------