public void render() { if (TerrainGlobals.getEditor().mBrushShowVerts) { float ptSize = 2; BRenderDevice.getDevice().SetRenderState(RenderStates.PointSize, ptSize); { BRenderDevice.getDevice().SetRenderState(RenderStates.AlphaBlendEnable, true); BRenderDevice.getDevice().SetRenderState(RenderStates.SourceBlend, (int)Blend.SourceAlpha); BRenderDevice.getDevice().SetRenderState(RenderStates.DestinationBlend, (int)Blend.InvSourceAlpha); BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1); BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.Diffuse); BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.AlphaOperation, (int)TextureOperation.SelectArg1); BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.AlphaArgument1, (int)TextureArgument.Diffuse); List <BTerrainQuadNode> nodes = new List <BTerrainQuadNode>(); float validRadius = (TerrainGlobals.getEditor().getCurrentBrushInfo().mRadius * 1.5f); //scaled out for dramatic changes TerrainGlobals.getTerrain().getQuadNodeRoot().getSphereIntersection(nodes, ref TerrainGlobals.getEditor().mBrushIntersectionPoint, validRadius); for (int i = 0; i < nodes.Count; i++) { nodes[i].renderCursor(); } BRenderDevice.getDevice().SetRenderState(RenderStates.AlphaBlendEnable, false); BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.Modulate); BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.Diffuse); BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor); BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.AlphaOperation, (int)TextureOperation.Modulate); BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.AlphaArgument1, (int)TextureArgument.Diffuse); BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.AlphaArgument2, (int)TextureArgument.TextureColor); BRenderDevice.getDevice().SetRenderState(RenderStates.ZEnable, true); } } else { // Draw 2D radius and hotspot circle BRenderDevice.getDevice().VertexFormat = VertexFormats.Position; BRenderDevice.getDevice().SetStreamSource(0, gCircleVB, 0); BRenderDevice.getDevice().VertexShader = null; BRenderDevice.getDevice().PixelShader = null; BRenderDevice.getDevice().SetTexture(0, null); BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.SelectArg1); BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.TFactor); BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.AlphaOperation, (int)TextureOperation.SelectArg1); BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.AlphaArgument1, (int)TextureArgument.TFactor); BRenderDevice.getDevice().SetTextureStageState(1, TextureStageStates.ColorOperation, (int)TextureOperation.Disable); BRenderDevice.getDevice().SetTextureStageState(1, TextureStageStates.AlphaOperation, (int)TextureOperation.Disable); BRenderDevice.getDevice().SetRenderState(RenderStates.Lighting, false); BRenderDevice.getDevice().SetRenderState(RenderStates.SourceBlend, (int)Blend.SourceAlpha); BRenderDevice.getDevice().SetRenderState(RenderStates.DestinationBlend, (int)Blend.InvSourceAlpha); BRenderDevice.getDevice().SetRenderState(RenderStates.AlphaBlendEnable, true); BRenderDevice.getDevice().SetRenderState(RenderStates.ZBufferFunction, (int)Compare.Always); BRenderDevice.getDevice().SetRenderState(RenderStates.ZBufferWriteEnable, false); BRenderDevice.getDevice().SetRenderState(RenderStates.AntialiasedLineEnable, true); // Set circle color based on mode Vector3 brushColor; bool selectionMode = (UIManager.GetAsyncKeyStateB(Key.RightControl) || UIManager.GetAsyncKeyStateB(Key.LeftControl)) && (!UIManager.GetAsyncKeyStateB(Key.LeftShift) && !UIManager.GetAsyncKeyStateB(Key.RightShift)); if (!selectionMode) { brushColor = new Vector3(1, 1, 1); } else { brushColor = new Vector3(1, 1, 0); } // Compute matrices for circles Matrix viewMat = BRenderDevice.getDevice().GetTransform(TransformType.View); viewMat.Invert(); Matrix circleMatrix = Matrix.Translation(TerrainGlobals.getEditor().mBrushIntersectionPoint); circleMatrix.M11 = viewMat.M11; circleMatrix.M12 = viewMat.M12; circleMatrix.M13 = viewMat.M13; circleMatrix.M21 = viewMat.M21; circleMatrix.M22 = viewMat.M22; circleMatrix.M23 = viewMat.M23; circleMatrix.M31 = viewMat.M31; circleMatrix.M32 = viewMat.M32; circleMatrix.M33 = viewMat.M33; float hotSpotDist = TerrainGlobals.getEditor().getCurrentBrushInfo().mRadius *TerrainGlobals.getEditor().getCurrentBrushInfo().mHotspot; Matrix WorldInnerRadius = Matrix.Scaling(hotSpotDist, hotSpotDist, hotSpotDist); WorldInnerRadius.Multiply(circleMatrix); Matrix WorldOuterRadius = Matrix.Scaling(TerrainGlobals.getEditor().getCurrentBrushInfo().mRadius, TerrainGlobals.getEditor().getCurrentBrushInfo().mRadius, TerrainGlobals.getEditor().getCurrentBrushInfo().mRadius); WorldOuterRadius.Multiply(circleMatrix); // Render circles with their corresponding colors BRenderDevice.getDevice().SetRenderState(RenderStates.TextureFactor, (int)BRenderDevice.D3DCOLOR_COLORVALUE(brushColor.X, brushColor.Y, brushColor.Z, 0.5f)); BRenderDevice.getDevice().SetTransform(TransformType.World, WorldInnerRadius); BRenderDevice.getDevice().DrawPrimitives(PrimitiveType.LineStrip, 0, cNumCircleVBVerts - 1); BRenderDevice.getDevice().SetRenderState(RenderStates.TextureFactor, (int)BRenderDevice.D3DCOLOR_COLORVALUE(brushColor.X, brushColor.Y, brushColor.Z, 1)); BRenderDevice.getDevice().SetTransform(TransformType.World, WorldOuterRadius); BRenderDevice.getDevice().DrawPrimitives(PrimitiveType.LineStrip, 0, cNumCircleVBVerts - 1); // Restore states BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.ColorOperation, (int)TextureOperation.Modulate); BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.ColorArgument1, (int)TextureArgument.Diffuse); BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor); BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.AlphaOperation, (int)TextureOperation.Modulate); BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.AlphaArgument1, (int)TextureArgument.Diffuse); BRenderDevice.getDevice().SetTextureStageState(0, TextureStageStates.ColorArgument2, (int)TextureArgument.TextureColor); BRenderDevice.getDevice().SetRenderState(RenderStates.AlphaBlendEnable, false); BRenderDevice.getDevice().SetRenderState(RenderStates.ZBufferFunction, (int)Compare.LessEqual); BRenderDevice.getDevice().SetRenderState(RenderStates.ZBufferWriteEnable, true); BRenderDevice.getDevice().SetRenderState(RenderStates.AntialiasedLineEnable, false); // Restore transform BRenderDevice.getDevice().SetTransform(TransformType.World, Matrix.Identity); } }