Ejemplo n.º 1
0
        private void CreateBody()
        {
            uint[] data = new uint[_textureBodyXna.Width * _textureBodyXna.Height];
            _textureBodyXna.GetData(data);

            Vertices textureVertices = PolygonTools.CreatePolygon(data, _textureBodyXna.Width, true);

            Vector2 centroid = -textureVertices.GetCentroid();

            textureVertices.Translate(ref centroid);


            Vector2         vertScale    = new Vector2(ConvertUnits.ToSimUnits(1));
            List <Vertices> triangulated = BayazitDecomposer.ConvexPartition(textureVertices);

            triangulated.ForEach(v => v.Scale(ref vertScale));

            _size   = _calcSize(triangulated.SelectMany(v => v));
            _origin = -centroid * vertScale;

            body = CreateBodyByList(triangulated);

            _parts = new Body[0];
            _infos.Values.ToList().ForEach(info => info.Effect.Dispose());
            _infos.Clear();

            foreach (Fixture fixture in body.FixtureList)
            {
                Guid id = Guid.NewGuid();

                fixture.UserData = id;
                _infos[id]       = new FixtureInfo(_effectXna.Clone(), fixture, _origin,
                                                   new Vector2(_diffuseTexture.Width, _diffuseTexture.Height)); //this.TextureSize
            }
        } // CreateBody()
Ejemplo n.º 2
0
        //constructor
        public SkyDome(ref Model newSkyDome, ref Texture2D newTexture, ref BasicEffect newEffect, ref GraphicsDeviceManager newDevice)
        {
            //initialize data memebers
            skyDome    = newSkyDome;
            skytexture = newTexture;
            effect     = newEffect;
            grapics    = newDevice;
            device     = grapics.GraphicsDevice;

            //set the effects of the model to the current effect being used
            skyDome.Meshes[0].MeshParts[0].Effect = effect.Clone(device);
        }
Ejemplo n.º 3
0
        void DrawGround()
        {
            mEffect.View = Matrix.CreateLookAt(
                mCameraPosition, mCameraLookAtVector, mCameraUpVector);

            float aspectRatio =
                mGraphicsDeviceManager.PreferredBackBufferWidth / (float)mGraphicsDeviceManager.PreferredBackBufferHeight;
            float fieldOfView   = MathHelper.PiOver4;
            float nearClipPlane = 1;
            float farClipPlane  = 2000;

            mEffect.Projection = Matrix.CreatePerspectiveFieldOfView(
                fieldOfView, aspectRatio, nearClipPlane, farClipPlane);

            mEffect.VertexColorEnabled = true;

            mGraphicsDevice.SetVertexBuffer(vb);
            mGraphicsDevice.Indices = ib;

            // solid render
            RasterizerState rSolidState = new RasterizerState();

            rSolidState.FillMode            = FillMode.Solid;
            rSolidState.CullMode            = CullMode.CullCounterClockwiseFace;
            mGraphicsDevice.RasterizerState = rSolidState;
            foreach (var pass in mEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                mGraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, ib.IndexCount / 3);
            }

            // wireframe
            BasicEffect wf = (BasicEffect)mEffect.Clone();

            wf.DiffuseColor      = Vector3.Zero;
            wf.AmbientLightColor = Vector3.Zero;
            wf.EmissiveColor     = Vector3.Zero;
            wf.SpecularColor     = Vector3.Zero;
            RasterizerState rWFState = new RasterizerState();

            rWFState.FillMode = FillMode.WireFrame;
            rWFState.CullMode = CullMode.CullCounterClockwiseFace;
            mGraphicsDevice.RasterizerState = rWFState;
            foreach (var pass in wf.CurrentTechnique.Passes)
            {
                pass.Apply();
                mGraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, ib.IndexCount / 3);
            }
        }
        protected override void LoadContent()
        {
            _cube = Game.Content.Load <Model>("chamfercube");

            foreach (ModelMesh mesh in _cube.Meshes)
            {
                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    var       effect = part.Effect as BasicEffect;
                    Texture2D tmpTex = (effect != null) ? effect.Texture : null;
                    part.Effect = _basicEffect.Clone(GraphicsDevice);
                    ((BasicEffect)part.Effect).Texture = tmpTex;
                }
            }

            base.LoadContent();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Create the default material.
        /// </summary>
        /// <param name="fromEffect">Effect to create material from.</param>
        /// <param name="copyEffectProperties">If true, will copy initial properties from effect.</param>
        public BasicMaterial(BasicEffect fromEffect, bool copyEffectProperties = true)
        {
            // store effect and set default properties
            _effect = fromEffect.Clone() as BasicEffect;
            SetDefaults();

            // copy properties from effect itself
            if (copyEffectProperties)
            {
                // set effect defaults
                Texture        = fromEffect.Texture;
                TextureEnabled = fromEffect.TextureEnabled;
                Alpha          = fromEffect.Alpha;
                AmbientLight   = new Color(fromEffect.AmbientLightColor.X, fromEffect.AmbientLightColor.Y, fromEffect.AmbientLightColor.Z);
                DiffuseColor   = new Color(fromEffect.DiffuseColor.X, fromEffect.DiffuseColor.Y, fromEffect.DiffuseColor.Z);
                SpecularColor  = new Color(fromEffect.SpecularColor.X, fromEffect.SpecularColor.Y, fromEffect.SpecularColor.Z);
                SpecularPower  = fromEffect.SpecularPower;

                // enable lightings by default
                _effect.EnableDefaultLighting();
                _effect.LightingEnabled = true;
            }
        }