/// <summary> /// Begin the modifier (This method is called by the DrawTarget) /// </summary> /// <param name="state"></param> public void Begin(DrawState state) { enabledBuffer = enabled; this.cameras = state.Camera; if (enabledBuffer) state.Cullers.PushPostCuller(this); }
/// <summary> /// End the modifier (This method is called by the DrawTarget) /// </summary> /// <param name="state"></param> public void End(DrawState state) { if (enabledBuffer) state.Cullers.PopPostCuller(); this.cameras = null; if (cubes.Count > 0 || spheres.Count > 0) { Xen.Ex.Shaders.FillSolidColour shader = state.GetShader<Xen.Ex.Shaders.FillSolidColour>(); shader.FillColour = new Vector4(1,1,1,0.25f); using (state.RenderState.Push()) using (state.Shader.Push(shader)) using (state.Camera.Push()) { ICamera camera = state.Camera.GetCamera(); state.RenderState.CurrentDepthState.DepthWriteEnabled = false; state.RenderState.CurrentDepthState.DepthTestEnabled = EnableDepthTesting; state.RenderState.CurrentBlendState = AlphaBlendState.Alpha; GenCubeVS(state); GenSphereVS(state); Matrix mat; for (int i = 0; i < cubes.Count; i++) { mat = cubes[i].Matrix; if (camera != cubes[i].Camera) { camera = cubes[i].Camera; state.Camera.SetCamera(camera); } using (state.WorldMatrix.Push(ref mat)) { cubeVS.Draw(state, null, PrimitiveType.LineList); } } mat = Matrix.Identity; for (int i = 0; i < spheres.Count; i++) { Vector3 v = spheres[i].Position; float scale = spheres[i].Radius; if (camera != spheres[i].Camera) { camera = spheres[i].Camera; state.Camera.SetCamera(camera); } mat.M11 = scale; mat.M22 = scale; mat.M33 = scale; mat.M41 = v.X; mat.M42 = v.Y; mat.M43 = v.Z; using (state.WorldMatrix.Push(ref mat)) { sphereVS.Draw(state, null, PrimitiveType.LineList); } } } } spheres.Clear(); cubes.Clear(); }