src/Accum.cpp

Go to the documentation of this file.
00001 
00008 /*
00009 This file is part of Teapot Colony Wars.
00010 
00011 Teapot Colony Wars is free software: you can redistribute it and/or modify
00012 it under the terms of the GNU General Public License as published by
00013 the Free Software Foundation, either version 2 of the License, or
00014 (at your option) any later version.
00015 
00016 Teapot Colony Wars is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 GNU General Public License for more details.
00020 
00021 You should have received a copy of the GNU General Public License
00022 along with Teapot Colony Wars.  If not, see <http://www.gnu.org/licenses/>.
00023 */
00024 
00025 /*
00026  * Copyright (c) 1993-1997, Silicon Graphics, Inc.
00027  * ALL RIGHTS RESERVED
00028  * Permission to use, copy, modify, and distribute this software for
00029  * any purpose and without fee is hereby granted, provided that the above
00030  * copyright notice appear in all copies and that both the copyright notice
00031  * and this permission notice appear in supporting documentation, and that
00032  * the name of Silicon Graphics, Inc. not be used in advertising
00033  * or publicity pertaining to distribution of the software without specific,
00034  * written prior permission.
00035  *
00036  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
00037  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
00038  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
00039  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
00040  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
00041  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
00042  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
00043  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
00044  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
00045  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
00046  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
00047  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
00048  *
00049  * US Government Users Restricted Rights
00050  * Use, duplication, or disclosure by the Government is subject to
00051  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
00052  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
00053  * clause at DFARS 252.227-7013 and/or in similar or successor
00054  * clauses in the FAR or the DOD or NASA FAR Supplement.
00055  * Unpublished-- rights reserved under the copyright laws of the
00056  * United States.  Contractor/manufacturer is Silicon Graphics,
00057  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
00058  *
00059  * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
00060  */
00061 
00062 #include "Accum.h"
00063 
00064 #include <cmath>
00065 
00066 #include "Constants.h"
00067 
00068 void accFrustum(GLdouble left, GLdouble right, GLdouble bottom,
00069                 GLdouble top, GLdouble near, GLdouble far, GLdouble pixdx,
00070                 GLdouble pixdy, GLdouble eyedx, GLdouble eyedy, GLdouble focus)
00071 {
00072   // make a frustum for use with the accumulation buffer
00073   GLdouble xwsize, ywsize;
00074   GLdouble dx, dy;
00075   GLint viewport[4];
00076 
00077   glGetIntegerv(GL_VIEWPORT, viewport);
00078   xwsize = right - left;
00079   ywsize = top - bottom;
00080   dx = -(pixdx * xwsize / (GLdouble)viewport[2] + eyedx * near / focus);
00081   dy = -(pixdx * ywsize / (GLdouble)viewport[3] + eyedy * near / focus);
00082 
00083   glMatrixMode(GL_PROJECTION);
00084   glLoadIdentity();
00085 
00086   glFrustum(left + dx, right + dx, bottom + dy, top + dy, near, far);
00087   glMatrixMode(GL_MODELVIEW);
00088   glLoadIdentity();
00089   glTranslatef(-eyedx, -eyedy, 0.0);
00090 }
00091 
00092 void accPerspective(GLdouble fovy, GLdouble aspect,
00093                     GLdouble near, GLdouble far, GLdouble pixdx, GLdouble pixdy,
00094                     GLdouble eyedx, GLdouble eyedy, GLdouble focus)
00095 {
00096   GLdouble fov2, left, right, bottom, top;
00097   fov2 = ((fovy * PI) / 180.0) / 2.0;
00098 
00099   top = near / (cos(fov2) / sin(fov2));
00100   bottom = -top;
00101   right = top * aspect;
00102   left = -right;
00103 
00104   accFrustum(left, right, bottom, top, near, far,
00105              pixdx, pixdy, eyedx, eyedy, focus);
00106 }

Generated on Sat Feb 2 22:22:54 2008 for Teapot Colony Wars by  doxygen 1.5.4