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;
}
|