Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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;
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public Block(MarkerNode markerNode, string[] names, float scale, ref GlobalVariables g)
        {
            global = g;

            buildingsInBlocks = new List <Building>();

            blockNode = markerNode;

            blockTransNode       = new TransformNode();
            blockTransNode.Scale = Vector3.One * scale;
            //////////////////////////////////////////////////////////////////////blockTransNode.Translation = new Vector3(0.0f, -64.25f, 0.0f);
            //blockTransNode.Translation = new Vector3(0.0f, -64.25f, 0.0f);  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //blockTransNode.Translation = new Vector3(-33.5f, -54.25f, 0);
            blockTransNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, MathHelper.PiOver2);
            blockNode.AddChild(blockTransNode);

            foreach (string s in names)
            {
                //Note, this needs to be changed so we are able to add different buildings to a marker

                Building tempBuilding = new Building(s, ref global);
                tempBuilding.loadBuildingModel(true, 1.0f); //change scale factor if necessary
                buildingsInBlocks.Add(tempBuilding);
                //blockTransNode.AddChild(tempBuilding.getBuildingNode()); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //  blockTransNode.Scale = new Vector3(blockTransNode.Scale.X * 1.0f, blockTransNode.Scale.Y * 1.0f, blockTransNode.Scale.Z * 1.0f);
                //    blockNode.AddChild(blockTransNode);
            }
        }
Beispiel #8
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);
        }
Beispiel #9
0
        protected override void Draw(GameTime gameTime)
        {
            // Set the render target for rendering the AR scene
            scene.SceneRenderTarget = arViewRenderTarget;
            // Set the scene background size to be the size of the AR scene viewport
            scene.BackgroundBound = arViewRect;
            // Set the camera to be the AR camera
            scene.CameraNode = arCameraNode;
            // Associate the overlaid model with the ground marker for rendering it in AR scene
            scene.RootNode.RemoveChild(overlayNode.Parent);
            groundMarkerNode.AddChild(overlayNode.Parent);
            // Don't render the marker board and camera representation
            markerBoardGeom.Enabled = false;
            vrCameraRepNode.Enabled = false;
            // Show the video background
            scene.ShowCameraImage = true;
            // Render the AR scene
            scene.Draw(gameTime.ElapsedGameTime, gameTime.IsRunningSlowly);

            // Set the render target for rendering the VR scene
            scene.SceneRenderTarget = vrViewRenderTarget;
            // Set the scene background size to be the size of the VR scene viewport
            scene.BackgroundBound = vrViewRect;
            // Set the camera to be the VR camera
            scene.CameraNode = vrCameraNode;
            // Remove the overlaid model from the ground marker for rendering it in VR scene
            groundMarkerNode.RemoveChild(overlayNode.Parent);
            scene.RootNode.AddChild(overlayNode.Parent);
            // Render the marker board and camera representation in VR scene
            markerBoardGeom.Enabled = true;
            vrCameraRepNode.Enabled = true;
            // Update the transformation of the camera representation in VR scene based on the
            // marker array transformation
            if (groundMarkerNode.MarkerFound)
            {
                vrCameraRepTransNode.WorldTransformation = Matrix.Invert(groundMarkerNode.WorldTransformation);
            }
            // Do not show the video background
            scene.ShowCameraImage = false;
            // Re-traverse the scene graph since we have modified it, and render the VR scene
            scene.RenderScene(false, true);

            // Set the render target back to the frame buffer
            State.Device.SetRenderTarget(null);
            // Render the two textures rendered on the render targets
            State.SharedSpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque);
            State.SharedSpriteBatch.Draw(arViewRenderTarget, arViewRect, Color.White);
            State.SharedSpriteBatch.Draw(vrViewRenderTarget, vrViewRect, Color.White);
            State.SharedSpriteBatch.End();
        }
Beispiel #10
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);
        }
Beispiel #11
0
        private void CreateGround()
        {
            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(800, 600, 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);

            groundNode.AddToPhysicsEngine = true;
            groundNode.Physics.Shape      = ShapeType.Box;
            groundNode.Physics.Collidable = true;
            //groundNode.Physics.MaterialName = "Ground";
            groundNode.Physics.ApplyGravity  = false;
            groundNode.Physics.Interactable  = true;
            groundNode.Physics.Manipulatable = true;
            groundNode.Physics.Mass          = 1;
            groundNode.Physics.Pickable      = true;

            NewtonPhysics.CollisionPair CannonGroundColisionPair = new NewtonPhysics.CollisionPair(p1Tiro.obj.Physics, groundNode.Physics);

            ((NewtonPhysics)scene.PhysicsEngine).AddCollisionCallback(CannonGroundColisionPair, ballBounceGround);
        }
Beispiel #12
0
        //Let's set up marker tracking

        public void CreateGround()
        {
            GeometryNode groundNode = new GeometryNode("Ground");

            groundNode.Model = new Box(95, 59, 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.ReceiveShadows = true;

            Material groundMaterial = new Material();

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

            groundNode.Material = groundMaterial;

            groundMarkerNode.AddChild(groundNode);
        }
Beispiel #13
0
        private void CreateLights()
        {
            // Create a directional light source
            LightSource lightSource = new LightSource();

            lightSource.Direction = new Vector3(1, -1, -1);
            lightSource.Diffuse   = new Vector4(0.8f, 0.8f, 0.8f, 1);
            lightSource.Specular  = new Vector4(0.6f, 0.6f, 0.6f, 1);

            // Create a light node to hold the light source
            LightNode lightNode = new LightNode();

            lightNode.CastShadows     = true;
            lightNode.LightProjection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                                                                            1, 1f, 500);
            // Add an ambient component
            lightNode.AmbientLightColor = new Vector4(0.3f, 0.3f, 0.3f, 1);
            lightNode.LightSource       = lightSource;

            // Add this light node to the root node
            groundMarkerNode.AddChild(lightNode);
        }
Beispiel #14
0
        public Graphics3D(MarkerNode MarkerNode, IShadowMap ShadowMap)
        {
            //Asignation Ground Node
            this.groundMarkerNode = MarkerNode;
            //Asignation Shadow Map
            this.GShadowMap = ShadowMap;

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

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

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

            LoadLevel = false;
            LoadCars  = false;
        }
Beispiel #15
0
        private void CreateObjects()
        {
            // Create a marker node to track a ground marker array.
#if USE_PATTERN_MARKER
            if (useSingleMarker)
            {
                groundMarkerNode = new MarkerNode(scene.MarkerTracker, "patt.hiro", 16, 16, markerSize, 0.7f);
            }
            else
            {
                groundMarkerNode = new MarkerNode(scene.MarkerTracker, "NyARToolkitGroundArray.xml",
                                                  NyARToolkitTracker.ComputationMethod.Average);
            }
#else
            groundMarkerNode = new MarkerNode(scene.MarkerTracker, "NyARToolkitIDGroundArray.xml",
                                              NyARToolkitTracker.ComputationMethod.Average);
#endif
            scene.RootNode.AddChild(groundMarkerNode);

            //toolbarMarkerNode = new MarkerNode(scene.MarkerTracker, "NyARToolkitIDToolbar1.xml",
            //  NyARToolkitTracker.ComputationMethod.Average);
            //scene.RootNode.AddChild(toolbarMarkerNode);

            SynchronizedGeometryNode wall = new SynchronizedGeometryNode("wall");
            wall.Model = new Box(WALL_WIDTH, WALL_HEIGHT, WALL_DEPTH);
            wall.Model.ShowBoundingBox = true;

            Material wallMaterial = new Material();
            wallMaterial.Diffuse  = Color.Gray.ToVector4();
            wallMaterial.Ambient  = Color.Blue.ToVector4();
            wallMaterial.Emissive = Color.Green.ToVector4();
            wall.Material         = wallMaterial;

            TransformNode wallTrans = new TransformNode();
            wallTrans.Translation     = new Vector3(0, 0, -20);
            wall.Physics.Collidable   = true;
            wall.Physics.Interactable = true;
            wall.AddToPhysicsEngine   = true;
            wall.Physics.Shape        = GoblinXNA.Physics.ShapeType.Box;
            wall.Physics.Mass         = 0;

            //scene.RootNode.AddChild(wall);
            groundMarkerNode.AddChild(wallTrans);
            wallTrans.AddChild(wall);
            /////////////////////////////////////////////////////


            SynchronizedGeometryNode ball = new SynchronizedGeometryNode("ball");
            ball.Model = new Sphere(SPHERE_RADIUS, 20, 20);
            ball.Model.ShowBoundingBox = true;

            Material ballMaterial = new Material();
            ballMaterial.Diffuse = Color.Yellow.ToVector4();
            //ballMaterial.Ambient = Color.Maroon.ToVector4();
            //ballMaterial.Emissive = Color.LightCoral.ToVector4();
            ball.Material = ballMaterial;

            TransformNode ballTrans = new TransformNode();
            ballTrans.Translation = new Vector3(0, 0, 200);

            //ball.Physics = new PhysicsObject(ball);
            ball.Physics.Collidable     = true;
            ball.Physics.Interactable   = true;
            ball.Physics.AngularDamping = Vector3.Zero;
            ball.Physics.LinearDamping  = 0f;

            ball.Physics.Shape      = GoblinXNA.Physics.ShapeType.Sphere;
            ball.Physics.Mass       = 10;
            ball.AddToPhysicsEngine = true;

            ballTrans.AddChild(ball);
            groundMarkerNode.AddChild(ballTrans);

            /////////////////////////////////////////////////////////////////

            paddleNode       = new SynchronizedGeometryNode("paddle");
            paddleNode.Model = new Box(PADDLE_HEIGHT, PADDLE_WIDTH, PADDLE_DEPTH);

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

            paddleNode.Physics.Collidable   = true;
            paddleNode.Physics.Interactable = true;
            paddleNode.Physics.Shape        = GoblinXNA.Physics.ShapeType.Box;
            paddleNode.Physics.Mass         = 10;
            paddleNode.AddToPhysicsEngine   = true;

            groundMarkerNode.AddChild(paddleNode);
        }
Beispiel #16
0
 private void dropBall()
 {
     ball_drop_delay     = false;
     ball_drop_countdown = 0;
     ground_marker_node.AddChild(vball.getTransformNode());
 }
Beispiel #17
0
        private void createObjects()
        {
            // Create a marker node to track the ground array
            ground_marker_node = new MarkerNode(scene.MarkerTracker, "SlimeGroundArray.xml", NyARToolkitTracker.ComputationMethod.Average);
            scene.RootNode.AddChild(ground_marker_node);

            InvisibleWall invisWallOne   = new InvisibleWall(float.MaxValue, new Vector3(COURT_WIDTH, PLANAR_THICKNESS, COURT_LENGTH));
            InvisibleWall invisWallTwo   = new InvisibleWall(float.MaxValue, new Vector3(PLANAR_THICKNESS, COURT_LENGTH, COURT_LENGTH));
            InvisibleWall invisWallThree = new InvisibleWall(float.MaxValue, new Vector3(COURT_WIDTH, PLANAR_THICKNESS, COURT_LENGTH));
            InvisibleWall invisWallFour  = new InvisibleWall(float.MaxValue, new Vector3(PLANAR_THICKNESS, COURT_LENGTH, COURT_LENGTH));

            invisWallOne.translate(new Vector3(0, COURT_LENGTH / 2, COURT_LENGTH / 2));
            invisWallTwo.translate(new Vector3(-(COURT_WIDTH / 2), 0, COURT_LENGTH / 2));
            invisWallThree.translate(new Vector3(0, -(COURT_LENGTH / 2), COURT_LENGTH / 2));
            invisWallFour.translate(new Vector3(COURT_WIDTH / 2, 0, COURT_LENGTH / 2));

            // Add the walls onto the ground marker
            ground_marker_node.AddChild(invisWallOne.getTransformNode());
            ground_marker_node.AddChild(invisWallTwo.getTransformNode());
            ground_marker_node.AddChild(invisWallThree.getTransformNode());
            ground_marker_node.AddChild(invisWallFour.getTransformNode());

            // Create the court
            court = new Court(float.MaxValue, new Vector3(COURT_WIDTH, COURT_LENGTH, PLANAR_THICKNESS * 4));
            // Initial translation
            court.translate(new Vector3(0, 0, -14f));
            // Add it to the scene
            ground_marker_node.AddChild(court.getTransformNode());

            // Time to create the net
            Net net = new Net(float.MaxValue, new Vector3(COURT_WIDTH, PLANAR_THICKNESS, GROUND_MARKER_SIZE));

            // Initial translation
            net.translate(new Vector3(0, 0, 1f + (GROUND_MARKER_SIZE / 2)));
            // Add it to the scene
            ground_marker_node.AddChild(net.getTransformNode());

            // Lets create the all important volleyball
            if (selected_game_type == (int)game_types.opponent)
            {
                vball = new VolleyBall(1f, GROUND_MARKER_SIZE / 2f, bounceSound, true);
            }
            else
            {
                vball = new VolleyBall(1f, GROUND_MARKER_SIZE / 2f, bounceSound, false);
            }
            // Perform initial manipulations
            vball.translate(PLAYER_BALL_START);
            // Add it to the scene
            ground_marker_node.AddChild(vball.getTransformNode());

            // Create a marker node to track the paddle
            player_marker_node = new MarkerNode(scene.MarkerTracker, "id511.xml", NyARToolkitTracker.ComputationMethod.Average);
            scene.RootNode.AddChild(player_marker_node);

            // Create the slime for the player
            //player_slime = new Paddle(float.MaxValue, new Vector3(WAND_MARKER_SIZE * 1.5f, WAND_MARKER_SIZE * 1.5f, 3f), Color.Red.ToVector4());
            player_slime = new Slime(float.MaxValue, GROUND_MARKER_SIZE, new Vector4(0.160784f, 0.501961f, 0.72549f, 1f), COURT_WIDTH / 2, -1 * COURT_WIDTH / 2, 0f, -1 * COURT_LENGTH / 2);
            // Initial translation
            player_slime.translate(PLAYER_SLIME_START);
            //player_slime.setRotation(Quaternion.CreateFromAxisAngle(Vector3.UnitX, MathHelper.ToRadians(-PADDLE_ANGLE)));
            //player_slime.setRotation(Quaternion.CreateFromAxisAngle(Vector3.UnitX, MathHelper.ToRadians(90)));
            // Add it to the scene
            ground_marker_node.AddChild(player_slime.getTransformNode());

            // Create the slime for the opponent
            //opponent_slime = new Paddle(float.MaxValue, new Vector3(WAND_MARKER_SIZE  * 1.5f, WAND_MARKER_SIZE * 1.5f, 3f), Color.Purple.ToVector4());
            opponent_slime = new Slime(float.MaxValue, GROUND_MARKER_SIZE, new Vector4(0.556863f, 0.266667f, 0.678431f, 1f), COURT_WIDTH / 2, -1 * COURT_WIDTH / 2, COURT_LENGTH / 2, 0f);
            // Initial translation
            opponent_slime.translate(OPPONENT_SLIME_START);
            //opponent_slime.setRotation(Quaternion.CreateFromAxisAngle(Vector3.UnitX, MathHelper.ToRadians(PADDLE_ANGLE)));
            //opponent_slime.setRotation(Quaternion.CreateFromAxisAngle(Vector3.UnitX, MathHelper.ToRadians(90)));
            // Add it to the scene
            ground_marker_node.AddChild(opponent_slime.getTransformNode());

            // Create the laser sight target
            target = new Target(TARGET_SIZE, Color.Red.ToVector4());
            // perform initial translations
            target.setTranslation(new Vector3(PLAYER_BALL_START.X, PLAYER_BALL_START.Y, (TARGET_SIZE / 2) + PLANAR_THICKNESS));
            // Add it to the scene
            ground_marker_node.AddChild(target.getTransformNode());
        }
Beispiel #18
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.
            groundMarkerNode = new MarkerNode(scene.MarkerTracker, "ALVARGroundArray.xml");

            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.
            toolbarMarkerNode = new MarkerNode(scene.MarkerTracker, "ALVARToolbar.xml");

            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);
        }
Beispiel #19
0
        private void CreateObjects()
        {
            // Create a marker node to track a ground marker array.
            groundMarkerNode = new MarkerNode(scene.MarkerTracker, "ALVARGroundArray.xml");


            // 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 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(100f, 100f, 5);

            // 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.
            toolbarMarkerNode = new MarkerNode(scene.MarkerTracker, "ALVARToolbar.xml");

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

            p1Tiro = new Tiro("p1Tiro", new Vector3(150, 0, 300), 1, 20, scene, groundMarkerNode);
            groundMarkerNode.AddChild(p1Tiro.objTransfNode);
            updatables.Add(p1Tiro);

            NewtonPhysics.CollisionPair CannonPlayerColisionPair = new NewtonPhysics.CollisionPair(p1Tiro.obj.Physics, boxNode.Physics);

            ((NewtonPhysics)scene.PhysicsEngine).AddCollisionCallback(CannonPlayerColisionPair, playerShot);

            targetNode = 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
            targetNode.Model = new TexturedBox(20f, 20f, 5);

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

            Material targetMaterial = new Material();

            targetMaterial.Diffuse       = Color.Indigo.ToVector4();
            targetMaterial.Specular      = Color.DarkGoldenrod.ToVector4();
            targetMaterial.SpecularPower = 10;

            targetNode.Material = targetMaterial;

            groundMarkerNode.AddChild(targetNode);

            NewtonPhysics.CollisionPair PlayerScoreColisionPair = new NewtonPhysics.CollisionPair(p1Tiro.obj.Physics, targetNode.Physics);

            ((NewtonPhysics)scene.PhysicsEngine).AddCollisionCallback(PlayerScoreColisionPair, playerScore);
        }
Beispiel #20
0
        public void CreateObjects()
        {
            floor       = new GeometryNode("Floor");//floor
            floor.Model = new Box(floorBreadth, floorLength, 0.0001f);
            floor.Model.ReceiveShadows = true;
            floorTransNode             = new TransformNode();
            floorTransNode.Translation = new Vector3(floorBreadth / 3, -floorLength / 2, 0);      // 0 0
            floor.Physics.Collidable   = true;
            floor.Physics.Pickable     = true;
            floor.GroupID            = roomGroupID;
            floor.Physics.Shape      = GoblinXNA.Physics.ShapeType.Box;
            floor.AddToPhysicsEngine = true;
            //grid1.IsOccluder = true;


            //Material for the room floor
            floorMaterial = new Material();
            Vector4 alpha     = Color.Gray.ToVector4();
            Vector3 tempAlpha = new Vector3(alpha.X, alpha.Y, alpha.Z);

            floorMaterial.Diffuse       = new Vector4(tempAlpha, 0.2f);
            floorMaterial.Specular      = Color.White.ToVector4();
            floorMaterial.SpecularPower = 20;

            floor.Material = floorMaterial;

            //Material for the walls
            wallsMaterial               = new Material();
            wallsMaterial.Diffuse       = Color.Gray.ToVector4();
            wallsMaterial.Specular      = Color.White.ToVector4();
            wallsMaterial.SpecularPower = 20;

            frontWall                      = new GeometryNode("Front wall");//front wall
            frontWall.Model                = new Box(floorBreadth, floorLength, 1);
            frontWallTransNode             = new TransformNode();
            frontWallTransNode.Translation = new Vector3(floorBreadth / 3, 0, floorLength / 2);  // 1 0
            frontWallTransNode.Rotation    = Quaternion.CreateFromAxisAngle(Vector3.UnitX, MathHelper.ToRadians(90));
            frontWall.Material             = wallsMaterial;
            frontWall.GroupID              = roomGroupID;
            frontWall.AddToPhysicsEngine   = true;
            frontWall.Physics.Collidable   = true;
            frontWall.Physics.Pickable     = true;
            frontWall.Physics.Shape        = GoblinXNA.Physics.ShapeType.Box;



            rightWall                      = new GeometryNode("Right wall");//right side wall
            rightWall.Model                = new Box(floorBreadth, floorLength, 1);
            rightWallTransNode             = new TransformNode();
            rightWallTransNode.Translation = new Vector3(floorBreadth * 4.2f / 5, -floorLength / 2, floorLength / 2); // -1 0
            rightWallTransNode.Rotation    = Quaternion.CreateFromAxisAngle(Vector3.UnitY, MathHelper.ToRadians(90));
            rightWall.Material             = wallsMaterial;
            rightWall.AddToPhysicsEngine   = true;
            rightWall.GroupID              = roomGroupID;
            rightWall.Physics.Pickable     = true;
            rightWall.Physics.Collidable   = true;
            rightWall.Physics.Shape        = GoblinXNA.Physics.ShapeType.Box;



            // Create a marker node to track a ground marker array.
#if USE_ARTAG
            groundMarkerNode = new MarkerNode(scene.MarkerTracker, "ground");

            // Since we expect that the ground marker array won't move very much, we use a
            // small smoothing alpha.
            //groundMarkerNode.Smoother = new DESSmoother(0.2f, 0.1f, 1, 1);
#else
            //   groundMarkerNode = new MarkerNode(scene.MarkerTracker, "ALVARGroundArray.xml");
            groundMarkerNode = new MarkerNode(this.scene.MarkerTracker, "ALVARConfig.txt");
#endif



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



            //Change the toolbar.txt config file. As of now, toolbar has markers included in the long stretch-alvarConfig.txt
            worldInMiniatureMarkerNode = new MarkerNode(scene.MarkerTracker, "ALVARConfig32_33.txt");


            scene.RootNode.AddChild(worldInMiniatureMarkerNode);



            groundMarkerNode.AddChild(floorTransNode);
            floorTransNode.AddChild(floor);


            groundMarkerNode.AddChild(frontWallTransNode);
            frontWallTransNode.AddChild(frontWall);

            groundMarkerNode.AddChild(rightWallTransNode);
            rightWallTransNode.AddChild(rightWall);
        }
Beispiel #21
0
        public void Draw(TimeSpan elapsedTime)
        {
            // Reset the XNA viewport to our centered and resized viewport
            State.Device.Viewport = viewport;

            // Set the render target for rendering the AR scene
            scene.SceneRenderTarget = arViewRenderTarget;
            scene.BackgroundColor   = Color.Black;
            // Set the scene background size to be the size of the AR scene viewport
            scene.BackgroundBound = arViewRect;
            // Set the camera to be the AR camera
            scene.CameraNode = arCameraNode;
            // Associate the overlaid model with the ground marker for rendering it in AR scene
            scene.RootNode.RemoveChild(overlayRoot);
            groundMarkerNode.AddChild(overlayRoot);
            // Don't render the marker board and camera representation
            markerBoardGeom.Enabled = false;
            vrCameraRepNode.Enabled = false;
            // Show the video background
            scene.BackgroundTexture = videoTexture;
            // Render the AR scene
            scene.Draw(elapsedTime, false);

            // Set the render target for rendering the VR scene
            scene.SceneRenderTarget = vrViewRenderTarget;
            scene.BackgroundColor   = Color.CornflowerBlue;
            // Set the scene background size to be the size of the VR scene viewport
            scene.BackgroundBound = vrViewRect;
            // Set the camera to be the VR camera
            scene.CameraNode = vrCameraNode;
            // Remove the overlaid model from the ground marker for rendering it in VR scene
            groundMarkerNode.RemoveChild(overlayRoot);
            scene.RootNode.AddChild(overlayRoot);
            // Render the marker board and camera representation in VR scene
            markerBoardGeom.Enabled = true;
            vrCameraRepNode.Enabled = true;
            // Update the transformation of the camera representation in VR scene based on the
            // marker array transformation
            if (groundMarkerNode.MarkerFound)
            {
                vrCameraRepTransNode.WorldTransformation = Matrix.Invert(groundMarkerNode.WorldTransformation);
            }
            // Do not show the video background
            scene.BackgroundTexture = null;
            // Re-traverse the scene graph since we have modified it, and render the VR scene
            scene.RenderScene(false, true);

            // Adjust the viewport to be centered
            arViewRect.X += viewport.X;
            vrViewRect.X += viewport.X;

            // Set the render target back to the frame buffer
            State.Device.SetRenderTarget(null);
            State.Device.Clear(Color.Black);
            // Render the two textures rendered on the render targets
            State.SharedSpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque);
            State.SharedSpriteBatch.Draw(arViewRenderTarget, arViewRect, Color.White);
            State.SharedSpriteBatch.Draw(vrViewRenderTarget, vrViewRect, Color.White);
            State.SharedSpriteBatch.End();

            // Reset the adjustments
            arViewRect.X -= viewport.X;
            vrViewRect.X -= viewport.X;
        }