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
Anonymous
unregistriert
Quellcode |
|
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 |
#include <d3d9.h> typedef struct _MATERIAL { char MaterialName[32]; D3DMATERIAL9 Material; char TextureName[24]; } MATERIAL; typedef struct _MATERIALLIST { MATERIAL *data; struct _MATERIALLIST *next; } MATERIALLIST; typedef enum _RESULT { LIST_ERROR=0, LIST_OK =1, } RESULT; MATERIALLIST *Materialliste; //Materialliste erzeugen mit RAM initialisierung RESULT MaterialListCreate(void) { Materialliste = (MATERIALLIST*)malloc(sizeof(MATERIALLIST)); if(Materialliste == NULL) return LIST_ERROR; Materialliste->data = NULL; Materialliste->next = NULL; return LIST_OK; } //Einfügen am Anfang der Materialliste RESULT MaterialListInsert(MATERIAL *data) { MATERIALLIST *Newelement; //neues Listenelement //1. Fall: Einfügen in leere Liste if(Materialliste->data == NULL) { Materialliste->data = data; return LIST_OK; } //2. Fall: Einfügen in nicht-leere Liste Newelement = (MATERIALLIST*)malloc(sizeof(MATERIALLIST)); //Fehler bei Initialisierung if(Newelement == NULL) return LIST_ERROR; else { //Daten speichern, Zeiger setzen Newelement->data = data; Newelement->next = Materialliste; Materialliste = Newelement; return LIST_OK; } } //Löschen an angegebener Position, Start bei index 0 RESULT MaterialListDelete(int index) { MATERIALLIST *temp, *prev; //1. Fall: Leere Liste if((Materialliste == NULL) || (Materialliste->data == NULL)) return LIST_ERROR; //2. Fall: Erstes Element löschen if(index == 0) { //Erstes Element übergehen und Speicher freigeben temp = Materialliste; Materialliste = Materialliste->next; free(temp); return LIST_OK; } //3. Fall: 2., 3., ... Element löschen temp = Materialliste; //Liste durchlaufen bis index erreicht oder Liste zu Ende while((Materialliste->next != NULL) && (index != 0)) { //Vorgängerelement merken und weitergehen prev = Materialliste; Materialliste = Materialliste->next; index--; } //Index wurde nicht gefunden -> Liste zu kurz if(index != 0) { Materialliste = temp; return LIST_ERROR; } //Gefundenes Element übergehen und Speicher freigeben prev->next = Materialliste->next; free(Materialliste); Materialliste = temp; return LIST_OK; } //Länge der Materialliste int MaterialListLength(void) { MATERIALLIST *temp; int Lenght=0; if(Materialliste == NULL || Materialliste->data == NULL) return Lenght; Lenght=1; temp = Materialliste; while(temp->next != NULL) { Lenght++; temp = temp->next; } return Lenght; } |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
//Suchen des Materialindex mithilfe des Namens int MaterialListSearch(char Name[32]) { MATERIALLIST *temp; int Index=0; //Leere Liste if(Materialliste == NULL || Materialliste->data==NULL) return -1; temp = Materialliste; while(temp->next != NULL) { if(temp->data->MaterialName==Name) return Index; Index++; temp = temp->next; } return -1; } |
Quellcode |
|
1 |
if(temp->data->MaterialName==Name) |
Quellcode |
|
1 |
char Name[32] |
Quellcode |
|
1 |
const char* Name |
Quellcode |
|
1 |
if(strcmp(temp->data->MaterialName,Name)==0) ... |
Zitat
while(temp->next != NULL)
{
...
}
Anonymous
unregistriert
Quellcode |
|
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 |
//Suchen des Materialindex mithilfe des Namens int MaterialListSearch(const char* Name) { MATERIALLIST *temp; int Index=0; //Leere Liste if(Materialliste == NULL || Materialliste->data==NULL) return -1; if(strcmp(Materialliste->data->MaterialName,Name)==0) return Index; temp = Materialliste; while(temp->next != NULL) { Index++; temp = temp->next; if(strcmp(temp->data->MaterialName,Name)==0) return Index; } return -1; } |
Quellcode |
|
1 2 3 4 5 6 7 8 |
0: ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌtõ 1: ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌtõ 2: ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌtõ 3: ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌtõ 4: ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌtõ 5: ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌtõ 6: ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌtõ 7: ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌtõ |
Quellcode |
|
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 |
MATERIAL AktMaterial; [b]char MaterialName[32];[/b] char TextureShortName[24]; //Wurde bereits definiert DWORD DiffuseColor; //Wurde bereits definiert DWORD AmbientColor; //Wurde bereits definiert DWORD SpecularColor; //Wurde bereits definiert DWORD EmissiveColor; //Wurde bereits definiert [b]MaterialName[0]=32; SendDlgItemMessage(hDlg, ROM_MM_NAME, EM_GETLINE, 0, (LPARAM)(MaterialName)); if(MaterialListSearch(MaterialName)!=-1) { MSGERR(NULL, "Ein Material mit diesem Namen ist schon vorhanden. Bitte ändern sie den Namen des Materials."); break; }[/b] AktMaterial.Material.Diffuse.r=(float)(GetRValue(DiffuseColor))/255; AktMaterial.Material.Diffuse.g=(float)(GetGValue(DiffuseColor))/255; AktMaterial.Material.Diffuse.b=(float)(GetBValue(DiffuseColor))/255; AktMaterial.Material.Diffuse.a=(float)(SendDlgItemMessage(hDlg, ROM_MM_DIFFUSE_ALPHA_CHOOSE, TBM_GETPOS, 0, 0))/255; AktMaterial.Material.Ambient.r=(float)(GetRValue(AmbientColor))/255; AktMaterial.Material.Ambient.g=(float)(GetGValue(AmbientColor))/255; AktMaterial.Material.Ambient.b=(float)(GetBValue(AmbientColor))/255; AktMaterial.Material.Ambient.a=(float)(SendDlgItemMessage(hDlg, ROM_MM_AMBIENT_ALPHA_CHOOSE, TBM_GETPOS, 0, 0))/255; AktMaterial.Material.Specular.r=(float)(GetRValue(SpecularColor))/255; AktMaterial.Material.Specular.g=(float)(GetGValue(SpecularColor))/255; AktMaterial.Material.Specular.b=(float)(GetBValue(SpecularColor))/255; AktMaterial.Material.Specular.a=(float)(SendDlgItemMessage(hDlg, ROM_MM_SPECULAR_ALPHA_CHOOSE, TBM_GETPOS, 0, 0))/255; AktMaterial.Material.Emissive.r=(float)(GetRValue(EmissiveColor))/255; AktMaterial.Material.Emissive.g=(float)(GetGValue(EmissiveColor))/255; AktMaterial.Material.Emissive.b=(float)(GetBValue(EmissiveColor))/255; AktMaterial.Material.Emissive.a=(float)(SendDlgItemMessage(hDlg, ROM_MM_EMISSIVE_ALPHA_CHOOSE, TBM_GETPOS, 0, 0))/255; AktMaterial.Material.Power=(float)(SendDlgItemMessage(hDlg, ROM_MM_SHARPNESS_CHOOSE, TBM_GETPOS, 0, 0)/255); [b]strcpy(AktMaterial.MaterialName, MaterialName);[/b] strcpy(AktMaterial.TextureName, TextureShortName); [b]MaterialListInsert(&AktMaterial); SendDlgItemMessage(hDlg, ROM_MM_LIST, LB_ADDSTRING, 0, (LPARAM)(MaterialName));[/b] break; |
Quellcode |
|
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 |
//Einfügen am Anfang der Materialliste RESULT MaterialListInsert(MATERIAL *data) { MATERIALLIST *Newelement; //neues Listenelement MATERIAL *Material; Material = (MATERIAL*)malloc(sizeof(MATERIAL)); //1. Fall: Einfügen in leere Liste if(Materialliste->data == NULL) { memcpy(Material, data, sizeof(MATERIAL)); Materialliste->data = Material; return LIST_OK; } //2. Fall: Einfügen in nicht-leere Liste Newelement = (MATERIALLIST*)malloc(sizeof(MATERIALLIST)); //Fehler bei Initialisierung if(Newelement == NULL) return LIST_ERROR; else { //Daten speichern, Zeiger setzen memcpy(Material, data, sizeof(MATERIAL)); Newelement->data = Material; Newelement->next = Materialliste; Materialliste = Newelement; return LIST_OK; } } |
Werbeanzeige