/* $Id: xform.c,v 1.10 1997/10/30 06:00:06 brianp Exp $ */ /* * Mesa 3-D graphics library * Version: 2.5 * Copyright (C) 1995-1997 Brian Paul * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* * $Log: xform.c,v $ * Revision 1.10 1997/10/30 06:00:06 brianp * added Intel X86 assembly optimzations (Josh Vanderhoof) * * Revision 1.9 1997/07/24 01:25:54 brianp * changed precompiled header symbol from PCH to PC_HEADER * * Revision 1.8 1997/05/28 03:27:03 brianp * added precompiled header (PCH) support * * Revision 1.7 1997/05/01 01:40:51 brianp * replaced sqrt() with GL_SQRT() * * Revision 1.6 1997/04/02 03:15:02 brianp * removed gl_xform_texcoords_4fv() * * Revision 1.5 1997/01/03 23:54:17 brianp * changed length threshold in gl_xform_normals_3fv() to 1E-30 per Jeroen * * Revision 1.4 1996/11/09 01:50:49 brianp * relaxed the minimum normal threshold in gl_xform_normals_3fv() * * Revision 1.3 1996/11/08 02:20:39 brianp * added gl_xform_texcoords_4fv() * * Revision 1.2 1996/11/05 01:38:50 brianp * fixed some comments * * Revision 1.1 1996/09/13 01:38:16 brianp * Initial revision * */ /* * Matrix/vertex/vector transformation stuff * * * NOTES: * 1. 4x4 transformation matrices are stored in memory in column major order. * 2. Points/vertices are to be thought of as column vectors. * 3. Transformation of a point p by a matrix M is: p' = M * p * */ #ifdef PC_HEADER #include "all.h" #else #include #include "mmath.h" #include "types.h" #include "xform.h" #endif /* * Apply a transformation matrix to an array of [X Y Z W] coordinates: * for i in 0 to n-1 do q[i] = m * p[i] * where p[i] and q[i] are 4-element column vectors and m is a 16-element * transformation matrix. */ void gl_xform_points_4fv( GLuint n, GLfloat q[][4], const GLfloat m[16], GLfloat p[][4] ) { /* This function has been carefully crafted to maximize register usage * and use loop unrolling with IRIX 5.3's cc. Hopefully other compilers * will like this code too. */ { GLuint i; GLfloat m0 = m[0], m4 = m[4], m8 = m[8], m12 = m[12]; GLfloat m1 = m[1], m5 = m[5], m9 = m[9], m13 = m[13]; if (m12==0.0F && m13==0.0F) { /* common case */ for (i=0;i1E-30) ? (1.0 / len) : 1.0; v[i][0] = tx * scale; v[i][1] = ty * scale; v[i][2] = tz * scale; } } } else { /* Just transform normals, don't scale */ GLuint i; GLfloat m0 = m[0], m4 = m[4], m8 = m[8]; GLfloat m1 = m[1], m5 = m[5], m9 = m[9]; GLfloat m2 = m[2], m6 = m[6], m10 = m[10]; for (i=0;i