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
Phili
unregistriert
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 |
#include <fstream> #include <string> #include <D3D9.h> using namespace std; class PHEffekt { public: int sampMenge; int *samp; int *sampWert; int rendMenge; int *rend; int *rendWert; int lichtMenge; D3DLIGHT9 *licht; int matMenge; D3DMATERIAL9 *mat; PHEffekt(int Menge_Sampler, int Menge_Render, int Menge_Licht, bool Material); }; PHEffekt::PHEffekt(int Menge_Sampler, int Menge_Render, int Menge_Licht, bool Material) { sampMenge=Menge_Sampler; samp = new int[Menge_Sampler]; sampWert = new int[Menge_Sampler]; rendMenge=Menge_Render; rend = new int[Menge_Render]; rendWert = new int[Menge_Render]; lichtMenge=Menge_Licht; licht = new D3DLIGHT9[Menge_Licht]; matMenge=Material; mat = new D3DMATERIAL9[Material]; } void PHEffektSpeichern(char *filename, PHEffekt eff) { ofstream ofs(filename); ofs<<"Start Sampler"<<endl; for(int i = 0; i < eff.sampMenge; i++) { ofs<<eff.samp[i]<<" "<<eff.sampWert[i]<<endl; } ofs<<"Start Render"<<endl; for(i = 0; i < eff.rendMenge; i++) { ofs<<eff.rend[i]<<" "<<eff.rendWert[i]<<endl; } ofs<<"Start Licht"<<endl; for(i = 0; i < eff.lichtMenge; i++) { ofs<<eff.licht[i].Type<<endl; ofs<<eff.licht[i].Diffuse.r<<" "<<eff.licht[i].Diffuse.g<<" "<<eff.licht[i].Diffuse.b<<endl; ofs<<eff.licht[i].Specular.r<<" "<<eff.licht[i].Specular.g<<" "<<eff.licht[i].Specular.b<<endl; ofs<<eff.licht[i].Ambient.r<<" "<<eff.licht[i].Ambient.g<<" "<<eff.licht[i].Ambient.b<<endl; ofs<<eff.licht[i].Position.x<<" "<<eff.licht[i].Position.y<<" "<<eff.licht[i].Position.z<<endl; ofs<<eff.licht[i].Direction.x<<" "<<eff.licht[i].Direction.y<<" "<<eff.licht[i].Direction.z<<endl; ofs<<eff.licht[i].Range<<endl; ofs<<eff.licht[i].Falloff<<endl; ofs<<eff.licht[i].Attenuation0<<" "<<eff.licht[i].Attenuation1<<" "<<eff.licht[i].Attenuation2<<endl; ofs<<eff.licht[i].Theta<<" "<<eff.licht[i].Phi<<endl; } ofs<<"Start Material"<<endl; for(i = 0; i < eff.matMenge; i++) { ofs<<eff.mat[i].Diffuse.r<<" "<<eff.mat[i].Diffuse.g<<" "<<eff.mat[i].Diffuse.b<<endl; ofs<<eff.mat[i].Ambient.r<<" "<<eff.mat[i].Ambient.g<<" "<<eff.mat[i].Ambient.b<<endl; ofs<<eff.mat[i].Specular.r<<" "<<eff.mat[i].Specular.g<<" "<<eff.mat[i].Specular.b<<endl; ofs<<eff.mat[i].Emissive.r<<" "<<eff.mat[i].Emissive.g<<" "<<eff.mat[i].Emissive.b<<endl; ofs<<eff.mat[i].Power<<endl;; } ofs<<"Ende"; } void PHEffektLaden(char *filename, PHEffekt *eff) { ifstream ifs(filename); string str; while(1) { ifs>>str; if(str == "Start") { ifs>>str; if(str == "Sampler") { for(int i = 0; i < eff->sampMenge; i++) { ifs>>eff->samp[i]; ifs>>eff->sampWert[i]; } } if(str == "Render") { for(int i = 0; i < eff->rendMenge; i++) { ifs>>eff->rend[i]; ifs>>eff->rendWert[i]; } } if(str == "Licht") { int typ; for(int i = 0; i < eff->lichtMenge; i++) { ifs>>typ; ZeroMemory(&eff->licht[i], sizeof(D3DLIGHT9)); eff->licht[i].Type = (D3DLIGHTTYPE)(typ); ifs>>eff->licht[i].Diffuse.r; ifs>>eff->licht[i].Diffuse.g; ifs>>eff->licht[i].Diffuse.b; ifs>>eff->licht[i].Specular.r; ifs>>eff->licht[i].Specular.g; ifs>>eff->licht[i].Specular.b; ifs>>eff->licht[i].Ambient.r; ifs>>eff->licht[i].Ambient.g; ifs>>eff->licht[i].Ambient.b; ifs>>eff->licht[i].Position.x; ifs>>eff->licht[i].Position.y; ifs>>eff->licht[i].Position.z; ifs>>eff->licht[i].Direction.x; ifs>>eff->licht[i].Direction.y; ifs>>eff->licht[i].Direction.z; ifs>>eff->licht[i].Range; ifs>>eff->licht[i].Falloff; ifs>>eff->licht[i].Attenuation0; ifs>>eff->licht[i].Attenuation1; ifs>>eff->licht[i].Attenuation2; ifs>>eff->licht[i].Theta; ifs>>eff->licht[i].Phi; } } if(str == "Material") { for(int i = 0; i < eff->matMenge; i++) { ifs>>eff->mat[i].Diffuse.r; ifs>>eff->mat[i].Diffuse.g; ifs>>eff->mat[i].Diffuse.b; ifs>>eff->mat[i].Ambient.r; ifs>>eff->mat[i].Ambient.g; ifs>>eff->mat[i].Ambient.b; ifs>>eff->mat[i].Specular.r; ifs>>eff->mat[i].Specular.g; ifs>>eff->mat[i].Specular.b; ifs>>eff->mat[i].Emissive.r; ifs>>eff->mat[i].Emissive.g; ifs>>eff->mat[i].Emissive.b; ifs>>eff->mat[i].Power; } } } if(str == "Ende") { return; } } } void PHEffektAktivieren(PHEffekt eff, IDirect3DDevice9 *D3DDev) { for(int i = 0; i < eff.lichtMenge; i++) { D3DDev->SetLight(i, eff.licht); D3DDev->LightEnable(i, TRUE); } for(i = 0; i < eff.matMenge; i++) { D3DDev->SetMaterial(&eff.mat[i]); } for(i = 0; i < eff.rendMenge; i++) { D3DDev->SetRenderState((D3DRENDERSTATETYPE)(eff.rend[i]), eff.rendWert[i]); } for(i = 0; i < eff.sampMenge; i++) { D3DDev->SetSamplerState(0, (D3DSAMPLERSTATETYPE)(eff.samp[i]), eff.sampWert[i]); } } |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
Start Material 0.75 0.75 0.75 0.25 0.25 0.25 0.0 0.0 0.0 1 1 1 1 Start Licht 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1000 0 0 0.25 0 0 0 Ende |
C-/C++-Quelltext |
|
1 2 3 |
PHEffekt eff(0, 0, 1, 1); PHEffektLaden("a.txt", &eff); PHEffektAktivieren(eff, D3DDev); |
Anonymous
unregistriert
Phili
unregistriert
C-/C++-Quelltext |
|
1 |
PHEffektSpeichern("a2.txt", eff);
|
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Start Sampler Start Render Start Licht 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1000 0 0 0.25 0 0 0 Start Material 0.75 0.75 0.75 0.25 0.25 0.25 0 0 0 1 1 1 1 Ende |
Phili
unregistriert
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 |
#include "PHENGINE.hpp" #include <MMSystem.h> #include <time.h> IDirect3DDevice9 *D3DDev; IDirect3DTexture9 *tex; MSG msg; HWND hwnd; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLie, int nShowCmd) { D3DDev = PHDirect3DErstellen(hInstance, hwnd, 1024, 768, "FarCry"); PHEffekt eff(0, 0, 1, 1); PHEffektLaden("a.txt", &eff); PHEffektSpeichern("a2.txt", eff); PHEffektAktivieren(eff, D3DDev); PHModel Ich(3); PHModelLaden("b.txt", &Ich); PHModelSpeichern("b2.txt", Ich); PHModelVertexBufferErstellen(&Ich, D3DDev); D3DXCreateTextureFromFile(D3DDev, "Tex1.bmp", &tex); D3DDev->SetTexture(0, tex); float geschx=0; float geschy=0; double zeit1 = 0; double zeit2 = 0; double zeit = 0; while(TRUE) { if(GetAsyncKeyState(VK_RIGHT)){geschx += (0.1*zeit);} if(GetAsyncKeyState(VK_LEFT)){geschx -= (0.1*zeit);}; if(geschx>0) geschx-=(0.01*zeit); if(geschx<0) geschx+=(0.01*zeit); Ich.position[0] += geschx; if(GetAsyncKeyState(VK_UP)){Ich.position[1] += (1*zeit); geschy += (0.1*zeit);} if(GetAsyncKeyState(VK_DOWN)){Ich.position[1] -= (1*zeit); geschy -= (0.1*zeit);}; if(geschy>0) geschy-=(0.01*zeit); if(geschy<0) geschy+=(0.01*zeit); Ich.position[1] += geschy; while(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } D3DDev->BeginScene(); D3DDev->Clear(0, 0, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 100, 1, 1); PHModelDarstellen(&Ich, D3DDev); D3DDev->EndScene(); D3DDev->Present(0, 0, 0, 0); zeit2 = zeit1; zeit1 = timeGetTime(); zeit = (zeit1 - zeit2)/1000; } return 0; } |
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 |
#include <windows.h> #include <StdIO.h> #include <fstream> using namespace std; #include "PHModel.hpp" #include "PHEffekt.hpp" IDirect3DDevice9 *PHDirect3DErstellen(HINSTANCE hInstance, HWND hwnd, int FensterX, int FensterY, LPSTR Name) { IDirect3DDevice9 *D3DDev; WNDCLASSEX wndclassex; D3DPRESENT_PARAMETERS pp; IDirect3D9 *D3D; wndclassex.cbClsExtra=NULL; wndclassex.cbSize=sizeof(WNDCLASSEX); wndclassex.cbWndExtra=NULL; wndclassex.hbrBackground=(HBRUSH)(COLOR_WINDOW); wndclassex.hCursor=NULL; wndclassex.hIcon=NULL; wndclassex.hIconSm=NULL; wndclassex.hInstance=hInstance; wndclassex.lpfnWndProc=DefWindowProc; wndclassex.lpszClassName="Philip"; wndclassex.lpszMenuName=NULL; wndclassex.style=CS_CLASSDC; RegisterClassEx(&wndclassex); hwnd = CreateWindowEx(NULL, "Philip", Name, WS_VISIBLE|WS_OVERLAPPEDWINDOW, 0, 0, 1024, 768, NULL, NULL, hInstance, NULL); D3D = Direct3DCreate9(D3D_SDK_VERSION); ZeroMemory(&pp, sizeof(D3DPRESENT_PARAMETERS)); pp.BackBufferWidth = FensterX; pp.BackBufferHeight = FensterY; pp.BackBufferFormat = D3DFMT_X8R8G8B8; pp.BackBufferCount = 1; pp.MultiSampleType = D3DMULTISAMPLE_NONE; pp.MultiSampleQuality = 0; pp.hDeviceWindow = hwnd; pp.Windowed = FALSE; pp.SwapEffect = D3DSWAPEFFECT_DISCARD; pp.FullScreen_RefreshRateInHz = 0; pp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; pp.EnableAutoDepthStencil = 1; pp.AutoDepthStencilFormat = D3DFMT_D16; D3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &pp, &D3DDev); D3DXMATRIX mat; D3DXMatrixPerspectiveFovLH(&mat, 2.09f, 1.333f, 0.1f, 100); D3DDev->SetTransform(D3DTS_PROJECTION, &mat); D3DDev->SetFVF(D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1); return D3DDev; } |
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 |
#include <fstream> #include <string> #include <D3D9.h> #include <D3DX9.h> using namespace std; struct Vertex { float Pos[3]; float Norm[3]; float Tex[2]; }; class PHModel { public: float position[3]; int menge; Vertex *vert; IDirect3DVertexBuffer9 *buffer; PHModel(int M); }; PHModel::PHModel(int M) { PHModel::vert = new Vertex[M]; PHModel::menge = M; for(int i = 0; i < PHModel::menge; i++) { PHModel::vert[i].Pos[0] = 0; PHModel::vert[i].Pos[1] = 0; PHModel::vert[i].Pos[2] = 0; PHModel::vert[i].Tex[0] = 0; PHModel::vert[i].Tex[1] = 0; } PHModel::position[0] = 0; PHModel::position[1] = 0; PHModel::position[2] = 0; } void PHModelSpeichern(char *filename, PHModel mod) { ofstream ofs(filename); ofs<<"Menge der Vertizies: "<<mod.menge<<endl; ofs<<"Start Position"<<endl; for(int i = 0; i < mod.menge; i++) { ofs<<mod.vert[i].Pos[0]<<" "; ofs<<mod.vert[i].Pos[1]<<" "; ofs<<mod.vert[i].Pos[2]<<endl; } ofs<<"Start Textur"<<endl; for(i = 0; i < mod.menge; i++) { ofs<<mod.vert[i].Tex[0]<<" "; ofs<<mod.vert[i].Tex[1]<<endl; } ofs<<"Start Normal"<<endl; for(i = 0; i < mod.menge; i++) { ofs<<mod.vert[i].Norm[0]<<" "; ofs<<mod.vert[i].Norm[1]<<" "; ofs<<mod.vert[i].Norm[2]<<endl; } ofs<<"Ende"; } void PHModelLaden(char *filename, PHModel *mod) { ifstream ifs(filename); string str; while(1) { ifs>>str; if(str == "Start") { ifs>>str; if(str == "Position") { for(int i = 0; i < mod->menge; i++) { ifs>>mod->vert[i].Pos[0]; ifs>>mod->vert[i].Pos[1]; ifs>>mod->vert[i].Pos[2]; } } if(str == "Textur") { for(int i = 0; i < mod->menge; i++) { ifs>>mod->vert[i].Tex[0]; ifs>>mod->vert[i].Tex[1]; } } if(str == "Normal") { for(int i = 0; i < mod->menge; i++) { ifs>>mod->vert[i].Norm[0]; ifs>>mod->vert[i].Norm[1]; ifs>>mod->vert[i].Norm[2]; } } } if(str == "Ende") { return; } } } void PHModelVertexBufferErstellen(PHModel *mod, IDirect3DDevice9 *D3DDev) { D3DDev->CreateVertexBuffer((mod->menge * sizeof(Vertex)), 0, (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1), D3DPOOL_MANAGED, &mod->buffer, NULL); Vertex *verte; mod->buffer->Lock(0, 0, (void**)(&verte), 0); for(int i = 0; i < mod->menge; i ++) { verte[i].Pos[0] = mod->vert[i].Pos[0]; verte[i].Pos[1] = mod->vert[i].Pos[1]; verte[i].Pos[2] = mod->vert[i].Pos[2]; verte[i].Tex[0] = mod->vert[i].Tex[0]; verte[i].Tex[1] = mod->vert[i].Tex[1]; } mod->buffer->Unlock(); } void PHModelDarstellen(PHModel *mod, IDirect3DDevice9 *D3DDev) { D3DXMATRIX mat; D3DXMatrixTranslation(&mat, mod->position[0], mod->position[1], mod->position[2]); D3DDev->SetTransform(D3DTS_WORLD, &mat); D3DDev->SetStreamSource(0, mod->buffer, 0, sizeof(Vertex)); int Menge = mod->menge/3; D3DDev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, Menge); } |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Start Position 0 -0.5 2 0 0.5 2 0.7 0 2 Start Textur 0 1 1 1 0.5 0 Start Normal 0 0 -1 0 0 -1 0 0 -1 Ende |
Phili
unregistriert
Phili
unregistriert
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
void PHModelVertexBufferErstellen(PHModel *mod, IDirect3DDevice9 *D3DDev) { D3DDev->CreateVertexBuffer((mod->menge * sizeof(Vertex)), 0, (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1), D3DPOOL_MANAGED, &mod->buffer, NULL); Vertex *verte; mod->buffer->Lock(0, 0, (void**)(&verte), 0); for(int i = 0; i < mod->menge; i ++) { verte[i].Pos[0] = mod->vert[i].Pos[0]; verte[i].Pos[1] = mod->vert[i].Pos[1]; verte[i].Pos[2] = mod->vert[i].Pos[2]; verte[i].Tex[0] = mod->vert[i].Tex[0]; verte[i].Tex[1] = mod->vert[i].Tex[1]; } mod->buffer->Unlock(); } |
Werbeanzeige