Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualmrmohadnan

Posted 14 April 2013 - 02:56 PM

hello again ! , 

I am very happy to be with experienced game developers , so I hope some one try to see the problem in my code , as the hands associated with the gun did not positoned in front of camera !!! , I tried out  a lot of ways to figure it out but ??  here is the code ????????????????????? :/ I hate this code very much !

 

           
{..
..
...
..
.
            // Update player Weapon and hands
            weaponWorldMatrix = WeaponWorldMatrix(0.45f, -0.75f, 1.65f);
            staticModel.Transform = weaponWorldMatrix;
            /*
            Vector3 forward = cameraa.ViewMatrix.Forward * new Vector3(40);
            Matrix translatePlayer = Matrix.CreateTranslation(cameraa.ViewMatrix.Translation + forward);
            Matrix scalePlayer = Matrix.CreateScale(10f);
            Matrix rotatePlayer = Matrix.Invert(Matrix.CreateFromYawPitchRoll(cameraa.Yaw, cameraa.Pitch, 0));
            staticModel.Transform = (scalePlayer * rotatePlayer * translatePlayer );
            */
}

        /// <summary>
        /// Calculates the world transformation matrix for the weapon attached
        /// to the FirstPersonCamera. The weapon moves along with the camera.
        /// The offsets are to ensure the weapon is slightly in front of the
        /// camera and to one side.
        /// </summary>
        /// <param name="xOffset">How far to position the weapon left or right.</param>
        /// <param name="yOffset">How far to position the weapon up or down.</param>
        /// <param name="zOffset">How far to position the weapon in front or behind.</param>
        /// <returns>The weapon world transformation matrix.</returns>
        public Matrix WeaponWorldMatrix(float xOffset, float yOffset, float zOffset)
        {
            Vector3 weaponPos = cci.Camera.Position;

            weaponPos = cci.Camera.WorldMatrix.Translation + new Vector3(10, -10, 10);

            return Matrix.CreateRotationX(MathHelper.ToRadians(cci.Camera.Yaw))
                    * Matrix.CreateRotationY(MathHelper.ToRadians(cci.Camera.Pitch))
                    * Matrix.CreateTranslation(weaponPos);
        }

#1mrmohadnan

Posted 14 April 2013 - 02:55 PM

hello again ! , 

I am very happy to be with experienced game developers , so I hope some one try to see the problem in my code , as the hands associated with the gun did not positoned in front of camera !!! , I tried out  a lot of ways to figure it out but ??  here is the code ????????????????????? :/ I hate this code very much !

 

            // Update player Weapon and hands
            weaponWorldMatrix = WeaponWorldMatrix(0.45f, -0.75f, 1.65f);
            staticModel.Transform = weaponWorldMatrix;
            /*
            Vector3 forward = cameraa.ViewMatrix.Forward * new Vector3(40);
            Matrix translatePlayer = Matrix.CreateTranslation(cameraa.ViewMatrix.Translation + forward);
            Matrix scalePlayer = Matrix.CreateScale(10f);
            Matrix rotatePlayer = Matrix.Invert(Matrix.CreateFromYawPitchRoll(cameraa.Yaw, cameraa.Pitch, 0));
            staticModel.Transform = (scalePlayer * rotatePlayer * translatePlayer );
            */

            ModelDrawer.Update();

            space.Update();

            # region pickupable Fly Modules
            Ray ray;
            ray.Position = cci.CharacterController.Body.Position;
            ray.Direction = Vector3.Normalize(cci.Camera.WorldMatrix.Forward);

            for (int i = 0; i < space.Entities.Count; i++)
            {
                if ((string)space.Entities[i].Tag == "pickupable")
                {
                    if (ray.Intersects(space.Entities[i].CollisionInformation.BoundingBox) <= 50)
                        if (MouseInput.LeftButton == ButtonState.Pressed)
                        {
                            Vector3 goalpos = cci.Camera.Position + cci.Camera.WorldMatrix.Forward * 25.0f;
                            space.Entities[i].LinearVelocity = (goalpos - space.Entities[i].Position) * 15;
                            space.Entities[i].AngularVelocity = Vector3.Zero;

                            // breaking out of the loop
                            i = space.Entities.Count;
                        }
                }

            }
            #endregion
        }

        /// <summary>
        /// Calculates the world transformation matrix for the weapon attached
        /// to the FirstPersonCamera. The weapon moves along with the camera.
        /// The offsets are to ensure the weapon is slightly in front of the
        /// camera and to one side.
        /// </summary>
        /// <param name="xOffset">How far to position the weapon left or right.</param>
        /// <param name="yOffset">How far to position the weapon up or down.</param>
        /// <param name="zOffset">How far to position the weapon in front or behind.</param>
        /// <returns>The weapon world transformation matrix.</returns>
        public Matrix WeaponWorldMatrix(float xOffset, float yOffset, float zOffset)
        {
            Vector3 weaponPos = cci.Camera.Position;

            weaponPos = cci.Camera.WorldMatrix.Translation + new Vector3(10, -10, 10);

            return Matrix.CreateRotationX(MathHelper.ToRadians(cci.Camera.Yaw))
                    * Matrix.CreateRotationY(MathHelper.ToRadians(cci.Camera.Pitch))
                    * Matrix.CreateTranslation(weaponPos);
        }

PARTNERS