, , , , - .
-, ProjectToTrackball?
, , ( ) , ? , , 2D- ? ? , , 2D ?
Track. , , 3D-, 3 ( ). . , . , .
, "-angle", "angle" -, , , , ;)
EDIT: .rar.
, ProjectToTrackball ( SurfaceTrackballDecorator.cs), , .
, ( , , ), . , , , .
, , , 2 , 3D, ( ).
, 2D- 3D- . , 2D .
, , 2D- ( ), . 2D- (z = 0).
, , " ":)
, , - 3D, , .
. , .
EDIT: :)
?
private Vector3D ProjectToTrackball(Point point)
{
double x = point.X / (ActualWidth / 2);
double y = point.Y / (ActualHeight / 2);
x = x - 1;
y = 1 - y;
double alpha = 1.0 / Math.Sqrt(x*x + y*y + 1);
return new Vector3D(x*alpha, y*alpha, alpha);
}
, ( , ), ...
, ...
EDIT: :
private Vector3D ProjectToTrackball(Point point)
{
double x = point.X / (ActualWidth / 2);
double y = point.Y / (ActualHeight / 2);
x = x - 1;
y = 1 - y;
double z2 = 1 - x * x - y * y;
double z = 0;
if(z2 > 0)
z2 = Math.Sqrt(z2);
else
{
double length = Math.Sqrt(x * x + y * y);
x = x / length;
y = y / length;
z = 1 - length;
length = Math.Sqrt(x * x + y * y + z * z);
x = x / length;
y = y / length;
z = z / length;
}
return new Vector3D(x, y, z);
}
, , , . . .
: , , , 2D- , ProjectToTrackball NON- . , .
: OpenGL 3D.
EDIT 11/18/2009:
, , , " Z".
_ . , _rotation, .
Track:
private void Track(Point currentPosition)
{
Vector3D currentPosition3D = ProjectToTrackball(currentPosition);
Vector3D axis = Vector3D.CrossProduct(_previousPosition3D, currentPosition3D);
double angle = Vector3D.AngleBetween(_previousPosition3D, currentPosition3D);
if (axis.Length == 0)
return;
Quaternion delta = new Quaternion(axis, -angle);
_rotation *= delta;
_previousPosition3D = currentPosition3D;
}
... - .