protected SceneComponent(Geom.Point3d pos) { _pos = pos; _obj = HiGL.CreateDisplayList(() => this.Render()); }
public void Draw(ISceneContext context) { _size = context.Camera.ScreenSize; using (var whole = context.Push()) { whole.Color = Color.Gray; whole.PointSize = 3; whole.LineWidth = 1; // X, Y 軸(直線)の描画 context.DrawLines(gl => { gl.Vertex(0, _pos.y); gl.Vertex(_size.x, _pos.y); gl.Vertex(_pos.x, 0); gl.Vertex(_pos.x, _size.y); }); // 目盛の間隔 const int P0 = 16; // 目盛の最小ピクセル数 double unit = context.Camera.LengthPerPixel; double exp = Math.Log10(P0 * unit); double delta = Math.Pow(10, Math.Ceiling(exp)); if (delta / unit > 5 * P0) { delta /= 2; } Geom.Box2d box = new Geom.Box2d( new Geom.Point2d(-_pos.x * unit, (_pos.y - _size.y) * unit), new Geom.Point2d((_size.x - _pos.x) * unit, _pos.y * unit) ); // 目盛を点列として描画 using (var gl = HiGL.Begin(GLPrimType.Points)) { for (double x = 0.0; x < box.Upper.x; x += delta) { gl.Vertex(_pos.x + (int)(x / unit), _pos.y); } for (double x = 0.0; x > box.Lower.x; x -= delta) { gl.Vertex(_pos.x + (int)(x / unit), _pos.y); } for (double y = 0.0; y < box.Upper.y; y += delta) { gl.Vertex(_pos.x, _pos.y - (int)(y / unit)); } for (double y = 0.0; y > box.Lower.y; y -= delta) { gl.Vertex(_pos.x, _pos.y - (int)(y / unit)); } } // 目盛の数値を描画 for (double x = 2 * delta; x < box.Upper.x; x += 2 * delta) { DrawNumber(context, _pos.x + (int)(x / unit), _pos.y + 16, x); } for (double x = -2 * delta; x > box.Lower.x; x -= 2 * delta) { DrawNumber(context, _pos.x + (int)(x / unit), _pos.y + 16, x); } for (double y = 2 * delta; y < box.Upper.y; y += 2 * delta) { DrawNumber(context, _pos.x + 2, _pos.y - (int)(y / unit), y); } for (double y = -2 * delta; y > box.Lower.y; y -= 2 * delta) { DrawNumber(context, _pos.x + 2, _pos.y - (int)(y / unit), y); } // 分度器の描画 double radius = 100; using (var gl = HiGL.Begin(GLPrimType.LineStrip)) { for (int deg = 0; deg <= 90; deg += 5) { double rad = Math.PI * deg / 180.0; double x = _pos.x + radius * Math.Cos(rad); double y = _pos.y - radius * Math.Sin(rad); gl.Vertex(x, y); } } using (var gl = HiGL.Begin(GLPrimType.Points)) { for (int deg = 15; deg < 90; deg += 15) { double rad = Math.PI * deg / 180.0; double x = _pos.x + radius * Math.Cos(rad); double y = _pos.y - radius * Math.Sin(rad); gl.Vertex(x, y); } } } }