Sign in to follow this  
john_t

D3DXVECTOR3

Recommended Posts

I would like the code I'm writing--the interfaces at least--to be API independent. I can't do this if I'm throwing D3DXVECTOR3 all over the place. I've looked at the D3DXVECTOR3 interface, and I feel like it wouldn't be that hard to implement my own vector class. Is this a terrible idea? One concern a friend of mine brought up when I bounced this idea of of him is that there may be hardware optimization for vector processing that a class like D3DXVECTOR3 exploits? If this is true, then my software implementation would crawl comparatively. What are people's thoughts on this?

Share this post


Link to post
Share on other sites
Latest versions of D3DX have math removed from the headers. Even the simpliest matrix multiplication forces you to use libraries/dlls, as operations are not implemented in dx headers (at least I don't see them as I look through just now).

So you would have to incorporate "d3dx9(d).lib" into your project, and that immediately forces the end user to have "d3dx9_2(5/6/7).dll", which is a pain in the butt.

As for implementing your own math classes, I think it's a good idea, as not understanding the math ideas is usually the main cause of errors/problems in people's graphic code. Another thing, is that I personally don't like D3DX way of doing everything with functions, and prefer the operator overloading, which leads to code that is easier to read.

Share this post


Link to post
Share on other sites
Quote:
Original post by john_t
So, there shouldn't be any inherent problems if I implementing my own vector classes? I think that's what I'll do then.

Nope. At most, your performance won't be as good, since D3DX is optimized by each CPU vendor. You can always look at the D3DX stuff as a reference, and fix some of its annoyances, like deffer pointed out.

Also, the same goes for matrices and if you need them, quaternions.

Share this post


Link to post
Share on other sites
Quote:
I would like the code I'm writing--the interfaces at least--to be API independent. I can't do this if I'm throwing D3DXVECTOR3 all over the place.

You can always wrap it:

#ifdef USE_D3DX_MATH
typedef D3DXVECTOR3 vector3_t;
typedef D3DXQUATERNAION quaternion_t;
// Rest of types
// ...

inline float vector3_length(const vector3_t& vec)
{
return D3DXVec3Length(&vec);
}

// Rest of functions
// ...

#else

class vector3_t
{
// Define your vector with the same interface
};

#endif



Also, I'd use a vendor-supplied math library if I didn't use D3DX - i.e. Intel's or AMD's math library.

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