Autor Beitrag
chaoslion Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45


Delphi 2k6 Prof,C,C#,Delphi
BeitragVerfasst: Do 23.03.06 22:32 
Die Seite sieht echt gut aus, bin noch nicht ganz fertig mit lesen..
naja ich stecke im Moment fest, ne simple Ebene zu zeichen, bzw die Fläche.
Ist noch nen bissle buggy :P
[url=img119.imageshack.us...maddeshading3cm.jpg]user defined image[/URL]

wenigstens klappt die rotation jetzt..
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Fr 24.03.06 21:34 
ich bekomme es auch nicht hin, mein koordinatensystem steht auf dem kopf
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
function Projektion(v3d: TVektor3d): TVektor2d;
var
  r1, r2: TVektor3d;
  m3x3: TMatrix3x3;
begin
  m3x3[00] :=               0; m3x3[01] := 0; m3x3[02] := 0;
  m3x3[10] := - (sqrt(2) / 4); m3x3[11] := 1; m3x3[12] := 0;
  m3x3[20] := - (sqrt(2) / 4); m3x3[21] := 0; m3x3[22] := 1;

  matrixrowtovektor_3x3(m3x3, r1, 1);
  matrixrowtovektor_3x3(m3x3, r2, 2);
  
  result.x1 := skalarprodukt_v3d(v3d, r1);
  result.x2 := skalarprodukt_v3d(v3d, r2);
end;

ausblenden volle Höhe Delphi-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:
var
  cube_3d: array [0..9of TVektor3d;
  cube_2d: array [0..9of TVektor2d;

procedure TForm1.Cube;
var
  i, j: integer;
begin
  image1.canvas.Pen.color := clblack;
  cube_3d[0].x1 :=  0; cube_3d[0].x2 :=  0;  cube_3d[0].x3 :=  0;
  cube_3d[1].x1 := 50; cube_3d[1].x2 :=  0;  cube_3d[1].x3 :=  0;
  cube_3d[2].x1 := 50; cube_3d[2].x2 := 50;  cube_3d[2].x3 :=  0;
  cube_3d[3].x1 :=  0; cube_3d[3].x2 := 50;  cube_3d[3].x3 :=  0;
  cube_3d[4].x1 :=  0; cube_3d[4].x2 :=  0;  cube_3d[4].x3 :=  0;
  cube_3d[5].x1 :=  0; cube_3d[5].x2 :=  0;  cube_3d[5].x3 := 50;
  cube_3d[6].x1 := 50; cube_3d[6].x2 :=  0;  cube_3d[6].x3 := 50;
  cube_3d[7].x1 := 50; cube_3d[7].x2 := 50;  cube_3d[7].x3 := 50;
  cube_3d[8].x1 :=  0; cube_3d[8].x2 := 50;  cube_3d[8].x3 := 50;
  cube_3d[9].x1 :=  0; cube_3d[9].x2 :=  0;  cube_3d[9].x3 := 50;
  for i := 0 to 9 do
    cube_2d[i] := Projektion(cube_3d[i]);
  image1.Canvas.MoveTo(image1.Width div 2 + round(cube_2d[0].x1), image1.Height div 2 + round(cube_2d[0].x2));
  for j := 1 to 9 do
    image1.canvas.LineTo(image1.Width div 2 + round(Cube_2d[j].x1), image1.Height div 2 + round(Cube_2d[j].x2));
end;

procedure TForm1.ODraw(x1, x2: double);
begin
  image1.Canvas.MoveTo(image1.Width div 2, image1.Height div 2);
  image1.Canvas.LineTo(image1.Width div 2 + round(x1), image1.Height div 2 + round(x2));
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  v3d_x1: TVektor3d;
  v2d_x1: TVektor2d;
  v3d_x2: TVektor3d;
  v2d_x2: TVektor2d;
  v3d_x3: TVektor3d;
  v2d_x3: TVektor2d;
begin
  image1.Canvas.pen.color := clred;
  v3d_x1.x1 := 200;
  v3d_x1.x2 := 0;
  v3d_x1.x3 := 0;
  v2d_x1 := Projektion(v3d_x1);
  ODraw(v2d_x1.x1, v2d_x1.x2);

  image1.Canvas.pen.color := clblue;
  v3d_x2.x1 := 0;
  v3d_x2.x2 := 100;
  v3d_x2.x3 := 0;
  v2d_x2 := Projektion(v3d_x2);
  ODraw(v2d_x2.x1, v2d_x2.x2);

  image1.Canvas.pen.color := clgreen;
  v3d_x3.x1 := 0;
  v3d_x3.x2 := 0;
  v3d_x3.x3 := 100;
  v2d_x3 := Projektion(v3d_x3);
  ODraw(v2d_x3.x1, v2d_x3.x2);
end;

die perspektive ist komisch, wie bekomme ich das korrekt ?

und wie zeichne ich den würfel einfacher, sodass ich nicht jede zeichenprozedur extra aufrufen muss, und zwar so, dass ich alle striche kriege ?

EDIT: nach langem gebastle:
ausblenden volle Höhe Delphi-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:
procedure TForm1.DrawCubeLine(a, b: integer);
begin
  image1.Canvas.MoveTo(image1.Width div 2 + round(cube_2d[a].x1), image1.Height div 2 + round(cube_2d[a].x2));
  image1.Canvas.LineTo(image1.Width div 2 + round(cube_2d[b].x1), image1.Height div 2 + round(cube_2d[b].x2));
end;

procedure TForm1.Cube;
var
  i, j: integer;
begin
  image1.canvas.Pen.color := clblack;
  cube_3d[0].x1 :=  0; cube_3d[0].x2 :=  0;  cube_3d[0].x3 :=  0;
  cube_3d[1].x1 :=  0; cube_3d[1].x2 := 50;  cube_3d[1].x3 :=  0;
  cube_3d[2].x1 := 50; cube_3d[2].x2 :=  0;  cube_3d[2].x3 :=  0;
  cube_3d[3].x1 := 50; cube_3d[3].x2 := 50;  cube_3d[3].x3 :=  0;
  cube_3d[4].x1 :=  0; cube_3d[4].x2 :=  0;  cube_3d[4].x3 := 50;
  cube_3d[5].x1 :=  0; cube_3d[5].x2 := 50;  cube_3d[5].x3 := 50;
  cube_3d[6].x1 := 50; cube_3d[6].x2 :=  0;  cube_3d[6].x3 := 50;
  cube_3d[7].x1 := 50; cube_3d[7].x2 := 50;  cube_3d[7].x3 := 50;
  for i := 0 to 7 do
    cube_2d[i] := Projektion(cube_3d[i]);
  DrawCubeLine(01);
  DrawCubeLine(02);
  DrawCubeLine(04);
  DrawCubeLine(13);
  DrawCubeLine(15);
  DrawCubeLine(23);
  DrawCubeLine(26);
  DrawCubeLine(37);
  DrawCubeLine(45);
  DrawCubeLine(46);
  DrawCubeLine(57);
  DrawCubeLine(67);
end;

aber mit der perspektive stimmt immer noch etwas nicht
chaoslion Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45


Delphi 2k6 Prof,C,C#,Delphi
BeitragVerfasst: Sa 25.03.06 08:46 
also ich muss ehrlich sagen, ich hab das nicht mit ner Projektionsmatrix gemacht sondern so:

1. das koordinatensystem muss ja nach meiner berechnung ohne rotation so wie das 2d aussehen, also so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
|Y
|
|

Z-------X


du musst es drehen damit es nicht mehr auf dem kopf steht->meine drehrotine

ausblenden volle Höhe Delphi-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:
    function Xrot(vek:TVek3d;winkel:real):TVek3d;
      begin
        result.x:=vek.x;
        result.y:=vek.y*cos(winkel)-vek.z*sin(winkel);
        result.z:=vek.y*sin(winkel)+vek.z*cos(winkel);
    end;

    function Yrot(vek:TVek3d;winkel:real):TVek3d;
      begin
        result.x:=vek.z*sin(winkel)+vek.x*cos(winkel);
        result.y:=vek.y;
        result.z:=vek.z*cos(winkel)-vek.x*sin(winkel);
      end;

    function Zrot(vek:TVek3d;winkel:real):TVek3d;
      begin
        result.x:=vek.x*cos(winkel)-vek.y*sin(winkel);
        result.y:=vek.x*sin(winkel)+vek.y*cos(winkel);
        result.z:=vek.z;
      end;

    function Convert3d2d(vek:TVek3d):TVek3d; //du kannst auch TVek2d nehmen
      begin
        vek:=Xrot(vek,TEMPX);                
        vek:=Yrot(vek,TEMPY);
        vek:=Zrot(vek,TEMPZ);

        result.x:=(vek.x*ZOOM)/(vek.z+ZOOM);
        result.y:=(vek.y*ZOOM)/(vek.z+ZOOM);
        result.z:=0;                          //musst dann z halt weglassen
      end;

//und zeichnen tue ich es so
 procedure ZeichneVektor(vek1,vek2:TVek3d;farbe:Cardinal);
      begin
        vek1:=Convert3d2d(vek1);
        vek2:=Convert3d2d(vek2);
        //line proc ist aus ner engine 
        //wenn du mit canvas von win arbeitest musst du
        //canvas.moveto(NULLX+vek1.x,NULLY-vek1.y);
        //und dann lineto(NULLX+vek2.x,NULLY-vek2.y);

        Canvas.Line(
        NULLX+vek1.x,
        NULLY-vek1.y,
        NULLX+vek2.x,
        NULLY-vek2.y,farbe,farbe,fxBlend);
      end;
Einloggen, um Attachments anzusehen!
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Sa 25.03.06 10:38 
ich möchte aber gerne vektoren und matrizen nehmen, da das ein mathematisches programm wird und eben alles stimmig sein muss ^^, außerdem ist dann die dynamik größer