| 36 |
private Point _previousPosition2D; |
private Point _previousPosition2D; |
| 37 |
private Vector3D _previousPosition3D = new Vector3D(0, 0, 1); |
private Vector3D _previousPosition3D = new Vector3D(0, 0, 1); |
| 38 |
|
|
|
private Transform3DGroup _transform; |
|
|
private ScaleTransform3D _scale = new ScaleTransform3D(); |
|
|
private AxisAngleRotation3D _rotation = new AxisAngleRotation3D(); |
|
|
private TranslateTransform3D _translate = new TranslateTransform3D(); |
|
|
|
|
|
private Vector3D _cameraLookDirection = new Vector3D(128, 128, 10); |
|
| 39 |
|
|
| 40 |
private PerspectiveCamera _camera; |
private PerspectiveCamera _camera; |
| 41 |
private Point3D _cameraLookPoint; |
private Point3D _cameraLookPoint; |
|
private RotateTransform3D _rotationTransform = new RotateTransform3D(); |
|
| 42 |
ModelVisual3D visul3d; |
ModelVisual3D visul3d; |
| 43 |
|
|
|
//rotate and pan object clicked |
|
|
private TranslateTransform3D _clickedTranslate = new TranslateTransform3D(); |
|
|
private RotateTransform3D _clickedRotate = new RotateTransform3D(); |
|
|
private AxisAngleRotation3D _clickedAxisAngleRotate = new AxisAngleRotation3D(); |
|
|
private QuaternionRotation3D _clickedQuaternionRotate = new QuaternionRotation3D(); |
|
| 44 |
Point3D _clickedCenterPosition; |
Point3D _clickedCenterPosition; |
|
Transform3DGroup _clickedGroup; |
|
| 45 |
|
|
| 46 |
bool isTracking = false; |
bool isTracking = false; |
| 47 |
|
bool isPanningObject = false; |
| 48 |
|
|
| 49 |
System.Windows.Threading.DispatcherTimer frameTimer; |
System.Windows.Threading.DispatcherTimer frameTimer; |
| 50 |
|
|
| 52 |
{ |
{ |
| 53 |
_camera = camera; |
_camera = camera; |
| 54 |
|
|
|
_rotationTransform.Rotation = _rotation; |
|
|
|
|
|
_transform = new Transform3DGroup(); |
|
|
// _transform.Children.Add(_translate); |
|
|
_transform.Children.Add(_rotationTransform); |
|
|
|
|
|
_cameraLookDirection = _camera.LookDirection; |
|
|
|
|
|
|
|
| 55 |
frameTimer = new System.Windows.Threading.DispatcherTimer(); |
frameTimer = new System.Windows.Threading.DispatcherTimer(); |
| 56 |
frameTimer.Tick += new EventHandler(frameTimer_Tick); |
frameTimer.Tick += new EventHandler(frameTimer_Tick); |
| 57 |
frameTimer.Interval = new TimeSpan(0, 0, 0, 0, 1); |
frameTimer.Interval = new TimeSpan(0, 0, 0, 0, 1); |
| 64 |
//this.OnMouseMove(sender, e); |
//this.OnMouseMove(sender, e); |
| 65 |
} |
} |
| 66 |
|
|
|
/// <summary> |
|
|
/// A transform to move the camera or scene to the trackball's |
|
|
/// current orientation and scale. |
|
|
/// </summary> |
|
|
public Transform3DGroup Transform |
|
|
{ |
|
|
get { return _transform; } |
|
|
} |
|
| 67 |
|
|
| 68 |
[System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "SetCursorPos")] |
[System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "SetCursorPos")] |
| 69 |
[return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)] |
[return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)] |
| 113 |
if (visul3d == null) |
if (visul3d == null) |
| 114 |
return; |
return; |
| 115 |
|
|
|
Transform3DGroup group = visul3d.Transform as Transform3DGroup; |
|
|
if (group != null) |
|
|
{ |
|
|
foreach (Transform3D tran in group.Children) |
|
|
{ |
|
|
if (tran is RotateTransform3D) |
|
|
{ |
|
|
|
|
|
_clickedRotate = tran as RotateTransform3D; |
|
|
if (_clickedRotate != null) |
|
|
{ |
|
|
_clickedAxisAngleRotate = new AxisAngleRotation3D(); |
|
|
_clickedRotate.Rotation = _clickedAxisAngleRotate; |
|
|
} |
|
|
} |
|
|
else if (tran is TranslateTransform3D) |
|
|
_clickedTranslate = tran as TranslateTransform3D; |
|
|
} |
|
|
} |
|
|
else |
|
|
return; |
|
|
|
|
| 116 |
//for ALT + MOUSE + ROTATE |
//for ALT + MOUSE + ROTATE |
| 117 |
VisualTreeHelper.HitTest(_eventSource, null, HitTestCallback, new PointHitTestParameters(pclick)); |
VisualTreeHelper.HitTest(_eventSource, null, HitTestCallback, new PointHitTestParameters(pclick)); |
| 118 |
|
|
| 119 |
_rotationTransform.CenterX = _cameraLookPoint.X; |
_camera.LookDirection = Point3D.Subtract(_cameraLookPoint, _camera.Position); |
|
_rotationTransform.CenterY = _cameraLookPoint.Y; |
|
|
_rotationTransform.CenterZ = _cameraLookPoint.Z; |
|
|
|
|
|
_cameraLookDirection = Point3D.Subtract(_cameraLookPoint, _camera.Position); |
|
|
_camera.LookDirection = _cameraLookDirection; |
|
| 120 |
|
|
| 121 |
isTracking = true; |
isTracking = true; |
| 122 |
_eventSource.CaptureMouse(); |
_eventSource.CaptureMouse(); |
| 141 |
if (visul3d == null) |
if (visul3d == null) |
| 142 |
return; |
return; |
| 143 |
|
|
| 144 |
string pos = visul3d.Content.Bounds.Location.ToString(); |
// mm += "clicked position: "+ visul3d.Content.Bounds.Location.ToString(); |
|
|
|
|
/* |
|
|
_clickedGroup = visul3d.Transform as Transform3DGroup; |
|
|
if (_clickedGroup != null) |
|
|
{ |
|
|
|
|
|
foreach (Transform3D tran in _clickedGroup.Children) |
|
|
{ |
|
|
if (tran is RotateTransform3D) |
|
|
{ |
|
|
_clickedRotate = tran as RotateTransform3D; |
|
|
if (_clickedRotate != null) |
|
|
{ |
|
|
_clickedAxisAngleRotate = _clickedRotate.Rotation as AxisAngleRotation3D; |
|
|
if (_clickedAxisAngleRotate == null) |
|
|
_clickedAxisAngleRotate = new AxisAngleRotation3D(); |
|
|
|
|
|
_clickedRotate.Rotation = _clickedAxisAngleRotate; |
|
|
} |
|
|
} |
|
|
else if (tran is TranslateTransform3D) |
|
|
{ |
|
|
_clickedTranslate = tran as TranslateTransform3D; |
|
|
} |
|
|
} |
|
|
} |
|
|
else |
|
|
return; |
|
|
*/ |
|
| 145 |
|
|
| 146 |
//for ALT + MOUSE + ROTATE |
//for ALT + MOUSE + ROTATE |
| 147 |
VisualTreeHelper.HitTest(_eventSource, null, HitTestCallback, new PointHitTestParameters(pclick)); |
VisualTreeHelper.HitTest(_eventSource, null, HitTestCallback, new PointHitTestParameters(pclick)); |
| 148 |
|
|
| 149 |
_rotationTransform.CenterX = _cameraLookPoint.X; |
_camera.LookDirection = Point3D.Subtract(_cameraLookPoint, _camera.Position); |
| 150 |
_rotationTransform.CenterY = _cameraLookPoint.Y; |
|
| 151 |
_rotationTransform.CenterZ = _cameraLookPoint.Z; |
|
| 152 |
|
_clickedCenterPosition = GetObjectCenterPosition(visul3d); |
|
//for rotate the object mouse clicked |
|
|
_clickedRotate.CenterX = _clickedCenterPosition.X = visul3d.Content.Bounds.Location.X + visul3d.Content.Bounds.SizeX / 2; |
|
|
_clickedRotate.CenterY = _clickedCenterPosition.Y = visul3d.Content.Bounds.Location.Y + visul3d.Content.Bounds.SizeY / 2; |
|
|
_clickedRotate.CenterZ = _clickedCenterPosition.Z = visul3d.Content.Bounds.Location.Z + visul3d.Content.Bounds.SizeZ / 2; |
|
| 153 |
|
|
|
_cameraLookDirection = Point3D.Subtract(_cameraLookPoint, _camera.Position); |
|
|
_camera.LookDirection = _cameraLookDirection; |
|
| 154 |
|
|
| 155 |
//TRACK BALL |
//TRACK BALL |
| 156 |
_previousPosition3D = ProjectToTrackball( |
_previousPosition3D = ProjectToTrackball( |
| 158 |
EventSource.ActualHeight, |
EventSource.ActualHeight, |
| 159 |
_previousPosition2D); |
_previousPosition2D); |
| 160 |
|
|
| 161 |
|
//mLastPos = new Point(pclick.X - _eventSource.ActualWidth / 2,_eventSource.ActualHeight / 2 - pclick.Y); |
|
mLastPos = new Point(pclick.X - _eventSource.ActualWidth / 2,_eventSource.ActualHeight / 2 - pclick.Y); |
|
|
|
|
| 162 |
|
|
| 163 |
isTracking = true; |
isTracking = true; |
| 164 |
_eventSource.CaptureMouse(); |
_eventSource.CaptureMouse(); |
| 166 |
e.Handled = true; |
e.Handled = true; |
| 167 |
} |
} |
| 168 |
|
|
| 169 |
|
private Point3D GetObjectCenterPosition(ModelVisual3D visual) |
| 170 |
|
{ |
| 171 |
|
return Point3D.Add(visual.Content.Bounds.Location, |
| 172 |
|
new Vector3D(visual.Content.Bounds.SizeX / 2, visual.Content.Bounds.SizeY / 2, visual.Content.Bounds.SizeZ / 2)); |
| 173 |
|
} |
| 174 |
|
|
| 175 |
private void OnMouseUp(object sender, MouseEventArgs e) |
private void OnMouseUp(object sender, MouseEventArgs e) |
| 176 |
{ |
{ |
| 177 |
//set the mouse to the original position when clicked the object. |
//set the mouse to the original position when clicked the object. |
| 179 |
|
|
| 180 |
Mouse.Capture(EventSource, CaptureMode.None); |
Mouse.Capture(EventSource, CaptureMode.None); |
| 181 |
isTracking = false; |
isTracking = false; |
| 182 |
|
if (isPanningObject == true) |
| 183 |
|
{ |
| 184 |
|
isPanningObject = false; |
| 185 |
|
_cameraLookPoint = GetObjectCenterPosition(visul3d); |
| 186 |
|
|
| 187 |
|
} |
| 188 |
string s = mm; |
//mm+="ResultPosition:" + visul3d.Content.Bounds.Location.ToString(); |
| 189 |
|
//string s = mm; |
| 190 |
|
|
| 191 |
_eventSource.ReleaseMouseCapture(); |
_eventSource.ReleaseMouseCapture(); |
| 192 |
_eventSource.Cursor = Cursors.Arrow; |
_eventSource.Cursor = Cursors.Arrow; |
| 238 |
if (isTracking) |
if (isTracking) |
| 239 |
{ |
{ |
| 240 |
_eventSource.Cursor = Cursors.None; |
_eventSource.Cursor = Cursors.None; |
| 241 |
|
isPanningObject = true; |
| 242 |
PanObject(currentPosition); |
PanObject(currentPosition); |
|
|
|
| 243 |
} |
} |
| 244 |
} |
} |
| 245 |
else if (e.LeftButton == MouseButtonState.Pressed) |
else if (e.LeftButton == MouseButtonState.Pressed) |
| 254 |
|
|
| 255 |
private void LookAround(Point currentPosition,Transform3D transformgroup) |
private void LookAround(Point currentPosition,Transform3D transformgroup) |
| 256 |
{ |
{ |
|
// Get the current orientantion from the RotateTransform3D |
|
|
Transform3DGroup group = transformgroup as Transform3DGroup; |
|
|
if (group == null) |
|
|
return; |
|
| 257 |
|
|
| 258 |
Vector3D currentPosition3D = ProjectToTrackball(EventSource.ActualWidth, EventSource.ActualHeight, currentPosition); |
Vector3D currentPosition3D = ProjectToTrackball(EventSource.ActualWidth, EventSource.ActualHeight, currentPosition); |
| 259 |
|
|
| 264 |
// Do not do this if you are rotating the scene instead. |
// Do not do this if you are rotating the scene instead. |
| 265 |
Quaternion delta = new Quaternion(axis, -angle); |
Quaternion delta = new Quaternion(axis, -angle); |
| 266 |
|
|
| 267 |
|
//foreach (Transform3D tran in group.Children) |
| 268 |
|
//{ |
| 269 |
|
// RotateTransform3D rotate = tran as RotateTransform3D; |
| 270 |
|
// if (rotate == null) |
| 271 |
|
// continue; |
| 272 |
|
// RotateTransform3D rt = (RotateTransform3D)rotate; |
| 273 |
|
// AxisAngleRotation3D r = (AxisAngleRotation3D)rt.Rotation; |
| 274 |
|
// Quaternion q = new Quaternion(r.Axis, r.Angle); |
| 275 |
|
|
| 276 |
|
// // Compose the delta with the previous orientation |
| 277 |
|
// q *= delta; |
| 278 |
|
|
| 279 |
|
// // Write the new orientation back to the Rotation3D |
| 280 |
|
// r.Axis = q.Axis; |
| 281 |
|
// r.Angle = q.Angle; |
| 282 |
|
//} |
| 283 |
|
|
| 284 |
|
if (_cameraLookPoint == new Point3D(0, 0, 0)) |
| 285 |
|
return; |
| 286 |
|
|
| 287 |
|
// delta *= delta; |
| 288 |
|
Matrix3D cameraMatrix3D = new Matrix3D(); |
| 289 |
|
cameraMatrix3D.RotateAt(delta,_cameraLookPoint); |
| 290 |
|
|
| 291 |
foreach (Transform3D tran in group.Children) |
|
| 292 |
{ |
_camera.Position = Point3D.Multiply(_camera.Position, cameraMatrix3D); |
| 293 |
RotateTransform3D rotate = tran as RotateTransform3D; |
_camera.LookDirection = Point3D.Subtract(_cameraLookPoint, _camera.Position); |
|
if (rotate == null) |
|
|
continue; |
|
|
RotateTransform3D rt = (RotateTransform3D)rotate; |
|
|
AxisAngleRotation3D r = (AxisAngleRotation3D)rt.Rotation; |
|
|
Quaternion q = new Quaternion(r.Axis, r.Angle); |
|
|
|
|
|
// Compose the delta with the previous orientation |
|
|
q *= delta; |
|
|
|
|
|
// Write the new orientation back to the Rotation3D |
|
|
r.Axis = q.Axis; |
|
|
r.Angle = q.Angle; |
|
|
} |
|
| 294 |
|
|
| 295 |
_previousPosition3D = currentPosition3D; |
_previousPosition3D = currentPosition3D; |
| 296 |
} |
} |
| 298 |
void _eventSource_MouseWheel(object sender, MouseWheelEventArgs e) |
void _eventSource_MouseWheel(object sender, MouseWheelEventArgs e) |
| 299 |
{ |
{ |
| 300 |
double scale = -e.Delta / 1200.000; |
double scale = -e.Delta / 1200.000; |
| 301 |
|
if(_cameraLookPoint!=null&&_cameraLookPoint!=new Point3D(0,0,0)) |
| 302 |
|
_camera.LookDirection = Point3D.Subtract(_cameraLookPoint, _camera.Position); |
| 303 |
|
|
| 304 |
AdjustCameraPosition(_camera, _cameraLookDirection, scale); |
AdjustCameraPosition(_camera, _camera.LookDirection, scale); |
| 305 |
} |
} |
| 306 |
|
|
| 307 |
Point mLastPos; |
|
| 308 |
private void RotateObject(Point currentPosition) |
private void RotateObject(Point currentPosition) |
| 309 |
{ |
{ |
|
/* for test |
|
|
* |
|
|
// Point actualPos = new Point(currentPosition.X - _eventSource.ActualWidth / 2, _eventSource.ActualHeight / 2 - currentPosition.Y); |
|
|
// double dx = actualPos.X - mLastPos.X, dy = actualPos.Y - mLastPos.Y; |
|
|
|
|
|
// double mouseAngle = 0; |
|
|
// if (dx != 0 && dy != 0) |
|
|
// { |
|
|
// mouseAngle = Math.Asin(Math.Abs(dy) / Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2))); |
|
|
// if (dx < 0 && dy > 0) mouseAngle += Math.PI / 2; |
|
|
// else if (dx < 0 && dy < 0) mouseAngle += Math.PI; |
|
|
// else if (dx > 0 && dy < 0) mouseAngle += Math.PI * 1.5; |
|
|
// } |
|
|
// else if (dx == 0 && dy != 0) mouseAngle = Math.Sign(dy) > 0 ? Math.PI / 2 : Math.PI * 1.5; |
|
|
// else if (dx != 0 && dy == 0) mouseAngle = Math.Sign(dx) > 0 ? 0 : Math.PI; |
|
|
|
|
|
// double axisAngle = mouseAngle + Math.PI / 2; |
|
|
|
|
|
// Vector3D axis = new Vector3D(Math.Cos(axisAngle) * 4, Math.Sin(axisAngle) * 4, 0); |
|
|
|
|
|
// double rotation = 0.01 * Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2)); |
|
|
|
|
|
// //Transform3DGroup group = visul3d.Transform as Transform3DGroup; |
|
|
// //QuaternionRotation3D r = new QuaternionRotation3D(new Quaternion(axis, rotation * 180 / Math.PI)); |
|
|
// //group.Children.Add(new RotateTransform3D(r)); |
|
|
//// _clickedRotate = new RotateTransform3D(r); |
|
|
// Quaternion q = new Quaternion(axis, _clickedQuaternionRotate.Quaternion.Angle + rotation * 180 / Math.PI); |
|
|
// _clickedQuaternionRotate.Quaternion = q; |
|
|
*/ |
|
| 310 |
Vector3D currentPosition3D = ProjectToTrackball(EventSource.ActualWidth, EventSource.ActualHeight, currentPosition); |
Vector3D currentPosition3D = ProjectToTrackball(EventSource.ActualWidth, EventSource.ActualHeight, currentPosition); |
|
|
|
| 311 |
Vector3D axis = Vector3D.CrossProduct(_previousPosition3D, currentPosition3D); |
Vector3D axis = Vector3D.CrossProduct(_previousPosition3D, currentPosition3D); |
| 312 |
double angle = Vector3D.AngleBetween(_previousPosition3D, currentPosition3D); |
double angle = Vector3D.AngleBetween(_previousPosition3D, currentPosition3D); |
| 313 |
|
|
|
//if (_clickedAxisAngleRotate.Angle >= 360 || _clickedAxisAngleRotate.Angle <= -360) |
|
|
// _clickedAxisAngleRotate.Angle = 0; |
|
| 314 |
|
|
| 315 |
//_clickedAxisAngleRotate.Axis = axis; |
Matrix3D mat = new Matrix3D(); |
|
//_clickedAxisAngleRotate.Angle += angle; |
|
|
|
|
|
|
|
|
Matrix3D mat = visul3d.Transform.Value; |
|
| 316 |
mat.RotateAt(new Quaternion(axis, angle),_clickedCenterPosition); |
mat.RotateAt(new Quaternion(axis, angle),_clickedCenterPosition); |
| 317 |
|
|
| 318 |
visul3d.Transform = new MatrixTransform3D(mat); |
GeometryModel3D geometryModel3D = visul3d.Content as GeometryModel3D; |
|
|
|
|
// Point3D realpos = visul3d.Content.Bounds.Location * visul3d.Transform.Value; |
|
|
// _clickedCenterPosition = Point3D.Add(realpos, new Vector3D(visul3d.Content.Bounds.SizeX / 2, visul3d.Content.Bounds.SizeY / 2, visul3d.Content.Bounds.SizeZ / 2)); |
|
|
|
|
|
|
|
|
//Vector3D vector3D = Point3D.Subtract(visul3d.Content.Bounds.Location,realpos ); |
|
|
|
|
|
//Point3DCollection points = ((visul3d.Content as GeometryModel3D).Geometry as MeshGeometry3D).Positions; |
|
| 319 |
|
|
| 320 |
//for (int i = 0; i < points.Count; i++) |
if (geometryModel3D != null) |
| 321 |
// points[i] = Point3D.Add(points[i], vector3D); |
{ |
| 322 |
|
MeshGeometry3D meshGeometry3D = geometryModel3D.Geometry as MeshGeometry3D; |
| 323 |
|
if (meshGeometry3D != null) |
| 324 |
|
{ |
| 325 |
|
Point3DCollection points = meshGeometry3D.Positions; |
| 326 |
|
|
| 327 |
|
for (int i = 0; i < points.Count; i++) |
| 328 |
|
points[i] = Point3D.Multiply(points[i], mat); |
| 329 |
|
} |
| 330 |
|
} |
| 331 |
|
|
| 332 |
_previousPosition3D = currentPosition3D; |
_previousPosition3D = currentPosition3D; |
|
// mLastPos = actualPos; |
|
| 333 |
} |
} |
| 334 |
|
|
| 335 |
private Vector3D ProjectToTrackball(double width, double height, Point point) |
private Vector3D ProjectToTrackball(double width, double height, Point point) |
| 362 |
|
|
| 363 |
private void PanObject(Point currentPosition) |
private void PanObject(Point currentPosition) |
| 364 |
{ |
{ |
|
double scaley = currentPosition.Y - _previousPosition2D.Y; |
|
|
scaley = Math.Abs(scaley); |
|
|
|
|
|
double scalex = currentPosition.X - _previousPosition2D.X; |
|
|
scalex = Math.Abs(scalex); |
|
|
|
|
|
|
|
| 365 |
Vector3D vector3D = GetTranslationVector3D(visul3d, _previousPosition2D, currentPosition); |
Vector3D vector3D = GetTranslationVector3D(visul3d, _previousPosition2D, currentPosition); |
| 366 |
|
GeometryModel3D geometryModel3D = visul3d.Content as GeometryModel3D; |
| 367 |
//_clickedTranslate.OffsetX += scalex * vector3D.X;// _clickedTranslateOriginal.OffsetX + vector3D.X; |
if (geometryModel3D != null) |
| 368 |
//_clickedTranslate.OffsetY += scalex * vector3D.Y;// _clickedTranslateOriginal.OffsetY + vector3D.Y; |
{ |
| 369 |
//_clickedTranslate.OffsetZ += scaley * vector3D.Z;// _clickedTranslateOriginal.OffsetZ + vector3D.Z;// vectMouse.Z; |
MeshGeometry3D meshGeometry3D = geometryModel3D.Geometry as MeshGeometry3D; |
| 370 |
|
if (meshGeometry3D != null) |
| 371 |
|
{ |
| 372 |
// transformgroup.matrix = child1.matrix * child2.matrix*... |
Point3DCollection points = meshGeometry3D.Positions; |
|
// Point3D realposition = mesh.position * transformgroup.matrix |
|
|
|
|
|
Point3DCollection points = ((visul3d.Content as GeometryModel3D).Geometry as MeshGeometry3D).Positions; |
|
| 373 |
|
|
| 374 |
for(int i=0;i<points.Count;i++) |
for(int i=0;i<points.Count;i++) |
| 375 |
points[i] = Point3D.Add(points[i],vector3D*10); |
points[i] = Point3D.Add(points[i],vector3D*10); |
| 376 |
|
|
|
////* for test |
|
|
//Matrix3D mat = visul3d.Transform.Value; |
|
|
//mat.Translate(new Vector3D( vector3D.X,vector3D.Z,vector3D.Y)*10); |
|
|
//visul3d.Transform = new MatrixTransform3D(mat); |
|
| 377 |
|
|
| 378 |
mm += visul3d.Content.Bounds.Location.ToString() + " "; |
} |
| 379 |
|
} |
| 380 |
} |
} |
| 381 |
string mm = ""; |
string mm = ""; |
| 382 |
private Vector3D GetTranslationVector3D(DependencyObject modelHit, Point startPosition, Point endPosition) |
private Vector3D GetTranslationVector3D(DependencyObject modelHit, Point startPosition, Point endPosition) |
| 404 |
private void LookUpDown(Point currentPosition) |
private void LookUpDown(Point currentPosition) |
| 405 |
{ |
{ |
| 406 |
double scale = currentPosition.Y- _previousPosition2D.Y; |
double scale = currentPosition.Y- _previousPosition2D.Y; |
| 407 |
scale = scale/5.000000; |
// scale = scale; |
| 408 |
_camera.LookDirection = new Vector3D(_camera.LookDirection.X, _camera.LookDirection.Y, _camera.LookDirection.Z + scale); |
_camera.LookDirection = new Vector3D(_camera.LookDirection.X, _camera.LookDirection.Y, _camera.LookDirection.Z + scale); |
| 409 |
} |
} |
| 410 |
|
|
| 413 |
//zoom |
//zoom |
| 414 |
double yDelta = currentPosition.Y - _previousPosition2D.Y; |
double yDelta = currentPosition.Y - _previousPosition2D.Y; |
| 415 |
double scale = yDelta / 100.000000; |
double scale = yDelta / 100.000000; |
| 416 |
AdjustCameraPosition(_camera,_cameraLookDirection,scale); |
AdjustCameraPosition(_camera,_camera.LookDirection,scale); |
| 417 |
|
|
| 418 |
//rotate the camera |
//rotate the camera |
| 419 |
double axisAngle = currentPosition.X - _previousPosition2D.X; |
double axisAngle = currentPosition.X - _previousPosition2D.X; |
| 420 |
_rotation.Axis = new Vector3D(0, 0, 1); |
Matrix3D matrixRoateCamera = new Matrix3D(); |
| 421 |
_rotation.Angle -= axisAngle; |
matrixRoateCamera.RotateAt(new Quaternion(new Vector3D(0, 0, 1), axisAngle), _cameraLookPoint); |
| 422 |
|
|
| 423 |
|
_camera.Position = Point3D.Multiply(_camera.Position, matrixRoateCamera); |
| 424 |
_camera.LookDirection = Point3D.Subtract(_cameraLookPoint, _camera.Position); |
_camera.LookDirection = Point3D.Subtract(_cameraLookPoint, _camera.Position); |
| 425 |
} |
} |
| 426 |
|
|