Example #1
0
        private float GetContactArea(MyFlatSurface plane)
        {
            Vector3 airdirection = Vector3.Scale(m_vVelocity, -1.0f);

            airdirection.Normalize();
            plane.normal.Normalize();

            return(Physics.GetContactArea(plane, airdirection));
        }
Example #2
0
        /* Given a surface calculate the area (surface) that is facing
         * speed/air direction */
        public static float GetContactArea(MyFlatSurface plane, Vector3 airDirection)
        {
            airDirection.Normalize();
            plane.normal.Normalize();
            float cosangle = Vector3.Dot(airDirection, plane.normal);

            if (Math.Abs(cosangle) < 0.017f)
            {
                return(0f);
            }
            return(plane.height * plane.width * cosangle);
        }
Example #3
0
        private float GetAirResistance(float dragcoefficient, float airdensity, float speed, MyFlatSurface area)
        {
            Vector3 airdirection = Vector3.Scale(m_vVelocity, -1.0f);

            airdirection.Normalize();
            area.normal.Normalize();
            return(dragcoefficient * airdensity * speed * speed * Physics.GetContactArea(area, airdirection) / 2);
        }
Example #4
0
        protected void CamaraTransform()
        {
            // Update the position vector
            Vector3 vT = new Vector3(0, 0, 0), vTemp = new Vector3();

            vT.Add(m_vVelocity);
            prepos = m_vPosition;
            m_vPosition.Add(vT);


            Quaternion qR  = new Quaternion();
            float      det = 0;

            Matrix matTrans = new Matrix(), matTemp = new Matrix();

            qR.RotateYawPitchRoll(ya, m_fPitchVelocity, m_fRollVelocity);
            rotation = Quaternion.Multiply(qR, rotation);

            checkLanded();

            //	m_vPosition.y=m_vPosition.y+gravityY;

            matTemp = Matrix.RotationQuaternion(rotation);
            matTrans.Translate(m_vPosition.X, m_vPosition.Y, m_vPosition.Z);

            m_matOrientation = Matrix.Multiply(matTemp, matTrans);

            /* if (newPos.Length() > 0f)
             *      m_vPosition=newPos; */

            speed = m_vVelocity.Length();

            /* apply the new orientation to all the surfaces
             * this should be improved so we don't have to create
             * new objects all the time */

            Vector3 up   = new Vector3(0, 1, 0);
            Vector3 left = new Vector3(1, 0, 0);

            wingsSpan = new MyFlatSurface(6f, 6f, up);
            Matrix matTemp2 = new Matrix();

            // wings have a 4ยบ on airplane's body
            matTemp2 = Matrix.RotationAxis(left, -0.069f);
            wingsSpan.normal.TransformNormal(matTemp2);

            tailSpan = new MyFlatSurface(1f, 1f, up);
            // rotate the tail to achieve pitch
            matTemp2 = Matrix.RotationAxis(left, this.tailPitchRotation);
            tailSpan.normal.TransformNormal(matTemp2);

            tailLateralSpan = new MyFlatSurface(1f, 1f, new Vector3(1, 0, 0));
            matTemp2        = Matrix.RotationAxis(new Vector3(0, 1, 0), this.tailRudderRotation);
            tailLateralSpan.normal.TransformNormal(matTemp2);

            bottomSpan  = new MyFlatSurface(4f, 4f, up);
            frontSpan   = new MyFlatSurface(4f, 4f, new Vector3(0, 0, 1));
            lateralSpan = new MyFlatSurface(4f, 4f, new Vector3(1, 0, 0));


            wingsSpan.normal.TransformNormal(m_matOrientation);
            wingsSpan.normal.Normalize();
            frontSpan.normal.TransformNormal(m_matOrientation);
            frontSpan.normal.Normalize();
            bottomSpan.normal.TransformNormal(m_matOrientation);
            bottomSpan.normal.Normalize();
            tailSpan.normal.TransformNormal(m_matOrientation);
            tailSpan.normal.Normalize();
            lateralSpan.normal.TransformNormal(m_matOrientation);
            lateralSpan.normal.Normalize();
            tailLateralSpan.normal.TransformNormal(m_matOrientation);
            tailLateralSpan.normal.Normalize();

            if (view == 2)
            {
                Vector3 pos = Vector3.TransformNormal(new Vector3(0f, 1f, -10f), m_matOrientation);
                pos.Add(m_vPosition);
                // Vector3 pos=new Vector3(m_vPosition.X, m_vPosition.Y, m_vPosition.Z-50);

                m_matView = Matrix.LookAtLH(pos, m_vPosition, new Vector3(0, 1, 0));
                this.myAirplane.Render(m_matOrientation);
            }
            else
            {
                m_matView = Matrix.Invert(ref det, m_matOrientation);
            }



            d3dDevice.SetTransform(TransformType.View, m_matView);
        }
Example #5
0
 public static float GetAirResistance(float dragcoefficient, float airdensity, float speed, MyFlatSurface area, Vector3 airdirection)
 {
     return(dragcoefficient * airdensity * speed * speed * GetContactArea(area, airdirection) / 2);
 }