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


C# Vector3.Normalize方法代码示例

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


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

示例1: GetActualSteer

    public Vector3 GetActualSteer(Vector3 desiredSteer)
    {
        Forces forces = mAttributes.Forces;
        float mag = desiredSteer.magnitude;

        if (mag < forces.MinSpeed)
        {
            desiredSteer.Normalize();
            desiredSteer *= forces.MinSpeed;
        }

        if (mag > forces.MaxSpeed)
        {
            desiredSteer.Normalize();
            desiredSteer *= forces.MaxSpeed;
        }

        float maxRateRadians = Mathf.Deg2Rad * forces.TurnRateDegrees * Time.deltaTime;

        Vector3 actualSteer = Vector3.RotateTowards(transform.forward, desiredSteer, maxRateRadians, forces.MaxSpeed);
        //transform.rotation = Quaternion.LookRotation(actualSteer, transform.up);

        {
            Vector3 desiredSteerNormalized = desiredSteer;
            desiredSteerNormalized.Normalize();
            Vector3 actualSteerNormalized = actualSteer;
            actualSteerNormalized.Normalize();

            const float factor = 50.0f;
            Debug.DrawLine(transform.position, transform.position + (desiredSteerNormalized * factor), Color.red);
            Debug.DrawLine(transform.position, transform.position + (actualSteerNormalized * factor), Color.green);
        }

        return actualSteer;
    }
开发者ID:RandomTiger,项目名称:SpaceGame1,代码行数:35,代码来源:SteeringBehaviours.cs

示例2: BallFold

 private static Vector3 BallFold(float r, Vector3 v)
 {
     float len = v.Len();
     if (len < r) return v.Normalize(len / (r * r));
     else if (len < 1) return v.Normalize(1 / len);
     return v;
 }
开发者ID:aguldstrand,项目名称:Stuff,代码行数:7,代码来源:MandelCube.cs

示例3: GetBodySegmentAngle

        /// <summary>
        /// Calculates the angle between the segments of the body defined by the specified joints.
        /// </summary>
        /// <param name="joints"></param>
        /// <param name="joint1"></param>
        /// <param name="joint2">Must be between joint1 and joint3</param>
        /// <param name="joint3"></param>
        /// <returns>The angle in degrees between the specified body segmeents.</returns>
        public double GetBodySegmentAngle(JointCollection joints)
        {
            Joint joint1 = joints[_JointId1.JointType];
            Joint joint2 = joints[_JointId2.JointType];
            Joint joint3 = joints[_JointId3.JointType];

            Vector3 vectorJoint1ToJoint2 = new Vector3(joint1.Position.X - joint2.Position.X, joint1.Position.Y - joint2.Position.Y, 0);
            Vector3 vectorJoint2ToJoint3 = new Vector3(joint2.Position.X - joint3.Position.X, joint2.Position.Y - joint3.Position.Y, 0);
            vectorJoint1ToJoint2.Normalize();
            vectorJoint2ToJoint3.Normalize();

            Vector3 crossProduct = Vector3.Cross(vectorJoint1ToJoint2, vectorJoint2ToJoint3);
            double crossProductLength = crossProduct.Z;
            double dotProduct = Vector3.Dot(vectorJoint1ToJoint2, vectorJoint2ToJoint3);
            double segmentAngle = Math.Atan2(crossProductLength, dotProduct);

            // Convert the result to degrees.
            double degrees = segmentAngle * (180 / Math.PI);

            // Add the angular offset.  Use modulo 360 to convert the value calculated above to a range
            // from 0 to 360.
            degrees = (degrees + _RotationOffset) % 360;

            // Calculate whether the coordinates should be reversed to account for different sides
            if (_ReverseCoordinates)
            {
                degrees = CalculateReverseCoordinates(degrees);
            }

            return degrees;
        }
开发者ID:khaledosman,项目名称:TVControl,代码行数:39,代码来源:SkeletonAnalyzer.cs

示例4: Reflect

	public void Reflect(Collider coll, Vector3 reflDir)
	{
		if (coll.attachedRigidbody && coll.gameObject.layer == LayerMask.NameToLayer("Bullet"))
		{
			GameObject refl = Instantiate<GameObject>(bulletPrefab);
			refl.gameObject.tag = "SpawnedBullet";
			refl.transform.position = coll.transform.position;

			Vector3 vel;
			vel = reflDir;
			vel.Normalize();

			BulletBase reflBase = refl.GetComponent<BulletBase>();
			refl.GetComponent<Rigidbody>().velocity = vel * reflBase.bulletSpeed;

			reflBase.ignoreEnemies = false;
			reflBase.rend.material = reflBase.reflectMat;

			Destroy(coll.gameObject);
		}
		else if (coll.attachedRigidbody)
		{
			Vector3 vel;
			vel = reflDir * coll.GetComponent<Rigidbody>().velocity.magnitude;
			coll.GetComponent<Rigidbody>().velocity = vel;
		}
	}
开发者ID:nessenbu2,项目名称:EECS494,代码行数:27,代码来源:DefaultReflector.cs

示例5: Move

    public void Move(float horizontal, float vertical)
    {
        if (!AIManager.staticManager.EndGame)
        {
            //velocity += new Vector3(horizontal, 0, vertical) * accel;
            /*if (Mathf.Abs(horizontal) < deadzone) horizontal = 0;
            if (Mathf.Abs(vertical) < deadzone) vertical = 0;

            if (horizontal > 3) horizontal = 3;
            if (vertical > 3) vertical = 3;*/

            velocity += new Vector3(horizontal, 0f, vertical).normalized * accel * accel;

            if (velocity.magnitude > maxVel)
            {
                velocity.Normalize();
                velocity *= maxVel;
            }

            velocity -= velocity.normalized * drag;
            if (horizontal == 0 && vertical == 0 && velocity.magnitude < drag) velocity *= 0;

            transform.position = new Vector3(transform.position.x + velocity.x * Time.deltaTime, transform.position.y, transform.position.z + velocity.z * Time.deltaTime);
            anim.SetFloat("Speed", velocity.magnitude);

            Rotate();
        }
    }
开发者ID:Appms,项目名称:OniOni,代码行数:28,代码来源:EnemyLeader.cs

示例6: Update

    // Update is called once per frame
    public override void Update()
    {
        //rotate
        transform.Rotate(0f, Input.GetAxis("Mouse X") * turnSpeed * Time.deltaTime, 0f); //turnSpeed is an absolute rotation

        //movement
        // create a new vector for move which takes input values
        move = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));

        //normalize the vector first so that it moves at a consistent speed in all directions
        move.Normalize();

        //before we call update, convert move to the direction our player is facing by using transformDirection
        //takes the local movement along x,y,z into a global movement
        move = transform.TransformDirection(move);

        //check if player wants to jump
        if (Input.GetKey(KeyCode.Space) && control.isGrounded )
        {
            jumping = true;
        }

        running = Input.GetKey(KeyCode.LeftShift);

        base.Update();
    }
开发者ID:iAmAim,项目名称:ImmunityProject,代码行数:27,代码来源:UnitPlayer.cs

示例7: Update

        public override void Update(GameTime gameTime)
        {
            Matrix collisionworld = Matrix.Identity;
            collisionworld *= tank1.world;

            if (this.CollidesWith(tank1.model, collisionworld))
            {

            }
            else
            {
                float distanceTotank1Position;
                float speed = 2;
                tankEnemyPosition = world.Translation;
                direction = tank1.world.Translation - tankEnemyPosition;
                direction.Normalize();
                Vector3 tankVelocity = speed * direction;
                distanceTotank1Position = Vector3.Distance(tank1.world.Translation, tankEnemyPosition);
                float timeTotank1Position = distanceTotank1Position / speed;
                Vector3 target = tank1.world.Translation;
                Vector3 targeDirection = target - tankEnemyPosition;
                targeDirection.Normalize();
                enemyPursueMove = targeDirection * speed;
                world *= Matrix.CreateTranslation(enemyPursueMove);
            }
        }
开发者ID:11614765,项目名称:game_week9,代码行数:26,代码来源:NPC.cs

示例8: Update

 // Update is called once per frame
 void Update()
 {
     Vector3 movement = new Vector3(Input.GetAxis ("Horizontal"), 0, 0);
     movement = movement;
     movement.Normalize();
     controller.SimpleMove(movement * speed);
 }
开发者ID:RoboCafaz,项目名称:CandyWub,代码行数:8,代码来源:PlayerInput.cs

示例9: SteeringBehaviours

        public SteeringBehaviours(Fighter entity)
        {
            this.fighter = entity;
            calculationMethod = CalculationMethods.WeightedTruncatedRunningSumWithPrioritisation;
            sphere = new Sphere(0.2f);
            XNAGame.Instance().Children.Add(sphere);
            wanderTarget = new Vector3(randomClamped(), randomClamped(), randomClamped());
            wanderTarget.Normalize();

            weights.Add(behaviour_type.allignment, 1.0f);
            weights.Add(behaviour_type.cohesion, 2.0f);
            weights.Add(behaviour_type.obstacle_avoidance, 20.0f);
            weights.Add(behaviour_type.wall_avoidance, 20.0f);
            weights.Add(behaviour_type.wander, 1.0f);
            weights.Add(behaviour_type.seek, 1.0f);
            weights.Add(behaviour_type.flee, 1.0f);
            weights.Add(behaviour_type.arrive, 1.0f);
            weights.Add(behaviour_type.pursuit, 1.0f);
            weights.Add(behaviour_type.offset_pursuit, 1.0f);
            weights.Add(behaviour_type.interpose, 1.0f);
            weights.Add(behaviour_type.hide, 1.0f);
            weights.Add(behaviour_type.evade, 0.01f);
            weights.Add(behaviour_type.follow_path, 1.0f);
            weights.Add(behaviour_type.separation, 1.0f);
        }
开发者ID:elena1905,项目名称:DoctorWho,代码行数:25,代码来源:SteeringBehavoiurs.cs

示例10: SetDirection

 // 지정한 방향으로 향한다.
 public void SetDirection(Vector3 direction)
 {
     forceRotateDirection = direction;
     forceRotateDirection.y = 0;
     forceRotateDirection.Normalize();
     forceRotate = true;
 }
开发者ID:gilbutITbook,项目名称:006762,代码行数:8,代码来源:CharacterMove.cs

示例11: Update

    // Update is called once per frame
    void Update()
    {
        // move in horizontal pane

        float x = -Input.GetAxis("Horizontal");
        float y = -Input.GetAxis("Vertical");

        Vector3 cameraMovement = new Vector3(x, 0f, y);
        cameraMovement.Normalize();
        cameraMovement *= cameraSpeed;

        transform.Translate(cameraMovement * Time.deltaTime, Space.World);

        // set height

        float cameraRotation = 0;
        float zoomChange = Input.GetAxis("Mouse ScrollWheel");
        cameraHeight += zoomChange * zoomHeightSpeed * Time.deltaTime;
        cameraRotation = zoomChange * zoomRotationSpeed * Time.deltaTime;
        cameraSpeed += zoomChange * zoomCameraAccelerationSpeed * Time.deltaTime;

        Vector3 cameraPosition = transform.position;
        cameraPosition.y = Terrain.activeTerrain.SampleHeight(transform.position) + cameraHeight;
        cameraPosition.z += zoomChange * zoomRailSpeed * Time.deltaTime;
        transform.Rotate(cameraRotation, 0, 0, Space.World);
        transform.position = cameraPosition;
    }
开发者ID:golergka,项目名称:KingOfCastles,代码行数:28,代码来源:RTSCameraController.cs

示例12: Update

    void Update()
    {
        Vector3 currentPosition = transform.position;
        time++;
        if (pauseShoot)
        {
            if (time % 50 == 0 && bullets < 5)
            {
                bullets++;
                BulletsManager.Reload(1);
            }
        }

        if (pauseShoot)
        {
            if (bullets > 0)
            {
                if (Input.GetButtonDown("Fire1"))
                {

                    Vector3 moveToward = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                    moveDirection = moveToward - currentPosition;
                    moveDirection.z = 0;
                    moveDirection.Normalize();

                    GameObject projectile = (GameObject)Instantiate(bullet[Random.Range(0,3)], firePosition.position, firePosition.rotation);
                    projectile.GetComponent<Rigidbody2D>().velocity = moveDirection * speed;
                    bullets--;
                    BulletsManager.PlayerShot(1);
                }
            }
        }
    }
开发者ID:EmperorOfQuesin,项目名称:emperor-of-quesin,代码行数:34,代码来源:Bullet.cs

示例13: FixedUpdate

    void FixedUpdate()
    {
        if(controller.levelFinished || controller.currentState == 0)
        {
            rigidbody.velocity = Vector3.zero;
            rigidbody.angularVelocity = Vector3.zero;
            return;
        }
        Vector3 direction = new Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"));
        if(direction.magnitude > 1.0) direction.Normalize();

        if(direction.magnitude > 0){

            // lets set the direction according to the camera now.
            direction = Camera.main.transform.TransformDirection(direction) * speed * 2;
            // lets take the downward velocity from the current so that we dont get wierd physics results
            direction.y = rigidbody.velocity.y;

            // Now, lets keep track of a velocity.
            // This will let the ball move while we are not pressing anything.
            rigidbody.velocity = Vector3.Lerp(rigidbody.velocity, direction, 3.0f * Time.deltaTime);
            // Now, lets break the rotation out from the movement.
            Vector3 rotation = new Vector3(rigidbody.velocity.z,0,-rigidbody.velocity.x) * 20;

            // Lets add some spin to make the ball move better
            rigidbody.angularVelocity = Vector3.Lerp(rigidbody.angularVelocity, rotation, 3.0f * Time.deltaTime);
        }
    }
开发者ID:jomaceld,项目名称:LudumDare29-Pianall,代码行数:28,代码来源:PlayerController.cs

示例14: AddForce

	void AddForce(Vector3 vector, Vector3 rotation)
	{
		vector.Normalize();
		vector.y = 1f;
		selfTf.eulerAngles = rotation;
		m_rigidbody.AddForce(vector * -1, ForceMode.VelocityChange);
	}
开发者ID:K-Yoshiki,项目名称:menko,代码行数:7,代码来源:Prototype_Menko.cs

示例15: Draw

        public override void Draw(GameTime gameTime)
        {
            RasterizerState rs = new RasterizerState();
            rs.CullMode = CullMode.None;
            device.RasterizerState = rs;

            viewMatrix = Game1.Instance.Camera.getView();
            projectionMatrix = Game1.Instance.Camera.getProjection();

            Matrix worldMatrix = Matrix.Identity;
            effect.CurrentTechnique = effect.Techniques["Colored"];
            effect.Parameters["xView"].SetValue(viewMatrix);
            effect.Parameters["xProjection"].SetValue(projectionMatrix);
            effect.Parameters["xWorld"].SetValue(worldMatrix);
            Vector3 lightDirection = new Vector3(1.0f, -1.0f, -1.0f);
            lightDirection.Normalize();
            effect.Parameters["xLightDirection"].SetValue(lightDirection);
            effect.Parameters["xAmbient"].SetValue(0.1f);
            effect.Parameters["xEnableLighting"].SetValue(true);

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                device.Indices = myIndexBuffer;
                device.SetVertexBuffer(myVertexBuffer);
                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, indices.Length / 3);
            }

            base.Draw(gameTime);
        }
开发者ID:DarrenLyne,项目名称:Game-Engine-Assignment1,代码行数:31,代码来源:MarsTerrain.cs


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