Beispiel #1
0
    public void SideToSide()
    {
        if (transform.position.x >= 9)
        {
            direction = -1;
        }
        else if (transform.position.x <= -9)
        {
            direction = 1;
        }

        t.Translate(new Vector3(1, 0) * moveSpeed * direction * Time.deltaTime);
        t.Rotate(new Vector3(0, 0, 1), spinSpeed * Time.deltaTime);
    }
Beispiel #2
0
    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();
    }
    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);
        }
    }