Jump to content
  • Advertisement
Sign in to follow this  
GlitchCog

Structs or Classes to Represent Coordinates

This topic is 2604 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

typedef struct vector2D
{
float x;
float y;
} vector2D_t;

// OR

class Vector2D
{
private:
public:
Vector2D(float x, float y);
float x;
float y;
};


Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Ah, I see. Even down to the member functions apparently, which I didn't know structs could also have.

Question withdrawn. Sorry.

Share this post


Link to post
Share on other sites
Just to add, structs in C++ can be defined in the same way as classes:

struct Vector2D
{
...

};


So no need for the typedef.

Share this post


Link to post
Share on other sites
you might be best using directx D3DXVECTOR2 for this , cause all the operators are overloaded, makeing maths so mauch easyer

Share this post


Link to post
Share on other sites

you might be best using directx D3DXVECTOR2 for this , cause all the operators are overloaded, makeing maths so mauch easyer

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
If the OP is targetting window then they would be better off using the newer XNA Math library (which is unrelated to the XNA C# library) anyway.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!