protected override void Initialise() { Camera3D camera = new Xen.Camera.FirstPersonControlledCamera3D(this.UpdateManager, Vector3.Zero,true); //create the draw target. drawToScreen = new DrawTargetScreen(camera); drawToScreen.ClearBuffer.ClearColour = Color.CornflowerBlue; //NEW CODE //create a BatchModel, this class stores the ModelData and will draw BatchModelInstances this.batchModel = new BatchModel(); //this.batchModel.ShaderProvider = new SimpleShaderProvider<Tutorial_16.Shader.Tutorial16>(); //NEW CODE //create a large number of actors (1600) for (float x = -20; x < 20; x++) for (float y = -20; y < 20; y++) { drawToScreen.Add(new Actor(this.batchModel, new Vector3(x * 5, y * 5, -5))); } //this is the most important bit... //always add the BatchModel itself to the draw target, //this should be added *after* all BatchModelInstances have been added //Note: each time a BatchModelInstance is drawn, it will store it's world matrix in the BatchModel //If the BatchModel is not drawn, the buffer storing these matrices will not be emptied, and will //eventually throw an OutOfMemoryException exception. this.drawToScreen.Add(batchModel); statistics = new Xen.Ex.Graphics2D.Statistics.DrawStatisticsDisplay(this.UpdateManager); this.drawToScreen.Add(statistics); }
/// <summary> /// Construct the batch model instance /// </summary> /// <param name="model">The BatchModel that will draw this instance</param> public BatchModelInstance(BatchModel model) { if (model == null) { throw new ArgumentNullException(); } this.parent = model; this.parent.CountChild(); }
public Actor(BatchModel model, Vector3 position) { this.instance = new BatchModelInstance(model); this.worldMatrix = Matrix.CreateTranslation(position); }
/// <summary> /// Construct the batch model instance /// </summary> /// <param name="model">The BatchModel that will draw this instance</param> public BatchModelInstance(BatchModel model) { if (model == null) throw new ArgumentNullException(); this.parent = model; this.parent.CountChild(); }