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


C# Matrix4x4类代码示例

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


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

示例1: DrawCylinder

    /// <summary>
    /// Draws a gizmo cylinder with the given TRS matrix and color
    /// </summary>
    /// <param name="trs"></param>
    /// <param name="color"></param>
    public static void DrawCylinder(Matrix4x4 trs, Color color)
    {
        if (cylVerts == null || cylTris == null)
        {
            GameObject cyl = GameObject.CreatePrimitive(
                PrimitiveType.Cylinder);
            MeshFilter filter = cyl.GetComponent<MeshFilter>();
            cylVerts = filter.sharedMesh.vertices;
            cylTris = filter.sharedMesh.triangles;
            GameObject.DestroyImmediate(cyl);
        }

        Vector3[] verts = new Vector3[cylVerts.Length];
        for (int i = 0; i < cylVerts.Length; i++)
            verts[i] = trs.MultiplyPoint(cylVerts[i]);

        Gizmos.color = color;
        for (int i = 0; i < cylTris.Length / 3; i++)
        {
            int j = i * 3;
            Gizmos.DrawLine(verts[cylTris[j]],
                verts[cylTris[j + 1]]);
            Gizmos.DrawLine(verts[cylTris[j + 1]],
                verts[cylTris[j + 2]]);
            Gizmos.DrawLine(verts[cylTris[j + 2]],
                verts[cylTris[j]]);
        }
    }
开发者ID:alerdenisov,项目名称:ADAPT,代码行数:33,代码来源:GizmoDraw.cs

示例2: Start

 void Start()
 {
     // This creates the diagonalised inertia tensor matrix from the Vector3 by the physics engine.
     // Note the physics engine is using the colliders of the object and it's children, and
     // the mass of the parent object to calculate an approximate inertia tensor.
     __inertiaTensor = Matrix4x4.Scale (GetComponent<Rigidbody>().inertiaTensor);
 }
开发者ID:cupsster,项目名称:Rotorcross,代码行数:7,代码来源:Spinning.cs

示例3: ConvertTangentBasis

    /// <summary>
    /// Converts vector data stored within a texture using the specified basis.  Assume all calculations are performed in tangent space.
    /// </summary>
    /// <param name='basis'>
    /// Basis to multiply the vector values against.
    /// </param>
    /// <param name='vectorData'>
    /// Texture2D containing vector data.  Textures are passed by reference, so make sure to copy beforehand if you don't want to overwrite your data!
    /// </param>
    public static void ConvertTangentBasis(Matrix4x4 basis, ref Texture2D vectorData, bool recomputeZ = false)
    {
        Color[] colorData = vectorData.GetPixels();
        Texture2D tmpTexture = new Texture2D(vectorData.width, vectorData.height, TextureFormat.ARGB32, false);

        for (int i = 0; i < colorData.Length; i++)
        {
            Color vecData = new Color(colorData[i].r, colorData[i].g, colorData[i].b, 1);
            vecData.r = Vector3.Dot(new Vector3(basis.m00, basis.m01, basis.m02), UnpackUnitVector(new Vector3(colorData[i].r, colorData[i].g, colorData[i].b))) * 0.5f + 0.5f;
            vecData.g = Vector3.Dot(new Vector3(basis.m10, basis.m11, basis.m12), UnpackUnitVector(new Vector3(colorData[i].r, colorData[i].g, colorData[i].b))) * 0.5f + 0.5f;
            if (recomputeZ)
            {
                vecData.r = vecData.r * 2 - 1;
                vecData.g = vecData.g * 2 - 1;
                vecData.b = Mathf.Sqrt(1 - vecData.r * vecData.r - vecData.g * vecData.g) * 0.5f + 0.5f;
                vecData.r = vecData.r * 0.5f + 0.5f;
                vecData.g = vecData.g * 0.5f + 0.5f;
            } else {
                vecData.b = Vector3.Dot(new Vector3(basis.m20, basis.m21, basis.m22), UnpackUnitVector(new Vector3(colorData[i].r, colorData[i].g, colorData[i].b))) * 0.5f + 0.5f;
            }
            colorData[i] = vecData;
        }
        tmpTexture.SetPixels(colorData);
        tmpTexture.Apply();
        vectorData = tmpTexture;
    }
开发者ID:Geenz,项目名称:Gz-Unity-Tools,代码行数:35,代码来源:TexturesSpaceConverter.cs

示例4: 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

示例5: PerspectiveOffCenter

 // From http://docs.unity3d.com/ScriptReference/Camera-projectionMatrix.html
 static Matrix4x4 PerspectiveOffCenter(float left, float right, float bottom, float top, float near, float far)
 {
     float x = 2.0F * near / (right - left);
     float y = 2.0F * near / (top - bottom);
     float a = (right + left) / (right - left);
     float b = (top + bottom) / (top - bottom);
     float c = -(far + near) / (far - near);
     float d = -(2.0F * far * near) / (far - near);
     float e = -1.0F;
     Matrix4x4 m = new Matrix4x4();
     m[0, 0] = x;
     m[0, 1] = 0;
     m[0, 2] = a;
     m[0, 3] = 0;
     m[1, 0] = 0;
     m[1, 1] = y;
     m[1, 2] = b;
     m[1, 3] = 0;
     m[2, 0] = 0;
     m[2, 1] = 0;
     m[2, 2] = c;
     m[2, 3] = d;
     m[3, 0] = 0;
     m[3, 1] = 0;
     m[3, 2] = e;
     m[3, 3] = 0;
     return m;
 }
开发者ID:Flafla2,项目名称:Wiimote-Headtracking,代码行数:29,代码来源:PerspectiveShifter.cs

示例6: GetMatrix

        public Matrix4x4 GetMatrix(){
            Matrix4x4 keystone = new Matrix4x4();
            // a b c d
            // e f g h
            // i j 1 0
            // m n 0 1
            keystone[0, 0] = a;
            keystone[0, 1] = b;
            //keystone[0, 2] = c;
            keystone[0, 3] = d;
            keystone[1, 0] = e;
            keystone[1, 1] = f;
            //keystone[1, 2] = g;
            keystone[1, 3] = h;
            keystone[2, 0] = 0;
            keystone[2, 1] = 0;
            keystone[2, 2] = 1 - Mathf.Abs(m) - Mathf.Abs(n);
            keystone[2, 3] = 0;
            keystone[3, 0] = m;
            keystone[3, 1] = n;
            keystone[3, 2] = 0;
            keystone[3, 3] = 1;

            return keystone;
        }
开发者ID:znjRoLS,项目名称:RUISAircraftGunner,代码行数:25,代码来源:RUISKeystoning.cs

示例7: DrawMesh

		public void DrawMesh(Mesh mesh, Matrix4x4 matrix, Material material)
		{
			MaterialPropertyBlock properties = null;
			int shaderPass = -1;
			int submeshIndex = 0;
			CommandBuffer.INTERNAL_CALL_DrawMesh(this, mesh, ref matrix, material, submeshIndex, shaderPass, properties);
		}
开发者ID:guozanhua,项目名称:UnityDecompiled,代码行数:7,代码来源:CommandBuffer.cs

示例8: Matrix4x4DeterminantTest1

        public void Matrix4x4DeterminantTest1()
        {
            Matrix4x4 a = new Matrix4x4();
            a.M11 = 5.0f;
            a.M12 = 2.0f;
            a.M13 = 8.25f;
            a.M14 = 1.0f;
            a.M21 = 12.0f;
            a.M22 = 6.8f;
            a.M23 = 2.14f;
            a.M24 = 9.6f;
            a.M31 = 6.5f;
            a.M32 = 1.0f;
            a.M33 = 3.14f;
            a.M34 = 2.22f;
            a.M41 = 0f;
            a.M42 = 0.86f;
            a.M43 = 4.0f;
            a.M44 = 1.0f;
            Matrix4x4 i;
            Assert.True(Matrix4x4.Invert(a, out i));

            float detA = a.GetDeterminant();
            float detI = i.GetDeterminant();
            float t = 1.0f / detI;

            // only accurate to 3 precision
            Assert.True(System.Math.Abs(detA - t) < 1e-3, "Matrix4x4.Determinant was not set correctly.");
        }
开发者ID:rajeevkb,项目名称:corefx,代码行数:29,代码来源:Matrix4x4Tests.cs

示例9: 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

示例10: Matrix4x4IdentityTest

        public void Matrix4x4IdentityTest()
        {
            Matrix4x4 val = new Matrix4x4();
            val.M11 = val.M22 = val.M33 = val.M44 = 1.0f;

            Assert.True(MathHelper.Equal(val, Matrix4x4.Identity), "Matrix4x4.Indentity was not set correctly.");
        }
开发者ID:rajeevkb,项目名称:corefx,代码行数:7,代码来源:Matrix4x4Tests.cs

示例11: ConvertToMatrix

    void ConvertToMatrix(Quaternion q, Vector3 pos, ref Matrix4x4 mat)
    {
        Matrix4x4 m=new Matrix4x4();
        qtomatrix(ref m, q);

        //added by yamen: include head position in the matrix
        m[3,0] = pos[0];
        m[3,1] = pos[1];
        m[3,2] = pos[2];

        mat[0] = m[0,0];
        mat[1] = m[1,0];
        mat[2] = m[2,0];
        mat[3] = 0;

        mat[4] = m[0,1];
        mat[5] = m[1,1];
        mat[6] = m[2,1];
        mat[7] = 0;

        mat[8] = m[0,2];
        mat[9] = m[1,2];
        mat[10] = m[2,2];
        mat[11] = 0;

        mat[12] = m[3,0];
        mat[13] = m[3,1];
        mat[14] = m[3,2];
        mat[15] = 1;
    }
开发者ID:mrayy,项目名称:Telexistence-Gateway,代码行数:30,代码来源:TorsoController.cs

示例12: CalculateTargetValues

    void CalculateTargetValues(ref float[] param)
    {
        float len=vecLength3(targetMatrix[12],targetMatrix[13],targetMatrix[14]-0.17f);
        param[2]=len-L1;

        if(len!=0){
            float tmp=targetMatrix[12]/len;
            tmp=tmp>+1?+1:tmp;
            tmp=tmp<-1?-1:tmp;
            param[1]=Mathf.Asin(tmp);

            tmp=-targetMatrix[13]/(len*Mathf.Cos(param[1]));
            tmp=tmp>+1?+1:tmp;
            tmp=tmp<-1?-1:tmp;
            param[0]=Mathf.Asin(tmp);
        }else{
            param[0]=0;
            param[1]=0;
        }

        Matrix4x4 mat,tmpM,tmpM2;
        mat=new Matrix4x4();
        MakeMatrix(myAxis.axisX,0,0,0,-0.17f,ref mat);
        tmpM2=mat*targetMatrix;
        MakeMatrix(myAxis.axisX,-param[0],0,0,0,ref mat);
        tmpM=mat*tmpM2;
        MakeMatrix(myAxis.axisY,-param[1],0,0,-len,ref mat);
        tmpM2=mat*tmpM;
        MatrixtoXYZ(tmpM2,ref param[3],ref param[4],ref param[5]);

        param[3]=-param[3];
        param[4]=-param[4];
        param[5]=-param[5];
    }
开发者ID:mrayy,项目名称:Telexistence-Gateway,代码行数:34,代码来源:TorsoController.cs

示例13: OnApply

        /// <inheritdoc/>
        protected override void OnApply(ImageBase source, ImageBase target, Rectangle targetRectangle, Rectangle sourceRectangle)
        {
            float saturationFactor = this.saturation / 100f;

            // Stop at -1 to prevent inversion.
            saturationFactor++;

            // The matrix is set up to "shear" the colour space using the following set of values.
            // Note that each colour component has an effective luminance which contributes to the
            // overall brightness of the pixel.
            // See http://graficaobscura.com/matrix/index.html
            float saturationComplement = 1.0f - saturationFactor;
            float saturationComplementR = 0.3086f * saturationComplement;
            float saturationComplementG = 0.6094f * saturationComplement;
            float saturationComplementB = 0.0820f * saturationComplement;

            Matrix4x4 matrix4X4 = new Matrix4x4()
            {
                M11 = saturationComplementR + saturationFactor,
                M12 = saturationComplementR,
                M13 = saturationComplementR,
                M21 = saturationComplementG,
                M22 = saturationComplementG + saturationFactor,
                M23 = saturationComplementG,
                M31 = saturationComplementB,
                M32 = saturationComplementB,
                M33 = saturationComplementB + saturationFactor,
            };

            this.matrix = matrix4X4;
        }
开发者ID:joaonlopes,项目名称:ThumbnailCreator,代码行数:32,代码来源:Saturation.cs

示例14: Update

    // Update is called once per frame
    void Update()
    {
        if(Input.GetButtonDown("Fire1")) {
            Shot();
        }
        if(Input.GetButtonDown("Fire2")) {
            Blow();
        }
        {
            Vector3 move = Vector3.zero;
            move.x = Input.GetAxis ("Horizontal");
            move.z = Input.GetAxis ("Vertical");
            trans.position += move * 0.1f;
        }
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            Plane plane = new Plane(Vector3.up, Vector3.zero);
            float distance = 0;
            if (plane.Raycast(ray, out distance)){
                trans.rotation = Quaternion.LookRotation(ray.GetPoint(distance) - trans.position);
            }
        }

        {
            Matrix4x4 ts = Matrix4x4.identity;
            ts.SetColumn (3, new Vector4(0.0f,0.0f,0.5f,1.0f));
            ts = Matrix4x4.Scale(new Vector3(5.0f, 5.0f, 10.0f)) * ts;
            blowMatrix = trans.localToWorldMatrix * ts;
        }
    }
开发者ID:Uhstrology,项目名称:MassParticle,代码行数:31,代码来源:Player.cs

示例15: DrawWireCube

    public static void DrawWireCube(Matrix4x4 mat, Color col)
    {
        const float s = 0.5f;
        Vector4[] vertices = new Vector4[8] {
            new Vector4( s, s, s, 1.0f),
            new Vector4(-s, s, s, 1.0f),
            new Vector4( s,-s, s, 1.0f),
            new Vector4( s, s,-s, 1.0f),
            new Vector4(-s,-s, s, 1.0f),
            new Vector4( s,-s,-s, 1.0f),
            new Vector4(-s, s,-s, 1.0f),
            new Vector4(-s,-s,-s, 1.0f),
        };
        for (int i = 0; i < vertices.Length; ++i )
        {
            vertices[i] = mat * vertices[i];
        }
        int[] indices = new int[24] {
            0,1, 0,2, 0,3,
            1,4, 1,6,
            2,4, 2,5,
            3,5, 3,6,
            4,7,
            5,7,
            6,7
        };

        GL.Begin(GL.LINES);
        GL.Color(col);
        for (int i = 0; i < indices.Length; ++i )
        {
            GL.Vertex(vertices[indices[i]]);
        }
        GL.End();
    }
开发者ID:robterrell,项目名称:MassParticle,代码行数:35,代码来源:Player.cs


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