• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Clunky API
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Clunky API


  • Subject: Re: Clunky API
  • From: Peter Ammon <email@hidden>
  • Date: Thu, 20 Sep 2001 10:28:42 -0400

On Thursday, September 20, 2001, at 08:42 AM, Rob Rix wrote:

Greetings,

In a framework I've been developing, I have a vector class. This class is used for a variety of things throughout the framework, one of them being OpenGL.

My vector class has the normal cartesian accessor methods: -x, -setX:, et cetera. Problem is, using these feels sort of clunky, for a couple of reasons:

1) when using OpenGL's glVertex3d (I may change to floats, it depends on my final requirements), I have to use [vector x], [vector y], [vector z]. Typing that out is a bit of a pain. To rectify this, I've been considering writing a wrapper function which takes a vector and just calling it instead.

2) for one call of glVertex3D, three message calls are sent. There are a couple of instances where I can cache these values to improve performance,
but not many.
Now, I'm not writing this for use in games or anything, so I don't need ultra-super-duper-mega-performance or anything like that. But three message calls for every drawn vertex, when there are potentially quite a large number of vertices drawn, is quite a lot.

So, what I'm wondering is the following:
1) can anybody think of a more elegant solution to this than the standard messaging? I've been considering reducing my vector class to a struct and a bunch of functions, but this is _not_ a very nice solution for me, as it removes all the object-oriented gains I get, and reduces its ability to integrate with the rest of my framework.
2) would this be considered an acceptable case to use the @public directive so that you could use vector.x, et cetera, and avoid both the messaging and a wee bit of the clunkiness? It's not elegant, certainly, but would it be generally considered apropos?

Thanks for any help in my conundrum,

- -- Rob


Why not use the vector form of the glVertex calls?

In your Vector class, create a method like

- (double*)vertexArray {
static double vertices[3];
vertices[0]=myXCoordinate;
vertices[1]=myYCoordinate;
vertices[2]=myZCoordinate;
return vertices;
}

Then you can call it like glVertex3dv([vector vertices]);

(Alternatively, just store the vertices as an array in your Vector object and return that array.)

-Peter


References: 
 >Clunky API (From: Rob Rix <email@hidden>)

  • Prev by Date: Re: Aqua Interface Guidelines & Close Window location ?
  • Next by Date: Re: Save To?
  • Previous by thread: Clunky API
  • Next by thread: Re: Clunky API
  • Index(es):
    • Date
    • Thread