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


C# UnityEngine.Matrix4x4类代码示例

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


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

示例1: DrawBrush

		public static void DrawBrush(	Vector3 point,
										Vector3 normal,
										z_BrushSettings brushSettings,
										Matrix4x4 matrix,
										Color innerColor,
										Color outerColor)
		{
			PushHandleColor();

			Vector3 p = matrix.MultiplyPoint3x4(point);
			Vector3 n = matrix.MultiplyVector(normal).normalized;
			
			/// radius
			Handles.color = outerColor;
			Handles.DrawWireDisc(p, n, brushSettings.radius);

			/// falloff
			Handles.color = innerColor;
			Handles.DrawWireDisc(p, n, brushSettings.radius * brushSettings.falloff);

			Handles.color = new Color(	Mathf.Abs(n.x),
										Mathf.Abs(n.y),
										Mathf.Abs(n.z),
										1f);

			Handles.DrawLine(p, p + n.normalized * HandleUtility.GetHandleSize(p));

			PopHandleColor();
		}
开发者ID:alex-carlson,项目名称:PixelitisGGJ,代码行数:29,代码来源:z_Handles.cs

示例2: GeometryMesh

        public GeometryMesh(MeshData meshData, Transform meshTransform, Matrix4x4 worldToVesselMatrix, GeometryPartModule module)
        {
            Vector3[] untransformedVerts = meshData.vertices;
            int[] triangles = meshData.triangles;
            Bounds meshBounds = meshData.bounds;

            vertices = new Vector3[untransformedVerts.Length];
            this.thisToVesselMatrix = worldToVesselMatrix * meshTransform.localToWorldMatrix;

            for (int i = 0; i < vertices.Length; i++)
            {
                //vertices[i] = thisToVesselMatrix.MultiplyPoint3x4(untransformedVerts[i]);
                Vector3 v = untransformedVerts[i];
                Vector3 vert = Vector3.zero;
                vert.x = thisToVesselMatrix.m00 * v.x + thisToVesselMatrix.m01 * v.y + thisToVesselMatrix.m02 * v.z + thisToVesselMatrix.m03;
                vert.y = thisToVesselMatrix.m10 * v.x + thisToVesselMatrix.m11 * v.y + thisToVesselMatrix.m12 * v.z + thisToVesselMatrix.m13;
                vert.z = thisToVesselMatrix.m20 * v.x + thisToVesselMatrix.m21 * v.y + thisToVesselMatrix.m22 * v.z + thisToVesselMatrix.m23;

                vertices[i] = vert;
            }

            this.triangles = triangles;
            this.meshTransform = meshTransform;

            bounds = TransformBounds(meshBounds, thisToVesselMatrix);

            this.module = module;
            this.part = module.part;

            if (!module.part.isMirrored)
                invertXYZ = 1;
            else
                invertXYZ = -1;
        }
开发者ID:boniboni,项目名称:Ferram-Aerospace-Research,代码行数:34,代码来源:GeometryMesh.cs

示例3: DrawScatterBrush

		public static void DrawScatterBrush(Vector3 point, Vector3 normal, z_BrushSettings settings, Matrix4x4 localToWorldMatrix)
		{
			Vector3 p = localToWorldMatrix.MultiplyPoint3x4(point);
			Vector3 n = localToWorldMatrix.MultiplyVector(normal).normalized;
			
			float r = settings.radius;
			Vector3 a = Vector3.zero;
			Quaternion rotation = Quaternion.LookRotation(normal, Vector3.up);

			for(int i = 0; i < 10; i++)
			{
				a.x = Mathf.Cos(Random.Range(0f, 360f));
				a.y = Mathf.Sin(Random.Range(0f, 360f));
				a = a.normalized * Random.Range(0f, r);

				Vector3 v = localToWorldMatrix.MultiplyPoint3x4(point + rotation * a);

				Handles.DrawLine(v, v  + (n * .5f));

				Handles.CubeCap(i + 2302, v, Quaternion.identity, .01f);
			}

			/// radius
			Handles.DrawWireDisc(p, n, settings.radius);
		}
开发者ID:alex-carlson,项目名称:PixelitisGGJ,代码行数:25,代码来源:z_Handles.cs

示例4: ExtractTranslationFromMatrix

		/// <summary>
        /// Extract translation from transform matrix.
        /// </summary>
        /// <param name="matrix">Transform matrix. This parameter is passed by reference
        /// to improve performance; no changes will be made to it.</param>
        /// <returns>
        /// Translation offset.
        /// </returns>
        public static Vector3 ExtractTranslationFromMatrix(ref Matrix4x4 matrix) {
            Vector3 translate;
            translate.x = matrix.m03;
            translate.y = matrix.m13;
            translate.z = matrix.m23;
            return translate;
        }
开发者ID:JokieW,项目名称:ShiningHill,代码行数:15,代码来源:Matrix4x4Utils.cs

示例5: OnPreCull

        internal void OnPreCull()
        {
            if (HighLogic.LoadedScene != GameScenes.MAINMENU)
            {
                Matrix4x4 bodies = new Matrix4x4();
                int i = 0;
                foreach (CelestialBody cb in shadowList)
                {
                    bodies.SetRow(i, cb.transform.position);
                    bodies[i, 3] = (float)(cb.Radius);
                    i++;
                    if (i == 4)
                        break;
                }
                if (shadowMat != null)
                {
                    shadowMat.SetVector(ShaderProperties._SunPos_PROPERTY, Sun.Instance.sun.transform.position);
                    shadowMat.SetMatrix(ShaderProperties._ShadowBodies_PROPERTY, bodies);
                }

                foreach (Transform child in body.transform)
                {
                    Renderer cr = child.GetComponent<Renderer>();
                    if (cr != null)
                    {
                        cr.sharedMaterial.SetFloat(ShaderProperties._SunRadius_PROPERTY, (float)(Sun.Instance.sun.Radius));
                        cr.sharedMaterial.SetVector(ShaderProperties._SunPos_PROPERTY, Sun.Instance.sun.transform.position);
                        cr.sharedMaterial.SetMatrix(ShaderProperties._ShadowBodies_PROPERTY, bodies);
                    }
                }
            }
        }
开发者ID:Kerbas-ad-astra,项目名称:EnvironmentalVisualEnhancements,代码行数:32,代码来源:ShadowObject.cs

示例6: GetPartColliderBoundsInBasis

        public static Bounds GetPartColliderBoundsInBasis(this Part part, Matrix4x4 worldToBasisMatrix, int excessiveVerts = 2500)
        {
            Transform[] transforms = part.FindModelComponents<Transform>();
            Bounds bounds = new Bounds();
            for (int i = 0; i < transforms.Length; i++)
            {
                Transform t = transforms[i];

                MeshCollider mc = t.GetComponent<MeshCollider>();
                Mesh m;
                Matrix4x4 matrix = worldToBasisMatrix * t.localToWorldMatrix;

                if (mc == null)
                {
                    BoxCollider bc = t.GetComponent<BoxCollider>();
                    if (bc != null)
                    {
                        bounds.Encapsulate(matrix.MultiplyPoint3x4(bc.bounds.min));
                        bounds.Encapsulate(matrix.MultiplyPoint3x4(bc.bounds.max));
                    }
                    continue;
                }
                else
                    m = mc.sharedMesh;

                if (m == null)
                    continue;

                bounds.Encapsulate(matrix.MultiplyPoint3x4(m.bounds.min));
                bounds.Encapsulate(matrix.MultiplyPoint3x4(m.bounds.max));

            }
            return bounds;
        }
开发者ID:khr15714n,项目名称:Ferram-Aerospace-Research,代码行数:34,代码来源:PartGeometryExtensions.cs

示例7: AdjustMidpointHandleColor

 private void AdjustMidpointHandleColor(Vector3 localPos, Vector3 localTangent, Vector3 localBinormal, Matrix4x4 transform, float alphaFactor)
 {
     float num;
     Vector3 vector = transform.MultiplyPoint(localPos);
     Vector3 lhs = transform.MultiplyVector(localTangent);
     Vector3 rhs = transform.MultiplyVector(localBinormal);
     Vector3 normalized = Vector3.Cross(lhs, rhs).normalized;
     if (Camera.current.isOrthoGraphic)
     {
         num = Vector3.Dot(-Camera.current.transform.forward, normalized);
     }
     else
     {
         Vector3 vector6 = Camera.current.transform.position - vector;
         num = Vector3.Dot(vector6.normalized, normalized);
     }
     if (num < -0.0001f)
     {
         alphaFactor *= 0.2f;
     }
     if (alphaFactor < 1f)
     {
         Handles.color = new Color(Handles.color.r, Handles.color.g, Handles.color.b, Handles.color.a * alphaFactor);
     }
 }
开发者ID:BenjaminMoore,项目名称:JPhysics,代码行数:25,代码来源:BoxEditor.cs

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

示例9: IntersectRayMesh

 	public static bool IntersectRayMesh(Ray ray, Mesh mesh, Matrix4x4 matrix, out RaycastHit hit)
 	{
 		var parameters = new object[]{ray,mesh,matrix,null};
 		bool result = (bool)meth_IntersectRayMesh.Invoke(null,parameters);
 		hit = (RaycastHit)parameters[3];
       return result;
    }
开发者ID:CarlosMeloStuff,项目名称:VertexPaint,代码行数:7,代码来源:RxLookingGlass.cs

示例10: getUnityProjectionMatrix

		/// <summary>
		/// This function returns OpenGL style projection matrix.
		/// </summary>
		/// <returns>
		/// output parametor.
		/// </returns>
		public Matrix4x4 getUnityProjectionMatrix()
		{
			Matrix4x4 mat=new Matrix4x4();
			NyARFrustum.FrustumParam f=this.getFrustum().getFrustumParam(new NyARFrustum.FrustumParam());
			NyARUnityUtil.toCameraFrustumRH(this._ref_param,1,f.near,f.far,ref mat);
			return mat;
		}
开发者ID:Carteor,项目名称:LensesAR-Unity3D,代码行数:13,代码来源:NyARUnityMarkerSystem.cs

示例11: OnRenderImage

 public void OnRenderImage(RenderTexture source, RenderTexture destination)
 {
     switch (colorBlindMode)
     {
     case ColorBlindMode.None:
         filterMatrix = Matrix4x4.identity;
         break;
     case ColorBlindMode.Protanopia:
         filterMatrix.SetColumn(0, new Vector4(0.567f, 0.433f, 0.0f, 0.0f));
         filterMatrix.SetColumn(1, new Vector4(0.558f, 0.442f, 0.0f, 0.0f));
         filterMatrix.SetColumn(2, new Vector4(0.0f, 0.242f, 0.758f, 0.0f));
         filterMatrix.SetColumn(3, new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
         break;
     case ColorBlindMode.Deuteranopia:
         filterMatrix.SetColumn(0, new Vector4(0.625f, 0.375f, 0.0f, 0.0f));
         filterMatrix.SetColumn(1, new Vector4(0.7f, 0.3f, 0.0f, 0.0f));
         filterMatrix.SetColumn(2, new Vector4(0.0f, 0.3f, 0.7f, 0.0f));
         filterMatrix.SetColumn(3, new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
         break;
     case ColorBlindMode.Tritanopia:
         filterMatrix.SetColumn(0, new Vector4(0.95f, 0.05f, 0.0f, 0.0f));
         filterMatrix.SetColumn(1, new Vector4(0.0f, 0.433f, 0.567f, 0.0f));
         filterMatrix.SetColumn(2, new Vector4(0.0f, 0.475f, 0.525f, 0.0f));
         filterMatrix.SetColumn(3, new Vector4(0.0f, 0.0f, 0.0f, 1.0f));
         break;
     default:
         break;
     }
     FilterMaterial.SetMatrix("_Filter", filterMatrix);
     Graphics.Blit(source, destination, FilterMaterial);
 }
开发者ID:Fromfame,项目名称:RED,代码行数:31,代码来源:ColorBlindFilter.cs

示例12: AdjustEdgeHandleColor

 private void AdjustEdgeHandleColor(Vector3 handlePos, Vector3 slideDir1, Vector3 slideDir2, Matrix4x4 transform, float alphaFactor)
 {
     bool flag;
     Vector3 inPoint = transform.MultiplyPoint(handlePos);
     Vector3 normalized = transform.MultiplyVector(slideDir1).normalized;
     Vector3 rhs = transform.MultiplyVector(slideDir2).normalized;
     if (Camera.current.isOrthoGraphic)
     {
         flag = (Vector3.Dot(-Camera.current.transform.forward, normalized) < 0f) && (Vector3.Dot(-Camera.current.transform.forward, rhs) < 0f);
     }
     else
     {
         Plane plane = new Plane(normalized, inPoint);
         Plane plane2 = new Plane(rhs, inPoint);
         flag = !plane.GetSide(Camera.current.transform.position) && !plane2.GetSide(Camera.current.transform.position);
     }
     if (flag)
     {
         alphaFactor *= 0.2f;
     }
     if (alphaFactor < 1f)
     {
         Handles.color = new Color(Handles.color.r, Handles.color.g, Handles.color.b, Handles.color.a * alphaFactor);
     }
 }
开发者ID:BenjaminMoore,项目名称:JPhysics,代码行数:25,代码来源:BoxEditor.cs

示例13: DrawOrbit

		private static void DrawOrbit(Orbit o, CelestialBody referenceBody, Matrix4x4 screenTransform, int numSegments)
		{
			if (!o.activePatch) {
				return;
			}

			double startTA;
			double endTA;
			double now = Planetarium.GetUniversalTime();
			if (o.patchEndTransition != Orbit.PatchTransitionType.FINAL) {
				startTA = o.TrueAnomalyAtUT(o.StartUT);
				endTA = o.TrueAnomalyAtUT(o.EndUT);
				if (endTA < startTA) {
					endTA += 2.0 * Math.PI;
				}
			} else {
				startTA = o.GetUTforTrueAnomaly(0.0, now);
				endTA = startTA + 2.0 * Math.PI;
			}
			double dTheta = (endTA - startTA) / (double)numSegments;
			double theta = startTA;
			double timeAtTA = o.GetUTforTrueAnomaly(theta, now);
			Vector3 lastVertex = screenTransform.MultiplyPoint3x4(o.getRelativePositionFromTrueAnomaly(theta).xzy + (o.referenceBody.getTruePositionAtUT(timeAtTA)) - (referenceBody.getTruePositionAtUT(timeAtTA)));
			for (int i = 0; i < numSegments; ++i) {
				GL.Vertex3(lastVertex.x, lastVertex.y, 0.0f);
				theta += dTheta;
				timeAtTA = o.GetUTforTrueAnomaly(theta, now);

				Vector3 newVertex = screenTransform.MultiplyPoint3x4(o.getRelativePositionFromTrueAnomaly(theta).xzy + (o.referenceBody.getTruePositionAtUT(timeAtTA)) - (referenceBody.getTruePositionAtUT(timeAtTA)));
				GL.Vertex3(newVertex.x, newVertex.y, 0.0f);

				lastVertex = newVertex;
			}
		}
开发者ID:dreadicon,项目名称:RasterPropMonitor,代码行数:34,代码来源:JSIOrbitDisplay.cs

示例14: IntakeCrossSectionAdjuster

        public IntakeCrossSectionAdjuster(PartModule intake, Matrix4x4 worldToVesselMatrix)
        {
            this.part = intake.part;
            intakeModule = intake as ModuleResourceIntake;
            intakeTrans = intakeModule.intakeTransform;

            if (!string.IsNullOrEmpty(intakeModule.occludeNode))
                node = intakeModule.node; 
            
            foreach (AttachNode candidateNode in part.attachNodes)
                if (candidateNode.nodeType == AttachNode.NodeType.Stack && Vector3.Dot(candidateNode.position, (part.transform.worldToLocalMatrix * intakeTrans.localToWorldMatrix).MultiplyVector(Vector3.forward)) > 0)
                {
                    if (candidateNode == node)
                        continue;

                    nodeOffsetArea = candidateNode.size;
                    if (nodeOffsetArea == 0)
                        nodeOffsetArea = 0.5;

                    nodeOffsetArea *= 0.625;     //scale it up as needed
                    nodeOffsetArea *= nodeOffsetArea;
                    nodeOffsetArea *= Math.PI;  //calc area;

                    nodeOffsetArea *= -1;        //and the adjustment area
                    break;
                }

            thisToVesselMatrix = worldToVesselMatrix * intakeTrans.localToWorldMatrix;

            vehicleBasisForwardVector = Vector3.forward;
            vehicleBasisForwardVector = thisToVesselMatrix.MultiplyVector(vehicleBasisForwardVector);

            Type intakeType = intake.GetType();
            intakeArea = (float)intakeType.GetField("Area").GetValue(intake);
        }
开发者ID:cupsster,项目名称:Ferram-Aerospace-Research,代码行数:35,代码来源:IntakeCrossSectionAdjuster.cs

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


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