maybe will share some piece of code ..
DX9 fixed function c/c++ : other flavors will be similar....
void Zclearscreen(int r,int g,int b)
{
Zd3d_device_ptr->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(r,g,b),1.0f,0);
}
// set parameters for a light
void Zsetlite(DWORD liteID,float x,float y,float z,float brightness)
{
D3DLIGHT9 light;
ZeroMemory(&light, sizeof(light));
light.Type=D3DLIGHT_DIRECTIONAL;
light.Diffuse=D3DXCOLOR(brightness,brightness,brightness,1.0f);
light.Ambient=D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
light.Specular=D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
light.Direction.x=x;
light.Direction.y=y;
light.Direction.z=z;
Zd3d_device_ptr->SetLight(liteID, &light);
}
// turn a light on/off
void Zlite(DWORD liteID,int onoff)
{
if (onoff==1) Zd3d_device_ptr->LightEnable(liteID,TRUE);
else Zd3d_device_ptr->LightEnable(liteID,FALSE);
}
// set camera position and orientation
void Zsetcam(float x,float y,float z,float rx,float ry,float rz)
{
D3DXMATRIX m;
// save cam location for when we sort meshes for drawing based on range to cam
Zcamx=x;
Zcamy=y;
Zcamz=z;
Zcamxr=rx;
Zcamyr=ry;
Zcamzr=rz;
D3DXMatrixTranslation(&ZmView,-x,-y,-z);
D3DXMatrixRotationZ(&m,-rz);
D3DXMatrixMultiply(&ZmView,&ZmView,&m);
D3DXMatrixRotationY(&m,-ry);
D3DXMatrixMultiply(&ZmView,&ZmView,&m);
D3DXMatrixRotationX(&m,-rx);
D3DXMatrixMultiply(&ZmView,&ZmView,&m);
Zd3d_device_ptr->SetTransform(D3DTS_VIEW,&ZmView);
// std transform order: scale, xrot, yrot, zrot, translate.
// inv transform order: untranslate, -zrot, -yrot, -xrot, unscale.
}
// set camera position and orientation using rot matrix
void Zsetcam2(float x,float y,float z,D3DXMATRIX *m)
{
D3DXMATRIX m2;
// save cam location for when we sort meshes for drawing based on range to cam
Zcamx=x;
Zcamy=y;
Zcamz=z;
m2=*m; // preform inverse transform on a copy of m so we dont change the plane's rot matrix.
D3DXMatrixTranslation(&ZmView,-x,-y,-z);
//D3DXMatrixInverse(&m2,NULL,&m2);
//D3DXMatrixTranspose(&m2,&m2);
D3DXMatrixMultiply(&ZmView,&ZmView,&m2);
Zd3d_device_ptr->SetTransform(D3DTS_VIEW,&ZmView);
// std transform order: scale, xrot, yrot, zrot, translate.
// inv transform order: untranslate, -zrot, -yrot, -xrot, unscale.
}
for drawing, i get a little fancy. i have a struct called a Zdrawinfo. it has all the info to draw a mesh or model: position, orientation, cull, alphatest, clamp, materialID, meshID, textureID, modelID, animationID, etc. i fill in the fields in a Zdrawinfo, then either send it off to a list for later drawing (ordered on texture), or call Zdrawimmediate(), which sets the approprite states (via a state manager to eliminate unnecessary state changes) and calls DrawIndexedPrimitive().