当前位置: 首页>>代码示例>>C#>>正文


C# Matrix4x4.SetTRS方法代码示例

本文整理汇总了C#中UnityEngine.Matrix4x4.SetTRS方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix4x4.SetTRS方法的具体用法?C# Matrix4x4.SetTRS怎么用?C# Matrix4x4.SetTRS使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Matrix4x4的用法示例。


在下文中一共展示了Matrix4x4.SetTRS方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CalculateScaleTimeMatrix

 public bool CalculateScaleTimeMatrix(float fromTime, float toTime, float offsetTime, float pivotTime, float frameRate, out Matrix4x4 transform, out bool flipKeys)
 {
     transform = Matrix4x4.identity;
     flipKeys = false;
     float num = !Mathf.Approximately(frameRate, 0f) ? (1f / frameRate) : 0.001f;
     float f = toTime - pivotTime;
     float num3 = fromTime - pivotTime;
     if ((Mathf.Abs(f) - offsetTime) < 0f)
     {
         return false;
     }
     f = (Mathf.Sign(f) != Mathf.Sign(num3)) ? (f + offsetTime) : (f - offsetTime);
     if (Mathf.Approximately(num3, 0f))
     {
         transform.SetTRS(new Vector3(f, 0f, 0f), Quaternion.identity, Vector3.one);
         flipKeys = false;
         return true;
     }
     if (Mathf.Abs(f) < num)
     {
         f = (f >= 0f) ? num : -num;
     }
     float x = f / num3;
     transform.SetTRS(new Vector3(pivotTime, 0f, 0f), Quaternion.identity, Vector3.one);
     transform *= Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(x, 1f, 1f));
     transform *= Matrix4x4.TRS(new Vector3(-pivotTime, 0f), Quaternion.identity, Vector3.one);
     flipKeys = x < 0f;
     return true;
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:29,代码来源:RectangleTool.cs

示例2: CalculateScaleValueMatrix

 public bool CalculateScaleValueMatrix(float fromValue, float toValue, float offsetValue, float pivotValue, out Matrix4x4 transform, out bool flipKeys)
 {
     transform = Matrix4x4.identity;
     flipKeys = false;
     float num = 0.001f;
     float f = toValue - pivotValue;
     float num3 = fromValue - pivotValue;
     if ((Mathf.Abs(f) - offsetValue) < 0f)
     {
         return false;
     }
     f = (Mathf.Sign(f) != Mathf.Sign(num3)) ? (f + offsetValue) : (f - offsetValue);
     if (Mathf.Approximately(num3, 0f))
     {
         transform.SetTRS(new Vector3(0f, f, 0f), Quaternion.identity, Vector3.one);
         flipKeys = false;
         return true;
     }
     if (Mathf.Abs(f) < num)
     {
         f = (f >= 0f) ? num : -num;
     }
     float y = f / num3;
     transform.SetTRS(new Vector3(0f, pivotValue, 0f), Quaternion.identity, Vector3.one);
     transform *= Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1f, y, 1f));
     transform *= Matrix4x4.TRS(new Vector3(0f, -pivotValue, 0f), Quaternion.identity, Vector3.one);
     flipKeys = y < 0f;
     return true;
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:29,代码来源:RectangleTool.cs

示例3: LocalToWorldMatrixWithoutScale

 public static Matrix4x4 LocalToWorldMatrixWithoutScale(this Transform transform)
 {
     Matrix4x4 matrix;
     matrix = new Matrix4x4();
     matrix.SetTRS(transform.position, transform.rotation, Vector3.one);
     return matrix;
 }
开发者ID:Jasper-Hilven,项目名称:LudumDare33,代码行数:7,代码来源:ExtensionMethodsTransform.cs

示例4: RenderMeshPreview

    public static void RenderMeshPreview(RoseMapObjectData mapObj, PreviewRenderUtility previewUtility, Vector2 direction)
    {
        if (mapObj == null || previewUtility == null)
        {
            return;
        }

        Bounds bounds = new Bounds();
        Matrix4x4[] mats = new Matrix4x4[mapObj.subObjects.Count];
        for (var i = 0; i < mapObj.subObjects.Count; ++i)
        {
            var subObj = mapObj.subObjects[i];

            Matrix4x4 mat = new Matrix4x4();
            mat.SetTRS(subObj.position, subObj.rotation, subObj.scale);
            if (i != 0)
                mat = mats[subObj.parent - 1] * mat;

            Utils.EncapsulateTransformedBounds(ref bounds, mat, subObj.mesh.bounds, i == 0);

            mats[i] = mat;
        }

        float magnitude = bounds.extents.magnitude;
        float num = 4f * magnitude;
        previewUtility.m_Camera.transform.position = -Vector3.forward * num;
        previewUtility.m_Camera.transform.rotation = Quaternion.identity;
        previewUtility.m_Camera.nearClipPlane = num - magnitude * 1.1f;
        previewUtility.m_Camera.farClipPlane = num + magnitude * 1.1f;
        previewUtility.m_Light[0].intensity = 1.4f;
        previewUtility.m_Light[0].transform.rotation = Quaternion.Euler(40f, 40f, 0f);
        previewUtility.m_Light[1].intensity = 1.4f;
        Color ambient = new Color(0.1f, 0.1f, 0.1f, 0f);
        RenderMeshPreviewSkipCameraAndLighting(mapObj, mats, bounds, previewUtility, null, direction);
    }
开发者ID:osROSE,项目名称:UnityRose,代码行数:35,代码来源:RoseMapObjectDataEditor.cs

示例5: Update

    // Update is called once per frame
    void Update()
    {
        if(isAnim){
        this.transform.Rotate(Vector3.one * Time.deltaTime * rotateSpeed);
        }

        for(int i = 0; i < num; i++){
            Matrix4x4 mtx = new Matrix4x4();
            float x = (Mathf.PerlinNoise((float)i/2.4f, 0.0f) - 0.5f) * 30;
            float y = (Mathf.PerlinNoise((float)i/5.6f, 0.25f) - 0.5f) * 30;
            float z = (Mathf.PerlinNoise((float)i/8.2f, 0.5f) - 0.5f) * 30;
            Vector3 size = Vector3.one * (Mathf.PerlinNoise((float)i/3.4f, 0.5f) + 0.01f);
            Vector3 pos = this.transform.rotation * new Vector3(x, y, z);
            Quaternion rot = Quaternion.AngleAxis((Mathf.PerlinNoise((float)i/num, 0.0f) - 0.5f) * 360, new Vector3(0.5f, 0.5f, 0.5f));
            mtx.SetTRS(pos, rot, size);

            Material _mat;
            if(i % 5 == 0){
                _mat = mats[0];
            }else if(i % 9 == 0){
                _mat = mats[1];
            }else{
                _mat = mats[2];
            }
            Graphics.DrawMesh(mesh, mtx, _mat, 0);
        }
    }
开发者ID:inoook,项目名称:EffectShader,代码行数:28,代码来源:Cubes.cs

示例6: BeginUIResizing

    public void BeginUIResizing()
    {
        Vector2 nativeSize = NativeResolution;
        _didResizeUI = true;

        stack.Add (GUI.matrix);
        Matrix4x4 m = new Matrix4x4 ();
        float w = Screen.width;
        float h = Screen.height;
        float aspect = w / h;

        if (aspect < (nativeSize.x / nativeSize.y)) {
            //screen is taller
            _guiScaleFactor = (Screen.width / nativeSize.x);
            _offset.y = (Screen.height - (nativeSize.y * _guiScaleFactor)) * 0.5f;
        }
        else {
            //screen is wider
            _guiScaleFactor = (Screen.height/nativeSize.y);
            _offset.x = (Screen.width-(nativeSize.x*_guiScaleFactor))*0.5f;
        }

        m.SetTRS (_offset,Quaternion.identity,Vector3.one*_guiScaleFactor);
        GUI.matrix *= m;
    }
开发者ID:dalinhuang,项目名称:Unity_3D-display-system,代码行数:25,代码来源:ima_scan_start.cs

示例7: Start

	// Use this for initialization
	void Start () {
		kinect = devOrEmu.getKinect();
		players = new Kinect.NuiSkeletonTrackingState[Kinect.Constants.NuiSkeletonCount];
		trackedPlayers = new int[Kinect.Constants.NuiSkeletonMaxTracked];
		trackedPlayers[0] = -1;
		trackedPlayers[1] = -1;
		bonePos = new Vector3[2,(int)Kinect.NuiSkeletonPositionIndex.Count];
		rawBonePos = new Vector3[2,(int)Kinect.NuiSkeletonPositionIndex.Count];
		boneVel = new Vector3[2,(int)Kinect.NuiSkeletonPositionIndex.Count];
		
		boneState = new Kinect.NuiSkeletonPositionTrackingState[2,(int)Kinect.NuiSkeletonPositionIndex.Count];
		boneLocalOrientation = new Quaternion[2, (int)Kinect.NuiSkeletonPositionIndex.Count];
		boneAbsoluteOrientation = new Quaternion[2, (int)Kinect.NuiSkeletonPositionIndex.Count];
		
		//create the transform matrix that converts from kinect-space to world-space
		Matrix4x4 trans = new Matrix4x4();
		trans.SetTRS( new Vector3(-kinect.getKinectCenter().x,
		                          kinect.getSensorHeight()-kinect.getKinectCenter().y,
		                          -kinect.getKinectCenter().z),
		             Quaternion.identity, Vector3.one );
		Matrix4x4 rot = new Matrix4x4();
		Quaternion quat = new Quaternion();
		double theta = Mathf.Atan((kinect.getLookAt().y+kinect.getKinectCenter().y-kinect.getSensorHeight()) / (kinect.getLookAt().z + kinect.getKinectCenter().z));
		float kinectAngle = (float)(theta * (180 / Mathf.PI));
		quat.eulerAngles = new Vector3(-kinectAngle, 0, 0);
		rot.SetTRS( Vector3.zero, quat, Vector3.one);

		//final transform matrix offsets the rotation of the kinect, then translates to a new center
		kinectToWorld = flipMatrix*trans*rot;
	}
开发者ID:BUscinski,项目名称:Firmamentum,代码行数:31,代码来源:SkeletonWrapper.cs

示例8: Begin

 /// <summary>
 /// Resize all future GUI calls to fit within fixed dimensions.
 /// </summary>
 /// <param name="width">
 /// A <see cref="System.Single"/>
 /// </param>
 /// <param name="height">
 /// A <see cref="System.Single"/>
 /// </param>
 public static void Begin(float width, float height)
 {
     GUIX.width = width;
     GUIX.height = height;
     stack.Add (GUI.matrix);
     Matrix4x4 m = new Matrix4x4 ();
     ComputeScaleAndOffset();
     m.SetTRS(offset+guiOffset, Quaternion.identity, Vector3.one * scale);
     GUI.matrix *= m;
 }
开发者ID:arunredmonster,项目名称:app-unity-master,代码行数:19,代码来源:GUIX.cs

示例9: Update

	// Update is called once per frame
	void Update () {

		if(m_time<= 0){
			float angle = Random.value*360.0f;
			m_time = (Random.value*3.0f)+2.0f;
			Matrix4x4 rotMatrix = new Matrix4x4();
			rotMatrix.SetTRS(new Vector3(), Quaternion.Euler(0.0f, angle, 0.0f), new Vector3(1.0f, 1.0f, 1.0f));
			body.velocity = rotMatrix.MultiplyVector(Vector3.right);
			body.velocity *= m_speed; 
		}else{
			m_time-=Time.deltaTime;
		}
	}
开发者ID:Lambwatt,项目名称:BrokenBladeScratch,代码行数:14,代码来源:EnemyMoveRandom.cs

示例10: DirectionTo3DGridPosition

    public Vector3 DirectionTo3DGridPosition(Vector3 observer, Vector3 direction, float yPlane)
    {
        direction = direction.normalized;

        Matrix4x4 mat = new Matrix4x4();

        float multiple = (yPlane - observer.y) / direction.y;

        mat.SetTRS(direction * multiple, Quaternion.identity, Vector3.one);

        Vector3 newPoint = mat.MultiplyPoint(observer);

        return GetNearest3DGridPoint(newPoint);
    }
开发者ID:amixtum,项目名称:block-placer-unity,代码行数:14,代码来源:GridPlacement.cs

示例11: SurfaceGrid

    public Vector3[] SurfaceGrid()
    {
        var width = Mathf.CeilToInt((float)Screen.width / pitchPix);
        var height = Mathf.CeilToInt((float)screenHeight / pitchPix);
        var widthPlusOne = width + 1;
        var heightPlusOne = height + 1;
        var vertexCount = widthPlusOne * heightPlusOne;
        if (vertexCount > VERTEX_LIMIT)
            return null;

        _triangleInvalidated = (width != _prevWidth || height != _prevHeight);
        if (_triangleInvalidated) {
            _mesh.Clear();
            _prevWidth = width;
            _prevHeight = height;
            _vertices = new Vector3[vertexCount];
        }

        var m = new Matrix4x4();
        m.SetTRS(new Vector3(-1f, -1f, 0f), Quaternion.identity, new Vector3(2f / Screen.width, 2f / Screen.height, 1f));
        m = targetCamera.cameraToWorldMatrix * targetCamera.projectionMatrix.inverse * m;
        var v = new Vector4(0f, 0f, 0f, 1f);
        for (var y = 0; y <= height; y++) {
            for (var x = 0; x <= width; x++) {
                var i = y * widthPlusOne + x;
                v.x = x * pitchPix;
                v.y = screenHeight - y * pitchPix;
                _vertices[i] = m.MultiplyPoint(v);
            }
        }

        if (_triangleInvalidated) {
            _triangles = new int[6 * width * height];
            var counter = 0;
            for (var y = 0; y < height; y++) {
                for (var x = 0; x < width; x++) {
                    var i = y * widthPlusOne + x;
                    _triangles[counter++] = i;
                    _triangles[counter++] = i + 1;
                    _triangles[counter++] = i + + widthPlusOne + 1;
                    _triangles[counter++] = i;
                    _triangles[counter++] = i + widthPlusOne + 1;
                    _triangles[counter++] = i + widthPlusOne;
                }
            }
        }

        return _vertices;
    }
开发者ID:nobnak,项目名称:ScreenSpaceMesh,代码行数:49,代码来源:ScreenSpaceGrid.cs

示例12: shoot

	void shoot(){

		//Create Shot
		Vector3 projectilePosition = this.transform.position;
		projectilePosition += this.transform.right * 1.5f;
		Transform clone = Instantiate(projectile, projectilePosition, Quaternion.identity) as Transform;
		activeAbility.setShot(clone.GetComponent<Projectile>());
		clone.RotateAround(this.transform.position, Vector3.up, m_angleToMouse);

		//Shot Pattern
		Matrix4x4 rotMatrix = new Matrix4x4();
		rotMatrix.SetTRS(new Vector3(), Quaternion.Euler(0.0f, m_angleToMouse, 0.0f), new Vector3(1.0f, 1.0f, 1.0f));
		clone.GetComponent<Rigidbody>().velocity = rotMatrix.MultiplyVector(Vector3.right);
		clone.GetComponent<Rigidbody>().velocity *= shotSpeed; 
		 
	}
开发者ID:Lambwatt,项目名称:BrokenBladeScratch,代码行数:16,代码来源:PlayerShoot.cs

示例13: shoot

	void shoot(){
		if(player!=null){
			float angleToPlayer = -Mathf.Atan2(player.position.z-transform.position.z, player.position.x-transform.position.x)*Mathf.Rad2Deg;
			
			Vector3 projectilePosition = this.transform.position;
			projectilePosition += this.transform.right * 1.5f;

			Transform clone = Instantiate(projectile, projectilePosition, Quaternion.identity) as Transform;

			attack.setShot(clone.GetComponent<Projectile>());
			clone.RotateAround(this.transform.position, Vector3.up, angleToPlayer);
			
			Matrix4x4 rotMatrix = new Matrix4x4();
			rotMatrix.SetTRS(new Vector3(), Quaternion.Euler(0.0f, angleToPlayer, 0.0f), new Vector3(1.0f, 1.0f, 1.0f));
			clone.GetComponent<Rigidbody>().velocity = rotMatrix.MultiplyVector(Vector3.right);
			clone.GetComponent<Rigidbody>().velocity *= speed; 
		}
	}
开发者ID:Lambwatt,项目名称:BrokenBladeScratch,代码行数:18,代码来源:EnemyShootAtPlayer.cs

示例14: Map

	public override Vector3 Map(int i, Vector3 p)
	{
		p = tm.MultiplyPoint3x4(p);	// Dont need either, so saving 3 vector mat mults but gaining a mat mult

		float alpha;

		if ( UseStretchCurve )
		{
			float str = stretchCurve.Evaluate(Mathf.Repeat(p.z * ovlen + usepercent, 1.0f)) * stretch;
			alpha = (p.z * ovlen * str) + usepercent;	//(percent / 100.0f);	// can precalc this
		}
		else
			alpha = (p.z * ovlen * stretch) + usepercent;	//(percent / 100.0f);	// can precalc this

		Vector3 ps	= path.InterpCurve3D(0, alpha, path.normalizedInterp);	// - start;
		Vector3 ps1	= path.InterpCurve3D(0, alpha + usetan, path.normalizedInterp);	// - start;

		if ( path.splines[0].closed )
			alpha = Mathf.Repeat(alpha, 1.0f);
		else
			alpha = Mathf.Clamp01(alpha);

		Quaternion	tw = Quaternion.identity;

		if ( UseTwistCurve )
		{
			float twst = twistCurve.Evaluate(alpha) * twist;
			tw = Quaternion.AngleAxis(twst, Vector3.forward);
		}
		else
			tw = Quaternion.AngleAxis(twist * alpha, Vector3.forward);

		Vector3 relativePos = ps1 - ps;
		Quaternion rotation = Quaternion.LookRotation(relativePos) * tw;

		Matrix4x4	wtm = new Matrix4x4();
		wtm.SetTRS(ps, rotation, Vector3.one);

		wtm = mat * wtm;
		p.z = 0.0f;

		return wtm.MultiplyPoint3x4(p);
	}
开发者ID:xiaopangoo,项目名称:MotionPlatform,代码行数:43,代码来源:MegaWorldPathDeform.cs

示例15: Draw

    /// <summary>
    /// ギズモを表示
    /// </summary>
    private void Draw()
    {
        float centerX;
        float centerY;
        float centerZ;

        if(centerToCornerX)
            centerX = this.transform.position.x + ((gizmoSize.x / 2.0f) * (invertCornerX ? -1.0f : 1.0f));
        else
            centerX = this.transform.position.x;

        if(centerToCornerY)
            centerY = this.transform.position.y + ((gizmoSize.y / 2.0f) * (invertCornerY ? -1.0f : 1.0f));
        else
            centerY = this.transform.position.y;

        if(centerToCornerZ)
            centerZ = this.transform.position.z - ((gizmoSize.z / 2.0f) * (invertCornerZ ? -1.0f : 1.0f));
        else
            centerZ = this.transform.position.z;

        Matrix4x4 tempMat = Gizmos.matrix;
        Matrix4x4 mat = new Matrix4x4();
        mat.SetTRS(
            new Vector3(centerX, centerY, centerZ),
            this.gameObject.transform.localRotation,
            Vector3.one);
        Gizmos.matrix = mat;

        switch(gizmoType)
        {
            case GIZMO_TYPE.CUBE:
                Gizmos.DrawWireCube(Vector3.zero, gizmoSize);
                break;
            case GIZMO_TYPE.SPHERE:
                Gizmos.DrawWireSphere(Vector3.zero, gizmoSize.x / 2.0f);
                break;
            default: break;
        }

        Gizmos.matrix = tempMat;
    }
开发者ID:sgyli7,项目名称:GarageKit_for_Unity,代码行数:45,代码来源:GizmoDrawer.cs


注:本文中的UnityEngine.Matrix4x4.SetTRS方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。