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


C# Transform.TransformVector方法代码示例

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


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

示例1: SplitAndGetObject

    public void SplitAndGetObject(Transform firstGraberTrans, Transform secondGraberTrans, Transform objectInHandTrans, out Rigidbody firstFirstObject, out Rigidbody secondFirstObject)
    {
        firstFirstObject = null;
        secondFirstObject = null;
        GameObject obj;
        switch (SplitType)
        {
            case SplitTypes.PreSpawnedSplitObject:
                Splited = true;
                secondFirstObject = PreSpawnedObject.AddComponent<Rigidbody>();
                break;
            case SplitTypes.SpawnOnSplit:
                obj = Instantiate(SplitObjectPrefab);
                secondFirstObject = obj.GetComponent<Rigidbody>();
                secondFirstObject.isKinematic = true;
                obj.transform.localRotation = secondGraberTrans.localRotation;
                obj.transform.position = objectInHandTrans.position - objectInHandTrans.TransformVector(SpawnOffset);
                break;
            case SplitTypes.SpawnNewOnSplit:
                Splited = true;

                obj = Instantiate(FirstSplitObject);
                firstFirstObject = obj.GetComponent<Rigidbody>();
                firstFirstObject.isKinematic = true;
                obj.transform.localRotation = Quaternion.identity;
                obj.transform.position = objectInHandTrans.position - objectInHandTrans.TransformVector(FirstSpawnOffset);

                obj = Instantiate(SecondSplitObject);
                secondFirstObject = obj.GetComponent<Rigidbody>();
                secondFirstObject.isKinematic = true;
                obj.transform.localRotation = Quaternion.identity;
                obj.transform.position = objectInHandTrans.position - objectInHandTrans.TransformVector(SecondSpawnOffset);
                break;
        }
    }
开发者ID:Fawcan,项目名称:GameJamVR,代码行数:35,代码来源:SplitableObject.cs

示例2: CovertToWorldSpace

	static void CovertToWorldSpace (ref Mesh originalMesh, Transform meshTransform)
	{
		Vector3[] newVertices = new Vector3[originalMesh.vertexCount];
		Vector3[] newNormals = new Vector3[originalMesh.vertexCount];
		Vector4[] newTangents = new Vector4[originalMesh.vertexCount];
		for (int i = 0; i < originalMesh.vertexCount; i++)
		{
			newVertices[i] = meshTransform.TransformPoint(originalMesh.vertices[i]);
			newNormals[i] = meshTransform.TransformVector(originalMesh.normals[i]);
			newTangents[i] = meshTransform.TransformVector(originalMesh.tangents[i]);
		}
		originalMesh.vertices = newVertices;
		originalMesh.normals = newNormals;
		originalMesh.tangents = newTangents;
	}
开发者ID:TheMasonX,项目名称:Project-True-Forest,代码行数:15,代码来源:ConvertVerticesToWorldSpace.cs

示例3: FixObj

    public void FixObj(Transform obj)
    {
        try {
            // rotate to (0,0,0) without changing how it looks
            MeshFilter mf = obj.GetComponent<MeshFilter>();
            Mesh m = (mf?mf.mesh:null);
            if (m) {
                // convert vertices to Quaternion.Identity
                Transform parent = obj.parent;
                obj.parent = null;
                Vector3[] verts = m.vertices;
                for (int i=0; i<verts.Length; ++i)
                    verts[i] = Vector3.Scale(
                        obj.TransformVector(verts[i]),
                        new Vector3(1/obj.localScale.x, 1/obj.localScale.y, 1/obj.localScale.z));

                // convert vertices to the final rotation
                Vector3 v1 = obj.TransformDirection(Vector3.right);
                Vector3 v2 = obj.lossyScale;
                float angle = Mathf.Atan2(v1.y, v1.x);
                for (int i=0; i<verts.Length; ++i)
                    verts[i] = new Vector3(
                        Mathf.Cos(-angle)*verts[i].x*v2.x/v2.x - Mathf.Sin(-angle)*verts[i].y*v2.y/v2.x,
                        Mathf.Sin(-angle)*verts[i].x*v2.x/v2.y + Mathf.Cos(-angle)*verts[i].y*v2.y/v2.y,
                        verts[i].z);

                // finalize rotation
                obj.eulerAngles = new Vector3(0, 0, angle*180/Mathf.PI);
                //obj.rotation = Quaternion.identity;
                obj.parent = parent;
                m.vertices = verts;
                m.RecalculateNormals();
                m.RecalculateBounds();

                // update collider
                BoxCollider boxColl3d = obj.GetComponent<BoxCollider>();
                if (boxColl3d)
                    throw new Exception("Rotator2D Doesn't Work with 3D Colliders");
                BoxCollider2D boxColl = obj.GetComponent<BoxCollider2D>();
                if (boxColl) {
                    boxColl.size = m.bounds.size;
                    boxColl.offset = m.bounds.center;
                }
            } else {
                Transform parent = obj.parent;
                obj.parent = null;
                Vector3 v = obj.TransformDirection(Vector3.right);
                float angle = Mathf.Atan2(v.y, v.x);
                obj.eulerAngles = new Vector3(0, 0, angle*180/Mathf.PI);
                obj.parent = parent;
            }
        } catch (Exception e) {
            Debug.LogWarning("Error processing an object:\n\n"+e.Message);
        }
    }
开发者ID:shadowseer99,项目名称:clockwork,代码行数:55,代码来源:Rotator2D.cs

示例4: IsClothParticleFacingCamera

        /**
         * Return whether all physical vertices at the particle should are culled or not. If at least one is not culled, the particle is visible.
         */
        private bool IsClothParticleFacingCamera(Transform clothTransform,Camera cam, Vector3[] meshNormals, int particleIndex, Vector3 particleWorldPosition)
        {
            if (cam == null || clothTransform == null) return false;

            if (particleIndex < cloth.edgeStructure.heVertices.Count){

            HalfEdge.HEVertex vertex = cloth.edgeStructure.heVertices[particleIndex];

            foreach(int index in vertex.physicalIDs){
                if (Vector3.Dot(clothTransform.TransformVector(meshNormals[index]),cam.transform.position - particleWorldPosition) > 0)
                    return true;
            }

            }

            return false;
        }
开发者ID:Fabbseh,项目名称:CuteHorrorGame,代码行数:20,代码来源:ObiClothEditor.cs

示例5: TTVector

 /*
  * Transform to Transform Vector
  */
 public static Vector3 TTVector(Vector3 vector, Transform fromParent, Transform toParent)
 {
     return toParent.InverseTransformVector(fromParent.TransformVector(vector));
 }
开发者ID:lightfromshadows,项目名称:qadunity,代码行数:7,代码来源:Math.cs

示例6: DrawBox

        public static void DrawBox(Bounds bounds, Transform transform = null)
        {
            Vector3 center = bounds.center;

            // Calculate each of the transformed axis with their corresponding length
            Vector3 up = Vector3.up * bounds.extents.y;
            Vector3 right = Vector3.right * bounds.extents.x;
            Vector3 forward = Vector3.forward * bounds.extents.z;

            if(transform != null)
            {
                center = transform.TransformPoint(bounds.center);

                // Calculate each of the transformed axis with their corresponding length
                up = transform.TransformVector(Vector3.up) * bounds.extents.y;
             	right = transform.TransformVector(Vector3.right) * bounds.extents.x;
                forward = transform.TransformVector(Vector3.forward) * bounds.extents.z;
            }

            // Verticals
            GL.Vertex(center - right - forward + up);
            GL.Vertex(center - right - forward - up);
            GL.Vertex(center - right + forward + up);
            GL.Vertex(center - right + forward - up);
            GL.Vertex(center + right - forward + up);
            GL.Vertex(center + right - forward - up);
            GL.Vertex(center + right + forward + up);
            GL.Vertex(center + right + forward - up);

            // Horizontal - forward/back
            GL.Vertex(center - right + forward - up);
            GL.Vertex(center - right - forward - up);
            GL.Vertex(center + right + forward - up);
            GL.Vertex(center + right - forward - up);
            GL.Vertex(center - right + forward + up);
            GL.Vertex(center - right - forward + up);
            GL.Vertex(center + right + forward + up);
            GL.Vertex(center + right - forward + up);

            // Horizontal - right/left
            GL.Vertex(center + right - forward - up);
            GL.Vertex(center - right - forward - up);
            GL.Vertex(center + right + forward - up);
            GL.Vertex(center - right + forward - up);
            GL.Vertex(center + right - forward + up);
            GL.Vertex(center - right - forward + up);
            GL.Vertex(center + right + forward + up);
            GL.Vertex(center - right + forward + up);
        }
开发者ID:5thFloorGames,项目名称:FollowTheLight,代码行数:49,代码来源:SabreGraphics.cs

示例7: RelativeMovePosition

    /// <summary>
    /// 相对位移后position
    /// </summary>
    /// <returns>The move.</returns>
    /// <param name="movement">Movement.</param>
    /// <param name="trans">Trans.</param>
    public static Vector3 RelativeMovePosition(Vector3 movement, Transform trans)
    {
        Vector3 origin = new Vector3 (trans.localPosition.x, trans.localPosition.y, trans.localPosition.z);
        //目标受击点
        Vector3 targetLocal = new Vector3 (origin.x + movement.x, origin.y + movement.y, origin.z + movement.z);

        Vector3 targetScreen = trans.TransformVector (targetLocal);

        return targetScreen;
    }
开发者ID:goddie,项目名称:u3dGameFramework,代码行数:16,代码来源:MapUtil.cs

示例8: TransformVectorFromTo

 /// <summary>
 /// Takes a vectpr in the coordinate space specified by the "from" transform and transforms it to be the correct direction in the coordinate space specified by the "to" transform
 /// applies rotation and scale, no translation
 /// </summary>
 /// <param name="from"></param>
 /// <param name="to"></param>
 /// <param name="vecInFrom"></param>
 /// <returns></returns>
 public static Vector3 TransformVectorFromTo(Transform from, Transform to, Vector3 vecInFrom)
 {
     Vector3 vecInWorld = (from == null) ? vecInFrom : from.TransformVector(vecInFrom);
     Vector3 vecInTo = (to == null) ? vecInWorld : to.InverseTransformVector(vecInWorld);
     return vecInTo;
 }
开发者ID:CameronVetter,项目名称:HoloToolkit-Unity,代码行数:14,代码来源:MathUtils.cs

示例9: Mirror

 public static Vector3 Mirror(Vector3 v, Transform root)
 {
     Vector3 local = root.InverseTransformVector(v);
     return root.TransformVector(-local.x, local.y, local.z);
 }
开发者ID:cupsster,项目名称:ExtremeBusiness,代码行数:5,代码来源:SymmetryTools.cs


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