Sign in to follow this  
lomateron

SetFloatVector()

Recommended Posts

I crated this

 

ID3D10EffectVectorVariable*         g_pVe = NULL;

 

So I am trying to give a float4 variable called "Ve" in the .fx file a value.

This is the first time i have used a float4 variable. when i use float3 variables I use D3DXVECTOR3 struct like this:

 

g_pVe->SetFloatVector(D3DXVECTOR3(0.0f,0.0f,0.0f,0.0f));

 

There is no D3DXVECTOR4 struct so i did this:

 

vector<float> FloatVct(4);

grd[0]=0.0f;

grd[1]=0.0f;

grd[2]=0.0f;

grd[3]=0.0f;

 

g_pVe->SetFloatVector(&grd[0]);

 

Is this correct?

 

I am asking because I have a bug and I think this could be causing it. The bug is related with the 4th value of the float4 variable.

Edited by lomateron

Share this post


Link to post
Share on other sites

That is how to set a 4-component floating-point vector, yes.

But there is no reason to use a vector<> here; you are wasting a lot of time allocating data that could just as easily be a hard-coded 4-component array on the stack.

 

 

L. Spiro

Share this post


Link to post
Share on other sites
D3DXVECTOR4 exists, here is D3DXVECTOR4 definition:
 
d3dx9math.h:
typedef struct D3DXVECTOR4
{
#ifdef __cplusplus
public:
    D3DXVECTOR4() {};
    D3DXVECTOR4( CONST FLOAT* );
    D3DXVECTOR4( CONST D3DXFLOAT16* );
    D3DXVECTOR4( CONST D3DVECTOR& xyz, FLOAT w );
    D3DXVECTOR4( FLOAT x, FLOAT y, FLOAT z, FLOAT w );

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

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

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

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

    friend D3DXVECTOR4 operator * ( FLOAT, CONST D3DXVECTOR4& );

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

public:
#endif //__cplusplus
    FLOAT x, y, z, w;
} D3DXVECTOR4, *LPD3DXVECTOR4;

Using vector for doing that is not wise, you can use D3DXVECTOR4 or make your own FLOAT4 class.

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