SetFloatVector()

Started by
2 comments, last by Medo Mex 11 years, 2 months ago

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.

Advertisement

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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

there is a D3DXVECTOR4 or you could use a D3DXCOLOR

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.

This topic is closed to new replies.

Advertisement