Ejemplo n.º 1
1
        public static AABBTree AABBTree(Model model, AABBNodeInfo tree_info)
        {
            List<TriangleVertexIndices> indices = new List<TriangleVertexIndices>();
              List<Vector3> points = new List<Vector3>();
              AABBFactory.ExtractData(model, points, indices, true);

              VertexPositionColor[] vertices = new VertexPositionColor[indices.Count * 3];

              List<float[]> triangles = new List<float[]>();

              int i = 0;
              foreach (TriangleVertexIndices index in indices)
              {
            vertices[i++] = new VertexPositionColor(points[index.I0], Color.White);
            vertices[i++] = new VertexPositionColor(points[index.I1], Color.White);
            vertices[i++] = new VertexPositionColor(points[index.I2], Color.White);

            float[] tri = new float[3];
            tri[0] = points[index.I0].X;
            tri[1] = points[index.I1].Y;
            tri[2] = points[index.I2].Z;
            triangles.Add(tri);
              }
              return new AABBTree(triangles, tree_info);
        }
Ejemplo n.º 2
1
        public Pigeon(ContentManager con)
        {
            boundingBox = new Vector3(6, 3, 6);

            distance = 0;
            rand = new Random();

            dx = (0.5-rand.NextDouble())*0.8 + 0.2;
            dy = rand.NextDouble()*1.5 + 0.7;
            dz = 0.8;

            x = 5.8;
            y = -2;
            z = 83.5;

            sx = 5.8;
            sy = -2;
            sz = 83.5;

            this.world = Matrix.CreateTranslation(new Vector3((float)x, (float)y, (float)z));

            model = con.Load<Model>(@"models/pigeon");

            isDone = false;
        }
Ejemplo n.º 3
1
        public override void DrawBuildings(GameTime gameTime)
        {
            base.DrawBuildings(gameTime);

            Model[] models = new Model[1];
            models[0] = GameResources.Inst().GetTreeModel(2);

            foreach (Model m in models)
            {
                Matrix[] transforms = new Matrix[m.Bones.Count];
                m.CopyAbsoluteBoneTransformsTo(transforms);

                foreach (ModelMesh mesh in m.Meshes)
                {
                    foreach (BasicEffect effect in mesh.Effects)
                    {
                        effect.Alpha = 1.0f;
                        effect.LightingEnabled = true;
                        effect.AmbientLightColor = GameState.MaterialAmbientColor;
                        effect.DirectionalLight0.Direction = GameState.LightDirection;
                        effect.DirectionalLight0.DiffuseColor = GameState.LightDiffusionColor;
                        effect.DirectionalLight0.SpecularColor = GameState.LightSpecularColor;
                        effect.DirectionalLight0.Enabled = true;
                        effect.World = transforms[mesh.ParentBone.Index] * worldM;
                        effect.View = GameState.view;
                        effect.Projection = GameState.projection;
                    }
                    mesh.Draw();
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the nearest intersection point from the specifed picking ray.
        /// </summary>
        /// <returns>Distance to the start of the ray.</returns>
        public static float?Intersects(this Microsoft.Xna.Framework.Graphics.Model model, Matrix world, Ray ray)
        {
            Ray      local;
            ModelTag extensions = model.Tag as ModelTag;

            // Collision tree not found, use bounding sphere instead.
            if (extensions == null || extensions.Collision == null)
            {
                float?result = null;

                foreach (var mesh in model.Meshes)
                {
                    local = ray.Transform(Matrix.Invert(GetAbsoluteTransform(mesh, world)));
                    float?current = mesh.BoundingSphere.Intersects(local);

                    if (result == null)
                    {
                        result = current;
                    }
                    else if (current.HasValue && current.Value < result.Value)
                    {
                        result = current.Value;
                    }
                }

                return(result);
            }

            // Detect using collision tree.

            local = ray.Transform(Matrix.Invert(GetAbsoluteTransform(model.Meshes[0], world)));
            return(extensions.Collision.Intersects(local));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Computes the bounding box for the specified xna model.
        /// </summary>
        public static BoundingBox ComputeBoundingBox(this Microsoft.Xna.Framework.Graphics.Model model)
        {
            ModelTag extensions = model.Tag as ModelTag;

            // Try to use collision tree.
            if (extensions != null && extensions.Collision != null)
            {
                return(extensions.Collision.CollisionTree.Bounds);
            }

            // Try to use vertices of the mesh
            BoundingBox result = new BoundingBox();

#if !SILVERLIGHT
            if (ComputeBoundingBoxFromVertices(model, out result))
            {
                return(result);
            }
#endif
            // Now use bounding spheres
            foreach (var mesh in model.Meshes)
            {
                BoundingBox box = BoundingBox.CreateFromSphere(
                    mesh.BoundingSphere.Transform(GetAbsoluteTransform(mesh, Matrix.Identity)));
                result = BoundingBox.CreateMerged(result, box);
            }

            return(result);
        }
Ejemplo n.º 6
0
 public cTree(Model treeModel, Matrix view, Matrix projection, Vector3 position)
 {
     //instantiate the tree
     loadModel(treeModel, view, projection);
     setScaleFactor(0.5f, 0.5f, 0.5f);
     setPosition(position);
 }
        public override void LoadContent()
        {
            this.pointLightEffect = this.Content.Load<Effect>("System/Effects/PointLight");
            this.pointLightEffect.CurrentTechnique = this.pointLightEffect.Techniques[0];

            this.pointLightModel = this.Content.Load<Model>("System/Models/PointLight");
        }
Ejemplo n.º 8
0
        public void DrawBall(float aspectRatio, Vector3 cameraPosition, Model ball, float xrotation,float yrotation)
        {
            // assign random number to roid1modelPosition.x or y

            // Copy any parent transforms.
            Matrix[] transforms = new Matrix[ball.Bones.Count];
            ball.CopyAbsoluteBoneTransformsTo(transforms);

            // Draw the model. A model can have multiple meshes, so loop.
            foreach (ModelMesh mesh in ball.Meshes)
            {
                // This is where the mesh orientation is set, as well as our camera and projection.
                foreach (BasicEffect effect in mesh.Effects)
                {

                    effect.EnableDefaultLighting();
                    effect.World = transforms[mesh.ParentBone.Index] //* Matrix.CreateRotationZ(Roid1modelRotation)
                        * Matrix.CreateRotationX(xrotation) * Matrix.CreateRotationY(yrotation)
                        * Matrix.CreateTranslation(new Vector3(3750, -2750, 0));

                    effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
                        aspectRatio, 1.0f, 10000.0f);
                }
                // Draw the mesh, using the effects set above.
                mesh.Draw();
            }
        }
Ejemplo n.º 9
0
        public override void LoadContent()
        {
            LoadModel("SandP-Player");
            Flame.LoadModel("SandP-PlayerFlame");

            for (int i = 0; i < 5; i++)
            {
                Shots[i] = new Shot(Game);
            }

            BaseRadar.LoadModel("core/cube");
            HealthModel = Load("core/cube");

            ThrustSound        = LoadSoundEffect("Thrust");
            ThrustTimer.Amount = (float)ThrustSound.Duration.TotalSeconds;

            FireSound        = LoadSoundEffect("PlayerShot");
            HitSound         = LoadSoundEffect("PlayerHit");
            ChestPickupSound = LoadSoundEffect("ChestPickup");
            DeadSound        = LoadSoundEffect("PlayerDead");
            OreSound         = LoadSoundEffect("PickupChunk");
            DockSound        = LoadSoundEffect("Dock");
            UnDockSound      = LoadSoundEffect("UnDock");
            ShotHitSound     = LoadSoundEffect("PlayerShotHit");
        }
Ejemplo n.º 10
0
            public TileMap3D(GraphicsDevice graphicsDevice, ContentManager contentManager, int width, int height)
            {
                this.GraphicsDevice = graphicsDevice;
                Wall = contentManager.Load<Model>("Models/TileMap3D/Wall");
                FloorTile = contentManager.Load<Model>("Models/TileMap3D/FloorTile");
                Dirt = contentManager.Load<Model>("Models/TileMap3D/Dirt");
                Cleaner = contentManager.Load<Model>("Models/TileMap3D/Cleaner");

                ((BasicEffect)Wall.Meshes[0].Effects[0]).EnableDefaultLighting();
                ((BasicEffect)FloorTile.Meshes[0].Effects[0]).EnableDefaultLighting();
                ((BasicEffect)Dirt.Meshes[0].Effects[0]).EnableDefaultLighting();
                ((BasicEffect)Cleaner.Meshes[0].Effects[0]).EnableDefaultLighting();
                foreach (BasicEffect effect in Cleaner.Meshes[0].Effects)
                    effect.Tag = effect.DiffuseColor;
                foreach (BasicEffect effect in FloorTile.Meshes[0].Effects)
                    effect.Tag = effect.DiffuseColor;

                dss.DepthBufferEnable = true;
                dss.DepthBufferFunction = CompareFunction.LessEqual;
                dss.DepthBufferWriteEnable = true;
                rs.CullMode = CullMode.CullCounterClockwiseFace;
                ss.AddressU = TextureAddressMode.Wrap;
                ss.AddressV = TextureAddressMode.Wrap;
                ss.Filter = TextureFilter.Anisotropic;

                Camera = new Camera(graphicsDevice.Viewport.AspectRatio, graphicsDevice);
            }
Ejemplo n.º 11
0
        public CarObject(int asset,
            Vector3 pos,
            Model model,Model wheels, bool FWDrive,
                       bool RWDrive,
                       float maxSteerAngle,
                       float steerRate,
                       float wheelSideFriction,
                       float wheelFwdFriction,
                       float wheelTravel,
                       float wheelRadius,
                       float wheelZOffset,
                       float wheelRestingFrac,
                       float wheelDampingFrac,
                       int wheelNumRays,
                       float driveTorque,
                       float gravity)
            : base()
        {
            car = new Car(FWDrive, RWDrive, maxSteerAngle, steerRate,
                wheelSideFriction, wheelFwdFriction, wheelTravel, wheelRadius,
                wheelZOffset, wheelRestingFrac, wheelDampingFrac,
                wheelNumRays, driveTorque, gravity);

            this.Body = car.Chassis.Body;
            this.Skin= car.Chassis.Skin;
            Body.CollisionSkin = Skin;
            Body.ExternalData = this;
            this.wheel = wheels;
            CommonInit(pos, new Vector3(1, 1, 1), model, true, asset);
            SetCarMass(100.1f);

            actionManager.AddBinding((int)Actions.Acceleration, new Helper.Input.ActionBindingDelegate(SimulateAcceleration), 1);
            actionManager.AddBinding((int)Actions.Steering, new Helper.Input.ActionBindingDelegate(SimulateSteering), 1);
            actionManager.AddBinding((int)Actions.Handbrake, new Helper.Input.ActionBindingDelegate(SimulateHandbrake), 1);
        }
Ejemplo n.º 12
0
        public Star(GameplayScreen game, Model model, Matrix view, Matrix projection, Random random)
            : base(game.ScreenManager.Game)
        {
            this.random = random;
            this.x = random.Next(-340, 200) / 100f;
            this.speed = random.Next(2, 8) / 1000f;

            float scale = random.Next(100, 1000)/100000f;

            if(speed > 0.0004)
                this.y = random.Next(5, 10);
            else
                this.y = random.Next(2, 5);

            xRotation = (float) random.Next(-360, 360);
            yRotation = (float)random.Next(-360, 360);
            zRotation = (float)random.Next(-360, 360);

            color = new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble());

            this.DrawOrder = 900;
            this.view = view;
            this.projection = projection;
            this.model = model;
            this.game = game;
            this.world = Matrix.Identity * Matrix.CreateScale(scale) * Matrix.CreateTranslation(x, y, 13f);
            transforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transforms);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// LoadContent will be called once per game and is the place to load
 /// all of your content.
 /// </summary>
 protected override void LoadContent()
 {
     // Create a new SpriteBatch, which can be used to draw textures.
     spriteBatch = new XFG.SpriteBatch(GraphicsDevice);
     castle      = this.Content.Load <XFG.Model>("Models\\castle");
     // TODO: use this.Content to load your game content here
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of <c>ModelSkeleton</c>.
        /// </summary>
        public ModelSkeleton(Microsoft.Xna.Framework.Graphics.Model model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var skeleton = model.GetSkeletonData();

            if (skeleton != null)
            {
                SkeletonRoot            = skeleton.SkeletonRoot;
                InverseAbsoluteBindPose = new ReadOnlyCollection <Matrix>(skeleton.InverseAbsoluteBindPose);
            }

            boneTransforms = new Matrix[model.Bones.Count];
            model.CopyBoneTransformsTo(boneTransforms);
            BoneNames = new ReadOnlyCollection <string>(new BoneNameCollection()
            {
                Model = model
            });
            parentBones = new ReadOnlyCollection <int>(new ParentBoneCollection()
            {
                Model = model
            });
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Copies only the geometry (Mesh,
        /// MinimumBoundingBox, MinimumBoundingSphere, TriangleCount and Transforms)
        /// </summary>
        /// <param name="model">A source model from which to copy</param>
        public override void CopyGeometry(IModel model)
        {
            if (!(model is AnimatedModel))
            {
                return;
            }

            AnimatedModel srcModel = (AnimatedModel)model;

            skinnedModel = srcModel.SkinnedModel;

            vertices.AddRange(((IPhysicsMeshProvider)model).Vertices);
            indices.AddRange(((IPhysicsMeshProvider)model).Indices);

            // Look up our custom skinning information.
            skinningData = srcModel.skinnedModel.Tag as SkinningData;

            if (skinningData == null)
            {
                throw new GoblinException("This model does not contain a SkinningData tag.");
            }

            // Create an animation player, and start decoding an animation clip.
            animationPlayer = new AnimationPlayer(skinningData);

            triangleCount        = srcModel.TriangleCount;
            boundingBox          = srcModel.MinimumBoundingBox;
            boundingSphere       = srcModel.MinimumBoundingSphere;
            UseInternalMaterials = srcModel.UseInternalMaterials;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Single Primitive Constructor with predefined MaterialProperty
        /// </summary>
        /// <param name="position">Initial Body Position</param>
        /// <param name="scale">Scale</param>
        /// <param name="primative">Primitive to add to Skin</param>
        /// <param name="propId">Predefined Material Properties of Primitive</param>
        public Gobject(Vector3 position, Vector3 scale, Primitive primative, MaterialTable.MaterialID propId, Model model)
            : this()
        {
            Skin.AddPrimitive(primative, (int)propId);

            CommonInit(position, scale, model, true);
        }
Ejemplo n.º 17
0
 public void Init(Microsoft.Xna.Framework.Graphics.Model model, Vector3 position, Vector3 rotation, Vector3 scale)
 {
     m_model    = model;
     m_position = position;
     m_scale    = scale;
     m_rotation = rotation;
 }
Ejemplo n.º 18
0
 public void Init(Microsoft.Xna.Framework.Graphics.Model model, Vector3 position)
 {
     m_model    = model;
     m_position = position;
     m_scale    = Vector3.One;
     m_rotation = Vector3.Zero;
 }
Ejemplo n.º 19
0
        public CarObject(Game game, Model model,Model wheels, bool FWDrive,
                       bool RWDrive,
                       float maxSteerAngle,
                       float steerRate,
                       float wheelSideFriction,
                       float wheelFwdFriction,
                       float wheelTravel,
                       float wheelRadius,
                       float wheelZOffset,
                       float wheelRestingFrac,
                       float wheelDampingFrac,
                       int wheelNumRays,
                       float driveTorque,
                       float gravity)
            : base(game, model)
        {
            car = new Car(FWDrive, RWDrive, maxSteerAngle, steerRate,
                wheelSideFriction, wheelFwdFriction, wheelTravel, wheelRadius,
                wheelZOffset, wheelRestingFrac, wheelDampingFrac,
                wheelNumRays, driveTorque, gravity);

            this.body = car.Chassis.Body;
            this.collision = car.Chassis.Skin;
            this.wheel = wheels;

            SetCarMass(100.0f);
        }
Ejemplo n.º 20
0
 protected virtual void loadModel(string file, bool reload)
 {
     if (!reload)
     {
         this.UnsupportedTechniques.Clear();
     }
     if (string.IsNullOrEmpty(file))
     {
         this.model         = null;
         this.effect        = null;
         this.IsValid.Value = false;
     }
     else
     {
         try
         {
             this.model = (this.MapContent ? this.main.MapContent : this.main.Content).Load <Microsoft.Xna.Framework.Graphics.Model>(file);
             this.loadEffect(this.EffectFile);
             this.IsValid.Value = true;
         }
         catch (Exception e)
         {
             Log.d(e.ToString());
             this.model         = null;
             this.effect        = null;
             this.IsValid.Value = false;
         }
     }
 }
Ejemplo n.º 21
0
        public void Initialize()
        {
            GraphicsDevice g = Global.GraphicsDevice;

            basicEffect = new BasicEffect(g);

            foreach (Battler b in battlers)
            {
                b.Initialize();
            }
            attackFx = new AttackEffect[maxNumAttackFx];
            map      = Global.Content.Load <Microsoft.Xna.Framework.Graphics.Model>("Models/BattleMaps/" + mapName);

            vertices = new VertexPositionNormalTexture[(battlers.Length + maxNumAttackFx) * 4];
            for (int i = 0; i < battlers.Length; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    vertices[(i * 4) + j] = battlers[i].GetVertices()[j];
                }
            }
            vertexBuffer = new VertexBuffer(g, typeof(VertexPositionNormalTexture), vertices.Length, BufferUsage.WriteOnly);

            rasterizerState          = new RasterizerState();
            rasterizerState.CullMode = CullMode.None;
            rasterizerState.FillMode = FillMode.Solid;

            basicEffect.View = Global.view;
            basicEffect.VertexColorEnabled = false;
            basicEffect.TextureEnabled     = true;

            basicEffect.AmbientLightColor = new Vector3(0.5f, 0.5f, 0.5f);
            nightTime = false;
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Single Primitive Constructor with custom MaterialProperty
        /// </summary>
        /// <param name="position">Initial Body Position</param>
        /// <param name="scale">Scale</param>
        /// <param name="primative">Primitive to add to Skin</param>
        /// <param name="prop">Material Properties of Primitive</param>
        public Gobject(Vector3 position, Vector3 scale, Primitive primative, MaterialProperties prop, Model model)
            : this()
        {
            Skin.AddPrimitive(primative, prop);

            CommonInit(position, scale, model, true);
        }
Ejemplo n.º 23
0
 protected override void LoadContent()
 {
     model = contentManager.Load<Model>(texture);
     boneTransforms = new Matrix[model.Bones.Count];
     //model.Root.Transform *= Matrix.CreateRotationY(MathHelper.ToRadians(90));
     base.LoadContent();
 }
Ejemplo n.º 24
0
 public PhysicObject(Game game)
     : base(game)
 {
     this.model = null;
     color = new Vector3(random.Next(255), random.Next(255), random.Next(255));
     color /= 255.0f;
 }
Ejemplo n.º 25
0
        public Googoo(Model model, Game game, Vector3 startPosition, Vector3 wanderPosition, int faceId, ModelManager modelManager)
            : base(model, game)
        {
            this.game = game;
            this.googoo = model;
            texture = modelManager.screenManager.texManager.getGoogooTexture();
            this.face = faceId;

            // init velocity, acceleration and friction
            acceleration = FaceDirection * accel;
            velocity = acceleration;
            friction = -FaceDirection * frictionValue;

            this.position = startPosition;

            this.startPosition = startPosition;
            this.wanderPosition = wanderPosition;

            //navigate.Add(startPosition); //first location in list
            //navigate.Add(wanderPosition); //last location in list

            this.modelManager = modelManager;
            effect = ((Spectrum)game).grayEffect;
            handelOrientation();

            loadStateFile();
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Constructs a new display model.
 /// </summary>
 /// <param name="entity">Entity to follow.</param>
 /// <param name="model">Model to draw on the entity.</param>
 /// <param name="modelDrawer">Model drawer to use.</param>
 public DisplayEntityModel(Entity entity, Model model, ModelDrawer modelDrawer)
     : base(modelDrawer)
 {
     OffsetTransform = Matrix.Identity;
     Entity = entity;
     Model = model;
 }
        /// <summary>
        /// Creates a bounding box for an model
        /// </summary>
        /// <param name="model">Model that the bounding box will be created for</param>
        /// <param name="worldTransform">Position of the Model</param>
        /// <returns>A Bounding box for the model</returns>
        public BoundingBox CreateBoundingBox(Model model, Matrix worldTransform)
        {
            Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
            Vector3 max = new Vector3(float.MinValue, float.MinValue, float.MinValue);

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    int vertexStride = meshPart.VertexBuffer.VertexDeclaration.VertexStride;
                    int vertexBufferSize = meshPart.NumVertices * vertexStride;

                    float[] vertexData = new float[vertexBufferSize / sizeof(float)];
                    meshPart.VertexBuffer.GetData<float>(vertexData);

                    for (int i = 0; i < vertexBufferSize / sizeof(float); i += vertexStride / sizeof(float))
                    {
                        Vector3 transformedPosition = Vector3.Transform(new Vector3(vertexData[i], vertexData[i + 1], vertexData[i + 2]), worldTransform);

                        min = Vector3.Min(min, transformedPosition);
                        max = Vector3.Max(max, transformedPosition);
                    }
                }
            }
            return new BoundingBox(min, max);
        }
Ejemplo n.º 28
0
        public Prota(Model text,Model[] disp)
        {
            g_nave = new modelo(text);
            t_disp=disp;

            box = new caja(new Vector3(pos.X - 10f, pos.Y - 10f, -10f), new Vector3(pos.X + 10f, pos.Y + 10f, 10f));
        }
Ejemplo n.º 29
0
 public Flag(Vector3 initialPosition)
 {
     this.Position = initialPosition;
     this.model = model;
     this.rotation = rotation;
     this.idle = true;
 }
Ejemplo n.º 30
0
        public Drawable3D(Game game, Entity.Entity parent,Model model, bool adjustBoundingBoxWithUCX = true)
            : base(game, parent)
        {
            this.model = model;
            modelManager.addModelToDrawList(Draw);

            boundingBoxes = new List<BoundingBox>();
            Vector3[] data;
            VertexDeclaration vd = model.Meshes[0].MeshParts[0].VertexBuffer.VertexDeclaration;

            foreach (ModelMesh mesh in model.Meshes)
            {
                if (mesh.Name.Length > 3 && mesh.Name.Substring(0, 3) == "UCX")
                {
                    ModelMeshPart mmp = mesh.MeshParts[0];
                    data = new Vector3[mmp.NumVertices];
                    mesh.MeshParts[0].VertexBuffer.GetData<Vector3>(mmp.VertexOffset * vd.VertexStride, data, 0, mmp.NumVertices, vd.VertexStride);
                    Matrix transform = GetAbsoluteTransform(mesh.ParentBone);
                    boundingBoxes.Add(createBoundingBox(data, mesh.ParentBone.Transform));
                }
                else
                {
                    ModelMeshPart mmp = mesh.MeshParts[0];
                    data = new Vector3[mmp.NumVertices];
                    mesh.MeshParts[0].VertexBuffer.GetData<Vector3>(mmp.VertexOffset * vd.VertexStride, data, 0, mmp.NumVertices, vd.VertexStride);
                    Matrix transform = GetAbsoluteTransform(mesh.ParentBone);
                    createModelBoundingBox(data, mesh.ParentBone.Transform);
                }
            }
            if (adjustBoundingBoxWithUCX)
            {
                adjustModelBoundingBoxWithCollisionBoxes();
            }
        }
Ejemplo n.º 31
0
 /// <summary>
 /// Load your graphics content.
 /// </summary>
 protected override void LoadContent()
 {
     spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
     spriteFont = Content.Load<SpriteFont>("hudFont");
     background = Content.Load<Texture2D>("sunset");
     model = Content.Load<Model>("tank");
 }
Ejemplo n.º 32
0
        public Ducky(Game game)
            : base(game)
        {
            thisDucky = game.Content.Load<Model>("ducky_highres");

            texture_ducky = game.Content.Load<Texture2D>("ducky");
        }
Ejemplo n.º 33
0
    public XnaModelSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;
      var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

      // Add a custom game object which controls the camera.
      _cameraObject = new CameraObject(Services);
      GameObjectService.Objects.Add(_cameraObject);

      // Load XNA model.
      _model = ContentManager.Load<Model>("Saucer3/saucer");

      // Enable default lighting.
      var basicEffects = _model.Meshes
                               .SelectMany(m => m.MeshParts)
                               .Select(mp => mp.Effect)
                               .OfType<BasicEffect>();
      foreach (var effect in basicEffects)
        effect.EnableDefaultLighting();
    }
Ejemplo n.º 34
0
        public void DrawTheMatrix(Model DModel, Matrix ChangeMatrix, Vector3 Pos)
        {
            Matrix[] transforms = new Matrix[DModel.Bones.Count];
            DModel.CopyAbsoluteBoneTransformsTo(transforms);

            //Draw model with all its meshes
            foreach (ModelMesh mesh in DModel.Meshes)//Every mesh in MyModel
            {

                //Mesh Orientation and camera and projection
                foreach (BasicEffect effect in mesh.Effects)
                {

                    effect.EnableDefaultLighting();

                    //Sets up the posibillity to use transformatiion on the G.myModelObject
                    effect.World
                        = transforms[mesh.ParentBone.Index]
                        * ChangeMatrix;

                    effect.View = Matrix.CreateLookAt(G.CamPos, G.ship.Position, Vector3.Up);
                    //                                                                                            Near  Far   Wherever you are
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(G.Fov), G.aspectRatio, 1.0f, 100000);

                }
                mesh.Draw();
            }
        }
Ejemplo n.º 35
0
 public Gun(int RoundsInClip, int TotalRounds, int GunCode, Model GunModel)
 {
     this.RoundsInClip = RoundsInClip;
     this.TotalRounds = TotalRounds;
     this.GunCode = GunCode;
     this.GunModel = GunModel;
 }
Ejemplo n.º 36
0
        public SkyBox(Game1 newGame, Vector3 newCenter, string newName)
        {
            Game = newGame;
            center = newCenter;

            skyBoxModel=LoadModel(newName, out skyBoxTextures);
        }
Ejemplo n.º 37
0
        public ModelRenderer(Model model)
        {
            mModel = model;
            ConstructBoundingSphere();

            mUIConfigurer = null;
        }
Ejemplo n.º 38
0
        /// <summary>
        /// Copies the positions of the model to the target array.
        /// </summary>
        public static int CopyPositionsTo(this Microsoft.Xna.Framework.Graphics.Model model, Vector3[] positions, int startIndex)
        {
            Matrix[] bones = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(bones);

            int count = 0;

            foreach (var mesh in model.Meshes)
            {
                foreach (var part in mesh.MeshParts)
                {
                    int partCount = CopyPositionsTo(model, mesh, part, positions, startIndex);
                    if (positions != null)
                    {
                        for (int i = startIndex; i < startIndex + partCount; ++i)
                        {
                            Vector3.Transform(ref positions[i], ref bones[mesh.ParentBone.Index], out positions[i]);
                        }
                    }
                    startIndex += partCount;
                    count      += partCount;
                }
            }
            return(count);
        }
Ejemplo n.º 39
0
 public Ent()
 {
     sprite = defaultSprite;
     model = defaultModel;
     size = model.Meshes[0].BoundingSphere.Radius;
     pendingRemoval = false;
 }
Ejemplo n.º 40
0
        protected override void LoadGraphicsContent(bool loadAllContent)
        {
            //this.font = this.content.Load<SpriteFont>("Content\\font\\gamefont");

            if (loadAllContent)
            {
                this.sphere         = this.content.Load <Microsoft.Xna.Framework.Graphics.Model>("Content\\Models\\newSphere");
                this.boneTransforms = new Matrix[sphere.Bones.Count];

                this.myTexture   = this.content.Load <Microsoft.Xna.Framework.Graphics.Texture2D>("Content\\textures\\wooden texture");
                this.spriteBatch = new Microsoft.Xna.Framework.Graphics.SpriteBatch(this.graphics.GraphicsDevice);
                for (int i = 0; i < Max_Obj; i++)
                {
                    this.box[i].LoadGraphicsContent(myTexture, spriteBatch);
                }

                this.myTexture = this.content.Load <Microsoft.Xna.Framework.Graphics.Texture2D>("Content\\textures\\cursor");
                Mouse.LoadGraphicsContent(spriteBatch, myTexture);

                this.myTextureTable = this.content.Load <Microsoft.Xna.Framework.Graphics.Texture2D>("Content\\textures\\horizontal");
                //this.myTextureTable = this.content.Load<Microsoft.Xna.Framework.Graphics.Texture2D>("Content\\textures\\table");
                this.arrowTexture = this.content.Load <Microsoft.Xna.Framework.Graphics.Texture2D>("Content\\textures\\arrow");
                this.arrow.LoadGraphicsContent(this.arrowTexture, spriteBatch);

                this.mysong = this.content.Load <Song>("Content\\Sounds\\12 Wake Up");
            }
        }
Ejemplo n.º 41
0
        public HeightmapObject(Game game, Model model,Vector2 shift)
            : base(game, model)
        {
            body = new Body(); // just a dummy. The PhysicObject uses its position to get the draw pos
            collision = new CollisionSkin(null);

            HeightMapInfo heightMapInfo = model.Tag as HeightMapInfo;
            Array2D field = new Array2D(heightMapInfo.heights.GetUpperBound(0), heightMapInfo.heights.GetUpperBound(1));

            for (int x = 0; x < heightMapInfo.heights.GetUpperBound(0); x++)
            {
                for (int z = 0; z < heightMapInfo.heights.GetUpperBound(1); z++)
                {
                    field.SetAt(x,z,heightMapInfo.heights[x,z]);
                }
            }

            // move the body. The body (because its not connected to the collision
            // skin) is just a dummy. But the base class shoudl know where to
            // draw the model.
            body.MoveTo(new Vector3(shift.X,0,shift.Y), Matrix.Identity);

            collision.AddPrimitive(new Heightmap(field, shift.X, shift.Y, 1, 1), new MaterialProperties(0.7f,0.7f,0.6f));

            PhysicsSystem.CurrentPhysicsSystem.CollisionSystem.AddCollisionSkin(collision);
        }
Ejemplo n.º 42
0
        public ModelContainer(Model modelpass, Pose posepass, SkeletonPose skeletonpass)
        {
            _model = modelpass;
            _pose = posepass;
            _skeleton = skeletonpass;

            var additionalData = (Dictionary<string,object>)_model.Tag;
            var animations = (Dictionary<string, SkeletonKeyFrameAnimation>)additionalData["Animations"];
            int index = 0;

            _animations = new ITimeline[animations.Count];

                _animations[0] = new AnimationClip<SkeletonPose>(animations["First"])
                {
                    LoopBehavior = LoopBehavior.Cycle,
                    Duration = TimeSpan.MaxValue
                };
                index++;

                _animations[1] = new AnimationClip<SkeletonPose>(animations["Second"]);

                _animations[2] = new AnimationClip<SkeletonPose>(animations["Second"])
                {
                    LoopBehavior = LoopBehavior.Cycle,
                    Duration = TimeSpan.MaxValue
                };
        }
Ejemplo n.º 43
0
 private void InitCollisionShapeVisualization()
 {
     collisionShapeEffect = new BasicEffect(game.Graphics.Device, null);
     collisionShapeEffect.EmissiveColor = Color.White.ToVector3();
     collisionShapeEffect.Alpha         = 0.2f;
     sphereMesh = game.Content.Load <Model>("Content\\Models\\SphereLowPoly");
     cubeMesh   = game.Content.Load <Model>("Content\\Models\\Cube");
 }
Ejemplo n.º 44
0
 public static void AddSkeleton(this DynamicPrimitive dynamicPrimitive, Microsoft.Xna.Framework.Graphics.Model model, Matrix?world, Color color, float lineWidth)
 {
     dynamicPrimitive.BeginPrimitive(PrimitiveType.LineList, null, world, lineWidth);
     {
         AddSkeleton(dynamicPrimitive, model.Root, Matrix.Identity, world, color);
     }
     dynamicPrimitive.EndPrimitive();
 }
Ejemplo n.º 45
0
 /// <summary>
 /// Builds a Model based on the parms specified
 /// </summary>
 /// <param name="parms"></param>
 public BaseModel(BaseModelParams parms)
 {
     this.model    = parms.Model;
     this.Position = parms.Position;
     this.Rotation = parms.Rotation;
     this.Scale    = parms.Scale;
     this.Visible  = parms.Visible;
 }
        public void Init(Microsoft.Xna.Framework.Graphics.Model model, Effect effect, TextureCube texture)
        {
            m_model   = model;
            m_effect  = effect;
            m_cubemap = texture;

            m_scale    = new Vector3(2000.0f, 2000.0f, 2000.0f);
            m_position = new Vector3(0.0f, -500.0f, 0.0f);
        }
Ejemplo n.º 47
0
        // Create Model from vertex buffer
        public Model(VertexBuffer vbuffer, IndexBuffer ibuffer, Vector3 position = new Vector3(), Vector3 rotation = new Vector3(), float scale = 1f)
        {
            xnaModel     = null;
            indexBuffer  = ibuffer;
            vertexBuffer = vbuffer;

            defaultPosition = this.position = position;
            defaultRotation = this.rotation = rotation;
            defaultScale    = this.scale = scale;
        }
Ejemplo n.º 48
0
        public override void LoadContent()
        {
            LoadModel("SandP-Pirate");
            HealthModel  = Load("Core/cube");
            ExplodeSound = LoadSoundEffect("PirateExplode");
            HitSound     = LoadSoundEffect("PirateHit");
            BumpSound    = LoadSoundEffect("PirateBump");

            BeginRun();
        }
Ejemplo n.º 49
0
        // Create Model from model resource
        public Model(XnaModel model, Vector3 position = new Vector3(), Vector3 rotation = new Vector3(), float scale = 1f)
        {
            xnaModel     = model;
            indexBuffer  = null;
            vertexBuffer = null;

            defaultPosition = this.position = position;
            defaultRotation = this.rotation = rotation;
            defaultScale    = this.scale = scale;
        }
Ejemplo n.º 50
0
        /// <summary>
        /// Gets the animation data associated with the specified model.
        /// Works with models that are processed by Nine.Pipeline.Processors.ExtendedModelProcessor.
        /// </summary>
        public static ICollection <string> GetAnimations(this Microsoft.Xna.Framework.Graphics.Model model)
        {
            ModelTag extensions = model.Tag as ModelTag;

            if (extensions != null && extensions.Animations != null)
            {
                return(extensions.Animations.Keys);
            }
            return(EmptyStringCollection);
        }
Ejemplo n.º 51
0
 /// <summary>
 /// Converts all the effects of the Model to a new effect.
 /// Materials (Diffuse, Emissive, etc) and textures parameters are copied to the new effect.
 /// </summary>
 /// <remarks>
 /// This function requires the effect to be either build in effect or effects
 /// that implements IEffectMaterial or IEffectTexture.
 /// </remarks>
 public static void ConvertEffectTo(this Microsoft.Xna.Framework.Graphics.Model model, Effect effect)
 {
     foreach (var mesh in model.Meshes)
     {
         foreach (var part in mesh.MeshParts)
         {
             part.ConvertEffectTo(effect.Clone());
         }
     }
 }
Ejemplo n.º 52
0
 /// <summary>
 /// Gets all the effects in the model.
 /// </summary>
 public static IEnumerable <Effect> GetEffects(this Microsoft.Xna.Framework.Graphics.Model model)
 {
     foreach (var mesh in model.Meshes)
     {
         foreach (var part in mesh.MeshParts)
         {
             yield return(part.Effect);
         }
     }
 }
Ejemplo n.º 53
0
        /// <summary>
        /// Copies the positions of the model mesh part to the target array.
        /// The positions are not transformed by the transform of the model mesh.
        /// </summary>
        private static int CopyPositionsTo(this Microsoft.Xna.Framework.Graphics.Model model, Microsoft.Xna.Framework.Graphics.ModelMesh mesh, ModelMeshPart part, Vector3[] positions, int startIndex)
        {
            int stride       = part.VertexBuffer.VertexDeclaration.VertexStride;
            int elementCount = part.NumVertices;

            if (positions != null)
            {
                part.VertexBuffer.GetData <Vector3>(part.VertexOffset * stride, positions, startIndex, elementCount, stride);
            }
            return(elementCount);
        }
Ejemplo n.º 54
0
 /// <summary>
 /// Dispose
 /// </summary>
 /// <param name="disposing">Disposing</param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         // Just set everything to null so we stop using this!
         name         = "";
         xnaModel     = null;
         transforms   = null;
         animatedMesh = null;
     }
 }
Ejemplo n.º 55
0
        /// <summary>
        /// Computes the bounding box for the specified xna model.
        /// </summary>
        public static BoundingBox ComputeBoundingBox(this Microsoft.Xna.Framework.Graphics.Model model, Microsoft.Xna.Framework.Graphics.ModelMesh mesh, ModelMeshPart part)
        {
            // Try to use vertices of the mesh
            BoundingBox result = new BoundingBox();

            if (ComputeBoundingBoxFromVertices(model, mesh, part, null, out result))
            {
                return(result);
            }

            // Now use bounding spheres
            return(BoundingBox.CreateFromSphere(mesh.BoundingSphere));
        }
Ejemplo n.º 56
0
        /// <summary>
        /// Gets the aboslute transform of the specified bone.
        /// </summary>
        public static Matrix GetAbsoluteBoneTransform(this Microsoft.Xna.Framework.Graphics.Model model, int boneIndex)
        {
            ModelBone bone = model.Bones[boneIndex];
            Matrix    absoluteTransform = bone.Transform;

            while (bone.Parent != null)
            {
                bone = bone.Parent;
                absoluteTransform = absoluteTransform * bone.Transform;
            }

            return(absoluteTransform);
        }
Ejemplo n.º 57
0
        /// <summary>
        /// Gets the animation data associated with the specified model.
        /// Works with models that are processed by Nine.Pipeline.Processors.ExtendedModelProcessor.
        /// </summary>
        public static BoneAnimationClip GetAnimation(this Microsoft.Xna.Framework.Graphics.Model model, string name)
        {
            ModelTag extensions = model.Tag as ModelTag;

            if (extensions != null && extensions.Animations != null)
            {
                BoneAnimationClip clip = null;
                extensions.Animations.TryGetValue(name, out clip);
                return(clip);
            }

            return(null);
        }
Ejemplo n.º 58
0
        public Picking(GraphicsDeviceManager manager, GraphicsDevice device, ContentManager content)
        {
            Manager = manager;
            Device  = device;
            Content = content;

            Model   = Content.Load <Microsoft.Xna.Framework.Graphics.Model>(@"Cube\Cube1x1");
            Actions = new Dictionary <string, Action>();

            Lambda        = 1;
            MaxLambda     = 30;
            CurrentAction = "NOTHING";
            Actions.Add("NOTHING", new Action(() => { }));
        }
Ejemplo n.º 59
0
        public override void LoadContent()
        {
            base.LoadContent();

            if (!string.IsNullOrEmpty(_assetName) && Content == null)
            {
                // Create a name for our object
                Name = _assetName + Game.Components.Count;

                if (GameScreen != null)
                {
                    // load using our scene manager
                    Content = GameScreen.Content.Load <Microsoft.Xna.Framework.Graphics.Model>(_assetName);
                }
                else
                {
                    // Load without our scene manager
                    Content = Game.Content.Load <Microsoft.Xna.Framework.Graphics.Model>(_assetName);
                }
            }

            if (Content != null)
            {
                // Be sure the Device is not currently holding any DATA!
                //GraphicsDevice.Vertices[0].SetSource(null, 0, 0);
                GraphicsDevice.Indices = null;

                // Generate our Bounding Box / Why are we not factoring in Scale here?
                foreach (ModelMesh mesh in Content.Meshes)
                {
                    foreach (ModelMeshPart part in mesh.MeshParts)
                    {
                        VertexPositionNormalTexture[] verts = new VertexPositionNormalTexture[part.NumVertices];
                        part.VertexBuffer.GetData(verts);
                        //mesh.VertexBuffer.GetData(verts);

                        // Loop thru and get our points
                        Vector3[] pos = new Vector3[verts.Length];
                        for (int i = 0; i < verts.Length; i++)
                        {
                            pos[i] = verts[i].Position;
                        }

                        // Create our Bounding Box from our models vertice positions
                        _boundingBox = BoundingBox.CreateFromPoints(pos);
                    }
                }
            }
        }
Ejemplo n.º 60
0
        /// <summary>
        /// Copies the indices of the model mesh part to the target array.
        /// </summary>
        private static int CopyIndicesTo(this Microsoft.Xna.Framework.Graphics.Model model, Microsoft.Xna.Framework.Graphics.ModelMesh mesh, ModelMeshPart part, ushort[] indices, int startIndex)
        {
            int indexCount = part.PrimitiveCount * 3;

            if (part.IndexBuffer.IndexElementSize == IndexElementSize.ThirtyTwoBits)
            {
                throw new NotSupportedException();
            }

            if (indices != null)
            {
                part.IndexBuffer.GetData <ushort>(part.StartIndex * 2, indices, startIndex, indexCount);
            }
            return(indexCount);
        }