AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Dreidimensionales Array darstellen.

Ein Thema von Muellermilchtrinker · begonnen am 11. Aug 2010 · letzter Beitrag vom 24. Aug 2010
Antwort Antwort
Seite 3 von 5     123 45      
Benutzerbild von Muellermilchtrinker
Muellermilchtrinker

Registriert seit: 1. Aug 2009
447 Beiträge
 
Delphi 2009 Professional
 
#21

AW: Dreidimensionales Array darstellen.

  Alt 19. Aug 2010, 19:04
Zum ändern/erstellen der Muster hab ich ja die Ebenen, die ich dann durchschalten kann.
Ich möchte aber noch eine 3D Ansicht machen, damit man das Muster auch "real" sieht.
Chuck Norris doesn't need backups. He just uploads his files and lets the world mirror them.
  Mit Zitat antworten Zitat
Jens01

Registriert seit: 14. Apr 2009
670 Beiträge
 
#22

AW: Dreidimensionales Array darstellen.

  Alt 20. Aug 2010, 10:34
Okay, bis dahin.
Meld Dich auch bei DGL an, die Leute sind richtig fit bei OpenGL.

Und sag, was ist Urlaub!?
  Mit Zitat antworten Zitat
Benutzerbild von Muellermilchtrinker
Muellermilchtrinker

Registriert seit: 1. Aug 2009
447 Beiträge
 
Delphi 2009 Professional
 
#23

AW: Dreidimensionales Array darstellen.

  Alt 24. Aug 2010, 11:32
Und sag, was ist Urlaub!?
Weißt du das nicht??? Man geht da in ein anderes Land/Gebiet/Stadt und entspannt sich dort.

Aber back to topic:

PROBLEM GELÖST
Ich hab das Problem gelöst (ohne gluOrtho2D ). Mir wurde auf DGL geraten diese Zeile:
gluPerspective(45.0, ClientWidth/ClientHeight, NearClipping, FarClipping); durch diese Zeile zu ersetzen:
gluPerspective(45.0, panel1.ClientWidth/panel1.ClientHeight, NearClipping, FarClipping); Und es hat geklappt. Begründung: mit meinem vorherigen Code hab ich alles auf die Formulargröße gesetzt. MIt diesem Code mach ich das auf mein Panel und das ist ja so schön quadratisch. Und jetzt ist mein Würfel ein Würfel.

Weiter gehts:

Ich hab mir jetzt diese Prozedur geschrieben:
Delphi-Quellcode:
procedure TForm1.Cube(Color:Integer);
begin
    if Color <> 0 then glColor4f(0.5, 0.5, 1.0, 0.8) // Set The Color
    else glColor4f(0.3, 0.3, 0.3, 0.4);
      glVertex3f( 1.0, 1.0,-1.0);         // Top Right Of The Quad (Top)
      glVertex3f(-1.0, 1.0,-1.0);         // Top Left Of The Quad (Top)
      glVertex3f(-1.0, 1.0, 1.0);         // Bottom Left Of The Quad (Top)
      glVertex3f( 1.0, 1.0, 1.0);         // Bottom Right Of The Quad (Top)

    if Color <> 0 then glColor4f(0.5, 0.5, 1.0, 0.8) // Set The Color
    else glColor4f(0.3, 0.3, 0.3, 0.4);
      glVertex3f( 1.0,-1.0, 1.0);         // Top Right Of The Quad (Bottom)
      glVertex3f(-1.0,-1.0, 1.0);         // Top Left Of The Quad (Bottom)
      glVertex3f(-1.0,-1.0,-1.0);         // Bottom Left Of The Quad (Bottom)
      glVertex3f( 1.0,-1.0,-1.0);         // Bottom Right Of The Quad (Bottom)

    if Color <> 0 then glColor4f(0.5, 0.5, 1.0, 0.8) // Set The Color
    else glColor4f(0.3, 0.3, 0.3, 0.4);
      glVertex3f( 1.0, 1.0, 1.0);         // Top Right Of The Quad (Front)
      glVertex3f(-1.0, 1.0, 1.0);         // Top Left Of The Quad (Front)
      glVertex3f(-1.0,-1.0, 1.0);         // Bottom Left Of The Quad (Front)
      glVertex3f( 1.0,-1.0, 1.0);         // Bottom Right Of The Quad (Front)

    if Color <> 0 then glColor4f(0.5, 0.5, 1.0, 0.8) // Set The Color
    else glColor4f(0.3, 0.3, 0.3, 0.4);
      glVertex3f( 1.0,-1.0,-1.0);         // Bottom Left Of The Quad (Back)
      glVertex3f(-1.0,-1.0,-1.0);         // Bottom Right Of The Quad (Back)
      glVertex3f(-1.0, 1.0,-1.0);         // Top Right Of The Quad (Back)
      glVertex3f( 1.0, 1.0,-1.0);         // Top Left Of The Quad (Back)

    if Color <> 0 then glColor4f(0.5, 0.5, 1.0, 0.8) // Set The Color
    else glColor4f(0.3, 0.3, 0.3, 0.4);
      glVertex3f(-1.0, 1.0, 1.0);         // Top Right Of The Quad (Left)
      glVertex3f(-1.0, 1.0,-1.0);         // Top Left Of The Quad (Left)
      glVertex3f(-1.0,-1.0,-1.0);         // Bottom Left Of The Quad (Left)
      glVertex3f(-1.0,-1.0, 1.0);         // Bottom Right Of The Quad (Left)

    if Color <> 0 then glColor4f(0.5, 0.5, 1.0, 0.8) // Set The Color
    else glColor4f(0.3, 0.3, 0.3, 0.4);
      glVertex3f( 1.0, 1.0,-1.0);         // Top Right Of The Quad (Right)
      glVertex3f( 1.0, 1.0, 1.0);         // Top Left Of The Quad (Right)
      glVertex3f( 1.0,-1.0, 1.0);         // Bottom Left Of The Quad (Right)
      glVertex3f( 1.0,-1.0,-1.0);         // Bottom Right Of The Quad (Right)
end;
Damit mache ich mein Cube und kann die Farbe beeinflussen. aber das ist ja nur ein Cube. Ich brauch aber mehrere (genau: 125). Wie schaffe ich die Verschiebung (je nach Koordinate)??? Zwischen den Cubes sollte auch ein bisschen Platz sein.
Chuck Norris doesn't need backups. He just uploads his files and lets the world mirror them.
  Mit Zitat antworten Zitat
blackfin
(Gast)

n/a Beiträge
 
#24

AW: Dreidimensionales Array darstellen.

  Alt 24. Aug 2010, 11:44
glTranslate()

und

Tutorial Matrix 2
  Mit Zitat antworten Zitat
Benutzerbild von Muellermilchtrinker
Muellermilchtrinker

Registriert seit: 1. Aug 2009
447 Beiträge
 
Delphi 2009 Professional
 
#25

AW: Dreidimensionales Array darstellen.

  Alt 24. Aug 2010, 11:57
Delphi-Quellcode:
    for x := 1 to 5 do
    begin
      for y := 1 to 5 do
      begin
        for z := 1 to 5 do
        begin
          glTranslatef(x/10,y/10,z/10);
          glBegin(GL_QUADS);
            Cube(0);
          glEnd;
        end;
      end;
    end;
Gibt leider nicht das Ergebnis. Ich glaub ich hab irgendwo in der Routine ein Problem.
Chuck Norris doesn't need backups. He just uploads his files and lets the world mirror them.
  Mit Zitat antworten Zitat
blackfin
(Gast)

n/a Beiträge
 
#26

AW: Dreidimensionales Array darstellen.

  Alt 24. Aug 2010, 12:00
Kurz nur draufgesehen, mögliches Problem:

Du verschiebst in deiner Routine ja immer weiter, ohne dass du den Zeichenstift zurücksetzt
OpenGL ist eine State-Machine, das heisst, wenn du verschiebst, verschiebt er immer relativ!

Also: Ursprung vor jedem Cube setzen:
Delphi-Quellcode:
 for x := 1 to 5 do
    begin
      for y := 1 to 5 do
      begin
        for z := 1 to 5 do
        begin
          glMatrixMode(GL_MODELVIEW) ; // optional, falls ModelView-Matrix nicht aktiv
          glLoadIdentity() ; // <---- möööp :D
          glTranslatef(x/10,y/10,z/10);
          glBegin(GL_QUADS);
            Cube(0);
          glEnd;
        end;
      end;
    end;

Geändert von blackfin (24. Aug 2010 um 12:03 Uhr)
  Mit Zitat antworten Zitat
Jens01

Registriert seit: 14. Apr 2009
670 Beiträge
 
#27

AW: Dreidimensionales Array darstellen.

  Alt 24. Aug 2010, 12:18
Ich persönlich würde hier eine bzw mehrere Schleifen bevorzugen.
ganz grob z.B.:
Delphi-Quellcode:
procedure WholeCube;
var
  i: Integer;
  i2: Integer;
  i3: Integer;
  x, y,z : Double;
begin
  Ebene := 5;
  Reihe := 5;
  Spalte := 5;

  z := 0;
  for i := 0 to Ebene - 1 do
  begin
    y := 0;
    for i2 := 0 to Reihe - 1 do
    begin
      x := 0;
      for i3 := 0 to Spalte - 1 do
      begin
        Cube(x, y, z);
        x := x + Abstand
      end;
      y := Y + Abstand;
    end;
    z := z + Abstand;
  end;
end;
Delphi-Quellcode:
procedure Cube(x,y,z: Double);
begin
  glVertex3f( 1.0 + x, 1.0 + Y,-1.0 + z); // Top Right Of The Quad (Top)
  glVertex3f(-1.0 + x, 1.0 + Y,-1.0 + z); // Top Left Of The Quad (Top)
  glVertex3f(-1.0 + x, 1.0 + Y, 1.0 + z); // Bottom Left Of The Quad (Top)
  glVertex3f( 1.0 + x, 1.0 + Y, 1.0 + z); // Bottom Right Of The Quad (Top)
  ...
end;
Also das ist jetzt eine ganz grobe Skizze (das funktioniert so 1:1 noch nicht). Für den Würfel selbst sollte man vielleicht auch eine Schleife nutzen.

Jetzt hast Du 2 Möglichkeiten!
  Mit Zitat antworten Zitat
blackfin
(Gast)

n/a Beiträge
 
#28

AW: Dreidimensionales Array darstellen.

  Alt 24. Aug 2010, 12:27
Wenn schon optimieren: Ich würde das Zeichnen eines einzelnen Cubes in eine Display-Liste speichern, die man nur noch aufrufen muss. (Stichwörter: GlNewList und GLEndList).
Das ist wesentlich schneller als dauernd glbegin / glvertex / glend.

Aber das ist erst dann angesagt, wenn die "normale" routine funzt
  Mit Zitat antworten Zitat
Benutzerbild von Muellermilchtrinker
Muellermilchtrinker

Registriert seit: 1. Aug 2009
447 Beiträge
 
Delphi 2009 Professional
 
#29

AW: Dreidimensionales Array darstellen.

  Alt 24. Aug 2010, 13:08
Also mein aktueller Code sieht so aus:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, dglOpenGL;

Type
  TVector2f = Array [0..1] of Single;
  TVector3f = Array [0..2] of Single;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Timer1: TTimer;
    Timer2: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
  private
    { Private-Deklarationen }
    FrameCount : Cardinal; //FrameCounter
    procedure SetupGL;
    procedure Render;
    procedure ErrorHandler;
    procedure Cube(x,y,z:Double;Color:Integer);
  public
    { Public-Deklarationen }
    DC : HDC; //Handle auf Zeichenfläche
    RC : HGLRC;//Rendering Context
  end;

var
  Form1: TForm1;

const
  NearClipping = 1;
  FarClipping = 1000;

var
  RotateX : single; // Rotation um die X-Achse
  RotateY : single; // Rotation um die Y-Achse
  RotateZ : single; // Rotation um die Z-Achse
  PosVect : TVector3f; // Vector mit der Position des Objektes.

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  DC:= GetDC(Panel1.Handle);
  if not InitOpenGL then Application.Terminate;
  RC:= CreateRenderingContext( DC,
                               [opDoubleBuffered],
                               32,
                               24,
                               0,0,0,
                               0);
  ActivateRenderingContext(DC, RC);
  SetupGL;
end;

procedure TForm1.SetupGL;
begin
  glClearColor(0.0, 0.0, 0.0, 0.0); //Hintergrundfarbe:
  glEnable(GL_DEPTH_TEST); //Tiefentest aktivieren
  glEnable(GL_CULL_FACE); //Backface Culling aktivieren

  RotateX := 0;
  RotateY := 0;
  RotateZ := 0;
  PosVect[0] := 0;
  PosVect[1] := 0;
  PosVect[2] := -5;
end;

procedure TForm1.Cube(x,y,z:Double;Color:Integer);
begin
    if Color <> 0 then glColor4f(0.5, 0.5, 1.0, 0.8) // Set The Color
    else glColor4f(0.3, 0.3, 0.3, 0.4);
      glVertex3f( 1.0+x, 1.0+y,-1.0+z);         // Top Right Of The Quad (Top)
      glVertex3f(-1.0+x, 1.0+y,-1.0+z);         // Top Left Of The Quad (Top)
      glVertex3f(-1.0+x, 1.0+y, 1.0+z);         // Bottom Left Of The Quad (Top)
      glVertex3f( 1.0+x, 1.0+y, 1.0+z);         // Bottom Right Of The Quad (Top)

    if Color <> 0 then glColor4f(0.5, 0.5, 1.0, 0.8) // Set The Color
    else glColor4f(0.3, 0.3, 0.3, 0.4);
      glVertex3f( 1.0+x,-1.0+y, 1.0+z);         // Top Right Of The Quad (Bottom)
      glVertex3f(-1.0+x,-1.0+y, 1.0+z);         // Top Left Of The Quad (Bottom)
      glVertex3f(-1.0+x,-1.0+y,-1.0+z);         // Bottom Left Of The Quad (Bottom)
      glVertex3f( 1.0+x,-1.0+y,-1.0+z);         // Bottom Right Of The Quad (Bottom)

    if Color <> 0 then glColor4f(0.5, 0.5, 1.0, 0.8) // Set The Color
    else glColor4f(0.3, 0.3, 0.3, 0.4);
      glVertex3f( 1.0+x, 1.0+y, 1.0+z);         // Top Right Of The Quad (Front)
      glVertex3f(-1.0+x, 1.0+y, 1.0+z);         // Top Left Of The Quad (Front)
      glVertex3f(-1.0+x,-1.0+y, 1.0+z);         // Bottom Left Of The Quad (Front)
      glVertex3f( 1.0+x,-1.0+y, 1.0+z);         // Bottom Right Of The Quad (Front)

    if Color <> 0 then glColor4f(0.5, 0.5, 1.0, 0.8) // Set The Color
    else glColor4f(0.3, 0.3, 0.3, 0.4);
      glVertex3f( 1.0+x,-1.0+y,-1.0+z);         // Bottom Left Of The Quad (Back)
      glVertex3f(-1.0+x,-1.0+y,-1.0+z);         // Bottom Right Of The Quad (Back)
      glVertex3f(-1.0+x, 1.0+y,-1.0+z);         // Top Right Of The Quad (Back)
      glVertex3f( 1.0+x, 1.0+y,-1.0+z);         // Top Left Of The Quad (Back)

    if Color <> 0 then glColor4f(0.5, 0.5, 1.0, 0.8) // Set The Color
    else glColor4f(0.3, 0.3, 0.3, 0.4);
      glVertex3f(-1.0+x, 1.0+y, 1.0+z);         // Top Right Of The Quad (Left)
      glVertex3f(-1.0+x, 1.0+y,-1.0+z);         // Top Left Of The Quad (Left)
      glVertex3f(-1.0+x,-1.0+y,-1.0+z);         // Bottom Left Of The Quad (Left)
      glVertex3f(-1.0+x,-1.0+y, 1.0+z);         // Bottom Right Of The Quad (Left)

    if Color <> 0 then glColor4f(0.5, 0.5, 1.0, 0.8) // Set The Color
    else glColor4f(0.3, 0.3, 0.3, 0.4);
      glVertex3f( 1.0+x, 1.0+y,-1.0+z);         // Top Right Of The Quad (Right)
      glVertex3f( 1.0+x, 1.0+y, 1.0+z);         // Top Left Of The Quad (Right)
      glVertex3f( 1.0+x,-1.0+y, 1.0+z);         // Bottom Left Of The Quad (Right)
      glVertex3f( 1.0+x,-1.0+y,-1.0+z);         // Bottom Right Of The Quad (Right)
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  DeactivateRenderingContext;
  DestroyRenderingContext(RC);
  ReleaseDC(Handle, DC);
end;

procedure TForm1.Render;
Const voffset : TVector3f = (0.0, 0.0, 0.0);
      toffset : TVector2f = (0.0, 0.0);
      tscale : TVector2f = (1.0, 1.0);
var x,y,z:Integer;
begin
  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity;
  gluPerspective(150.0, Panel1.ClientWidth/Panel1.ClientHeight, NearClipping, FarClipping);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity;

  glTranslatef(0, 0, 0);

  // Das Objekt auf seine aktuelle Position setzen.
  glTranslatef( PosVect[0], PosVect[1], PosVect[2]);

  { Das Objekt noch drehen, damit denn wir haben bis jetzt ja nur den }
  { Vector gedreht.                                                   }
  glRotatef(RotateX, 1, 0, 0);
  glRotatef(RotateY, 0, 1, 0);
  glRotatef(RotateZ, 0, 0, 1);

  glBegin(GL_QUADS);
    for x := 0 to 4 do
      for y := 0 to 4 do
        for z := 0 to 4 do
          Cube(x*3,y*3,z*3,0);
  glEnd;

  SwapBuffers(DC);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  inc(FrameCount);
  Render;
  If FrameCount = 20 then
  begin
    ErrorHandler;
    FrameCount := 0;
  end;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin
  RotateY := RotateY + 0.5;
// if RotateY <= 0 then RotateY := RotateY + 360;
// RotateX := RotateX + 0.5;
// if RotateX <= 0 then RotateX := RotateX + 360;
// RotateZ := RotateY + 0.5;
end;

procedure TForm1.ErrorHandler;
begin
  Form1.Caption := string(gluErrorString(glGetError));
end;

end.
Rauskommt nun das: siehe Video in der Zip Datei: clip0001.zip PS: Das ruckeln kommt von der Aufnahme. In Wirklichkeit ist es schön flüssig. Leider sieht es noch nicht so aus, wie in diesem Beispiel: http://www.delphipraxis.net/1041654-post6.html

Farben sind die gleichen. Hab von turboPASCAL schon den Code bekommen. Blick aber nicht ganz so durch und ich will es ja selber machen. Farben sind die gleichen wie in dem Programm von turboPASCAL
Chuck Norris doesn't need backups. He just uploads his files and lets the world mirror them.
  Mit Zitat antworten Zitat
Jens01

Registriert seit: 14. Apr 2009
670 Beiträge
 
#30

AW: Dreidimensionales Array darstellen.

  Alt 24. Aug 2010, 14:02
von der Bewegung her, solltest Du Dich mit dem Kamera-Thema auseinandersetzen.
http://wiki.delphigl.com/index.php/Kamera

Der Autor hat ein Programmteil veröffentlicht, welches (bis auf Kleinigkeiten) gut läuft. Es läßt sich auch in Dein Programm einfacher einbinden, als man am Anfang vermuten würde. Ggf kannst Du den Autor auch einfach ansprechen.

Bei Deinem Problem mit den Farben mußt Du konkreter werden.
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 3 von 5     123 45      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:30 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz