// Update is called once per frame void LateUpdate() { if (Input.GetMouseButton(1)) { float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); if (Mathf.Abs(h) > Mathf.Epsilon || Mathf.Abs(v) > Mathf.Epsilon) { float aOffset = h * rotateSpeed * Time.deltaTime; float eOffset = v * rotateSpeed * Time.deltaTime; cam.position = sphericalCoordinates.Rotate(aOffset, eOffset).ToCartesian() + pivot.position; } } float scroll = (-1f) * Input.GetAxis("Mouse ScrollWheel"); if (Mathf.Abs(scroll) > Mathf.Epsilon) { float scrollOffset = scroll * scrollSpeed * Time.deltaTime; cam.position = sphericalCoordinates.TranslateRadius(scrollOffset).ToCartesian() + pivot.position; } cam.LookAt(pivot); }
void Update() { float kh, kv, mh, mv, h, v; // I have manually inverted the controls because I think it makes it more intuitive kh = -1 * Input.GetAxis("Horizontal"); kv = -1 * Input.GetAxis("Vertical"); bool anyMouseButton = Input.GetMouseButton(0) | Input.GetMouseButton(1) | Input.GetMouseButton(2); mh = anyMouseButton ? Input.GetAxis("Mouse X") : 0f; mv = anyMouseButton ? Input.GetAxis("Mouse Y") : 0f; h = kh * kh > mh * mh ? kh : mh; v = kv * kv > mv * mv ? kv : mv; if (h * h > .1f || v * v > .1f) { transform.position = sc.Rotate(h * rotateSpeed * Time.deltaTime, v * rotateSpeed * Time.deltaTime).toCartesian + pivot.position; } float sw = -Input.GetAxis("Mouse ScrollWheel"); if (sw * sw > Mathf.Epsilon) { transform.position = sc.TranslateRadius(sw * Time.deltaTime * scrollSpeed).toCartesian + pivot.position; } transform.LookAt(pivot.position); }
// Update is called once per frame void Update() { DrawCameraLine(); float kh, kv, mh, mv, h, v; kh = Input.GetAxis("Horizontal"); kv = Input.GetAxis("Vertical"); bool anyMouseButton = Input.GetMouseButton(0) | Input.GetMouseButton(1) | Input.GetMouseButton(2); mh = anyMouseButton ? Input.GetAxis("Mouse X") : 0f; mv = anyMouseButton ? Input.GetAxis("Mouse Y") : 0f; h = kh * kh > mh * mh ? kh : mh; v = kv * kv > mv * mv ? kv : mv; if (h * h > Mathf.Epsilon || v * v > Mathf.Epsilon) { transform.position = sphericalCoordinates.Rotate(h * rotateSpeed * Time.deltaTime, v * rotateSpeed * Time.deltaTime).toCartesian + pivot.position; } float sw = -Input.GetAxis("Mouse ScrollWheel"); if (sw * sw > Mathf.Epsilon) { transform.position = sphericalCoordinates.TranslateRadius(sw * Time.deltaTime * scrollSpeed).toCartesian + pivot.position; } transform.LookAt(pivot.position); }
void UpdateMoveCamera() { _sphericalCoordinate.SetProperties( transform.position, 1, 500, 0, Mathf.PI * 2, Mathf.Deg2Rad * _upDownAngleMinMax.x, Mathf.Deg2Rad * _upDownAngleMinMax.y); //Mathf.Deg2Rad * _minAngle.x, Mathf.Deg2Rad * _maxAngle.x, transform.position = _sphericalCoordinate.toCartesian + _pivotPoint.position; if (Mov.x != 0 || Mov.y != 0) { transform.position = _sphericalCoordinate.Rotate(Mov.x * _speed * Time.deltaTime, Mov.y * _speed * Time.deltaTime).toCartesian + _pivotPoint.position; } // temporal zoom in, zoom out if (_zoom != 0) { transform.position = _sphericalCoordinate.TranslateRadius(_zoom * Time.deltaTime * _scrollSpeed).toCartesian + _pivotPoint.position; } //_distanceToPivot = (_camera.transform.position - _pivotPoint.transform.position).magnitude; transform.LookAt(_pivotPoint); }
private void Rotate() { if (f_horizontal * f_horizontal > Mathf.Epsilon || f_vertical * f_vertical > Mathf.Epsilon) { transform.position = sphericalCoordinates.Rotate(f_horizontal * rotateSpeed * Time.deltaTime, f_vertical * rotateSpeed * Time.deltaTime).toCartesian + target.position; } }
public void RotateCamera(float h, float v) { if (Mathf.Abs(h) > Mathf.Epsilon || Mathf.Abs(v) > Mathf.Epsilon) { float aOffset = h * rotateSpeed * Time.deltaTime; float eOffset = v * rotateSpeed * Time.deltaTime; sphericalCoordinates.Rotate(aOffset, eOffset); SetCamera(); } }
void Update() { var axis = movePaddle.GetAxis(SteamVR_Input_Sources.RightHand); var cx = axis.x; var cy = axis.y; var h = cx * cx > cy * cy ? cx : cy; if (h * h > .1f) { transform.position = sc.Rotate(cx * rotateSpeed * Time.deltaTime, cy * rotateSpeed * Time.deltaTime).toCartesian + Pivot.position; transform.LookAt(Pivot.transform, Vector3.up); transform.Rotate(Vector3.up, 180f); } if (Input.GetKeyDown("space")) { transform.position = sc.Rotate(0f, 0f).toCartesian; } }
void Update() { float h, v; h = Input.GetAxis("Mouse X"); v = Input.GetAxis("Mouse Y"); if (pivot == null) { return; } //Debug.Log("Pivot position: " + pivot.position); //Debug.Log("Spherical coordinates: " + sc); transform.position = sc.Rotate(-h * rotateSpeed * Time.deltaTime, -v * rotateSpeed * Time.deltaTime).toCartesian + pivot.position; float sw = -Input.GetAxis("Mouse ScrollWheel"); if (sw * sw > Mathf.Epsilon) { transform.position = sc.TranslateRadius(sw * Time.deltaTime * scrollSpeed).toCartesian + pivot.position; } transform.LookAt(pivot.position + cameraAssign); }
public void BuildWall() { SphericalCoordinates p1 = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); SphericalCoordinates p2 = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); SphericalCoordinates p3 = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); SphericalCoordinates p4 = new SphericalCoordinates(radius, 0, 0, 1, radius + .3f, -Mathf.PI, Mathf.PI, -Mathf.PI / 2, Mathf.PI / 2); int triBase; int numVertices = (segments) * 4 + 28; int numTriangles = (4 * segments) + 16; float polarDif = (polarSize * Mathf.Deg2Rad) / 2; float eleDif = (elevationSize * Mathf.Deg2Rad) / 2f; p1.SetRotation(-polarDif, eleDif); p2.SetRotation(-polarDif, -eleDif); p3.SetRotation(polarDif, eleDif); p4.SetRotation(polarDif, -eleDif); float polarStep = (polarSize * Mathf.Deg2Rad) / segments; float eleStep = 0;//(p1.elevation - p4.elevation) / segments; Vector3 p1Cart, p2Cart, p3Cart, p4Cart; p1Cart = p1.toCartesian; p2Cart = p2.toCartesian; p3Cart = p3.toCartesian; p4Cart = p4.toCartesian; //Vector3[] normals = new Vector3[numVertices]; Vector3[] vertices = new Vector3[numVertices]; int[] triangles = new int[3 * numTriangles]; Vector3 leftMid = (p1Cart + p3Cart) / 2; Vector3 rightMid = (p2Cart + p4Cart) / 2; Vector3 center = (leftMid + rightMid) / 2; //int v = 0; vertices[0] = p1Cart - center; vertices[1] = p2Cart - center; vertices[2] = p3Cart - center; vertices[3] = p4Cart - center; vertices[4] = leftMid - center; vertices[5] = rightMid - center; //Vector3 verticalNorm = -center.normalized; for (int i = 0; i < 6; i++) { //vertices[i + 6] = vertices[i] + height * norm; vertices[i + 6] = vertices[i+12] = vertices[i] - height * (vertices[i] + center).normalized; //normals[i + 6] = verticalNorm; } topLeft = vertices[6]; topRight = vertices[7]; bottomLeft = vertices[8]; bottomRight = vertices[9]; Vector3 farTopLeft = vertices[0]; Vector3 farTopRight = vertices[1]; Vector3 farBottomLeft = vertices[2]; Vector3 farBottomRight = vertices[3]; //front rectangle triangles[0] = 10; triangles[1] = 6; triangles[2] = 7; triangles[3] = 10; triangles[4] = 7; triangles[5] = 11; triangles[6] = 8; triangles[7] = 10; triangles[8] = 11; triangles[9] = 8; triangles[10] = 11; triangles[11] = 9; //left side rectangle triangles[12] = 16; triangles[13] = 4; triangles[14] = 12; triangles[15] = 12; triangles[16] = 4; triangles[17] = 0; triangles[18] = 2; triangles[19] = 4; triangles[20] = 16; triangles[21] = 14; triangles[22] = 2; triangles[23] = 16; //right side rectangle for (int i = 0; i < 12; i += 3) { triangles[i + 24] = triangles[i + 12] + 1; triangles[i + 25] = triangles[i + 14] + 1; triangles[i + 26] = triangles[i + 13] + 1; } vertices[18] = farTopLeft; vertices[19] = farTopRight; vertices[20] = farBottomLeft; vertices[21] = farBottomRight; vertices[22] = topLeft; vertices[23] = topRight; vertices[24] = bottomLeft; vertices[25] = bottomRight; //top rectangle triangles[36] = 23; triangles[37] = 22; triangles[38] = 19; triangles[39] = 19; triangles[40] = 22; triangles[41] = 18; //bottom rectangle triangles[42] = 24; triangles[43] = 25; triangles[44] = 20; triangles[45] = 20; triangles[46] = 25; triangles[47] = 21; vertices[26] = farTopLeft; vertices[27] = farTopRight; int roundleftIdx = 26; int roundrightIdx = 27; int flatLeftIdx = 0; int flatRightIdx = 1; for (int i = 1; i < segments; i++) { SphericalCoordinates newLeft = p1.Rotate(polarStep, eleStep); SphericalCoordinates newRight = p2.Rotate(polarStep, eleStep); //Debug.Log(newLeft.ToString()); //Debug.Log(newRight.ToString()); Vector3 nRCart = newRight.toCartesian - center; Vector3 nLCart = newLeft.toCartesian - center; int nLIdx = 4 * i + 26; int nRIdx = nLIdx+1; int bLIdx = nRIdx + 1; int bRIdx = bLIdx + 1; vertices[nLIdx] = vertices[bLIdx] = nLCart; vertices[nRIdx] = vertices [bRIdx] = nRCart; triBase = 12 * i + 36; triangles[triBase] = 4; triangles[triBase + 1] = bLIdx; triangles[triBase + 2] = flatLeftIdx; triangles[triBase + 3] = roundleftIdx; triangles[triBase + 4] = nLIdx; triangles[triBase + 5] = nRIdx; triangles[triBase + 6] = roundleftIdx; triangles[triBase + 7] = nRIdx; triangles[triBase + 8] = roundrightIdx; triangles[triBase + 9] = 5; triangles[triBase + 10] = flatRightIdx; triangles[triBase + 11] = bRIdx; roundleftIdx = nLIdx; roundrightIdx = nRIdx; flatLeftIdx = bLIdx; flatRightIdx = bRIdx; } vertices[flatRightIdx + 1] = farBottomLeft; vertices[flatRightIdx + 2] = farBottomRight; Debug.Log(flatRightIdx + 2); triBase = (3 * numTriangles) - 12; triangles[triBase] = 4; triangles[triBase + 1] = 2; triangles[triBase + 2] = flatLeftIdx; triangles[triBase + 3] = flatRightIdx + 2; triangles[triBase + 4] = roundleftIdx; triangles[triBase + 5] = flatRightIdx + 1; triangles[triBase + 6] = roundleftIdx; triangles[triBase + 7] = flatRightIdx + 2; triangles[triBase + 8] = roundrightIdx; triangles[triBase + 9] = 5; triangles[triBase + 10] = flatRightIdx; triangles[triBase + 11] = 3; //state = 'i'; Mesh mesh = new Mesh(); mesh.name = "Barrier"; mesh.vertices = vertices; mesh.triangles = triangles; mesh.RecalculateNormals(); //GameObject next = Instantiate(prefab, center, Quaternion.identity) as GameObject; p1.SetRotation(polarAngle * Mathf.Deg2Rad, elevationAngle * Mathf.Deg2Rad); p1.SetRadius(center.magnitude); transform.position = p1.toCartesian; GetComponent<MeshFilter>().sharedMesh = mesh; GetComponent<MeshCollider>().sharedMesh = mesh; CreateGlow(); }