コード例 #1
0
 private void ballBounceGround(NewtonPhysics.CollisionPair pair)
 {
     p1Tiro.bounceCount++;
     if (p1Tiro._momentum.Z < 0)
     {
         Vector3 impulseForceWithDrag = new Vector3(p1Tiro._momentum.X * -0.3f, p1Tiro._momentum.Y * -0.3f, p1Tiro._momentum.Z * -1.7f);
         p1Tiro._momentum += impulseForceWithDrag;
         if (p1Tiro._momentum.Z < 0.2)
         {
             p1Tiro._momentum.Z = 0;
         }
     }
 }
コード例 #2
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);
        }
コード例 #3
0
        private void playerShot(NewtonPhysics.CollisionPair pair)
        {
            Vector3    scaleBox;
            Quaternion rotationBox;
            Vector3    translationBox;

            pair.CollisionObject2.PhysicsWorldTransform.Decompose(out scaleBox, out rotationBox, out translationBox);

            Vector3    scaleSphere;
            Quaternion rotationSphere;
            Vector3    translationSphere;

            pair.CollisionObject1.PhysicsWorldTransform.Decompose(out scaleSphere, out rotationSphere, out translationSphere);

            Vector3 racket_direction = Vector3.Transform(new Vector3(0, 0, 1), rotationBox);

            Vector3 resulting_direction = Vector3.Transform(racket_direction, Quaternion.Inverse(rotationSphere));

            p1Tiro.addImpulse_using_Mass_and_Velocity(1, resulting_direction / 10);

            p1Tiro.animationStartedApplyGravity = true;
        }
コード例 #4
0
ファイル: Tutorial8.cs プロジェクト: ARLM-Attic/goblin-xna
 /// <summary>
 /// A callback function that will be called when the box and sphere model collides
 /// </summary>
 /// <param name="pair"></param>
 private void BoxSphereCollision(NewtonPhysics.CollisionPair pair)
 {
     Console.WriteLine("Box and Sphere has collided");
 }
コード例 #5
0
ファイル: Tutorial8.cs プロジェクト: ARLM-Attic/goblin-xna
        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);
        }
コード例 #6
0
 private void playerScore(NewtonPhysics.CollisionPair pair)
 {
     score++;
     p1Tiro.resetBall(groundMarkerNode);
 }
コード例 #7
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);
        }