home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.sgi
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!elroy.jpl.nasa.gov!usc!zaphod.mps.ohio-state.edu!cs.utexas.edu!bcm!aio!carla!goza
- From: goza@carla.JSC.NASA.GOV (Mike Goza)
- Subject: Re: Matrix multiplication in GL
- Message-ID: <1992Nov5.183947.6290@aio.jsc.nasa.gov>
- Sender: goza@carla (Mike Goza)
- Organization: IGOAL
- References: <Bx7KA3.2Ix@cs.uiuc.edu>
- Date: Thu, 5 Nov 1992 18:39:47 GMT
- Lines: 36
-
- There is a way to use the GL to multiply points.
- 1. Load the transformation matrix using loadmatrix()
- 2. Create another matrix where the point is a vector in the 4x4 with [x,y,z,1]
- 3. use multmatrix() to multiply the vector matrix by the loaded matrix
- 4. use getmatrix() to retrieve the resultant matrix and look in the appropriate collumn or row
- for the result of the transformation.
-
- Might I make a suggestion though, from my extensive use of the matrix multiplication and doing
- point and normal transformations, NOT using the GL is much faster. If you create routines to
- multiply a point by a 4x4 matrix or 4x4 times 4x4 matrix, or normal by 4x4, and set the values for
- the result by longhand. The answer is returned DRAMATICALLY quicker. By "longhand," I mean...
-
- xprime = x * mat[0][0] + y * mat[1][0] + z * mat[2][0] + mat[3][0]
- yprime ...
- newmat[0][0] = ...
-
- Hopefully you get the picture. If you do timing test on GL versus non GL, I think that you will
- find the NON GL version to work much quicker. Try a simple test program for a 1000 point transforms
- That should show a major difference between the two methods.
-
- The reason you save so much time is the load and get take lots of time and your transformation
- ignores the 4th collumn of the matrix on point and normal transforms, thus saving operations.
-
- Try it and see what happens.
-
- Mike Goza
- goza@cheers.jsc.nasa.gov
-
-
- PS. Another speed up for your code is the abs() function that most people use. _ABS() is much
- faster than abs() or fabs() and it works for integers or floating points. It is in math.h and
- is nothing more than a conditional if...
-
- #define _ABS(x) ((x) < 0 ? -(x) : (x))
-
- Try that as well, I think you will find it faster.
-