Example #1
0
        private GeometryNode ShootBullet; //Geometry for Bullet

        #endregion Fields

        #region Constructors

        public Bullet(Vector3 InitPos, PrimitiveModel BulletModel, Material Material, Vector3 DirBullet, MarkerNode grdMarkerNode)
        {
            //Create Bullet
            ShootBullet = new GeometryNode();
            ShootBullet.Name = "ShootBullet" + ShootBullet.ID;
            ShootBullet.Model = BulletModel;

            ShootBullet.Material = Material;
            ShootBullet.Physics.Interactable = true;
            ShootBullet.Physics.Collidable = true;
            ShootBullet.Physics.Shape = GoblinXNA.Physics.ShapeType.Box;
            ShootBullet.Physics.Mass = 60f;
            ShootBullet.Physics.MaterialName = "Bullet";
            ShootBullet.AddToPhysicsEngine = true;

            // Assign the initial velocity to this shooting box
            ShootBullet.Physics.InitialLinearVelocity = new Vector3(DirBullet.X * 80, DirBullet.Y * 80, DirBullet.Z * 50);

            BulletTrans = new TransformNode();
            BulletTrans.Translation = InitPos;

            grdMarkerNode.AddChild(BulletTrans);
            BulletTrans.AddChild(ShootBullet);

            //Normal asignament
            isvisible = true;

            //Agrego Segundo desde que se creo
            livetime = Convert.ToInt32(DateTime.Now.TimeOfDay.TotalSeconds) + BULLET_TIMELIVE;
        }
Example #2
0
        /// <summary>
        /// Copies only the geometry (Mesh, customMesh, AnimatedMesh,
        /// MinimumBoundingBox, MinimumBoundingSphere, TriangleCount and Transforms)
        /// </summary>
        /// <param name="model">A source model from which to copy</param>
        public virtual void CopyGeometry(IModel model)
        {
            if (!(model is PrimitiveModel))
            {
                return;
            }

            PrimitiveModel srcModel = (PrimitiveModel)model;

            vertices.AddRange(((IPhysicsMeshProvider)model).Vertices);
            indices.AddRange(((IPhysicsMeshProvider)model).Indices);
            customMesh = srcModel.customMesh;

            triangleCount  = srcModel.TriangleCount;
            boundingBox    = srcModel.MinimumBoundingBox;
            boundingSphere = srcModel.MinimumBoundingSphere;
        }
Example #3
0
        TransformNode parentTNodeGrd; //Parent for all Scene Objects

        #endregion Fields

        #region Constructors

        public Graphics3D(MarkerNode MarkerNode, IShadowMap ShadowMap)
        {
            //Asignation Ground Node
            this.groundMarkerNode = MarkerNode;
            //Asignation Shadow Map
            this.GShadowMap = ShadowMap;

            //Add Big Parent for All Scenary Elements
            parentTNodeGrd = new TransformNode();
            parentTNodeGrd.Name = "Level";
            groundMarkerNode.AddChild(parentTNodeGrd);

            // Create a material for the model
            BulletrMat = new Material();
            BulletrMat.Diffuse = Color.Blue.ToVector4();
            BulletrMat.Specular = Color.White.ToVector4();
            BulletrMat.SpecularPower = 10;

            //create Bullet Model
            BulletModel = new TexturedBox(2.0f);

            LoadLevel = false;
            LoadCars = false;
        }
Example #4
0
        private void CreateObject()
        {
            // Create a primitive mesh for creating our custom pyramid shape
            CustomMesh pyramid = new CustomMesh();

            // Even though we really need 5 vertices to create a pyramid shape, since
            // we want to assign different normals for points with same position to have
            // more accurate lighting effect, we will use 16 vertices.
            // Also, we want to have position, normal, and texture information in our
            // vertices, we'll use VertexPositionNormalTexture format. There are other
            // types of Vertex format as well depending on your needs. 
            VertexPositionNormalTexture[] verts = new VertexPositionNormalTexture[16];

            // Create a pyramid with 8x8 base and height of 6
            Vector3 vBase0 = new Vector3(-4, 0, 4);
            Vector3 vBase1 = new Vector3(4, 0, 4);
            Vector3 vBase2 = new Vector3(4, 0, -4);
            Vector3 vBase3 = new Vector3(-4, 0, -4);
            Vector3 vTop = new Vector3(0, 6, 0);

            verts[0].Position = vTop;
            verts[1].Position = vBase1;
            verts[2].Position = vBase0;

            verts[3].Position = vTop;
            verts[4].Position = vBase2;
            verts[5].Position = vBase1;

            verts[6].Position = vTop;
            verts[7].Position = vBase3;
            verts[8].Position = vBase2;

            verts[9].Position = vTop;
            verts[10].Position = vBase0;
            verts[11].Position = vBase3;

            verts[12].Position = vBase0;
            verts[13].Position = vBase1;
            verts[14].Position = vBase2;
            verts[15].Position = vBase3;

            verts[0].Normal = verts[1].Normal = verts[2].Normal = CalcNormal(vTop, vBase1, vBase0);
            verts[3].Normal = verts[4].Normal = verts[5].Normal = CalcNormal(vTop, vBase2, vBase1);
            verts[6].Normal = verts[7].Normal = verts[8].Normal = CalcNormal(vTop, vBase3, vBase2);
            verts[9].Normal = verts[10].Normal = verts[11].Normal = CalcNormal(vTop, vBase0, vBase3);
            verts[12].Normal = verts[13].Normal = verts[14].Normal = verts[15].Normal = CalcNormal(vBase0, 
                vBase1, vBase3);

            Vector2 texCoordTop = new Vector2(0.5f, 0);
            Vector2 texCoordLeftBase = new Vector2(0, 1);
            Vector2 texCoordRightBase = new Vector2(1, 1);

            verts[0].TextureCoordinate = texCoordTop;
            verts[1].TextureCoordinate = texCoordLeftBase;
            verts[2].TextureCoordinate = texCoordRightBase;

            verts[3].TextureCoordinate = texCoordTop;
            verts[4].TextureCoordinate = texCoordLeftBase;
            verts[5].TextureCoordinate = texCoordRightBase;

            verts[6].TextureCoordinate = texCoordTop;
            verts[7].TextureCoordinate = texCoordLeftBase;
            verts[8].TextureCoordinate = texCoordRightBase;

            verts[9].TextureCoordinate = texCoordTop;
            verts[10].TextureCoordinate = texCoordLeftBase;
            verts[11].TextureCoordinate = texCoordRightBase;

            verts[12].TextureCoordinate = new Vector2(1, 1);
            verts[13].TextureCoordinate = new Vector2(1, 0);
            verts[14].TextureCoordinate = new Vector2(0, 0);
            verts[15].TextureCoordinate = new Vector2(0, 1);

            pyramid.VertexBuffer = new VertexBuffer(graphics.GraphicsDevice, 
                typeof(VertexPositionNormalTexture), 16, BufferUsage.None);
            pyramid.VertexDeclaration = VertexPositionNormalTexture.VertexDeclaration;
            pyramid.VertexBuffer.SetData(verts);
            pyramid.NumberOfVertices = 16;

            short[] indices = new short[18];

            indices[0] = 0;
            indices[1] = 1;
            indices[2] = 2;

            indices[3] = 3;
            indices[4] = 4;
            indices[5] = 5;

            indices[6] = 6;
            indices[7] = 7;
            indices[8] = 8;

            indices[9] = 9;
            indices[10] = 10;
            indices[11] = 11;

            indices[12] = 12;
            indices[13] = 13;
            indices[14] = 15;

            indices[15] = 13;
            indices[16] = 14;
            indices[17] = 15;

            pyramid.IndexBuffer = new IndexBuffer(graphics.GraphicsDevice, typeof(short), 18, 
                BufferUsage.WriteOnly);
            pyramid.IndexBuffer.SetData(indices);

            pyramid.PrimitiveType = PrimitiveType.TriangleList;
            pyramid.NumberOfPrimitives = 6;

            PrimitiveModel pyramidModel = new PrimitiveModel(pyramid);

            GeometryNode pyramidNode = new GeometryNode();
            pyramidNode.Model = pyramidModel;

            Material pyramidMaterial = new Material();
            pyramidMaterial.Diffuse = Color.White.ToVector4();
            pyramidMaterial.Specular = Color.White.ToVector4();
            pyramidMaterial.SpecularPower = 10;
            pyramidMaterial.Texture = Content.Load<Texture2D>("brick_wall_14");

            pyramidNode.Material = pyramidMaterial;

            scene.RootNode.AddChild(pyramidNode);
        }
Example #5
0
        private List<Bullet> WBullets; //Bullets For Weapon

        #endregion Fields

        #region Constructors

        public Game_Weapon(PrimitiveModel BulletModel, Material BulletMaterial, MarkerNode GrdMarkerNode)
        {
            FOV = NORMAL_FOV;
            DeltaGiro = DELTA_THETA;
            Active = true;
            ActAngle = 0;
            InitAngle = 0;
            MaxAng = 360;
            RadActAngle = 0;
            GirDir = RotDirection.RECHS;
            RotaMode = RotMode.CONTINUE;

            this.BulletModel = BulletModel;
            BulletMat = BulletMaterial;
            GMarkerNode = GrdMarkerNode;

            WBullets = new List<Bullet>();

            //Config type of Shoot
            WaitBullet = WAIT_SHOOT;
            CountToShoot = WaitBullet;
            ReloadTime = WAIT_RELOAD;
            CountToReload = 0;
            CountOfBullets = 0;
            NumBullets = Game_Logic.MAX_BULLET;

            RadOffset = Math.PI * (95) / 180.0;
            BulletOffset = new Vector3(0, 10, 30);
        }
Example #6
0
        private void CreateDominos()
        {
            dominoModel = new DominoBox(new Vector3(dominoSize.X, dominoSize.Z, dominoSize.Y),
                new Vector2(0.663f, 0.707f));

            dominoModel.ShadowAttribute = ShadowAttribute.ReceiveCast;
            dominoModel.Shader = new SimpleShadowShader(scene.ShadowMap);

            float radius = 18;
            for (int x = 0; x < 360; x += 30)
            {
                GeometryNode dominoNode = new GeometryNode("Domino " + dominos.Count);
                dominoNode.Model = dominoModel;

                dominoNode.Physics.Mass = 20;
                dominoNode.Physics.Shape = ShapeType.Box;
                dominoNode.Physics.MaterialName = "Domino";
                dominoNode.Physics.Pickable = true;
                dominoNode.AddToPhysicsEngine = true;

                Material dominoMaterial = new Material();
                dominoMaterial.Diffuse = Color.White.ToVector4();
                dominoMaterial.Specular = Color.White.ToVector4();
                dominoMaterial.SpecularPower = 10;
                dominoMaterial.Texture = cguiLogoTexture;

                dominoNode.Material = dominoMaterial;

                TransformNode dominoTransNode = new TransformNode();
                dominoTransNode.Translation = new Vector3(
                    (float)(radius * Math.Cos(MathHelper.ToRadians(x))),
                    radius * (float)(Math.Sin(MathHelper.ToRadians(x))), dominoSize.Y / 2);
                dominoTransNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ,
                    MathHelper.ToRadians(x + 90));

                markerNode.AddChild(dominoTransNode);

                dominoTransNode.AddChild(dominoNode);

                dominos.Add(dominoNode);
            }
        }
Example #7
0
        private void CreateObjects()
        {
            // Create a model of box and sphere
            boxModel = new Box(Vector3.One);
            PrimitiveModel sphereModel = new Sphere(1f, 20, 20);

            // Create our ground plane
            GeometryNode groundNode = new GeometryNode("Ground");
            groundNode.Model = boxModel;
            // Define the material name of this ground model
            groundNode.Physics.MaterialName = "Ground";
            // Make this ground plane collidable, so other collidable objects can collide
            // with this ground
            groundNode.Physics.Collidable = true;
            groundNode.Physics.Shape = GoblinXNA.Physics.ShapeType.Box;
            groundNode.AddToPhysicsEngine = true;

            // Create a material for the ground
            Material groundMaterial = new Material();
            groundMaterial.Diffuse = Color.LightGreen.ToVector4();
            groundMaterial.Specular = Color.White.ToVector4();
            groundMaterial.SpecularPower = 20;

            groundNode.Material = groundMaterial;

            // Create a parent transformation for both the ground and the sphere models
            TransformNode parentTransNode = new TransformNode();
            parentTransNode.Translation = new Vector3(0, -10, -20);

            // Create a scale transformation for the ground to make it bigger
            TransformNode groundScaleNode = new TransformNode();
            groundScaleNode.Scale = new Vector3(100, 1, 100);

            // Add this ground model to the scene
            scene.RootNode.AddChild(parentTransNode);
            parentTransNode.AddChild(groundScaleNode);
            groundScaleNode.AddChild(groundNode);

            // Create a material that will be applied to all of the sphere models
            Material sphereMaterial = new Material();
            sphereMaterial.Diffuse = Color.Cyan.ToVector4();
            sphereMaterial.Specular = Color.White.ToVector4();
            sphereMaterial.SpecularPower = 10;

            Random rand = new Random();

            // Create bunch of sphere models and pile them up
            for (int i = 0; i <= 0; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    TransformNode pileTrans = new TransformNode();
                    pileTrans.Translation = new Vector3(2 * j + (float)rand.NextDouble()/5, 2*i + 5f + (i + 1) * 0.05f,
                        0 + 0.01f * i + (float)rand.NextDouble()/5);

                    GeometryNode gNode = new GeometryNode("Sphere" + (10 * i + j));
                    gNode.Model = sphereModel;
                    gNode.Material = sphereMaterial;
                    // Make the sphere models interactable, which means that they
                    // participate in the physical simulation
                    gNode.Physics.Interactable = true;
                    gNode.Physics.Collidable = true;
                    gNode.Physics.Shape = GoblinXNA.Physics.ShapeType.Sphere;
                    gNode.Physics.Mass = 30f;
                    gNode.AddToPhysicsEngine = true;

                    parentTransNode.AddChild(pileTrans);
                    pileTrans.AddChild(gNode);
                }
            }

            // Create a material for shooting box models
            shooterMat = new Material();
            shooterMat.Diffuse = Color.Pink.ToVector4();
            shooterMat.Specular = Color.Yellow.ToVector4();
            shooterMat.SpecularPower = 10;
        }