Наследование: MonoBehaviour
        void AttachMirrorPlane(BabylonTexture babylonTexture, NovaObject novaObject)
        {
            // Mirror plane
            int f1, f2, f3;

            if (novaObject.Is32bits)
            {
                f1 = novaObject.Indices32[2];
                f2 = novaObject.Indices32[1];
                f3 = novaObject.Indices32[0];
            }
            else
            {
                f1 = novaObject.Indices[2];
                f2 = novaObject.Indices[1];
                f3 = novaObject.Indices[0];
            }
            Vector3 a = novaObject.PositionOnlyVertices[f1];
            Vector3 b = novaObject.PositionOnlyVertices[f2];
            Vector3 c = novaObject.PositionOnlyVertices[f3];

            var mainPlane = new Plane(a, b, c);

            Matrix matrix = Matrix.Invert(novaObject.WorldMatrix);
            matrix = Matrix.Transpose(matrix);
            Plane plane = Plane.Transform(mainPlane, matrix);

            babylonTexture.mirrorPlane = new[] { plane.Normal.X, plane.Normal.Y, plane.Normal.Z, plane.D };
        }
Пример #2
1
    void Update()
    {
        // Movement Input
        Vector3 moveInput = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
        Vector3 moveVelocity = moveInput.normalized * moveSpeed;

        pc.Move(moveVelocity);

        // Look/Aim Input
        Ray ray = cam.ScreenPointToRay(Input.mousePosition);
        Plane groundPlane = new Plane(Vector3.up, Vector3.zero);

        float rayDist;

        if(groundPlane.Raycast(ray, out rayDist))
        {
            Vector3 point = ray.GetPoint(rayDist);
            Debug.DrawLine(ray.origin, point, Color.red);
            pc.LookAt(point);
        }

        // Shooting Input
        if(Input.GetMouseButton(0))
        {
            gc.Shoot();
        }
    }
    public static void TestPlaneConstructor()
    {
        PlaneAttributes atts = new PlaneAttributes("badger50", 1, 5, 3, 7, 2000);
        Plane p = new Plane("acas-1200-badger50", atts);

        //A plane should have anything assigned to it in the constructor reflected in it immediately.
        p.attributes.maxHeight.ShouldBe(2000);
        p.attributes.planeModelGUID.ShouldBe("badger50");
        p.attributes.planeHeight.ShouldBe(3);
        p.attributes.planeWidth.ShouldBe(5);
        p.attributes.planeLength.ShouldBe(7);
        p.attributes.planeClass.ShouldBe(1);

        //A new plane should have no position data within it.
        p.GetPositionCount().ShouldBe(0);

        //A new plane with no position data should have a 'zero' velocity
        p.IsClass(p.attributes.planeClass).ShouldBe(true);
        Vector3d vel = p.GetVelocity();
        vel.x.ShouldBe(0, .01);
        vel.y.ShouldBe(0, .01);
        vel.z.ShouldBe(0, .01);

        //Getting position from a newly constructed plane (with no position data)
        //should cause a NotSupportedException
        Exception ex = null;
        try {
            Vector3d pos = p.GetPosition();
        } catch (Exception e) {
            ex = e;
        }
        ex.ShouldNotBeNull();
        ex.GetType().ShouldBe(typeof(NotSupportedException));
    }
Пример #4
1
        /// <summary>
        /// Checks if curve is flipped to a plane.
        /// </summary>
        /// <param name="plane">
        /// The plane.
        /// </param>
        /// <param name="curve">
        /// The curve.
        /// </param>
        /// <returns>
        /// True if the curve is flipped to the plane, false otherwise.
        /// </returns>
        public static bool MustFlipCurve(Plane plane, Curve curve)
        {
            XYZ xVector = null;
            XYZ yVector = null;
            if (curve is Arc)
            {
                Arc arc = curve as Arc;
                xVector = arc.XDirection;
                yVector = arc.YDirection;
            }
            else if (curve is Ellipse)
            {
                Ellipse ellipse = curve as Ellipse;
                xVector = ellipse.XDirection;
                yVector = ellipse.YDirection;
            }
            else
                return false;

            List<double> realListX = ConvertVectorToLocalCoordinates(plane, xVector);
            List<double> realListY = ConvertVectorToLocalCoordinates(plane, yVector);

            double dot = realListY[0] * (-realListX[1]) + realListY[1] * (realListX[0]);
            if (dot < -MathUtil.Eps())
                return true;

            return false;
        }
Пример #5
1
    IEnumerator DragObject(float distance)
    {
        var oldDrag = springJoint.connectedBody.drag;
        var oldAngularDrag = springJoint.connectedBody.angularDrag;
        springJoint.connectedBody.drag = drag;
        springJoint.connectedBody.angularDrag = angularDrag;
        var mainCamera = FindCamera();
        while (Input.GetMouseButton (0))
        {
            Plane plane = new Plane(Vector3.back, constraintPlaneObject.transform.position);
            Ray ray = mainCamera.ScreenPointToRay (Input.mousePosition);
            float constraintPlaneDistance = 0.0f;
            plane.Raycast(ray, out constraintPlaneDistance);

            springJoint.transform.position = ray.GetPoint(constraintPlaneDistance);
            line.SetPosition(0, springJoint.transform.TransformPoint(springJoint.anchor));
            line.SetPosition(1, springJoint.transform.position);

            yield return null;
        }
        if (springJoint.connectedBody)
        {
            springJoint.connectedBody.drag = oldDrag;
            springJoint.connectedBody.angularDrag = oldAngularDrag;
            springJoint.connectedBody.freezeRotation = false;
            //springJoint.connectedBody = null;
            Destroy(go);
        }
    }
    void Caminar()
    {
        // Da seguimiento a la distancia entre este gameObject y posicionDestino.
        distanciaDestino = Vector3.Distance(posicionDestino, esteTransform.position);

        // Mueve al jugador si el click izquierdo del mouse fue clickeado.
        if (Input.GetMouseButtonDown(0) && GUIUtility.hotControl == 0) {
            Plane planoJugador = new Plane(Vector3.up, esteTransform.position);
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            //Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow);
            float longitudRayo = 0.0f;

            // Obtenemos la longitud del rayo.
            if (planoJugador.Raycast(ray, out longitudRayo)) {

                posicionDestino = ray.GetPoint(longitudRayo); // Coordenada destino
                Quaternion rotacionDestino = Quaternion.LookRotation(posicionDestino - transform.position);
                esteTransform.rotation = rotacionDestino;
            }
        }

        // Evita que el codigo se ejecute si no es necesario.
        if(distanciaDestino > .5f){
            esteTransform.position = Vector3.MoveTowards(esteTransform.position, posicionDestino, velocidad * Time.deltaTime);
        }
    }
Пример #7
1
    public static void BuildDecalForObject(DecalGenerator generator, Transform decal, Transform affectedObject)
    {
        Mesh affectedMesh = affectedObject.GetComponent<MeshFilter>().sharedMesh;
        if (affectedMesh == null) return;

        float maxAngle = generator.maxAngle;

        Plane right = new Plane(Vector3.right, Vector3.right / 2f);
        Plane left = new Plane(-Vector3.right, -Vector3.right / 2f);

        Plane top = new Plane(Vector3.up, Vector3.up / 2f);
        Plane bottom = new Plane(-Vector3.up, -Vector3.up / 2f);

        Plane front = new Plane(Vector3.forward, Vector3.forward / 2f);
        Plane back = new Plane(-Vector3.forward, -Vector3.forward / 2f);

        Vector3[] vertices = affectedMesh.vertices;
        int[] triangles = affectedMesh.triangles;
        int startVertexCount = bufVertices.Count;

        Matrix4x4 matrix = decal.worldToLocalMatrix * affectedObject.transform.localToWorldMatrix;

        for (int i = 0; i < triangles.Length; i += 3)
        {
            int i1 = triangles[i];
            int i2 = triangles[i + 1];
            int i3 = triangles[i + 2];

            Vector3 v1 = matrix.MultiplyPoint(vertices[i1]);
            Vector3 v2 = matrix.MultiplyPoint(vertices[i2]);
            Vector3 v3 = matrix.MultiplyPoint(vertices[i3]);

            Vector3 side1 = v2 - v1;
            Vector3 side2 = v3 - v1;
            Vector3 normal = Vector3.Cross(side1, side2).normalized;

            if (Vector3.Angle(-Vector3.forward, normal) >= maxAngle) continue;

            DecalPolygon poly = new DecalPolygon(v1, v2, v3);

            poly = DecalPolygon.ClipPolygon(poly, right);
            if (poly == null) continue;
            poly = DecalPolygon.ClipPolygon(poly, left);
            if (poly == null) continue;

            poly = DecalPolygon.ClipPolygon(poly, top);
            if (poly == null) continue;
            poly = DecalPolygon.ClipPolygon(poly, bottom);
            if (poly == null) continue;

            poly = DecalPolygon.ClipPolygon(poly, front);
            if (poly == null) continue;
            poly = DecalPolygon.ClipPolygon(poly, back);
            if (poly == null) continue;

            AddPolygon(poly, normal);
        }

        GenerateTexCoords(startVertexCount, generator.sprite);
    }
Пример #8
1
    // =============================================================================
    // METHODS STATIC --------------------------------------------------------------
    public static void SetVanishingPoint( Camera cam, float offset, ClientCameraScreen screen )
    {
        Transform t = cam.transform;
        NearPlane plane = new NearPlane();

        Vector3 nearCenter = t.position + t.forward*cam.nearClipPlane;
        Plane nearPlane = new Plane ( -t.forward, nearCenter );
        float distance = 0f;
        Vector3 direction;
        Ray ray;

        Vector3 screenTL = t.TransformPoint ( new Vector3 ( ( -screen.Width/2.0f ) + offset, screen.Height/2.0f, screen.Distance ) );
        direction = ( screenTL - t.position ).normalized;
        ray = new Ray ( t.position, direction );
        nearPlane.Raycast ( ray, out distance );
        Vector3 nearTL = -( t.InverseTransformPoint ( nearCenter ) - t.InverseTransformPoint ( ( t.position + direction*distance ) ) );

        Vector3 screenBR = t.TransformPoint ( new Vector3 ( ( screen.Width/2.0f ) + offset, -screen.Height/2.0f, screen.Distance ) );
        direction = ( screenBR - t.position ).normalized;
        ray = new Ray ( t.position, direction );
        nearPlane.Raycast ( ray, out distance );
        Vector3 nearBR = -( t.InverseTransformPoint ( nearCenter ) - t.InverseTransformPoint ( ( t.position + direction*distance ) ) );

        plane.left = nearTL.x;
        plane.top = nearTL.y;
        plane.right = nearBR.x;
        plane.bottom = nearBR.y;
        plane.near = cam.nearClipPlane;
        plane.far = cam.farClipPlane;
        cam.projectionMatrix = PerspectiveOffCenter ( plane );
    }
Пример #9
1
	void Update () {
		// Movement input
		Vector3 moveInput = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical"));
		Vector3 moveVelocity = moveInput.normalized * moveSpeed;
		controller.Move (moveVelocity);

		// Look input
		Ray ray = viewCamera.ScreenPointToRay (Input.mousePosition);
		Plane groundPlane = new Plane (Vector3.up, Vector3.up * gunController.GunHeight);
		float rayDistance;

		if (groundPlane.Raycast(ray,out rayDistance)) {
			Vector3 point = ray.GetPoint(rayDistance);
			//Debug.DrawLine(ray.origin,point,Color.red);
			controller.LookAt(point);
			crosshairs.transform.position = point;
			crosshairs.DetectTargets(ray);
			if ((new Vector2(point.x, point.z) - new Vector2(transform.position.x, transform.position.z)).sqrMagnitude > 1) {
				gunController.Aim(point);
			}
		}

		// Weapon input
		if (Input.GetMouseButton(0)) {
			gunController.OnTriggerHold();
		}
		if (Input.GetMouseButtonUp(0)) {
			gunController.OnTriggerRelease();
		}
		if (Input.GetKeyDown (KeyCode.R)) {
			gunController.Reload();
		}
	}
Пример #10
1
    // converts a screen-space position to a world-space position constrained to the current drag plane type
    // returns false if it was unable to get a valid world-space position
    public bool ProjectScreenPointOnDragPlane( Vector3 refPos, Vector2 screenPos, out Vector3 worldPos )
    {
        worldPos = refPos;

        if( DragPlaneCollider )
        {
            Ray ray = RaycastCamera.ScreenPointToRay( screenPos );
            RaycastHit hit;

            if( !DragPlaneCollider.Raycast( ray, out hit, float.MaxValue ) )
                return false;

            worldPos = hit.point + DragPlaneOffset * hit.normal;
		}
		else // DragPlaneType.Camera
		{
            Transform camTransform = RaycastCamera.transform;

            // create a plane passing through refPos and facing toward the camera
            Plane plane = new Plane( -camTransform.forward, refPos );

            Ray ray = RaycastCamera.ScreenPointToRay( screenPos );

            float t = 0;
            if( !plane.Raycast( ray, out t ) )
                return false;

            worldPos = ray.GetPoint( t );
        }
               
		return true;
    }
Пример #11
1
	void Update()
	{
		var plane = new Plane(Vector3.up, transform.position);
		var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		float hit;
		if (plane.Raycast(ray, out hit))
		{
			var aimDirection = Vector3.Normalize(ray.GetPoint(hit) - transform.position);
			var targetRotation = Quaternion.LookRotation(aimDirection);
			transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, 360 * Time.deltaTime);

			if (Input.GetMouseButtonDown(0))
				bulletPrefab.Spawn(gun.position, gun.rotation);
		}

		if (Input.GetKeyDown(KeyCode.Space))
		{
			bulletPrefab.DestroyPooled();
		}

		if (Input.GetKeyDown(KeyCode.Z))
		{
			bulletPrefab.DestroyAll();
		}
	}
Пример #12
1
 private void DoClick(object sender, ClickedEventArgs e)
 {
     if (this.teleportOnClick)
     {
         float y = this.reference.position.y;
         Plane plane = new Plane(Vector3.up, -y);
         Ray ray = new Ray(base.transform.position, base.transform.forward);
         bool flag = false;
         float d = 0f;
         if (this.teleportType == SteamVR_Teleporter.TeleportType.TeleportTypeUseCollider)
         {
             TerrainCollider component = Terrain.activeTerrain.GetComponent<TerrainCollider>();
             RaycastHit raycastHit;
             flag = component.Raycast(ray, out raycastHit, 1000f);
             d = raycastHit.distance;
         }
         else if (this.teleportType == SteamVR_Teleporter.TeleportType.TeleportTypeUseCollider)
         {
             RaycastHit raycastHit2;
             Physics.Raycast(ray, out raycastHit2);
             d = raycastHit2.distance;
         }
         else
         {
             flag = plane.Raycast(ray, out d);
         }
         if (flag)
         {
             Vector3 position = ray.origin + ray.direction * d - new Vector3(this.reference.GetChild(0).localPosition.x, 0f, this.reference.GetChild(0).localPosition.z);
             this.reference.position = position;
         }
     }
 }
 /// <summary>
 /// Extends a plane into a plane surface so that the latter goes through a bounding box.
 /// </summary>
 /// <param name="plane">An original plane value.</param>
 /// <param name="box">A box to use for extension boundary.</param>
 /// <returns>A new plane surface on success, or null on error.</returns>
 /// <example>
 /// <code source='examples\vbnet\ex_splitbrepwithplane.vb' lang='vbnet'/>
 /// <code source='examples\cs\ex_splitbrepwithplane.cs' lang='cs'/>
 /// <code source='examples\py\ex_splitbrepwithplane.py' lang='py'/>
 /// </example>
 public static PlaneSurface CreateThroughBox(Plane plane, BoundingBox box)
 {
   IntPtr ptr = UnsafeNativeMethods.RHC_RhinoPlaneThroughBox2(ref plane, ref box);
   if (IntPtr.Zero == ptr)
     return null;
   return new PlaneSurface(ptr, null);
 }
Пример #14
1
		public Frustum()
		{
			for (var planeIndex = 0; planeIndex < _planes.Length; planeIndex++)
			{
				_planes[planeIndex] = new Plane();
			}
		}
Пример #15
1
 internal RobotCellUR(string name, RobotArm robot, IO io, Plane basePlane, Mesh environment) : base(name, Manufacturers.UR, io, basePlane, environment)
 {
     this.Robot = robot as RobotUR;
     this.DisplayMesh = new Mesh();
     DisplayMesh.Append(robot.DisplayMesh);
     this.DisplayMesh.Transform(this.BasePlane.ToTransform());
 }
Пример #16
1
    public void OnMouseMove( dfControl control, dfMouseEventArgs args )
    {
        if( animating || !dragging )
            return;

        this.momentum = ( momentum + args.MoveDelta.Scale( 1, -1 ) ) * 0.5f;

        args.Use();

        if( args.Buttons.IsSet( dfMouseButtons.Left ) )
        {

            var ray = args.Ray;
            var distance = 0f;
            var direction = Camera.main.transform.TransformDirection( Vector3.back );
            var plane = new Plane( direction, lastPosition );
            plane.Raycast( ray, out distance );

            var pos = ( ray.origin + ray.direction * distance ).Quantize( control.PixelsToUnits() );
            var offset = pos - lastPosition;

            var transformPos = ( control.transform.position + offset ).Quantize( control.PixelsToUnits() );
            control.transform.position = transformPos;

            lastPosition = pos;

        }
    }
Пример #17
1
        /// <summary>
        /// Checks the mouse's position set in the in-game world plane.
        /// </summary>
        /// <param name="mousePosition">Mouse's position on screen</param>
        /// <param name="camera">Camera object</param>
        /// <param name="device">Graphics device used in rendering</param>
        /// <returns></returns>
        public static Vector3 getMouseWorldPosition(Vector2 mousePosition,CameraAndLights camera,GraphicsDevice device)
        {
            Vector3 nearsource = new Vector3(mousePosition,0f);
            Vector3 farsource = new Vector3(mousePosition,CameraAndLights.nearClip);

            Vector3 nearPoint = device.Viewport.Unproject(nearsource,
                                                          camera.projectionMatrix,
                                                          camera.viewMatrix,
                                                          Matrix.Identity);

            Vector3 farPoint = device.Viewport.Unproject(farsource,
                                                         camera.projectionMatrix,
                                                         camera.viewMatrix,
                                                         Matrix.Identity);

            // Create a ray from the near clip plane to the far clip plane.
            Vector3 direction = farPoint - nearPoint;
            direction.Normalize();
            Ray pickRay = new Ray(nearPoint,direction);

            Plane floor = new Plane(new Vector3(0f,1f,0f),0f);

            float denominator = Vector3.Dot(floor.Normal,pickRay.Direction);
            float numerator = Vector3.Dot(floor.Normal,pickRay.Position) + floor.D;
            float dist = -(numerator / denominator);

            Vector3 mouseWorldPos = nearPoint + direction * dist;

            return mouseWorldPos * new Vector3(1f,0f,1f);
        }
Пример #18
0
    // Update is called once per frame
    void Update()
    {
        int layerMask = 1 << 0;  // general

        if (Input.GetMouseButton(0)) {
            if (!isMoving) {
                RaycastHit hit;

                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask) && (hit.rigidbody != null) && (hit.rigidbody.gameObject.tag == "Item")) {
                    // move plane to initial hit position
                    hitDetectPlane = new Plane(Vector3.left, hit.rigidbody.transform.position);
                    movingObject = hit.rigidbody.gameObject;
                    isMoving = true;
                }
            } else {
                //Debug.Log ("ismoving");
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                float rayDistance;
                if (hitDetectPlane.Raycast(ray, out rayDistance))
                    movingObject.transform.position = ray.GetPoint(rayDistance);
            }

        } else {
            isMoving = false;
        }
    }
Пример #19
0
    void FixedUpdate()
    {
        // Generate a plane that intersects the transform's position with an upwards normal.
        Plane playerPlane = new Plane(Vector3.up, transform.position);

        // Generate a ray from the cursor position
        Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);

        // Determine the point where the cursor ray intersects the plane.
        // This will be the point that the object must look towards to be looking at the mouse.
        // Raycasting to a Plane object only gives us a distance, so we'll have to take the distance,
        //   then find the point along that ray that meets that distance.  This will be the point
        //   to look at.
        float hitdist = 0.0f;
        // If the ray is parallel to the plane, Raycast will return false.
        if (playerPlane.Raycast (ray, out hitdist))
        {
            // Get the point along the ray that hits the calculated distance.
            Vector3 targetPoint = ray.GetPoint(hitdist);

            // Determine the target rotation.  This is the rotation if the transform looks at the target point.
            Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);

            // Smoothly rotate towards the target point.
            transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, speed * Time.time);
        }
    }
Пример #20
0
        public void PlaneEqualsTest()
        {
            Plane a = new Plane(1.0f, 2.0f, 3.0f, 4.0f);
            Plane b = new Plane(1.0f, 2.0f, 3.0f, 4.0f);

            // case 1: compare between same values
            object obj = b;

            bool expected = true;
            bool actual = a.Equals(obj);
            Assert.Equal(expected, actual);

            // case 2: compare between different values
            b.Normal = new Vector3(10.0f, b.Normal.Y, b.Normal.Z);

            obj = b;
            expected = false;
            actual = a.Equals(obj);
            Assert.Equal(expected, actual);

            // case 3: compare between different types.
            obj = new Quaternion();
            expected = false;
            actual = a.Equals(obj);
            Assert.Equal(expected, actual);

            // case 3: compare against null.
            obj = null;
            expected = false;
            actual = a.Equals(obj);
            Assert.Equal(expected, actual);
        }
Пример #21
0
    void Update()
    {
        // Movement input
        Vector3 moveInput = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
        Vector3 moveVelocity = moveInput.normalized * moveSpeed;
        controller.Move (moveVelocity);

        // Look input
        Ray ray = viewCamera.ScreenPointToRay (Input.mousePosition);
        Plane groundPlane = new Plane (Vector3.up, Vector3.zero);
        float rayDistance;

        // out keyword assign a value to the rayDistance variable
        if (groundPlane.Raycast (ray, out rayDistance)) {
            Vector3 point = ray.GetPoint(rayDistance);
            // Debug.DrawLine(ray.origin, point, Color.red);
            controller.LookAt(point);
        }

        // Weapon input
        // left mouse button
        if(Input.GetMouseButton(0)) {
            gunController.Shoot();
        }
    }
Пример #22
0
        internal void PlaneGetDistanceToIntersection()
        {
            Plane testPlane = new Plane(Vector3.UnitZ, 10);
            bool hitFrontOfPlane;
            double distanceToHit;

            Ray lookingAtFrontOfPlane = new Ray(new Vector3(0, 0, 11), new Vector3(0, 0, -1));
            Assert.IsTrue(testPlane.RayHitPlane(lookingAtFrontOfPlane, out distanceToHit, out hitFrontOfPlane));
            Assert.IsTrue(distanceToHit == 1);
            Assert.IsTrue(hitFrontOfPlane);

            Ray notLookingAtFrontOfPlane = new Ray(new Vector3(0, 0, 11), new Vector3(0, 0, 1));
            Assert.IsTrue(!testPlane.RayHitPlane(notLookingAtFrontOfPlane, out distanceToHit, out hitFrontOfPlane));
            Assert.IsTrue(distanceToHit == double.PositiveInfinity);
            Assert.IsTrue(!hitFrontOfPlane);

            Ray lookingAtBackOfPlane = new Ray(new Vector3(0, 0, 9), new Vector3(0, 0, 1));
            Assert.IsTrue(testPlane.RayHitPlane(lookingAtBackOfPlane, out distanceToHit, out hitFrontOfPlane));
            Assert.IsTrue(distanceToHit == 1);
            Assert.IsTrue(!hitFrontOfPlane);

            Ray notLookingAtBackOfPlane = new Ray(new Vector3(0, 0, 9), new Vector3(0, 0, -1));
            Assert.IsTrue(!testPlane.RayHitPlane(notLookingAtBackOfPlane, out distanceToHit, out hitFrontOfPlane));
            Assert.IsTrue(distanceToHit == double.PositiveInfinity);
            Assert.IsTrue(hitFrontOfPlane);
        }
Пример #23
0
 // Update is called once per frame
 void Update()
 {
     Plane targetPlane = new Plane(transform.up, transform.position);
     foreach (Touch touch in Input.touches) {
         anim.SetBool("isWalking",true);
         //Gets the ray at position where the screen is touched
         Ray ray = Camera.main.ScreenPointToRay(touch.position);
         //Gets the position of ray along plane
         float dist = 0.0f;
         //Intersects ray with the plane. Sets dist to distance along the ray where intersects
         targetPlane.Raycast(ray, out dist);
         //Returns point dist along the ray.
         Vector3 planePoint = ray.GetPoint(dist);
         //Debug.Log("Point=" + planePoint);
         //True if finger touch began. If ray intersects collider, set pickedObject to transform
         //of collider object
         if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Stationary) {
             //anim.SetBool("isWalking",true);
             player.transform.LookAt(planePoint);
             player.transform.localPosition = Vector3.MoveTowards(playerPos, planePoint, 0.5F * Time.deltaTime);
             //playerPos = player.transform.position;
             playerPos = player.transform.localPosition;
         } else if (touch.phase == TouchPhase.Ended){
             anim.SetBool("isWalking",false);
         }
     }
 }
Пример #24
0
        public void SetPrintLevelingEquation(Vector3 position0, Vector3 position1, Vector3 position2, Vector2 bedCenter)
        {
            if (position0 == position1 || position1 == position2 || position2 == position0)
            {
                return;
            }

            Plane planeOfPoints = new Plane(position0, position1, position2);

            Ray ray = new Ray(new Vector3(bedCenter, 0), Vector3.UnitZ);
            bool inFront;
            double distanceToPlaneAtBedCenter = planeOfPoints.GetDistanceToIntersection(ray, out inFront);

            Matrix4X4 makePointsFlatMatrix = Matrix4X4.CreateTranslation(-bedCenter.x, -bedCenter.y, -distanceToPlaneAtBedCenter);
            makePointsFlatMatrix *= Matrix4X4.CreateRotation(planeOfPoints.planeNormal, Vector3.UnitZ);
            makePointsFlatMatrix *= Matrix4X4.CreateTranslation(bedCenter.x, bedCenter.y, 0);//distanceToPlaneAtBedCenter);

            bedLevelMatrix = Matrix4X4.Invert(makePointsFlatMatrix);

            {
                // test that the points come back as 0 zs
                Vector3 outPosition0 = Vector3.TransformPosition(position0, makePointsFlatMatrix);
                Vector3 outPosition1 = Vector3.TransformPosition(position1, makePointsFlatMatrix);
                Vector3 outPosition2 = Vector3.TransformPosition(position2, makePointsFlatMatrix);

                Vector3 printPosition0 = new Vector3(ActiveSliceSettings.Instance.GetPrintLevelSamplePosition(0), 0);
                Vector3 printPosition1 = new Vector3(ActiveSliceSettings.Instance.GetPrintLevelSamplePosition(1), 0);
                Vector3 printPosition2 = new Vector3(ActiveSliceSettings.Instance.GetPrintLevelSamplePosition(2), 0);

                Vector3 leveledPositon0 = Vector3.TransformPosition(printPosition0, bedLevelMatrix);
                Vector3 leveledPositon1 = Vector3.TransformPosition(printPosition1, bedLevelMatrix);
                Vector3 leveledPositon2 = Vector3.TransformPosition(printPosition2, bedLevelMatrix);
            }
        }
Пример #25
0
    // 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;
        }
    }
Пример #26
0
    void Update()
    {
        if (null != mirrorPlane) {
            if (null != objectBeforeMirror) {
                transform.position = objectBeforeMirror.transform.position;
                transform.rotation = objectBeforeMirror.transform.rotation;

                Vector3 positionInMirrorSpace = mirrorPlane.transform.InverseTransformPoint( objectBeforeMirror.transform.position );

                // move camera forward
                positionInMirrorSpace.y = -positionInMirrorSpace.y;
                positionInMirrorSpace.z = (positionInMirrorSpace.z)/2.5f;

                transform.position = mirrorPlane.transform.TransformPoint( positionInMirrorSpace );

                /** object is now in correct position, but looking in parallel look direction to original */
                /* So, cast a ray from the original object along look-direction until you hit the plane,
                 * then make the cloned object "look at" that position */
                Vector3 mirrorsNormal = mirrorPlane.transform.localRotation * new Vector3( 0f, 1, 0f ); // Unity planes always start with normal pointing up
                Plane planeOfMirror = new Plane(  mirrorsNormal, mirrorPlane.transform.position );
                float intersectionDistance;
                Ray rayToMirror = new Ray( objectBeforeMirror.transform.position, objectBeforeMirror.transform.forward );
                planeOfMirror.Raycast( rayToMirror, out intersectionDistance );
                Vector3 hitPoint = rayToMirror.GetPoint( intersectionDistance );

                transform.LookAt( hitPoint );
            }
        }
    }
Пример #27
0
 internal bool Internal_RaycastRef(Ray ray, ref UIHotSpot.Hit hit)
 {
     float single;
     Vector2 vector2 = new Vector2();
     if (this.radius == 0f)
     {
         return false;
     }
     Plane plane = new Plane(UIHotSpot.forward, this.center);
     if (!plane.Raycast(ray, out single))
     {
         hit = new UIHotSpot.Hit();
         return false;
     }
     hit.point = ray.GetPoint(single);
     hit.normal = (!plane.GetSide(ray.origin) ? UIHotSpot.backward : UIHotSpot.forward);
     vector2.x = hit.point.x - this.center.x;
     vector2.y = hit.point.y - this.center.y;
     float single1 = vector2.x * vector2.x + vector2.y * vector2.y;
     if (single1 >= this.radius * this.radius)
     {
         return false;
     }
     hit.distance = Mathf.Sqrt(single1);
     return true;
 }
Пример #28
0
    Vector3 GetPositionTouch()
    {
        //Create a Vector to store the position where the player will be moving to
        Vector3 moveTo = Vector3.zero;

        //Get the position where it was touched on the screen
        Vector3 positionTouch = Input.GetTouch(0).position;

        //Create a ray from the camera going through the position touched on the screen
        Ray ray = Camera.main.ScreenPointToRay(positionTouch);

        //Create a plane perpendicular to the players's position
        Plane plane = new Plane(Vector3.up, transform.position);

        //Create variable to store distance between the camera and the plane
        float distance = 0;

        //Verify if it ray hits the plane
        if (plane.Raycast(ray, out distance))
        {
            //Get the position where it was hit
            moveTo = ray.GetPoint(distance);
            return moveTo;
        }
        else
        {
            return transform.position;
        }
    }
Пример #29
0
        public override unsafe void GenerateSortKey(RenderView renderView, RenderViewStage renderViewStage, SortKey* sortKeys)
        {
            Matrix viewInverse = renderView.View;
            viewInverse.Invert();
            var plane = new Plane(viewInverse.Forward, Vector3.Dot(viewInverse.TranslationVector, viewInverse.Forward)); // TODO: Point-normal-constructor seems wrong. Check.

            var renderNodes = renderViewStage.RenderNodes;

            int distanceShift = 32 - distancePrecision;
            int stateShift = 32 - statePrecision;

            for (int i = 0; i < renderNodes.Count; ++i)
            {
                var renderNode = renderNodes[i];

                var renderObject = renderNode.RenderObject;
                var distance = CollisionHelper.DistancePlanePoint(ref plane, ref renderObject.BoundingBox.Center);
                var distanceI = ComputeDistance(distance);
                if (reverseDistance)
                    distanceI = ~distanceI;

                // Compute sort key
                sortKeys[i] = new SortKey { Value = ((ulong)renderNode.RootRenderFeature.SortKey << 56) | ((ulong)(distanceI >> distanceShift) << distancePosition) | ((ulong)(renderObject.StateSortKey >> stateShift) << statePosition), Index = i };
            }
        }
Пример #30
0
	void Update(){
		guiIsActive = false;
		foreach(Canvas cn in GameObject.FindObjectsOfType<Canvas>()){
			if(cn.gameObject.activeSelf){
				guiIsActive = true;
			}
		}
		foreach(NpcActionsTemplateScript cn in GameObject.FindObjectsOfType<NpcActionsTemplateScript>()){
			if(cn.gameObject.activeSelf){
				guiIsActive = true;
			}
		}
		if (!guiIsActive && Input.GetMouseButtonDown(0) && GUIUtility.hotControl ==0) {
			
			Plane playerPlane = new Plane(Vector3.up, transform.position);
			Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
			float hitdist = 0.0f;
			
			if (playerPlane.Raycast(ray, out hitdist)) {
				targetPos= ray.GetPoint(hitdist);
			}
			agent.SetDestination (targetPos);
		}

	}
Пример #31
0
        protected override void PerformUpdate()
        {
            if (!hasControl)
            {
                vel = Vector3.zero;
                animator.SetFloat("speed", 0f);
                if (isFiring)
                {
                    StopFiring();
                }
                return;
            }

            // Movement
            if (!isGrounded)
            {
                horizTangent = Vector3.right;
                vertTangent  = Vector3.forward;
            }
            Debug.DrawLine(transform.position, transform.position + horizTangent, Color.red);
            Debug.DrawLine(transform.position, transform.position + vertTangent, Color.blue);
            vel = horizTangent * Input.GetAxisRaw("Horizontal") + vertTangent * Input.GetAxisRaw("Vertical");
            vel.Normalize();
            vel *= speed;
            animator.SetFloat("speed", vel.magnitude);

            // Heading
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            Debug.DrawLine(ray.origin, ray.origin + ray.direction * 1000f, Color.green);
            if (Physics.Raycast(ray, out hit, 100f, 1 << LayerMask.NameToLayer("Ground")))
            {
                target = hit.point + Vector3.up;
                Debug.DrawLine(transform.position, target, Color.red);
            }
            else
            {
                Plane playerPlane = new Plane(transform.position, transform.position + Vector3.forward, transform.position + Vector3.right);
                float distance;
                playerPlane.Raycast(ray, out distance);
                target = ray.origin + ray.direction * distance;
            }
            transform.LookAt(new Vector3(target.x, transform.position.y, target.z));

            // Actions
            if (Input.GetButton("Select Spell 1"))
            {
                SelectSpell(Spell.GetSpell(SpellType.Fireball, this));
            }
            if (Input.GetButton("Select Spell 2") && SpellsManager.I.generalInstability > 0)
            {
                SelectSpell(Spell.GetSpell(SpellType.IceSpike, this));
            }
            if (Input.GetButton("Select Spell 3") && SpellsManager.I.generalInstability > 1)
            {
                SelectSpell(Spell.GetSpell(SpellType.ElectricArc, this));
            }
            if (Input.GetButton("Select Spell 4") && SpellsManager.I.generalInstability > 2)
            {
                SelectSpell(Spell.GetSpell(SpellType.Tornado, this));
            }
            if (Input.GetButton("Select Spell 5") && SpellsManager.I.generalInstability > 3)
            {
                SelectSpell(Spell.GetSpell(SpellType.Beam, this));
            }

            if (Input.GetButtonDown("Fire1"))
            {
                StartFiring();
            }
            if (Input.GetButton("Fire1"))
            {
                SelectedSpell.target = target;
            }
            if (Input.GetButtonUp("Fire1"))
            {
                StopFiring();
            }
        }
Пример #32
0
 // Use this for initialization
 void Awake()
 {
     instance = this;
     myPlane  = new Plane(Vector3.up, new Vector3(0, 0.2f, 0));
 }
Пример #33
0
    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;
                for (int j = 0; j < m_Colliders.Count; ++j)
                {
                    DynamicBoneCollider c = m_Colliders[j];
                    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);
            }
        }
    }
Пример #34
0
    // Token: 0x06003EFD RID: 16125 RVA: 0x000E59D8 File Offset: 0x000E3BD8
    private static int clipToPlane(Plane plane, global::dfClippingUtil.ClipTriangle triangle, global::dfClippingUtil.ClipTriangle[] dest, int destIndex)
    {
        Vector3[] corner   = triangle.corner;
        int       num      = 0;
        int       num2     = 0;
        Vector3   normal   = plane.normal;
        float     distance = plane.distance;

        for (int i = 0; i < 3; i++)
        {
            if (Vector3.Dot(normal, corner[i]) + distance > 0f)
            {
                global::dfClippingUtil.inside[num++] = i;
            }
            else
            {
                num2 = i;
            }
        }
        if (num == 3)
        {
            triangle.CopyTo(dest[destIndex]);
            return(1);
        }
        if (num == 0)
        {
            return(0);
        }
        if (num == 1)
        {
            int     num3    = global::dfClippingUtil.inside[0];
            int     num4    = (num3 + 1) % 3;
            int     num5    = (num3 + 2) % 3;
            Vector3 vector  = corner[num3];
            Vector3 vector2 = corner[num4];
            Vector3 vector3 = corner[num5];
            Vector2 vector4 = triangle.uv[num3];
            Vector2 vector5 = triangle.uv[num4];
            Vector2 vector6 = triangle.uv[num5];
            Color32 color   = triangle.color[num3];
            Color32 color2  = triangle.color[num4];
            Color32 color3  = triangle.color[num5];
            float   num6    = 0f;
            Vector3 vector7 = vector2 - vector;
            Ray     ray;
            ray..ctor(vector, vector7.normalized);
            plane.Raycast(ray, ref num6);
            float   num7    = num6 / vector7.magnitude;
            Vector3 vector8 = ray.origin + ray.direction * num6;
            Vector2 vector9 = Vector2.Lerp(vector4, vector5, num7);
            Color   color4  = Color.Lerp(color, color2, num7);
            vector7 = vector3 - vector;
            ray..ctor(vector, vector7.normalized);
            plane.Raycast(ray, ref num6);
            num7 = num6 / vector7.magnitude;
            Vector3 vector10 = ray.origin + ray.direction * num6;
            Vector2 vector11 = Vector2.Lerp(vector4, vector6, num7);
            Color   color5   = Color.Lerp(color, color3, num7);
            dest[destIndex].corner[0] = vector;
            dest[destIndex].corner[1] = vector8;
            dest[destIndex].corner[2] = vector10;
            dest[destIndex].uv[0]     = vector4;
            dest[destIndex].uv[1]     = vector9;
            dest[destIndex].uv[2]     = vector11;
            dest[destIndex].color[0]  = color;
            dest[destIndex].color[1]  = color4;
            dest[destIndex].color[2]  = color5;
            return(1);
        }
        int     num8     = num2;
        int     num9     = (num8 + 1) % 3;
        int     num10    = (num8 + 2) % 3;
        Vector3 vector12 = corner[num8];
        Vector3 vector13 = corner[num9];
        Vector3 vector14 = corner[num10];
        Vector2 vector15 = triangle.uv[num8];
        Vector2 vector16 = triangle.uv[num9];
        Vector2 vector17 = triangle.uv[num10];
        Color32 color6   = triangle.color[num8];
        Color32 color7   = triangle.color[num9];
        Color32 color8   = triangle.color[num10];
        Vector3 vector18 = vector13 - vector12;
        Ray     ray2;

        ray2..ctor(vector12, vector18.normalized);
        float num11 = 0f;

        plane.Raycast(ray2, ref num11);
        float   num12    = num11 / vector18.magnitude;
        Vector3 vector19 = ray2.origin + ray2.direction * num11;
        Vector2 vector20 = Vector2.Lerp(vector15, vector16, num12);
        Color   color9   = Color.Lerp(color6, color7, num12);

        vector18 = vector14 - vector12;
        ray2..ctor(vector12, vector18.normalized);
        plane.Raycast(ray2, ref num11);
        num12 = num11 / vector18.magnitude;
        Vector3 vector21 = ray2.origin + ray2.direction * num11;
        Vector2 vector22 = Vector2.Lerp(vector15, vector17, num12);
        Color   color10  = Color.Lerp(color6, color8, num12);

        dest[destIndex].corner[0] = vector19;
        dest[destIndex].corner[1] = vector13;
        dest[destIndex].corner[2] = vector21;
        dest[destIndex].uv[0]     = vector20;
        dest[destIndex].uv[1]     = vector16;
        dest[destIndex].uv[2]     = vector22;
        dest[destIndex].color[0]  = color9;
        dest[destIndex].color[1]  = color7;
        dest[destIndex].color[2]  = color10;
        destIndex++;
        dest[destIndex].corner[0] = vector21;
        dest[destIndex].corner[1] = vector13;
        dest[destIndex].corner[2] = vector14;
        dest[destIndex].uv[0]     = vector22;
        dest[destIndex].uv[1]     = vector16;
        dest[destIndex].uv[2]     = vector17;
        dest[destIndex].color[0]  = color10;
        dest[destIndex].color[1]  = color7;
        dest[destIndex].color[2]  = color8;
        return(2);
    }
Пример #35
0
    // Update is called once per frame
    void Update()
    {
        Ray   ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        Plane xy  = new Plane(Vector3.forward, new Vector3(0, 0, 0));
        float distance;

        xy.Raycast(ray, out distance);
        Vector3 mousePosition = ray.GetPoint(distance);

        Vector2 touchPos = new Vector2(mousePosition.x, mousePosition.y);

        /*
         * Debug.Log(mousePosition);
         * Debug.Log(Input.mousePosition);
         */

        if (!game_started)
        {
            return;
        }
        int i;

        //pressed first time
        if (Input.GetMouseButtonDown(0))
        {
            mouse_diff         = Vector3.zero;
            prev_mouseposition = mousePosition;
            Debug.Log("1");
            if (manager.is_my_turn() || debug)
            {
                get_clicked_on_3d(ref mouse_on, ref hit_game_object, mousePosition);
            }
            if (mouse_on == clicked_on.good_tank)
            {
                Debug.Log("2");
                ui_background.GetComponent <ScrollRect>().enabled = false;

                /*
                 * Vector3 look_at_tank = new Vector3(hit_game_object.transform.position.x ,
                 *                                 hit_game_object.transform.position.y,
                 *                                 Camera.main.transform.position.z);
                 * Camera.main.transform.position = look_at_tank;
                 */
            }
        }
        else
        {
            //conitune to press.
            if (Input.GetMouseButton(0))
            {
                if (manager.is_my_turn() == false)
                {
                    if (mouse_on == clicked_on.good_tank)
                    {
                        lineRenderer.enabled = false;

                        ui_background.GetComponent <ScrollRect>().enabled = true;

                        mouse_on = clicked_on.nothing;
                        for (i = 0; i < max_amount_of_arrows; i++)
                        {
                            arrows[i].SetActive(false);
                        }
                    }
                }
                else
                {
                    mouse_diff        += prev_mouseposition - mousePosition;
                    prev_mouseposition = mousePosition;

                    if ((mouse_on == clicked_on.good_tank) && (lineRenderer.enabled == false))
                    {
                        lineRenderer.enabled = true;
                    }
                }
            }
            //pick finger up
            if (Input.GetMouseButtonUp(0))
            {
                if (mouse_on == clicked_on.good_tank)
                {
                    ui_background.GetComponent <ScrollRect>().enabled = true;
                }

                mouse_on = clicked_on.nothing;
                for (i = 0; i < max_amount_of_arrows; i++)
                {
                    arrows[i].SetActive(false);
                }

                if (shot)
                {
                    shot = false;
                    shot_f();
                }
            }
        }

        //Debug.Log (mouse_on);

        if (mouse_on == clicked_on.background)
        {
            mouse_diff = mouse_diff * fade_move_speed;
            if (mouse_diff.sqrMagnitude > 0.01)
            {
                Camera.main.transform.position += (mouse_diff * (speed * Time.deltaTime));
            }
            return;
        }

        if (mouse_on == clicked_on.good_tank)
        {
            lineRenderer.enabled = true;
            shot = true;

            new_mouse_pos = new Vector3(mousePosition.x, mousePosition.y, 9.0f);
            new_mouse_pos = Camera.main.ScreenToWorldPoint(new_mouse_pos);

            /**
             * if camera is prespective
             */
            new_mouse_pos = mousePosition;

            float   distnace         = Vector3.Distance(new_mouse_pos, good_tank.transform.position);
            int     amount_of_arrows = (int)(distnace / size_of_arrow);
            Vector3 diff             = good_tank.transform.position - new_mouse_pos;
            diff_norm = diff.normalized * -1;
            if (amount_of_arrows >= max_amount_of_arrows)
            {
                distnace         = max_amount_of_arrows * size_of_arrow;
                amount_of_arrows = max_amount_of_arrows;

                new_mouse_pos = new Vector3(good_tank.transform.position.x + diff_norm.x * distnace,
                                            good_tank.transform.position.y + diff_norm.y * distnace,
                                            good_tank.transform.position.z);
                diff = good_tank.transform.position - new_mouse_pos;
            }

            if (distnace < min_distance)
            {
                shot = false;
                for (i = 0; i < amount_of_arrows; i++)
                {
                    arrows[i].SetActive(false);
                }
                lineRenderer.enabled = false;
                return;
            }

            scale_circle(good_tank.transform.position, distnace);
            canon_angle = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;

            good_tank_canon.transform.rotation = Quaternion.AngleAxis(canon_angle, Vector3.forward);
            for (i = 0; i < amount_of_arrows; i++)
            {
                arrows[i].SetActive(true);

                arrows[i].transform.rotation = Quaternion.AngleAxis(canon_angle, Vector3.forward);

                Vector3 arrow_pos = new Vector3(new_mouse_pos.x + (diff.x * i) / amount_of_arrows, new_mouse_pos.y + (diff.y * i) / amount_of_arrows, 0f);
                arrows[i].transform.position = arrow_pos;
            }
            for (; i < max_amount_of_arrows; i++)
            {
                arrows[i].SetActive(false);
            }
        }
        else
        {
            lineRenderer.enabled = false;
        }
    }
Пример #36
0
 private void Start()
 {
     player          = GameObject.FindGameObjectWithTag("Player").transform;
     rg              = GetComponent <Rigidbody>();
     playGroundPlane = new Plane(Vector3.up, -1);
 }
Пример #37
0
        public SWIGTYPE_p_std__pairT_bool_float_t intersects(Plane p)
        {
            SWIGTYPE_p_std__pairT_bool_float_t ret = new SWIGTYPE_p_std__pairT_bool_float_t(OgrePINVOKE.Ray_intersects__SWIG_0(swigCPtr, Plane.getCPtr(p)), true);

            if (OgrePINVOKE.SWIGPendingException.Pending)
            {
                throw OgrePINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Пример #38
0
 /// <summary>
 /// Create a new CoreFace for a specific Plane.
 /// </summary>
 /// <param name="id">Id of the face.</param>
 /// <param name="p">PLane representing the face of the Core.</param>
 public CoreFace(string id, Plane p)
 {
     this.Coordinates = p;
     this.Id          = id;
 }
Пример #39
0
 private Plane PrepareUpperPlane()
 {
     upperPlane = new Plane(this, MeshType.Quad, ResourceType.CONCRETE_ID, Block.UP_FACE_INDEX, 0);
     return(upperPlane);
 }
Пример #40
0
 public static bool Equal(Plane a, Plane b)
 {
     return(Equal(a.Normal, b.Normal) && Equal(a.D, b.D));
 }
Пример #41
0
        void Update()
        {
            var position = Temtem.Players.LocalPlayerAvatar.nkqrjhelndm.qqhqkomhdoq;

            if (Input.GetMouseButtonDown(1))
            {
                var obj = FindObjectsOfType <InGameMapUI>().FirstOrDefault();
                if (obj != null && obj.transform.GetChild(0).gameObject.activeInHierarchy)
                {
                    var mapCenterOffset = -obj.GetField <Vector2>("hqkopqprqfl") / 10;
                    var mapZoom         = obj.GetField <Single>("mjmcenrnfli");
                    var newX            = (Input.mousePosition.x - Screen.width / 2) / 10 / mapZoom;
                    var newY            = (Input.mousePosition.y - Screen.height / 2) / 10 / mapZoom;
                    var newTarget       = new Vector3(position.x + newX + mapCenterOffset.x, position.y + 100, position.z + newY + mapCenterOffset.y);
                    UnityEngine.AI.NavMeshHit navHit;
                    UnityEngine.AI.NavMesh.SamplePosition(newTarget, out navHit, 200, UnityEngine.AI.NavMesh.AllAreas);
                    //Temtem.Network.NetworkLogic.nkqrjhelndm.elennjqknrp(Temtem.Network.NetworkLogic.nkqrjhelndm.npqcecmqpio, navHit.position);
                    typeof(LocalPlayerAvatar).GetField <LocalPlayerAvatar>().gameObject.GetComponent <PlayerMovement>().cimqnlfephf(navHit.position);
                }
                else
                {
                    var minimap = (MonoBehaviour)FindObjectsOfType <MinimapFogController>().FirstOrDefault();
                    if (minimap == null)
                    {
                        minimap = (MonoBehaviour)FindObjectsOfType <GenericMinimap>().FirstOrDefault();
                    }
                    if (minimap != null && minimap.gameObject.activeInHierarchy)
                    {
                        var pos = Input.mousePosition;
                        pos.z = typeof(Temtem.Configuration.VisualSettings).GetField <Single>("cameraDistance");
                        var playerPlane = new Plane(Vector3.up, position);
                        var ray         = Camera.allCameras[0].ScreenPointToRay(pos);
                        var hitdist     = 0.0f;
                        if (playerPlane.Raycast(ray, out hitdist))
                        {
                            var clickPosition = ray.GetPoint(hitdist);
                            UnityEngine.AI.NavMeshHit navHit;
                            UnityEngine.AI.NavMesh.SamplePosition(clickPosition, out navHit, 200, UnityEngine.AI.NavMesh.AllAreas);
                            //Temtem.Network.NetworkLogic.nkqrjhelndm.elennjqknrp(Temtem.Network.NetworkLogic.nkqrjhelndm.npqcecmqpio, navHit.position);
                            typeof(LocalPlayerAvatar).GetField <LocalPlayerAvatar>().gameObject.GetComponent <PlayerMovement>().cimqnlfephf(navHit.position);
                        }
                    }
                }
            }
            var teleportDistance = 1;

            if (Input.GetKeyDown(KeyCode.Keypad4))
            {
                typeof(LocalPlayerAvatar).GetField <LocalPlayerAvatar>().gameObject.GetComponent <PlayerMovement>().cimqnlfephf(new Vector3(position.x - teleportDistance, position.y, position.z));
            }
            if (Input.GetKeyDown(KeyCode.Keypad6))
            {
                typeof(LocalPlayerAvatar).GetField <LocalPlayerAvatar>().gameObject.GetComponent <PlayerMovement>().cimqnlfephf(new Vector3(position.x + teleportDistance, position.y, position.z));
            }
            if (Input.GetKeyDown(KeyCode.Keypad8))
            {
                typeof(LocalPlayerAvatar).GetField <LocalPlayerAvatar>().gameObject.GetComponent <PlayerMovement>().cimqnlfephf(new Vector3(position.x, position.y, position.z + teleportDistance));
            }
            if (Input.GetKeyDown(KeyCode.Keypad2))
            {
                typeof(LocalPlayerAvatar).GetField <LocalPlayerAvatar>().gameObject.GetComponent <PlayerMovement>().cimqnlfephf(new Vector3(position.x, position.y, position.z - teleportDistance));
            }
            if (Input.GetKeyDown(KeyCode.Keypad7))
            {
                typeof(LocalPlayerAvatar).GetField <LocalPlayerAvatar>().gameObject.GetComponent <PlayerMovement>().cimqnlfephf(new Vector3(position.x, position.y + teleportDistance, position.z));
            }
            if (Input.GetKeyDown(KeyCode.Keypad1))
            {
                typeof(LocalPlayerAvatar).GetField <LocalPlayerAvatar>().gameObject.GetComponent <PlayerMovement>().cimqnlfephf(new Vector3(position.x, position.y - teleportDistance, position.z));
            }
        }
        /// <summary>
        /// Create a new swept blend form using arcs to
        /// define circular start and end profiles and an
        /// arc path. The NewSweptBlend method requires
        /// the input profiles to be in the XY plane.
        /// </summary>
        public void CreateNewSweptBlendArc(Document doc)
        {
            Debug.Assert(doc.IsFamilyDocument,
                         "this method will only work in a family document");

            Application app = doc.Application;

            Autodesk.Revit.Creation.Application creapp
                = app.Create;

            Autodesk.Revit.Creation.FamilyItemFactory credoc
                = doc.FamilyCreate;

            #region Original code for Revit 2012
      #if COMPILE_ORIGINAL_CODE
            XYZ           pnt1    = new XYZ(0, -1, 0);
            XYZ           pnt2    = new XYZ(1, 0, 0);
            XYZ           pnt3    = new XYZ(0, 1, 0);
            XYZ           pnt4    = new XYZ(-1, 0, 0);
            Arc           aArc1   = creapp.NewArc(pnt1, pnt3, pnt2);
            Arc           aArc2   = creapp.NewArc(pnt3, pnt1, pnt4);
            CurveArrArray arrarr1 = new CurveArrArray();

            SweepProfile bottomProfile
                = creapp.NewCurveLoopsProfile(arrarr1);

            CurveArray arr1 = new CurveArray();
            arr1.Append(aArc1);
            arr1.Append(aArc2);
            XYZ           pnt6    = new XYZ(0, -2, 0);
            XYZ           pnt7    = new XYZ(2, 0, 0);
            XYZ           pnt8    = new XYZ(0, 2, 0);
            XYZ           pnt9    = new XYZ(-2, 0, 0);
            Arc           aArc3   = creapp.NewArc(pnt6, pnt8, pnt7);
            Arc           aArc4   = creapp.NewArc(pnt8, pnt6, pnt9);
            CurveArrArray arrarr2 = new CurveArrArray();
            CurveArray    arr2    = new CurveArray();
            arr2.Append(aArc3);
            arr2.Append(aArc4);
            arrarr2.Append(arr2);

            SweepProfile topProfile
                = creapp.NewCurveLoopsProfile(arrarr2);

            XYZ   pnt10   = new XYZ(0, 0, 0);
            XYZ   pnt11   = new XYZ(0, 5, 0);
            XYZ   pnt122  = new XYZ(2.5, 2.5, 0);
            Arc   testArc = creapp.NewArc(pnt10, pnt11, pnt122);
            Curve curve   = (Curve)testArc;

            Plane geometryPlane = creapp.NewPlane(
                XYZ.BasisZ, XYZ.Zero);

            SketchPlane sketchPlane = doc.NewSketchPlane(
                geometryPlane);

            SweptBlend aSweptBlend = doc.NewSweptBlend(
                true, curve, sketchPlane, bottomProfile,
                topProfile);
      #endif // COMPILE_ORIGINAL_CODE
            #endregion // Original code for Revit 2012

            XYZ        px   = XYZ.BasisX;
            XYZ        py   = XYZ.BasisY;
            Arc        arc1 = Arc.Create(-px, px, -py);
            Arc        arc2 = Arc.Create(px, -px, py);
            CurveArray arr1 = new CurveArray();
            arr1.Append(arc1);
            arr1.Append(arc2);
            CurveArrArray arrarr1 = new CurveArrArray();
            arrarr1.Append(arr1);

            SweepProfile bottomProfile
                = creapp.NewCurveLoopsProfile(arrarr1);

            px += px;
            py += py;
            Arc        arc3 = Arc.Create(-px, px, -py);
            Arc        arc4 = Arc.Create(px, -px, py);
            CurveArray arr2 = new CurveArray();
            arr2.Append(arc3);
            arr2.Append(arc4);
            CurveArrArray arrarr2 = new CurveArrArray();
            arrarr2.Append(arr2);

            SweepProfile topProfile
                = creapp.NewCurveLoopsProfile(arrarr2);

            XYZ p0      = XYZ.Zero;
            XYZ p5      = 5 * XYZ.BasisY;
            XYZ pmid    = new XYZ(2.5, 2.5, 0);
            Arc testArc = Arc.Create(p0, p5, pmid);

            //Plane geometryPlane = creapp.NewPlane( XYZ.BasisZ, XYZ.Zero ); // 2016
            Plane geometryPlane = Plane.CreateByNormalAndOrigin(
                XYZ.BasisZ, XYZ.Zero); // 2017

            SketchPlane sketchPlane = SketchPlane.Create(
                doc, geometryPlane);

            SweptBlend aSweptBlend = credoc.NewSweptBlend(
                true, testArc, sketchPlane, bottomProfile,
                topProfile);
        }
Пример #43
0
        // This builds the geometry. Returns false when no geometry created.
        public override bool Setup()
        {
            //mxd
            if (Sidedef.LongMiddleTexture == MapSet.EmptyLongName)
            {
                base.SetVertices(null);
                return(false);
            }

            Vector2D vl, vr;

            //mxd. lightfog flag support
            int  lightvalue;
            bool lightabsolute;

            GetLightValue(out lightvalue, out lightabsolute);

            Vector2D tscale = new Vector2D(Sidedef.Fields.GetValue("scalex_mid", 1.0f),
                                           Sidedef.Fields.GetValue("scaley_mid", 1.0f));
            Vector2D toffset = new Vector2D(Sidedef.Fields.GetValue("offsetx_mid", 0.0f),
                                            Sidedef.Fields.GetValue("offsety_mid", 0.0f));

            // Left and right vertices for this sidedef
            if (Sidedef.IsFront)
            {
                vl = new Vector2D(Sidedef.Line.Start.Position.x, Sidedef.Line.Start.Position.y);
                vr = new Vector2D(Sidedef.Line.End.Position.x, Sidedef.Line.End.Position.y);
            }
            else
            {
                vl = new Vector2D(Sidedef.Line.End.Position.x, Sidedef.Line.End.Position.y);
                vr = new Vector2D(Sidedef.Line.Start.Position.x, Sidedef.Line.Start.Position.y);
            }

            // Load sector data
            SectorData sd  = mode.GetSectorData(Sidedef.Sector);
            SectorData osd = mode.GetSectorData(Sidedef.Other.Sector);

            if (!osd.Updated)
            {
                osd.Update();
            }

            // Load texture
            if (Sidedef.LongMiddleTexture != MapSet.EmptyLongName)
            {
                base.Texture = General.Map.Data.GetTextureImage(Sidedef.LongMiddleTexture);
                if (base.Texture == null || base.Texture is UnknownImage)
                {
                    base.Texture         = General.Map.Data.UnknownTexture3D;
                    setuponloadedtexture = Sidedef.LongMiddleTexture;
                }
                else if (!base.Texture.IsImageLoaded)
                {
                    setuponloadedtexture = Sidedef.LongMiddleTexture;
                }
            }
            else
            {
                // Use missing texture
                base.Texture         = General.Map.Data.MissingTexture3D;
                setuponloadedtexture = 0;
            }

            // Get texture scaled size
            Vector2D tsz = new Vector2D(base.Texture.ScaledWidth, base.Texture.ScaledHeight);

            tsz = tsz / tscale;

            // Get texture offsets
            Vector2D tof = new Vector2D(Sidedef.OffsetX, Sidedef.OffsetY);

            tof = tof + toffset;
            tof = tof / tscale;
            if (General.Map.Config.ScaledTextureOffsets && !base.Texture.WorldPanning)
            {
                tof = tof * base.Texture.Scale;
            }

            // Determine texture coordinates plane as they would be in normal circumstances.
            // We can then use this plane to find any texture coordinate we need.
            // The logic here is the same as in the original VisualMiddleSingle (except that
            // the values are stored in a TexturePlane)
            // NOTE: I use a small bias for the floor height, because if the difference in
            // height is 0 then the TexturePlane doesn't work!
            TexturePlane tp        = new TexturePlane();
            float        floorbias = (Sidedef.Sector.CeilHeight == Sidedef.Sector.FloorHeight) ? 1.0f : 0.0f;
            float        geotop    = Math.Min(Sidedef.Sector.CeilHeight, Sidedef.Other.Sector.CeilHeight);
            float        geobottom = Math.Max(Sidedef.Sector.FloorHeight, Sidedef.Other.Sector.FloorHeight);
            float        zoffset   = Sidedef.Sector.CeilHeight - Sidedef.Other.Sector.CeilHeight;    //mxd

            // When lower unpegged is set, the middle texture is bound to the bottom
            if (Sidedef.Line.IsFlagSet(General.Map.Config.LowerUnpeggedFlag))
            {
                tp.tlt.y = tsz.y - (geotop - geobottom);
            }

            if (zoffset > 0)
            {
                tp.tlt.y -= zoffset;                                      //mxd
            }
            tp.trb.x = tp.tlt.x + (float)Math.Round(Sidedef.Line.Length); //mxd. (G)ZDoom snaps texture coordinates to integral linedef length
            tp.trb.y = tp.tlt.y + (Sidedef.Sector.CeilHeight - (Sidedef.Sector.FloorHeight + floorbias));

            // Apply texture offset
            tp.tlt += tof;
            tp.trb += tof;

            // Transform pixel coordinates to texture coordinates
            tp.tlt /= tsz;
            tp.trb /= tsz;

            // Left top and right bottom of the geometry that
            tp.vlt = new Vector3D(vl.x, vl.y, Sidedef.Sector.CeilHeight);
            tp.vrb = new Vector3D(vr.x, vr.y, Sidedef.Sector.FloorHeight + floorbias);

            // Make the right-top coordinates
            tp.trt = new Vector2D(tp.trb.x, tp.tlt.y);
            tp.vrt = new Vector3D(tp.vrb.x, tp.vrb.y, tp.vlt.z);

            // Keep top and bottom planes for intersection testing
            top    = sd.Ceiling.plane;
            bottom = sd.Floor.plane;

            // Create initial polygon, which is just a quad between floor and ceiling
            WallPolygon poly = new WallPolygon();

            poly.Add(new Vector3D(vl.x, vl.y, sd.Floor.plane.GetZ(vl)));
            poly.Add(new Vector3D(vl.x, vl.y, sd.Ceiling.plane.GetZ(vl)));
            poly.Add(new Vector3D(vr.x, vr.y, sd.Ceiling.plane.GetZ(vr)));
            poly.Add(new Vector3D(vr.x, vr.y, sd.Floor.plane.GetZ(vr)));

            // Determine initial color
            int lightlevel = lightabsolute ? lightvalue : sd.Ceiling.brightnessbelow + lightvalue;

            //mxd. This calculates light with doom-style wall shading
            PixelColor wallbrightness = PixelColor.FromInt(mode.CalculateBrightness(lightlevel, Sidedef));
            PixelColor wallcolor      = PixelColor.Modulate(sd.Ceiling.colorbelow, wallbrightness);

            fogfactor  = CalculateFogFactor(lightlevel);
            poly.color = wallcolor.WithAlpha(255).ToInt();

            // Cut off the part below the other floor and above the other ceiling
            CropPoly(ref poly, osd.Ceiling.plane, true);
            CropPoly(ref poly, osd.Floor.plane, true);

            // Determine if we should repeat the middle texture
            repeatmidtex = Sidedef.IsFlagSet("wrapmidtex") || Sidedef.Line.IsFlagSet("wrapmidtex");             //mxd
            if (!repeatmidtex)
            {
                // First determine the visible portion of the texture
                float textop;

                // Determine top portion height
                if (Sidedef.Line.IsFlagSet(General.Map.Config.LowerUnpeggedFlag))
                {
                    textop = geobottom + tof.y + Math.Abs(tsz.y);
                }
                else
                {
                    textop = geotop + tof.y;
                }

                // Calculate bottom portion height
                float texbottom = textop - Math.Abs(tsz.y);

                // Create crop planes (we also need these for intersection testing)
                topclipplane    = new Plane(new Vector3D(0, 0, -1), textop);
                bottomclipplane = new Plane(new Vector3D(0, 0, 1), -texbottom);

                // Crop polygon by these heights
                CropPoly(ref poly, topclipplane, true);
                CropPoly(ref poly, bottomclipplane, true);
            }

            //mxd. In(G)ZDoom, middle sidedef parts are not clipped by extrafloors of any type...
            List <WallPolygon> polygons = new List <WallPolygon> {
                poly
            };

            //ClipExtraFloors(polygons, sd.ExtraFloors, true); //mxd
            //ClipExtraFloors(polygons, osd.ExtraFloors, true); //mxd

            //if(polygons.Count > 0)
            //{
            // Keep top and bottom planes for intersection testing
            top    = osd.Ceiling.plane;
            bottom = osd.Floor.plane;

            // Process the polygon and create vertices
            List <WorldVertex> verts = CreatePolygonVertices(polygons, tp, sd, lightvalue, lightabsolute);

            if (verts.Count > 2)
            {
                // Apply alpha to vertices
                byte alpha = SetLinedefRenderstyle(true);
                if (alpha < 255)
                {
                    for (int i = 0; i < verts.Count; i++)
                    {
                        WorldVertex v = verts[i];
                        v.c      = PixelColor.FromInt(v.c).WithAlpha(alpha).ToInt();
                        verts[i] = v;
                    }
                }

                base.SetVertices(verts);
                return(true);
            }
            //}

            base.SetVertices(null);             //mxd
            return(false);
        }
Пример #44
0
 protected abstract bool ShouldOrNotFire(Plane plane);
Пример #45
0
 ///<description>Fire bullet</description>
 public void FireBullet(Plane plane)
 {
     onFireShot(plane);
 }
Пример #46
0
    /// <summary>
    /// Given the widget's corners, convert the given screen coordinates to world coordinates.
    /// </summary>

    static public bool ScreenToWorldPoint(Vector3[] corners, Vector2 screenPos, out Vector3 worldPos)
    {
        Plane p = new Plane(corners[0], corners[1], corners[3]);

        return(ScreenToWorldPoint(p, screenPos, out worldPos));
    }
Пример #47
0
    void Update()
    {
        //topdown behaviour
        if (PlayerBehaviour == Type.TopDown)
        {
            //Move Input
            if (InputDirection == DirectionType.Global)
            {
                moveDirection = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical")).normalized;
            }
            else
            if (InputDirection == DirectionType.Camera)
            {
                moveDirection        = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical")).normalized;
                cameraBasedDirection = cam.transform.TransformDirection(moveDirection);
                moveDirection        = new Vector3(cameraBasedDirection.x, moveDirection.y, cameraBasedDirection.z);
            }


            //Aim Input
            float distance;
            Plane aimPlane = new Plane(Vector3.up, Vector3.zero);
            Ray   ray      = cam.ScreenPointToRay(Input.mousePosition);
            if (aimPlane.Raycast(ray, out distance))
            {
                Vector3 hitPoint = ray.origin + ray.direction * distance;
                Debug.DrawLine(cam.transform.position, hitPoint);
                transform.LookAt(new Vector3(hitPoint.x, transform.position.y, hitPoint.z));
            }
        }

        //firstperson behaviour
        if (PlayerBehaviour == Type.FirstPerson)
        {
            EquippedGun.transform.forward = Camera.main.transform.forward;
            //EquippedGun.transform.LookAt(Camera.main.transform.forward * 1000f);
            //Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            //RaycastHit hit;
            //if (Physics.Raycast(ray, out hit, Mathf.Infinity, MaskToIgnore))
            //{
            //    print(":)");
            //    Debug.DrawLine(ray.origin, hit.point);
            //    EquippedGun.transform.LookAt(hit.point);
            //}
        }

        //Shoot Input
        if (Input.GetKeyDown(shootInput) && EquippedGun)
        {
            EquippedGun.Shoot();
        }

        if (moveDirection == Vector3.zero)
        {
            IsMoving = false;
        }
        else
        {
            IsMoving = true;
        }
    }
Пример #48
0
    //---------------------------------------------------
    // Input handling:
    //---------------------------------------------------
    public override void OnInput(POINTER_INFO ptr)
    {
        if (!m_controlIsEnabled)
        {
            return;
        }

        if (inputDelegate != null)
        {
            inputDelegate(ref ptr);
        }

// Only check for out-of-viewport input if such is possible
// (i.e. if we aren't on a hardware device where it is
// impossible to have input outside the viewport)
#if UNITY_EDITOR || !(UNITY_IPHONE || UNITY_ANDROID)
        // See if the input should be considered a move-off
        // because it is outside the viewport:
        if (ptr.devicePos.x < 0 ||
            ptr.devicePos.y < 0 ||
            ptr.devicePos.x > ptr.camera.pixelWidth ||
            ptr.devicePos.y > ptr.camera.pixelHeight)
        {
            if (m_panelState == STATE.OVER)
            {
                SetPanelState(STATE.NORMAL);
            }

            // Only continue if we are dragging the panel:
            if (m_panelState != STATE.DRAGGING)
            {
                return;
            }
        }
#endif

        // Change the state if necessary:
        switch (ptr.evt)
        {
        case POINTER_INFO.INPUT_EVENT.MOVE:
            if (m_panelState != STATE.OVER)
            {
                SetPanelState(STATE.OVER);
            }
            break;

        case POINTER_INFO.INPUT_EVENT.DRAG:
            if (draggable && !ptr.callerIsControl)
            {
                // Early out:
                if (ptr.inputDelta.sqrMagnitude == 0)
                {
                    break;
                }
                ;

                float   dist;
                Vector3 pt1, pt2;
                Plane   plane = default(Plane);

                plane.SetNormalAndPosition(transform.forward * -1f, transform.position);

                plane.Raycast(ptr.ray, out dist);
                pt1 = ptr.ray.origin + ptr.ray.direction * dist;

                plane.Raycast(ptr.prevRay, out dist);
                pt2 = ptr.prevRay.origin + ptr.prevRay.direction * dist;

                pt1 = transform.position + (pt1 - pt2);

                if (constrainDragArea)
                {
                    pt1.x = Mathf.Clamp(pt1.x, dragBoundaryMin.x, dragBoundaryMax.x);
                    pt1.y = Mathf.Clamp(pt1.y, dragBoundaryMin.y, dragBoundaryMax.y);
                    pt1.z = Mathf.Clamp(pt1.z, dragBoundaryMin.z, dragBoundaryMax.z);
                }

                transform.position = pt1;

                SetPanelState(STATE.DRAGGING);
            }
            break;

        case POINTER_INFO.INPUT_EVENT.MOVE_OFF:
        case POINTER_INFO.INPUT_EVENT.RELEASE_OFF:
//              if (!ptr.callerIsControl)
//                  SetPanelState(STATE.NORMAL);
//              else
        {                               // Else do a raycast to see if we're
                                        // still under the pointer and one of
                                        // our child controls is just catching
                                        // the hit instead:
            RaycastHit hit;
            if (collider != null)
            {
                if (!collider.Raycast(ptr.ray, out hit, ptr.rayDepth))
                {
                    SetPanelState(STATE.NORMAL);
                }
                else
                {
                    if (ptr.evt == POINTER_INFO.INPUT_EVENT.MOVE_OFF)
                    {
                        // Change the event to a MOVE so that any
                        // parent panel doesn't try its own raycast
                        // and fail since the pointer is over us
                        // instead:
                        ptr.evt = POINTER_INFO.INPUT_EVENT.MOVE;
                    }
                    else
                    {
                        ptr.evt = POINTER_INFO.INPUT_EVENT.RELEASE;
                    }
                }
            }
        }
        break;
        }

        base.OnInput(ptr);
    }
Пример #49
0
    // Get raw makes it stop really fast, without a slope
    // Update is called once per frame
    void Update()
    {
        // Quit game function
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }

        // Setting the position for the camera with and without the screenshake.
        if (cameraShake)
        {
            mainCamera.transform.position = new Vector3((transform.position.x - shakeAmount) + Random.Range(0, shakeAmount * 2), transform.position.y + 15, ((transform.position.z - shakeAmount) + Random.Range(0, shakeAmount * 2)) - 4);
            //shake -= Time.deltaTime * decreaseFactor;
        }

        if (!cameraShake)
        {
            mainCamera.transform.position = new Vector3(transform.position.x, transform.position.y + 15, transform.position.z - 4);
        }


        // Moving around with the traditional keys

        moveInput = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical"));

        // Setting running controls
        if (running)
        {
            moveVelocity = moveInput * moveSpeed * 1.5f;
        }

        if (!running)
        {
            moveVelocity = moveInput * moveSpeed;
        }


        // Ray is a beam coming out of a point. The plane is a mathematical plane, not a physical object in the gameworld.
        // Rotating with the mouse below.

        if (!useController)
        {
            Ray   cameraRay   = mainCamera.ScreenPointToRay(Input.mousePosition);
            Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
            float rayLength;

            if (groundPlane.Raycast(cameraRay, out rayLength))
            {
                Vector3 pointToLook = cameraRay.GetPoint(rayLength);
                //Debug.DrawLine(cameraRay.origin, pointToLook, Color.blue);

                transform.LookAt(new Vector3(pointToLook.x, transform.position.y, pointToLook.z));
            }

            // Mouse button 0 is left, 1 is right, 2 is middle.
            if (Input.GetAxis("Fire1") > 0)
            {
                theGun.isFiring = true;
            }

            if (Input.GetAxis("Fire1") <= 0)
            {
                theGun.isFiring = false;
            }

            // Running controls
            if (Input.GetAxis("Run") > 0)
            {
                running = true;
            }

            if (Input.GetAxis("Run") <= 0)
            {
                running = false;
            }

            // Jumping controls
            if (Input.GetAxis("Jump") > 0 && jumpCooldown <= 0 && Input.GetAxis("Jetpack") <= 0)
            {
                transform.position = new Vector3(transform.position.x, transform.position.y + 0.5f, transform.position.z);
                jumpThrust        += 1f;
                jumpCooldown      += 0.8f;
            }

            if (jumpThrust > 0)
            {
                transform.position = new Vector3(transform.position.x, transform.position.y + 0.4f, transform.position.z);
                jumpThrust        -= Time.deltaTime * 7;
            }

            if (jumpCooldown > 0)
            {
                jumpCooldown -= Time.deltaTime;
            }

            // Jumping controls
            if (Input.GetAxis("Jetpack") > 0)
            {
                transform.position = new Vector3(transform.position.x, transform.position.y + 0.3f, transform.position.z);
            }
        }


        // Includes the Shake amount set for camera.
        if (theGun.isFiring)
        {
            cameraShake = true;
        }

        if (!theGun.isFiring)
        {
            cameraShake = false;
        }


        // Rotate with a controller.
        if (useController)
        {
            Vector3 playerDirection = Vector3.right * Input.GetAxisRaw("RHorizontal") + Vector3.forward * -Input.GetAxisRaw("RVertical");

            if (playerDirection.sqrMagnitude > 0.0f)
            {
                transform.rotation = Quaternion.LookRotation(playerDirection, Vector3.up);
            }

            if (Input.GetKeyDown(KeyCode.Joystick1Button5))
            {
                theGun.isFiring = true;
            }

            if (Input.GetKeyUp(KeyCode.Joystick1Button5))
            {
                theGun.isFiring = false;
            }
        }
    }
Пример #50
0
        /// <summary>
        /// Create geometry for an IfcHalfSpaceSolid.
        /// </summary>
        /// <param name="shapeEditScope">The shape edit scope.</param>
        /// <param name="lcs">Local coordinate system for the geometry, without scale.</param>
        /// <param name="scaledLcs">Local coordinate system for the geometry, including scale, potentially non-uniform.</param>
        /// <param name="guid">The guid of an element for which represntation is being created.</param>
        /// <returns>A list containing one geometry for the IfcHalfSpaceSolid.</returns>
        protected virtual IList <GeometryObject> CreateGeometryInternal(
            IFCImportShapeEditScope shapeEditScope, Transform unscaledLcs, Transform scaledLcs, string guid)
        {
            IFCPlane ifcPlane = BaseSurface as IFCPlane;
            Plane    plane    = ifcPlane.Plane;
            XYZ      origin   = plane.Origin;
            XYZ      xVec     = plane.XVec;
            XYZ      yVec     = plane.YVec;

            // Set some huge boundaries for now.
            const double largeCoordinateValue = 100000;

            XYZ[] corners = new XYZ[4] {
                unscaledLcs.OfPoint((xVec * -largeCoordinateValue) + (yVec * -largeCoordinateValue) + origin),
                unscaledLcs.OfPoint((xVec * largeCoordinateValue) + (yVec * -largeCoordinateValue) + origin),
                unscaledLcs.OfPoint((xVec * largeCoordinateValue) + (yVec * largeCoordinateValue) + origin),
                unscaledLcs.OfPoint((xVec * -largeCoordinateValue) + (yVec * largeCoordinateValue) + origin)
            };

            IList <CurveLoop> loops = new List <CurveLoop>();
            CurveLoop         loop  = new CurveLoop();

            for (int ii = 0; ii < 4; ii++)
            {
                if (AgreementFlag)
                {
                    loop.Append(Line.CreateBound(corners[(5 - ii) % 4], corners[(4 - ii) % 4]));
                }
                else
                {
                    loop.Append(Line.CreateBound(corners[ii], corners[(ii + 1) % 4]));
                }
            }
            loops.Add(loop);

            XYZ          normal       = unscaledLcs.OfVector(AgreementFlag ? -plane.Normal : plane.Normal);
            SolidOptions solidOptions = new SolidOptions(GetMaterialElementId(shapeEditScope), shapeEditScope.GraphicsStyleId);
            Solid        baseSolid    = GeometryCreationUtilities.CreateExtrusionGeometry(loops, normal, largeCoordinateValue, solidOptions);

            if (BaseBoundingCurve != null)
            {
                CurveLoop polygonalBoundary = BaseBoundingCurve.CurveLoop;

                Transform unscaledTotalTransform = unscaledLcs.Multiply(BaseBoundingCurveTransform);
                Transform scaledTotalTransform   = scaledLcs.Multiply(BaseBoundingCurveTransform);

                // Make sure this bounding polygon extends below base of half-space soild.
                Transform moveBaseTransform = Transform.Identity;
                moveBaseTransform.Origin = new XYZ(0, 0, -largeCoordinateValue);

                unscaledTotalTransform = unscaledTotalTransform.Multiply(moveBaseTransform);
                scaledTotalTransform   = scaledTotalTransform.Multiply(moveBaseTransform);

                CurveLoop         transformedPolygonalBoundary = IFCGeometryUtil.CreateTransformed(polygonalBoundary, Id, unscaledTotalTransform, scaledTotalTransform);
                IList <CurveLoop> boundingLoops = new List <CurveLoop>();
                boundingLoops.Add(transformedPolygonalBoundary);

                Solid boundingSolid = GeometryCreationUtilities.CreateExtrusionGeometry(boundingLoops, unscaledTotalTransform.BasisZ, 2.0 * largeCoordinateValue,
                                                                                        solidOptions);
                baseSolid = IFCGeometryUtil.ExecuteSafeBooleanOperation(Id, BaseBoundingCurve.Id, baseSolid, boundingSolid, BooleanOperationsType.Intersect, null);
            }

            IList <GeometryObject> returnList = new List <GeometryObject>();

            returnList.Add(baseSolid);
            return(returnList);
        }
Пример #51
0
        protected virtual void CanvasRaycast(Ray ray, PointerEventData eventData)
        {
            float         distance              = 0;
            float         closestDistance       = physicsHitDistance;
            RectTransform closestCanvasRect     = null;
            Plane         closestCanvasPlane    = new Plane();
            Vector3       closestIntersectPoint = Vector3.zero;

            foreach (var canvas in CanvasTracker.GetCanvasSet(EventMask.value))
            {
                if (!canvas.canvas)
                {
                    continue;
                }

                Plane canvasPlane = new Plane(canvas.worldCorners[1], canvas.worldCorners[2], canvas.worldCorners[3]);

                if (ignoreReversedGraphics && !canvasPlane.GetSide(transform.position))
                {
                    continue;
                }

                if (canvasPlane.Raycast(ray, out distance))
                {
                    Vector3 intersectionPoint   = transform.position + transform.forward * distance;
                    Vector3 localIntersectPoint = canvas.canvasRect.InverseTransformPoint(intersectionPoint);

                    if (canvas.canvasRect.rect.Contains(localIntersectPoint) && distance < closestDistance)
                    {
                        closestDistance       = distance;
                        closestCanvasRect     = canvas.canvasRect;
                        closestCanvasPlane    = canvasPlane;
                        closestIntersectPoint = intersectionPoint;
                    }
                }
            }

            // We've determined the closest Canvas we're pointing at, if any. Check graphic compponents for hits.

            if (closestCanvasRect != null)
            {
                var canvas = closestCanvasRect.GetComponent <Canvas>();

                if (graphicsToAppend == null)
                {
                    graphicsToAppend = new List <Graphic>();
                }
                else
                {
                    graphicsToAppend.Clear();
                }

                graphicsToAppend = GraphicRegistry.GetGraphicsForCanvas(canvas).ToList()
                                   .Where(graphic => graphic.depth > -1 &&
                                          graphic.raycastTarget &&
                                          graphic.isActiveAndEnabled &&
                                          graphic.rectTransform.rect.Contains(graphic.transform.InverseTransformPoint(closestIntersectPoint)))
                                   .OrderByDescending(graphic => graphic.depth)
                                   .ToList();

                foreach (Graphic graphic in graphicsToAppend)
                {
                    var castResult = new RaycastResult
                    {
                        gameObject     = graphic.gameObject,
                        module         = this,
                        distance       = closestDistance,
                        screenPosition = graphic.transform.InverseTransformPoint(closestIntersectPoint),
                        index          = raycastHits.Count,
                        depth          = graphic.depth,
                        sortingLayer   = canvas.sortingLayerID,
                        sortingOrder   = canvas.sortingOrder,
                        worldPosition  = closestIntersectPoint,
                        worldNormal    = closestCanvasPlane.normal
                    };

                    raycastHits.Add(castResult);
                }
            }
        }
Пример #52
0
 override public void Load(System.IO.Stream fs, Plane sblock)
 {
     base.Load(fs, sblock);
     lodgersCount = (byte)fs.ReadByte();
 }
Пример #53
0
 private Plane PrepareBottomPlane()
 {
     bottomPlane = new Plane(this, MeshType.Quad, ResourceType.CONCRETE_ID, Block.DOWN_FACE_INDEX, 0);
     return(bottomPlane);
 }
Пример #54
0
        // Returns 'true' if the OBB intersects (or is inside) the frustum, 'false' otherwise.
        public static bool Overlap(OrientedBBox obb, Frustum frustum, int numPlanes, int numCorners)
        {
            bool overlap = true;

            // Test the OBB against frustum planes. Frustum planes are inward-facing.
            // The OBB is outside if it's entirely behind one of the frustum planes.
            // See "Real-Time Rendering", 3rd Edition, 16.10.2.
            for (int i = 0; overlap && i < numPlanes; i++)
            {
                Vector3 n = frustum.planes[i].normal;
                float   d = frustum.planes[i].distance;

                // Max projection of the half-diagonal onto the normal (always positive).
                float maxHalfDiagProj = obb.extentX * Mathf.Abs(Vector3.Dot(n, obb.right))
                                        + obb.extentY * Mathf.Abs(Vector3.Dot(n, obb.up))
                                        + obb.extentZ * Mathf.Abs(Vector3.Dot(n, obb.forward));

                // Positive distance -> center in front of the plane.
                // Negative distance -> center behind the plane (outside).
                float centerToPlaneDist = Vector3.Dot(n, obb.center) + d;

                // outside = maxHalfDiagProj < -centerToPlaneDist
                // outside = maxHalfDiagProj + centerToPlaneDist < 0
                // overlap = overlap && !outside
                overlap = overlap && (maxHalfDiagProj + centerToPlaneDist >= 0);
            }

            if (numCorners == 0)
            {
                return(overlap);
            }

            // Test the frustum corners against OBB planes. The OBB planes are outward-facing.
            // The frustum is outside if all of its corners are entirely in front of one of the OBB planes.
            // See "Correct Frustum Culling" by Inigo Quilez.
            // We can exploit the symmetry of the box by only testing against 3 planes rather than 6.
            Plane[] planes = new Plane[3];

            planes[0].normal   = obb.right;
            planes[0].distance = obb.extentX;
            planes[1].normal   = obb.up;
            planes[1].distance = obb.extentY;
            planes[2].normal   = obb.forward;
            planes[2].distance = obb.extentZ;

            for (int i = 0; overlap && i < 3; i++)
            {
                Plane plane = planes[i];

                // We need a separate counter for the "box fully inside frustum" case.
                bool outsidePos = true; // Positive normal
                bool outsideNeg = true; // Reversed normal

                // Merge 2 loops. Continue as long as all points are outside either plane.
                for (int j = 0; j < numCorners; j++)
                {
                    float proj = Vector3.Dot(plane.normal, frustum.corners[j] - obb.center);
                    outsidePos = outsidePos && (proj > plane.distance);
                    outsideNeg = outsideNeg && (-proj > plane.distance);
                }

                overlap = overlap && !(outsidePos || outsideNeg);
            }

            return(overlap);
        }
Пример #55
0
    public void Cut(Plane cutPlane)
    {
        int avoidInfCount = 0;


        Vector3 p1, p2, p3;
        bool    p1Bool, p2Bool, p3Bool;
        //カットした後の2つのオブジェクトに対応するuv,vertices, triangles, normals
        var uvs1       = new List <Vector2>();
        var uvs2       = new List <Vector2>();
        var vertices1  = new List <Vector3>();
        var vertices2  = new List <Vector3>();
        var triangles1 = new List <int>();
        var triangles2 = new List <int>();
        var normals1   = new List <Vector3>();
        var normals2   = new List <Vector3>();
        //処理中に使ういれもの
        var crossVertices = new List <Vector3>();
        int numLimit      = 3000;

        /*カットしたいオブジェクトのメッシュをトライアングルごとに処理
         */

        for (int i = 0; i < triangles.Count; i += 3)
        {
            if (bool2)
            {
                for (int k = 0; k < 3; k++)
                {
                    vertices1.Add(vertices[triangles[i + k]]);
                    triangles1.Add(vertices1.Count - 1);
                }
            }
            else
            {
                //メッシュの3つの頂点を取得
                p1 = vertices[triangles[i]];
                p2 = vertices[triangles[i + 1]];
                p3 = vertices[triangles[i + 2]];

                //頂点がカットする面のどちら側にあるか
                p1Bool = cutPlane.GetSide(p1);
                p2Bool = cutPlane.GetSide(p2);
                p3Bool = cutPlane.GetSide(p3);

                //3つの頂点が同じ側にある場合はそのまま代入、頂点がカットする場合はその処理を行う
                if (p1Bool && p2Bool && p3Bool)
                {
                    //3つの頂点が同じ側にある、そのままそれぞれの1に代入
                    for (int k = 0; k < 3; k++)
                    {
                        vertices1.Add(vertices[triangles[i + k]]);
                        triangles1.Add(vertices1.Count - 1);
                    }
                }
                else if (!p1Bool && !p2Bool && !p3Bool)
                {
                    //3つの頂点が同じ側にある、そのままそれぞれの2に代入
                    for (int k = 0; k < 3; k++)
                    {
                        vertices2.Add(vertices[triangles[i + k]]);
                        triangles2.Add(vertices2.Count - 1);
                    }
                }
                else
                {
                    //3つの頂点が同じ側にない場合の処理1、以下仲間外れの頂点をp,それ以外をcとする
                    Vector3 p, c1, c2;
                    int     n1, n2, n3;
                    if ((p1Bool && !p2Bool && !p3Bool) || (!p1Bool && p2Bool && p3Bool))
                    {
                        p  = p1;
                        c1 = p2;
                        c2 = p3;
                        n1 = 0;
                        n2 = 1;
                        n3 = 2;
                    }
                    else if ((!p1Bool && p2Bool && !p3Bool) || (p1Bool && !p2Bool && p3Bool))
                    {
                        p  = p2;
                        c1 = p3;
                        c2 = p1;
                        n1 = 1;
                        n2 = 2;
                        n3 = 0;
                    }
                    else
                    {
                        p  = p3;
                        c1 = p1;
                        c2 = p2;
                        n1 = 2;
                        n2 = 0;
                        n3 = 1;
                    }

                    //カットした面に生じる新しい頂点を計算、カットする平面の法線方向に対するpとcの距離の比からc-pの長さを決める
                    Vector3 cross1 = (p + (c1 - p) * (cutPlane.distance + Vector3.Dot(cutPlane.normal, p)) / Vector3.Dot(cutPlane.normal, p - c1));
                    Vector3 cross2 = (p + (c2 - p) * (cutPlane.distance + Vector3.Dot(cutPlane.normal, p)) / Vector3.Dot(cutPlane.normal, p - c2));


                    //断面をつくるために取っておく
                    crossVertices.Add(cross1);
                    crossVertices.Add(cross2);


                    //pの2通りの処理、カットする面に対してどちらにあるかで異なる
                    if ((p1Bool && !p2Bool && !p3Bool) || (!p1Bool && p2Bool && !p3Bool) || (!p1Bool && !p2Bool && p3Bool))
                    {
                        //p側のメッシュを追加
                        vertices1.Add(cross1);
                        triangles1.Add(vertices1.Count - 1);

                        vertices1.Add(cross2);
                        triangles1.Add(vertices1.Count - 1);

                        vertices1.Add(vertices[triangles[i + n1]]);
                        triangles1.Add(vertices1.Count - 1);

                        //c側のメッシュを追加1
                        vertices2.Add(cross2);
                        triangles2.Add(vertices2.Count - 1);

                        vertices2.Add(vertices[triangles[i + n2]]);
                        triangles2.Add(vertices2.Count - 1);

                        vertices2.Add(vertices[triangles[i + n3]]);
                        triangles2.Add(vertices2.Count - 1);

                        //c側のメッシュを追加2
                        vertices2.Add(cross2);
                        triangles2.Add(vertices2.Count - 1);

                        vertices2.Add(cross1);
                        triangles2.Add(vertices2.Count - 1);

                        vertices2.Add(vertices[triangles[i + n2]]);
                        triangles2.Add(vertices2.Count - 1);
                    }
                    else
                    {
                        //p側のメッシュを追加
                        vertices2.Add(cross1);
                        triangles2.Add(vertices2.Count - 1);

                        vertices2.Add(cross2);
                        triangles2.Add(vertices2.Count - 1);

                        vertices2.Add(vertices[triangles[i + n1]]);
                        triangles2.Add(vertices2.Count - 1);

                        //c側のメッシュを追加1
                        vertices1.Add(cross2);
                        triangles1.Add(vertices1.Count - 1);

                        vertices1.Add(vertices[triangles[i + n2]]);
                        triangles1.Add(vertices1.Count - 1);

                        vertices1.Add(vertices[triangles[i + n3]]);
                        triangles1.Add(vertices1.Count - 1);

                        //c側のメッシュを追加2
                        vertices1.Add(cross2);
                        triangles1.Add(vertices1.Count - 1);

                        vertices1.Add(cross1);
                        triangles1.Add(vertices1.Count - 1);

                        vertices1.Add(vertices[triangles[i + n2]]);
                        triangles1.Add(vertices1.Count - 1);
                    }
                }
            }
        }
        for (int i = 0; i < crossVertices.Count; i++)
        {
            Instantiate(point, crossVertices[i], Quaternion.identity);
        }


        var verticeIndices = new List <int>();
        var pVertices      = new List <Vector3>();
        var pNormals       = new List <Vector3>();
        var pUvs           = new List <Vector2>();

        //Debug.Log ("-------");
        int numCur = 10;

        Debug.Log(triangles1.Count);

        for (int i = 0; i < vertices1.Count; i += 3)
        {
            uvs1.Add(new Vector2(0, 0));
            uvs1.Add(new Vector2(0, 1));
            uvs1.Add(new Vector2(1, 0));
            normals1.Add(new Vector3(0, 0, -1).normalized);
            normals1.Add(new Vector3(0, 0, -1).normalized);
            normals1.Add(new Vector3(0, 0, -1).normalized);
        }

        for (int i = 0; i < vertices2.Count; i += 3)
        {
            uvs2.Add(new Vector2(0, 0));
            uvs2.Add(new Vector2(0, 1));
            uvs2.Add(new Vector2(1, 0));
            normals2.Add(new Vector3(0, 0, -1).normalized);
            normals2.Add(new Vector3(0, 0, -1).normalized);
            normals2.Add(new Vector3(0, 0, -1).normalized);
        }


        if (bool1)
        {
            for (int i = 0; i < vertices1.Count; i += 3)
            {
                verticeIndices.Clear();
                verticeIndices.Add(i);
                Debug.Log("---------------------------------");
                for (int j = i + 3; j < vertices1.Count; j += 3)
                {
                    //同一の平面上にある三角形かどうか。数値計算のためdeltaで誤差を考慮する
                    //	Debug.Log(Vector3.Dot (Vector3.Cross (vertices1 [i + 1] - vertices1 [i], vertices1 [i + 1] - vertices1 [i + 2]).normalized, Vector3.Cross (vertices1 [j + 1] - vertices1 [j], vertices1 [j + 1] - vertices1 [j + 2]).normalized));
                    //	Debug.Log(Vector3.Dot (Vector3.Cross (vertices1 [i + 1] - vertices1 [i], vertices1 [i +2] - vertices1 [i + 1]).normalized, Vector3.Cross (vertices1 [j + 1] - vertices1 [j], vertices1 [j + 2] - vertices1 [j + 1]).normalized));
                    //if (Vector3.Dot (Vector3.Cross ((10^numCur)*vertices1 [i + 1] - (10^numCur)*vertices1 [i],  (10^numCur)*vertices1 [i + 2]-(10^numCur)*vertices1 [i + 1]).normalized, Vector3.Cross ((10^numCur)*vertices1 [j + 1] - (10^numCur)*vertices1 [j],  (10^numCur)*vertices1 [j + 2]-(10^numCur)*vertices1 [j + 1] ).normalized)>1-delta2) {
                    //if (Vector3.Dot (Vector3.Cross (vertices1 [i + 1] - vertices1 [i], vertices1 [i +2] - vertices1 [i + 1]).normalized, Vector3.Cross (vertices1 [j + 1] - vertices1 [j], vertices1 [j + 2] - vertices1 [j + 1]).normalized)>1-delta2) {
                    if (Vector3.Dot(Vector3.Cross((numCur) * vertices1[i + 1] - (numCur) * vertices1[i], (numCur) * vertices1[i + 2] - (numCur) * vertices1[i + 1]).normalized, Vector3.Cross((numCur) * vertices1[j + 1] - (numCur) * vertices1[j], (numCur) * vertices1[j + 2] - (numCur) * vertices1[j + 1]).normalized) > 1 - delta2)
                    {
                        verticeIndices.Add(j);
                    }
                    if (j == vertices1.Count - 3)
                    {
                        Debug.Log("onSamePlane");
                        Debug.Log(verticeIndices.Count);
                        if (verticeIndices.Count > 1)
                        {
                            //三角形から直線を3つずつ追加
                            for (int k = 0; k < verticeIndices.Count; k++)
                            {
                                for (int l = 0; l < 3; l++)
                                {
                                    pVertices.Add(vertices1[verticeIndices[k] + l]);
                                    pNormals.Add(normals1[verticeIndices[k] + l]);
                                    pUvs.Add(uvs1[verticeIndices[k] + l]);

                                    pVertices.Add(vertices1[verticeIndices[k] + numRep(l + 1)]);
                                    pNormals.Add(normals1[verticeIndices[k] + numRep(l + 1)]);
                                    pUvs.Add(uvs1[verticeIndices[k] + numRep(l + 1)]);
                                }
                            }
                        }
                        //一致する直線(図形の外側に位置しない直線)を消去

                        for (int k = 0; k < pVertices.Count; k += 2)
                        {
                            for (int l = k + 2; l < pVertices.Count; l += 2)
                            {
                                if (((pVertices[l + 1] - pVertices[k]).magnitude < delta) && ((pVertices[l] - pVertices[k + 1]).magnitude < delta))
                                {
                                    pVertices.RemoveRange(l, 2);
                                    pVertices.RemoveRange(k, 2);
                                    pNormals.RemoveRange(l, 2);
                                    pNormals.RemoveRange(k, 2);
                                    pUvs.RemoveRange(l, 2);
                                    pUvs.RemoveRange(k, 2);
                                    k -= 2;

                                    Debug.Log("一致する直線を消去");

                                    avoidInfCount++;
                                    if (avoidInfCount > numLimit)
                                    {
                                        Debug.Log("error1");
                                        return;//kyousei
                                    }
                                    break;
                                }
                            }
                        }



                        for (int l = 0; l < pVertices.Count; l += 2)
                        {
                            for (int k = l + 2; k < pVertices.Count; k += 2)
                            {
                                //4つの頂点が一直線上にあるか
                                if (Vector3.Dot(((numCur) * pVertices[l] - (numCur) * pVertices[l + 1]).normalized, ((numCur) * pVertices[k] - (numCur) * pVertices[k + 1]).normalized) > 1 - delta2)
                                {
                                    //以下重なる点に応じた処理
                                    if ((pVertices[l + 1] - pVertices[k]).magnitude < delta)
                                    {
                                        //Debug.Log ("1done");

                                        pVertices.Add(pVertices[l]);
                                        pVertices.Add(pVertices[k + 1]);
                                        pNormals.Add(pNormals[l]);
                                        pNormals.Add(pNormals[k + 1]);
                                        pUvs.Add(pUvs[l]);
                                        pUvs.Add(pUvs[k + 1]);

                                        pVertices.RemoveRange(k, 2);
                                        pVertices.RemoveRange(l, 2);
                                        pNormals.RemoveRange(k, 2);
                                        pNormals.RemoveRange(l, 2);
                                        pUvs.RemoveRange(k, 2);
                                        pUvs.RemoveRange(l, 2);

                                        l -= 2;
                                        avoidInfCount++;
                                        if (avoidInfCount > numLimit)
                                        {
                                            Debug.Log("error2");
                                            return;//kyousei
                                        }
                                        break;
                                    }
                                    else if ((pVertices[l] - pVertices[k + 1]).magnitude < delta)
                                    {
                                        //	Debug.Log ("2done");
                                        pVertices.Add(pVertices[k]);
                                        pVertices.Add(pVertices[l + 1]);
                                        pNormals.Add(pNormals[k]);
                                        pNormals.Add(pNormals[l + 1]);
                                        pUvs.Add(pUvs[k]);
                                        pUvs.Add(pUvs[l + 1]);
                                        pVertices.RemoveRange(k, 2);
                                        pVertices.RemoveRange(l, 2);
                                        pNormals.RemoveRange(k, 2);
                                        pNormals.RemoveRange(l, 2);
                                        pUvs.RemoveRange(k, 2);
                                        pUvs.RemoveRange(l, 2);

                                        avoidInfCount++;
                                        if (avoidInfCount > numLimit)
                                        {
                                            Debug.Log("error3");
                                            return;//kyousei
                                        }
                                        l -= 2;
                                        break;
                                    }
                                    else if ((pVertices[l + 1] - pVertices[k + 1]).magnitude < delta)
                                    {
                                        //	Debug.Log ("3done");
                                        pVertices.Add(pVertices[l]);
                                        pVertices.Add(pVertices[k]);
                                        pNormals.Add(pNormals[l]);
                                        pNormals.Add(pNormals[k]);
                                        pUvs.Add(pUvs[l]);
                                        pUvs.Add(pUvs[k]);
                                        pVertices.RemoveRange(k, 2);
                                        pVertices.RemoveRange(l, 2);
                                        pNormals.RemoveRange(k, 2);
                                        pNormals.RemoveRange(l, 2);
                                        pUvs.RemoveRange(k, 2);
                                        pUvs.RemoveRange(l, 2);

                                        avoidInfCount++;
                                        if (avoidInfCount > numLimit)
                                        {
                                            Debug.Log("error4");
                                            return;//kyousei
                                        }
                                        l -= 2;
                                        break;
                                    }
                                    else if ((pVertices[l] - pVertices[k]).magnitude < delta)
                                    {
                                        //		Debug.Log ("4done");
                                        pVertices.Add(pVertices[k + 1]);
                                        pVertices.Add(pVertices[l + 1]);
                                        pNormals.Add(pNormals[k + 1]);
                                        pNormals.Add(pNormals[l + 1]);
                                        pUvs.Add(pUvs[k + 1]);
                                        pUvs.Add(pUvs[l + 1]);
                                        pVertices.RemoveRange(k, 2);
                                        pVertices.RemoveRange(l, 2);
                                        pNormals.RemoveRange(k, 2);
                                        pNormals.RemoveRange(l, 2);
                                        pUvs.RemoveRange(k, 2);
                                        pUvs.RemoveRange(l, 2);
                                        l -= 2;
                                        avoidInfCount++;
                                        if (avoidInfCount > numLimit)
                                        {
                                            Debug.Log("error5");
                                            return;//kyousei
                                        }
                                        break;
                                    }
                                }
                            }
                        }



                        //重なる点を消去
                        for (int k = 0; k < pVertices.Count; k++)
                        {
                            for (int l = k + 1; l < pVertices.Count; l++)
                            {
                                if ((pVertices[k] - pVertices[l]).magnitude < delta)
                                {
                                    pVertices.RemoveAt(l);
                                    pNormals.RemoveAt(l);
                                    pUvs.RemoveAt(l);
                                    avoidInfCount++;
                                    if (avoidInfCount > numLimit)
                                    {
                                        Debug.Log("errorD2");
                                        return;//kyousei
                                    }
                                }
                            }
                        }

                        //並べ替え
                        for (int k = 2; k < pVertices.Count; k++)
                        {
                            for (int l = k + 1; l < pVertices.Count; l++)
                            {
                                if (System.Math.Acos(Vector3.Dot((pVertices[0] - pVertices[1]).normalized, (pVertices[0] - pVertices[k]).normalized)) >= System.Math.Acos(Vector3.Dot((pVertices[0] - pVertices[1]).normalized, (pVertices[0] - pVertices[l]).normalized)))
                                {
                                    if (System.Math.Acos(Vector3.Dot((pVertices[0] - pVertices[1]).normalized, (pVertices[0] - pVertices[k]).normalized)) == System.Math.Acos(Vector3.Dot((pVertices[0] - pVertices[1]).normalized, (pVertices[0] - pVertices[l]).normalized)))
                                    {
                                        if ((pVertices[0] - pVertices[k]).magnitude > (pVertices[0] - pVertices[l]).magnitude)
                                        {
                                            pVertices.Insert(0, pVertices[l]);
                                            pVertices.RemoveAt(l + 1);
                                            pNormals.Insert(0, pNormals[l]);
                                            pNormals.RemoveAt(l + 1);
                                            pUvs.Insert(0, pUvs[l]);
                                            pUvs.RemoveAt(l + 1);
                                        }
                                        else
                                        {
                                            pVertices.Insert(0, pVertices[k]);
                                            pVertices.RemoveAt(k + 1);
                                            pNormals.Insert(0, pNormals[k]);
                                            pNormals.RemoveAt(k + 1);
                                            pUvs.Insert(0, pUvs[k]);
                                            pUvs.RemoveAt(k + 1);
                                        }

                                        avoidInfCount++;
                                        if (avoidInfCount > numLimit)
                                        {
                                            Debug.Log("error6-1-1");
                                            avoidInfCount = 0;
                                            return;//kyousei
                                        }
                                        k = 1;
                                        break;
                                    }

                                    pVertices.Insert(k, pVertices[l]);
                                    pVertices.RemoveAt(l + 1);
                                    pNormals.Insert(k, pNormals[l]);
                                    pNormals.RemoveAt(l + 1);
                                    pUvs.Insert(k, pUvs[l]);
                                    pUvs.RemoveAt(l + 1);
                                    avoidInfCount++;
                                    if (avoidInfCount > numLimit)
                                    {
                                        Debug.Log("error6-1-2");
                                        avoidInfCount = 0;
                                        return;//kyousei
                                    }

                                    k = 1;

                                    break;
                                }
                            }
                        }
                        Debug.Log("	pVertices.Count");
                        Debug.Log(pVertices.Count);
                        //三角形形成
                        for (int k = 1; k < pVertices.Count - 1; k++)
                        {
                            vertices1.Insert(0, pVertices[0]);
                            normals1.Insert(0, pNormals[0]);
                            uvs1.Insert(0, pUvs[0]);
                            triangles1.Insert(0, (pVertices.Count - 2) * 3 - (3 * k));

                            vertices1.Insert(1, pVertices[k]);
                            normals1.Insert(1, pNormals[k]);
                            uvs1.Insert(1, pUvs[k]);
                            triangles1.Insert(1, (pVertices.Count - 2) * 3 - (3 * k - 1));

                            vertices1.Insert(2, pVertices[k + 1]);
                            normals1.Insert(2, pNormals[k + 1]);
                            uvs1.Insert(2, pUvs[k + 1]);
                            triangles1.Insert(2, (pVertices.Count - 2) * 3 - (3 * k - 2));

                            avoidInfCount++;
                            if (avoidInfCount > numLimit)
                            {
                                Debug.Log("errorD3");
                                return;//kyousei
                            }
                        }
                        //	古い三角形を消す
                        for (int k = verticeIndices.Count - 1; k >= 0; k--)
                        {
                            vertices1.RemoveRange(verticeIndices[k] + 3 * (pVertices.Count - 2), 3);
                            normals1.RemoveRange(verticeIndices[k] + 3 * (pVertices.Count - 2), 3);
                            uvs1.RemoveRange(verticeIndices[k] + 3 * (pVertices.Count - 2), 3);
                            triangles1.RemoveRange(verticeIndices[k] + 3 * (pVertices.Count - 2), 3);
                            avoidInfCount++;
                            if (avoidInfCount > numLimit)
                            {
                                Debug.Log("errorD4");
                                return;//kyousei
                            }
                        }

                        for (int k = 0; k < triangles1.Count; k++)
                        {
                            triangles1[k] = k;
                            //Debug.Log (triangles1 [k]);
                        }

                        pVertices.Clear();
                        pNormals.Clear();
                        pUvs.Clear();
                        i = vertices1.Count;
                        break;
                    }
                }
            }


            for (int i = 0; i < vertices2.Count; i += 3)
            {
                verticeIndices.Clear();
                verticeIndices.Add(i);
                Debug.Log("---------------------------------");
                for (int j = i + 3; j < vertices2.Count; j += 3)
                {
                    //同一の平面上にある三角形かどうか。数値計算のためdeltaで誤差を考慮する
                    //	Debug.Log(Vector3.Dot (Vector3.Cross (vertices2 [i + 1] - vertices2 [i], vertices2 [i + 1] - vertices2 [i + 2]).normalized, Vector3.Cross (vertices2 [j + 1] - vertices2 [j], vertices2 [j + 1] - vertices2 [j + 2]).normalized));
                    //	Debug.Log(Vector3.Dot (Vector3.Cross (vertices2 [i + 1] - vertices2 [i], vertices2 [i +2] - vertices2 [i + 1]).normalized, Vector3.Cross (vertices2 [j + 1] - vertices2 [j], vertices2 [j + 2] - vertices2 [j + 1]).normalized));
                    //if (Vector3.Dot (Vector3.Cross ((10^numCur)*vertices2 [i + 1] - (10^numCur)*vertices2 [i],  (10^numCur)*vertices2 [i + 2]-(10^numCur)*vertices2 [i + 1]).normalized, Vector3.Cross ((10^numCur)*vertices2 [j + 1] - (10^numCur)*vertices2 [j],  (10^numCur)*vertices2 [j + 2]-(10^numCur)*vertices2 [j + 1] ).normalized)>1-delta2) {
                    //if (Vector3.Dot (Vector3.Cross (vertices2 [i + 1] - vertices2 [i], vertices2 [i +2] - vertices2 [i + 1]).normalized, Vector3.Cross (vertices2 [j + 1] - vertices2 [j], vertices2 [j + 2] - vertices2 [j + 1]).normalized)>1-delta2) {
                    if (Vector3.Dot(Vector3.Cross((numCur) * vertices2[i + 1] - (numCur) * vertices2[i], (numCur) * vertices2[i + 2] - (numCur) * vertices2[i + 1]).normalized, Vector3.Cross((numCur) * vertices2[j + 1] - (numCur) * vertices2[j], (numCur) * vertices2[j + 2] - (numCur) * vertices2[j + 1]).normalized) > 1 - delta2)
                    {
                        verticeIndices.Add(j);
                    }
                    if (j == vertices2.Count - 3)
                    {
                        Debug.Log("onSamePlane");
                        Debug.Log(verticeIndices.Count);
                        if (verticeIndices.Count > 1)
                        {
                            //三角形から直線を3つずつ追加
                            for (int k = 0; k < verticeIndices.Count; k++)
                            {
                                for (int l = 0; l < 3; l++)
                                {
                                    pVertices.Add(vertices2[verticeIndices[k] + l]);
                                    pNormals.Add(normals2[verticeIndices[k] + l]);
                                    pUvs.Add(uvs2[verticeIndices[k] + l]);

                                    pVertices.Add(vertices2[verticeIndices[k] + numRep(l + 1)]);
                                    pNormals.Add(normals2[verticeIndices[k] + numRep(l + 1)]);
                                    pUvs.Add(uvs2[verticeIndices[k] + numRep(l + 1)]);
                                }
                            }
                        }
                        //一致する直線(図形の外側に位置しない直線)を消去

                        for (int k = 0; k < pVertices.Count; k += 2)
                        {
                            for (int l = k + 2; l < pVertices.Count; l += 2)
                            {
                                if (((pVertices[l + 1] - pVertices[k]).magnitude < delta) && ((pVertices[l] - pVertices[k + 1]).magnitude < delta))
                                {
                                    pVertices.RemoveRange(l, 2);
                                    pVertices.RemoveRange(k, 2);
                                    pNormals.RemoveRange(l, 2);
                                    pNormals.RemoveRange(k, 2);
                                    pUvs.RemoveRange(l, 2);
                                    pUvs.RemoveRange(k, 2);
                                    k -= 2;

                                    Debug.Log("一致する直線を消去");

                                    avoidInfCount++;
                                    if (avoidInfCount > numLimit)
                                    {
                                        Debug.Log("error1");
                                        return;//kyousei
                                    }
                                    break;
                                }
                            }
                        }



                        for (int l = 0; l < pVertices.Count; l += 2)
                        {
                            for (int k = l + 2; k < pVertices.Count; k += 2)
                            {
                                //4つの頂点が一直線上にあるか
                                if (Vector3.Dot(((numCur) * pVertices[l] - (numCur) * pVertices[l + 1]).normalized, ((numCur) * pVertices[k] - (numCur) * pVertices[k + 1]).normalized) > 1 - delta2)
                                {
                                    //以下重なる点に応じた処理
                                    if ((pVertices[l + 1] - pVertices[k]).magnitude < delta)
                                    {
                                        //Debug.Log ("1done");

                                        pVertices.Add(pVertices[l]);
                                        pVertices.Add(pVertices[k + 1]);
                                        pNormals.Add(pNormals[l]);
                                        pNormals.Add(pNormals[k + 1]);
                                        pUvs.Add(pUvs[l]);
                                        pUvs.Add(pUvs[k + 1]);

                                        pVertices.RemoveRange(k, 2);
                                        pVertices.RemoveRange(l, 2);
                                        pNormals.RemoveRange(k, 2);
                                        pNormals.RemoveRange(l, 2);
                                        pUvs.RemoveRange(k, 2);
                                        pUvs.RemoveRange(l, 2);

                                        l -= 2;
                                        avoidInfCount++;
                                        if (avoidInfCount > numLimit)
                                        {
                                            Debug.Log("error2");
                                            return;//kyousei
                                        }
                                        break;
                                    }
                                    else if ((pVertices[l] - pVertices[k + 1]).magnitude < delta)
                                    {
                                        //	Debug.Log ("2done");
                                        pVertices.Add(pVertices[k]);
                                        pVertices.Add(pVertices[l + 1]);
                                        pNormals.Add(pNormals[k]);
                                        pNormals.Add(pNormals[l + 1]);
                                        pUvs.Add(pUvs[k]);
                                        pUvs.Add(pUvs[l + 1]);
                                        pVertices.RemoveRange(k, 2);
                                        pVertices.RemoveRange(l, 2);
                                        pNormals.RemoveRange(k, 2);
                                        pNormals.RemoveRange(l, 2);
                                        pUvs.RemoveRange(k, 2);
                                        pUvs.RemoveRange(l, 2);

                                        avoidInfCount++;
                                        if (avoidInfCount > numLimit)
                                        {
                                            Debug.Log("error3");
                                            return;//kyousei
                                        }
                                        l -= 2;
                                        break;
                                    }
                                    else if ((pVertices[l + 1] - pVertices[k + 1]).magnitude < delta)
                                    {
                                        //	Debug.Log ("3done");
                                        pVertices.Add(pVertices[l]);
                                        pVertices.Add(pVertices[k]);
                                        pNormals.Add(pNormals[l]);
                                        pNormals.Add(pNormals[k]);
                                        pUvs.Add(pUvs[l]);
                                        pUvs.Add(pUvs[k]);
                                        pVertices.RemoveRange(k, 2);
                                        pVertices.RemoveRange(l, 2);
                                        pNormals.RemoveRange(k, 2);
                                        pNormals.RemoveRange(l, 2);
                                        pUvs.RemoveRange(k, 2);
                                        pUvs.RemoveRange(l, 2);

                                        avoidInfCount++;
                                        if (avoidInfCount > numLimit)
                                        {
                                            Debug.Log("error4");
                                            return;//kyousei
                                        }
                                        l -= 2;
                                        break;
                                    }
                                    else if ((pVertices[l] - pVertices[k]).magnitude < delta)
                                    {
                                        //		Debug.Log ("4done");
                                        pVertices.Add(pVertices[k + 1]);
                                        pVertices.Add(pVertices[l + 1]);
                                        pNormals.Add(pNormals[k + 1]);
                                        pNormals.Add(pNormals[l + 1]);
                                        pUvs.Add(pUvs[k + 1]);
                                        pUvs.Add(pUvs[l + 1]);
                                        pVertices.RemoveRange(k, 2);
                                        pVertices.RemoveRange(l, 2);
                                        pNormals.RemoveRange(k, 2);
                                        pNormals.RemoveRange(l, 2);
                                        pUvs.RemoveRange(k, 2);
                                        pUvs.RemoveRange(l, 2);
                                        l -= 2;
                                        avoidInfCount++;
                                        if (avoidInfCount > numLimit)
                                        {
                                            Debug.Log("error5");
                                            return;//kyousei
                                        }
                                        break;
                                    }
                                }
                            }
                        }



                        //重なる点を消去
                        for (int k = 0; k < pVertices.Count; k++)
                        {
                            for (int l = k + 1; l < pVertices.Count; l++)
                            {
                                if ((pVertices[k] - pVertices[l]).magnitude < delta)
                                {
                                    pVertices.RemoveAt(l);
                                    pNormals.RemoveAt(l);
                                    pUvs.RemoveAt(l);
                                    avoidInfCount++;
                                    if (avoidInfCount > numLimit)
                                    {
                                        Debug.Log("errorD2");
                                        return;//kyousei
                                    }
                                }
                            }
                        }

                        //並べ替え
                        for (int k = 2; k < pVertices.Count; k++)
                        {
                            for (int l = k + 1; l < pVertices.Count; l++)
                            {
                                if (System.Math.Acos(Vector3.Dot((pVertices[0] - pVertices[1]).normalized, (pVertices[0] - pVertices[k]).normalized)) >= System.Math.Acos(Vector3.Dot((pVertices[0] - pVertices[1]).normalized, (pVertices[0] - pVertices[l]).normalized)))
                                {
                                    if (System.Math.Acos(Vector3.Dot((pVertices[0] - pVertices[1]).normalized, (pVertices[0] - pVertices[k]).normalized)) == System.Math.Acos(Vector3.Dot((pVertices[0] - pVertices[1]).normalized, (pVertices[0] - pVertices[l]).normalized)))
                                    {
                                        if ((pVertices[0] - pVertices[k]).magnitude > (pVertices[0] - pVertices[l]).magnitude)
                                        {
                                            pVertices.Insert(0, pVertices[l]);
                                            pVertices.RemoveAt(l + 1);
                                            pNormals.Insert(0, pNormals[l]);
                                            pNormals.RemoveAt(l + 1);
                                            pUvs.Insert(0, pUvs[l]);
                                            pUvs.RemoveAt(l + 1);
                                        }
                                        else
                                        {
                                            pVertices.Insert(0, pVertices[k]);
                                            pVertices.RemoveAt(k + 1);
                                            pNormals.Insert(0, pNormals[k]);
                                            pNormals.RemoveAt(k + 1);
                                            pUvs.Insert(0, pUvs[k]);
                                            pUvs.RemoveAt(k + 1);
                                        }

                                        avoidInfCount++;
                                        if (avoidInfCount > numLimit)
                                        {
                                            Debug.Log("error6-1-1");
                                            avoidInfCount = 0;
                                            return;//kyousei
                                        }
                                        k = 1;
                                        break;
                                    }

                                    pVertices.Insert(k, pVertices[l]);
                                    pVertices.RemoveAt(l + 1);
                                    pNormals.Insert(k, pNormals[l]);
                                    pNormals.RemoveAt(l + 1);
                                    pUvs.Insert(k, pUvs[l]);
                                    pUvs.RemoveAt(l + 1);
                                    avoidInfCount++;
                                    if (avoidInfCount > numLimit)
                                    {
                                        Debug.Log("error6-1-2");
                                        avoidInfCount = 0;
                                        return;//kyousei
                                    }

                                    k = 1;

                                    break;
                                }
                            }
                        }
                        Debug.Log("	pVertices.Count");
                        Debug.Log(pVertices.Count);
                        //三角形形成
                        for (int k = 1; k < pVertices.Count - 1; k++)
                        {
                            vertices2.Insert(0, pVertices[0]);
                            normals2.Insert(0, pNormals[0]);
                            uvs2.Insert(0, pUvs[0]);
                            triangles2.Insert(0, (pVertices.Count - 2) * 3 - (3 * k));

                            vertices2.Insert(1, pVertices[k]);
                            normals2.Insert(1, pNormals[k]);
                            uvs2.Insert(1, pUvs[k]);
                            triangles2.Insert(1, (pVertices.Count - 2) * 3 - (3 * k - 1));

                            vertices2.Insert(2, pVertices[k + 1]);
                            normals2.Insert(2, pNormals[k + 1]);
                            uvs2.Insert(2, pUvs[k + 1]);
                            triangles2.Insert(2, (pVertices.Count - 2) * 3 - (3 * k - 2));

                            avoidInfCount++;
                            if (avoidInfCount > numLimit)
                            {
                                Debug.Log("errorD3");
                                return;//kyousei
                            }
                        }
                        //	古い三角形を消す
                        for (int k = verticeIndices.Count - 1; k >= 0; k--)
                        {
                            vertices2.RemoveRange(verticeIndices[k] + 3 * (pVertices.Count - 2), 3);
                            normals2.RemoveRange(verticeIndices[k] + 3 * (pVertices.Count - 2), 3);
                            uvs2.RemoveRange(verticeIndices[k] + 3 * (pVertices.Count - 2), 3);
                            triangles2.RemoveRange(verticeIndices[k] + 3 * (pVertices.Count - 2), 3);
                            avoidInfCount++;
                            if (avoidInfCount > numLimit)
                            {
                                Debug.Log("errorD4");
                                return;//kyousei
                            }
                        }

                        for (int k = 0; k < triangles2.Count; k++)
                        {
                            triangles2[k] = k;
                            //Debug.Log (triangles2 [k]);
                        }

                        pVertices.Clear();
                        pNormals.Clear();
                        pUvs.Clear();
                        i = vertices2.Count;
                        break;
                    }
                }
            }
        }



        uvs1.Clear();
        uvs2.Clear();

        for (int i = 0; i < vertices1.Count; i += 3)
        {
            uvs1.Add(new Vector2(0, 0));
            uvs1.Add(new Vector2(0, 1));
            uvs1.Add(new Vector2(1, 0));
        }

        for (int i = 0; i < vertices2.Count; i += 3)
        {
            uvs2.Add(new Vector2(0, 0));
            uvs2.Add(new Vector2(0, 1));
            uvs2.Add(new Vector2(1, 0));
        }



        GameObject obj  = new GameObject("cut obj", typeof(MeshFilter), typeof(MeshRenderer));
        var        mesh = new Mesh();

        mesh.vertices  = vertices1.ToArray();
        mesh.triangles = triangles1.ToArray();
        mesh.uv        = uvs1.ToArray();
        mesh.normals   = normals1.ToArray();
        obj.GetComponent <MeshFilter>().mesh        = mesh;
        obj.GetComponent <MeshRenderer>().materials = GetComponent <MeshRenderer>().materials;
        obj.tag = "obj";

        GameObject obj2  = new GameObject("cut obj", typeof(MeshFilter), typeof(MeshRenderer));
        var        mesh2 = new Mesh();

        mesh2.vertices  = vertices2.ToArray();
        mesh2.triangles = triangles2.ToArray();
        mesh2.uv        = uvs2.ToArray();
        mesh2.normals   = normals2.ToArray();
        obj2.GetComponent <MeshFilter>().mesh        = mesh2;
        obj2.GetComponent <MeshRenderer>().materials = GetComponent <MeshRenderer>().materials;
        obj2.tag = "obj";
        // obj.transform.position = transform.position;
        // obj.transform.rotation = transform.rotation;
        // obj.transform.localScale = transform.localScale;
        // //	obj.GetComponent<MeshCut>().Start();

        // GameObject obj2 = new GameObject ("cut obj", typeof(MeshFilter), typeof(MeshRenderer), typeof(MeshCollider), typeof(Rigidbody), typeof(MeshCut));

        // var mesh2 = new Mesh ();
        // mesh2.vertices = vertices2.ToArray ();
        // mesh2.triangles = triangles2.ToArray ();
        // mesh2.uv = uvs2.ToArray ();
        // mesh2.normals = normals2.ToArray ();
        // obj2.GetComponent<MeshFilter> ().mesh = mesh2;
        // obj2.GetComponent<MeshRenderer> ().materials = GetComponent<MeshRenderer> ().materials;
        // obj2.GetComponent<MeshCollider> ().sharedMesh = mesh2;
        // obj2.GetComponent<MeshCollider> ().inflateMesh = true;
        // obj2.GetComponent<MeshCollider> ().skinWidth = skinWidth;
        // obj2.GetComponent<MeshCollider> ().convex = true;
        // obj2.GetComponent<MeshCollider> ().material = GetComponent<Collider> ().material;
        // obj2.transform.position = transform.position;
        // obj2.transform.rotation = transform.rotation;
        // obj2.transform.localScale = transform.localScale;
        // obj2.GetComponent<Rigidbody> ().velocity = GetComponent<Rigidbody> ().velocity;
        // obj2.GetComponent<Rigidbody> ().angularVelocity = GetComponent<Rigidbody> ().angularVelocity;
        // obj2.GetComponent<MeshCut> ().skinWidth = skinWidth;
        // obj2.tag = "obj";
        // //	obj2.GetComponent<MeshCut>().Start();

        //Destroy (gameObject);
    }
Пример #56
0
        /// <summary>
        /// Determines if the Tagalong needs to move based on the provided
        /// position.
        /// </summary>
        /// <param name="fromPosition">Where the Tagalong is.</param>
        /// <param name="toPosition">Where the Tagalong needs to go.</param>
        /// <returns>True if the Tagalong needs to move to satisfy requirements; false otherwise.</returns>
        protected virtual bool CalculateTagalongTargetPosition(Vector3 fromPosition, out Vector3 toPosition)
        {
            // Check to see if any part of the Tagalong's BoxCollider's bounds is
            // inside the camera's view frustum. Note, the bounds used are an Axis
            // Aligned Bounding Box (AABB).
            bool      needsToMove     = !GeometryUtility.TestPlanesAABB(frustumPlanes, tagalongCollider.bounds);
            Transform cameraTransform = Camera.main.transform;

            // If we already know we don't need to move, bail out early.
            if (!needsToMove)
            {
                toPosition = fromPosition;
                return(false);
            }

            // Calculate a default position where the Tagalong should go. In this
            // case TagalongDistance from the camera along the gaze vector.
            toPosition = cameraTransform.position + cameraTransform.forward * TagalongDistance;

            // Create a Ray and set it's origin to be the default toPosition that
            // was calculated above.
            Ray   ray            = new Ray(toPosition, Vector3.zero);
            Plane plane          = new Plane();
            float distanceOffset = 0f;

            // Determine if the Tagalong needs to move to the right or the left
            // to get back inside the camera's view frustum. The normals of the
            // planes that make up the camera's view frustum point inward.
            bool moveRight = frustumPlanes[frustumLeft].GetDistanceToPoint(fromPosition) < 0;
            bool moveLeft  = frustumPlanes[frustumRight].GetDistanceToPoint(fromPosition) < 0;

            if (moveRight)
            {
                // If the Tagalong needs to move to the right, that means it is to
                // the left of the left frustum plane. Remember that plane and set
                // our Ray's direction to point towards that plane (remember the
                // Ray's origin is already inside the view frustum.
                plane         = frustumPlanes[frustumLeft];
                ray.direction = -cameraTransform.right;
            }
            else if (moveLeft)
            {
                // Apply similar logic to above for the case where the Tagalong
                // needs to move to the left.
                plane         = frustumPlanes[frustumRight];
                ray.direction = cameraTransform.right;
            }
            if (moveRight || moveLeft)
            {
                // If the Tagalong needed to move in the X direction, cast a Ray
                // from the default position to the plane we are working with.
                plane.Raycast(ray, out distanceOffset);

                // Get the point along that ray that is on the plane and update
                // the x component of the Tagalong's desired position.
                toPosition.x = ray.GetPoint(distanceOffset).x;
            }

            // Similar logic follows below for determining if and how the
            // Tagalong would need to move up or down.
            bool moveDown = frustumPlanes[frustumTop].GetDistanceToPoint(fromPosition) < 0;
            bool moveUp   = frustumPlanes[frustumBottom].GetDistanceToPoint(fromPosition) < 0;

            if (moveDown)
            {
                plane         = frustumPlanes[frustumTop];
                ray.direction = cameraTransform.up;
            }
            else if (moveUp)
            {
                plane         = frustumPlanes[frustumBottom];
                ray.direction = -cameraTransform.up;
            }
            if (moveUp || moveDown)
            {
                plane.Raycast(ray, out distanceOffset);
                toPosition.y = ray.GetPoint(distanceOffset).y;
            }

            // Create a ray that starts at the camera and points in the direction
            // of the calculated toPosition.
            ray = new Ray(cameraTransform.position, toPosition - cameraTransform.position);

            // Find the point along that ray that is the right distance away and
            // update the calculated toPosition to be that point.
            toPosition = ray.GetPoint(TagalongDistance);

            // If we got here, needsToMove will be true.
            return(needsToMove);
        }
Пример #57
0
 public CirTri(Plane basePlane, double r, Boolean Mirr)
 {
     Radius    = r;
     BasePlane = basePlane;
     Mirror    = Mirr;
 }
 private void Awake()
 {
     groundPlane = new Plane(Vector3.up, Vector3.zero);
     parent      = GetComponent <Player>();
 }
Пример #59
0
        /***************************************************/

        public static Plane Transform(this Plane plane, TransformMatrix transform)
        {
            return(new Plane {
                Origin = plane.Origin.Transform(transform), Normal = plane.Normal.Transform(transform).Normalise()
            });
        }