Re: cocoa-dev digest, Vol 1 #541 - 16 msgs
Re: cocoa-dev digest, Vol 1 #541 - 16 msgs
- Subject: Re: cocoa-dev digest, Vol 1 #541 - 16 msgs
- From: David Trevas <email@hidden>
- Date: Fri, 7 Sep 2001 22:35:57 -0500
>
But, in addition, I want to regularly access the data in a convenient
>
and
>
easy format. For example, when I'm done processing all my vectors, it's
>
REALLY nice to be able to cast them to an array of floats and feed that
>
straight to OpenGL instead of going through a lengthy conversion
>
process.
>
Oh, well that's a horse of a different color! With OpenGL, you will
want your Vector structure to be a storage class since OpenGL has a lot
of nice functions for doing transformations with vectors so you wouldn't
need to "roll your own".
>
Dogmatically speaking I could see why that's bad, but in the case of a
>
vector class, exposing those values makes a lot of sense to me. In the
>
case of a 3-element vector, the implementation IS the interface, for all
>
intents and purpose.
It depends on how much you want to stay object-oriented and retain the
Cocoa spirit. If you are interfacing with a C API (OpenGL), you will
probably want to depart from that kind of programming. That is not to
say that it is bad programming nor that Cocoa (or OOP, for that matter)
is always the best, fastest and most efficient style out there.
>
>
> Here's a method for the Vec3f class that does scalar multiplication and
>
> the code would read:
>
>
>
> vector2 = [vector1 multipliedByScalar: 3.453];
>
>
>
> That's almost starting to look like plain English!
>
>
>
> - (void) multipliedByScalar: (float) factor
>
> {
>
> x *= factor; y *= factor; z *= factor;
>
> }
>
>
Except you're assigning a void return type to a variable ;)
>
Oops, it should have been (float)multipliedByScalar: . Sorry, it was
late!
Dave