changed ClutterPerspective.fovy from ClutterAngle to degrees

This commit is contained in:
Tomas Frydrych 2007-06-25 13:43:13 +00:00
parent c451d0501b
commit 2ef9e63f9c
3 changed files with 21 additions and 14 deletions

4
cogl.h
View File

@ -63,7 +63,7 @@ gboolean
cogl_check_extension (const gchar *name, const gchar *ext); cogl_check_extension (const gchar *name, const gchar *ext);
void void
cogl_perspective (ClutterAngle fovy, cogl_perspective (ClutterFixed fovy,
ClutterFixed aspect, ClutterFixed aspect,
ClutterFixed zNear, ClutterFixed zNear,
ClutterFixed zFar); ClutterFixed zFar);
@ -71,7 +71,7 @@ cogl_perspective (ClutterAngle fovy,
void void
cogl_setup_viewport (guint width, cogl_setup_viewport (guint width,
guint height, guint height,
ClutterAngle fovy, ClutterFixed fovy,
ClutterFixed aspect, ClutterFixed aspect,
ClutterFixed z_near, ClutterFixed z_near,
ClutterFixed z_far); ClutterFixed z_far);

View File

@ -443,13 +443,14 @@ cogl_alpha_func (COGLenum func,
} }
void void
cogl_perspective (ClutterAngle fovy, cogl_perspective (ClutterFixed fovy,
ClutterFixed aspect, ClutterFixed aspect,
ClutterFixed zNear, ClutterFixed zNear,
ClutterFixed zFar) ClutterFixed zFar)
{ {
ClutterFixed xmax, ymax; ClutterFixed xmax, ymax;
ClutterFixed x, y, c, d; ClutterFixed x, y, c, d;
ClutterFixed fovy_rad_half = CFX_MUL (fovy, CFX_PI) / 360;
GLfloat m[16]; GLfloat m[16];
@ -461,10 +462,11 @@ cogl_perspective (ClutterAngle fovy,
* 1) xmin = -xmax => xmax + xmin == 0 && xmax - xmin == 2 * xmax * 1) xmin = -xmax => xmax + xmin == 0 && xmax - xmin == 2 * xmax
* same true for y, hence: a == 0 && b == 0; * same true for y, hence: a == 0 && b == 0;
* *
* 2) When working with small numbers, we can are loosing significant * 2) When working with small numbers, we are loosing significant
* precision, hence we use clutter_qmulx() here, not the fast macro. * precision, hence we use clutter_qmulx() here, not the fast macro.
*/ */
ymax = clutter_qmulx (zNear, clutter_tani (fovy >> 1)); ymax = clutter_qmulx (zNear, CFX_DIV (clutter_sinx (fovy_rad_half),
clutter_cosx (fovy_rad_half)));
xmax = clutter_qmulx (ymax, aspect); xmax = clutter_qmulx (ymax, aspect);
x = CFX_DIV (zNear, xmax); x = CFX_DIV (zNear, xmax);
@ -486,12 +488,13 @@ cogl_perspective (ClutterAngle fovy,
void void
cogl_setup_viewport (guint width, cogl_setup_viewport (guint width,
guint height, guint height,
ClutterAngle fovy, ClutterFixed fovy,
ClutterFixed aspect, ClutterFixed aspect,
ClutterFixed z_near, ClutterFixed z_near,
ClutterFixed z_far) ClutterFixed z_far)
{ {
GLfloat z_camera; GLfloat z_camera;
ClutterFixed fovy_rad = CFX_MUL (fovy, CFX_PI) / 180;
GE( glViewport (0, 0, width, height) ); GE( glViewport (0, 0, width, height) );
@ -505,8 +508,8 @@ cogl_setup_viewport (guint width,
/* camera distance from screen, 0.5 * tan (FOV) */ /* camera distance from screen, 0.5 * tan (FOV) */
#define DEFAULT_Z_CAMERA 0.866025404f #define DEFAULT_Z_CAMERA 0.866025404f
z_camera = CLUTTER_FIXED_TO_FLOAT (clutter_tani (fovy) >> 1); z_camera = CLUTTER_FIXED_TO_FLOAT (CFX_DIV (clutter_sinx (fovy_rad),
clutter_cosx (fovy_rad)) >> 1);
GE( glTranslatef (-0.5f, -0.5f, -z_camera) ); GE( glTranslatef (-0.5f, -0.5f, -z_camera) );
GE( glScalef ( 1.0f / width, GE( glScalef ( 1.0f / width,
-1.0f / height, -1.0f / height,

View File

@ -449,13 +449,14 @@ cogl_alpha_func (COGLenum func,
* Fixed point implementation of the perspective function * Fixed point implementation of the perspective function
*/ */
void void
cogl_perspective (ClutterAngle fovy, cogl_perspective (ClutterFixed fovy,
ClutterFixed aspect, ClutterFixed aspect,
ClutterFixed zNear, ClutterFixed zNear,
ClutterFixed zFar) ClutterFixed zFar)
{ {
ClutterFixed xmax, ymax; ClutterFixed xmax, ymax;
ClutterFixed x, y, c, d; ClutterFixed x, y, c, d;
ClutterFixed fovy_rad_half = CFX_MUL (fovy, CFX_PI) / 360;
GLfixed m[16]; GLfixed m[16];
@ -470,7 +471,8 @@ cogl_perspective (ClutterAngle fovy,
* 2) When working with small numbers, we can are loosing significant * 2) When working with small numbers, we can are loosing significant
* precision, hence we use clutter_qmulx() here, not the fast macro. * precision, hence we use clutter_qmulx() here, not the fast macro.
*/ */
ymax = clutter_qmulx (zNear, clutter_tani (fovy >> 1)); ymax = clutter_qmulx (zNear, CFX_DIV (clutter_sinx (fovy_rad_half),
clutter_cosx (fovy_rad_half)));
xmax = clutter_qmulx (ymax, aspect); xmax = clutter_qmulx (ymax, aspect);
x = CFX_DIV (zNear, xmax); x = CFX_DIV (zNear, xmax);
@ -492,7 +494,7 @@ cogl_perspective (ClutterAngle fovy,
void void
cogl_setup_viewport (guint w, cogl_setup_viewport (guint w,
guint h, guint h,
ClutterAngle fovy, ClutterFixed fovy,
ClutterFixed aspect, ClutterFixed aspect,
ClutterFixed z_near, ClutterFixed z_near,
ClutterFixed z_far) ClutterFixed z_far)
@ -500,6 +502,7 @@ cogl_setup_viewport (guint w,
gint width = (gint) w; gint width = (gint) w;
gint height = (gint) h; gint height = (gint) h;
ClutterFixed z_camera; ClutterFixed z_camera;
ClutterFixed fovy_rad = CFX_MUL (fovy, CFX_PI) / 180;
GE( glViewport (0, 0, width, height) ); GE( glViewport (0, 0, width, height) );
GE( glMatrixMode (GL_PROJECTION) ); GE( glMatrixMode (GL_PROJECTION) );
@ -516,7 +519,8 @@ cogl_setup_viewport (guint w,
/* camera distance from screen, 0.5 * tan (FOV) */ /* camera distance from screen, 0.5 * tan (FOV) */
#define DEFAULT_Z_CAMERA 0.866025404f #define DEFAULT_Z_CAMERA 0.866025404f
z_camera = clutter_tani (fovy) >> 1; z_camera = CFX_DIV (clutter_sinx (fovy_rad),
clutter_cosx (fovy_rad)) >> 1;
GE( glTranslatex (-1 << 15, -1 << 15, -z_camera)); GE( glTranslatex (-1 << 15, -1 << 15, -z_camera));