/* $Id: xform.c,v 1.2 2000/10/27 15:21:40 mholst Exp $ */ /* * Mesa 3-D graphics library * Version: 2.2 * Copyright (C) 1995-1996 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. */ /* * 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 * */ #include #include "types.h" #include "xform.h" /* * 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