Jump to content
  • Advertisement
Sign in to follow this  
onnel

Mapping between D3DFVF_* and struct

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I define my vertix type as: #define D3DFVF_VERTEX (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 | D3DFVF_TEX2) But how does D3D know how to map the variables to those in my struct:
struct D3DVERTEX
{
    D3DXVECTOR3 p;
    D3DXVECTOR3 n;
    FLOAT       tu;
	FLOAT		tv;

    FLOAT       tu1;
	FLOAT		tv1;

	D3DVERTEX() {};
	D3DVERTEX(D3DXVECTOR3& v1,D3DXVECTOR3& v2 ,FLOAT f1, FLOAT f2, FLOAT f21, FLOAT f22) {
		p = v1;
		n = v2;
		tu = f1;
		tv = f2;
		tu1 = f21;
		tv1 = f22;
	};
};


For example that n = normals and p = x,y,z? Sorry for the dumb question! Onnel

Share this post


Link to post
Share on other sites
Advertisement
The order of the various elements of a vertex is fixed for FVF. The size of each type is also known so one can simply calculate. For example:

DWORD dwFVF = D3DFVF_POSITION | D3DFVF_NORMAL;

// Begin at beginning of struct
offset = 0

// 1. Check if there are vertices
if ( dwFVF contains D3DFVF_POSITION )
- positions are at offset from the start of the struct
- increase offset by 3*sizeof(float)

// 2. Check if there are normals
if ( dwFVF contains D3DFVF_NORMAL )
- normals are at current offset
- increae offset by 3*sizeof(float)

...

// 28. Check if there are binormals
if ( ... )
- binormals are at current offset
- increase offset by 3*sizeof(float)


Et cetera. Greetz,

Illco

PS: order is for example purposes only

Share this post


Link to post
Share on other sites
Thanks! Is the order based on the DWORD?

So:

DWORD dwFVF = D3DFVF_POSITION | D3DFVF_NORMAL;

Would need a struct:


struct D3DVERTEX
{
D3DXVECTOR3 p;
D3DXVECTOR3 n;
};



Would it mix up the values if it were defined:


struct D3DVERTEX
{
D3DXVECTOR3 n;
D3DXVECTOR3 p;
};



Thanks. this is probably all really dumb, but I'd like to make sure I understand the relationship correctly.

Onnel

Share this post


Link to post
Share on other sites
Yes that would mix up:

struct D3DVERTEX
{
D3DXVECTOR3 n;
D3DXVECTOR3 p;
};

Because the deal is that positions come before normals. See the SDK documentation for the precise order.

Greetz,

Illco

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!