Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Administrator
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
#include <tribase.h> #include <iostream> using namespace std; //Variable D3DPRESENT_PARAMETERS PresentParams; PDIRECT3D9 g_pD3D; PDIRECT3DDEVICE9 g_pD3DDevice; HINSTANCE hInstance; PDIRECT3DTEXTURE9 g_pTexture; float fCameraAngle = 0.0f; float fFOV = TB_DEG_TO_RAD(90.0f); float fZeit = 0; tbVector3 vCameraPosition = tbVector3(0,0,1); float fAspect; tbMatrix mProjection; #define IDI_ICON1 101 // Variablen HWND g_hWindow; struct SVertex { tbVector3 vPosition; DWORD dwColor; }; SVertex Dreieck[3]; //Verschiedene Funktionen int macheFenster(int iWidth, int iHeight, char* pcName, HICON hIcon); int Start(); int Rendere(float Zeitanfang); LRESULT WINAPI WindowProc(HWND hWindow, unsigned int uiMessage, WPARAM WParam, LPARAM LParam); int Move(); //Hauptfunktion int main () { int Gedrueckt=0; int Auswahl=0; printf("Lade...\nZum dieser Anwendung druecken sie einfach die Leertaste!!\n"); int Differenz; float ZeitAnfang, ZeitEnde; Gedrueckt = 0; macheFenster(1024, 768, "Test", LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1))); Dreieck[0].vPosition = tbVector3( 0.0f, 1.0f, 0.0f); Dreieck[1].vPosition = tbVector3( 1.0f, -1.0f, 0.0f); Dreieck[2].vPosition = tbVector3( -1.0f, -1.0f, -1.0f); Dreieck[0].dwColor = tbColor( 1.0f, 0.0f, 0.0f); Dreieck[1].dwColor = tbColor( 0.0f, 1.0f, 0.0f); Dreieck[2].dwColor = tbColor( 0.0f, 0.0f, 1.0f); Start(); //Einstellungen //Schleife1 while(Gedrueckt != 1) { ZeitAnfang = timeGetTime(); fZeit += ZeitAnfang; //Spielframe Anfang Rendere(fZeit); if(GetAsyncKeyState(VK_SPACE)) { Gedrueckt = 1; } //Anfang zeichnen Move(); //Spielframe Ende ZeitEnde = timeGetTime(); Differenz = ZeitEnde - ZeitAnfang ; while (Differenz < 40) { ZeitEnde = timeGetTime(); Differenz = ZeitEnde - ZeitAnfang; } } //Schleife1 g_pD3D ->Release(); return 0; } //ENDE HAUPTFUNKTION int macheFenster(int iWidth, int iHeight, char* pcName, HICON hIcon) { // Fensterklassenstruktur ausfüllen WNDCLASSEX WindowClass = {sizeof(WNDCLASSEX), CS_CLASSDC, WindowProc, 0, 0, GetModuleHandle(NULL), hIcon, LoadCursor (NULL, MAKEINTRESOURCE(IDC_ARROW)), NULL, NULL, "Direct3D window", NULL}; // Klasse registrieren if(!RegisterClassEx(&WindowClass)) { TB_ERROR("Fensterklassenregistrierung fehlgeschlagen!", TB_ERROR); } TB_INFO("Fensterklasse wurde registriert!"); RECT Rect; SetRect(&Rect, 0, 0, iWidth, iHeight); AdjustWindowRect(&Rect, WS_VISIBLE | WS_OVERLAPPEDWINDOW, FALSE); iWidth = Rect.right - Rect.left; iHeight = Rect.bottom - Rect.top; // Fenster erstellen und prüfen g_hWindow = CreateWindow("Direct3D window", pcName, WS_VISIBLE | WS_OVERLAPPEDWINDOW, GetSystemMetrics(SM_CXSCREEN) / 2 - iWidth / 2, GetSystemMetrics(SM_CYSCREEN) / 2 - iHeight / 2, iWidth, iHeight, NULL, NULL, GetModuleHandle(NULL), NULL); if(g_hWindow == NULL) { TB_ERROR("Erstellung des Fensters ist fehlgeschlagen!\n", TB_ERROR); } // Alles OK! TB_INFO("Fenster wurde erstellt!"); return TB_OK; } int Move() { if(GetAsyncKeyState(VK_LEFT)) fCameraAngle -= TB_DEG_TO_RAD(45.0f) * fZeit; if(GetAsyncKeyState(VK_RIGHT)) fCameraAngle += TB_DEG_TO_RAD(45.0f) * fZeit; tbVector3 vCameraDirection = tbVector3(sinf(fCameraAngle), 0.0f, cosf(fCameraAngle)); if(GetAsyncKeyState(VK_UP)) vCameraPosition += vCameraDirection * 10.0f * fZeit; if(GetAsyncKeyState(VK_DOWN)) vCameraPosition -= vCameraDirection * 10.0f * fZeit; if(GetAsyncKeyState(VK_PRIOR)) fFOV -= TB_DEG_TO_RAD(15.0f) * fZeit; if(GetAsyncKeyState(VK_NEXT)) fFOV += TB_DEG_TO_RAD(15.0f) * fZeit; if(fFOV>= TB_DEG_TO_RAD(180.0f)) fFOV = TB_DEG_TO_RAD(179.9f); if(fFOV>= TB_DEG_TO_RAD(0.0f)) fFOV = TB_DEG_TO_RAD(0.1f); return 0; } int Start() { //Schnittstelle erstellen if (!(g_pD3D = Direct3DCreate9 (D3D_SDK_VERSION))) MessageBox(NULL,"Adapter konnte nicht\nerstellt werden!\nHaben sie DirectX9 installiert?","Adapterfehler",MB_OK); ZeroMemory(&PresentParams, sizeof(D3DPRESENT_PARAMETERS)); PresentParams.BackBufferWidth = 1024; PresentParams.BackBufferHeight = 768; PresentParams.BackBufferFormat = D3DFMT_X8R8G8B8; PresentParams.BackBufferCount = 1; PresentParams.MultiSampleType = D3DMULTISAMPLE_NONE; PresentParams.MultiSampleQuality = 0; PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD; PresentParams.hDeviceWindow = g_hWindow; PresentParams.Windowed = FALSE; PresentParams.EnableAutoDepthStencil = TRUE; PresentParams.AutoDepthStencilFormat = D3DFMT_D24S8; PresentParams.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER | D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL; PresentParams.FullScreen_RefreshRateInHz= D3DPRESENT_RATE_DEFAULT; PresentParams.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; g_pD3D -> CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWindow, D3DCREATE_MULTITHREADED|D3DCREATE_HARDWARE_VERTEXPROCESSING, &PresentParams, &g_pD3DDevice); ShowCursor(FALSE); g_pD3DDevice -> SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE); g_pD3DDevice -> SetRenderState(D3DRS_LIGHTING , FALSE); g_pD3DDevice -> SetRenderState(D3DRS_CULLMODE , D3DCULL_NONE); g_pD3DDevice -> SetRenderState(D3DRS_DITHERENABLE , TRUE); g_pD3DDevice -> SetRenderState(D3DRS_ZENABLE , D3DZB_USEW); g_pD3DDevice -> SetRenderState(D3DRS_SHADEMODE , D3DSHADE_GOURAUD); //Texturen laden u. einsetzen D3DXCreateTextureFromFileEx(g_pD3DDevice, "Steine.jpg", D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT, 0, NULL, NULL, &g_pTexture); g_pD3DDevice->SetSamplerState(0, D3DSAMP_MAXANISOTROPY,4); g_pD3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC); g_pD3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); g_pD3DDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE); g_pD3DDevice->SetTexture(0, g_pTexture); return 0; } LRESULT WINAPI WindowProc(HWND hWindow, unsigned int uiMessage, WPARAM WParam, LPARAM LParam) { PAINTSTRUCT Paint; switch(uiMessage) { case WM_CREATE: break; case WM_PAINT: // Das Fenster mit Schwarz füllen BeginPaint(hWindow, &Paint); FillRect(Paint.hdc, &Paint.rcPaint, (HBRUSH)(GetStockObject(BLACK_BRUSH))); EndPaint(hWindow, &Paint); break; case WM_CLOSE: DestroyWindow(hWindow); PostQuitMessage(0); break; default: return DefWindowProc(hWindow, uiMessage, WParam, LParam); } return TRUE; } int Rendere(float ZeitAnfang) { g_pD3DDevice->Clear(0,NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, D3DCOLOR_XRGB( 0, 0, 0), 1.0f,0); tbMatrix mCamera; tbMatrix mWorld; mCamera = tbMatrixCamera(vCameraPosition, vCameraPosition + tbVector3(sinf(fCameraAngle), 0.0f, cosf(fCameraAngle)), tbVector3(0.0f,4.0f,0.0f)); g_pD3DDevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)(&mCamera)); fAspect = (float) (1024) / (float) (768); mProjection = tbMatrixProjection(fFOV, // Sichtfeld fAspect, // Bildseitenverhältnis 0.1f, // Nahe Clipping-Ebene 250.0f); // Ferne Clipping-Ebene g_pD3DDevice->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)(&mProjection)); //In Bildpuffer zeichnen 1 g_pD3DDevice->BeginScene(); g_pD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 1, Dreieck, sizeof(SVertex)); g_pD3DDevice->EndScene(); g_pD3DDevice->Present(NULL, NULL, NULL, NULL); return 0; } |
Administrator
C-/C++-Quelltext |
|
1 2 3 4 5 |
if(GetAsyncKeyState(VK_LEFT)) fCameraAngle -= TB_DEG_TO_RAD(45.0f) * fZeit; if(GetAsyncKeyState(VK_RIGHT)) fCameraAngle += TB_DEG_TO_RAD(45.0f) * fZeit; |
Administrator
Administrator
Werbeanzeige