home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / graphics / 8077 < prev    next >
Encoding:
Internet Message Format  |  1992-07-23  |  1.8 KB

  1. Path: sparky!uunet!olivea!sgigate!odin!fido!blivet.houst.sgi.com!reuel
  2. From: reuel@blivet.houst.sgi.com (Reuel Nash)
  3. Newsgroups: comp.graphics
  4. Subject: Re: Graphics Gems
  5. Message-ID: <nlkgvn4@fido.asd.sgi.com>
  6. Date: 23 Jul 92 16:26:38 GMT
  7. References: <8242@amsaa-cleo.brl.mil>
  8. Sender: news@fido.asd.sgi.com (Usenet News Admin)
  9. Reply-To: reuel@blivet.houst.sgi.com (Reuel Nash)
  10. Organization: Silicon Graphics Inc., Mountain View, CA
  11. Lines: 53
  12.  
  13.  
  14. In article <8242@amsaa-cleo.brl.mil>, neiderer@amsaa-seer.brl.mil
  15. (Andrew Neiderer ) writes:
  16. |> 
  17. |> Can anyone tell me why some vector functions, such as 
  18. |> 
  19. |> Vector2 *V2Add(a, b, c)
  20. |> Vector2 *a, *b, *c;
  21. |> {
  22. |>         c->x = a->x+b->x;  c->y = a->y+b->y;
  23. |>         return(c);
  24. |>         };
  25. |> 
  26. |> return the pointer to the resultant vector.  I would 
  27. |> just declare it as void since c already contains the
  28. |> answer.  There must be some advantage to doing it this way.
  29. |> I looked throughout the Graphics Gems source code, and
  30. |> found that this particular function is used, e.g. as
  31. |> 
  32. |> V2Add(&bezCurve[0],V2Scale(&tHat1, dist),&bezCurve[1]);
  33. |> 
  34. |> Sorry if this appears to be a C question.  My reason for 
  35. |> posting here is to get the attention of some graphics 
  36. |> programmer who uses this stuff.  Thanks.
  37.  
  38. The answer is hidden in your own example.
  39. I'm assuming that V2Scale is:
  40.  
  41. Vector2 *V2Scale(Vector2 *a, float b)
  42. {
  43.     a->x *= b;
  44.     a->y *= b;
  45.     return a;
  46. }
  47.  
  48.  
  49. If it were declared as:
  50.  
  51. void V2Scale(Vector2 *a, float b)
  52.  
  53. you'd have to code the example as:
  54.  
  55. V2Scale(&tHat1, dist);
  56. V2Add(&bezCurve[0],&tHat1,&bezCurve[1]);
  57.  
  58. which is a bit inconvenient. However, coding it this way does make it more 
  59. clear that the argument is modified by the subroutine.
  60.  
  61.  
  62.  
  63. Reuel Nash                Email:    reuel@sgi.sgi.com  
  64. "Question Skepticism"            Phone:    713-293-9292 (new)
  65. USMail:     Silicon Graphics, 11490 Westheimer Suite 100, Houston, TX  77077
  66.