Esempio n. 1
0
      public override void Initialize()
      {
         cubeCollision_ = new CubeCollision(this.Game, this.PositionInitiale, this.Dimension, Vector3.Zero);//ROTATION TJRS A ZERO
         float arreteUn = MathHelper.Max(MathHelper.Max(Dimension.X,Dimension.Y),Dimension.Z);
         float arreteDeux = MathHelper.Max(Dimension.X,Dimension.Z);
         float rayon = (float)Math.Sqrt(arreteUn*arreteUn + arreteDeux*arreteDeux);

         SphereCollision_ = new BoundingSphere(Position, rayon);
         base.Initialize();
      }
      public override void Initialize()
      {
          cubeCollision_ = new CubeCollision(this.Game, this.Position, Dimension, this.Rotation);
         SphereCollision = new BoundingSphere(this.Position, 2f); //TODO, AJOUTER BON RAYON
      
         Rotation = Vector3.Zero;
         Priorité = 0;

         Monde = Matrix.Identity;
         Monde *= Matrix.CreateScale(Échelle);
         Monde *= Matrix.CreateFromYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z);
         Monde *= Matrix.CreateTranslation(Position);

         base.Initialize();
      }
Esempio n. 3
0
      public bool EnCollisionAvec(CubeCollision cube)
      {
         bool enCollision = true;
         Vector3 Distance = this.Position - cube.Position;

         //case 1
         Vector3 AxeComparé = this.AxeX;
         if (ValeurAbsolue(Vector3.Dot(Distance, AxeComparé)) > this.DemiDimention.X + ValeurAbsolue(Vector3.Dot(cube.DemiDimention.X * cube.AxeX, AxeComparé)) + ValeurAbsolue(Vector3.Dot(cube.DemiDimention.Y * cube.AxeY, AxeComparé)) + ValeurAbsolue(Vector3.Dot(cube.DemiDimention.Z * cube.AxeZ, AxeComparé)))
            enCollision = false;

         AxeComparé = this.AxeY;
         if (enCollision && ValeurAbsolue(Vector3.Dot(Distance, AxeComparé)) > this.DemiDimention.Y + ValeurAbsolue(Vector3.Dot(cube.DemiDimention.X * cube.AxeX, AxeComparé)) + ValeurAbsolue(Vector3.Dot(cube.DemiDimention.Y * cube.AxeY, AxeComparé)) + ValeurAbsolue(Vector3.Dot(cube.DemiDimention.Z * cube.AxeZ, AxeComparé)))
            enCollision = false;

         AxeComparé = this.AxeZ;
         if (enCollision && ValeurAbsolue(Vector3.Dot(Distance, AxeComparé)) > this.DemiDimention.Z + ValeurAbsolue(Vector3.Dot(cube.DemiDimention.X * cube.AxeX, AxeComparé)) + ValeurAbsolue(Vector3.Dot(cube.DemiDimention.Y * cube.AxeY, AxeComparé)) + ValeurAbsolue(Vector3.Dot(cube.DemiDimention.Z * cube.AxeZ, AxeComparé)))
            enCollision = false;

         AxeComparé = cube.AxeX;
         if (enCollision && ValeurAbsolue(Vector3.Dot(Distance, AxeComparé)) > cube.DemiDimention.X + ValeurAbsolue(Vector3.Dot(this.DemiDimention.X * this.AxeX, AxeComparé)) + ValeurAbsolue(Vector3.Dot(this.DemiDimention.Y * this.AxeY, AxeComparé)) + ValeurAbsolue(Vector3.Dot(this.DemiDimention.Z * this.AxeZ, AxeComparé)))
            enCollision = false;

         AxeComparé = cube.AxeY;
         if (enCollision && ValeurAbsolue(Vector3.Dot(Distance, AxeComparé)) > cube.DemiDimention.Y + ValeurAbsolue(Vector3.Dot(this.DemiDimention.X * this.AxeX, AxeComparé)) + ValeurAbsolue(Vector3.Dot(this.DemiDimention.Y * this.AxeY, AxeComparé)) + ValeurAbsolue(Vector3.Dot(this.DemiDimention.Z * this.AxeZ, AxeComparé)))
            enCollision = false;

         AxeComparé = cube.AxeZ;
         if (enCollision && ValeurAbsolue(Vector3.Dot(Distance, AxeComparé)) > cube.DemiDimention.Z + ValeurAbsolue(Vector3.Dot(this.DemiDimention.X * this.AxeX, AxeComparé)) + ValeurAbsolue(Vector3.Dot(this.DemiDimention.Y * this.AxeY, AxeComparé)) + ValeurAbsolue(Vector3.Dot(this.DemiDimention.Z * this.AxeZ, AxeComparé)))
            enCollision = false;

         AxeComparé = Vector3.Cross(this.AxeX, cube.AxeX);
         if (enCollision && ValeurAbsolue(Vector3.Dot(Distance, AxeComparé)) > LongueurCubeProjeté(this,cube,AxeComparé))
            enCollision = false;

         AxeComparé = Vector3.Cross(this.AxeX, cube.AxeY);
         if (enCollision && ValeurAbsolue(Vector3.Dot(Distance, AxeComparé)) > LongueurCubeProjeté(this, cube, AxeComparé))
            enCollision = false;

         AxeComparé = Vector3.Cross(this.AxeX, cube.AxeZ);
         if (enCollision && ValeurAbsolue(Vector3.Dot(Distance, AxeComparé)) > LongueurCubeProjeté(this, cube, AxeComparé))
            enCollision = false;

         AxeComparé = Vector3.Cross(this.AxeY, cube.AxeX);
         if (enCollision && ValeurAbsolue(Vector3.Dot(Distance, AxeComparé)) > LongueurCubeProjeté(this, cube, AxeComparé))
            enCollision = false;

         AxeComparé = Vector3.Cross(this.AxeY, cube.AxeY);
         if (enCollision && ValeurAbsolue(Vector3.Dot(Distance, AxeComparé)) > LongueurCubeProjeté(this, cube, AxeComparé))
            enCollision = false;

         AxeComparé = Vector3.Cross(this.AxeY, cube.AxeZ);
         if (enCollision && ValeurAbsolue(Vector3.Dot(Distance, AxeComparé)) > LongueurCubeProjeté(this, cube, AxeComparé))
            enCollision = false;

         AxeComparé = Vector3.Cross(this.AxeZ, cube.AxeX);
         if (enCollision && ValeurAbsolue(Vector3.Dot(Distance, AxeComparé)) > LongueurCubeProjeté(this, cube, AxeComparé))
            enCollision = false;

         AxeComparé = Vector3.Cross(this.AxeZ, cube.AxeY);
         if (enCollision && ValeurAbsolue(Vector3.Dot(Distance, AxeComparé)) > LongueurCubeProjeté(this, cube, AxeComparé))
            enCollision = false;

         AxeComparé = Vector3.Cross(this.AxeZ, cube.AxeZ);
         if (enCollision && ValeurAbsolue(Vector3.Dot(Distance, AxeComparé)) > LongueurCubeProjeté(this, cube, AxeComparé))
            enCollision = false;

         return enCollision;
      }
Esempio n. 4
0
      static float LongueurCubeProjeté(CubeCollision A, CubeCollision B, Vector3 AxeComparé)
      {
         return ValeurAbsolue(Vector3.Dot(A.DemiDimention.X * A.AxeX, AxeComparé)) + ValeurAbsolue(Vector3.Dot(A.DemiDimention.Y * A.AxeY, AxeComparé)) + ValeurAbsolue(Vector3.Dot(A.DemiDimention.Z * A.AxeZ, AxeComparé)) +
                ValeurAbsolue(Vector3.Dot(B.DemiDimention.X * B.AxeX, AxeComparé)) + ValeurAbsolue(Vector3.Dot(B.DemiDimention.Y * B.AxeY, AxeComparé)) + ValeurAbsolue(Vector3.Dot(B.DemiDimention.Z * B.AxeZ, AxeComparé));

      }