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




On May 8, 2008, at 12:41 PM, Jocelyn Houle wrote:

I usually write a small class (or struct, same difference) such as:
 struct MyPoint
 {
   float x;
   float y;
 };

To loop by index, I redefine the operator[] in C++ and/or write a small ptr() method return the address of the first member.

Beyond the [] operator, it's highly convenient to have operators like + * etc defined and keeping the actual vector components private. That way vector math is faster to type and easier to read. Also, it gives you the option to do your vector math using SSE/AltiVec should it become desirable at some point. Or you can easily switch it to fixed- point or double precision math while still being able to provide a GFloat accessor.


-Stefan
_______________________________________________
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>)



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.