void CompositionTarget_Rendering(object sender, EventArgs e) { if (_timer.OnInterval()) { CheckCommand(); } _rubikscube.Animator.Start(null); _rubikscube.Animator.Update(); //camera movement if (_cameraMove != 0) { _cameraZ += _cameraMove; Vector3D p = new Vector3D(0, 0, _cameraZ);//120); //60; p = Ext3D.Transform(p, _cameraRotate); _camera.Position = new Point3D(p.X, p.Y, p.Z); //Debug.WriteLine(_camera.Position); if (_cameraZ <= _cameraNear || _cameraZ >= _cameraFar) { _cameraMove = 0; OnLayoutUpdated(); } } }
public void RotateUnit(Axis axis, double rotation) { Matrix3D transform = Matrix3D.Identity; switch (axis) { case Axis.X: transform = Ext3D.CreateRotationX(rotation); break; case Axis.Y: transform = Ext3D.CreateRotationY(rotation); break; case Axis.Z: transform = Ext3D.CreateRotationZ(rotation); break; } _axisTransform = _axisTransform * transform; transform = _axisTransform; transform.Invert(); _unitX = Ext3D.Transform(Ext3D.UnitX, transform); _unitY = Ext3D.Transform(Ext3D.UnitY, transform); _unitZ = Ext3D.Transform(Ext3D.UnitZ, transform); }
public override void Restore() { base.Restore(); foreach (CubieFace face in Faces.Values) { face.Restore(); } _center = Ext3D.Transform(_center, base.Transform); }
public override Matrix3D Rotate(Axis axis, double deltaAngle, bool isFromSaved) { Matrix3D matrix = base.Rotate(axis, deltaAngle, isFromSaved); _center = Ext3D.Transform(_center, base.Transform); foreach (CubieFace face in Faces.Values) { face.DoTransform(matrix, isFromSaved); } return(matrix); }
public override void DoTransform(double deltaAngle) { // Debug.WriteLine("start DoTransform"); foreach (CubicleFace face in AffectedFaces) { Cubie cubie = face.CubieFace.Cubie; CubieFace cubieFace = face.CubieFace; //cubicle.Cubie.Rotate(BasicOp.Axis, deltaAngle, false); Vector3D axis = face.CubieFace.Cubie.UnitX; if (Axis == Axis.X) { axis = face.CubieFace.Cubie.UnitX; } else if (Axis == Axis.Y) { axis = face.CubieFace.Cubie.UnitY; } else if (Axis == Axis.Z) { axis = face.CubieFace.Cubie.UnitZ; } Quaternion3D rot = Quaternion3D.CreateFromAxisAngle(axis, deltaAngle); Matrix3D rotMatrix = Ext3D.CreateFromQuaternion(rot); Matrix3D matrix = cubie.Transform;// Matrix.Invert(cubie.Transform); matrix.Invert(); Matrix3D rotation = Ext3D.CreateTranslation(Ext3D.Transform(-AxisTranslationFromOrigin, matrix)) * rotMatrix * Ext3D.CreateTranslation(Ext3D.Transform(AxisTranslationFromOrigin, matrix)); if (IsAxisMoving) { Vector3D v1; if (!_axisTranslation.ContainsKey(cubieFace)) { Matrix3D m = (cubieFace as ITransform).Transform; m.Invert(); v1 = Ext3D.Transform(Axis2TranslationFromOrigin, m); _axisTranslation.Add(cubieFace, v1); } v1 = _axisTranslation[cubieFace]; Matrix3D r = rotation; r.Invert(); v1 = Ext3D.Transform(v1, r);// Matrix.Invert(rotation)); Matrix3D rotationAxis = Ext3D.CreateTranslation(-v1) * rotMatrix * Ext3D.CreateTranslation(v1); rotation = rotationAxis * rotation; _axisTranslation[cubieFace] = v1; } (cubieFace as ITransform).DoTransform(rotation, false); } }
private void Track(Point currentPosition) { Vector3D currentPosition3D = currentPosition.ProjectToTrackball( _viewport.ActualWidth, _viewport.ActualHeight); Vector3D axis = Vector3D.CrossProduct(_previousPosition3D, currentPosition3D); double angle = Ext3D.AngleBetween(_previousPosition3D, currentPosition3D); axis = Ext3D.Transform(axis, _cameraRotate); Methods.RotateCameraResult rcr = _camera.RotateCamera(axis, -angle); _cameraRotate *= rcr.RotateMatrix; _viewMatrix = rcr.ViewMatrix; OnLayoutUpdated(); _previousPosition3D = currentPosition3D; }
void ResetCamera() { _cameraZ = _cameraNear; _cameraMove = 0; _camera.Position = new Point3D(0, 0, _cameraNear); //60 _camera.LookDirection = new Vector3D(0, 0, -1); _camera.UpDirection = new Vector3D(0, 1, 0); _camera.FieldOfView = 80; Matrix3D vm = Matrix3D.Identity; _cameraRotate = _camera.RotateCamera(new Vector3D(0, 1, 0), Math.PI / 6).RotateMatrix; Vector3D axis = new Vector3D(1, 0, 0); axis = Ext3D.Transform(axis, _cameraRotate); Methods.RotateCameraResult rcr = _camera.RotateCamera(axis, -Math.PI / 6); _cameraRotate *= rcr.RotateMatrix; _viewMatrix = rcr.ViewMatrix; }
public static RotateCameraResult RotateCamera(this PerspectiveCamera camera, Vector3D axis, double angle) { axis.Normalize(); Quaternion3D q = Quaternion3D.CreateFromAxisAngle(axis, angle); Matrix3D m = Ext3D.CreateFromQuaternion(q); Vector3D p = new Vector3D(camera.Position.X, camera.Position.Y, camera.Position.Z); Vector3D pos = Ext3D.Transform(p, m); camera.Position = new Point3D(pos.X, pos.Y, pos.Z); Vector3D d = new Vector3D(camera.LookDirection.X, camera.LookDirection.Y, camera.LookDirection.Z); camera.LookDirection = Ext3D.Transform(d, m); Vector3D up = new Vector3D(camera.UpDirection.X, camera.UpDirection.Y, camera.UpDirection.Z); camera.UpDirection = Ext3D.Transform(up, m); return(new RotateCameraResult { RotateMatrix = m, ViewMatrix = CalculateViewMatrix(camera.Position, camera.LookDirection, camera.UpDirection) }); }