public SpaceShip(CollisionDetection cd, Vector3 position) { _boundingCube = cd.BoudingCube; _oldKeyState = Keyboard.GetState(); _model = cd.Content.Load <Model>("Models\\ShipModel"); _hullModel = cd.Content.Load <Model>("Models\\ShipHull"); _modelTransforms = new Matrix[_model.Bones.Count]; _hullTransforms = new Matrix[_hullModel.Bones.Count]; _position = position; _direction = //Vector3.Zero; new Vector3( ((float)cd.Random.NextDouble() - 0.5f) * Speed, ((float)cd.Random.NextDouble() - 0.5f) * Speed, ((float)cd.Random.NextDouble() - 0.5f) * Speed); //initial rotation _rotation = new Rotation(cd.Random); #region creating bounding ball { var meshPart = _model.Meshes[0].MeshParts[0]; var vpnt = new VertexPositionNormalTexture[meshPart.VertexBuffer.VertexCount]; meshPart.VertexBuffer.GetData <VertexPositionNormalTexture>(vpnt); var vertices = new Vector3[vpnt.Length]; for (int i = 0; i < vpnt.Length; i++) { vertices[i] = Vector3.Transform(vpnt[i].Position, Scale); } CollisionSphere = new BoundingBall(cd, vertices, this); } #endregion #region make hullobject for GJK //loop through each mesh of hull ShipHulls = new List <Hull>(); foreach (var hullmesh in _hullModel.Meshes) { List <Vector3> hull_vertices = new List <Vector3>(); //now get the vertices and make a hull object and add it to shiphull list foreach (var mparts in hullmesh.MeshParts) { int vertexStride = mparts.VertexBuffer.VertexDeclaration.VertexStride; var vpnt_hull = new VertexPositionNormalTexture[mparts.NumVertices]; mparts.VertexBuffer.GetData <VertexPositionNormalTexture>(vpnt_hull); for (int k = 0; k < mparts.NumVertices; k++) { hull_vertices.Add(vpnt_hull[k].Position); } } //how that i have all the vertices in a hull //let me add that to ship hull with index number ShipHulls.Add(new Hull(hull_vertices, Size, hullmesh.ParentBone.Index, _rotation)); } #endregion #region rearrange hulls Shuffle(ShipHulls); #endregion }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new SpriteBatch(GraphicsDevice); _random = new Random(); // Camera _camera = new Camera(); // Outer bouding cube _boundinghCube = new BoundingCube(this, OuterBoundarySize); // Spaceships _spaceShips = new SpaceShip[NumberOfShips]; float shipSpacing = 0; for (int i = 0; i < NumberOfShips; i++) { Vector3 position = new Vector3( (i & 1) != 0 ? shipSpacing : -shipSpacing, (i & 2) != 0 ? shipSpacing : -shipSpacing, (i & 4) != 0 ? shipSpacing : -shipSpacing); _spaceShips[i] = new SpaceShip(this, position); if (i % 8 == 0) { shipSpacing += ShipSpacing; } } _octTree = new Octree(GraphicsDevice, OuterBoundarySize, _spaceShips); // Text that displays FPS on upper left coner _fpsFont = Content.Load <SpriteFont>("Models\\Font"); base.LoadContent(); }