Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Structs versus Vectors



Hi Y'all,

I would have said "avoid immediate mode" but I was OOTO. :-) Regarding small batches, um, "avoid small batches". :-) :-)

But it sounds like Richard's problem is more on the math/geometry side than the OGL side.

Our code has three different things going on:

- Our "low level" matrix goo is based on straight arrays, e.g. our CPU-based mult-vector-by-matrix takes a GLdouble[4] and a GLdouble[16] or something very simple; the implication is that there is a logical meaning to all arrays. This hasn't caused us any problems.

- We also have some C++ classes that are more like recVec3, usually aimed at computational-geometry ideas, e.g. we have a plane struct that can do what-side-am-I-on, etc. and it's a struct with stuff inside it. Those tend to be for more abstract usages that don't get fed directly into the sim.

You can bridge that by making the guts of your struct an array, e.g.

struct vec4 {

   // nice C++-like stuff for "math"
   vec4& operator+=(const vec4& rhs);

   // Raw array for when you want that.
   GLdouble xyzw[4];

};

- For drawing we have dedicated classes for groups of stuff that know how to become VBOs, etc. So we don't find ourselves using our point classes to storing any real quantity of data.

cheers
Ben


Richard Somers wrote:
Thanks to everyone for their comments. I have learned a lot. Perhaps I should describe the exact issue I am struggling with.

I have an axis-aligned bounding box which is transformed by the modelview matrix. I need to find a second bounding box which encloses the first but which is unaffected by the modelview matrix or in other words is in another coordinate system.

My axis-aligned bounding box data structure looks like this.

     typedef struct _recVec3 {
         double x,y,z;
     } recVec3;

     typedef struct _recExtent3 {
         recVec3 min;
         recVec3 max;
     } recExtent3;

First I get the modelViewMatrix like this.

     GLfloat m[16];
     glGetFloatv(GL_MODELVIEW_MATRIX, m);

Then I multiply the first bounding box by the modelview matrix. I then check the x, y, and z coordinates of all eight points of the transformed box to see which ones will determine the extents of the second enclosing box.

My first attempt at the code, after correcting the errors, actually worked but was incredibly ugly. That is when I thought if I could just use some looping it would make life easier and that my current bounding box or extent data type is not very friendly to looping. (Some of the prior comments suggest ways as to how to loop through a struct and I will be thinking about that.) I am currently coding in C and Objective-C. My project will eventually have some C++ code but I am not there yet.

Best Regards,
Richard


_______________________________________________ Do not post admin requests to the list. They will be ignored. Mac-opengl mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/mac-opengl/email@hidden

This email sent to email@hidden


-- Scenery Home Page: http://scenery.x-plane.com/ Scenery blog: http://xplanescenery.blogspot.com/ Plugin SDK: http://www.xsquawkbox.net/xpsdk/ X-Plane Wiki: http://wiki.x-plane.com/ Scenery mailing list: email@hidden Developer mailing list: email@hidden _______________________________________________ Do not post admin requests to the list. They will be ignored. Mac-opengl mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/mac-opengl/email@hidden

This email sent to email@hidden
References: 
 >Structs versus Vectors (From: Richard Somers <email@hidden>)
 >Re: Structs versus Vectors (From: "Wesley Smith" <email@hidden>)
 >Re: Structs versus Vectors (From: "Keith Bauer" <email@hidden>)
 >Re: Structs versus Vectors (From: Jocelyn Houle <email@hidden>)
 >Re: Structs versus Vectors (From: Richard Somers <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.