• 12
• 11
• 9
• 10
• 13

# initilise a D3DXVECTOR

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

## Recommended Posts

.h file
D3DXVECTOR3 rotWorld;

.cpp file
rotWorld.x = 0;
rotWorld.y = 0;
rotWorld.z = 0;

is there a simple way to set all componants of D3DXVECTOR to zero

##### Share on other sites
My vector class' contain static member variables called 'Zero' so I can copy construct/assign 0 to all components of the vector (without having to create a temporary). Could also pass it to a function if you really wanted, meh.

You can define a constant such as the following:
const D3DXVECTOR3 D3DXZeroVec3(0, 0, 0);// ... and then maybe ...D3DXVECTOR3 rotWorld = D3DXZeroVec3;// .. but whats wrong with just ...D3DXVECTOR3 rotWorld(0.0f, 0.0f, 0.0f); // constructor ?

maybe that would help, I donno..

PS: This method comes in particularly handy for matrices IMO, in this way you can define the special 'Identity' and 'Zero' matrices and. Looks nicer than a function call, virtually the only difference.

##### Share on other sites
when initilizing variables inside of a class you should use an initilizer list attached to the constructer

MyClass::MyClass() : randomD3DVec(0.0f,0.0f,0.0f), randomInt(0), randomFloat(0.0f){}

This is the appropriate way to do it. It has to do with variables in a class being created earlier than some other class construction, so its better to specify them to be initilized on their creation rather than creating them then assigning values to them.

D3DXVECTOR3 Position(0,0,0);//orD3DXVECTOR3 Position = D3DXVECTOR3(0,0,0);