void Update() { bool needRedraw = false; if (Input.GetButton("XBoxBt7") || Input.GetKeyDown(KeyCode.Q)) { rotationObject = RotationStruct.Next(); needRedraw = true; } else if (Input.GetButton("XBoxBt8") || Input.GetKeyDown(KeyCode.W)) { rotationObject = RotationStruct.Previous(); needRedraw = true; } if (Input.GetKey(KeyCode.Equals)) { RotateObject(rotationObject, 1); needRedraw = true; } else if (Input.GetKey(KeyCode.Minus)) { RotateObject(rotationObject, -1); needRedraw = true; } if (needRedraw && rotationObject != null) { needRedraw = false; UnColorObjects(); DrawAxisAndColorObjects(rotationObject); DrawUI(rotationObject); } }
void SwitchCurrentRotationObject() { currentObjectIndex++; if (currentObjectIndex == rotationObjects.Count) { currentObjectIndex = 0; } currentRotationObject.axes.SetActive(false); currentRotationObject = rotationObjects[currentObjectIndex]; currentRotationObject.axes.SetActive(true); }
void ColorObjectsRed(RotationObject rot) { foreach (GameObject go in rot.dependantObjects) { if (go != null) { Renderer renderer = go.GetComponent <Renderer> (); renderer.material.color = Color.red; coloredObjects.Add(go); } } }
void RotateObject(RotationObject ro, int direction) { foreach (GameObject go in ro.dependantObjects) { if (go != null) { //Vector3 rotationFrom = go.transform.position; //Quaternion actualRotation = go.transform.rotation; //print ("Game Object: " + go.name + " AroundObject : " + ro.goToRotateAround.name + " go pos " + go.transform.position + " axis " + ro.rotationAxis ); go.transform.RotateAround(ro.goToRotateAround.transform.position, ro.goToRotateAround.transform.rotation * ro.rotationAxis, (0.5f * direction)); } } }
private int FindRotationObjectPosition(RotationObject rot) { int i = 0; foreach (RotationObject aRot in RotationStruct.RotationObjectsValues()) { if (aRot.name.Equals(rot.name)) { return(i); } i++; } return(-1); }
void DrawAxisRotation(RotationObject rot) { lineRenderer.SetVertexCount(2); lineRenderer.enabled = true; lineRenderer.material = new Material(Shader.Find("Particles/Additive")); lineRenderer.SetColors(Color.green, Color.green); lineRenderer.SetWidth(0.2f, 0.2f); lineRenderer.useWorldSpace = false; Vector3 point1 = rot.goToRotateAround.transform.position + (rot.goToRotateAround.transform.rotation * rot.rotationAxis * 3); Vector3 point2 = rot.goToRotateAround.transform.position + (rot.goToRotateAround.transform.rotation * rot.rotationAxis * -3); int i = 0; lineRenderer.SetPosition(i++, point1); lineRenderer.SetPosition(i++, point2); }
RotationObject CreateRotationObject(string name, GameObject goToRotateAround, GameObject pointForAngleCalc, Vector3 rotationAxis, Vector3 axisForAngleCalc, Vector3 signAxis, params GameObject[] values) { RotationObject rotObject = new RotationObject(); rotObject.name = name; rotObject.goToRotateAround = goToRotateAround; rotObject.pointForAngleCalc = pointForAngleCalc; rotObject.rotationAxis = rotationAxis; rotObject.axisForAngleCalc = axisForAngleCalc; rotObject.signAxis = signAxis; foreach (GameObject go in values) { if (go == null) { print("Can't get gameObject"); } rotObject.dependantObjects.Add(go); } return(rotObject); }
void DrawUI(RotationObject rot) { rotationObjectName.text = rot.name; Vector3 targetDir = rot.goToRotateAround.transform.position - rot.pointForAngleCalc.transform.position; Vector3 targetDirForDebug = targetDir; targetDir = rot.goToRotateAround.transform.InverseTransformDirection(targetDir); Vector3 targetDir2ForDebug = targetDir; if (rot.rotationAxis == Vector3.right || rot.rotationAxis == Vector3.left) { targetDir.x = 0; } else if (rot.rotationAxis == Vector3.up || rot.rotationAxis == Vector3.down) { targetDir.y = 0; } else if (rot.rotationAxis == Vector3.forward || rot.rotationAxis == Vector3.back) { targetDir.z = 0; } bool isPositive = true; if (rot.signAxis == Vector3.right) { isPositive = targetDir.x >= 0; } else if (rot.signAxis == Vector3.up) { isPositive = targetDir.y >= 0; } else if (rot.signAxis == Vector3.forward) { isPositive = targetDir.z >= 0; } else if (rot.signAxis == Vector3.left) { isPositive = targetDir.x <= 0; } else if (rot.signAxis == Vector3.down) { isPositive = targetDir.y <= 0; } else if (rot.signAxis == Vector3.back) { isPositive = targetDir.z <= 0; } float angle = Vector3.Angle(rot.axisForAngleCalc, targetDir) * (isPositive ? 1 : -1); //angle1.text = "" + angle; int index = FindRotationObjectPosition(rot); if (index != -1) { angles[index].text = "" + angle; } if (Input.GetKey(KeyCode.B)) { print("Point1 " + rot.goToRotateAround.transform.position + " Point2 " + rot.pointForAngleCalc.transform.position + " targetDir " + targetDirForDebug + " targetDir2 " + targetDir2ForDebug); print(rot.name + " Angle " + angle + " rotaxis " + rot.rotationAxis + " axis for anglecalc " + rot.axisForAngleCalc + " targetDir " + targetDir); } }
void DrawAxisAndColorObjects(RotationObject rot) { CreateLineRenderers(); DrawAxisRotation(rot); ColorObjectsRed(rot); }
void Awake() { currentRotationObject = rotationObjects[0]; currentRotationObject.axes.SetActive(true); }
public static void Add(RotationObject rotationObject) { rotationObjects.Add(rotationObject); //print ("Rotation Objects count: " + rotationObjects.Count); }