home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / sys / sgi / 16015 < prev    next >
Encoding:
Text File  |  1992-11-06  |  2.1 KB  |  48 lines

  1. Newsgroups: comp.sys.sgi
  2. 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
  3. From: goza@carla.JSC.NASA.GOV (Mike Goza)
  4. Subject: Re: Matrix multiplication in GL
  5. Message-ID: <1992Nov5.183947.6290@aio.jsc.nasa.gov>
  6. Sender: goza@carla (Mike Goza)
  7. Organization: IGOAL
  8. References:  <Bx7KA3.2Ix@cs.uiuc.edu>
  9. Date: Thu, 5 Nov 1992 18:39:47 GMT
  10. Lines: 36
  11.  
  12. There is a way to use the GL to multiply points. 
  13.   1. Load the transformation matrix using loadmatrix()
  14.   2. Create another matrix where the point is a vector in the 4x4 with [x,y,z,1]
  15.   3. use multmatrix() to multiply the vector matrix by the loaded matrix
  16.   4. use getmatrix() to retrieve the resultant matrix and look in the appropriate collumn or row
  17.      for the result of the transformation.
  18.  
  19. Might I make a suggestion though, from my extensive use of the matrix multiplication and doing
  20. point and normal transformations, NOT using the GL is much faster.  If you create routines to
  21. multiply a point by a 4x4 matrix or 4x4 times 4x4 matrix, or normal by 4x4, and set the values for
  22. the result by longhand.  The answer is returned DRAMATICALLY quicker.  By "longhand," I mean...
  23.  
  24. xprime = x * mat[0][0] + y * mat[1][0] + z * mat[2][0] + mat[3][0]
  25. yprime ...
  26. newmat[0][0] = ...
  27.  
  28. Hopefully you get the picture.  If you do timing test on GL versus non GL, I think that you will
  29. find the NON GL version to work much quicker.  Try a simple test program for a 1000 point transforms
  30. That should show a major difference between the two methods.
  31.  
  32. The reason you save so much time is the load and get take lots of time and your transformation
  33. ignores the 4th collumn of the matrix on point and normal transforms, thus saving operations.
  34.  
  35. Try it and see what happens.
  36.  
  37. Mike Goza
  38. goza@cheers.jsc.nasa.gov
  39.  
  40.  
  41. PS.  Another speed up for your code is the abs() function that most people use.  _ABS() is much
  42.      faster than abs() or fabs() and it works for integers or floating points.  It is in math.h and
  43.      is nothing more than a conditional if...
  44.  
  45.      #define _ABS(x) ((x) < 0 ? -(x) : (x))
  46.  
  47.      Try that as well, I think you will find it faster.
  48.