private void RotateCube(Direction direction) { if (!_isRotating) { // Let the quaternion animation figure out how to transform between 2 quaternions... QuaternionAnimation animation = new QuaternionAnimation(); // A quaternion is way of representing a rotation around an axis // The From quaternion is the one required to display the current cube side based on the original side being the 'front' animation.From = _possibleRotationMatrix[_currentCubeRotation.CubeSide][Direction.None].Quaternion; // The To quaternion is the one required to display the next cube side based on the original side being the 'front' animation.To = _possibleRotationMatrix[_currentCubeRotation.CubeSide][direction].Quaternion; animation.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 650)); _isRotating = true; animation.Completed += (o, e) => { _isRotating = false; ToggleVisualHitTesting(true); _currentCubeRotation = _possibleRotationMatrix[_currentCubeRotation.CubeSide][direction]; }; // Temporarily remove hit testing to make things a but smoother ToggleVisualHitTesting(false); this.CameraRotation.BeginAnimation(QuaternionRotation3D.QuaternionProperty, animation); } }
/// <summary> /// Initializes a new instance of the <see cref="CubeWindow"/> class. /// </summary> public CubeWindow() { InitializeComponent(); _currentCubeRotation = _cubeFrontSideFacing; DateTime date1 = DateTime.Now; data_label.Content = DateTime.Now.Hour + ":" + DateTime.Now.Minute; }
private void createCube(int zanorenie, float x, float y, float z, float sizeX, float sizeY, float sizeZ) { GameObject cubetmp = Instantiate(cubeObj, Vector3.zero, Quaternion.identity) as GameObject; cubetmp.transform.position = new Vector3(x - sizeX / 2, y - sizeY / 2, z - sizeZ / 2); cubetmp.transform.parent = father.transform; float size = Mathf.Min(sizeX, Mathf.Min(sizeY, sizeZ)); size = size / Mathf.Sqrt(3); cubetmp.transform.localScale = new Vector3(size, size, size); CubeRotation cubeRotationScript = cubetmp.GetComponent <CubeRotation> (); cubeRotationScript.Xaxis = Random.Range(0, maxRotationX); cubeRotationScript.Yaxis = Random.Range(0, maxRotationY); cubeRotationScript.Zaxis = Random.Range(0, maxRotationZ); }
// Use this for initialization void Start() { int totalCubes = 20; float totalDistance = 2.0f; for (int i = 0; i < totalCubes; i++) { float perc = i / (float)totalCubes; float sin = Mathf.Sin(perc * Mathf.PI / 2); float x = 1.8f + sin * totalDistance; float y = 5.0f; float z = 0.0f; GameObject newCube = (GameObject)Instantiate(cubePrefab, new Vector3(x, y, z), Quaternion.identity); CubeRotation cubeRotation = newCube.GetComponent <CubeRotation> (); cubeRotation.SetSize((1 - perc) * 0.6f); cubeRotation.rotateSpeed = .4f + perc * 3.2f; // perc } }
public void Rotate(CubeRotation rot) { switch (rot) { case CubeRotation.RIGHT: RotateRight(); break; case CubeRotation.LEFT: RotateLeft(); break; case CubeRotation.UP: RotateUp(); break; case CubeRotation.DOWN: RotateDown(); break; default: throw new ArgumentOutOfRangeException(); } }
static MainWindow() { // Create a class for each side of the cube which contains the // quaternion rotation needed to display the side based on the // intially displayed side being the 'front'. _cubeFrontSideFacing = new CubeRotation() { CubeSide = CubeSide.Front, Quaternion = new Quaternion(new Vector3D(0, 0, 1), 0) }; _cubeBackSideFacing = new CubeRotation() { CubeSide = CubeSide.Back, Quaternion = new Quaternion(new Vector3D(0, 1, 0), 180) }; _cubeLeftSideFacing = new CubeRotation() { CubeSide = CubeSide.Left, Quaternion = new Quaternion(new Vector3D(0, 1, 0), -90) }; _cubeRightSideFacing = new CubeRotation() { CubeSide = CubeSide.Right, Quaternion = new Quaternion(new Vector3D(0, 1, 0), 90) }; _cubeTopSideFacing = new CubeRotation() { CubeSide = CubeSide.Top, Quaternion = new Quaternion(new Vector3D(1, 0, 0), -90) }; _cubeBottomSideFacing = new CubeRotation() { CubeSide = CubeSide.Bottom, Quaternion = new Quaternion(new Vector3D(1, 0, 0), 90) }; // For each cube side that could be facing there are 4 possible directions (based on user dragging a mouse) // to rotate the cube. // Store this as a collection for easy use later on. _possibleRotationMatrix = new Dictionary <CubeSide, Dictionary <Direction, CubeRotation> >(); Dictionary <Direction, CubeRotation> possibleRotations = new Dictionary <Direction, CubeRotation>(5); // 1. FRONT - First store all possible rotations from the cube front side facing possibleRotations[Direction.None] = _cubeFrontSideFacing; possibleRotations[Direction.West] = _cubeRightSideFacing; possibleRotations[Direction.East] = _cubeLeftSideFacing; possibleRotations[Direction.North] = _cubeBottomSideFacing; possibleRotations[Direction.South] = _cubeTopSideFacing; _possibleRotationMatrix[CubeSide.Front] = possibleRotations; // 2. BACK possibleRotations = new Dictionary <Direction, CubeRotation>(5); possibleRotations[Direction.None] = _cubeBackSideFacing; possibleRotations[Direction.West] = _cubeLeftSideFacing; possibleRotations[Direction.East] = _cubeRightSideFacing; possibleRotations[Direction.North] = _cubeBottomSideFacing; possibleRotations[Direction.South] = _cubeTopSideFacing; _possibleRotationMatrix[CubeSide.Back] = possibleRotations; // 3. LEFT possibleRotations = new Dictionary <Direction, CubeRotation>(5); possibleRotations[Direction.None] = _cubeLeftSideFacing; possibleRotations[Direction.West] = _cubeFrontSideFacing; possibleRotations[Direction.East] = _cubeBackSideFacing; possibleRotations[Direction.North] = _cubeBottomSideFacing; possibleRotations[Direction.South] = _cubeTopSideFacing; _possibleRotationMatrix[CubeSide.Left] = possibleRotations; // 4. RIGHT possibleRotations = new Dictionary <Direction, CubeRotation>(5); possibleRotations[Direction.None] = _cubeRightSideFacing; possibleRotations[Direction.West] = _cubeBackSideFacing; possibleRotations[Direction.East] = _cubeFrontSideFacing; possibleRotations[Direction.North] = _cubeBottomSideFacing; possibleRotations[Direction.South] = _cubeTopSideFacing; _possibleRotationMatrix[CubeSide.Right] = possibleRotations; // 5. TOP possibleRotations = new Dictionary <Direction, CubeRotation>(5); possibleRotations[Direction.None] = _cubeTopSideFacing; possibleRotations[Direction.West] = _cubeRightSideFacing; possibleRotations[Direction.East] = _cubeLeftSideFacing; possibleRotations[Direction.North] = _cubeFrontSideFacing; possibleRotations[Direction.South] = _cubeBackSideFacing; _possibleRotationMatrix[CubeSide.Top] = possibleRotations; // 6. BOTTOM possibleRotations = new Dictionary <Direction, CubeRotation>(5); possibleRotations[Direction.None] = _cubeBottomSideFacing; possibleRotations[Direction.West] = _cubeRightSideFacing; possibleRotations[Direction.East] = _cubeLeftSideFacing; possibleRotations[Direction.North] = _cubeBackSideFacing; possibleRotations[Direction.South] = _cubeFrontSideFacing; _possibleRotationMatrix[CubeSide.Bottom] = possibleRotations; }
public MainWindow() { InitializeComponent(); _currentCubeRotation = _cubeFrontSideFacing; }
/// <summary> /// Rotate the CubeCoordinate around a center on the hexagonal grid. /// </summary> /// <param name="target">The CubeCoordinate to rotate.</param> /// <param name="center">The center of the rotation.</param> /// <param name="rotation">The angle of rotation.</param> /// <returns>A CubeCoordinate representing the rotation around the center on the hexagonal grid</returns> public static CubeCoordinate RotateCoordinate(CubeCoordinate target, CubeCoordinate center, CubeRotation rotation) { CubeCoordinate vectorIN = target - center; CubeCoordinate vectorOut = vectorIN; switch (rotation) { case CubeRotation.CW_60: case CubeRotation.CCW_300: vectorOut = new CubeCoordinate(-vectorIN.S, -vectorIN.Q, -vectorIN.R); break; case CubeRotation.CW_120: case CubeRotation.CCW_240: vectorOut = new CubeCoordinate(vectorIN.R, vectorIN.S, vectorIN.Q); break; case CubeRotation.CW_180: case CubeRotation.CCW_180: vectorOut = vectorIN * -1; break; case CubeRotation.CW_240: case CubeRotation.CCW_120: vectorOut = new CubeCoordinate(vectorIN.S, vectorIN.Q, vectorIN.R); break; case CubeRotation.CW_300: case CubeRotation.CCW_60: vectorOut = new CubeCoordinate(-vectorIN.R, -vectorIN.S, -vectorIN.Q); break; } return(center + vectorOut); }