Beispiel #1
0
        /// <summary>
        /// Determines if the <see cref="Attitude"/> is equal to the specified object.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (!(obj is Attitude))
            {
                return(false);
            }
            Attitude attidue = (Attitude)obj;

            if (obj == null)
            {
                return(false);
            }
            if (attidue.Heading != this.heading)
            {
                return(false);
            }
            if (attidue.Pitch != this.pitch)
            {
                return(false);
            }
            if (attidue.Roll != this.roll)
            {
                return(false);
            }
            return(true);
        }
Beispiel #2
0
        public MeshObject(string fileName, Vector3 offset, Attitude adjust) : base()
        {
            _levelsOfDetail        = 1;
            _maxLevelOfDetailRange = 1.0f;
            _positiveExtents       = new Vector3(-1.0f, -1.0f, -1.0f);
            _negativeExtents       = new Vector3(1.0f, 1.0f, 1.0f);
            _corners = new Vector3[8];

            Mesh         tempMesh = null;
            WeldEpsilons epsilons = new WeldEpsilons();

            Vector3 center;

            _offset         = offset;
            _attitudeOffset = adjust;
            Position        = new Vector3(100.0f, 100.0f, 0.0f);

            MaterialList materials = null;

            _mesh = new Mesh(GameEngine.Device, fileName, MeshFlags.SystemMemory,
                             _adjacency, materials, new EffectInstanceList());

            VertexBuffer vertexBuffer = _mesh.VertexBuffer;

            GraphicsBuffer vertexData = vertexBuffer.Lock(0, 0, LockFlags.NoSystemLock);

            BoundingRadius = Geometry.ComputeBoundingSphere(vertexData,
                                                            _mesh.NumberVertices, _mesh.VertexFormat).Radius;

            BoundingBox box = Geometry.ComputeBoundingBox(vertexData, _mesh.NumberVertices, _mesh.VertexFormat);


            vertexBuffer.Unlock();
            vertexBuffer.Dispose();

            //calculate the corners of the bounding box based on the extents obtained
            //from the mesh.
            _offset.Y = -_negativeExtents.Y;

            _corners[0].X = _negativeExtents.X;
            _corners[0].Y = _negativeExtents.Y + _offset.Y;
            _corners[0].Z = _negativeExtents.Z;

            _corners[1].X = _positiveExtents.X;
            _corners[1].Y = _negativeExtents.Y + _offset.Y;
            _corners[1].Z = _negativeExtents.Z;

            _corners[2].X = _negativeExtents.X;
            _corners[2].Y = _positiveExtents.Y + _offset.Y;
            _corners[2].Z = _negativeExtents.Z;

            _corners[3].X = _positiveExtents.X;
            _corners[3].Y = _positiveExtents.Y + _offset.Y;
            _corners[3].Z = _negativeExtents.Z;

            _corners[4].X = _negativeExtents.X;
            _corners[4].Y = _negativeExtents.Y;
            _corners[4].Z = _positiveExtents.Z;

            _corners[5].X = _positiveExtents.X;
            _corners[5].Y = _negativeExtents.Y + _offset.Y;
            _corners[5].Z = _positiveExtents.Z;

            _corners[6].X = _positiveExtents.X;
            _corners[6].Y = _positiveExtents.Y + _offset.Y;
            _corners[6].Z = _positiveExtents.Z;

            //TODO: IS THIS CORRECT?
            _corners[7].X = _positiveExtents.X;
            _corners[7].Y = _positiveExtents.Y + _offset.Y;
            _corners[7].Z = _positiveExtents.Z;

            tempMesh = Mesh.Clean(CleanType.BackFacing, _mesh, _adjacency, _adjacency);
            _mesh.Dispose();
            _mesh = tempMesh;

            _mesh.WeldVertices(0, epsilons, _adjacency);
            _mesh.Validate(_adjacency);

            //CreateLevelOfDetail();

            if (_meshTextures == null && materials != null)
            {
                _meshTextures  = new Texture[materials.Count];
                _meshMaterials = new Material[materials.Count];

                for (int i = 0; i < materials.Count; i++)
                {
                    _meshMaterials[i] = materials[i].Material;
                    _meshMaterials[i].AmbientColor = _meshMaterials[i].DiffuseColor;

                    if (materials[i].TextureFileName != null)
                    {
                        _meshTextures[i] = new Texture(GameEngine.Device, materials[i].TextureFileName);
                    }
                }
            }
        }