Sign in to follow this  
GlitchCog

Structs or Classes to Represent Coordinates

Recommended Posts

GlitchCog    122
I'd be interested in hearing anyone's opinion on the pros and cons of representing coordinates (or more generally any vector) either as a struct or as a class in C++. It's such a fundamental data type for game programming, so I thought some people might have ideas or experiences they could share regarding having used one or the other and what difference it made in a game engine for ease of coding and/or performance. Is there any consensus on whether one is definitively better, or does it just boil down to personal preference?

[code]typedef struct vector2D
{
float x;
float y;
} vector2D_t;

// OR

class Vector2D
{
private:
public:
Vector2D(float x, float y);
float x;
float y;
};[/code]

Thanks.

Share this post


Link to post
Share on other sites
jyk    2094
[quote name='thedodgeruk' timestamp='1307289511' post='4819781']
you might be best using directx D3DXVECTOR2 for this , cause all the operators are overloaded, makeing maths so mauch easyer
[/quote]
What if the OP isn't using DirectX/Direct3D, or is targeting platforms that don't support it?

(I didn't see anything in the OP's posts specifying what APIs are being used or what platforms are being targeted.)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this