コード例 #1
0
        public static TransformRate Add(TransformRate rate1, TransformRate rate2)
        {
            TransformRate result = new TransformRate();

            Vector3.Add(ref rate1.Velocity, ref rate2.Velocity, out result.Velocity);
            Vector3.Add(ref rate1.AngularVelocity, ref rate2.AngularVelocity, out result.AngularVelocity);
            return(result);
        }
コード例 #2
0
ファイル: Transform.cs プロジェクト: jdarc/jiglibx
        public void ApplyTransformRate(TransformRate rate, float dt)
        {
            Vector3.Multiply(ref rate.Velocity, dt, out var pos);
            Vector3.Add(ref Position, ref pos, out Position);

            var dir = rate.AngularVelocity;
            var ang = dir.Length();

            if (ang > 0.0f)
            {
                Vector3.Divide(ref dir, ang, out dir);
                ang *= dt;
                Matrix.CreateFromAxisAngle(ref dir, ang, out var rot);
                Matrix.Multiply(ref Orientation, ref rot, out Orientation);
            }
        }
コード例 #3
0
        /// <summary>
        /// ApplyTranformRate
        /// </summary>
        /// <param name="rate"></param>
        /// <param name="dt"></param>
        public void ApplyTransformRate(TransformRate rate, float dt)
        {
            //Position += dt * rate.Velocity;
            Vector3 pos;

            Vector3.Multiply(ref rate.Velocity, dt, out pos);
            Vector3.Add(ref Position, ref pos, out Position);

            Vector3 dir = rate.AngularVelocity;
            float   ang = dir.Length;

            if (ang > 0.0f)
            {
                Vector3.Divide(ref dir, ang, out dir);  // dir /= ang;
                ang *= dt;
                Matrix4 rot = Matrix4.CreateFromAxisAngle(dir, ang);
                Matrix4Extensions.Multiply(ref Orientation, ref rot, out Orientation);
            }

            //  JiggleMath.Orthonormalise(ref this.Orientation);
        }
コード例 #4
0
        public void ApplyTransformRate(ref TransformRate rate, float dt)
        {
            //Position += dt * rate.Velocity;
            Vector3 pos;
            Vector3.Multiply(ref rate.Velocity, dt, out pos);
            Vector3.Add(ref Position, ref pos, out Position);

            Vector3 dir = rate.AngularVelocity;
            float ang = dir.Length();

            if (ang > 0.0f)
            {
                Vector3.Divide(ref dir, ang, out dir);  // dir /= ang;
                ang *= dt;
                Matrix rot;
                Matrix.CreateFromAxisAngle(ref dir, ang, out rot);
                Matrix.Multiply(ref Orientation, ref rot, out Orientation);
            }

            //JiggleMath.Orthonormalise(ref this.Orientation);
        }
コード例 #5
0
ファイル: Body.cs プロジェクト: cody82/spacewar-arena
 /// <summary>
 /// Copies the current position etc to old - normally called only
 /// by tPhysicsSystem.
 /// </summary>
 public void CopyCurrentStateToOld()
 {
     oldTransform = transform;
     oldTransformRate = transformRate;
 }
コード例 #6
0
ファイル: Body.cs プロジェクト: cody82/spacewar-arena
        /// <summary>
        /// Updates the position with the auxilary velocities, and zeros them.
        /// </summary>
        /// <param name="dt"></param>
        public void UpdatePositionWithAux(float dt)
        {
            if (immovable || !IsActive)
            {
                transformRateAux = TransformRate.Zero;
                return;
            }

            PhysicsSystem physics = PhysicsSystem.CurrentPhysicsSystem;
            int ga = physics.MainGravityAxis;

            if (ga != -1)
            {
                int ga2 = (ga + 1) % 3;
                if (ga2 == 0) { transformRateAux.Velocity.X *= 0.1f; transformRateAux.Velocity.Y *= 0.1f; }
                else if (ga2 == 1) { transformRateAux.Velocity.Y *= 0.1f; transformRateAux.Velocity.Z *= 0.1f; }
                else if (ga2 == 2) { transformRateAux.Velocity.Z *= 0.1f; transformRateAux.Velocity.X *= 0.1f; }
            }

            #region REFERENCE: Vector3 angMomBefore = Vector3.Transform(transformRate.AngularVelocity,worldInertia;
            Vector3 angMomBefore;
            Vector3Extensions.TransformNormal(ref transformRate.AngularVelocity, ref worldInertia, out angMomBefore);
            #endregion

            #region REFERENCE: TransformRate rate = transformRate + tranformRateAux;
            TransformRate rate;
            TransformRate.Add(ref transformRate, ref transformRateAux, out rate);
            #endregion

            transform.ApplyTransformRate(ref rate, dt);

            #region INLINE: tranformRateAux = TransformRate.Zero;
            transformRateAux.AngularVelocity.X = 0.0f;
            transformRateAux.AngularVelocity.Y = 0.0f;
            transformRateAux.AngularVelocity.Z = 0.0f;
            transformRateAux.Velocity.X = 0.0f;
            transformRateAux.Velocity.Y = 0.0f;
            transformRateAux.Velocity.Z = 0.0f;
            #endregion

            #region REFERENCE: invOrientation = Matrix4.Transpose(transform.Orientation);
            Matrix4.Transpose(ref transform.Orientation, out invOrientation);
            #endregion

            // recalculate the world inertia
            //worldInvInertia = transform.Orientation * bodyInvInertia * invOrientation;
            #region REFERENCE: worldInvInertia =  invOrientation * bodyInvInertia* transform.Orientation;
            Matrix4Extensions.Multiply(ref invOrientation, ref bodyInvInertia, out worldInvInertia);
            Matrix4Extensions.Multiply(ref worldInvInertia, ref transform.Orientation, out worldInvInertia);
            #endregion

            //worldInertia = transform.Orientation * bodyInertia * invOrientation;
            #region REFERENCE: worldInertia = invOrientation * bodyInertia* transform.Orientation;
            Matrix4Extensions.Multiply(ref invOrientation, ref bodyInertia, out worldInertia);
            Matrix4Extensions.Multiply(ref worldInertia, ref transform.Orientation, out worldInertia);
            #endregion

            // conservation of momentum
            #region transformRate.AngularVelocity = Vector3.Transform(angMomBefore, worldInvInertia);
            Vector3Extensions.TransformNormal(ref angMomBefore, ref worldInvInertia, out transformRate.AngularVelocity);
            #endregion

            if (this.CollisionSkin != null)
                this.CollisionSkin.SetTransform(ref oldTransform, ref transform);
        }
コード例 #7
0
ファイル: Body.cs プロジェクト: cody82/spacewar-arena
 /// <summary>
 /// Copy our current state (position, velocity etc) into the stored state
 /// </summary>
 public void StoreState()
 {
     storedTransform = transform;
     storedTransformRate = transformRate;
 }
コード例 #8
0
ファイル: Body.cs プロジェクト: cody82/spacewar-arena
        /// <summary>
        /// Restore from the stored state into our current state.
        /// </summary>
        public void RestoreState()
        {
            transform = storedTransform;
            transformRate = storedTransformRate;

            #region REFERENCE: invOrientation = Matrix4.Transpose(transform.Orientation);
            Matrix4.Transpose(ref transform.Orientation, out invOrientation);
            #endregion

            //worldInvInertia = transform.Orientation * bodyInvInertia * invOrientation;
            #region REFERENCE: worldInvInertia = invOrientation *bodyInvInertia* transform.Orientation;
            Matrix4Extensions.Multiply(ref invOrientation, ref bodyInvInertia, out worldInvInertia);
            Matrix4Extensions.Multiply(ref worldInvInertia, ref transform.Orientation, out worldInvInertia);
            #endregion

            //worldInertia = transform.Orientation * bodyInertia * invOrientation;
            #region REFERENCE: worldInertia = invOrientation *bodyInertia * transform.Orientation;
            Matrix4Extensions.Multiply(ref invOrientation, ref bodyInertia, out worldInertia);
            Matrix4Extensions.Multiply(ref worldInertia, ref transform.Orientation, out worldInertia);
            #endregion
        }
コード例 #9
0
 public static void Add(ref TransformRate rate1, ref TransformRate rate2, out TransformRate result)
 {
     Vector3.Add(ref rate1.Velocity, ref rate2.Velocity, out result.Velocity);
     Vector3.Add(ref rate1.AngularVelocity, ref rate2.AngularVelocity, out result.AngularVelocity);
 }
コード例 #10
0
 public static void Add(ref TransformRate rate1, ref TransformRate rate2 ,out TransformRate result)
 {
     Vector3.Add(ref rate1.Velocity, ref rate2.Velocity, out result.Velocity);
     Vector3.Add(ref rate1.AngularVelocity, ref rate2.AngularVelocity, out result.AngularVelocity);
 }
コード例 #11
0
 public static TransformRate Add(TransformRate rate1, TransformRate rate2)
 {
     TransformRate result = new TransformRate();
     Vector3.Add(ref rate1.Velocity, ref rate2.Velocity, out result.Velocity);
     Vector3.Add(ref rate1.AngularVelocity, ref rate2.AngularVelocity, out result.AngularVelocity);
     return result;
 }