Got a little bored last night and decided to refresh myself on some of the internal 3D functions. So, I coded you a "dbMakeObjectGroundPlane" function.
#include <DarkGDK.h>
bool CreateNewObject ( int iID, LPSTR pName );
bool SetNewObjectFinalProperties( int iID, float fRadius );
void SetTexture ( int iID, int iImage );
bool SetupMeshFVFData ( sMesh* pMesh, DWORD dwFVF, DWORD dwVertexCount, DWORD dwIndexCount );
bool SetupStandardVertex ( DWORD dwFVF, BYTE* pVertex, int iOffset, float x, float y, float z, float nx, float ny, float nz, DWORD dwDiffuseColour, float tu, float tv );
void dbMakeObjectGroundPlane ( int iID, float fWidth, float fDepth );
void dbMakeObject3DAxes ( int iID, float fLength, DWORD dwColourX, DWORD dwColourY, DWORD dwColourZ );
void DarkGDK()
{
dbSetWindowTitle("Dark GDK - Internal 3D-Functions Demo");
dbSyncOn();
dbSyncRate(60);
dbBackdropOn();
dbColorBackdrop(0);
dbAutoCamOff();
dbPositionCamera(20.0f, 20.0f, -50.0f);
dbPointCamera(0.0f, 0.0f, 0.0f);
dbMakeObjectGroundPlane(1, 10.0f, 10.0f);
dbSetObjectCull(1, 1);
dbScaleObject(1, 200.0f, 100.0f, 200.0f);
dbMakeObject3DAxes(2, 1000.0f, 0xFF0000FF, 0xFFFF0000, 0xFF00FF00);
while (LoopGDK())
{
dbPitchObjectDown(1, (float)dbUpKey()-(float)dbDownKey());
dbSync();
}
return;
}
void dbMakeObjectGroundPlane(int iID, float fWidth, float fDepth)
{
DWORD dwVertexCount;
DWORD dwIndexCount;
sObject* pObject;
sFrame* pFrame;
sMesh* pMesh;
if (!CreateNewObject(iID, "Ground"))
return;
fWidth /= 2.0f;
fDepth /= 2.0f;
dwVertexCount = 4;
dwIndexCount = 6;
pObject = dbGetObject(iID);
pFrame = pObject->pFrame;
pMesh = pObject->pFrame->pMesh;
SetupMeshFVFData(pMesh, D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1, dwVertexCount, dwIndexCount);
SetupStandardVertex(pMesh->dwFVF, pMesh->pVertexData, 0, -fWidth, 0.0f, fDepth, 0.0f, 1.0f, 0.0f, D3DCOLOR_ARGB(255, 255, 255, 255), 0.0f, 0.0f);
SetupStandardVertex(pMesh->dwFVF, pMesh->pVertexData, 1, fWidth, 0.0f, fDepth, 0.0f, 1.0f, 0.0f, D3DCOLOR_ARGB(255, 255, 255, 255), 1.0f, 0.0f);
SetupStandardVertex(pMesh->dwFVF, pMesh->pVertexData, 2, -fWidth, 0.0f, -fDepth, 0.0f, 1.0f, 0.0f, D3DCOLOR_ARGB(255, 255, 255, 255), 0.0f, 1.0f);
SetupStandardVertex(pMesh->dwFVF, pMesh->pVertexData, 3, fWidth, 0.0f, -fDepth, 0.0f, 1.0f, 0.0f, D3DCOLOR_ARGB(255, 255, 255, 255), 1.0f, 1.0f);
pMesh->pIndices[0] = 0;
pMesh->pIndices[1] = 1;
pMesh->pIndices[2] = 2;
pMesh->pIndices[3] = 1;
pMesh->pIndices[4] = 3;
pMesh->pIndices[5] = 2;
pMesh->iPrimitiveType = D3DPT_TRIANGLELIST;
pMesh->iDrawVertexCount = pMesh->dwVertexCount;
pMesh->iDrawPrimitives = 2;
SetNewObjectFinalProperties(iID, 0.0f);
SetTexture(iID, 0);
}
void dbMakeObject3DAxes(int iID, float fLength, DWORD dwColourX, DWORD dwColourY, DWORD dwColourZ)
{
DWORD dwVertexCount;
DWORD dwIndexCount;
sOffsetMap offsetMap;
sObject* pObject;
sFrame* pFrame;
sMesh* pMesh;
if (!CreateNewObject(iID, "Axes"))
return;
fLength /= 2.0f;
dwVertexCount = 6;
dwIndexCount = 0;
pObject = dbGetObject(iID);
pFrame = pObject->pFrame;
pMesh = pObject->pFrame->pMesh;
SetupMeshFVFData(pMesh, D3DFVF_XYZ | D3DFVF_DIFFUSE, dwVertexCount, dwIndexCount);
GetFVFValueOffsetMap(pMesh->dwFVF, &offsetMap);
*((float*) pMesh->pVertexData + offsetMap.dwX + (offsetMap.dwSize * 0)) = -fLength;
*((float*) pMesh->pVertexData + offsetMap.dwY + (offsetMap.dwSize * 0)) = 0.0f;
*((float*) pMesh->pVertexData + offsetMap.dwZ + (offsetMap.dwSize * 0)) = 0.0f;
*((DWORD*) pMesh->pVertexData + offsetMap.dwDiffuse + (offsetMap.dwSize * 0)) = dwColourX;
*((float*) pMesh->pVertexData + offsetMap.dwX + (offsetMap.dwSize * 1)) = fLength;
*((float*) pMesh->pVertexData + offsetMap.dwY + (offsetMap.dwSize * 1)) = 0.0f;
*((float*) pMesh->pVertexData + offsetMap.dwZ + (offsetMap.dwSize * 1)) = 0.0f;
*((DWORD*) pMesh->pVertexData + offsetMap.dwDiffuse + (offsetMap.dwSize * 1)) = dwColourX;
*((float*) pMesh->pVertexData + offsetMap.dwX + (offsetMap.dwSize * 2)) = 0.0f;
*((float*) pMesh->pVertexData + offsetMap.dwY + (offsetMap.dwSize * 2)) = -fLength;
*((float*) pMesh->pVertexData + offsetMap.dwZ + (offsetMap.dwSize * 2)) = 0.0f;
*((DWORD*) pMesh->pVertexData + offsetMap.dwDiffuse + (offsetMap.dwSize * 2)) = dwColourY;
*((float*) pMesh->pVertexData + offsetMap.dwX + (offsetMap.dwSize * 3)) = 0.0f;
*((float*) pMesh->pVertexData + offsetMap.dwY + (offsetMap.dwSize * 3)) = fLength;
*((float*) pMesh->pVertexData + offsetMap.dwZ + (offsetMap.dwSize * 3)) = 0.0f;
*((DWORD*) pMesh->pVertexData + offsetMap.dwDiffuse + (offsetMap.dwSize * 3)) = dwColourY;
*((float*) pMesh->pVertexData + offsetMap.dwX + (offsetMap.dwSize * 4)) = 0.0f;
*((float*) pMesh->pVertexData + offsetMap.dwY + (offsetMap.dwSize * 4)) = 0.0f;
*((float*) pMesh->pVertexData + offsetMap.dwZ + (offsetMap.dwSize * 4)) = -fLength;
*((DWORD*) pMesh->pVertexData + offsetMap.dwDiffuse + (offsetMap.dwSize * 4)) = dwColourZ;
*((float*) pMesh->pVertexData + offsetMap.dwX + (offsetMap.dwSize * 5)) = 0.0f;
*((float*) pMesh->pVertexData + offsetMap.dwY + (offsetMap.dwSize * 5)) = 0.0f;
*((float*) pMesh->pVertexData + offsetMap.dwZ + (offsetMap.dwSize * 5)) = fLength;
*((DWORD*) pMesh->pVertexData + offsetMap.dwDiffuse + (offsetMap.dwSize * 5)) = dwColourZ;
pMesh->bLight = false;
pMesh->bAmbient = false;
pMesh->iPrimitiveType = D3DPT_LINELIST;
pMesh->iDrawVertexCount = pMesh->dwVertexCount;
pMesh->iDrawPrimitives = 3;
SetNewObjectFinalProperties(iID, 0.0f);
SetTexture(iID, 0);
}
From appearance I could tell there was something wrong with the "dbmakeObjectPlane" function. That’s the reason I added the orientation parameter to the variant function in the update (which is available in DBPro). After looking at the source I see the vertex winding is clockwise, which is correct. But the normal’s are pointing into the front facing direction instead of away, as they should. The uv coordinates are off too. I suppose if your looking at the back face it will look correct. But, if you set the object culling flag the object will disappear. Does anybody know of any possible reason it would be coded this way?