public Vector3 AnswerRequest(RotateAxis axis, float angle) { Vector3 rotateAxis = new Vector3(); switch (axis) { case RotateAxis.UP: { rotateAxis = _lerpToObject.transform.up; break; } case RotateAxis.DOWN: { rotateAxis = -_lerpToObject.transform.up; break; } case RotateAxis.RIGHT: { rotateAxis = _lerpToObject.transform.right; break; } case RotateAxis.LEFT: { rotateAxis = -_lerpToObject.transform.right; break; } case RotateAxis.FORWARD: { rotateAxis = _lerpToObject.transform.forward; break; } case RotateAxis.BACK: { rotateAxis = -_lerpToObject.transform.forward; break; } } Time.timeScale = 0.2f; _lerpCounter = 0.0f; _currentPosition = _camera.transform.position; _currentRotation = _camera.transform.rotation; _lerpToObject.transform.RotateAround(Vector3.zero, rotateAxis, angle); _shouldUpdate = true; return(_lerpToObject.transform.up); }
/* The next two methods are overrides from IPGameObject. In addition to the * base class methods, we save and restore variables specific to this class. */ public override void SaveCheckpointState() { base.SaveCheckpointState(); savedAttachPlayer = attachPlayer; savedDirection = direction; savedRotationAxis = rotationAxis; savedStepDegrees = stepDegrees; savedStepDelay = stepDelay; savedSpeed = speed; savedAxis = axis; savedAngle = angle; savedDelayed = delayed; }
private void rotateButton_Click(object sender, RoutedEventArgs e) { RotateAxis r = RotateAxis.RotateNone; int angle = (int)angelComboBox.SelectedItem; switch ((string)axisComboBox.SelectedItem) { case "X": r = RotateAxis.RotateX; break; case "Y": r = RotateAxis.RotateY; break; case "Z": r = RotateAxis.RotateZ; break; case "A": r = RotateAxis.RotateA; break; } int[] dims = _arrCtl.Data.GetDimensions(); switch (_arrCtl.Data.Rank) { case 2: Reset((_arrCtl.Data.AsEnumerable <object>().ToArray(dims[0], dims[1])).Rotate(angle)); break; case 3: Reset((_arrCtl.Data.AsEnumerable <object>().ToArray(dims[0], dims[1], dims[2])).Rotate(r, angle)); break; case 4: Reset((_arrCtl.Data.AsEnumerable <object>().ToArray(dims[0], dims[1], dims[2], dims[3])).Rotate(r, angle)); break; } }
public override void RestoreCheckpointState() { StopCoroutine("WaitForDelay"); base.RestoreCheckpointState(); attachPlayer = savedAttachPlayer; direction = savedDirection; rotationAxis = savedRotationAxis; stepDegrees = savedStepDegrees; stepDelay = savedStepDelay; speed = savedSpeed; delayed = savedDelayed; angle = savedAngle; axis = savedAxis; Debug.Log("Angle = " + angle + "Rot Angle = " + transform.eulerAngles.y); if (delayed) StartCoroutine("WaitForDelay"); }
private void RotateBrush(RotateAxis axis) { switch (axis) { case RotateAxis.X: Helper.RotateVoxelArrayX(ref EditorPersistence.Brush, EditorPersistence.BrushSize); int tempY = EditorPersistence.BrushSize.Y; EditorPersistence.BrushSize.Y = EditorPersistence.BrushSize.Z; EditorPersistence.BrushSize.Z = tempY; break; case RotateAxis.Y: Helper.RotateVoxelArrayY(ref EditorPersistence.Brush, EditorPersistence.BrushSize); int tempZ = EditorPersistence.BrushSize.Z; EditorPersistence.BrushSize.Z = EditorPersistence.BrushSize.X; EditorPersistence.BrushSize.X = tempZ; break; case RotateAxis.Z: Helper.RotateVoxelArrayZ(ref EditorPersistence.Brush, EditorPersistence.BrushSize); int tempX = EditorPersistence.BrushSize.X; EditorPersistence.BrushSize.X = EditorPersistence.BrushSize.Y; EditorPersistence.BrushSize.Y = tempX; break; } }
internal static HouseItem[] RotateGroup(HouseItem[] Items, double RotationDegree, RotateAxis axis, Vector3D RotatePoint, bool RotateAroundPoint) { decimal minx = 0 , miny = 0 , minz = 0 , maxx = 0 , maxy = 0 , maxz = 0 , medx = 0 , medy = 0 , medz = 0; if (RotateAroundPoint) { medx = Convert.ToDecimal(RotatePoint.X); medy = Convert.ToDecimal(RotatePoint.Y); medz = Convert.ToDecimal(RotatePoint.Z); } else { minx = Items[0].x; maxx = minx; medx = minx; miny = Items[0].y; maxy = miny; medy = miny; minz = Items[0].z; maxz = minz; medz = minz; foreach (HouseItem item in Items) { if (item.x < minx) { minx = item.x; } if (item.x > maxx) { maxx = item.x; } if (item.y < miny) { miny = item.y; } if (item.y > maxy) { maxy = item.y; } if (item.z < minz) { minz = item.z; } if (item.z > maxz) { maxz = item.z; } } medx = minx + ((maxx - minx) / 2); medy = miny + ((maxy - miny) / 2); medz = minz + ((maxz - minz) / 2); } int ItemCtr = Items.Length; double radRotation = RotationDegree / 180 * Math.PI; for (int curritem = 0; curritem < ItemCtr; curritem++) { double opposite = 0, adjacent = 0; double itemdegree = 0, itemradius = 0; switch (axis) { case RotateAxis.x: adjacent = (double)(Items[curritem].y - medy); opposite = (double)(Items[curritem].z - medz); if (adjacent == 0 && opposite > 0) { itemdegree = 0; } else if (adjacent == 0) { itemdegree = Math.PI; } else { itemdegree = Math.Atan2(opposite, adjacent); // * 180.0 / Math.PI; } itemradius = Math.Sqrt(Math.Pow(adjacent, 2.0) + Math.Pow(opposite, 2.0)); Items[curritem].y = (decimal)((double)medy + itemradius * Math.Cos(itemdegree + radRotation)); Items[curritem].z = (decimal)((double)medz + itemradius * Math.Sin(itemdegree + radRotation)); Items[curritem].Pitch -= (decimal)RotationDegree; break; case RotateAxis.y: adjacent = (double)(Items[curritem].x - medx); opposite = (double)(Items[curritem].z - medz); if (adjacent == 0 && opposite > 0) { itemdegree = 0; } else if (adjacent == 0) { itemdegree = Math.PI; } else { itemdegree = Math.Atan2(opposite, adjacent); // * 180.0 / Math.PI; } itemradius = Math.Sqrt(Math.Pow(adjacent, 2.0) + Math.Pow(opposite, 2.0)); Items[curritem].x = (decimal)((double)medx + itemradius * Math.Cos(itemdegree + radRotation)); Items[curritem].z = (decimal)((double)medz + itemradius * Math.Sin(itemdegree + radRotation)); Items[curritem].Roll += (decimal)RotationDegree; break; case RotateAxis.z: adjacent = (double)(Items[curritem].x - medx); opposite = (double)(Items[curritem].y - medy); if (adjacent == 0 && opposite > 0) { itemdegree = 0; } else if (adjacent == 0) { itemdegree = Math.PI; } else { itemdegree = Math.Atan2(opposite, adjacent); // * 180.0 / Math.PI; } itemradius = Math.Sqrt(Math.Pow(adjacent, 2.0) + Math.Pow(opposite, 2.0)); Items[curritem].x = (decimal)((double)medx + itemradius * Math.Cos(itemdegree + radRotation)); Items[curritem].y = (decimal)((double)medy + itemradius * Math.Sin(itemdegree + radRotation)); Items[curritem].Rotation -= (decimal)RotationDegree; break; } } return(Items); }