home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!sgigate!odin!fido!blivet.houst.sgi.com!reuel
- From: reuel@blivet.houst.sgi.com (Reuel Nash)
- Newsgroups: comp.graphics
- Subject: Re: Graphics Gems
- Message-ID: <nlkgvn4@fido.asd.sgi.com>
- Date: 23 Jul 92 16:26:38 GMT
- References: <8242@amsaa-cleo.brl.mil>
- Sender: news@fido.asd.sgi.com (Usenet News Admin)
- Reply-To: reuel@blivet.houst.sgi.com (Reuel Nash)
- Organization: Silicon Graphics Inc., Mountain View, CA
- Lines: 53
-
-
- In article <8242@amsaa-cleo.brl.mil>, neiderer@amsaa-seer.brl.mil
- (Andrew Neiderer ) writes:
- |>
- |> Can anyone tell me why some vector functions, such as
- |>
- |> Vector2 *V2Add(a, b, c)
- |> Vector2 *a, *b, *c;
- |> {
- |> c->x = a->x+b->x; c->y = a->y+b->y;
- |> return(c);
- |> };
- |>
- |> return the pointer to the resultant vector. I would
- |> just declare it as void since c already contains the
- |> answer. There must be some advantage to doing it this way.
- |> I looked throughout the Graphics Gems source code, and
- |> found that this particular function is used, e.g. as
- |>
- |> V2Add(&bezCurve[0],V2Scale(&tHat1, dist),&bezCurve[1]);
- |>
- |> Sorry if this appears to be a C question. My reason for
- |> posting here is to get the attention of some graphics
- |> programmer who uses this stuff. Thanks.
-
- The answer is hidden in your own example.
- I'm assuming that V2Scale is:
-
- Vector2 *V2Scale(Vector2 *a, float b)
- {
- a->x *= b;
- a->y *= b;
- return a;
- }
-
-
- If it were declared as:
-
- void V2Scale(Vector2 *a, float b)
-
- you'd have to code the example as:
-
- V2Scale(&tHat1, dist);
- V2Add(&bezCurve[0],&tHat1,&bezCurve[1]);
-
- which is a bit inconvenient. However, coding it this way does make it more
- clear that the argument is modified by the subroutine.
-
-
-
- Reuel Nash Email: reuel@sgi.sgi.com
- "Question Skepticism" Phone: 713-293-9292 (new)
- USMail: Silicon Graphics, 11490 Westheimer Suite 100, Houston, TX 77077
-