 |
JLI Spieleprogrammierung
|
Vorheriges Thema anzeigen :: Nächstes Thema anzeigen |
Autor |
Nachricht |
Sardo Mini JLI'ler
Anmeldedatum: 23.01.2005 Beiträge: 2
Medaillen: Keine
|
Verfasst am: 23.01.2005, 01:31 Titel: Warum ist meine Kamerasicht statisch? |
|
|
ich habe das Problem, dass ich eigentlich ein texturiertes Feld wollte, dass sie selbst um seine X-Achse dreht... Aber es passiert nichts (es bleibt starr). Auch wenn ich verschiedene Werte für die Kamera und ihre Perspektiven angebe, tut sich nichts. Wo kann der Fehler sein?
Code: | #include <windows.h>
#include <mmsystem.h>
#include <fstream.h>
#include <d3d9.h>
#include <d3dx9.h>
LPDIRECT3D9 lpD3D = NULL;
LPDIRECT3DDEVICE9 lpD3DDevice = NULL;
LPDIRECT3DVERTEXBUFFER9 lpVB = NULL;
LPDIRECT3DTEXTURE9 lpD3DTexture = NULL;
struct CUSTOMVERTEX
{
float x, y, z, rhw;
float u, v;
};
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_TEX1)
HRESULT InitD3D(HWND hWnd)
{
if(NULL == (lpD3D = Direct3DCreate9( D3D_SDK_VERSION)))
return E_FAIL;
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
if(FAILED(lpD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &lpD3DDevice)))
return E_FAIL;
// Turn off culling
lpD3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
// Turn off D3D lighting
lpD3DDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
// Turn on the zbuffer
lpD3DDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
return S_OK;
}
HRESULT InitVB()
{
CUSTOMVERTEX vertices[] =
{
{ 50.0f, 50.0f, 0.5f, 1.0f, 0.0f,0.0f,},
{250.0f, 50.0f, 0.5f, 1.0f, 1.0f,0.0f,},
{ 50.0f, 250.0f, 0.5f, 1.0f, 0.0f,1.0f,},
{250.0f, 250.0f, 0.5f, 1.0f, 1.0f,1.0f,},
};
D3DXCreateTextureFromFile(lpD3DDevice, "banana.bmp", &lpD3DTexture);
if(FAILED(lpD3DDevice->CreateVertexBuffer(4*sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_MANAGED, &lpVB, NULL)))
return E_FAIL;
VOID* pVertices;
if(FAILED(lpVB->Lock(0, sizeof(vertices), (void**)&pVertices, 0)))
return E_FAIL;
memcpy(pVertices, vertices, sizeof(vertices));
lpVB->Unlock();
return S_OK;
}
VOID Cleanup()
{
if(lpVB != NULL)
lpVB->Release();
if(lpD3DDevice != NULL)
lpD3DDevice->Release();
if(lpD3D != NULL)
lpD3D->Release();
if(lpD3DTexture != NULL)
lpD3DTexture->Release();
}
VOID SetupMatrices()
{
// For our world matrix, we will just leave it as the identity
D3DXMATRIXA16 matWorld;
D3DXMatrixIdentity( &matWorld );
D3DXMatrixRotationX( &matWorld, timeGetTime()/1000.0f );
lpD3DDevice->SetTransform( D3DTS_WORLD, &matWorld );
// Set up our view matrix. A view matrix can be defined given an eye point,
// a point to lookat, and a direction for which way is up. Here, we set the
// eye five units back along the z-axis and up three units, look at the
// origin, and define "up" to be in the y-direction.
D3DXVECTOR3 vEyePt( 0.0f, 3.0f,-5.0f );
D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
D3DXMATRIXA16 matView;
D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
lpD3DDevice->SetTransform( D3DTS_VIEW, &matView );
// For the projection matrix, we set up a perspective transform (which
// transforms geometry from 3D view space to 2D viewport space, with
// a perspective divide making objects smaller in the distance). To build
// a perpsective transform, we need the field of view (1/4 pi is common),
// the aspect ratio, and the near and far clipping planes (which define at
// what distances geometry should be no longer be rendered).
D3DXMATRIXA16 matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
lpD3DDevice->SetTransform( D3DTS_PROJECTION, &matProj );
}
VOID Render()
{
lpD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,255), 1.0f, 0);
if(SUCCEEDED(lpD3DDevice->BeginScene()))
{
SetupMatrices();
lpD3DDevice->SetTexture(0,lpD3DTexture);
lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
lpD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
/*D3DXMATRIXA16 mat;
mat._11 = 0.25f; mat._12 = 0.00f; mat._13 = 0.00f; mat._14 = 0.00f;
mat._21 = 0.00f; mat._22 =-0.25f; mat._23 = 0.00f; mat._24 = 0.00f;
mat._31 = 0.00f; mat._32 = 0.00f; mat._33 = 1.00f; mat._34 = 0.00f;
mat._41 = 0.50f; mat._42 = 0.50f; mat._43 = 0.00f; mat._44 = 1.00f;
lpD3DDevice->SetTransform( D3DTS_TEXTURE0, &mat );
lpD3DDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
lpD3DDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION );*/
lpD3DDevice->SetStreamSource(0, lpVB, 0, sizeof(CUSTOMVERTEX));
lpD3DDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
lpD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
lpD3DDevice->EndScene();
}
lpD3DDevice->Present(NULL, NULL, NULL, NULL);
}
LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
Cleanup();
PostQuitMessage(0);
return 0;
case WM_KEYDOWN:
switch(wParam)
{
case VK_ESCAPE:
DestroyWindow(hWnd);
break;
case VK_LEFT:
break;
case VK_RIGHT:
break;
case VK_UP:
break;
case VK_DOWN:
break;
case VK_F1:
break;
}
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT)
{
WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, "Game Engine", NULL};
RegisterClassEx(&wc);
HWND hWnd = CreateWindow("Game Engine", "RomTech Game Engine", WS_OVERLAPPEDWINDOW, 100, 100, 300, 300, GetDesktopWindow(), NULL, wc.hInstance, NULL);
if(SUCCEEDED(InitD3D(hWnd)))
{
if(SUCCEEDED(InitVB()))
{
ShowWindow(hWnd, SW_SHOWDEFAULT);
UpdateWindow(hWnd);
MSG msg;
ZeroMemory(&msg, sizeof(msg));
while(msg.message!=WM_QUIT)
{
if(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
Render();
}
}
}
UnregisterClass("Game Engine", wc.hInstance);
return 0;
} |
|
|
Nach oben |
|
 |
FH Super JLI'ler
Alter: 37 Anmeldedatum: 16.10.2004 Beiträge: 438
Medaillen: Keine
|
Verfasst am: 23.01.2005, 03:09 Titel: |
|
|
Herzlich Willkommen Sardo,
Ich setz mich dran, aber eine Anmerkung:
Das gehört ins DirectX, OpenGL-Forum. Das ist etwas irreführend, die Namensgebung der SubForen. Aber laut der Ankündigung (steht hier ganz oben. Link: Ankündigungen: -> Dieses forum <-), ist das hier für Bildbearbeitung, etc.
Ich hab mich das erste mal hier auch verfranst.
Gruß, gute Besserung für Patricks Freundin und (g)n8
FH _________________ goto work, send your kids to school
follow fashion, act normal
walk on the pavement, watch T.V.
save for your old age, obey the law
Repeat after me: I am free |
|
Nach oben |
|
 |
Cyianor Super JLI'ler

Anmeldedatum: 23.12.2002 Beiträge: 452
Medaillen: Keine
|
Verfasst am: 23.01.2005, 08:11 Titel: |
|
|
Wenn du dein Vertexformat mit D3DFVF_XYZRHW erstellst kannst du AFAIK nicht rotieren. Um um die X, Y und Z Achse rotieren zu können muss das rhw weg. Nimm also einfach D3DFVF_XYZ. (Translations müssten mit dem rhw Format AFAIK auch nich funktionieren.) |
|
Nach oben |
|
 |
Sardo Mini JLI'ler
Anmeldedatum: 23.01.2005 Beiträge: 2
Medaillen: Keine
|
Verfasst am: 23.01.2005, 09:10 Titel: |
|
|
Wenn ich das RHW aus dem Customvertex und den Vertices streiche, dann kommt nix mehr im Fenster (außer ein blauer Hintergrund)... |
|
Nach oben |
|
 |
Jonathan_Klein Living Legend

Alter: 37 Anmeldedatum: 17.02.2003 Beiträge: 3433 Wohnort: Siegerland Medaillen: Keine
|
Verfasst am: 23.01.2005, 10:37 Titel: |
|
|
tja, dann ist die Kamera wohl nicht richtig positioniert. Aber es ist auch logisch, das es sich nicht drehren KANN, weil das rhw nämlich bedeutet, das die Daten in keiner Weise manipuliert werden, weil sie ja schon Bildaschirmkoordinaten sind. Du könntest die natürlich jetzt eineznt mit einer Rotatiosnmatrix tranfsormieren, andesr wirds wohl nicht gehen.
Und wenn du das RHW weglässt, interpretiert die DX halt im 3D Raum, weswegen deine Kamera höchstwahrscheinlich einfach nur falsch ausgericthet ist, und so nix angezeigt wird. _________________ https://jonathank.de/games/ |
|
Nach oben |
|
 |
|
|
Du kannst keine Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum nicht antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen.
|
Powered by phpBB © 2001, 2005 phpBB Group Deutsche Übersetzung von phpBB.de
|