public SimulationManager(GraphicsDevice device, ContentManager content) { if (Instance != null) { throw new InvalidOperationException("Cannot create more than once instance of the simulation manager."); } Instance = this; _sb = new SpriteBatch(device); _blankTex = new Texture2D(device, 1, 1); _blankTex.SetData(new Color[] { Color.White }); _device = device; _world = new WorldModel(device, (int)Constants.WorldSize.X / 10); _uavModel = new CModel(device, content.Load <Model>("UAV")); _tankModel = new CModel(device, content.Load <Model>("tank")); _missModel = new CModel(device, content.Load <Model>("sphere_missile")); _cone = new ConeModel(device); _ring = new RingModel(device, Constants.TankFiringRange / 10, 1); _font = content.Load <SpriteFont>("debugfont"); _lRect = new Rectangle(0, 0, 130, 70); Simulation = new Simulation(); _entityFollow = new EntityFollowBehavior(); }
public override GeometryModel CreateSourceGeometryModel( ) { ConeModel coneModel = new ConeModel( ); float height = this.height.ChangeUnit(Parent.Parent.Environment.DefaultLengthUnit); float radius1 = this.bottomRadius.ChangeUnit(Parent.Parent.Environment.DefaultLengthUnit); float radius2 = this.topRadius.ChangeUnit(Parent.Parent.Environment.DefaultLengthUnit); if (height > 0) { coneModel.Height = height; coneModel.Radius1 = radius1; coneModel.Radius2 = radius2; } else { coneModel.Height = -height; coneModel.Radius1 = radius2; coneModel.Radius2 = radius1; } //Compute the center and transform matrix Vector3 centerVector3 = this.center.GetDirectXVector(Parent.Parent.Environment.DefaultLengthUnit); Matrix worldMatrix = Matrix.Identity; //Set the matrix switch (this.alineAxis) { case Axis.X: centerVector3.Add(new Vector3(height / 2.0f, 0, 0)); worldMatrix = Matrix.RotationY((float)Math.PI / 2.0f) * Matrix.Translation(centerVector3); break; case Axis.Y: centerVector3.Add(new Vector3(0, height / 2.0f, 0)); worldMatrix = Matrix.RotationX(-(float)Math.PI / 2.0f) * Matrix.Translation(centerVector3); break; case Axis.Z: centerVector3.Add(new Vector3(0, 0, height / 2.0f)); worldMatrix = Matrix.Translation(centerVector3); break; } coneModel.CenterVector3 = centerVector3; coneModel.WorldMatrix = worldMatrix; coneModel.AlineAxis = this.alineAxis; return(coneModel); }
/// <summary> /// Create the primitives to be drawed /// Z ---- length /// </summary> public override void Initialize( ) { if (coneMesh != null) { coneMesh.Dispose(); } model = source as ConeModel; //Create the mesh coneMesh = new AutoMesh(d3d, Mesh.Cylinder(d3d.Dx, model.Radius1, model.Radius2, model.Height, Direct3dRender.DefaultSlices, Direct3dRender.DefaultStacks)); //Get the bounding box coneMesh.BoundingBox(out minVector3, out maxVector3); minVector3.TransformCoordinate(model.WorldMatrix); maxVector3.TransformCoordinate(model.WorldMatrix); model.MinVector3 = minVector3; model.MaxVector3 = maxVector3; }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void PerformDispose( ) { coneMesh.Dispose( ); model = null; }