home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / FAQSYS18.ZIP / FAQS.DAT / 3D-TRICK.TXT < prev    next >
Text File  |  1996-06-02  |  3KB  |  54 lines

  1. MATH TRICKS
  2.  
  3. This class is probably the most important one, but it is also the most
  4. difficult to explain. I mean, there is no standard optimization method
  5. formaths which will give good results on the general case. But it is
  6. probably the most important one! My only little examples will be for 3D
  7. vectors. When you rotate a point around an axis, you must do 4 MULS:
  8.  
  9. x'=x*cos(Θ)+y*sin(Θ)
  10. y'=x*sin(Θ)-y*cos(Θ)
  11. z'=z
  12.  
  13. So 3 rotations around 3 axes should be 12 MULS????? No, if you are an
  14. intelligent coder! You can develop you formulaes and get something like:
  15.  
  16. x'=x*xvx+y*xvy+z*xvz+xv0
  17. y'=x*yvx+y*yvy+z*yvz+yv0
  18. z'=x*zvx+y*zvy+z*zvz+zv0
  19.  
  20. where x',y',z' are the 3 coordinates of you point after the rotations and
  21. xvx,yvx,zvx,.... are some coefficients depending of the 3 rotation angles.
  22. So you first calculate these coefficients at the beginning of your frame
  23. code, then you have 9 MULs only for each dot! This is called the 3D matrix
  24. method for rotating the dots, but don't panic, you don't have to know any-
  25. thing about matrixes to use it! Another advantage of this method is that if
  26. you decide to use 123 rotations instead of 3, or to do some gelly vectors
  27. or whatever else, your formula remains the same, only the coefficients are
  28. different! There is also some other methods for rotating the dots, but this
  29. is the most precise one. Then you have the problem of calculating this 3D
  30. matrix, i.e. calculating the 12 coefficients. Well, each of them are a sum
  31. of products of sines and cosines of the different rotation angles, for ex.:
  32.  
  33. yvy=sin(a)*cos(b)*sin(c)-cos(a)*cos(c)
  34.  
  35. It should be interesting to eliminate the MULs instructs in this formula!
  36. Well, it is quite possible: This is what is called linearization in mathe-
  37. matical therms. For example you have:
  38.  
  39. cos(a)*cos(b)=(cos(a+b)+cos(a-b))/2
  40.  
  41. so, if you use this formula and some others like this, you can write yvy
  42. (and the others coefficients) as a sum of sines and cosines, which elimi-
  43. nates the MULs. (evidently you just get the sines and cosines in a table)
  44. There are thousands of other mathematical tricks but I can't explain them
  45. all, let's just say that if you are imaginative enough you can usually boost
  46. the speed of your code by 50% using this kind of tricks. If someone knows
  47. some very technical tips, I would be pleased to hear about.... for example
  48. math tricks for SpaceCode or SuperComplex 3D or something like that....
  49. Yes Mr.H. I'm talking to you.....
  50.  
  51. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  52. Ripped from Imphobia Issue #7 by Dr. ZiXuS / TRiNiTY
  53. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  54.