// Instantiates a moving gameobject GameObject InstantiateGameObject() { GameObject gameObj = new GameObject(); gameObj.AddComponent <GraphicalObject>(); gameObj.AddComponent <IGB283Transform>(); gameObj.AddComponent <ColourLerp>(); GraphicalObject gra = gameObj.GetComponent <GraphicalObject>(); gra.xSize = Random.Range(minVerts, maxVerts); gra.ySize = Random.Range(minVerts, maxVerts); IGB283Transform trans = gameObj.GetComponent <IGB283Transform>(); Vector3 newPos = new Vector3(Random.Range(-posRange, posRange), Random.Range(-posRange, posRange), 0); trans.initialPosition = newPos; trans.initialScale = new Vector3(Random.Range(minSize, maxSize), Random.Range(minSize, maxSize), 1); trans.xSpeed = Random.Range(minMovSpeed, maxMovSpeed); trans.rotSpeed = Random.Range(minRotSpeed, maxRotSpeed); ColourLerp col = gameObj.GetComponent <ColourLerp>(); col.colour00 = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255)); col.colour01 = new Color32((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255)); return(gameObj); }
public void renderSquare() { resetMesh(); Vector3[] vertices = mesh.vertices; Matrix3x3 translate = IGB283Transform.Translate(x, y); for (int i = 0; i < vertices.Length; i++) { vertices[i] = translate.MultiplyPoint(vertices[i]); } mesh.vertices = vertices; mesh.RecalculateBounds(); }
void Update() { positionX = positionX >= maxX ? maxX : positionX; positionY = positionY >= maxY ? maxY : positionY; positionX = positionX <= minX ? minX : positionX; positionY = positionY <= minY ? minY : positionY; r = positionX > 0 ? 1.0f : 0; g = positionY > 0 ? 1.0f : 0; b = positionX < 0 ? 1.0f : 0; resetMesh(r, g, b); translationSpeedX = positionX <maxX && positionX> minX ? translationSpeedX : -translationSpeedX; translationSpeedY = positionY <maxY && positionY> minY ? translationSpeedY : -translationSpeedY; size = size >= maxSize ? maxSize : size; size = size <= minSize ? minSize : size; bigger = size < maxSize && !smaller; smaller = size > minSize && !bigger; size = bigger && !smaller ? size + scalingSpeed : size - scalingSpeed; angle += Time.deltaTime * rotationSpeed; positionX += Time.deltaTime * translationSpeedX; positionY += Time.deltaTime * translationSpeedY; size += Time.deltaTime * scalingSpeed; Vector3[] vertices = mesh.vertices; Matrix3x3 scale = IGB283Transform.Scale(size, size); Matrix3x3 rotate = IGB283Transform.Rotate(angle); Matrix3x3 translate = IGB283Transform.Translate(positionX, positionY); //Matrix3x3 transformation = TRS Matrix3x3 transformation = translate * rotate * scale; for (int i = 0; i < vertices.Length; i++) { vertices[i] = transformation.MultiplyPoint(vertices[i]); } mesh.vertices = vertices; mesh.RecalculateBounds(); }
void Move() { Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (moving) { resetMesh(); x = mousePosition.x; y = mousePosition.y; Vector3[] vertices = mesh.vertices; Matrix3x3 translate = IGB283Transform.Translate(mousePosition.x, mousePosition.y); for (int i = 0; i < vertices.Length; i++) { vertices[i] = translate.MultiplyPoint(vertices[i]); } mesh.vertices = vertices; mesh.RecalculateBounds(); } }
private void RotateAndTranslate(Shape shape, float point1, float point2) { Vector3 moveDir; if (!shape.MoveTowardsFirst) { if (shape.Center.x >= point2) { shape.MoveTowardsFirst = true; } moveDir = Vector3.right; } else { if (shape.Center.x <= point1) { shape.MoveTowardsFirst = false; } moveDir = Vector3.left; } if (!ThreeDimensional) { var center = new Vector2(shape.Center.x, shape.Center.y); Matrix3x3 T = IGB283Transform.Translate(-center); Matrix3x3 R = IGB283Transform.Rotate(shape.RotationSpeed.z * Time.deltaTime); Matrix3x3 TReverse = IGB283Transform.Translate(center + Time.deltaTime * shape.Speed * new Vector2(moveDir.x, moveDir.y)); shape.ApplyTransformation(TReverse * R * T); } else { IGB283.Matrix4x4 T = IGB283Transform.Translate(-shape.Center); IGB283.Matrix4x4 R = IGB283Transform.Rotate(shape.RotationSpeed * Time.deltaTime); IGB283.Matrix4x4 TReverse = IGB283Transform.Translate(shape.Center + Time.deltaTime * shape.Speed * moveDir); shape.ApplyTransformation(TReverse * R * T); } }
// Update is called once per frame private void Update() { //Left Click if (Input.GetMouseButtonDown(0)) { //Stupidly complicated interact code Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition) + new Vector3(0, 0, 10); Debug.Log(pos); Shape interactedShape; if (TryGetClosestShape(pos, out interactedShape)) { if (interactedShape.Speed < maxSpeed) { interactedShape.Speed += 1; } Debug.Log("Interacted at: " + interactedShape.Center); draggedShape = interactedShape; } } if (Input.GetMouseButton(0) && draggedShape != null) { if (curDragCooldown > 0) { curDragCooldown -= Time.deltaTime; } else { float distance = Camera.main.ScreenToWorldPoint(Input.mousePosition).y - draggedShape.Center.y; Debug.Log(distance); Matrix3x3 T = IGB283Transform.Translate(new Vector2(0, distance)); draggedShape.ApplyTransformation(T); } } if (Input.GetMouseButtonUp(0)) { draggedShape = null; curDragCooldown = DragCooldown; } //Right Click if (Input.GetMouseButtonDown(1)) { //Stupidly complicated interact code Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition) + new Vector3(0, 0, 10); Debug.Log(pos); Shape interactedShape; if (TryGetClosestShape(pos, out interactedShape)) { if (interactedShape.Speed > 0) { interactedShape.Speed -= 1; } Debug.Log("Interacted at: " + interactedShape.Center); } } RotateAndTranslate(shapes[0], -1, 1); RotateAndTranslate(shapes[1], -1, 1); RotateAndTranslate(shapes[2], -1, 1); RotateAndTranslate(shapes[3], -1, 1); RotateAndTranslate(shapes[4], -1, 1); UpdateMesh(); }