home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.graphics
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!po.CWRU.Edu!exk11
- From: exk11@po.CWRU.Edu (Erik Kangas)
- Subject: Re: Graphics Gems
- Message-ID: <1992Jul23.183445.17553@usenet.ins.cwru.edu>
- Sender: news@usenet.ins.cwru.edu
- Nntp-Posting-Host: cwns1.ins.cwru.edu
- Reply-To: exk11@po.CWRU.Edu (Erik Kangas)
- Organization: Case Western Reserve University, Cleveland, OH (USA)
- References: <8242@amsaa-cleo.brl.mil>
- Date: Thu, 23 Jul 92 18:34:45 GMT
- Lines: 52
-
-
- In a previous article, neiderer@amsaa-seer.brl.mil (Andrew Neiderer) says:
-
- >
- >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
- >
- >
- You can treat it as returning a void - the compiler will just ignore
- the return. It's declared this way so you can use it in other functions.
- I'm not familiar with this library, but if some functions were...
-
- Vector2 *V2Mult(a,b,c) ...
-
- you could implement such composite functions as
-
- Vector2 *a,b,c,d;
-
- V2Mult(a,V2Mult(b,V2Add(a,b,c),c),d);
-
- Which is equivalent to
-
- d = a * (b * (a+b)) or
- d = a * (c = (b*(c=a+b)))
-
- This programming style simply allows more flexibillity in implementing
- the library functions.
-
- Note: these functions could be re-written easily in c++ so that you
- could actually ise the "*", "+", "=" and other operator signs to
- operate on you're vectors and or matricies. (I have done such a thing
- to a small extent for 3d transformation and scaling points and matricies.)
-
-
- --
- Erik Kangas
- Physics/Math/CompE "I lift up mine eyes unto the hills whence
- Phone 754-2316 cometh my strength" Psalms
- Zeta Psi #304 Whereof we cannot speak, Thereof we must be silent.
-