public override void UpdateDebugDisplay(Page p, SceneNode sn) { byte dbglvl = mManager.DebugDisplayLevel; if (dbglvl != 0) { // we could try to avoid updating the geometry every time here, but this // wouldn't easily deal with paging parameter changes. There shouldn't // be that many pages anyway, and this is debug after all, so update every time int x, y; var stratData = (Grid2DPageStrategyData)p.ParentSection.StrategyData; stratData.CalculateCell(p.PageID, out x, out y); var data = (Grid2DPageStrategyData)p.ParentSection.StrategyData; // Determine our centre point, we'll anchor here // Note that world points are initialised to ZERO since only 2 dimensions // are updated by the grid data (we could display this grid anywhere) Vector2 gridMidPoint = Vector2.Zero; Vector3 worldMidPoint = Vector3.Zero; data.GetMidPointGridSpace(x, y, ref gridMidPoint); data.ConvertGridToWorldSpace(gridMidPoint, ref worldMidPoint); sn.Position = worldMidPoint; var gridCorners = new Vector2[4]; var worldCorners = new Vector3[4]; data.GetCornersGridSpace(x, y, ref gridCorners); for (int i = 0; i < 4; ++i) { worldCorners[i] = Vector3.Zero; data.ConvertGridToWorldSpace(gridCorners[i], ref worldCorners[i]); // make relative to mid point worldCorners[i] -= worldMidPoint; } string matName = "Axiom/G2D/Debug"; var mat = (Material)MaterialManager.Instance.GetByName(matName); if (mat == null) { mat = (Material)MaterialManager.Instance.Create(matName, ResourceGroupManager.DefaultResourceGroupName); Pass pass = mat.GetTechnique(0).GetPass(0); pass.LightingEnabled = false; pass.VertexColorTracking = TrackVertexColor.Ambient; pass.DepthWrite = false; mat.Load(); } ManualObject mo = null; if (sn.ChildCount == 0) { mo = p.ParentSection.SceneManager.CreateManualObject(); mo.Begin(matName, OperationType.LineStrip); } else { mo = (ManualObject)sn.GetObject(0); mo.BeginUpdate(0); } ColorEx vcol = ColorEx.Green; for (int i = 0; i < 5; ++i) { mo.Position(worldCorners[i % 4]); mo.Color(vcol); } mo.End(); if (sn.ObjectCount == 0) { sn.AttachObject(mo); } } }
public DebugRenderable( Node parent ) { _parent = parent; string materialName = "Axiom/Debug/AxesMat"; _material = (Material)MaterialManager.Instance[ materialName ]; if ( _material == null ) { _material = (Material)MaterialManager.Instance.Create( materialName, ResourceGroupManager.InternalResourceGroupName ); Pass p = _material.GetTechnique( 0 ).GetPass( 0 ); p.LightingEnabled = false; //TODO: p.PolygonModeOverrideable = false; p.VertexColorTracking = TrackVertexColor.Ambient; p.SetSceneBlending( SceneBlendType.TransparentAlpha ); p.CullingMode = CullingMode.None; p.DepthWrite = false; } string meshName = "Axiom/Debug/AxesMesh"; _mesh = MeshManager.Instance[ meshName ]; if ( _mesh == null ) { ManualObject mo = new ManualObject( "tmp" ); mo.Begin( Material.Name, OperationType.TriangleList ); /* 3 axes, each made up of 2 of these (base plane = XY) * .------------|\ * '------------|/ */ mo.EstimateVertexCount( 7 * 2 * 3 ); mo.EstimateIndexCount( 3 * 2 * 3 ); Quaternion[] quat = new Quaternion[ 6 ]; ColorEx[] col = new ColorEx[ 3 ]; // x-axis quat[ 0 ] = Quaternion.Identity; quat[ 1 ] = Quaternion.FromAxes( Vector3.UnitX, Vector3.NegativeUnitZ, Vector3.UnitY ); col[ 0 ] = ColorEx.Red; col[ 0 ].a = 0.8f; // y-axis quat[ 2 ] = Quaternion.FromAxes( Vector3.UnitY, Vector3.NegativeUnitX, Vector3.UnitZ ); quat[ 3 ] = Quaternion.FromAxes( Vector3.UnitY, Vector3.UnitZ, Vector3.UnitX ); col[ 1 ] = ColorEx.Green; col[ 1 ].a = 0.8f; // z-axis quat[ 4 ] = Quaternion.FromAxes( Vector3.UnitZ, Vector3.UnitY, Vector3.NegativeUnitX ); quat[ 5 ] = Quaternion.FromAxes( Vector3.UnitZ, Vector3.UnitX, Vector3.UnitY ); col[ 2 ] = ColorEx.Blue; col[ 2 ].a = 0.8f; Vector3[] basepos = new Vector3[ 7 ] { // stalk new Vector3(0f, 0.05f, 0f), new Vector3(0f, -0.05f, 0f), new Vector3(0.7f, -0.05f, 0f), new Vector3(0.7f, 0.05f, 0f), // head new Vector3(0.7f, -0.15f, 0f), new Vector3(1f, 0f, 0f), new Vector3(0.7f, 0.15f, 0f) }; // vertices // 6 arrows for ( int i = 0; i < 6; ++i ) { // 7 points for ( int p = 0; p < 7; ++p ) { Vector3 pos = quat[ i ] * basepos[ p ]; mo.Position( pos ); mo.Color( col[ i / 2 ] ); } } // indices // 6 arrows for ( int i = 0; i < 6; ++i ) { ushort baseIndex = (ushort)( i * 7 ); mo.Triangle( (ushort)( baseIndex + 0 ), (ushort)( baseIndex + 1 ), (ushort)( baseIndex + 2 ) ); mo.Triangle( (ushort)( baseIndex + 0 ), (ushort)( baseIndex + 2 ), (ushort)( baseIndex + 3 ) ); mo.Triangle( (ushort)( baseIndex + 4 ), (ushort)( baseIndex + 5 ), (ushort)( baseIndex + 6 ) ); } mo.End(); _mesh = mo.ConvertToMesh( meshName, ResourceGroupManager.InternalResourceGroupName ); } }