home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / graphics / 8085 < prev    next >
Encoding:
Text File  |  1992-07-23  |  2.1 KB  |  65 lines

  1. Newsgroups: comp.graphics
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!po.CWRU.Edu!exk11
  3. From: exk11@po.CWRU.Edu (Erik Kangas)
  4. Subject: Re: Graphics Gems
  5. Message-ID: <1992Jul23.183445.17553@usenet.ins.cwru.edu>
  6. Sender: news@usenet.ins.cwru.edu
  7. Nntp-Posting-Host: cwns1.ins.cwru.edu
  8. Reply-To: exk11@po.CWRU.Edu (Erik Kangas)
  9. Organization: Case Western Reserve University, Cleveland, OH (USA)
  10. References: <8242@amsaa-cleo.brl.mil>  
  11. Date: Thu, 23 Jul 92 18:34:45 GMT
  12. Lines:       52
  13.  
  14.  
  15. In a previous article, neiderer@amsaa-seer.brl.mil (Andrew Neiderer) says:
  16.  
  17. >
  18. >Can anyone tell me why some vector functions, such as 
  19. >
  20. >Vector2 *V2Add(a, b, c)
  21. >Vector2 *a, *b, *c;
  22. >{
  23. >        c->x = a->x+b->x;  c->y = a->y+b->y;
  24. >        return(c);
  25. >        };
  26. >
  27. >return the pointer to the resultant vector.  I would 
  28. >just declare it as void since c already contains the
  29. >answer.  There must be some advantage to doing it this way.
  30. >I looked throughout the Graphics Gems source code, and
  31. >found that this particular function is used, e.g. as
  32. >
  33. >
  34. You can treat it as returning a void - the compiler will just ignore
  35. the return.  It's declared this way so you can use it in other functions.
  36. I'm not familiar with this library, but if some functions were...
  37.  
  38. Vector2 *V2Mult(a,b,c) ...
  39.  
  40. you could implement such composite functions as
  41.  
  42. Vector2 *a,b,c,d;
  43.  
  44. V2Mult(a,V2Mult(b,V2Add(a,b,c),c),d);
  45.  
  46. Which is equivalent to
  47.  
  48. d = a * (b * (a+b)) or
  49. d = a * (c = (b*(c=a+b)))
  50.  
  51. This programming style simply allows more flexibillity in implementing
  52. the library functions.
  53.  
  54. Note: these functions could be re-written easily in c++ so that you
  55. could actually ise the "*", "+", "=" and other operator signs to
  56. operate on you're vectors and or matricies.  (I have done such a thing
  57. to a small extent for 3d transformation and scaling points and matricies.)
  58.  
  59.  
  60. -- 
  61. Erik Kangas  
  62. Physics/Math/CompE         "I lift up mine eyes unto the hills whence  
  63. Phone 754-2316              cometh my strength"  Psalms                
  64. Zeta Psi #304               Whereof we cannot speak, Thereof we must be silent.
  65.