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


Delphi 2k6 Prof,C,C#,Delphi
BeitragVerfasst: So 12.03.06 16:08 
Hallo!

Wie ihr aus der Überschrift lesen könnte hab ich im moment das Problem der Umwandlung von 3 Koordinaten (x,y,z) in die Bildschirmkoordinaten (x,y).
Ich hab folgende Umwandlungen versucht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function x3d2d(x,z:real):real;
begin
  //result:=(x+1*z); //funktioniert gut, aber probleme beim rotieren
  result:=ZOOMFAKTOR * (x / (1 + z)); //funktioniert überhaupt nicht
end;
function y3d2d(y,z:real):real;
begin
//  result:=(y+1*z); //funktioniert gut, aber probleme beim rotieren
  result:=ZOOMFAKTOR * (y / (1 + z) ); //funktioniert überhaupt nicht
end;


Das erste Bild zeigt komische Werte wenn ich die 2. Formel benutze.
Das 2. Bild zeigt wie es Aussieht mit der ersten Formel jedoch ist das rotieren falsch,
den das Koorinatensystem wird schief (3. bild ein wenig um y rotiert)..
[url=img59.imageshack.us/...mage=fehler12im.jpg]user defined image[/URL]
[url=img59.imageshack.us/...hp?image=ok17on.jpg]user defined image[/URL]
[url=img59.imageshack.us/...k1rotiertumy5ub.jpg]user defined image[/URL]
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: So 12.03.06 16:48 
wozu schreibst du eigentlich:
ausblenden Delphi-Quelltext
1:
  (y + 1 * z)					

wenns auch so geht:
ausblenden Delphi-Quelltext
1:
y+z					


?
chaoslion Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45


Delphi 2k6 Prof,C,C#,Delphi
BeitragVerfasst: So 12.03.06 16:53 
weil 1 er teilungsfaktor ist, eigentlich war es vorher 0.5, das heisst das die z werte nur halb so groß sind wie die y oder x aber im moment steht 1 als platzhalter da.
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: So 12.03.06 16:55 
hast du dir das mal angeguckt ?

de.wikipedia.org/wiki/Parallelprojektion

wie wendest du deine funktion überhaupt an ?
chaoslion Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45


Delphi 2k6 Prof,C,C#,Delphi
BeitragVerfasst: So 12.03.06 17:15 
so rufe ich sie auf:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
type 
 TVek3d=record
  x,y,z:real;
  end;

//...//

procedure TMATHE.ZeichnePunkt(pkt1:TVek3d);
begin
CANVAS.PutPixel(VNULLX+x3d2d(pkt1.x,pkt1.z),VNULLY-y3d2d(pkt1.y,pkt1.z),RED,fxBlend);
end;

VNULLX ^ VNULLY sind konstanten = 320 und 240, da ich von 640*480 als auflösung ausgehe
desweiteren soll er alles vom zentrum ausrichten
zb hast du x=20, y=20, z=30 welcher er dann "umrechnet" in 340, 260 und z halt durch formel..

putpixel..ist von einer Grafikengine..
red ist Farbkonstante
fxblend nen Effekt
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: So 12.03.06 18:03 
btw da ist n highlighting fehler, das .z wird als zahl gelesen Oo
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: So 12.03.06 19:28 
Siehe Projektionsmatrix und homogene Koordinaten.

Bzw. Mit was für Koordinaten hast du es zu tun? Nimm mal für Zoomfaktor 400 und anstelle von "1" ebenfalls einen Wert in dieser Grössenordnung.
chaoslion Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45


Delphi 2k6 Prof,C,C#,Delphi
BeitragVerfasst: So 12.03.06 19:45 
hab ich ja schon dennoch ist das koordinatensystem bei der rotation schief..
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: So 12.03.06 21:50 
Je höher du diese beiden Werte setzst, desto näher solltest du eine Parallelprojektion erhalten. Wenn das nicht der Fall ist, dann ist eventuell etwas mit deiner Drehroutine falsch.
NCortex
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 126

WIN 2000
D7 Enterprise
BeitragVerfasst: So 12.03.06 22:11 
hey, ich hatte ein ähnliches Problem. Ich hab das mit Matrixrechnung gelöst.

Kurze Vorerklärung:

TVektor, ist ein 3D Vektor mit (x,y,z)
TProjektionsMatrix ist eine 2x3 Matrix. also:

(x1,x2,x3)
(y1,y2,y3)

Die Projektionsmatrix bestimmt die Perspektive (Militär-,Isometrie, Dimetrie... etc):

Sie standaertprojektion sieht folgendermaßen aus:

(-0.5 , 1 , 0)
(-0,5 , 0 , 1)

fVR.mal() ist skalarprodukt. fVR.Vektor() gibt einen Vektor aus.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
function TMatrixrechnung.Auf2DProjizieren(a:TVektor;P:TProjektionsMatrix):TPoint;
begin
result.X := round(fVR.mal(fVR.Vektor(P.x1,P.x2,P.x3),a));
result.Y := round(fVR.mal(fVR.Vektor(P.y1,P.y2,P.y3),a));
end;


der obige Code ist eiglich nur da um es dynamisch zu machen, du kannst auch einfach:

ausblenden Delphi-Quelltext
1:
2:
V2d.x := -0.5 * V3d.x +  V3d.y;
V2d.x := -0.5 * V3d.x +  V3d.z;


benutzen.

wenn du noch fragen dazu hast, kann ich dir gern noch tiefgehender helfen.

mfg Ncortex

_________________
"...by all means, do not use a hammer." (aus einer IBM Technikerdokumentation ca. 1920)
--->außer es kam von Microsoft<---
chaoslion Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45


Delphi 2k6 Prof,C,C#,Delphi
BeitragVerfasst: Mo 13.03.06 00:13 
user profile iconNCortex hat folgendes geschrieben:

ausblenden Delphi-Quelltext
1:
2:
V2d.x := -0.5 * V3d.x +  V3d.y;
V2d.x := -0.5 * V3d.x +  V3d.z;



hey!

Ist wahrscheinlich nur nen Schreibfehler, aber wieso berechnest Du 2x den x Wert?

Ich hab ja zur Darstellung eines Punktes das "Schulkoordinatensystem" genommen.
Das heißt der Punkt(x,y,z) wird so gezeichnet:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
     y |   .
       |  .
       | .
-------.---------- x
      .|
     . | 
   z.  |


korrekter Weise muss man doch von einer Zentralprojektion ausgehen, also das
der Benutzer in Richtung Z Achse schaut, oder?
Allesquarks
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 510

Win XP Prof
Delphi 7 E
BeitragVerfasst: Mo 13.03.06 00:34 
Wie hier schon erwähnt gibt es verschiedene Arten der Projektion Fluchtpunkt,senkrechte Projektion auf eine Ebene etc.
Aber beim Schulkoordinatensystem ist es für das Auge sowieso gewöhnungsbedürftig. Dort schaut der Benutzer keineswegs in z-Richtung. Und gerade weil dieses Darstellungssystem so zerrt auf jeden Fall immer erst die Koordinaten drehen und dann erneut abbilden. Und zum Abbildungsmaßstab:

| .
| .
| .
-----------------
|
|
|

z-Achse um die Hälfte gekürzt aber bei x-,y-Längenberechnung nochmal durch Wurzel zwei teilen.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mo 13.03.06 02:15 
NCortex: Deine Rechnung sieht etwas ungewöhnlich aus. Wenn man eine Projektion will muss man irgendwann mal durch die Tiefenkoordinate z teilen. Denn: Je grösser die Tiefenkoordinate z, desto kleiner soll das Objekt sichtbar sein. Wenn man durch z teilt, erhält man genau diesen Effekt: Je grösser z, desto kleiner die Abbildung.
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: Mo 13.03.06 15:07 
im grunde ist es auch eine 3x3 matrix, nur stehen in der letzten zeile lauter nullen, damit die z achse wegfällt.
man kann auch ebenso auf der x oder y achse projezieren.
NeoInDerMATRIX
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 245

Win95, Win98(+se), WinNT, Win2000, WinME, WinXP(+pro), VISTA, Linux(SuSe), DOS [MultiMon(3)], Vista
D6 PeE + (FP 2.0l) + D3 Pe + D2005+ D2006 Arch
BeitragVerfasst: Mo 13.03.06 20:55 
Hi,

ich habe dazu mal gerade nen altes DOC auf meiner Platte gefunden! Evtl hilft es ja.

Damit habe ich das auch unter DOS mal hinbekommen.

Cu
Neo
Einloggen, um Attachments anzusehen!
NCortex
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 126

WIN 2000
D7 Enterprise
BeitragVerfasst: Mi 15.03.06 14:59 
ähm... mir fällt grade auf, dass mein koordinatensystem anders ist.


bei mir ist z nach oben, y nach rechts und x die Tiefe. Daher auch 0.5 * x

das ist die standartperspektive, die man auch in der SChule benutzt. die tiefe einfach um die hälfte verkürzt dazu addieren.

hoffe das erklärt die Rechnung

_________________
"...by all means, do not use a hammer." (aus einer IBM Technikerdokumentation ca. 1920)
--->außer es kam von Microsoft<---
NeoInDerMATRIX
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 245

Win95, Win98(+se), WinNT, Win2000, WinME, WinXP(+pro), VISTA, Linux(SuSe), DOS [MultiMon(3)], Vista
D6 PeE + (FP 2.0l) + D3 Pe + D2005+ D2006 Arch
BeitragVerfasst: Mi 15.03.06 21:44 
Hi,

das mit dem Verkürtzt Rechnen ist doch aber wenn ich mich nicht irre bei der Perspektive nur so wenn der sicht winkel auf die Fläche ca. 45° sind oder irre ich mich da?

Cu
Neo
chaoslion Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45


Delphi 2k6 Prof,C,C#,Delphi
BeitragVerfasst: Do 16.03.06 15:51 
jap 45°..er muss aber für ne korrekte betrachtung 90° sein

-----------------------------------------------------------
danke euch, hab mal nen bissle gegoogelt nach den begriffen die hier im thread so fielen
und hab ne lösung gefunden:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
function x3d2d(x,z:real):real;
begin
  result:=(x*ZOOMFAKTOR)/(z+ZOOMFAKTOR);
end;

function y3d2d(y,z:real):real;
begin
  result:=(y*ZOOMFAKTOR)/(z+ZOOMFAKTOR);
end;


wobei 100 <= ZOOMFAKTOR <= 400 liegt. und bitte nicht kleiner 100 sonst ÜBELST fischaugeneffekt.. :)

ich kann ja dann mal nen screen posten, falls der rest mit den graden auch geht..
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Do 16.03.06 21:33 
Dafür hättest du nicht googeln müssen, ich hatte dir die Lösung ja schon in meinem ersten Post gegeben ;)
user profile icondelfiphan hat folgendes geschrieben:
Nimm mal für Zoomfaktor 400 und anstelle von "1" ebenfalls einen Wert in dieser Grössenordnung.
(...)
Je höher du diese beiden Werte setzst, desto näher solltest du eine Parallelprojektion erhalten. Wenn das nicht der Fall ist, dann ist eventuell etwas mit deiner Drehroutine falsch.
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: Do 23.03.06 20:53 
ich bin gerade per zufall bei google auf was gutes gestoßen:

www.felix-colibri.co...phi_3d_designer.html

dort ist alles echt genial erklärt, objekte drehen, kamera drehen, etc ....


(ich sehe gerade, du schreibst das gleiche programm wie ich im moment, voerst ist die grafische umsetzung bei mir mit ogl was mir aber nicht so ganz gefällt)