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: 344:
| unit DXQuad;
interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, DirectX;
const EckZahl = 8; SeitenZahl = 6; VertexZahl = 24; xAchse = 1; yAchse = 2; zAchse = 3;
function GetD3DVector (x, y, z: TD3DValue): TD3DVector; function GetD3DVertex (Ecke, Seite: TD3DVector; texU, texV: TD3DValue): TD3DVertex;
type TD3DPoly = class QEck : Array[1..EckZahl] of TD3DVector; QSeite: Array[1..SeitenZahl] of TD3DVector; Vertex: Array[1..VertexZahl] of TD3DVertex; Tx : Array[0..1] of TD3DValue; isRoom: Boolean; constructor Create; procedure SetVectors; procedure SetVertices; end;
TD3DKoords = class WorldMatrix, ViewMatrix, ProjectionMatrix: TD3DMatrix; ViewVector, TurnVector, LeftXRight, DownYUp, BackZFront: TD3DVector; constructor Create; procedure SetMatrices; procedure SetRotation (Achse: Integer); procedure SetScale (xMal, yMal, zMal: TD3DValue); procedure SetShift (xDiff, yDiff, zDiff: TD3DValue); procedure SetView (Winkel: TD3DValue; isRoom: Boolean); procedure SetView2; procedure SetTurn (Achse: Integer; isRoom: Boolean); procedure SetTurn2 (Achse: Integer; isRoom: Boolean); end;
implementation
function GetD3DVector(x, y, z: TD3DValue): TD3DVector; begin Result.x := x; Result.y := y; Result.z := z; end;
function GetD3DVertex (Ecke, Seite: TD3DVector; texU, texV: TD3DValue): TD3DVertex; begin with Result do begin x := Ecke.x; nx := Seite.x; y := Ecke.y; ny := Seite.y; z := Ecke.z; nz := Seite.z; tu := texU; tv := texV; end; end;
constructor TD3DPoly.Create; begin Tx[0] := 0.0; Tx[1] := 1.0; SetVectors; SetVertices; isRoom := false; end;
procedure TD3DPoly.SetVectors; begin QEck[1] := GetD3DVector (-1.0, 1.0,-1.0); QEck[2] := GetD3DVector ( 1.0, 1.0,-1.0); QEck[3] := GetD3DVector ( 1.0,-1.0,-1.0); QEck[4] := GetD3DVector (-1.0,-1.0,-1.0); QEck[5] := GetD3DVector (-1.0, 1.0, 1.0); QEck[6] := GetD3DVector ( 1.0, 1.0, 1.0); QEck[7] := GetD3DVector ( 1.0,-1.0, 1.0); QEck[8] := GetD3DVector (-1.0,-1.0, 1.0); QSeite[1] := GetD3DVector ( 0.0, 0.0,-1.0); QSeite[2] := GetD3DVector ( 0.0, 0.0, 1.0); QSeite[3] := GetD3DVector (-1.0, 0.0, 0.0); QSeite[4] := GetD3DVector ( 1.0, 0.0, 0.0); QSeite[5] := GetD3DVector ( 0.0, 1.0, 0.0); QSeite[6] := GetD3DVector ( 0.0,-1.0, 0.0); end;
procedure TD3DPoly.SetVertices; begin Vertex[1] := GetD3DVertex (QEck[1], QSeite[1], Tx[0], Tx[0]); Vertex[2] := GetD3DVertex (QEck[2], QSeite[1], Tx[0], Tx[1]); Vertex[3] := GetD3DVertex (QEck[4], QSeite[1], Tx[1], Tx[0]); Vertex[4] := GetD3DVertex (QEck[3], QSeite[1], Tx[1], Tx[1]); Vertex[5] := GetD3DVertex (QEck[5], QSeite[2], Tx[0], Tx[0]); Vertex[6] := GetD3DVertex (QEck[8], QSeite[2], Tx[0], Tx[1]); Vertex[7] := GetD3DVertex (QEck[6], QSeite[2], Tx[1], Tx[0]); Vertex[8] := GetD3DVertex (QEck[7], QSeite[2], Tx[1], Tx[1]); Vertex[9] := GetD3DVertex (QEck[1], QSeite[3], Tx[0], Tx[0]); Vertex[10] := GetD3DVertex (QEck[4], QSeite[3], Tx[0], Tx[1]); Vertex[11] := GetD3DVertex (QEck[5], QSeite[3], Tx[1], Tx[0]); Vertex[12] := GetD3DVertex (QEck[8], QSeite[3], Tx[1], Tx[1]); Vertex[13] := GetD3DVertex (QEck[2], QSeite[4], Tx[0], Tx[0]); Vertex[14] := GetD3DVertex (QEck[6], QSeite[4], Tx[0], Tx[1]); Vertex[15] := GetD3DVertex (QEck[3], QSeite[4], Tx[1], Tx[0]); Vertex[16] := GetD3DVertex (QEck[7], QSeite[4], Tx[1], Tx[1]); Vertex[17] := GetD3DVertex (QEck[5], QSeite[5], Tx[0], Tx[0]); Vertex[18] := GetD3DVertex (QEck[6], QSeite[5], Tx[0], Tx[1]); Vertex[19] := GetD3DVertex (QEck[1], QSeite[5], Tx[1], Tx[0]); Vertex[20] := GetD3DVertex (QEck[2], QSeite[5], Tx[1], Tx[1]); Vertex[21] := GetD3DVertex (QEck[8], QSeite[6], Tx[0], Tx[0]); Vertex[22] := GetD3DVertex (QEck[4], QSeite[6], Tx[0], Tx[1]); Vertex[23] := GetD3DVertex (QEck[7], QSeite[6], Tx[1], Tx[0]); Vertex[24] := GetD3DVertex (QEck[3], QSeite[6], Tx[1], Tx[1]); end;
constructor TD3DKoords.Create; begin SetMatrices; ViewVector := GetD3DVector (0.0, 0.0, 5.0); TurnVector := GetD3DVector (0.0, 0.0, 5.0); LeftXRight := GetD3DVector (1.0, 0.0, 0.0); DownYUp := GetD3DVector (0.0, 1.0, 0.0); BackZFront := GetD3DVector (0.0, 0.0, 1.0); end;
procedure TD3DKoords.SetMatrices; begin FillChar (WorldMatrix, SizeOf(WorldMatrix), 0); with WorldMatrix do begin _11 := 1.0; _22 := 1.0; _33 := 1.0; _44 := 1.0; end; FillChar (ViewMatrix, SizeOf(ViewMatrix), 0); with ViewMatrix do begin _11 := 1.0; _22 := 1.0; _23 := -0.5; _32 := 0.5; _33 := 1.0; _43 := 5.0; _44 := 1.0; end; FillChar (ProjectionMatrix, SizeOf(ProjectionMatrix), 0); with ProjectionMatrix do begin _11 := 2.0; _22 := 2.0; _33 := 1.0; _34 := 1.0; _43 := -1.0; end; end;
procedure TD3DKoords.SetRotation (Achse: Integer); var Zeit: Extended; sinQ, cosQ: TD3DValue; begin Zeit := GetTickCount/1000; if Achse < 0 then begin Achse := -Achse; Zeit := -Zeit; end; sinQ := sin (Zeit); cosQ := cos (Zeit); FillChar (WorldMatrix, SizeOf(WorldMatrix), 0); with WorldMatrix do begin case Achse of xAchse: begin _11 := 1.0; _22 := cosQ; _23 := sinQ; _32 := -sinQ; _33 := cosQ; _44 := 1.0; end; yAchse: begin _11 := cosQ; _13 := -sinQ; _22 := 1.0; _31 := sinQ; _33 := cosQ; _44 := 1.0; end; zAchse: begin _11 := cosQ; _12 := sinQ; _21 := -sinQ; _22 := cosQ; _33 := 1.0; _44 := 1.0; end else begin _11 := 1.0; _22 := 1.0; _33 := 1.0; _44 := 1.0; end; end; end; end;
procedure TD3DKoords.SetScale (xMal, yMal, zMal: TD3DValue); begin with WorldMatrix do begin _11 := _11 * xMal; _22 := _22 * yMal; _33 := _33 * zMal; end; end;
procedure TD3DKoords.SetShift (xDiff, yDiff, zDiff: TD3DValue); begin with WorldMatrix do begin _41 := _41 + xDiff; _42 := _42 + yDiff; _43 := _43 + zDiff; end; end;
procedure TD3DKoords.SetView (Winkel: TD3DValue; isRoom: Boolean); begin with ViewMatrix do begin if isRoom then _11 := -1.0 else _11 := 1.0; _22 := cos(Winkel*Pi/180); _23 := -sin(Winkel*Pi/180); _32 := sin(Winkel*Pi/180); _33 := cos(Winkel*Pi/180); _41 := ViewVector.x; _42 := ViewVector.y; _43 := ViewVector.z; end; end;
procedure TD3DKoords.SetTurn (Achse: Integer; isRoom: Boolean); begin with ViewMatrix do begin case Achse of yAchse: begin if isRoom then begin _11 := -cos(TurnVector.y); _31 := -sin(TurnVector.y); end else begin _11 := cos(TurnVector.y); _31 := sin(TurnVector.y); end; _13 := -sin(TurnVector.y); _33 := cos(TurnVector.y); end; zAchse: _43 := ViewVector.z; end; end; end;
procedure TD3DKoords.SetView2; begin with ViewMatrix do begin _11 := LeftXRight.x; _12 := DownYUp.x; _13 := BackZFront.x; _21 := LeftXRight.y; _22 := DownYUp.y; _23 := BackZFront.y; _31 := LeftXRight.z; _32 := DownYUp.z; _33 := BackZFront.z; _41 := VectorDotProduct (ViewVector, LeftXRight); _42 := VectorDotProduct (ViewVector, DownYUp); _43 := VectorDotProduct (ViewVector, BackZFront); end; end;
procedure TD3DKoords.SetTurn2 (Achse: Integer; isRoom: Boolean); begin case Achse of xAchse: begin end; yAchse: begin if isRoom then begin LeftXRight.x := -cos(TurnVector.y); LeftXRight.z := -sin(TurnVector.y); end else begin LeftXRight.x := cos(TurnVector.y); LeftXRight.z := sin(TurnVector.y); end; BackZFront.x := -sin(TurnVector.y); BackZFront.z := cos(TurnVector.y); end; zAchse: begin end; end; SetView2; end;
end. |