Moteur 3d basique en d3d

Soyez le premier à donner votre avis sur cette source.

Snippet vu 7 705 fois - Téléchargée 40 fois

Contenu du snippet

Editeur 3d, trois vues différentes, énumération de hard, zbuff, textures , 5 degrés de liberté ...

Source / Exemple :


#include "includes.h"
#include "Moi.h"

#define NB_TRI     12

D3DMATRIX spin,trans,rotx,roty;
D3DMATRIXHANDLE hTrans,hRotx,hRoty;
DWORD size;
int i;
BOOL rigole=TRUE;

const D3DCOLOR MaterialColors[6][2] =
{
  RGBA_MAKE(240,  20,  20, 255),    // Unsaturated Red
  RGB_MAKE (240,  20,  20),         // Unsaturated Red
  RGBA_MAKE( 20, 240,  20, 255),    // Unsaturated Green
  RGB_MAKE ( 20, 240,  20),         // Unsaturated Green
  RGBA_MAKE( 20,  20, 240, 255),    // Unsaturated Blue  
  RGB_MAKE ( 20,  20, 240),         // Unsaturated Blue
  RGBA_MAKE(128,  64,   0, 255),    // Brown
  RGB_MAKE (128,  64,   0),         // Brown
  RGBA_MAKE(240,  20, 240, 255),    // Unsaturated Magenta
  RGB_MAKE (240,  20, 240),         // Unsaturated Magenta
  RGBA_MAKE(240, 240,  20, 255),    // Unsaturated Yellow
  RGB_MAKE (240, 240,  20),         // Unsaturated Yellow
};

OBJET cube;
static D3DEXECUTEDATA d3dExData;
static LPDIRECT3DEXECUTEBUFFER lpD3DExBuf[4];
static D3DEXECUTEBUFFERDESC debDesc;
LPDIRECT3DMATERIAL lpbmat;
LPDIRECT3DMATERIAL lpmat; 
const D3DCOLOR AmbientColor = RGBA_MAKE(100, 100, 100, 80);
LPDIRECT3DLIGHT lpD3DLight;
LPDIRECT3DMATERIAL lpBackgroundMaterial;
LPDIRECT3DMATERIAL lpD3DMaterial[16];
D3DMATERIALHANDLE  D3DMaterialHandle[16];

static D3DVERTEX CubeVertices[] = {
  {D3DVAL(-1.0),D3DVAL(1.0),D3DVAL(1.0),D3DVAL(0.0),D3DVAL(1.0),D3DVAL(0.0),D3DVAL(1.0),D3DVAL(0.0) },
  {D3DVAL(1.0),D3DVAL(1.0),D3DVAL(1.0),D3DVAL(0.0),D3DVAL(1.0),D3DVAL(0.0),D3DVAL(1.0),D3DVAL(1.0) },
  {D3DVAL(1.0),D3DVAL(1.0),D3DVAL(-1.0),D3DVAL(0.0),D3DVAL(1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(1.0) },
  {D3DVAL(-1.0),D3DVAL(1.0),D3DVAL(-1.0),D3DVAL(0.0),D3DVAL(1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(0.0) },

  {D3DVAL(1.0),D3DVAL(1.0),D3DVAL(-1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(-1.0),D3DVAL(1.0),D3DVAL(0.0) },
  {D3DVAL(1.0),D3DVAL(-1.0),D3DVAL(-1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(-1.0),D3DVAL(1.0),D3DVAL(1.0) },
  {D3DVAL(-1.0),D3DVAL(-1.0),D3DVAL(-1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(-1.0),D3DVAL(0.0),D3DVAL(1.0) },
  {D3DVAL(-1.0),D3DVAL(1.0),D3DVAL(-1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(-1.0),D3DVAL(0.0),D3DVAL(0.0) },

  {D3DVAL(1.0),D3DVAL(1.0),D3DVAL(1.0),D3DVAL(1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(1.0),D3DVAL(0.0) },
  {D3DVAL(1.0),D3DVAL(-1.0),D3DVAL(1.0),D3DVAL(1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(1.0),D3DVAL(1.0) },
  {D3DVAL(1.0),D3DVAL(-1.0),D3DVAL(-1.0),D3DVAL(1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(1.0) },
  {D3DVAL(1.0),D3DVAL(1.0),D3DVAL(-1.0),D3DVAL(1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(0.0) },

  {D3DVAL(-1.0),D3DVAL(1.0),D3DVAL(1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(1.0),D3DVAL(1.0),D3DVAL(0.0) },
  {D3DVAL(-1.0),D3DVAL(-1.0),D3DVAL(1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(1.0),D3DVAL(1.0),D3DVAL(1.0) },
  {D3DVAL(1.0),D3DVAL(-1.0),D3DVAL(1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(1.0),D3DVAL(0.0),D3DVAL(1.0) },
  {D3DVAL(1.0),D3DVAL(1.0),D3DVAL(1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(1.0),D3DVAL(0.0),D3DVAL(0.0) },

  {D3DVAL(-1.0),D3DVAL(-1.0),D3DVAL(-1.0),D3DVAL(-1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(1.0) },
  {D3DVAL(-1.0),D3DVAL(-1.0),D3DVAL(1.0),D3DVAL(-1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(1.0),D3DVAL(1.0) },
  {D3DVAL(-1.0),D3DVAL(1.0),D3DVAL(1.0),D3DVAL(-1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(1.0),D3DVAL(0.0) },
  {D3DVAL(-1.0),D3DVAL(1.0),D3DVAL(-1.0),D3DVAL(-1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(0.0) },
  
  {D3DVAL(1.0),D3DVAL(-1.0),D3DVAL(-1.0),D3DVAL(0.0),D3DVAL(-1.0),D3DVAL(0.0),D3DVAL(1.0),D3DVAL(1.0) },
  {D3DVAL(1.0),D3DVAL(-1.0),D3DVAL(1.0),D3DVAL(0.0),D3DVAL(-1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(1.0) },
  {D3DVAL(-1.0),D3DVAL(-1.0),D3DVAL(1.0),D3DVAL(0.0),D3DVAL(-1.0),D3DVAL(0.0),D3DVAL(0.0),D3DVAL(0.0) },
  {D3DVAL(-1.0),D3DVAL(-1.0),D3DVAL(-1.0),D3DVAL(0.0),D3DVAL(-1.0),D3DVAL(0.0),D3DVAL(1.0),D3DVAL(0.0) }
};

int CubeTri[] = {
   0,  1,  2,  0, 2, 3,
   4,  5,  6,  4, 6, 7,
   8,  9, 10, 8, 10, 11,
  12, 13, 14, 12, 14, 15,
  16, 17, 18, 16, 18, 19,
  20, 21, 22, 20, 22, 23
};

BOOL RenderScene(LPDIRECT3DDEVICE lpDev, LPDIRECT3DVIEWPORT lpView,
            LPD3DRECT lpExtent)
{
	Identite(&view); 
	Identite(&rotx);
	Identite(&roty);
	
	MultiplyD3DMATRIX(&world, &spin, &world);
	XRotation(&rotx,(float) (90-Moi[d3dinfo.CurrVue].theta));
	YRotation(&roty,(float) Moi[d3dinfo.CurrVue].phi);
	InitTranslation(&trans,-Moi[d3dinfo.CurrVue].x,-Moi[d3dinfo.CurrVue].y,-Moi[d3dinfo.CurrVue].z);
	
	if (lpDev->SetMatrix(hTrans, &trans) != D3D_OK) return FALSE;
	if (lpDev->SetMatrix(hRotx, &rotx) != D3D_OK) return FALSE;
	if (lpDev->SetMatrix(hRoty, &roty) != D3D_OK) return FALSE;
	if (lpDev->SetMatrix(hView, &view) != D3D_OK) return FALSE;
	
	if (lpDev->BeginScene() != D3D_OK) return FALSE;
	
	if (lpDev->Execute(lpD3DExBuf[d3dinfo.CurrVue],lpView, D3DEXECUTE_CLIPPED) != D3D_OK) return FALSE;
	
	if (lpDev->EndScene() != D3D_OK) return FALSE;
	
	AfficheDivers();

    return TRUE;
}

void OverrideDefaults(Defaults* defaults)
{
    defaults->rs.ShadeMode = D3DSHADE_GOURAUD;
    defaults->rs.ZBuffer = FALSE;
    defaults->PasTex = FALSE;
	defaults->PasResize=TRUE;
	d3dinfo.PleinEcran=TRUE;
	Glob.MontreInfo=FALSE;
    lstrcpy(defaults->Name, "Moteur 3d pas très fin!");
}

BOOL InitScene(void)
{
	world = identity;
	spin=identity;
	YRotation(&spin,2.00f);
	
	return TRUE;
}

void ReleaseScene(void)
{

}

void ReleaseView(LPDIRECT3DVIEWPORT lpView)
{
    int i;
    if (lpView)
        lpView->DeleteLight(lpD3DLight);
    RELEASE(lpD3DLight);
    RELEASE(lpD3DExBuf[1]);

    RELEASE(lpBackgroundMaterial);
    for (i = 0; i < 6; i++) {
        RELEASE(lpD3DMaterial[i]);
    }
}

BOOL InitView(LPDIRECTDRAW lpDD, LPDIRECT3D lpD3D, LPDIRECT3DDEVICE lpDev,
           LPDIRECT3DVIEWPORT lpView, int NumTextures,
           LPD3DTEXTUREHANDLE TextureHandle)
{
    D3DMATERIAL MaterialDesc;
    D3DMATERIALHANDLE BackgroundHandle;
    D3DLIGHT LightDesc;
    LPDIRECT3DEXECUTEBUFFER lpD3DExCmdBuf;
    LPVOID lpBufStart, lpInsStart, lpPointer;
	
	LoadMonde("Monde.dat");
	//InitMonde();
	InitVisual();
	
	d3dinfo.CurrVue=1;
    
	for (i = 0; i < 6; i++) 
	{
        if (lpD3D->CreateMaterial(&lpD3DMaterial[i], NULL) != D3D_OK)
           return FALSE;
        memset(&MaterialDesc, 0, sizeof(D3DMATERIAL));
        MaterialDesc.dwSize = sizeof(D3DMATERIAL);
        MaterialDesc.diffuse.r = (D3DVALUE)(RGBA_GETRED(MaterialColors[i][0]) / 255.0);
        MaterialDesc.diffuse.g = (D3DVALUE)(RGBA_GETGREEN(MaterialColors[i][0]) / 255.0);
        MaterialDesc.diffuse.b = (D3DVALUE)(RGBA_GETBLUE(MaterialColors[i][0]) / 255.0);
        MaterialDesc.diffuse.a = (D3DVALUE)(RGBA_GETALPHA(MaterialColors[i][0]) / 255.0);
        MaterialDesc.ambient.r = (D3DVALUE)(RGBA_GETALPHA(MaterialColors[i][1]) / 255.0);
        MaterialDesc.ambient.g = (D3DVALUE)(RGBA_GETALPHA(MaterialColors[i][1]) / 255.0);
        MaterialDesc.ambient.b = (D3DVALUE)(RGBA_GETALPHA(MaterialColors[i][1]) / 255.0);
        MaterialDesc.ambient.a = (D3DVALUE)(RGBA_GETALPHA(MaterialColors[i][1]) / 255.0);
        MaterialDesc.specular.r = (D3DVALUE)1.0;
        MaterialDesc.specular.g = (D3DVALUE)1.0;
        MaterialDesc.specular.b = (D3DVALUE)1.0;
        MaterialDesc.emissive.r = (D3DVALUE)1.0;
        MaterialDesc.emissive.g = (D3DVALUE)1.0;
        MaterialDesc.emissive.b = (D3DVALUE)1.0;
        MaterialDesc.power = (float)20.0;
        MaterialDesc.dwRampSize = 16;
        MaterialDesc.hTexture = TextureHandle[i % 4];
        lpD3DMaterial[i]->SetMaterial(&MaterialDesc);
        lpD3DMaterial[i]->GetHandle(lpDev,&D3DMaterialHandle[i]);
    }
    
	if (lpD3D->CreateMaterial(&lpD3DMaterial[7], NULL) != D3D_OK)
		return FALSE;
    memset(&MaterialDesc, 0, sizeof(D3DMATERIAL));
    MaterialDesc.dwSize = sizeof(D3DMATERIAL);
    MaterialDesc.diffuse.r = (D3DVALUE)(RGBA_GETRED(MaterialColors[i][0]) / 255.0);
    MaterialDesc.diffuse.g = (D3DVALUE)(RGBA_GETGREEN(MaterialColors[i][0]) / 255.0);
    MaterialDesc.diffuse.b = (D3DVALUE)(RGBA_GETBLUE(MaterialColors[i][0]) / 255.0);
    MaterialDesc.diffuse.a = (D3DVALUE)(RGBA_GETALPHA(MaterialColors[i][0]) / 255.0);
    MaterialDesc.ambient.r = (D3DVALUE)(RGBA_GETALPHA(MaterialColors[i][1]) / 255.0);
    MaterialDesc.ambient.g = (D3DVALUE)(RGBA_GETALPHA(MaterialColors[i][1]) / 255.0);
    MaterialDesc.ambient.b = (D3DVALUE)(RGBA_GETALPHA(MaterialColors[i][1]) / 255.0);
    MaterialDesc.ambient.a = (D3DVALUE)(RGBA_GETALPHA(MaterialColors[i][1]) / 255.0);
    MaterialDesc.specular.r = (D3DVALUE)1.0;
    MaterialDesc.specular.g = (D3DVALUE)1.0;
    MaterialDesc.specular.b = (D3DVALUE)1.0;
    MaterialDesc.emissive.r = (D3DVALUE)1.0;
    MaterialDesc.emissive.g = (D3DVALUE)1.0;
    MaterialDesc.emissive.b = (D3DVALUE)1.0;
    MaterialDesc.power = (float)20.0;
    MaterialDesc.dwRampSize = 16;
    MaterialDesc.hTexture = NULL;
    lpD3DMaterial[7]->SetMaterial(&MaterialDesc);
    lpD3DMaterial[7]->GetHandle(lpDev,&D3DMaterialHandle[7]);

    if (lpD3D->CreateMaterial(&lpBackgroundMaterial, NULL) != D3D_OK) return FALSE;
    memset(&MaterialDesc, 0, sizeof(D3DMATERIAL));
    MaterialDesc.dwSize = sizeof(D3DMATERIAL);
    MaterialDesc.power = (float)20.0;
    MaterialDesc.diffuse.r = (float) 0.6;
    MaterialDesc.diffuse.g = (float) 0.8;
    MaterialDesc.diffuse.b = (float) 0.9;
    MaterialDesc.diffuse.a = 0.0;

    lpBackgroundMaterial->SetMaterial(&MaterialDesc);
    lpBackgroundMaterial->GetHandle(lpDev,&BackgroundHandle);
    lpView->SetBackground(BackgroundHandle);
    /*

  • Add one directional light.
  • /
memset(&LightDesc, 0, sizeof(D3DLIGHT)); LightDesc.dwSize = sizeof(D3DLIGHT); LightDesc.dltType = D3DLIGHT_POINT; LightDesc.dcvColor.r = D3DVAL(0.9); LightDesc.dcvColor.g = D3DVAL(0.9); LightDesc.dcvColor.b = D3DVAL(0.9); LightDesc.dcvColor.a = D3DVAL(1.0); LightDesc.dvPosition.x = D3DVALP(0.0, 12); LightDesc.dvPosition.y = D3DVALP(0.0, 12); LightDesc.dvPosition.z = D3DVALP(-12.0, 12); LightDesc.dvAttenuation0 = D3DVAL(0.0); LightDesc.dvAttenuation1 = D3DVAL(0.0); LightDesc.dvAttenuation2 = D3DVAL(0.0); LightDesc.dltType = D3DLIGHT_DIRECTIONAL; LightDesc.dvDirection.x = D3DVALP(0.0, 12); LightDesc.dvDirection.y = D3DVALP(0.0, 12); LightDesc.dvDirection.z = D3DVALP(1.0, 12); if (lpD3D->CreateLight(&lpD3DLight, NULL) != D3D_OK) return FALSE; if (lpD3DLight->SetLight(&LightDesc) != D3D_OK) return FALSE; if (lpView->AddLight(lpD3DLight) != D3D_OK) return FALSE; Identite(&rotx); Identite(&roty); Identite(&trans); MAKE_MATRIX(lpDev, hView, view); MAKE_MATRIX(lpDev, hProj, proj); MAKE_MATRIX(lpDev, hWorld, world); MAKE_MATRIX(lpDev, hTrans, trans); MAKE_MATRIX(lpDev, hRotx, rotx); MAKE_MATRIX(lpDev, hRoty, roty); size = 0; size += sizeof(D3DINSTRUCTION) * 3; size += sizeof(D3DSTATE) * 4; memset(&debDesc, 0, sizeof(D3DEXECUTEBUFFERDESC)); debDesc.dwSize = sizeof(D3DEXECUTEBUFFERDESC); debDesc.dwFlags = D3DDEB_BUFSIZE; debDesc.dwBufferSize = size; if (lpDev->CreateExecuteBuffer(&debDesc, &lpD3DExCmdBuf, NULL) != D3D_OK) return FALSE; if (lpD3DExCmdBuf->Lock(&debDesc) != D3D_OK) return FALSE; lpBufStart = debDesc.lpData; memset(lpBufStart, 0, size); lpPointer = lpBufStart; lpInsStart = lpPointer; OP_STATE_TRANSFORM(3, lpPointer); STATE_DATA(D3DTRANSFORMSTATE_WORLD, hWorld, lpPointer); STATE_DATA(D3DTRANSFORMSTATE_VIEW, hView, lpPointer); STATE_DATA(D3DTRANSFORMSTATE_PROJECTION, hProj, lpPointer); OP_STATE_LIGHT(1, lpPointer); STATE_DATA(D3DLIGHTSTATE_AMBIENT, AmbientColor, lpPointer); OP_EXIT(lpPointer); lpD3DExCmdBuf->Unlock(); memset(&d3dExData, 0, sizeof(D3DEXECUTEDATA)); d3dExData.dwSize = sizeof(D3DEXECUTEDATA); d3dExData.dwInstructionOffset = (ULONG) 0; d3dExData.dwInstructionLength = (ULONG) ((char *)lpPointer - (char*)lpInsStart); lpD3DExCmdBuf->SetExecuteData(&d3dExData); lpDev->BeginScene(); lpDev->Execute(lpD3DExCmdBuf, lpView, D3DEXECUTE_UNCLIPPED); lpDev->EndScene(); /*
  • We are done with the command buffer.
  • /
lpD3DExCmdBuf->Release(); /*
  • Create an execute buffer
  • /
if (!FillExBuff1(0,lpDD,lpD3D,lpDev,lpView,NumTextures,TextureHandle)) { return FALSE; } if (!FillExBuff2(0,lpDD,lpD3D,lpDev,lpView,NumTextures,TextureHandle)) { return FALSE; } lpD3DExBuf[3]=lpD3DExBuf[1]; InitMoi(); AffichetoutExBuff(); return TRUE; } BOOL FillExBuff1(BOOL Redraw,LPDIRECTDRAW lpDD, LPDIRECT3D lpD3D, LPDIRECT3DDEVICE lpDev, LPDIRECT3DVIEWPORT lpView, int NumTextures, LPD3DTEXTUREHANDLE TextureHandle) { LPVOID lpBufStart, lpInsStart, lpPointer; // calculate the size of the buffer if (!rigole) Msg("AhhBon"); size = sizeof(D3DVERTEX) * (NB_V*Monde.Nb_Caisses); size += sizeof(D3DVERTEX) * 2 * Monde.Nb_Line; size += sizeof(D3DSTATUS) * 1; size += sizeof(D3DPROCESSVERTICES) * (6*Monde.Nb_Caisses+Monde.Nb_Line) ; size += sizeof(D3DINSTRUCTION) * (4 + 12*Monde.Nb_Caisses+Monde.Nb_Line); size += sizeof(D3DMATRIXMULTIPLY) * 3; size += sizeof(D3DSTATE) * (3+6*Monde.Nb_Caisses+Monde.Nb_Line); size += sizeof(D3DLINE) * NB_TRI * 3+ 128000; // Create an execute buffer memset(&debDesc, 0, sizeof(D3DEXECUTEBUFFERDESC)); debDesc.dwSize = sizeof(D3DEXECUTEBUFFERDESC); debDesc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS; debDesc.dwBufferSize = size; debDesc.dwCaps= D3DDEBCAPS_SYSTEMMEMORY; if (!rigole) Msg("AhhBon"); if (!Redraw) { if (lpDev->CreateExecuteBuffer(&debDesc, &lpD3DExBuf[1], NULL)!= D3D_OK) return FALSE; } if (lpD3DExBuf[1]->Lock(&debDesc) != D3D_OK) return FALSE; lpBufStart = debDesc.lpData; memset(lpBufStart, 0, size); lpPointer = lpBufStart; for (i=0;i<Monde.Nb_Caisses;i++) { VERTEX_DATA(&Monde.Caisses[i].VERTEX[0], NB_V, lpPointer); } VERTEX_DATA(&Monde.PointsLine[0], 2 * Monde.Nb_Line, lpPointer); lpInsStart = lpPointer; OP_MATRIX_MULTIPLY(3,lpPointer); MATRIX_MULTIPLY_DATA(hView,hTrans,hView,lpPointer); MATRIX_MULTIPLY_DATA(hView,hRoty,hView,lpPointer); MATRIX_MULTIPLY_DATA(hView,hRotx,hView,lpPointer); OP_SET_STATUS(D3DSETSTATUS_ALL, D3DSTATUS_DEFAULT, 2048, 2048, 0, 0, lpPointer); for (i = 0; i < 6*Monde.Nb_Caisses; i++) { OP_STATE_LIGHT(1, lpPointer); STATE_DATA(D3DLIGHTSTATE_MATERIAL, D3DMaterialHandle[i % 6], lpPointer); OP_PROCESS_VERTICES(1, lpPointer); PROCESSVERTICES_DATA(D3DPROCESSVERTICES_TRANSFORMLIGHT, i * 6, 6, lpPointer); } for (i=0; i<Monde.Nb_Line;i++) { OP_STATE_LIGHT(1, lpPointer); STATE_DATA(D3DLIGHTSTATE_MATERIAL, D3DMaterialHandle[7], lpPointer); OP_PROCESS_VERTICES(1, lpPointer); PROCESSVERTICES_DATA(D3DPROCESSVERTICES_TRANSFORMLIGHT, NB_V*Monde.Nb_Caisses+ i * 2, 2, lpPointer); } OP_STATE_RENDER(3, lpPointer); STATE_DATA(D3DRENDERSTATE_TEXTUREHANDLE, TextureHandle[1], lpPointer); STATE_DATA(D3DRENDERSTATE_WRAPU, FALSE, lpPointer); STATE_DATA(D3DRENDERSTATE_WRAPV, FALSE, lpPointer); if (QWORD_ALIGNED(lpPointer)) { OP_NOP(lpPointer); } OP_LINE_LIST((NB_TRI*3*Monde.Nb_Caisses)+Monde.Nb_Line, lpPointer); LPD3DLINE line; line=(LPD3DLINE) lpPointer; int j; for (j=0;j<Monde.Nb_Caisses;j++) { for (i = 0; i < NB_TRI; i++) { line->v1=3*i + j*NB_V; line->v2=3*i + 1 + j*NB_V; line++; line->v1=3*i + 1 + j*NB_V; line->v2=3*i + 2 + j*NB_V; line++; line->v1=3*i + 2 + j*NB_V; line->v2=3*i + j*NB_V; line++; } } for (j=0;j<Monde.Nb_Line;j++) { line->v1= Monde.Nb_Caisses*NB_V+ (j*2) ; line->v2= Monde.Nb_Caisses*NB_V+ (j*2) +1; line++; } lpPointer=(void *) line; OP_EXIT(lpPointer); lpD3DExBuf[1]->Unlock(); memset(&d3dExData, 0, sizeof(D3DEXECUTEDATA)); d3dExData.dwSize = sizeof(D3DEXECUTEDATA); d3dExData.dwVertexCount = NB_V*Monde.Nb_Caisses + 2 * Monde.Nb_Line; d3dExData.dwInstructionOffset = (ULONG)((char*)lpInsStart - (char*)lpBufStart); d3dExData.dwInstructionLength = (ULONG)((char*)lpPointer - (char*)lpInsStart); lpD3DExBuf[1]->SetExecuteData(&d3dExData); return TRUE; } BOOL FillExBuff2(BOOL Redraw,LPDIRECTDRAW lpDD, LPDIRECT3D lpD3D, LPDIRECT3DDEVICE lpDev, LPDIRECT3DVIEWPORT lpView, int NumTextures, LPD3DTEXTUREHANDLE TextureHandle) { LPVOID lpBufStart, lpInsStart, lpPointer; // calculate the size of the buffer if (!Redraw) { size = sizeof(D3DVERTEX) * (NB_V*Monde.Nb_Caisses); size += sizeof(D3DSTATUS) * 1; size += sizeof(D3DPROCESSVERTICES) * (6*Monde.Nb_Caisses+Monde.Nb_Line) ; size += sizeof(D3DINSTRUCTION) * (2 + 12*Monde.Nb_Caisses+Monde.Nb_Line+NB_TRI); size += sizeof(D3DMATRIXMULTIPLY) * 3; size += sizeof(D3DSTATE) * (3*(NB_TRI>>1)+6*Monde.Nb_Caisses+Monde.Nb_Line); size += sizeof(D3DTRIANGLE) * NB_TRI * Monde.Nb_Caisses; size += sizeof(D3DLINE)*Monde.Nb_Line + 64000; // Create an execute buffer memset(&debDesc, 0, sizeof(D3DEXECUTEBUFFERDESC)); debDesc.dwSize = sizeof(D3DEXECUTEBUFFERDESC); debDesc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS; debDesc.dwBufferSize = size; debDesc.dwCaps= D3DDEBCAPS_SYSTEMMEMORY; if (lpDev->CreateExecuteBuffer(&debDesc, &lpD3DExBuf[2], NULL)!= D3D_OK) return FALSE; } if (lpD3DExBuf[2]->Lock(&debDesc) != D3D_OK) { Msg("Hummm Hummm Hummm Locke"); return FALSE; } lpBufStart = debDesc.lpData; memset(lpBufStart, 0, size); lpPointer = lpBufStart; for (i=0;i<Monde.Nb_Caisses;i++) { VERTEX_DATA(&Monde.Caisses[i].VERTEX[0], NB_V, lpPointer); } VERTEX_DATA(&Monde.PointsLine[0], 2 * Monde.Nb_Line, lpPointer); lpInsStart = lpPointer; OP_MATRIX_MULTIPLY(3,lpPointer); MATRIX_MULTIPLY_DATA(hView,hTrans,hView,lpPointer); MATRIX_MULTIPLY_DATA(hView,hRoty,hView,lpPointer); MATRIX_MULTIPLY_DATA(hView,hRotx,hView,lpPointer); OP_SET_STATUS(D3DSETSTATUS_ALL, D3DSTATUS_DEFAULT, 2048, 2048, 0, 0, lpPointer); for (i = 0; i < 6*Monde.Nb_Caisses; i++) { OP_STATE_LIGHT(1, lpPointer); STATE_DATA(D3DLIGHTSTATE_MATERIAL, D3DMaterialHandle[i % 6], lpPointer); OP_PROCESS_VERTICES(1, lpPointer); PROCESSVERTICES_DATA(D3DPROCESSVERTICES_TRANSFORMLIGHT, i * 6, 6, lpPointer); } for (i=0; i<Monde.Nb_Line;i++) { OP_STATE_LIGHT(1, lpPointer); STATE_DATA(D3DLIGHTSTATE_MATERIAL, D3DMaterialHandle[i % 6], lpPointer); OP_PROCESS_VERTICES(1, lpPointer); PROCESSVERTICES_DATA(D3DPROCESSVERTICES_TRANSFORMLIGHT, NB_V*Monde.Nb_Caisses+ i * 2, 2, lpPointer); } if (QWORD_ALIGNED(lpPointer)) { OP_NOP(lpPointer); } LPD3DTRIANGLE tri; int j; for (j = 0; j < Monde.Nb_Caisses; j++) { for (i = 0; i < (NB_TRI>>1); i++) { OP_STATE_RENDER(3, lpPointer); STATE_DATA(D3DRENDERSTATE_TEXTUREHANDLE, TextureHandle[Monde.Caisses[j].IndexTex[i]], lpPointer); STATE_DATA(D3DRENDERSTATE_WRAPU, FALSE, lpPointer); STATE_DATA(D3DRENDERSTATE_WRAPV, FALSE, lpPointer); OP_TRIANGLE_LIST(2, lpPointer); tri=(LPD3DTRIANGLE) lpPointer; ((LPD3DTRIANGLE)lpPointer)->v1 = j*NB_V+i*6; ((LPD3DTRIANGLE)lpPointer)->v2 = j*NB_V+i*6 + 1; ((LPD3DTRIANGLE)lpPointer)->v3 = j*NB_V+i*6 + 2; ((LPD3DTRIANGLE)lpPointer)->wFlags = NULL; lpPointer = (void *)(((LPD3DTRIANGLE) lpPointer) + 1); ((LPD3DTRIANGLE)lpPointer)->v1 = j*NB_V+i*6 + 3; ((LPD3DTRIANGLE)lpPointer)->v2 = j*NB_V+i*6 + 4; ((LPD3DTRIANGLE)lpPointer)->v3 = j*NB_V+i*6 + 5; ((LPD3DTRIANGLE)lpPointer)->wFlags = NULL; lpPointer = (void *)(((LPD3DTRIANGLE) lpPointer) + 1); } } OP_LINE_LIST(Monde.Nb_Line, lpPointer); LPD3DLINE line; line=(LPD3DLINE) lpPointer; for (j=0;j<Monde.Nb_Line;j++) { line->v1= NB_V*Monde.Nb_Caisses + (j*2) ; line->v2= NB_V*Monde.Nb_Caisses + (j*2) +1; line++; } lpPointer=(void *) line; OP_EXIT(lpPointer); lpD3DExBuf[2]->Unlock(); memset(&d3dExData, 0, sizeof(D3DEXECUTEDATA)); d3dExData.dwSize = sizeof(D3DEXECUTEDATA); d3dExData.dwVertexCount = NB_V*Monde.Nb_Caisses + 2*Monde.Nb_Line; d3dExData.dwInstructionOffset = (ULONG)((char*)lpInsStart - (char*)lpBufStart); d3dExData.dwInstructionLength = (ULONG)((char*)lpPointer - (char*)lpInsStart); lpD3DExBuf[2]->SetExecuteData(&d3dExData); return TRUE; } BOOL JarteExBuff(int n) { if (FAILED(lpD3DExBuf[n]->Release())) return FALSE; return TRUE; } void AjouteCaisseTaille(int n) { lpD3DExBuf[n]->GetExecuteData(&d3dExData); d3dExData.dwSize = sizeof(D3DEXECUTEDATA); d3dExData.dwVertexCount+=NB_V; d3dExData.dwInstructionOffset+=NB_V*sizeof(D3DVERTEX); d3dExData.dwInstructionLength+=NB_TRI*sizeof(D3DTRIANGLE); + 6*sizeof(D3DSTATE) + sizeof(D3DPROCESSVERTICES) * 6 + 12*sizeof(D3DINSTRUCTION); if (n==2) { d3dExData.dwInstructionLength+=3*sizeof(D3DSTATE)*(NB_TRI>>1) + NB_TRI*sizeof(D3DINSTRUCTION); } lpD3DExBuf[n]->SetExecuteData(&d3dExData); } void AjouteLineTaille(int n,int nb) { lpD3DExBuf[n]->GetExecuteData(&d3dExData); d3dExData.dwSize = sizeof(D3DEXECUTEDATA); d3dExData.dwVertexCount+=2*nb; d3dExData.dwInstructionOffset+=2*sizeof(D3DVERTEX)*nb; d3dExData.dwInstructionLength+=2*sizeof(D3DLINE)*nb; lpD3DExBuf[n]->SetExecuteData(&d3dExData); } BOOL AffichetoutExBuff(void) { int i; DDBLTFX ddbltfx; for (i=1;i<4;i++) { Identite(&view); Identite(&rotx); Identite(&roty); XRotation(&rotx,(float) (90-Moi[i].theta)); YRotation(&roty,(float) Moi[i].phi); InitTranslation(&trans,-Moi[i].x,-Moi[i].y,-Moi[i].z); ChangeViewport(i); RECT r; D3DRECT rect; switch (i) { case 1: r.left=1; r.top=1; r.right=d3dinfo.Mode.w/2; r.bottom=d3dinfo.Mode.h/2; rect.x1=1; rect.y1=1; rect.x2=d3dinfo.Mode.w/2; rect.y2=d3dinfo.Mode.h/2; break; case 2: r.left=d3dinfo.Mode.w/2+1; r.top=d3dinfo.Mode.h/2+1; r.right=d3dinfo.Mode.w-1; r.bottom=d3dinfo.Mode.h-1; rect.x1=d3dinfo.Mode.w/2+1; rect.y1=d3dinfo.Mode.h/2+1; rect.x2=d3dinfo.Mode.w-1; rect.y2=d3dinfo.Mode.h-1; break; case 3: r.left=1; r.top=d3dinfo.Mode.h/2+1; r.right=d3dinfo.Mode.w/2; r.bottom=d3dinfo.Mode.h-1; rect.x1=1; rect.y1=d3dinfo.Mode.h/2+1; rect.x2=d3dinfo.Mode.w/2; rect.y2=d3dinfo.Mode.h-1; break; } d3dinfo.lpD3DViewport->Clear(1,&rect,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER); if (d3dinfo.lpD3DDevice->SetMatrix(hTrans, &trans) != D3D_OK) return FALSE; if (d3dinfo.lpD3DDevice->SetMatrix(hRotx, &rotx) != D3D_OK) return FALSE; if (d3dinfo.lpD3DDevice->SetMatrix(hRoty, &roty) != D3D_OK) return FALSE; if (d3dinfo.lpD3DDevice->SetMatrix(hView, &view) != D3D_OK) return FALSE; if (d3dinfo.lpD3DDevice->BeginScene() != D3D_OK) return FALSE; if (d3dinfo.lpD3DDevice->Execute(lpD3DExBuf[i],d3dinfo.lpD3DViewport, D3DEXECUTE_CLIPPED) != D3D_OK) return FALSE; if (d3dinfo.lpD3DDevice->EndScene() != D3D_OK) return FALSE; memset(&ddbltfx, 0, sizeof(ddbltfx)); ddbltfx.dwSize = sizeof(DDBLTFX); d3dinfo.lpFrontBuffer->Blt(&r,d3dinfo.lpBackBuffer, &r, DDBLT_WAIT, NULL); } AfficheDivers(); InitCroix(); d3dinfo.lpFrontBuffer->Blt(NULL, d3dinfo.lpBackBuffer, NULL,DDBLT_WAIT,&ddbltfx); ChangeViewport(d3dinfo.CurrVue); InitVisual(); return TRUE; } void InitCrossXZ(float x,float y,float z) { D3DVERTEX *v; v = &Monde.PointsLine[2*Monde.Nb_Line]; v->nx=0; v->ny=1; v->nz=0; v->tu=0; v->tv=0; v->x=(float) (x-0.5) ; v->y=y; v->z=z; v++; v->nx=0; v->ny=1; v->nz=0; v->tu=1; v->tv=0; v->x=(float) (x+0.5) ; v->y=y; v->z=z; v++; v->nx=0; v->ny=1; v->nz=0; v->tu=0; v->tv=0; v->x=x; v->y=y; v->z=(float) (z+0.5) ; v++; v->nx=0; v->ny=1; v->nz=0; v->tu=1; v->tv=0; v->x=x; v->y=y; v->z=(float) (z-0.5) ; v++; Monde.Nb_Line+=2; } void TranslateCross(float dx,float dy,float dz) { D3DVERTEX *v; v=&Monde.PointsLine[2*(Monde.Nb_Line-3)]; v->x+=dx; v->y+=dy; v->z+=dz; v++; v->x+=dx; v->y+=dy; v->z+=dz; v++; v->x+=dx; v->y+=dy; v->z+=dz; v++; v->x+=dx; v->y+=dy; v->z+=dz; v++; v->x+=dx; v->y+=dy; v->z+=dz; v++; v->x+=dx; v->y+=dy; v->z+=dz; } void EnregistrePoint(D3DVECTOR *v) { v->x=Monde.PointsLine[2*Monde.Nb_Line-1].x; v->y=Monde.PointsLine[2*Monde.Nb_Line-1].y; v->z=Monde.PointsLine[2*Monde.Nb_Line-1].z+(float) 0.5; }

Conclusion :


c qu'une partie, demandez à ostrogoth22@caramail.com pour le reste ...

A voir également

Ajouter un commentaire

Commentaires

Messages postés
10
Date d'inscription
vendredi 4 juin 2004
Statut
Membre
Dernière intervention
9 février 2005

peux tu faire un zip d'une bonne fois
Messages postés
330
Date d'inscription
jeudi 22 mai 2003
Statut
Membre
Dernière intervention
26 janvier 2009

Toujours pas de zip...
Messages postés
331
Date d'inscription
mardi 12 novembre 2002
Statut
Membre
Dernière intervention
10 février 2009

Tu pourrais pas faire zip stp ?
ce serais bcp plus pratique, surtout pour un moteur 3d !!!
merci !
JE VEUX FAIRE PART A TOUT CPPFRANCE D'UNE FAIBLESSE DE VISUAL C++ :
Si l'include #include "stdafx.h"
N'est pas AU TOUT DEBUT du prog eh ben ça plante !!!!
HaHaHa
tu pourrait donner ta libraires moi.h et includes.h
merci !
Afficher les 7 commentaires

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.