Sign in to follow this  
ctaclas

d3dxvector3 question

Recommended Posts

ctaclas    122
hi, i've been playing around with setting up the view matrix and stuff, and i noticed it uses a vector type called d3dxvector3. i looked it up on msdn and it appears to be a struct with a couple of overloaded opperators http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/d3dx/structures/d3dxvector3extensions.asp the page i found doesn't even really explain what the operators do, like, do i assume * is just a straight up multiplication, or is it a dot or cross product? it seems like its a pretty bare vector type, should i just make my own vector class with all the stuff i need? thanks

Share this post


Link to post
Share on other sites
DrunkenHyena    805
The D3DX Vector functions are highly optimized. Unless you're doing it as a learning experience I see very little reason to not use what's provided.

As for the overloads, I never use them. They'll just end up calling the D3DXVector* functions anyway.

Share this post


Link to post
Share on other sites
Quote:
should i just make my own vector class with all the stuff i need

Good Lord No! Well, I mean, you could. But most of the time there is no real reason.

I've had the same trouble figuring out those operators, the documentation doesn't seem to mention them much. You could just fiddle around with them for a while, or just use the D3DX math functions.

Share this post


Link to post
Share on other sites
circlesoft    1178
Quote:
Original post by lack o comments
Quote:
should i just make my own vector class with all the stuff i need

Good Lord No! Well, I mean, you could. But most of the time there is no real reason.

I've had the same trouble figuring out those operators, the documentation doesn't seem to mention them much. You could just fiddle around with them for a while, or just use the D3DX math functions.

Just make sure you have a firm understanding of what vectors (and the associated operations, like dot and cross product) actually are, first. The same thing goes for all of the matrix math - sure, D3DX can do it all for you, but you need to know what each function does (and how it does it) to be successful.

It's tought learning an API as tough as D3D if you have no knowledge of linear algebra or graphics theory.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
i have some knowledge of how vectors work, i've taken lots of math classes, and even one in linear algebra. although i've forgotten most of the messy details, i still know what things like dot product and cross product are used for.

my question is does d3dxvector3 have all the functionality built in for whatever vector manipulation i need to do? on msdn is this:


typedef struct D3DXVECTOR3 : public D3DVECTOR {
public:
D3DXVECTOR3() {};
D3DXVECTOR3( CONST FLOAT * );
D3DXVECTOR3( CONST D3DVECTOR& );
D3DXVECTOR3( FLOAT x, FLOAT y, FLOAT z );

// casting
operator FLOAT* ();
operator CONST FLOAT* () const;

// assignment operators
D3DXVECTOR3& operator += ( CONST D3DXVECTOR3& );
D3DXVECTOR3& operator -= ( CONST D3DXVECTOR3& );
D3DXVECTOR3& operator *= ( FLOAT );
D3DXVECTOR3& operator /= ( FLOAT );

// unary operators
D3DXVECTOR3 operator + () const;
D3DXVECTOR3 operator - () const;

// binary operators
D3DXVECTOR3 operator + ( CONST D3DXVECTOR3& ) const;
D3DXVECTOR3 operator - ( CONST D3DXVECTOR3& ) const;
D3DXVECTOR3 operator * ( FLOAT ) const;
D3DXVECTOR3 operator / ( FLOAT ) const;

friend D3DXVECTOR3 operator * ( FLOAT, CONST struct D3DXVECTOR3& );

BOOL operator == ( CONST D3DXVECTOR3& ) const;
BOOL operator != ( CONST D3DXVECTOR3& ) const;

} D3DXVECTOR3, *LPD3DXVECTOR3;




with no explanation what exactly the operators do.

Share this post


Link to post
Share on other sites
DrunkenHyena    805
Quote:
Original post by Anonymous Poster

my question is does d3dxvector3 have all the functionality built in for whatever vector manipulation i need to do? on msdn is this:

*** Source Snippet Removed ***

with no explanation what exactly the operators do.


Why not just use D3DXVec3Dot() or D3DXVec3Cross()? This way you are explicitly stating what you are doing.

Share this post


Link to post
Share on other sites
ctaclas    122
thanks, thats exactly what i was looking for :)

now that i know where to look, i see all sorts of useful functions there

i got confused because i was reading someone's tutorial on creating a fps style camera in directx. the way they did it was they created their own vector class with their own dot and cross product functions. they used their vector class for everything except at the last second when they set up the view matrix they use the x, y, and z values from their vector class to create an instance of d3dxvector3 to pass the function that sets up the view matrix.

thats why i was wondering how come they didn't use d3dxvector3 for the whole way. when i went to look at the description in msdn of d3dxvector3 i was surprised to see it had no member functions other than some operators, now i see theres a whole package of math functions that manipulate vectors

hopefully i'll be able to improve on what i'm learning from the tutorial with this information, because the program in the tutorial is slow as hell :)

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