Exemplo n.º 1
0
        private void CreateObject()
        {
            {
                // Create a sphere
                GeometryNode shape = new GeometryNode();
                shape.Model        = new Sphere(2, 30, 30);
                shape.Model.Shader = generalShader;

                // Create a material which we want to apply to a sphere model
                Material modelMaterial = new Material();
                modelMaterial.Diffuse       = new Vector4(1, 1, 1, 1);
                modelMaterial.Specular      = Color.White.ToVector4();
                modelMaterial.SpecularPower = 128f;
                //modelMaterial.Emissive = Color.Yellow.ToVector4();
                shape.Material = modelMaterial;

                sphereTrans             = new TransformNode();
                sphereTrans.Translation = new Vector3(0, 2, 0);
                sphereTrans.AddChild(shape);
                scene.RootNode.AddChild(sphereTrans);
            }

            {
                // Create a ground
                GeometryNode shape = new GeometryNode();
                shape.Model        = new Box(200, 0.01f, 200);
                shape.Model.Shader = generalShader;

                // Create a material which we want to apply to a ground model
                Material modelMaterial = new Material();
                modelMaterial.Diffuse       = new Vector4(1, 1, 1, 1);
                modelMaterial.SpecularPower = 64f;


                shape.Material = modelMaterial;

                TransformNode trans = new TransformNode();
                trans.Translation = new Vector3(0, 0, 0);
                trans.AddChild(shape);
                scene.RootNode.AddChild(trans);
            }

            {
                // Create a box
                GeometryNode shape = new GeometryNode();
                shape.Model        = new Box(2);
                shape.Model.Shader = generalShader;

                // Create a material which we want to apply to a box model
                Material modelMaterial = new Material();
                modelMaterial.Diffuse = new Vector4(1, 1, 1, 1);

                shape.Material = modelMaterial;

                floorTrans             = new TransformNode();
                floorTrans.Translation = new Vector3(10, 1, 0);
                floorTrans.AddChild(shape);
                scene.RootNode.AddChild(floorTrans);
            }
        }
Exemplo n.º 2
0
        public List<TransformNode> getListTransformNodes(Object PtID, Object EqID)
        {
            //create Box
            GeometryNode boxNode = new GeometryNode("Box");
            boxNode.Model = new Box(6);
            boxNode.Model.CastShadows = true;
            boxNode.Model.ReceiveShadows = true;
            Material boxMat = new Material();
            boxMat.Diffuse = Color.Blue.ToVector4();
            boxMat.Specular = Color.White.ToVector4();
            boxMat.SpecularPower = 20;
            boxNode.Material = boxMat;
            TransformNode boxTrans = new TransformNode();
            boxTrans.Translation = new Vector3(-35, -18, 8);
            boxTrans.AddChild(boxNode);

            //Create cylinder
            GeometryNode cylinderNode = new GeometryNode("Cylinder");
            cylinderNode.Model = new Cylinder(3.5f, 3.5f, 10, 20);
            cylinderNode.Model.CastShadows = true;
            cylinderNode.Model.ReceiveShadows = true;
            Material cylinderMat = new Material();
            cylinderMat.Diffuse = Color.Green.ToVector4();
            cylinderMat.Specular = Color.White.ToVector4();
            cylinderMat.SpecularPower = 20;
            cylinderNode.Material = cylinderMat;
            TransformNode cylinderTrans = new TransformNode();
            cylinderTrans.Translation = new Vector3(35, -18, 8);
            cylinderTrans.AddChild(cylinderNode);

            List<TransformNode> nodes = new List<TransformNode>();
            nodes.Add(boxTrans);
            nodes.Add(cylinderTrans);
            return nodes;
        }
Exemplo n.º 3
0
        /********************* Helpers **********************/

        public static GeometryNode LoadModel(string DirModel, string Modelname, bool InternalMaterial)
        {
            GeometryNode MyNode = new GeometryNode(Modelname);
            //Intento cargar un modelo
            ModelLoader loader = new ModelLoader();

            MyNode.Physics.Mass         = 20;
            MyNode.Physics.Shape        = ShapeType.ConvexHull;
            MyNode.Physics.MaterialName = Modelname;
            MyNode.Physics.ApplyGravity = true;
            //Debo probar mas esta propiedad
            MyNode.Physics.NeverDeactivate = true;
            MyNode.AddToPhysicsEngine      = true;

            //Load Model
            MyNode.Model = (Model)loader.Load(DirModel, Modelname);

            //Define Material
            if (InternalMaterial)
            {
                ((Model)MyNode.Model).UseInternalMaterials = true;
            }
            else
            {
                // Create a material for the Model
                Material ModelMat = new Material();
                ModelMat.Diffuse       = Color.Blue.ToVector4();
                ModelMat.Specular      = Color.White.ToVector4();
                ModelMat.SpecularPower = 20;
                //Add Material
                MyNode.Material = ModelMat;
            }

            return(MyNode);
        }
Exemplo n.º 4
0
        private void create(string name)
        {
            geomNode = new GeometryNode(name);

            if (name.Equals("cube"))
            {
                geomNode.Model = new Box(20);

                // Create a material to apply to the box model
                Material cubeMaterial = new Material();
                cubeMaterial.Diffuse       = Color.Tomato.ToVector4();
                cubeMaterial.Specular      = Color.White.ToVector4();
                cubeMaterial.SpecularPower = 5;

                geomNode.Material = cubeMaterial;
            }
            else if (name.Equals("sphere"))
            {
                geomNode.Model = new Sphere(1, 20, 20);

                // Create a material to apply to the ball
                Material ballMaterial = new Material();
                ballMaterial.Diffuse       = Color.SteelBlue.ToVector4();
                ballMaterial.Specular      = Color.White.ToVector4();
                ballMaterial.SpecularPower = 5;

                geomNode.Material = ballMaterial;
            }
        }
Exemplo n.º 5
0
        public void CreateGround(bool Occluder)
        {
            GeometryNode groundNode = new GeometryNode("Ground");

            //Cordenates X, y, Z
            groundNode.Model = new TexturedBox(324, 180, 0.1f);

            // Set this model Occluded ist or not
            groundNode.IsOccluder = Occluder;

            //Setup Physics Aspecte
            groundNode.Physics.Collidable   = true;
            groundNode.Physics.Shape        = GoblinXNA.Physics.ShapeType.Box;
            groundNode.Physics.MaterialName = "Ground";
            groundNode.AddToPhysicsEngine   = true;

            // Make the ground model to receive shadow casted by other objects
            groundNode.Model.ShadowAttribute = ShadowAttribute.ReceiveOnly;
            // Assign a shadow shader
            groundNode.Model.Shader = new SimpleShadowShader(GShadowMap);

            //Material
            Material groundMaterial = new Material();

            groundMaterial.Diffuse       = Color.Gray.ToVector4();
            groundMaterial.Specular      = Color.White.ToVector4();
            groundMaterial.SpecularPower = 20;

            //Assig Material
            groundNode.Material = groundMaterial;

            //Add Model in the Scene
            parentTNodeGrd.AddChild(groundNode);
        }
Exemplo n.º 6
0
        public void CreateShootBullet(Vector3 InitPos, Vector3 DirBullet, Color BulletColor)
        {
            if (BulletID == 20)
            {
                return;
            }

            GeometryNode ShootBullet = new GeometryNode("ShootBullet" + BulletID++);

            ShootBullet.Model = BulletModel;

            BulletrMat.Diffuse = BulletColor.ToVector4();

            ShootBullet.Material             = BulletrMat;
            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);

            TransformNode BulletTrans = new TransformNode();

            BulletTrans.Translation = InitPos;

            groundMarkerNode.AddChild(BulletTrans);
            BulletTrans.AddChild(ShootBullet);
        }
Exemplo n.º 7
0
        /********************* Basic Elements ****************/

        public GeometryNode CreateCube(MarkerNode Marker, Vector4 CubeColor)
        {
            GeometryNode boxNode;

            // Create a geometry node with a model of a box
            boxNode       = new GeometryNode("Box");
            boxNode.Model = new TexturedBox(32.4f);

            // Add this box model to the physics engine for collision detection
            boxNode.AddToPhysicsEngine = true;
            boxNode.Physics.Shape      = ShapeType.Box;
            // Make this box model cast and receive shadows
            boxNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;
            // Assign a shadow shader for this model that uses the IShadowMap we assigned to the scene
            boxNode.Model.Shader = new SimpleShadowShader(GShadowMap);

            // Create a material to apply to the box model
            Material boxMaterial = new Material();

            boxMaterial.Diffuse       = CubeColor;
            boxMaterial.Specular      = Color.White.ToVector4();
            boxMaterial.SpecularPower = 10;

            boxNode.Material = boxMaterial;

            // Add this box model node to the ground marker node
            Marker.AddChild(boxNode);

            return(boxNode);

            // Create a collision pair and add a collision callback function that will be
            // called when the pair collides
            //NewtonPhysics.CollisionPair pair = new NewtonPhysics.CollisionPair(boxNode.Physics, sphereNode.Physics);
            //((NewtonPhysics)scene.PhysicsEngine).AddCollisionCallback(pair, BoxSphereCollision);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Shoot a box from the clicked mouse location
        /// </summary>
        /// <param name="near"></param>
        /// <param name="far"></param>
        private void ShootBox(Vector3 near, Vector3 far)
        {
            GeometryNode shootBox = new GeometryNode("ShooterBox" + shooterID++);

            shootBox.Model    = boxModel;
            shootBox.Material = shooterMat;
#if !WINDOWS
            shootBox.Physics = new MataliObject(shootBox);
            ((MataliObject)shootBox.Physics).CollisionStartCallback = BoxCollideWithGround;
#endif
            // Define the material name of this shooting box model
            shootBox.Physics.MaterialName = "ShootingBox";
            shootBox.Physics.Interactable = true;
            shootBox.Physics.Collidable   = true;
            shootBox.Physics.Shape        = GoblinXNA.Physics.ShapeType.Box;
            shootBox.Physics.Mass         = 60f;
            shootBox.AddToPhysicsEngine   = true;

            // Calculate the direction to shoot the box based on the near and far point
            Vector3 linVel = far - near;
            linVel.Normalize();
            // Multiply the direction with the velocity of 20
            linVel *= 20f;

            // Assign the initial velocity to this shooting box
            shootBox.Physics.InitialLinearVelocity = linVel;

            TransformNode shooterTrans = new TransformNode();
            shooterTrans.Translation = near;

            scene.RootNode.AddChild(shooterTrans);
            shooterTrans.AddChild(shootBox);
        }
Exemplo n.º 9
0
        public static GeometryNode AddModel(MarkerNode Marker, String Folder, String Model, bool IntMaterial, float Scala)
        {
            GeometryNode ObstNode;

            if (Model == "null")
            {
                return(ObstNode = new GeometryNode());
            }

            ObstNode = Graphics3D.LoadModel("Models/" + Folder, Model, IntMaterial);

            //define the Physic Material name
            ObstNode.Physics.MaterialName = "Obstacle";

            TransformNode parentTransNode = new TransformNode();

            parentTransNode.Name     = Model;
            parentTransNode.Scale    = new Vector3(Scala, Scala + 2, Scala);
            parentTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), MathHelper.ToRadians(90));
            //Add Rotation because Blender Axis
            parentTransNode.AddChild(ObstNode);

            // Add this box model node to the ground marker node
            if (Marker != null)
            {
                Marker.AddChild(parentTransNode);
            }

            return(ObstNode);
        }
Exemplo n.º 10
0
        public static RaceCar AddRaceCar(Scene scene, TransformNode Marke, Vector3 CarPos, GeometryNode CModel, int IdPlayer)
        {
            TransformNode transNode = new TransformNode();
            transNode.Name = "Tcar:" + IdPlayer;
            transNode.Translation = CarPos;

            CModel.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;

            NewtonPhysics physicsEngine = (NewtonPhysics)scene.PhysicsEngine;

            RaceCar car = new RaceCar(CModel, physicsEngine);
            for (int i = 0; i < 4; i++)
                car.Tires[i] = CreateTire((TireID)Enum.ToObject(typeof(TireID), i),
                    car.TireTransformNode[i], CModel, scene.PhysicsEngine.Gravity);

            car.Collidable = true;
            car.Interactable = true;
            car.StartPos = CarPos;
            //Physic material Name
            car.MaterialName = "Car" + IdPlayer;

            CModel.Physics = car;
            CModel.Physics.NeverDeactivate = true;
            CModel.AddToPhysicsEngine = true;

            //Add To node
            transNode.AddChild(CModel);
            Marke.AddChild(transNode);

            Newton.NewtonSetBodyLeaveWorldEvent(physicsEngine.NewtonWorld,
                car.LeaveWorldCallback);

            return car;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Shoot a box from the clicked mouse location
        /// </summary>
        /// <param name="near"></param>
        /// <param name="far"></param>
        private void ShootBox(Vector3 near, Vector3 far)
        {
            GeometryNode shootBox = new GeometryNode("ShooterBox" + shooterID++);

            shootBox.Model                = boxModel;
            shootBox.Material             = shooterMat;
            shootBox.Physics.Interactable = true;
            shootBox.Physics.Collidable   = true;
            shootBox.Physics.Shape        = GoblinXNA.Physics.ShapeType.Box;
            shootBox.Physics.Mass         = 60f;
            shootBox.AddToPhysicsEngine   = true;

            // Calculate the direction to shoot the box based on the near and far point
            Vector3 linVel = far - near;

            linVel.Normalize();
            // Multiply the direction with the velocity of 20
            linVel *= 30f;

            // Assign the initial velocity to this shooting box
            shootBox.Physics.InitialLinearVelocity = linVel;

            TransformNode shooterTrans = new TransformNode();

            shooterTrans.Translation = near;

            scene.RootNode.AddChild(shooterTrans);
            shooterTrans.AddChild(shootBox);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Creates a camera that chases a given object.
        /// </summary>
        /// <param name="chasedObject"></param>
        private void CreateChasingCamera(GeometryNode chasedObject)
        {
            // Set up the camera of the scene graph
            Camera camera = new Camera();

            camera.Translation = new Vector3(5, 3, 0);
            // Rotate the camera -20 degrees along the X axis
            camera.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY,
                                                             MathHelper.ToRadians(90)) * Quaternion.CreateFromAxisAngle(Vector3.UnitX,
                                                                                                                        MathHelper.ToRadians(-20));
            // Set the vertical field of view to be 60 degrees
            camera.FieldOfViewY = MathHelper.ToRadians(45);
            // Set the near clipping plane to be 0.1f unit away from the camera
            camera.ZNearPlane = 0.1f;
            // Set the far clipping plane to be 1000 units away from the camera
            camera.ZFarPlane = 1000;

            // Add this camera node to a geometry node we want to chase for
            CameraNode cameraNode = new CameraNode("ChasingCamera", camera);

            chasedObject.AddChild(cameraNode);

            // Initially assign the chasing camera to be our scene graph's active camera node
            scene.CameraNode = cameraNode;
        }
Exemplo n.º 13
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;
        }
Exemplo n.º 14
0
        private void createObj(int type, Vector3 dim)
        {
            geomNode = new GeometryNode("powerup" + type);

            geomNode.Model = new Box(dim.X, dim.Y, dim.Z);

            // Create a material to apply to the wall
            Material powerMaterial = new Material();
            Vector4  color;

            if (powerUpType == type)
            {
                color = Color.Black.ToVector4();
            }
            else
            {
                color = Color.DarkRed.ToVector4();
            }

            powerMaterial.Diffuse       = color;
            powerMaterial.Specular      = color;
            powerMaterial.SpecularPower = 5;

            geomNode.Material = powerMaterial;

            transNode = new TransformNode();
            transNode.AddChild(geomNode);
        }
Exemplo n.º 15
0
        private void createCorderBackground()
        {
            cornerPanelTransformNode = new TransformNode("Corner Panel Trans");
            scene.RootNode.AddChild(cornerPanelTransformNode);

            cornerPanelNode       = new GeometryNode("Corner Panel");
            cornerPanelNode.Model = new TexturedLayer(new Vector2(250, 250));//new Box(300, 250, 1);
            cornerPanelTransformNode.AddChild(cornerPanelNode);


            cornerPanelTransformNode.Translation = new Vector3(2.3f, -1.58f, -5);
            cornerPanelTransformNode.Rotation    = Quaternion.CreateFromAxisAngle(Vector3.UnitX, MathHelper.ToRadians(90));
            //cornerPanelTransformNode.Translation = new Vector3(0, .06f, -1);

            cornerPanelTransformNode.Scale = new Vector3(0.005f, 0.005f, 0.005f);

            Material pointerLabelMaterial = new Material();

            pointerLabelMaterial.Diffuse = Color.White.ToVector4();; // new Vector4(0, 0.5f, 0, 1);
            // pointerLabelMaterial.Specular = Color.White.ToVector4();
            // pointerLabelMaterial.SpecularPower = 50;
            pointerLabelMaterial.Texture = Content.Load <Texture2D>("hud/cornerPanel");

            cornerPanelNode.Material = pointerLabelMaterial;

            //cornerPanelTransformNode.SetAlpha(0.55f);
            Vector4 tempColor = cornerPanelNode.Material.Diffuse;
            Vector3 tempVec   = new Vector3(tempColor.X, tempColor.Y, tempColor.Z);

            cornerPanelNode.Material.Diffuse = new Vector4(tempVec, 0.7f);
        }
Exemplo n.º 16
0
        private void CreateObjects()
        {
            float size = 4.0f;

            // Create a marker node to track a feature-based image.
            // NOTE: If you get an exception here, that means you haven't generated the .dat file yet
            // Please see this
            MarkerNode groundMarkerNode = new MarkerNode(scene.MarkerTracker, "markerless.png.dat");

            // Now add the above nodes to the scene graph in the appropriate order.
            // Note that only the nodes added below the marker node are affected by
            // the marker transformation.
            scene.RootNode.AddChild(groundMarkerNode);

            // Create a geometry node with a model of a box that will be overlaid on top of the image
            GeometryNode boxNode = new GeometryNode("Box")
            {
                Model    = new Box(size),
                Material = new Material()
                {
                    Diffuse       = Color.Red.ToVector4(),
                    Specular      = Color.White.ToVector4(),
                    SpecularPower = 10
                }
            };

            TransformNode boxTrans = new TransformNode()
            {
                Translation = new Vector3(0, 0, -size / 2)
            };

            groundMarkerNode.AddChild(boxTrans);
            boxTrans.AddChild(boxNode);
        }
Exemplo n.º 17
0
        private void CreateGround()
        {
            GeometryNode groundNode = new GeometryNode("Ground");

            // We will use TexturedBox instead of regular Box class since we will need the
            // texture coordinates elements for passing the vertices to the SimpleShadowShader
            // we will be using
            groundNode.Model = new TexturedBox(324, 180, 0.1f);

            // Set this ground model to act as an occluder so that it appears transparent
            groundNode.IsOccluder = true;

            // Make the ground model to receive shadow casted by other objects with
            // ShadowAttribute.ReceiveCast
            groundNode.Model.ShadowAttribute = ShadowAttribute.ReceiveOnly;
            // Assign a shadow shader for this model that uses the IShadowMap we assigned to the scene
            groundNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap);

            Material groundMaterial = new Material();

            groundMaterial.Diffuse       = Color.Gray.ToVector4();
            groundMaterial.Specular      = Color.White.ToVector4();
            groundMaterial.SpecularPower = 20;

            groundNode.Material = groundMaterial;

            groundMarkerNode.AddChild(groundNode);
        }
Exemplo n.º 18
0
        private TransformNode BulletTrans;          //Transfor Node for Bullet

        #endregion

        #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;
        }
Exemplo n.º 19
0
        List <Attribute> attributes = new List <Attribute>(); //size 8

        //Constructors
        public Building(ref GlobalVariables g)
        {
            global = g;

            buildingGeomNode  = new GeometryNode();
            buildingMaterial  = new Material();
            buildingTransNode = new TransformNode();
        }
Exemplo n.º 20
0
        private void load(string name)
        {
            ModelLoader loader = new ModelLoader();

            geomNode       = new GeometryNode(name);
            geomNode.Model = (Model)loader.Load("", name);
            ((Model)geomNode.Model).UseInternalMaterials = true;
        }
Exemplo n.º 21
0
        private static void SetPolygonData(GeometryNode Polygon, Obj obj, int LodLevel)
        {
            if (Polygon.LODs.Count <= LodLevel)
            {
                for (int i = Polygon.LODs.Count - 1; i < LodLevel; ++i)
                {
                    Polygon.LODs.Add(new ServiceUtilities.Process.Geometry.LOD());
                }
            }

            ServiceUtilities.Process.Geometry.VertexNormalTangent[] VertexTangentNormals = new ServiceUtilities.Process.Geometry.VertexNormalTangent[obj.VertexList.Count];

            //Assumes triangulated faces
            for (int i = 0; i < obj.FaceList.Count; ++i)
            {
                for (int c = 0; c < 3; c++)
                {
                    Vertex       v1  = obj.VertexList[obj.FaceList[i].VertexIndexList[c] - 1];
                    VertexNormal vn1 = obj.NormalList[obj.FaceList[i].VertexNormalIndexList[c] - 1];

                    int CurrentIndex = v1.Index - 1;

                    Polygon.LODs[LodLevel].Indexes.Add((uint)CurrentIndex);

                    if (VertexTangentNormals[CurrentIndex] == null)
                    {
                        VertexTangentNormals[CurrentIndex] = new ServiceUtilities.Process.Geometry.VertexNormalTangent();
                    }

                    if (VertexTangentNormals[CurrentIndex].Vertex == null)
                    {
                        VertexTangentNormals[CurrentIndex].Vertex = new ServiceUtilities.Process.Geometry.Vector3D((float)v1.X * 100, (float)v1.Y * 100, (float)v1.Z * 100);
                    }
                    else
                    {
                        VertexTangentNormals[CurrentIndex].Vertex.X = (float)v1.X * 100;
                        VertexTangentNormals[CurrentIndex].Vertex.Y = (float)v1.Y * 100;
                        VertexTangentNormals[CurrentIndex].Vertex.Z = (float)v1.Z * 100;
                    }

                    if (VertexTangentNormals[CurrentIndex].Normal == null)
                    {
                        VertexTangentNormals[CurrentIndex].Normal = new ServiceUtilities.Process.Geometry.Vector3D((float)vn1.X, (float)vn1.Y, (float)vn1.Z);
                    }
                    else
                    {
                        VertexTangentNormals[CurrentIndex].Normal.X = (float)vn1.X;
                        VertexTangentNormals[CurrentIndex].Normal.Y = (float)vn1.Y;
                        VertexTangentNormals[CurrentIndex].Normal.Z = (float)vn1.Z;
                    }
                }
                //Index++;
            }

            Polygon.LODs[LodLevel].VertexNormalTangentList = new List <ServiceUtilities.Process.Geometry.VertexNormalTangent>(VertexTangentNormals);
            Polygon.LODs[LodLevel].Indexes.Reverse();
        }
Exemplo n.º 22
0
        private void SelectFromRoom()
        {
            // Now convert the near and far source to actual near and far 3D points based on our eye location
            // and view frustum
            Vector3 nearPoint = graphicsDevice.Viewport.Unproject(nearSource,
                                                                  State.ProjectionMatrix, State.ViewMatrix, room.getMarkerTransform());
            Vector3 farPoint = graphicsDevice.Viewport.Unproject(farSource,
                                                                 State.ProjectionMatrix, State.ViewMatrix, room.getMarkerTransform());

            // Have the physics engine intersect the pick ray defined by the nearPoint and farPoint with
            // the physics objects in the scene (which we have set up to approximate the model geometry).
            List <PickedObject> pickedObjects = ((NewtonPhysics)scene.PhysicsEngine).PickRayCast(nearPoint, farPoint);

            // If one or more objects intersect with our ray vector
            if (pickedObjects.Count > 0)
            {
                // Since PickedObject can be compared (which means it implements IComparable), we can sort it in
                // the order of closest intersected object to farthest intersected object
                pickedObjects.Sort();

                // We only care about the closest picked object for now, so we'll simply display the name
                // of the closest picked object whose container is a geometry node
                //label = ((GeometryNode)pickedObjects[0].PickedPhysicsObject.Container).Name + " is picked";

                GeometryNode tempNode = new GeometryNode();
                int          i        = 0;
                tempNode = (GeometryNode)pickedObjects[i].PickedPhysicsObject.Container;
                while (tempNode.GroupID == room.roomGroupID && i + 1 < pickedObjects.Count)
                {
                    i++;
                    tempNode = (GeometryNode)pickedObjects[i].PickedPhysicsObject.Container;
                }

                //Console.WriteLine("Duplicating item from " + tempNode.Name);
                selectedItem = catalog.selectPlacedItem(tempNode.Name);

                if (tempNode.GroupID != room.roomGroupID)
                {
                    DrawSelectedItem(catalog.clonePlacedItem(tempNode.Name));
                }

                if (selectedItem != null)
                {
                    //Console.WriteLine("New item is " + selectedItem.Label);
                    setState(STATES.MANIPULATING);
                }
                else
                {
                    Console.WriteLine("No item received");
                }
            }
            else
            {
                Console.WriteLine("Nothing to select");
            }
        }
Exemplo n.º 23
0
        private void ProcessQueue(Action <string> _ErrorMessageAction, ManualResetEvent ProcessQueueWait, ConcurrentQueue <Node> ProcessQueue, EDeflateCompression QueueCompressMode)
        {
            BTaskWrapper.Run(() =>
            {
                try
                {
                    _ErrorMessageAction?.Invoke($"[{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fffff")}] Start processing Queue");
                    Dictionary <ENodeType, StreamStruct> WriteStreams = CreateStreams(QueueCompressMode);

                    using (XStreamWriter Writer = new XStreamWriter(WriteStreams))
                    {
                        while (!QueueComplete || ProcessQueue.Count > 0)
                        {
                            if (ProcessQueue.TryDequeue(out Node WriteNode))
                            {
                                if (WriteNode.GetNodeType() == ENodeType.Hierarchy)
                                {
                                    HierarchyNode CurrentHierarchyNode = (HierarchyNode)WriteNode;

                                    //Need to check that lists are not null
                                    CheckHierarchyNode(CurrentHierarchyNode);

                                    Writer.Write(CurrentHierarchyNode);
                                }

                                if (WriteNode.GetNodeType() == ENodeType.Geometry)
                                {
                                    GeometryNode CurrentGeometry = (GeometryNode)WriteNode;
                                    CheckGeometry(CurrentGeometry);

                                    Writer.Write((GeometryNode)WriteNode);
                                }

                                if (WriteNode.GetNodeType() == ENodeType.Metadata)
                                {
                                    Writer.Write((MetadataNode)WriteNode);
                                }
                            }
                            else
                            {
                                Thread.Sleep(10);
                            }
                        }
                        _ErrorMessageAction?.Invoke($"[{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fffff")}] Closing Stream");
                    }
                    _ErrorMessageAction?.Invoke($"[{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fffff")}] Closed Stream");
                }
                catch (Exception ex)
                {
                    _ErrorMessageAction?.Invoke($"[{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fffff")}] {ex.Message}\n{ex.StackTrace}");
                    State = FAILED_STATE;
                }

                ProcessQueueWait.Set();
            });
        }
Exemplo n.º 24
0
        public Building(System.String name, ref GlobalVariables g)
        {
            global = g;

            buildingName = name;

            buildingGeomNode  = new GeometryNode();
            buildingMaterial  = new Material();
            buildingTransNode = new TransformNode();
        }
Exemplo n.º 25
0
        public void HitTest_On_Geometry_Node_With_Zero_Transform_Does_Not_Throw()
        {
            var geometry     = Mock.Of <IGeometryImpl>();
            var geometryNode = new GeometryNode(
                new Matrix(),
                Brushes.Black,
                null,
                geometry);

            geometryNode.HitTest(new Point());
        }
Exemplo n.º 26
0
        private void CreateObjects()
        {
            // Loads a textured model of a ship
            ModelLoader loader    = new ModelLoader();
            Model       shipModel = (Model)loader.Load("", "p1_wedge");

            // Create a geometry node of a loaded ship model
            GeometryNode shipNode = new GeometryNode("Ship");

            shipNode.Model = shipModel;
            // This ship model has material definitions in the model file, so instead
            // of creating a material node for this ship model, we simply use its internal materials
            ((Model)shipNode.Model).UseInternalMaterials = true;
            ((Model)shipNode.Model).ContainsTransparency = true;

            // Create a transform node to define the transformation for the ship
            TransformNode shipTransNode = new TransformNode();

            // shipTransNode.Translation = new Vector3(0, 5, -12);
            shipTransNode.Scale    = new Vector3(0.002f, 0.002f, 0.002f); // It's huge!
            shipTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0),
                                                                    MathHelper.ToRadians(-90));

            shipTransParentNode = new TransformNode();

            //Set our rotation animation to ease in initially
            animationRotation = new AnimationHelper(Easing.EaseIn);

            startPosition = new Vector3(-10, 0, -10);
            endPosition   = new Vector3(5, 2, -5);

            startRotationVector = new Vector3(0, 0, 0);
            endRotationVector   = new Vector3(MathHelper.ToRadians(0), MathHelper.ToRadians(180), MathHelper.ToRadians(180));

            //Set our translation animation to ease in initially
            animationTranslation = new AnimationHelper(Easing.EaseIn);

            //Define what kind of interpolation to use.
            animationTranslation.Animate(arrayOfTransitions[currentInterpolation], startPosition, endPosition, 2);
            // animationTranslation.SetLooping(true, 5); // Use if you want to loop through an animation.

            // Set an action to take place once the animation concludes.
            animationTranslation.SetEndAction(delegate()
            {
                animationRotation.Animate(arrayOfTransitions[currentInterpolation], startRotationVector, endRotationVector, 2.0);
            }); // Note: if you loop and set this animation, it'll occur after the end of the first loop, not after the end of all loops!

            textToPrint = "Linear interpolation";

            // Now add the above nodes to the scene graph in appropriate order
            scene.RootNode.AddChild(shipTransParentNode);
            shipTransParentNode.AddChild(shipTransNode);
            shipTransNode.AddChild(shipNode);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Creates a rope-like object by connecting several ball and socket joints.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="parentTrans"></param>
        public static void AddRope(Scene scene, TransformNode parentTrans)
        {
            Vector3 size     = new Vector3(1.5f, 0.25f, 0.25f);
            Vector3 location = new Vector3(0, 9, 0);

            IPhysicsObject link0 = null;

            Color[] colors = { Color.Red,    Color.Orange, Color.Yellow, Color.Green, Color.Blue,
                               Color.Indigo, Color.Violet };

            PrimitiveModel capsule = new Capsule(size.Y, size.X, 12);

            for (int i = 0; i < 7; i++)
            {
                TransformNode pileTrans = new TransformNode();
                pileTrans.Translation = location;

                Material linkMat = new Material();
                linkMat.Diffuse       = colors[i].ToVector4();
                linkMat.Specular      = Color.White.ToVector4();
                linkMat.SpecularPower = 10;

                GeometryNode link1 = new GeometryNode("Link " + i);
                link1.Model = capsule;
                link1.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;
                link1.Material = linkMat;

                link1.AddToPhysicsEngine     = true;
                link1.Physics.Interactable   = true;
                link1.Physics.Collidable     = true;
                link1.Physics.Shape          = ShapeType.Capsule;
                link1.Physics.Mass           = 2.0f;
                link1.Physics.LinearDamping  = 1f;
                link1.Physics.AngularDamping = new Vector3(1f, 1f, 1f);

                parentTrans.AddChild(pileTrans);
                pileTrans.AddChild(link1);

                Vector3 pivot = location + parentTrans.Translation;
                pivot.Y += (size.X - size.Y) * 0.5f;

                BallAndSocketJoint joint = new BallAndSocketJoint(pivot);
                joint.Pin           = -Vector3.UnitY;
                joint.MaxConeAngle  = 0.0f;
                joint.MaxTwistAngle = 10.0f * MathHelper.Pi / 180;

                ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(link1.Physics, link0, joint);

                link0    = link1.Physics;
                location = new Vector3(location.X, location.Y
                                       - (size.X - size.Y), location.Z);
            }
        }
Exemplo n.º 28
0
        public Catalog(Scene s)
        {
            this.my_scene = s;

            this.marker       = new MarkerNode(my_scene.MarkerTracker, "palette_marker.xml");
            this.changeMarker = new MarkerNode(my_scene.MarkerTracker, "palette_turn_marker.xml");
            my_scene.RootNode.AddChild(marker);
            my_scene.RootNode.AddChild(changeMarker);
            library = new ItemLibrary("models.txt");
            names2itemsInCatalog = new Dictionary <string, Item>();
            names2itemsInRoom    = new Dictionary <string, Item>();
            item_list            = library.getAllItems();
            //  this.objects = l;
            int grid_x = 0;
            int grid_y = 0;

            foreach (Item i in item_list)
            {
                names2itemsInCatalog.Add(i.Label, i);
                i.setGroupID(catalogGroupID);
                i.Scale = new Vector3(9.0f, 9.0f, 9.0f) / i.Radius;
            }
            for (int i = cur_start; i < cur_end && i < item_list.Count; i++)
            {
                if (grid_x > 15)
                {
                    grid_x  = 0;
                    grid_y -= 15;
                }
                item_list[i].BindTo(marker);
                item_list[i].MoveTo(new Vector3(grid_x, grid_y, 0));
                grid_x += 15;
            }

            // Create a geometry node with a model of box
            GeometryNode boxNode = new GeometryNode("Box");

            boxNode.Model = new Box(30, 30, 0.1f);

            TransformNode boxTransNode = new TransformNode();

            boxTransNode.AddChild(boxNode);
            boxTransNode.Translation += new Vector3(6, -6, -0.5f);

            Material boxMat = new Material();

            boxMat.Diffuse = Color.DimGray.ToVector4();

            boxNode.Material = boxMat;

            marker.AddChild(boxTransNode);
        }
Exemplo n.º 29
0
 private static void CheckGeometry(GeometryNode CurrentGeometry)
 {
     if (CurrentGeometry.LODs != null)
     {
         for (int i = 0; i < CurrentGeometry.LODs.Count; ++i)
         {
             if (CurrentGeometry.LODs[i].Indexes != null)
             {
                 CurrentGeometry.LODs[i].Indexes.Reverse();
             }
         }
     }
 }
Exemplo n.º 30
0
        private void CreateObjects()
        {
            // Create our ground plane
            GeometryNode groundNode = new GeometryNode("Ground");

            groundNode.Model = new Box(Vector3.One);
            // 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 groundMat = new Material();

            groundMat.Diffuse       = Color.LightGreen.ToVector4();
            groundMat.Specular      = Color.White.ToVector4();
            groundMat.SpecularPower = 20;

            groundNode.Material = groundMat;

            // 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);

            // Add a rope-like object using ball and socket joint
            JointCreator.AddRope(scene, parentTransNode);

            // Add a door-like object using hinge joint
            JointCreator.AddDoubleSwingDoors(scene, parentTransNode);

            JointCreator.AddRollingBeats(scene, parentTransNode);

            // Add a race car
            car = VehicleCreator.AddRaceCar(scene, parentTransNode);

            // Create a camera that chases the car
            CreateChasingCamera((GeometryNode)car.Container);
        }
Exemplo n.º 31
0
        private void CreateGround()
        {
            GeometryNode groundNode = new GeometryNode("Ground");

            groundNode.Model = new TexturedLayer(new Vector2(300, 300));

            Material groundMaterial = new Material();

            groundMaterial.Diffuse = Color.White.ToVector4();
            groundMaterial.Texture = Content.Load <Texture2D>("checkerboard");

            groundNode.Material = groundMaterial;

            scene.RootNode.AddChild(groundNode);
        }
Exemplo n.º 32
0
        private bool isOverCatalogItem()
        {
            if (catalog.isVisible())
            {
                // Now convert the near and far source to actual near and far 3D points based on our eye location
                // and view frustum
                Vector3 nearPoint = graphicsDevice.Viewport.Unproject(nearSource,
                                                                      State.ProjectionMatrix, State.ViewMatrix, catalog.getMarkerTransform());
                Vector3 farPoint = graphicsDevice.Viewport.Unproject(farSource,
                                                                     State.ProjectionMatrix, State.ViewMatrix, catalog.getMarkerTransform());

                // Have the physics engine intersect the pick ray defined by the nearPoint and farPoint with
                // the physics objects in the scene (which we have set up to approximate the model geometry).
                List <PickedObject> pickedObjects = ((NewtonPhysics)scene.PhysicsEngine).PickRayCast(nearPoint, farPoint);

                // If one or more objects intersect with our ray vector
                if (pickedObjects.Count > 0)
                {
                    // Since PickedObject can be compared (which means it implements IComparable), we can sort it in
                    // the order of closest intersected object to farthest intersected object
                    pickedObjects.Sort();

                    // We only care about the closest picked object for now, so we'll simply display the name
                    // of the closest picked object whose container is a geometry node
                    //label = ((GeometryNode)pickedObjects[0].PickedPhysicsObject.Container).Name + " is picked";
                    GeometryNode tempNode = new GeometryNode();
                    int          i        = 0;
                    tempNode = (GeometryNode)pickedObjects[i].PickedPhysicsObject.Container;
                    while (tempNode.GroupID == room.roomGroupID && i + 1 < pickedObjects.Count)
                    {
                        i++;
                        tempNode = (GeometryNode)pickedObjects[i].PickedPhysicsObject.Container;
                    }


                    //Console.WriteLine("Over item from " + (tempNode.Name));
                    return(catalog.catalogContains(tempNode.Name));
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false); //catalog not visible
            }
        }
Exemplo n.º 33
0
        protected void createObj(Vector4 color)
        {
            geomNode       = new GeometryNode("slime");
            geomNode.Model = new Sphere(1, 20, 20);

            Material paddleMaterial = new Material();

            paddleMaterial.Diffuse       = color;
            paddleMaterial.Specular      = color;
            paddleMaterial.SpecularPower = .15f;

            geomNode.Material = paddleMaterial;

            transNode = new TransformNode();
            transNode.AddChild(geomNode);
        }
Exemplo n.º 34
0
        public static RaceCar AddRaceCar(Scene scene, TransformNode parentTrans)
        {
            TransformNode transNode = new TransformNode();
            transNode.Translation = new Vector3(0, 10, 10);

            Material carMat = new Material();
            carMat.Diffuse = Color.Pink.ToVector4();
            carMat.Specular = Color.White.ToVector4();
            carMat.SpecularPower = 10;

            GeometryNode carNode = new GeometryNode("Race Car");
            carNode.Model = new Box(3, 1.0f, 2);
            carNode.Material = carMat;
            carNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;

            NewtonPhysics physicsEngine = (NewtonPhysics)scene.PhysicsEngine;

            RaceCar car = new RaceCar(carNode, physicsEngine);
            for (int i = 0; i < 4; i++)
                car.Tires[i] = CreateTire((TireID)Enum.ToObject(typeof(TireID), i), 
                    car.TireTransformNode[i], carNode, scene.PhysicsEngine.Gravity);

            car.Collidable = true;
            car.Interactable = true;

            carNode.Physics = car;
            carNode.Physics.NeverDeactivate = true;
            carNode.AddToPhysicsEngine = true;

            parentTrans.AddChild(transNode);
            transNode.AddChild(carNode);

            Newton.NewtonSetBodyLeaveWorldEvent(physicsEngine.NewtonWorld,
                car.LeaveWorldCallback);

            return car;
        }
Exemplo n.º 35
0
        public TransformNode getPatientNameNode(Object markerID)
        {
            if (markerID.Equals("PatientMarkerConfig.txt"))
            {
                GeometryNode sphereNode = new GeometryNode("Sphere");
                sphereNode.Model = new Sphere(3.5f, 20, 20);
                sphereNode.Model.CastShadows = true;
                sphereNode.Model.ReceiveShadows = true;

                Material sphereMat = new Material();
                sphereMat.Diffuse = Color.Red.ToVector4();
                sphereMat.Specular = Color.White.ToVector4();
                sphereMat.SpecularPower = 20;

                sphereNode.Material = sphereMat;
                //sphereNode.Physics.Interactable = false;

                TransformNode sphereTrans = new TransformNode();
                sphereTrans.Translation = new Vector3(0, 0, 5);
                sphereTrans.AddChild(sphereNode);
                return sphereTrans;
            }
            return null;
        }
Exemplo n.º 36
0
        private void CreateObject()
        {
            // Loads a textured model of a ship
            ModelLoader loader = new ModelLoader();
            Model shipModel = (Model)loader.Load("", "p1_wedge");

            // Create a geometry node of a loaded ship model
            GeometryNode shipNode = new GeometryNode("Ship");
            shipNode.Model = shipModel;
            ((Model)shipNode.Model).UseInternalMaterials = true;

            // Create a transform node to define the transformation for the ship
            TransformNode shipTransNode = new TransformNode();
            shipTransNode.Translation = new Vector3(0, 0, -50);
            shipTransNode.Scale = new Vector3(0.01f, 0.01f, 0.01f); // It's huge!
            shipTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0),
                MathHelper.ToRadians(90));

            shipTransParentNode = new TransformNode();
            shipTransParentNode.Translation = Vector3.Zero;

            // Create a geometry node with model of a torus
            GeometryNode torusNode = new GeometryNode("Torus");
            torusNode.Model = new Torus(12f, 15.5f, 20, 20);

            TransformNode torusTransNode = new TransformNode();
            torusTransNode.Translation = new Vector3(-50, 0, 0);
            torusTransNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX,
                MathHelper.ToRadians(90));

            // Create a material node for this torus model
            Material torusMaterial = new Material();
            torusMaterial.Diffuse = Color.DarkGoldenrod.ToVector4();
            torusMaterial.Specular = Color.White.ToVector4();
            torusMaterial.SpecularPower = 5;

            torusNode.Material = torusMaterial;

            // Now add the above nodes to the scene graph in appropriate order
            scene.RootNode.AddChild(shipTransParentNode);
            shipTransParentNode.AddChild(shipTransNode);
            shipTransNode.AddChild(shipNode);

            scene.RootNode.AddChild(torusTransNode);
            torusTransNode.AddChild(torusNode);

            // Now create couple of particle effects to attach to the models

            // Create a smoke particle effect and fire particle effect to simulate a
            // ring of fire around the torus model
#if WINDOWS_PHONE
            SmokePlumeParticleEffect smokeParticles = new SmokePlumeParticleEffect(20, spriteBatch);
            FireParticleEffect fireParticles = new FireParticleEffect(40, spriteBatch);
#else
            SmokePlumeParticleEffect smokeParticles = new SmokePlumeParticleEffect();
            FireParticleEffect fireParticles = new FireParticleEffect();
            // The order defines which particle effect to render first. Since we want
            // to show the fire particles in front of the smoke particles, we make
            // the smoke particles to be rendered first, and then fire particles
            smokeParticles.DrawOrder = 200;
            fireParticles.DrawOrder = 300;
#endif

            // Create a particle node to hold these two particle effects
            ParticleNode fireRingEffectNode = new ParticleNode();
            fireRingEffectNode.ParticleEffects.Add(smokeParticles);
            fireRingEffectNode.ParticleEffects.Add(fireParticles);

            // Implement an update handler for each of the particle effects which will be called
            // every "Update" call 
            fireRingEffectNode.UpdateHandler += new ParticleUpdateHandler(UpdateRingOfFire);

            torusNode.AddChild(fireRingEffectNode);

            // Create another set of fire and smoke particle effects to simulate the fire
            // the ship catches when the ship passes the ring of fire
#if WINDOWS_PHONE
            FireParticleEffect shipFireEffect = new FireParticleEffect(150, spriteBatch);
            SmokePlumeParticleEffect shipSmokeEffect = new SmokePlumeParticleEffect(80, spriteBatch);
            shipFireEffect.MinScale *= 1.5f;
            shipFireEffect.MaxScale *= 1.5f;
#else
            FireParticleEffect shipFireEffect = new FireParticleEffect();
            SmokePlumeParticleEffect shipSmokeEffect = new SmokePlumeParticleEffect();
            shipSmokeEffect.DrawOrder = 400;
            shipFireEffect.DrawOrder = 500;
#endif

            ParticleNode shipFireNode = new ParticleNode();
            shipFireNode.ParticleEffects.Add(shipFireEffect);
            shipFireNode.ParticleEffects.Add(shipSmokeEffect);

            shipFireNode.UpdateHandler += new ParticleUpdateHandler(UpdateShipFire);

            shipNode.AddChild(shipFireNode);
        }
Exemplo n.º 37
0
        private void CreateObjects()
        {
            // Create a sphere geometry
            {
                GeometryNode sphereNode = new GeometryNode("Sphere");
                sphereNode.Model = new Sphere(3.5f, 20, 20);
                sphereNode.Model.CastShadows = true;
                sphereNode.Model.ReceiveShadows = true;

                Material sphereMat = new Material();
                sphereMat.Diffuse = Color.Red.ToVector4();
                sphereMat.Specular = Color.White.ToVector4();
                sphereMat.SpecularPower = 20;

                sphereNode.Material = sphereMat;

                TransformNode sphereTrans = new TransformNode();
                sphereTrans.Translation = new Vector3(0, 0, 5);

                groundMarkerNode.AddChild(sphereTrans);
                sphereTrans.AddChild(sphereNode);
            }

            // Create a box geometry
            {
                GeometryNode boxNode = new GeometryNode("Box");
                boxNode.Model = new Box(6);
                boxNode.Model.CastShadows = true;
                boxNode.Model.ReceiveShadows = true;

                Material boxMat = new Material();
                boxMat.Diffuse = Color.Blue.ToVector4();
                boxMat.Specular = Color.White.ToVector4();
                boxMat.SpecularPower = 20;

                boxNode.Material = boxMat;

                TransformNode boxTrans = new TransformNode();
                boxTrans.Translation = new Vector3(-35, -18, 8);

                groundMarkerNode.AddChild(boxTrans);
                boxTrans.AddChild(boxNode);
            }

            // Create a cylinder geometry
            {
                GeometryNode cylinderNode = new GeometryNode("Cylinder");
                cylinderNode.Model = new Cylinder(3.5f, 3.5f, 10, 20);
                cylinderNode.Model.CastShadows = true;
                cylinderNode.Model.ReceiveShadows = true;

                Material cylinderMat = new Material();
                cylinderMat.Diffuse = Color.Green.ToVector4();
                cylinderMat.Specular = Color.White.ToVector4();
                cylinderMat.SpecularPower = 20;

                cylinderNode.Material = cylinderMat;

                TransformNode cylinderTrans = new TransformNode();
                cylinderTrans.Translation = new Vector3(35, -18, 8);

                groundMarkerNode.AddChild(cylinderTrans);
                cylinderTrans.AddChild(cylinderNode);
            }

            // Create a torus geometry
            {
                GeometryNode torusNode = new GeometryNode("Torus");
                torusNode.Model = new Torus(2.5f, 6.0f, 20, 20);
                torusNode.Model.CastShadows = true;
                torusNode.Model.ReceiveShadows = true;

                Material torusMat = new Material();
                torusMat.Diffuse = Color.Yellow.ToVector4();
                torusMat.Specular = Color.White.ToVector4();
                torusMat.SpecularPower = 20;

                torusNode.Material = torusMat;

                TransformNode torusTrans = new TransformNode();
                torusTrans.Translation = new Vector3(-35, 18, 8);

                groundMarkerNode.AddChild(torusTrans);
                torusTrans.AddChild(torusNode);
            }

            // Create a capsule geometry
            {
                GeometryNode capsuleNode = new GeometryNode("Capsule");
                capsuleNode.Model = new Capsule(3, 12, 20);
                capsuleNode.Model.CastShadows = true;
                capsuleNode.Model.ReceiveShadows = true;

                Material capsuleMat = new Material();
                capsuleMat.Diffuse = Color.Cyan.ToVector4();
                capsuleMat.Specular = Color.White.ToVector4();
                capsuleMat.SpecularPower = 20;

                capsuleNode.Material = capsuleMat;

                TransformNode capsuleTrans = new TransformNode();
                capsuleTrans.Translation = new Vector3(35, 18, 8);

                groundMarkerNode.AddChild(capsuleTrans);
                capsuleTrans.AddChild(capsuleNode);
            }
        }
Exemplo n.º 38
0
        private void CreateGround()
        {
            GeometryNode groundNode = new GeometryNode("Ground");

            #if USE_ARTAG
            groundNode.Model = new Box(85, 66, 0.1f);
            #else
            groundNode.Model = new Box(95, 59, 0.1f);
            #endif

            // Set this ground model to act as an occluder so that it appears transparent
            groundNode.IsOccluder = true;

            // Make the ground model to receive shadow casted by other objects with
            // CastShadows set to true
            groundNode.Model.ReceiveShadows = true;

            Material groundMaterial = new Material();
            groundMaterial.Diffuse = new Vector4(0.5f, 0.5f, 0.5f, 0.5f);
            groundMaterial.Specular = Color.White.ToVector4();
            groundMaterial.SpecularPower = 20;

            groundNode.Material = groundMaterial;

            groundMarkerNode.AddChild(groundNode);
        }
Exemplo n.º 39
0
        private static NewtonTire CreateTire(TireID tireID, TransformNode tireTrans,
            GeometryNode carNode, float gravity)
        {
            NewtonTire tire = new NewtonTire();

            Material tireMat = new Material();
            tireMat.Diffuse = Color.Orange.ToVector4();
            tireMat.Specular = Color.White.ToVector4();
            tireMat.SpecularPower = 10;

            float tireRadius = 0.7f;
            GeometryNode tireNode = new GeometryNode("Race Car " + tireID + " Tire");
            tireNode.Model = new Cylinder(tireRadius, tireRadius, 0.3f, 20);
            tireNode.Material = tireMat;

            carNode.AddChild(tireTrans);
            tireTrans.AddChild(tireNode);

            tire.Mass = 5.0f;
            tire.Width = 0.3f * 1.25f;
            tire.Radius = tireRadius;

            switch (tireID)
            {
                case TireID.FrontLeft:
                    tire.TireOffsetMatrix = Matrix.CreateTranslation(new Vector3(-1.5f, 0, -1f));
                    break;
                case TireID.FrontRight:
                    tire.TireOffsetMatrix = Matrix.CreateTranslation(new Vector3(-1.5f, 0, 1f));
                    break;
                case TireID.RearLeft:
                    tire.TireOffsetMatrix = Matrix.CreateTranslation(new Vector3(1.5f, 0, -1f));
                    break;
                case TireID.RearRight:
                    tire.TireOffsetMatrix = Matrix.CreateTranslation(new Vector3(1.5f, 0, 1f));
                    break;
            }

            // the tire will spin around the lateral axis of the same tire space
            tire.Pin = Vector3.UnitZ;

            tire.SuspensionLength = RaceCar.SUSPENSION_LENGTH;

            // calculate the spring and damper contact for the subquestion  
            //
            // from the equation of a simple spring the force is given by
            // a = k * x
            // where k is a spring constant and x is the displacement and a is the spring acceleration.
            // we desire that a rest length the acceleration generated by the spring equal that of the gravity
            // several gravity forces
            // m * gravity = k * SUSPENSION_LENGTH * 0.5f, 
            float x = RaceCar.SUSPENSION_LENGTH;
            tire.SuspensionSpring = (200.0f * (float)Math.Abs(gravity)) / x;
            //tireSuspesionSpring = (100.0f * dAbs (GRAVITY)) / x;

            // from the equation of a simple spring / damper system
            // the system resonate at a frequency 
            // w^2 = ks
            //
            // and the damping attenuation is given by
            // d = ks / 2.0f
            // where:
            // if   d = w = 2 * pi * f -> the system is critically damped
            // if   d > w < 2 * pi * f -> the system is super critically damped
            // if   d < w < 2 * pi * f -> the system is under damped damped 
            // for a vehicle we usually want a suspension that is about 10% super critically damped 
            float w = (float)Math.Sqrt(tire.SuspensionSpring);

            // a critically damped suspension act too jumpy for a race car
            tire.SuspensionShock = 1.0f * w;

            // make it a little super critical y damped
            //tireSuspesionShock = 2.0f * w;

            tire.CollisionID = 0x100;

            return tire;
        }
Exemplo n.º 40
0
        public void CreateShootBullet(Vector3 InitPos, Vector3 DirBullet, Color BulletColor)
        {
            if (BulletID == 20)
                return;

            GeometryNode ShootBullet = new GeometryNode("ShootBullet" + BulletID++);

            ShootBullet.Model = BulletModel;

            BulletrMat.Diffuse = BulletColor.ToVector4();

            ShootBullet.Material = BulletrMat;
            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);

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

            groundMarkerNode.AddChild(BulletTrans);
            BulletTrans.AddChild(ShootBullet);
        }
Exemplo n.º 41
0
        /********************* Basic Elements ****************/
        public GeometryNode CreateCube(MarkerNode Marker, Vector4 CubeColor)
        {
            GeometryNode boxNode;
            // Create a geometry node with a model of a box
            boxNode = new GeometryNode("Box");
            boxNode.Model = new TexturedBox(32.4f);

            // Add this box model to the physics engine for collision detection
            boxNode.AddToPhysicsEngine = true;
            boxNode.Physics.Shape = ShapeType.Box;
            // Make this box model cast and receive shadows
            boxNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;
            // Assign a shadow shader for this model that uses the IShadowMap we assigned to the scene
            boxNode.Model.Shader = new SimpleShadowShader(GShadowMap);

            // Create a material to apply to the box model
            Material boxMaterial = new Material();
            boxMaterial.Diffuse = CubeColor;
            boxMaterial.Specular = Color.White.ToVector4();
            boxMaterial.SpecularPower = 10;

            boxNode.Material = boxMaterial;

            // Add this box model node to the ground marker node
            Marker.AddChild(boxNode);

            return boxNode;

            // Create a collision pair and add a collision callback function that will be
            // called when the pair collides
            //NewtonPhysics.CollisionPair pair = new NewtonPhysics.CollisionPair(boxNode.Physics, sphereNode.Physics);
            //((NewtonPhysics)scene.PhysicsEngine).AddCollisionCallback(pair, BoxSphereCollision);
        }
Exemplo n.º 42
0
        public static void CreateBall(MarkerNode Marker)
        {
            // Create a geometry node for Sphere
            PrimitiveModel PsphereModel = new Sphere(15f, 20, 20);

            // Create a material to apply to the sphere model
            Material sphereMaterial = new Material();
            sphereMaterial.Diffuse = new Vector4(0, 0.5f, 0, 1);
            sphereMaterial.Specular = Color.White.ToVector4();
            sphereMaterial.SpecularPower = 10;

            GeometryNode sphereNode = new GeometryNode("Sphere");
            //sphereNode.Model = new TexturedSphere(16, 20, 20);
            sphereNode.Model = PsphereModel;
            sphereNode.Material = sphereMaterial;

            // Add this sphere model to the physics engine for collision detection
            sphereNode.Physics.Interactable = true;
            sphereNode.Physics.Collidable = true;
            sphereNode.Physics.Shape = ShapeType.Sphere;
            sphereNode.Physics.Mass = 30;

            //sphereNode.Physics.ApplyGravity = false;
            sphereNode.Physics.InitialLinearVelocity = new Vector3(30, 0, 0);
            //sphereNode.Physics.MaterialName = "Sphere";
            //sphereNode.Physics.ApplyGravity = true;
            sphereNode.AddToPhysicsEngine = true;

            // Make this sphere model cast and receive shadows
            //sphereNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;
            // Assign a shadow shader for this model that uses the IShadowMap we assigned to the scene
            //sphereNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap);

            TransformNode sphereTransNode = new TransformNode();
            sphereTransNode.Translation = new Vector3(50, 0, 50);

            // Now add the above nodes to the scene graph in the appropriate order.
            // Note that only the nodes added below the marker node are affected by
            // the marker transformation.
            Marker.AddChild(sphereTransNode);
            sphereTransNode.AddChild(sphereNode);
        }
Exemplo n.º 43
0
        /// <summary>
        /// To initializa external Components like GoblinsXna
        /// </summary>
        protected override void Initialize()
        {
            int idx;

            //Init Console
            Console.WriteLine("CarGame AR: " + Version());
            Console.WriteLine(DateTime.Now.ToString() + " Loading game\n");

            // To initialize Xna
            base.Initialize();

            // Initialize the GoblinXNA framework
            State.InitGoblin(graphics, Content, "");

            // Initialize the scene graph
            scene = new Scene();

            /********* Init Content from Game *********/

            //Instantiate the Markers
            HinderMarkeNodes = new MarkerNode[Max_Markers];
            WeaponMarkeNodes = new MarkerNode[Max_palyer]; //One Weapon for Player

            //Instantiate Models
            Console.WriteLine(DateTime.Now.ToString() + " Loading Car´s Models\n");
            
            CarModels = new GeometryNode[Max_Models];
            ModelLoader loader = new ModelLoader();
            for (idx = 0; idx < Max_Models; idx++)
            {
                CarModels[idx] = new GeometryNode("CarModel" + idx.ToString());
                CarModels[idx].Model = (Model)loader.Load("Models", ModelsName[idx]);
                ((Model)CarModels[idx].Model).UseInternalMaterials = true;
            }

            //Instantiate the Logic Game
            GameLogic = new Game_Logic(Max_palyer);

            //Create Obj for Cars
            CarObjPhy = new RaceCar[Max_palyer];

            //Instancio los Obj de los obstaculos
            ObstModels = new GeometryNode[Max_Markers];

            //Instantiate the 2DManager
            My2Dmanager = new My2DSpriteManager(GameLogic);
            My2Dmanager.LoadContent();

            //Load SoundEffects
            GameLogic.SoundGame.SoundLoad();

            /******************************************/

            // Use the newton physics engine
            scene.PhysicsEngine = new NewtonPhysics();

            //Config Physics
            SetupPhysics();

#if USE_SOCKET_NETWORK
            //Init Network
            State.EnableNetworking = true;
            State.IsServer = true;
            ConfigServer(14242);
#endif

            State.ThreadOption = (ushort)ThreadOptions.MarkerTracking;

            // Setup and Create optical marker tracking
            SetupMarkerTracking();
            CreateMarkerTracking();

            // Enable shadow mapping
            scene.ShadowMap = new MultiLightShadowMap();

            //Instantiate the 3DManager
            Manager3D = new Graphics3D(groundMarkerNode, scene.ShadowMap);

            //Config Callbacks for Collitions
            ConfigCallBacks();

            // Set up the lights used in the scene
            CreateLights();

            // Create 3D objects
            CreateObjects();

            // Show Frames-Per-Second on the screen for debugging
            State.ShowFPS = true;
            //State.ShowTriangleCount = true;
            //State.ShowNotifications = true;
            // Make the debugging message fade out after 3000 ms (3 seconds)
            Notifier.FadeOutTime = 1000;

            Console.WriteLine(DateTime.Now.ToString() + " End Loading\n");

            //Server
            ServidorAr = new ARServer(GameLogic);
            ServidorAr.CallBackAddPlayer = AgregaPlayer;

#if INIT_SERVER
            ServidorAr.StartServer();
            //Add Ip Address
            My2Dmanager.ServerIp = ServidorAr.SetLocalIp();
#endif
            //Config Controls
            ConfigControls();
            if (CtrlPlayers[0] == Ctrl_Player.KEYBOARD)
                ServidorAr.AddPlayerOne();

#if USR_DEBUG
            //GameLogic.CurrentGameState = Game_Logic.Game_States.SEL_PLY;
            //GameLogic.StateScreen = Game_Logic.Game_SCR.GAME_LOADING;

            //GameLogic.AddPlayer("Player 2", 2);
            //GameLogic.Players[1].IsPlyOK = true;
            //GameLogic.Players[1].PlySelect = 7;
            //GameLogic.Players[1].IsDead = true;
            //GameLogic.AddPlayer("Player 3", 3);
            //GameLogic.AddPlayer("Player 4", 4);
#endif

        }
Exemplo n.º 44
0
        private void CreateObjects()
        {
            // Loads a textured model of a ship
            ModelLoader loader = new ModelLoader();
            Model shipModel = (Model)loader.Load("", "p1_wedge");

            // Create a geometry node of a loaded ship model
            GeometryNode shipNode = new GeometryNode("Ship");
            shipNode.Model = shipModel;
            // This ship model has material definitions in the model file, so instead
            // of creating a material node for this ship model, we simply use its internal materials
            ((Model)shipNode.Model).UseInternalMaterials = true;
            ((Model)shipNode.Model).ContainsTransparency = true;

            // Create a transform node to define the transformation for the ship
            TransformNode shipTransNode = new TransformNode();
           // shipTransNode.Translation = new Vector3(0, 5, -12);
            shipTransNode.Scale = new Vector3(0.002f, 0.002f, 0.002f); // It's huge!
            shipTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0),
                MathHelper.ToRadians(-90));

            shipTransParentNode = new TransformNode();
            
            //Set our rotation animation to ease in initially
            animationRotation = new AnimationHelper(Easing.EaseIn);

            startPosition = new Vector3(-10, 0, -10);
            endPosition = new Vector3(5, 2, -5);

            startRotationVector = new Vector3(0, 0, 0);
            endRotationVector = new Vector3(MathHelper.ToRadians(0), MathHelper.ToRadians(180), MathHelper.ToRadians(180));

            //Set our translation animation to ease in initially
            animationTranslation = new AnimationHelper(Easing.EaseIn);

            //Define what kind of interpolation to use.
            animationTranslation.Animate(arrayOfTransitions[currentInterpolation], startPosition, endPosition, 2);
           // animationTranslation.SetLooping(true, 5); // Use if you want to loop through an animation.

            // Set an action to take place once the animation concludes.
            animationTranslation.SetEndAction(delegate()
            {
                animationRotation.Animate(arrayOfTransitions[currentInterpolation], startRotationVector, endRotationVector, 2.0);
            }); // Note: if you loop and set this animation, it'll occur after the end of the first loop, not after the end of all loops!

            textToPrint = "Linear interpolation";

            // Now add the above nodes to the scene graph in appropriate order
            scene.RootNode.AddChild(shipTransParentNode);
            shipTransParentNode.AddChild(shipTransNode);
            shipTransNode.AddChild(shipNode);
        }
Exemplo n.º 45
0
        private void CreateObjects()
        {
            // Create a sphere geometry
            {
                GeometryNode sphereNode = new GeometryNode("Sphere");
                sphereNode.Model = new TexturedSphere(14, 20, 20);
                sphereNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;
                sphereNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap);

                Material sphereMat = new Material();
                sphereMat.Diffuse = Color.Red.ToVector4();
                sphereMat.Specular = Color.White.ToVector4();
                sphereMat.SpecularPower = 20;

                sphereNode.Material = sphereMat;

                TransformNode sphereTrans = new TransformNode();
                sphereTrans.Translation = new Vector3(0, 0, 20);

                groundMarkerNode.AddChild(sphereTrans);
                sphereTrans.AddChild(sphereNode);
            }

            // Create a box geometry
            {
                GeometryNode boxNode = new GeometryNode("Box");
                boxNode.Model = new TexturedBox(24);
                boxNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;
                boxNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap);

                Material boxMat = new Material();
                boxMat.Diffuse = Color.Blue.ToVector4();
                boxMat.Specular = Color.White.ToVector4();
                boxMat.SpecularPower = 20;

                boxNode.Material = boxMat;

                TransformNode boxTrans = new TransformNode();
                boxTrans.Translation = new Vector3(-140, -72, 32);

                groundMarkerNode.AddChild(boxTrans);
                boxTrans.AddChild(boxNode);
            }

            // Create a cylinder geometry
            {
                GeometryNode cylinderNode = new GeometryNode("Cylinder");
                cylinderNode.Model = new Cylinder(14, 14, 10, 20);
                cylinderNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;

                Material cylinderMat = new Material();
                cylinderMat.Diffuse = Color.Green.ToVector4();
                cylinderMat.Specular = Color.White.ToVector4();
                cylinderMat.SpecularPower = 20;

                cylinderNode.Material = cylinderMat;

                TransformNode cylinderTrans = new TransformNode();
                cylinderTrans.Translation = new Vector3(140, -72, 32);

                groundMarkerNode.AddChild(cylinderTrans);
                cylinderTrans.AddChild(cylinderNode);
            }

            // Create a torus geometry
            {
                GeometryNode torusNode = new GeometryNode("Torus");
                torusNode.Model = new Torus(10, 24, 20, 20);
                torusNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;

                Material torusMat = new Material();
                torusMat.Diffuse = Color.Yellow.ToVector4();
                torusMat.Specular = Color.White.ToVector4();
                torusMat.SpecularPower = 20;

                torusNode.Material = torusMat;

                TransformNode torusTrans = new TransformNode();
                torusTrans.Translation = new Vector3(-140, 72, 32);

                groundMarkerNode.AddChild(torusTrans);
                torusTrans.AddChild(torusNode);
            }

            // Create a capsule geometry
            {
                GeometryNode capsuleNode = new GeometryNode("Capsule");
                capsuleNode.Model = new Capsule(12, 48, 20);
                capsuleNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;

                Material capsuleMat = new Material();
                capsuleMat.Diffuse = Color.Cyan.ToVector4();
                capsuleMat.Specular = Color.White.ToVector4();
                capsuleMat.SpecularPower = 20;

                capsuleNode.Material = capsuleMat;

                TransformNode capsuleTrans = new TransformNode();
                capsuleTrans.Translation = new Vector3(140, 72, 32);

                groundMarkerNode.AddChild(capsuleTrans);
                capsuleTrans.AddChild(capsuleNode);
            }
        }
Exemplo n.º 46
0
        private void CreateGround()
        {
            GeometryNode groundNode = new GeometryNode("Ground");

            groundNode.Model = new TexturedBox(340, 200, 0.1f);

            // Set this ground model to act as an occluder so that it appears transparent
            groundNode.IsOccluder = true;

            // Make the ground model to receive shadow casted by other objects with
            // CastShadows set to true
            groundNode.Model.ShadowAttribute = ShadowAttribute.ReceiveOnly;
            groundNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap);

            Material groundMaterial = new Material();
            groundMaterial.Diffuse = new Vector4(0.5f, 0.5f, 0.5f, 0.5f);
            groundMaterial.Specular = Color.White.ToVector4();
            groundMaterial.SpecularPower = 20;

            groundNode.Material = groundMaterial;

            groundMarkerNode.AddChild(groundNode);
        }
Exemplo n.º 47
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);
        }
Exemplo n.º 48
0
        private void build(IModel model, string name)
        {
            this.name = name;
            this.instanceNumber = instance;

            restrictedDimension = new Vector3(1,1,0);
            geo = new GeometryNode(this.Label);
            trans = new TransformNode(this.Label + "_Trans");

            instance++;
            trans.AddChild(geo);

            geo.Model = model;
            geo.Physics.Shape = GoblinXNA.Physics.ShapeType.Box;
            geo.Physics.Pickable = true;
            geo.AddToPhysicsEngine = true;
            trans.Rotation = Quaternion.CreateFromYawPitchRoll((float)Math.PI / 2, 0, (float)Math.PI / 2);
        }
Exemplo n.º 49
0
        public static GeometryNode AddModel(MarkerNode Marker, String Folder, String Model, bool IntMaterial, float Scala)
        {
            GeometryNode ObstNode;

            if (Model == "null")
                return ObstNode = new GeometryNode();

            ObstNode = Graphics3D.LoadModel("Models/" + Folder, Model, IntMaterial);

            //define the Physic Material name
            ObstNode.Physics.MaterialName = "Obstacle";

            TransformNode parentTransNode = new TransformNode();
            parentTransNode.Name = Model;
            parentTransNode.Scale = new Vector3(Scala, Scala + 2, Scala);
            parentTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), MathHelper.ToRadians(90));
            //Add Rotation because Blender Axis
            parentTransNode.AddChild(ObstNode);

            // Add this box model node to the ground marker node
            if(Marker != null)
                Marker.AddChild(parentTransNode);

            return ObstNode;
        }
Exemplo n.º 50
0
        private void CreateObjects()
        {
            // Create a geometry node with a model of a sphere that will be overlaid on
            // top of the ground marker array
            GeometryNode sphereNode = new GeometryNode("Sphere");
            // We will use TexturedSphere instead of regular Box class since we will need the
            // texture coordinates elements for passing the vertices to the SimpleShadowShader
            // we will be using
            sphereNode.Model = new TexturedSphere(16, 20, 20);

            // Add this sphere model to the physics engine for collision detection
            sphereNode.AddToPhysicsEngine = true;
            sphereNode.Physics.Shape = ShapeType.Sphere;
            // Make this sphere model cast and receive shadows
            sphereNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;
            // Assign a shadow shader for this model that uses the IShadowMap we assigned to the scene
            sphereNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap);

            // Create a marker node to track a ground marker array.
#if USE_NYARTOOLKIT
            groundMarkerNode = new MarkerNode(scene.MarkerTracker, "NyARToolkitGroundArray.xml",
                NyARToolkitTracker.ComputationMethod.Average);
#else
            groundMarkerNode = new MarkerNode(scene.MarkerTracker, "ALVARGroundArray.xml");
#endif

            TransformNode sphereTransNode = new TransformNode();
            sphereTransNode.Translation = new Vector3(0, 0, 50);

            // Create a material to apply to the sphere model
            Material sphereMaterial = new Material();
            sphereMaterial.Diffuse = new Vector4(0, 0.5f, 0, 1);
            sphereMaterial.Specular = Color.White.ToVector4();
            sphereMaterial.SpecularPower = 10;

            sphereNode.Material = sphereMaterial;

            // Now add the above nodes to the scene graph in the appropriate order.
            // Note that only the nodes added below the marker node are affected by 
            // the marker transformation.
            scene.RootNode.AddChild(groundMarkerNode);
            groundMarkerNode.AddChild(sphereTransNode);
            sphereTransNode.AddChild(sphereNode);

            // Create a geometry node with a model of a box that will be overlaid on
            // top of the ground marker array initially. (When the toolbar marker array is
            // detected, it will be overlaid on top of the toolbar marker array.)
            boxNode = new GeometryNode("Box");
            // We will use TexturedBox instead of regular Box class since we will need the
            // texture coordinates elements for passing the vertices to the SimpleShadowShader
            // we will be using
            boxNode.Model = new TexturedBox(32.4f);

            // Add this box model to the physics engine for collision detection
            boxNode.AddToPhysicsEngine = true;
            boxNode.Physics.Shape = ShapeType.Box;
            // Make this box model cast and receive shadows
            boxNode.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;
            // Assign a shadow shader for this model that uses the IShadowMap we assigned to the scene
            boxNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap);

            // Create a marker node to track a toolbar marker array.
#if USE_NYARTOOLKIT
            toolbarMarkerNode = new MarkerNode(scene.MarkerTracker, "ToolbarNyARToolkit.xml",
                NyARToolkitTracker.ComputationMethod.Average);
#else
            toolbarMarkerNode = new MarkerNode(scene.MarkerTracker, "ALVARToolbar.xml");
#endif

            scene.RootNode.AddChild(toolbarMarkerNode);

            // Create a material to apply to the box model
            Material boxMaterial = new Material();
            boxMaterial.Diffuse = new Vector4(0.5f, 0, 0, 1);
            boxMaterial.Specular = Color.White.ToVector4();
            boxMaterial.SpecularPower = 10;

            boxNode.Material = boxMaterial;

            // Add this box model node to the ground marker node
            groundMarkerNode.AddChild(boxNode);

            // Create a collision pair and add a collision callback function that will be
            // called when the pair collides
            NewtonPhysics.CollisionPair pair = new NewtonPhysics.CollisionPair(boxNode.Physics, sphereNode.Physics);
            ((NewtonPhysics)scene.PhysicsEngine).AddCollisionCallback(pair, BoxSphereCollision);
        }
Exemplo n.º 51
0
        /********************* Helpers **********************/
        public static GeometryNode LoadModel(string DirModel, string Modelname, bool InternalMaterial)
        {
            GeometryNode MyNode = new GeometryNode(Modelname);
            //Intento cargar un modelo
            ModelLoader loader = new ModelLoader();

            MyNode.Physics.Mass = 20;
            MyNode.Physics.Shape = ShapeType.ConvexHull;
            MyNode.Physics.MaterialName = Modelname;
            MyNode.Physics.ApplyGravity = true;
            //Debo probar mas esta propiedad
            MyNode.Physics.NeverDeactivate = true;
            MyNode.AddToPhysicsEngine = true;

            //Load Model
            MyNode.Model = (Model)loader.Load(DirModel, Modelname);

            //Define Material
            if (InternalMaterial)
            {
                ((Model)MyNode.Model).UseInternalMaterials = true;
            }
            else
            {
                // Create a material for the Model
                Material ModelMat = new Material();
                ModelMat.Diffuse = Color.Blue.ToVector4();
                ModelMat.Specular = Color.White.ToVector4();
                ModelMat.SpecularPower = 20;
                //Add Material
                MyNode.Material = ModelMat;
            }

            return MyNode;
        }
Exemplo n.º 52
0
        private bool isOverRoomItem()
        {
            if (room.isVisible())
            {
                // Now convert the near and far source to actual near and far 3D points based on our eye location
                // and view frustum
                Vector3 nearPoint = graphicsDevice.Viewport.Unproject(nearSource,
                    State.ProjectionMatrix, State.ViewMatrix, room.getMarkerTransform());
                Vector3 farPoint = graphicsDevice.Viewport.Unproject(farSource,
                    State.ProjectionMatrix, State.ViewMatrix, room.getMarkerTransform());

                // Have the physics engine intersect the pick ray defined by the nearPoint and farPoint with
                // the physics objects in the scene (which we have set up to approximate the model geometry).
                List<PickedObject> pickedObjects = ((NewtonPhysics)scene.PhysicsEngine).PickRayCast(nearPoint, farPoint);

                // If one or more objects intersect with our ray vector
                if (pickedObjects.Count > 0)
                {
                    // Since PickedObject can be compared (which means it implements IComparable), we can sort it in
                    // the order of closest intersected object to farthest intersected object
                    pickedObjects.Sort();

                    // We only care about the closest picked object for now, so we'll simply display the name
                    // of the closest picked object whose container is a geometry node
                    //label = ((GeometryNode)pickedObjects[0].PickedPhysicsObject.Container).Name + " is picked";
                    GeometryNode tempNode = new GeometryNode();
                    int i = 0;
                    tempNode = (GeometryNode)pickedObjects[i].PickedPhysicsObject.Container;
                    while (tempNode.GroupID == room.roomGroupID && i + 1 < pickedObjects.Count)
                    {
                        i++;
                        tempNode = (GeometryNode)pickedObjects[i].PickedPhysicsObject.Container;
                    }
                    //Console.WriteLine("Over item from " + (tempNode.Name));
                    return catalog.roomContains(tempNode.Name) && !catalog.isItemSelectedRoom(tempNode.Name);

                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false; //room not visible
            }
        }
Exemplo n.º 53
0
        public void CreateGround(bool Occluder)
        {
            GeometryNode groundNode = new GeometryNode("Ground");

            //Cordenates X, y, Z
            groundNode.Model = new TexturedBox(324, 180, 0.1f);

            // Set this model Occluded ist or not
            groundNode.IsOccluder = Occluder;

            //Setup Physics Aspecte
            groundNode.Physics.Collidable = true;
            groundNode.Physics.Shape = GoblinXNA.Physics.ShapeType.Box;
            groundNode.Physics.MaterialName = "Ground";
            groundNode.AddToPhysicsEngine = true;

            // Make the ground model to receive shadow casted by other objects
            groundNode.Model.ShadowAttribute = ShadowAttribute.ReceiveOnly;
            // Assign a shadow shader
            groundNode.Model.Shader = new SimpleShadowShader(GShadowMap);

            //Material
            Material groundMaterial = new Material();
            groundMaterial.Diffuse = Color.Gray.ToVector4();
            groundMaterial.Specular = Color.White.ToVector4();
            groundMaterial.SpecularPower = 20;

            //Assig Material
            groundNode.Material = groundMaterial;

            //Add Model in the Scene
            parentTNodeGrd.AddChild(groundNode);
        }
Exemplo n.º 54
0
        public static void AddRollingBeats(Scene scene, TransformNode parentTrans)
        {
            Vector3 size = new Vector3(10.0f, 0.25f, 0.25f);
            Vector3 location = new Vector3(0, 3, 3);

            GeometryNode bar;
            // //////////////////////////////////////////////////////////////////            
            //
            // Create a bar and attach it to the world with a hinge with limits
            //
            // //////////////////////////////////////////////////////////////////
            {
                TransformNode pileTrans = new TransformNode();
                pileTrans.Translation = location;
                pileTrans.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, MathHelper.PiOver2);

                Material barMat = new Material();
                barMat.Diffuse = Color.Purple.ToVector4();
                barMat.Specular = Color.White.ToVector4();
                barMat.SpecularPower = 10;

                bar = new GeometryNode("Bar");
                bar.Model = new Cylinder(size.Y, size.Y, size.X, 20);
                bar.Material = barMat;
                bar.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;

                bar.AddToPhysicsEngine = true;
                bar.Physics.Interactable = true;
                bar.Physics.Collidable = true;
                bar.Physics.Shape = ShapeType.Cylinder;
                bar.Physics.Mass = 2.0f;

                parentTrans.AddChild(pileTrans);
                pileTrans.AddChild(bar);

                Vector3 pivot = location + parentTrans.Translation;
                Vector3 pin = Vector3.UnitY;
                pivot.X -= size.X * 0.5f;

                HingeJoint joint = new HingeJoint(pivot, pin);
                joint.NewtonHingeCallback = doubleDoor;

                ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(bar.Physics, null, joint);
            }

            // /////////////////////////////////////////////////////////////////
            //
            // Add a sliding visualObject with limits
            //
            ////////////////////////////////////////////////////////////////////
            {
                Vector3 beatLocation = location;
                Vector3 beatSize = new Vector3(0.5f, 2.0f, 2.0f);

                beatLocation.X += size.X * 0.25f;

                TransformNode pileTrans = new TransformNode();
                pileTrans.Translation = beatLocation;

                Material beatMat = new Material();
                beatMat.Diffuse = Color.Red.ToVector4();
                beatMat.Specular = Color.White.ToVector4();
                beatMat.SpecularPower = 10;

                GeometryNode beat = new GeometryNode("Beat Slider");
                beat.Model = new Box(beatSize);
                beat.Material = beatMat;
                beat.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;

                beat.AddToPhysicsEngine = true;
                beat.Physics.Interactable = true;
                beat.Physics.Collidable = true;
                beat.Physics.Shape = ShapeType.Box;
                beat.Physics.Mass = 2.0f;

                parentTrans.AddChild(pileTrans);
                pileTrans.AddChild(beat);

                Vector3 pivot = beatLocation + parentTrans.Translation;
                Vector3 pin = Vector3.UnitX;

                sliderLimit.X = ((location.X - beatLocation.X) - size.X * 0.5f);
                sliderLimit.Y = ((location.X - beatLocation.X) + size.X * 0.5f);

                SliderJoint joint = new SliderJoint(pivot, pin);
                sliderUpdate = delegate(IntPtr slider, ref Newton.NewtonHingeSliderUpdateDesc desc)
                {
                    float distance = Newton.NewtonSliderGetJointPosit(slider);
                    if (distance < sliderLimit.X)
                    {
                        // if the distance is smaller than the predefine interval, stop the slider
                        desc.m_Accel = Newton.NewtonSliderCalculateStopAccel(slider, ref desc, sliderLimit.X);
                        return 1;
                    }
                    else if (distance > sliderLimit.Y)
                    {
                        // if the distance is larger than the predefine interval, stop the slider
                        desc.m_Accel = Newton.NewtonSliderCalculateStopAccel(slider, ref desc, sliderLimit.Y);
                        return 1;
                    }

                    // no action need it if the joint angle is with the limits
                    return 0;
                };
                joint.NewtonSliderCallback = sliderUpdate;

                ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(beat.Physics, bar.Physics, joint);
            }

            // /////////////////////////////////////////////////////////////////
            //
            // Add a corkscrew visualObject with limits
            //
            // /////////////////////////////////////////////////////////////////
            {
                Vector3 beatLocation = location;
                Vector3 beatSize = new Vector3(0.5f, 2.0f, 2.0f);

                beatLocation.X -= size.X * 0.25f;

                TransformNode pileTrans = new TransformNode();
                pileTrans.Translation = beatLocation;

                Material beatMat = new Material();
                beatMat.Diffuse = Color.YellowGreen.ToVector4();
                beatMat.Specular = Color.White.ToVector4();
                beatMat.SpecularPower = 10;

                GeometryNode beat = new GeometryNode("Beat Corkscrew");
                beat.Model = new Box(beatSize);
                beat.Material = beatMat;
                beat.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;

                beat.AddToPhysicsEngine = true;
                beat.Physics.Interactable = true;
                beat.Physics.Collidable = true;
                beat.Physics.Shape = ShapeType.Box;
                beat.Physics.Mass = 2.0f;

                parentTrans.AddChild(pileTrans);
                pileTrans.AddChild(beat);

                Vector3 pivot = beatLocation + parentTrans.Translation;
                Vector3 pin = Vector3.UnitX;

                corkscrewLimit.X = ((location.X - beatLocation.X) - size.X * 0.5f);
                corkscrewLimit.Y = ((location.X - beatLocation.X) + size.X * 0.5f);

                CorkscrewJoint joint = new CorkscrewJoint(pivot, pin);
                corkscrewUpdate = delegate(IntPtr corkscrew, Newton.NewtonHingeSliderUpdateDesc[] desc)
                {
                    // no action need it if the joint angle is with the limits
                    uint retCode = 0;

                    float distance = Newton.NewtonCorkscrewGetJointPosit(corkscrew);

                    // The first entry in NewtonHingeSliderUpdateDesc control the screw linear acceleration 
                    if (distance < corkscrewLimit.X)
                    {
                        // if the distance is smaller than the predefine interval, stop the slider
                        desc[0].m_Accel = Newton.NewtonCorkscrewCalculateStopAccel(corkscrew,
                            ref desc[0], corkscrewLimit.X);
                        retCode |= 1;
                    }
                    else if (distance > corkscrewLimit.Y)
                    {
                        // if the distance is larger than the predefine interval, stop the slider
                        desc[0].m_Accel = Newton.NewtonCorkscrewCalculateStopAccel(corkscrew, ref 
                            desc[0], corkscrewLimit.Y);
                        retCode |= 1;
                    }

                    // The second entry in NewtonHingeSliderUpdateDesc control the screw angular acceleration. 
                    // Make s small screw motor by setting the angular acceleration of the screw axis
                    // We are not going to limit the angular rotation of the screw, but is we did we should 
                    // or return code with 2
                    float omega = Newton.NewtonCorkscrewGetJointOmega(corkscrew);
                    desc[1].m_Accel = 1.5f - 0.2f * omega;

                    // or with 0x10 to tell newton this axis is active
                    retCode |= 2;

                    // return the code
                    return retCode;
                };
                joint.NewtonCorkscrewCallback = corkscrewUpdate;

                ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(beat.Physics, bar.Physics, joint);
            }

            // /////////////////////////////////////////////////////////////////
            //
            // Add a universal joint visualObject with limits
            //
            // /////////////////////////////////////////////////////////////////
            {
                Vector3 beatLocation = location;
                Vector3 beatSize = new Vector3(0.5f, 2.0f, 2.0f);

                beatLocation.X -= size.X * 0.45f;

                TransformNode pileTrans = new TransformNode();
                pileTrans.Translation = beatLocation;

                Material beatMat = new Material();
                beatMat.Diffuse = Color.YellowGreen.ToVector4();
                beatMat.Specular = Color.White.ToVector4();
                beatMat.SpecularPower = 10;

                GeometryNode beat = new GeometryNode("Beat Universal");
                beat.Model = new Box(beatSize);
                beat.Material = beatMat;
                beat.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;

                beat.AddToPhysicsEngine = true;
                beat.Physics.Interactable = true;
                beat.Physics.Collidable = true;
                beat.Physics.Shape = ShapeType.Box;
                beat.Physics.Mass = 2.0f;

                parentTrans.AddChild(pileTrans);
                pileTrans.AddChild(beat);

                Vector3 pivot = beatLocation + parentTrans.Translation;
                Vector3 pin0 = Vector3.UnitX;
                Vector3 pin1 = Vector3.UnitY;

                universalLimit.X = -30.0f * MathHelper.Pi / 180.0f;
                universalLimit.Y = 30.0f * MathHelper.Pi / 180.0f;

                UniversalJoint joint = new UniversalJoint(pivot, pin0, pin1);
                universalUpdate = delegate(IntPtr universal, Newton.NewtonHingeSliderUpdateDesc[] desc)
                {
                    // no action need it if the joint angle is with the limits
                    uint retCode = 0;

                    float omega = Newton.NewtonUniversalGetJointOmega0(universal);
                    desc[0].m_Accel = -1.5f - 0.2f * omega;
                    retCode |= 1;

                    float angle = Newton.NewtonUniversalGetJointAngle1(universal);
                    if (angle < universalLimit.X)
                    {
                        desc[1].m_Accel = Newton.NewtonUniversalCalculateStopAlpha1(universal, ref desc[1],
                            universalLimit.X);
                        retCode |= 2;
                    }
                    else if (angle > universalLimit.Y)
                    {
                        desc[1].m_Accel = Newton.NewtonUniversalCalculateStopAlpha1(universal, ref desc[1],
                            universalLimit.Y);
                        retCode |= 2;
                    }

                    // return the code
                    return retCode;
                };
                joint.NewtonUniversalCallback = universalUpdate;

                ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(beat.Physics, bar.Physics, joint);
            }
        }
Exemplo n.º 55
0
        private void SelectFromRoom()
        {
            // Now convert the near and far source to actual near and far 3D points based on our eye location
            // and view frustum
            Vector3 nearPoint = graphicsDevice.Viewport.Unproject(nearSource,
                State.ProjectionMatrix, State.ViewMatrix, room.getMarkerTransform());
            Vector3 farPoint = graphicsDevice.Viewport.Unproject(farSource,
                State.ProjectionMatrix, State.ViewMatrix, room.getMarkerTransform());

            // Have the physics engine intersect the pick ray defined by the nearPoint and farPoint with
            // the physics objects in the scene (which we have set up to approximate the model geometry).
            List<PickedObject> pickedObjects = ((NewtonPhysics)scene.PhysicsEngine).PickRayCast(nearPoint, farPoint);

            // If one or more objects intersect with our ray vector
            if (pickedObjects.Count > 0)
            {
                // Since PickedObject can be compared (which means it implements IComparable), we can sort it in
                // the order of closest intersected object to farthest intersected object
                pickedObjects.Sort();

                // We only care about the closest picked object for now, so we'll simply display the name
                // of the closest picked object whose container is a geometry node
                //label = ((GeometryNode)pickedObjects[0].PickedPhysicsObject.Container).Name + " is picked";

                GeometryNode tempNode = new GeometryNode();
                int i = 0;
                tempNode = (GeometryNode)pickedObjects[i].PickedPhysicsObject.Container;
                while (tempNode.GroupID == room.roomGroupID && i + 1 < pickedObjects.Count)
                {
                    i++;
                    tempNode = (GeometryNode)pickedObjects[i].PickedPhysicsObject.Container;
                }

                //Console.WriteLine("Duplicating item from " + tempNode.Name);
                selectedItem = catalog.selectPlacedItem(tempNode.Name);

                if (tempNode.GroupID != room.roomGroupID)
                    DrawSelectedItem(catalog.clonePlacedItem(tempNode.Name));

                if (selectedItem != null)
                {
                    //Console.WriteLine("New item is " + selectedItem.Label);
                    setState(STATES.MANIPULATING);
                }
                else
                {
                    Console.WriteLine("No item received");
                }
            }
            else
            {
                Console.WriteLine("Nothing to select");
            }
        }
Exemplo n.º 56
0
        private void CreateObject()
        {
            // Loads a textured model of a ship
            ModelLoader loader = new ModelLoader();
            Model shipModel = (Model)loader.Load("", "p1_wedge");

            // Create a geometry node of a loaded ship model
            GeometryNode shipNode = new GeometryNode("Ship");
            shipNode.Model = shipModel;
            // This ship model has material definitions in the model file, so instead
            // of creating a material node for this ship model, we simply use its internal materials
            shipNode.Model.UseInternalMaterials = true;

            // Create a transform node to define the transformation for the ship
            shipTransNode = new TransformNode();
            shipTransNode.Translation = new Vector3(0, 0, 0);
            shipTransNode.Scale = new Vector3(0.002f, 0.002f, 0.002f); // It's huge!
            shipTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0),
                MathHelper.ToRadians(0));

            scene.RootNode.AddChild(shipTransNode);
            shipTransNode.AddChild(shipNode);
        }
Exemplo n.º 57
0
        private void CreateGround()
        {
            GeometryNode groundNode = new GeometryNode("Ground");

            // We will use TexturedBox instead of regular Box class since we will need the
            // texture coordinates elements for passing the vertices to the SimpleShadowShader
            // we will be using
            groundNode.Model = new TexturedBox(324, 180, 0.1f);

            // Set this ground model to act as an occluder so that it appears transparent
            groundNode.IsOccluder = true;

            // Make the ground model to receive shadow casted by other objects with
            // ShadowAttribute.ReceiveCast
            groundNode.Model.ShadowAttribute = ShadowAttribute.ReceiveOnly;
            // Assign a shadow shader for this model that uses the IShadowMap we assigned to the scene
            groundNode.Model.Shader = new SimpleShadowShader(scene.ShadowMap);

            Material groundMaterial = new Material();
            groundMaterial.Diffuse = Color.Gray.ToVector4();
            groundMaterial.Specular = Color.White.ToVector4();
            groundMaterial.SpecularPower = 20;

            groundNode.Material = groundMaterial;

            groundMarkerNode.AddChild(groundNode);
        }
Exemplo n.º 58
0
        /// <summary>
        /// Creates a rope-like object by connecting several ball and socket joints.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="parentTrans"></param>
        public static void AddRope(Scene scene, TransformNode parentTrans)
        {
            Vector3 size = new Vector3(1.5f, 0.25f, 0.25f);
            Vector3 location = new Vector3(0, 9, 0);

            IPhysicsObject link0 = null;
            Color[] colors = {Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue,
                                  Color.Indigo, Color.Violet};

            PrimitiveModel capsule = new Capsule(size.Y, size.X, 12);
            for (int i = 0; i < 7; i++)
            {
                TransformNode pileTrans = new TransformNode();
                pileTrans.Translation = location;

                Material linkMat = new Material();
                linkMat.Diffuse = colors[i].ToVector4();
                linkMat.Specular = Color.White.ToVector4();
                linkMat.SpecularPower = 10;

                GeometryNode link1 = new GeometryNode("Link " + i);
                link1.Model = capsule;
                link1.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;
                link1.Material = linkMat;

                link1.AddToPhysicsEngine = true;
                link1.Physics.Interactable = true;
                link1.Physics.Collidable = true;
                link1.Physics.Shape = ShapeType.Capsule;
                link1.Physics.Mass = 2.0f;
                link1.Physics.LinearDamping = 1f;
                link1.Physics.AngularDamping = new Vector3(1f, 1f, 1f);

                parentTrans.AddChild(pileTrans);
                pileTrans.AddChild(link1);

                Vector3 pivot = location + parentTrans.Translation;
                pivot.Y += (size.X - size.Y) * 0.5f;

                BallAndSocketJoint joint = new BallAndSocketJoint(pivot);
                joint.Pin = -Vector3.UnitY;
                joint.MaxConeAngle = 0.0f;
                joint.MaxTwistAngle = 10.0f * MathHelper.Pi / 180;

                ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(link1.Physics, link0, joint);

                link0 = link1.Physics;
                location = new Vector3(location.X, location.Y
                    - (size.X - size.Y), location.Z);
            }
        }
Exemplo n.º 59
0
        public static void AddDoubleSwingDoors(Scene scene, TransformNode parentTrans)
        {
            Vector3 size = new Vector3(2.0f, 5.0f, 0.5f);
            Vector3 location = new Vector3(0, 3.5f, -3);

            Material linkMat = new Material();
            linkMat.Diffuse = Color.Cyan.ToVector4();
            linkMat.Specular = Color.White.ToVector4();
            linkMat.SpecularPower = 10;

            GeometryNode link1 = null;
            // Make first wing
            {
                TransformNode pileTrans = new TransformNode();
                pileTrans.Translation = location;

                link1 = new GeometryNode("Door 1");
                link1.Model = new Box(size.X, size.Y, size.Z);
                link1.Material = linkMat;
                link1.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;

                link1.AddToPhysicsEngine = true;
                link1.Physics.Interactable = true;
                link1.Physics.Collidable = true;
                link1.Physics.Shape = ShapeType.Box;
                link1.Physics.Mass = 2.0f;

                parentTrans.AddChild(pileTrans);
                pileTrans.AddChild(link1);

                Vector3 pivot = location + parentTrans.Translation;
                Vector3 pin = Vector3.UnitY;
                pivot.X += size.X * 0.5f;
                pivot.Y -= size.Y * 0.5f;

                HingeJoint joint = new HingeJoint(pivot, pin);
                joint.NewtonHingeCallback = doubleDoor;

                ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(link1.Physics, null, joint);
            }

            // Make second wing
            {
                location.X -= size.X;

                TransformNode pileTrans = new TransformNode();
                pileTrans.Translation = location;

                GeometryNode link2 = new GeometryNode("Door 2");
                link2.Model = new Box(size.X, size.Y, size.Z);
                link2.Material = linkMat;
                link2.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;

                link2.AddToPhysicsEngine = true;
                link2.Physics.Interactable = true;
                link2.Physics.Collidable = true;
                link2.Physics.Shape = ShapeType.Box;
                link2.Physics.Mass = 2.0f;

                parentTrans.AddChild(pileTrans);
                pileTrans.AddChild(link2);

                Vector3 pivot = location + parentTrans.Translation;
                Vector3 pin = Vector3.UnitY;
                pivot.X += size.X * 0.5f;
                pivot.Y -= size.Y * 0.5f;

                HingeJoint joint = new HingeJoint(pivot, pin);
                joint.NewtonHingeCallback = doubleDoor;

                ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(link2.Physics, link1.Physics, joint);
            }
        }
Exemplo n.º 60
0
        private void createCorderBackground()
        {
            cornerPanelTransformNode = new TransformNode("Corner Panel Trans");
            scene.RootNode.AddChild(cornerPanelTransformNode);

            cornerPanelNode = new GeometryNode("Corner Panel");
            cornerPanelNode.Model = new TexturedLayer(new Vector2(250, 250));//new Box(300, 250, 1);
            cornerPanelTransformNode.AddChild(cornerPanelNode);

            cornerPanelTransformNode.Translation = new Vector3(2.3f, -1.58f, -5);
            cornerPanelTransformNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, MathHelper.ToRadians(90));
            //cornerPanelTransformNode.Translation = new Vector3(0, .06f, -1);

            cornerPanelTransformNode.Scale = new Vector3(0.005f, 0.005f, 0.005f);

            Material pointerLabelMaterial = new Material();
            pointerLabelMaterial.Diffuse = Color.White.ToVector4(); ;// new Vector4(0, 0.5f, 0, 1);
               // pointerLabelMaterial.Specular = Color.White.ToVector4();
               // pointerLabelMaterial.SpecularPower = 50;
            pointerLabelMaterial.Texture = Content.Load<Texture2D>("hud/cornerPanel");

            cornerPanelNode.Material = pointerLabelMaterial;

            //cornerPanelTransformNode.SetAlpha(0.55f);
            Vector4 tempColor = cornerPanelNode.Material.Diffuse;
            Vector3 tempVec = new Vector3(tempColor.X, tempColor.Y, tempColor.Z);
            cornerPanelNode.Material.Diffuse = new Vector4(tempVec, 0.7f);
        }