Hi there,
Here is the translated Dot3D and Line3D from Cloggy's d3dfunc.dll:
d3dfunc.h :
void InitD3DFunc();
void d3d_line3D ( float x1, float y1, float z1, float x2, float y2, float z2, int nZenable, int g_nRed, int g_nGreen, int g_nBlue, int g_nAlpha);
void d3d_dot3D ( float x1, float y1, float z1, int nZenable, int g_nRed, int g_nGreen, int g_nBlue, int g_nAlpha);
void d3d_SetView ( int nLeft, int nTop, int nRight, int nBottom);
3d3func.cpp :
#include "DarkSDK.h"
#include "d3d9.h"
//for 3d functions
#define D3DFVF_MY_VERTEX ( D3DFVF_XYZ | D3DFVF_DIFFUSE )
struct Vertex // D3DFVF_MY_VERTEX
{
float x, y, z; // Position of vertex in 3D space
DWORD color; // Color of vertex
};
IDirect3DDevice9* g_pd3dDevice = NULL;
// ONLY NEEDED FOR 3D FUNCTIONS
D3DVIEWPORT9 g_pViewPort;
void InitD3DFunc() {
g_pd3dDevice = dbGetDirect3DDevice();
// Get default viewport (FULLSCREEN SIZE). This means you only need to call
// Set View command from DBP if you change the screen size
// FOR 3D FUNCTIONS
g_pd3dDevice->GetViewport( &g_pViewPort );
}
void d3d_SetView ( int nLeft, int nTop, int nRight, int nBottom)
{
g_pViewPort.X = nLeft;
g_pViewPort.Y = nTop;
g_pViewPort.Width = nRight-nLeft;
g_pViewPort.Height = nBottom-nTop;
g_pViewPort.MinZ = 0.0f;
g_pViewPort.MaxZ = 1.0f;
}
void d3d_line3D ( float x1, float y1, float z1, float x2, float y2, float z2, int nZenable, int g_nRed, int g_nGreen, int g_nBlue, int g_nAlpha)
{
Vertex *pVertices = NULL;
Vertex g_lineList[] =
{
{-1.0f, 0.0f, 0.0f, D3DCOLOR_ARGB( 255, 0, 0, 255 ) }, // Line #1
{-1.0f, 0.0f, 0.0f, D3DCOLOR_ARGB( 255, 0, 0, 255 ) }, // Line #1
};
g_lineList[0].x=x1;
g_lineList[0].y=y1;
g_lineList[0].z=z1;
g_lineList[0].color=D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue );
g_lineList[1].x=x2;
g_lineList[1].y=y2;
g_lineList[1].z=z2;
g_lineList[1].color=D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue );
//Translate the line into the current world space
D3DXMATRIX matWorld;
D3DXMatrixIdentity( &matWorld );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
g_pd3dDevice->SetTexture(0,NULL);
g_pd3dDevice->SetTexture(1,NULL);
g_pd3dDevice->SetVertexShader(NULL);
g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue ) );
g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, nZenable );
// g_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, nZenable );
// g_pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
g_pd3dDevice->SetViewport( &g_pViewPort );
g_pd3dDevice->SetFVF( D3DFVF_MY_VERTEX );
g_pd3dDevice->DrawPrimitiveUP(D3DPT_LINELIST,1,g_lineList,sizeof(Vertex));
g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0 );
}
void d3d_dot3D ( float x1, float y1, float z1, int nZenable, int g_nRed, int g_nGreen, int g_nBlue, int g_nAlpha)
{
// LPDIRECT3DVERTEXBUFFER9 g_pLineList_VB = NULL;
Vertex *pVertices = NULL;
Vertex g_pointList[] =
{
{-1.0f, 0.0f, 0.0f, D3DCOLOR_ARGB( 255, 0, 0, 255 ) }, // Line #1
};
g_pointList[0].x=x1;
g_pointList[0].y=y1;
g_pointList[0].z=z1;
g_pointList[0].color=D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue );
D3DXMATRIX matWorld;
D3DXMatrixIdentity( &matWorld );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
g_pd3dDevice->SetTexture(0,NULL);
g_pd3dDevice->SetTexture(1,NULL);
g_pd3dDevice->SetVertexShader(NULL);
g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue ) );
g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, nZenable );
g_pd3dDevice->SetViewport( &g_pViewPort );
g_pd3dDevice->SetFVF( D3DFVF_MY_VERTEX );
g_pd3dDevice->DrawPrimitiveUP(D3DPT_POINTLIST,1,g_pointList,sizeof(Vertex));
g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0 );
}
And sample code:
#include "DarkSDK.h"
#include "d3dfunc.h"
void DarkSDK(void) {
float ca=0;
float cx=0;
float cz=0;
float x1=0;
float y1=0;
float z1=0;
float x2=0;
float y2=0;
float z2=0;
float zpos=50;
float zmove=0;
int x=0;
int y=0;
dbSyncOn();
dbSyncRate(90);
InitD3DFunc();
for (int i=1 ; i<21 ;i++)
{
dbMakeObjectSphere (i+100,1);
//remove to see objects
dbHideObject(i+100);
}
while (LoopSDK())
{
if (dbEscapeKey())
return;
cx=dbCos(ca)*zpos;
cz=dbSin(ca)*zpos;
dbPositionCamera (cx,2,cz);
dbPointCamera (0,0,0);
ca+=.1;
dbRandomize (1);
x1=dbRnd(20)-5;
y1=dbRnd(20)-5;
z1=dbRnd(20)-5;
for (int i=1 ; i<21 ; i++)
{
x2=dbRnd(20)-5;
y2=dbRnd(20)-5;
z2=dbRnd(20)-5;
dbPositionObject (i+100,x1,y1,z1);
//red points
d3d_dot3D (x1, y1, z1, 1, 255, 0, 0, 255 );
//change to "0" the "1" for disabling zenable of the 3d lines
d3d_line3D (x1, y1, z1, x2, y2, z2, 1, dbRnd(255), dbRnd(255), dbRnd(255), dbRnd(100) );
x1=x2;
y1=y2;
z1=z2;
}
if (zpos>=50) zmove=-.01;
if (zpos<=-50) zmove=.01;
zpos=zpos+zmove;
dbSync();
}
}
The code works fine at the example. 3D dots appear in red.
However, I have a couple of issues and if somebody has any clue, I would be grateful. I inserted the functions in a big project so I don't know exactly what's wrong, but:
1 - 3D Lines do not obey ZENABLED flag, they appear over any 3d object.
2 - 3D Dots do not appear as dots, but as squared sprites.
I'm stuck finding out the reasons why.