D3D Points shared memory for normal vector.

Well since nobody answered before, i'll retype my question:

How can i create a FVF structure where the normal vector is allocated to the exact same memory location, so their values are the same, except they save space.

1
2
3
4
5
struct point3D
{
	float	          x,y,z;
	D3DVECTOR	          Normal;
};

Please somebody help me.

To reiterate that:

I need to create a group of point3D points, the variable Normal must have the exact same value for all the points, so to save space i want it to be allocated to the same memory location.
Last edited on
Bump because its been like um 9 hours.
For this, I would recommend that, on your data level, the objects which share the same normal, share a pointer to the normal.

Judging from a cursory glance at this problem (and Direct3D), it would seem that the FVF structure cannot contain pointers, so you would have to put your vertex data into a vertex buffer on the fly.

e.g.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
struct point3D
{
     float x,y,z;
     D3DVECTOR Normal;
};

#define D3DFVF_POINT3D (D3DFVF_XYZ  |  D3DFVF_NORMAL)

class myObject
{
     public:
          float x;
          float y;
          float z;
          D3DVECTOR* normal;

          myObject(float _x, float _y, float _z, D3DVECTOR* _normal) : x(_x), y(_y), z(_z), normal(_normal)
          {
          }

          point3D getPoint3DStructOnTheFly()
          {
                 point3D p3DOnTheFly = {x, y, z, *normal};
                 return p3DOnTheFly;
          }
};


int main()
{
     D3DVECTOR* sharedNormal = new D3DVECTOR;
     sharedNormal->x = 1.0; //I assume this is correct. I haven't done Direct3D
     sharedNormal->y = 0.0; //I assume this is correct. I haven't done Direct3D
     sharedNormal->z = 0.0; //I assume this is correct. I haven't done Direct3D

     myObject obj1(1.0, 2.0, 3.0, sharedNormal);
     myObject obj2(4.0, 5.0, 6.0, sharedNormal);
     myObject obj3(7.0, 8.0, 9.0, sharedNormal);

     //put initialization for your gD3dDevice here
     gD3dDevice->SetFVF(D3DFVF_POINT3D);
   
     LPDIRECT3DVERTEXBUFFER9 vb;
    
     HRESULT hr=gD3dDevice->CreateVertexBuffer( 3*sizeof(point3D),
                                D3DUSAGE_WRITEONLY, D3DFVF_POINT3D,
                                D3DPOOL_MANAGED, &vb, NULL );

     point3D* pVertices;
     vb->Lock( 0, 0, (void**)&pVertices, 0 ));

     pVertices[0] = obj1.getPoint3DStructOnTheFly();
     pVertices[1] = obj2.getPoint3DStructOnTheFly();
     pVertices[2] = obj3.getPoint3DStructOnTheFly();

     vb->Unlock();
     delete sharedNormal;
}


Bump because its been like um 9 hours.

What did you expect? This is a C++ forum, not games or graphics. You'll have better luck having your question answered on a DirectX/game-specific forum such as gamedev.net.
Last edited on
Thankyou! but yeah your point is taken. thankyou.
Topic archived. No new replies allowed.