Hallo,
ich versuche gerade die Komponenten X, und Z zu berechnen, wenn Y = 0 ist.
Ein Ray behandelte ich wie eine Gerade.
Im linearen System berechne ich die X -Komponente für ein Y = beliebig wie folgt;
x_bei_y_beliebig = -(m * (y_position - y_beliebig)) + x_position
Exemplarisch : x = 15 und y = 30 und m = -1
Wann ist y = 15
x = -(-1*(30-15))+15=30
Übertragen auf ein Ray:
Anfangs war mein Versuch
Zur Berechnung des Rays bediene ich mich folgender Methode:
Meine Intention:
Ich versuche ein Objekt mit der Maus zu führen.
Dabei muss die Y-Komponente des Objektes immer 0 sein. (Y=0)
Ray - BoundingBox -Intersection funktioniert hervorragend; egal aus welcher Perspektive ich schaue..
Nur die Positionsbestimmung will nicht..
Im Anhang finden sich die Screenshots wieder..
Die gelben Pfeile markieren approximiert die Position des Cursors..(Windows fängt Cursor beim Screenshot nicht ein)
Liebe Grüße...
ich versuche gerade die Komponenten X, und Z zu berechnen, wenn Y = 0 ist.
Ein Ray behandelte ich wie eine Gerade.
Im linearen System berechne ich die X -Komponente für ein Y = beliebig wie folgt;
x_bei_y_beliebig = -(m * (y_position - y_beliebig)) + x_position
Exemplarisch : x = 15 und y = 30 und m = -1
Wann ist y = 15
x = -(-1*(30-15))+15=30
Übertragen auf ein Ray:
Anfangs war mein Versuch
Zur Berechnung des Rays bediene ich mich folgender Methode:
C#-Quellcode
- public static Ray CalculateRay(Vector2 mouseLocation, Matrix view, Matrix projection, Viewport viewport)
- {
- Vector3 nearPoint = viewport.Unproject(new Vector3(mouseLocation.X,
- mouseLocation.Y, 0.0f),
- projection,
- view,
- Matrix.Identity);
- Vector3 farPoint = viewport.Unproject(new Vector3(mouseLocation.X,
- mouseLocation.Y, 1.0f),
- projection,
- view,
- Matrix.Identity);
- Vector3 direction = farPoint - nearPoint;
- float n = direction.X * direction.X + direction.Y * direction.Y + direction.Z * direction.Z;
- float n1 = 1f / (float)Math.Sqrt((double)n);
- direction.X *= n1;
- direction.Y *= n1;
- direction.Z *= n1;
- return new Ray(nearPoint, direction);
- }
Meine Intention:
Ich versuche ein Objekt mit der Maus zu führen.
Dabei muss die Y-Komponente des Objektes immer 0 sein. (Y=0)
Ray - BoundingBox -Intersection funktioniert hervorragend; egal aus welcher Perspektive ich schaue..
Nur die Positionsbestimmung will nicht..
Im Anhang finden sich die Screenshots wieder..
Die gelben Pfeile markieren approximiert die Position des Cursors..(Windows fängt Cursor beim Screenshot nicht ein)
Liebe Grüße...
Und Gott alleine weiß alles am allerbesten und besser.