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


C# CRSpline.Velocity方法代码示例

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


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

示例1: generateMesh

	void generateMesh()
	{		
		if(meshPrefab==null)
			return;
		List<Vector3> vertices=new List<Vector3>();
		List<int>[] triangles=new List<int>[3];
		triangles[0]=new List<int>();
		triangles[1]=new List<int>();
		triangles[2]=new List<int>();
		List<Vector2> uv=new List<Vector2>();
		List<Vector3> normals=new List<Vector3>();
		List<Vector4> tangents=new List<Vector4>();
		
		CRSpline posSpline = new CRSpline( path.getPositions() );
		//CRSpline rotSpline = new CRSpline( path.getRotations() );
		
		Mesh[] mesh=new Mesh[3];
		mesh[0]=meshPrefab.FindChild("start").GetComponent<MeshFilter>().sharedMesh;
		mesh[1]=meshPrefab.FindChild("middle").GetComponent<MeshFilter>().sharedMesh;
		mesh[2]=meshPrefab.FindChild("end").GetComponent<MeshFilter>().sharedMesh;
		
		Vector3[][] meshVertices=new Vector3[3][];
		int[][] meshTriangles=new int[3][];
		Vector2[][] meshUv=new Vector2[3][];
		Vector3[][] meshNormals=new Vector3[3][];
		Vector4[][] meshTangents=new Vector4[3][];
		
		float[] max=new float[3];
		
		for(int i=0;i<3;i++)
		{
			meshVertices[i]=mesh[i].vertices;
			meshTriangles[i]=mesh[i].GetTriangles(0);
			meshUv[i]=mesh[i].uv;
			meshNormals[i]=mesh[i].normals;
			meshTangents[i]=mesh[i].tangents;
			
			for(int vi=0;vi<meshTriangles[i].Length;vi++)
			{
				if(meshVertices[i][meshTriangles[i][vi]].x>max[i])
					max[i]=meshVertices[i][meshTriangles[i][vi]].x;
			}
		}
		
		float cursor=0;
		int vertI=0;
		
		int meshI=0;
		if(path.round)
			meshI=1;
		bool last=false;
		//float scale=1;
		while(true)
		{
			if(meshI==2)
				break;
			if(getT(cursor+max[meshI])<1.0f || last)
			{
				if(last)
				{
					//scale=1.0f/(getT(cursor+max[meshI])-getT(cursor))*(1.0f-getT(cursor));
					
				}
				if(getT(cursor+max[meshI]+max[2])>1.0f && !path.round)
					meshI=2;
					
				for(int i=0;i<meshTriangles[meshI].Length;i++)
				{
					triangles[meshI].Add(vertI+meshTriangles[meshI][i]);
				}
				vertI+=mesh[meshI].vertexCount;
				
				for(int i=0;i<meshVertices[meshI].Length;i++)
				{
					float vertexCursor=cursor+Mathf.Max(meshVertices[meshI][i].x,0);
					float t=getT(vertexCursor);
					Vector3 vPos=posSpline.Interp(t);
					Vector3 look=posSpline.Velocity(t).normalized;
					
					Quaternion r=Quaternion.LookRotation(look);
					r=Quaternion.Euler(0,-90,0)*Quaternion.Euler(r.eulerAngles.z,(r.eulerAngles.y),-r.eulerAngles.x);
				
					Vector3 localVert=meshVertices[meshI][i];
					localVert.x=0;
					Vector3 vert=(r*localVert)+(vPos-transform.position);
					//vert.x-=middleVertices[i].x;
					
					//Debug.Log(t);
					vertices.Add(vert);
					
					uv.Add(meshUv[meshI][i]);
					normals.Add(r*meshNormals[meshI][i]);
					tangents.Add(r*meshTangents[meshI][i]);
				}
				//Debug.Log(max);
				cursor+=max[meshI];
				
				if(meshI==0)
					meshI=1;
					
//.........这里部分代码省略.........
开发者ID:Gounemond,项目名称:GGJ2016,代码行数:101,代码来源:PathMesh.cs

示例2: easePath

	protected void easePath(  )
	{
		positionSpline = new CRSpline( path.getPositions() );
		rotationSpline = new CRSpline( path.getRotations() );
		
		float startI=(1.0f/(positionSpline.pts.Length-3))*(pathStartNode-1);
		float endI=(1.0f/(positionSpline.pts.Length-3))*(pathEndNode-1);
		
		float i=startI+ ((endI-startI)*normalizedTime);
		
		Vector3 newPos = positionSpline.Interp( i );
		if (transform==null)
		{
			Debug.Log("EasePath error: "+easingGroup + " " + animationCurveName);
			return;
		}
		if(space==Space.World)
			transform.position = newPos;
		else
			transform.localPosition = newPos;
		
		if( lookAtTransform!= null )
		{
			transform.LookAt( lookAtTransform, vectorUp );
		}
		else if( pathAlignWithSpeed )
		{
			Vector3 velVector = positionSpline.Velocity( i);
			if(space==Space.World)
				transform.rotation = Quaternion.LookRotation( velVector );
			else
				transform.localRotation = Quaternion.LookRotation( velVector );
		}
		else
		{
			Vector3 newRot = rotationSpline.Interp( i );
			if(space==Space.World)
				transform.rotation = Quaternion.Euler( newRot );
			else
				transform.localRotation = Quaternion.Euler( newRot );
		}	
		
	}
开发者ID:Gounemond,项目名称:GGJ2016,代码行数:43,代码来源:Easing.cs


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