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


C# Plane.SetNormalAndPosition方法代码示例

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


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

示例1: OnDrawGizmos

    void OnDrawGizmos( )
    {
        UpdateSplineNodes( );

        if( splineNodes == null )
            return;

        DrawSplineGizmo( new Color( 0.5f, 0.5f, 0.5f, 0.5f ) );

        Plane screen = new Plane( );
        Gizmos.color = new Color( 1f, 1f, 1f, 0.5f );

        screen.SetNormalAndPosition( Camera.current.transform.forward, Camera.current.transform.position );

        foreach( SplineNode node in splineNodes )
        {
            float sizeMultiplier = 0f;

            if( Camera.current.orthographic )
                sizeMultiplier = Camera.current.orthographicSize * 2.5f;
            else
                screen.Raycast( new Ray( node.Position, Camera.current.transform.forward ), out sizeMultiplier );

            Gizmos.DrawSphere( node.Position, sizeMultiplier * 0.015f );
        }
    }
开发者ID:salvadorlemus,项目名称:AppEducativa,代码行数:26,代码来源:SplineGizmos.cs

示例2: OnDrawGizmos

	void OnDrawGizmos( )
	{
		UpdateSpline( );
		
		if( !HasNodes )
			return;
		
		DrawSplineGizmo( new Color( 0.5f, 0.5f, 0.5f, 0.5f ) );
		
		Plane screen = new Plane( );
		Gizmos.color = new Color( 1f, 1f, 1f, 0.5f );
		
		
		screen.SetNormalAndPosition( Camera.current.transform.forward, Camera.current.transform.position );
		
		foreach( SplineNode node in splineNodesInternal )
			Gizmos.DrawSphere( node.Position, GetSizeMultiplier( node ) * 2 );
	}
开发者ID:GDxU,项目名称:incomplete-richman,代码行数:18,代码来源:SplineGizmos.cs

示例3: OnBrushApply

		public override void OnBrushApply(z_BrushTarget target, z_BrushSettings settings)
		{
			Vector3[] vertices = target.editableObject.vertices;
			Vector3 v, t, avg, dirVec = direction.ToVector3();
			Plane plane = new Plane(Vector3.up, Vector3.zero);

			foreach(KeyValuePair<int, float> weight in target.weights)
			{
				if(weight.Value < .0001f || (ignoreNonManifoldIndices && nonManifoldIndices.Contains(weight.Key)))
					continue;

				v = vertices[weight.Key];

				if(direction == z_Direction.Normal && relax)
					avg = z_Math.Average(cached_vertices, neighborLookup[weight.Key]);
				else
					avg = z_Math.WeightedAverage(cached_vertices, neighborLookup[weight.Key], target.weights);

				if(direction != z_Direction.Normal || !relax)
				{
					if(direction == z_Direction.Normal)
						dirVec = z_Math.WeightedAverage(cached_normals, neighborLookup[weight.Key], target.weights).normalized;

					plane.SetNormalAndPosition(dirVec, avg);
					avg = v - dirVec * plane.GetDistanceToPoint(v);
				}

				t = Vector3.Lerp(v, avg, weight.Value);

				vertices[weight.Key] = v + (t-v) * settings.strength * SMOOTH_STRENGTH_MODIFIER;
			}

			target.editableObject.mesh.vertices = vertices;

			if(tempComponent != null)
				tempComponent.OnVerticesMoved();

			base.OnBrushApply(target, settings);
		}
开发者ID:alex-carlson,项目名称:PixelitisGGJ,代码行数:39,代码来源:z_BrushModeSmooth.cs

示例4: MakeRandomPlane

    /// <summary>
    /// Create a plane from a list of points at random.
    /// </summary>
    /// <returns>A random plane.</returns>
    /// <param name="cam">The Unity camera so we can make sure the plane orientation is correct.</param>
    /// <param name="points">The points to compute a random plane from.</param>
    private Plane MakeRandomPlane(Camera cam, List<int> points)
    {
        if (points.Count < 3)
        {
            return new Plane();
        }

        // Choose 3 points randomly.
        int r0 = m_rand.Next(points.Count);
        int r1 = m_rand.Next(points.Count - 1);

        // Make sure we handle collisions.
        if (r1 == r0)
        {
            r1++;
        }
        else if (r1 < r0)
        {
            // We'll make sure to keep r0 and r1 in sorted order.
            int temp = r0;
            r0 = r1;
            r1 = temp;
        }

        int r2 = m_rand.Next(points.Count - 2);

        // Handle collisions.
        if (r2 == r0)
        {
            ++r2;
        }
        if (r2 == r1)
        {
            ++r2;
        }

        int idx0 = points[r0];
        int idx1 = points[r1];
        int idx2 = points[r2];

        Vector3 p0 = m_points[idx0];
        Vector3 p1 = m_points[idx1];
        Vector3 p2 = m_points[idx2];

        // Define the plane
        Plane plane = new Plane(p0, p1, p2);

        // Make sure that the normal of the plane points towards the camera.
        if (Vector3.Dot(cam.transform.forward, plane.normal) > 0)
        {
            plane.SetNormalAndPosition(plane.normal * -1.0f, p0);
        }
        return plane;
    }
开发者ID:nigelDaMan,项目名称:WeCanTango,代码行数:60,代码来源:TangoPointCloud.cs

示例5: UpdateParticles2

    void UpdateParticles2()
    {
        Plane movePlane = new Plane();

        for (int i = 1; i < m_Particles.Count; ++i)
        {
            Particle p = m_Particles[i];
            Particle p0 = m_Particles[p.m_ParentIndex];

            float restLen;
            if (p.m_Transform != null)
            {
                restLen = (p0.m_Transform.position - p.m_Transform.position).magnitude;
            }
            else
            {
                restLen = p0.m_Transform.localToWorldMatrix.MultiplyVector(p.m_EndOffset).magnitude;
            }

            // keep shape
            float stiffness = Mathf.Lerp(1.0f, p.m_Stiffness, m_Weight);
            if (stiffness > 0 || p.m_Elasticity > 0)
            {
                Matrix4x4 m0 = p0.m_Transform.localToWorldMatrix;
                m0.SetColumn(3, p0.m_Position);
                Vector3 restPos;
                if (p.m_Transform != null)
                {
                    restPos = m0.MultiplyPoint3x4(p.m_Transform.localPosition);
                }
                else
                {
                    restPos = m0.MultiplyPoint3x4(p.m_EndOffset);
                }

                Vector3 d = restPos - p.m_Position;
                p.m_Position += d * p.m_Elasticity;

                if (stiffness > 0)
                {
                    d = restPos - p.m_Position;
                    float len = d.magnitude;
                    float maxlen = restLen * (1 - stiffness) * 2;
                    if (len > maxlen)
                    {
                        p.m_Position += d * ((len - maxlen) / len);
                    }
                }
            }

            // collide
            if (m_Colliders != null)
            {
                float particleRadius = p.m_Radius * m_ObjectScale;
                foreach (DynamicBoneCollider c in m_Colliders)
                {
                    if (c != null && c.enabled)
                        c.Collide(ref p.m_Position, particleRadius);
                }
            }

            // freeze axis, project to plane
            if (m_FreezeAxis != FreezeAxis.None)
            {
                switch (m_FreezeAxis)
                {
                    case FreezeAxis.X:
                        movePlane.SetNormalAndPosition(p0.m_Transform.right, p0.m_Position);
                        break;
                    case FreezeAxis.Y:
                        movePlane.SetNormalAndPosition(p0.m_Transform.up, p0.m_Position);
                        break;
                    case FreezeAxis.Z:
                        movePlane.SetNormalAndPosition(p0.m_Transform.forward, p0.m_Position);
                        break;
                }
                p.m_Position -= movePlane.normal * movePlane.GetDistanceToPoint(p.m_Position);
            }

            // keep length
            Vector3 dd = p0.m_Position - p.m_Position;
            float leng = dd.magnitude;
            if (leng > 0)
            {
                p.m_Position += dd * ((leng - restLen) / leng);
            }
        }
    }
开发者ID:Zyow,项目名称:GameJam_P3D_2015,代码行数:88,代码来源:DynamicBone.cs

示例6: Split

    private void Split(Plane worldPlane, Vector3 lineStart, Vector3 lineEnd, int casts)
    {
        if (!splitting)
            return;

        // Sometimes there is null here
        // Too lazy to find real reason right now
        if (transform == null)
            return;

        float distance = worldPlane.GetDistanceToPoint(transform.position);

        Plane plane = new Plane();
        Vector3 newNormal = transform.InverseTransformDirection(worldPlane.normal);
        //Vector3 newNormal = Quaternion.Inverse(transform.rotation) * worldPlane.normal;
        plane.SetNormalAndPosition(newNormal, newNormal * -distance);

        posNormals.Add(-newNormal);
        negNormals.Add(newNormal);
        posNormals.AddRange(mesh.normals);
        negNormals.AddRange(mesh.normals);

        for (int i = 0; i < triangles.Length; i += 3)
        {
            int i1 = triangles[i];//index 1, 2 and 3 of vertices
            int i2 = triangles[i + 1];
            int i3 = triangles[i + 2];
            bool side1 = plane.GetSide(vertices[i1]);
            bool side2 = plane.GetSide(vertices[i2]);
            bool side3 = plane.GetSide(vertices[i3]);

            if (side1 == true && side2 == true && side3 == true)
            {
                posTriangles.Add(i1 + 1); //first index is reserved for interior face middle vertex so every index is incremented by 1
                posTriangles.Add(i2 + 1);
                posTriangles.Add(i3 + 1);
            }
            else if (side1 == false && side2 == false && side3 == false)
            {
                negTriangles.Add(i1 + 1);
                negTriangles.Add(i2 + 1);
                negTriangles.Add(i3 + 1);
            }
            else
            {
                //find odd boolean value(expression found using karnaugh map)
                bool odd = (!side1 && !side2) || (!side1 && !side3) || (!side2 && !side3);

                //find vertex with odd boolean value
                int vertex1, vertex2;
                if (side1 == odd)
                {
                    vertex1 = findNewVertex(i1, i2, plane);
                    vertex2 = findNewVertex(i1, i3, plane);
                    if (side1 == true)
                    {                                          //               i1 /\                  Positive Side
                        posTriangles.Add(i1 + 1);              //                 /  \
                        posTriangles.Add(vertex1 + 1);         //         vertex1/____\vertex2
                        posTriangles.Add(vertex2 + 1);         //               /   _-'\
                                                               //            i2/_.-'____\i3            Negative Side
                        negTriangles.Add(i2 + 1);
                        negTriangles.Add(i3 + 1);
                        negTriangles.Add(vertex2 + 1);

                        negTriangles.Add(i2 + 1);
                        negTriangles.Add(vertex2 + 1);
                        negTriangles.Add(vertex1 + 1);
                    }
                    else
                    {                                           //               i1 /\                  Negative Side
                        negTriangles.Add(i1 + 1);               //                 /  \
                        negTriangles.Add(vertex1 + 1);          //         vertex1/____\vertex2
                        negTriangles.Add(vertex2 + 1);          //               /   _-'\
                                                                //            i2/_.-'____\i3            Positive Side
                        posTriangles.Add(i2 + 1);
                        posTriangles.Add(i3 + 1);
                        posTriangles.Add(vertex2 + 1);

                        posTriangles.Add(i2 + 1);
                        posTriangles.Add(vertex2 + 1);
                        posTriangles.Add(vertex1 + 1);
                    }
                }
                else if (side2 == odd)
                {
                    vertex1 = findNewVertex(i2, i3, plane);
                    vertex2 = findNewVertex(i2, i1, plane);
                    if (side2 == true)
                    {                                           //               i2 /\                  Positive Side
                        posTriangles.Add(i2 + 1);               //                 /  \
                        posTriangles.Add(vertex1 + 1);          //         vertex1/____\vertex2
                        posTriangles.Add(vertex2 + 1);          //               /   _-'\
                                                                //            i3/_.-'____\i1            Negative Side
                        negTriangles.Add(i3 + 1);
                        negTriangles.Add(i1 + 1);
                        negTriangles.Add(vertex2 + 1);

                        negTriangles.Add(i3 + 1);
                        negTriangles.Add(vertex2 + 1);
                        negTriangles.Add(vertex1 + 1);
//.........这里部分代码省略.........
开发者ID:gamezter,项目名称:BananaSplit,代码行数:101,代码来源:Splitable.cs

示例7: GetScreenPointInWorldPlane

 private Vector3 GetScreenPointInWorldPlane(Vector3 screenPoint, float height)
 {
     var ray = Camera.main.ScreenPointToRay(screenPoint);
     var worldPlane = new Plane();
     var dist = 0f;
     worldPlane.SetNormalAndPosition(Vector3.up, new Vector3(0, height, 0));
     worldPlane.Raycast(ray, out dist);
     return ray.GetPoint(dist);
 }
开发者ID:bodedoctor,项目名称:onslaught,代码行数:9,代码来源:Player.cs

示例8: OnSceneGUI

	public void OnSceneGUI() 
	{
		// We can only build or do anything if we can link to our libraries.
#if !( UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || ( UNITY_METRO && UNITY_EDITOR ) )
		return;
		#pragma warning disable 0162
#endif // !( UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || ( UNITY_METRO && UNITY_EDITOR ) )

		if ( myCurve == null )
			return;

		// Enable point size on OpenGL.
		HoudiniHost.preDrawSetup();

		// First Remake and Draw Guide Geometry if necessary.
		if ( mySelectionMeshColours == null )
			buildGuideGeometry();
		
		if ( !myTempCamera && Camera.current )
			myTempCamera = Camera.current;

		Event current_event 		= Event.current;
		Vector3 mouse_position		= getMousePosition( ref current_event );

		// Set appropriate handles matrix.
		// TODO: Fix.
		/*
		Vector3 handle_pos = HAPI_AssetUtility.getPosition( myCurve.transform.localToWorldMatrix );
		Quaternion handle_rot = HAPI_AssetUtility.getQuaternion( myCurve.transform.localToWorldMatrix );
		Matrix4x4 handle_matrix = Matrix4x4.identity;
		handle_matrix.SetTRS( handle_pos, handle_rot, new Vector3( 1.0f, 1.0f, 1.0f ) );
		//Debug.Log( handle_pos );
		//Debug.Log( handle_rot );
		//Debug.Log( handle_matrix );
		Handles.matrix = handle_matrix;
		 */
		Handles.matrix = myCurve.transform.localToWorldMatrix;

		// Determine key state.
		getKeyState( current_event );

		// Decide modes.
		if ( current_event.type == EventType.Layout && mySceneWindowHasFocus )
			decideModes( ref current_event );

		// Draw scene UI.
		drawSceneUI();

		// Add points.
		if ( !current_event.alt && !( current_event.type == EventType.MouseDown && current_event.button == 1 ) )
		{
			if ( myCurve.prIsAddingPoints )
			{
				Vector3 position	= Vector3.zero;
				float handle_size 	= HandleUtility.GetHandleSize( position ) * myBigButtonHandleSizeMultiplier;
				Quaternion rotation = HoudiniAssetUtility.getQuaternion( myTempCamera.transform.localToWorldMatrix );
				bool button_press 	= Handles.Button( 	position, 
														rotation,
														handle_size,
														handle_size,
														Handles.RectangleCap );

				Ray ray = myTempCamera.ScreenPointToRay( mouse_position );
#if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6
				if ( !myTempCamera.isOrthoGraphic )
#else
				if ( !myTempCamera.orthographic )
#endif // UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6
					ray.origin = myTempCamera.transform.position;

				Vector3 intersection = new Vector3();

				if ( myTarget != null && myTarget.GetComponent< Collider >() )
				{
					Collider collider = myTarget.GetComponent< Collider >();
					RaycastHit hit_info;
					collider.Raycast( ray, out hit_info, myIntersectionRayLength );
					intersection = hit_info.point;
				}
				else
				{
					Plane plane = new Plane();
					plane.SetNormalAndPosition( Vector3.up, Vector3.zero );
					float enter = 0.0f;
					plane.Raycast( ray, out enter );
					enter = Mathf.Clamp( enter, myTempCamera.nearClipPlane, myTempCamera.farClipPlane );
 					intersection = ray.origin + ray.direction * enter;
				}

				bool is_mid_point			= false;
				int insert_index			= -1;
				Vector3 new_point_location	= intersection;
				
				// Draw guide line.
				if ( myCurve.prPoints.Count > 0 )
				{
					Vector3 anchor1 = myCurve.transform.TransformPoint(
						myCurve.prPoints[ myCurve.prPoints.Count - 1 ] );
					Vector3 anchor2 = Vector3.zero;
					insert_index = myCurve.prPoints.Count;
//.........这里部分代码省略.........
开发者ID:mbradley36,项目名称:SESIJam,代码行数:101,代码来源:HoudiniCurveGUI.cs

示例9: SliceMyMesh

	public void SliceMyMesh() {
		if (MyMesh) {
			//GameObject SlicedMesh = (GameObject) Instantiate (gameObject, transform.position, Quaternion.identity);	// off set the positions after the meshes are created, by finding out the releative bounds difference
			SlicedCustomMesh1 = (CustomMesh) gameObject.GetComponent("CustomMesh");
			//SlicedCustomMesh2 = (CustomMesh) SlicedMesh.GetComponent("CustomMesh");

			//SlicedCustomMesh2.IsSingleCube = false;

			//MyPlaneNormal = MyPlaneRotation.transform.position;
			MySlicePlane = new Plane(MyPlaneNormal, PlaneDistance);
			MySlicePlane.SetNormalAndPosition(MyPlaneNormal, new Vector3(0,0.5f,0));
			 SlicedPoints1 = new List<Vector3>();
			SlicedIndicies1 = new List<int>();
			SlicedPoints2 = new List<Vector3>();
			SlicedIndicies2 = new List<int>();
			// Where the plane intersects
			SlicedIndicies3 = new List<int>();
			SlicedIndicies4 = new List<int>();
			SlicedPoints4 = new List<Vector3>();
			//SlicedMesh.MyCustomMesh

			// Add all the indicies that intersect with the plane
			for (int i = 0; i < SlicedCustomMesh1.MyCustomMesh.Indicies.Count; i += 3) {	// for all the meshes triangles
				Vector3 Vertex1 = SlicedCustomMesh1.MyCustomMesh.Verticies[SlicedCustomMesh1.MyCustomMesh.Indicies[i]];
				Vector3 Vertex2 = SlicedCustomMesh1.MyCustomMesh.Verticies[SlicedCustomMesh1.MyCustomMesh.Indicies[i+1]];
				Vector3 Vertex3 = SlicedCustomMesh1.MyCustomMesh.Verticies[SlicedCustomMesh1.MyCustomMesh.Indicies[i+2]];
				
				if (MySlicePlane.GetSide(Vertex1+MyPlanePosition) && MySlicePlane.GetSide(Vertex2+MyPlanePosition) && MySlicePlane.GetSide(Vertex3+MyPlanePosition)) {	// if all 3 verticies are on the same side

				} else if (!MySlicePlane.GetSide(Vertex1+MyPlanePosition) && !MySlicePlane.GetSide(Vertex2+MyPlanePosition) && !MySlicePlane.GetSide(Vertex3+MyPlanePosition)) { // if they are not on same side, they are intersected by the plane

				} else {
					SlicedIndicies3.Add(SlicedCustomMesh1.MyCustomMesh.Indicies[i]);
					SlicedIndicies3.Add(SlicedCustomMesh1.MyCustomMesh.Indicies[i+1]);
					SlicedIndicies3.Add(SlicedCustomMesh1.MyCustomMesh.Indicies[i+2]);
					SlicedPoints3.Add (Vertex1);
					SlicedPoints3.Add (Vertex2);
					SlicedPoints3.Add (Vertex3);
				}
			}

			// Now create slices in these triangles
			for (int i = 0; i < SlicedIndicies3.Count; i += 3) {	// for all the meshes triangles
				Vector3 Vertex1 = SlicedCustomMesh1.MyCustomMesh.Verticies[SlicedIndicies3[i]];
				Vector3 Vertex2 = SlicedCustomMesh1.MyCustomMesh.Verticies[SlicedIndicies3[i+1]];
				Vector3 Vertex3 = SlicedCustomMesh1.MyCustomMesh.Verticies[SlicedIndicies3[i+2]];
				// from a slice through a triangle
				// we can get a maximum of 5 points
				// break down 5 points into 3 triangles
				// test this by chose random points along the triangle lines and adding them vertexes

				//RaycastHit hit1;
				Ray Ray1 = new Ray(Vertex1, Vertex1-Vertex2);
				float RayDistance1 = Vector3.Distance (Vertex1, Vertex2);
				if (MySlicePlane.Raycast(Ray1, out RayDistance1)) {
					Debug.Log(" Triangles are sliced 1" );
					DebugVector3 (SlicedCustomMesh1.MyCustomMesh.Verticies[SlicedIndicies3[i]]);
				} else  {
					Debug.Log(i + " Triangles Not Sliced Vertex 1 - ");
					Debug.Log ("    Distance: " + RayDistance1);
					DebugVector3 (Vertex1);
					DebugVector3 (Vertex1 + Ray1.direction*RayDistance1);

					if (RayDistance1 != 0) {
						SlicedIndicies4.Add (i);
						SlicedPoints4.Add (Vertex1 + Ray1.direction*RayDistance1);
						//SlicedCustomMesh1.MyCustomMesh.Verticies[SlicedIndicies3[i]] = Vertex1 + Ray1.direction*RayDistance1;
					}
				}
				Ray Ray2 = new Ray(Vertex2, Vertex2-Vertex3);
				float RayDistance2 = Vector3.Distance (Vertex1, Vertex2);
				if (MySlicePlane.Raycast(Ray2, out RayDistance2)) {
					Debug.Log(" Triangles are sliced 2" );
					SlicedCustomMesh1.MyCustomMesh.Verticies[SlicedIndicies3[i]] = Vertex2 + Ray2.direction*RayDistance2;
				} else  {
					Debug.Log(i + " Triangles Not Sliced 2 - ");
					Debug.Log ("    Distance: " + RayDistance2);
					DebugVector3 (Vertex2);
					DebugVector3 (Vertex2 + Ray2.direction*RayDistance2);
					if (RayDistance2 != 0) {
						SlicedIndicies4.Add (i+1);
						SlicedPoints4.Add (Vertex2 + Ray2.direction*RayDistance2);
						//SlicedCustomMesh1.MyCustomMesh.Verticies[SlicedIndicies3[i]] = Vertex2 + Ray2.direction*RayDistance2;
					}
				}
				Ray Ray3 = new Ray(Vertex3, Vertex3-Vertex1);
				float RayDistance3 = Vector3.Distance (Vertex3, Vertex1);
				if (MySlicePlane.Raycast(Ray3, out RayDistance3)) {
					Debug.Log(" Triangles are sliced 3" );
					DebugVector3 (Vertex2);
					SlicedCustomMesh1.MyCustomMesh.Verticies[SlicedIndicies3[i]] = Vertex3 + Ray3.direction*RayDistance3;
				} else  {
					Debug.Log(i + " Triangles a Not Sliced 3 -");
					Debug.Log ("    Distance: " + RayDistance3);
					DebugVector3 (Vertex3);
					DebugVector3 (Vertex3 + Ray3.direction*RayDistance3);
					if (RayDistance3 != 0) {
						SlicedIndicies4.Add (i+2);
						SlicedPoints4.Add (Vertex3 + Ray3.direction*RayDistance3);
						//SlicedCustomMesh1.MyCustomMesh.Verticies[SlicedIndicies3[i]] = Vertex3 + Ray3.direction*RayDistance3;
//.........这里部分代码省略.........
开发者ID:Deus0,项目名称:Zeltex,代码行数:101,代码来源:SliceMesh.cs

示例10: PreUpdate

        // AT THE START OF EACH FRAME: SYNCHRONIZE INPUT EVENTS AND CALL ONVREVENT CALLBACK FUNCTIONS
        void PreUpdate()
        {
            List<VREvent> inputEvents = new List<VREvent> ();

            // TODO: Add input events generated in Unity to the list of inputEvents to sync them across all clients

            // ----- FAKE TRACKER INPUT FOR DEBUGGING IN DESKTOP MODE USING MOUSE INPUT -----
            if (fakeTrackersForDebugging) {
                float x = Input.mousePosition.x;
                float y = Input.mousePosition.y;
                // first time through
                if (lastx == -9999) {
                    lastx = x;
                    lasty = y;
                    return;
                }

                if (Input.GetKeyDown ("1")) {
                    curTracker = 0;
                } else if (Input.GetKeyDown ("2")) {
                    curTracker = 1;
                }

                if (Input.GetKey ("x")) {
                    float angle = 0.1f * (x - lastx);
                    if (curTracker == 0) {
                        tracker1Rot = Quaternion.AngleAxis (angle, new Vector3 (1f, 0f, 0f)) * tracker1Rot;
                    } else if (curTracker == 1) {
                        tracker2Rot = Quaternion.AngleAxis (angle, new Vector3 (1f, 0f, 0f)) * tracker2Rot;
                    }
                } else if (Input.GetKey ("y")) {
                    float angle = 0.1f * (x - lastx);
                    if (curTracker == 0) {
                        tracker1Rot = Quaternion.AngleAxis (angle, new Vector3 (0f, 1f, 0f)) * tracker1Rot;
                    } else if (curTracker == 1) {
                        tracker2Rot = Quaternion.AngleAxis (angle, new Vector3 (0f, 1f, 0f)) * tracker2Rot;
                    }
                } else if (Input.GetKey ("z")) {
                    float angle = 0.1f * (x - lastx);
                    if (curTracker == 0) {
                        tracker1Rot = Quaternion.AngleAxis (angle, new Vector3 (0f, 0f, 1f)) * tracker1Rot;
                    } else if (curTracker == 1) {
                        tracker2Rot = Quaternion.AngleAxis (angle, new Vector3 (0f, 0f, 1f)) * tracker2Rot;
                    }
                } else if (Input.GetKey ("left shift")) {
                    float depth = 0.005f * (y - lasty);
                    if (curTracker == 0) {
                        tracker1Pos += depth * Camera.main.transform.forward;
                    } else if (curTracker == 1) {
                        tracker2Pos += depth * Camera.main.transform.forward;
                    }
                } else {
                    Ray ray = Camera.main.ScreenPointToRay (new Vector3 (x, y, 0f));
                    Plane p = new Plane ();
                    float dist = 0.0f;
                    if (curTracker == 0) {
                        p.SetNormalAndPosition (-Camera.main.transform.forward, tracker1Pos);
                        if (p.Raycast (ray, out dist)) {
                            tracker1Pos = ray.GetPoint (dist);
                        }
                    } else if (curTracker == 1) {
                        p.SetNormalAndPosition (-Camera.main.transform.forward, tracker2Pos);
                        if (p.Raycast (ray, out dist)) {
                            tracker2Pos = ray.GetPoint (dist);
                        }
                    }
                }

                Matrix4x4 m1 = Matrix4x4.TRS (tracker1Pos, tracker1Rot, Vector3.one);
                double[] d1 = VRConvert.ToDoubleArray (m1);
                VRDataIndex data1 = new VRDataIndex ();
                data1.AddData ("Transform", d1);
                inputEvents.Add (new VREvent (fakeTracker1Event, data1));
                Matrix4x4 m2 = Matrix4x4.TRS (tracker2Pos, tracker2Rot, Vector3.one);
                double[] d2 = VRConvert.ToDoubleArray (m2);
                VRDataIndex data2 = new VRDataIndex ();
                data2.AddData ("Transform", d2);
                inputEvents.Add (new VREvent (fakeTracker2Event, data2));
                lastx = x;
                lasty = y;
            }
            if (fakeHeadTracking) {
                if (Input.GetKey("up")) {
                    headTrackerPos += 0.1f * Camera.main.transform.forward;
                }
                else if (Input.GetKey("down")) {
                    headTrackerPos -= 0.1f * Camera.main.transform.forward;
                }
                else if (Input.GetKey("left")) {
                    headTrackerRot *= Quaternion.AngleAxis (-1.0f, new Vector3 (0f, 1f, 0f));
                }
                else if (Input.GetKey("right")) {
                    headTrackerRot *= Quaternion.AngleAxis (1.0f, new Vector3 (0f, 1f, 0f));
                }
                Matrix4x4 m3 = Matrix4x4.TRS (headTrackerPos, headTrackerRot, Vector3.one);
                double[] d3 = VRConvert.ToDoubleArray (m3);
                VRDataIndex data3 = new VRDataIndex ();
                data3.AddData ("Transform", d3);
                inputEvents.Add (new VREvent (fakeHeadTrackerEvent, data3));
//.........这里部分代码省略.........
开发者ID:ivlab,项目名称:Paint3D,代码行数:101,代码来源:VRMain.cs

示例11: GetSizeMultiplier

	float GetSizeMultiplier( SplineNode node )
	{
		if( !Camera.current.orthographic )
		{
			Plane screen = new Plane( );
			
			float sizeMultiplier = 0f;
			
			screen.SetNormalAndPosition( Camera.current.transform.forward, Camera.current.transform.position );
			screen.Raycast( new Ray( node.Position, Camera.current.transform.forward ), out sizeMultiplier );
			
			return sizeMultiplier * .0075f;
		}
	
		return Camera.current.orthographicSize * 0.01875f;
	}
开发者ID:GDxU,项目名称:incomplete-richman,代码行数:16,代码来源:SplineGizmos.cs


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