void OnSizeChanged(object sender, EventArgs e) { double ratio_x = _size.x > 0 ? (double)_pos.x / _size.x : _pos.x; double ratio_y = _size.y > 0 ? (double)_pos.y / _size.y : _pos.y; _size = _owner.Camera.ScreenSize; _pos.x = (int)(ratio_x * _size.x); _pos.y = (int)(ratio_y * _size.y); this.FixPos(); }
void FixPos() { const int MARGIN = 5; Geom.Size2i size = _view.Camera.ScreenSize; Geom.Box2i box = this.BoundingBox; if (box.Lower.x < MARGIN) { _pos.x += MARGIN - box.Lower.x; } if (box.Lower.y < MARGIN) { _pos.y += MARGIN - box.Lower.y; } if (box.Upper.x + MARGIN > size.x) { _pos.x -= box.Upper.x + MARGIN - size.x; } if (box.Upper.y + MARGIN > size.y) { _pos.y -= box.Upper.y + MARGIN - size.y; } }
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 ���i�����j�̕`�� 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 ); } ); // �ڐ��̊Ԋu const int P0 = 16; // �ڐ��̍ŏ��s�N�Z���� 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) ); } } // �ڐ��̐��l��`�� 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 ); } // ���x��̕`�� 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 ); } } } }
void OnSizeChanged( object sender, EventArgs e ) { double ratio_x = _size.x > 0 ? (double)_pos.x / _size.x : _pos.x; double ratio_y = _size.y > 0 ? (double)_pos.y / _size.y : _pos.y; _size = _owner.Camera.ScreenSize; _pos.x = (int)(ratio_x * _size.x); _pos.y = (int)(ratio_y * _size.y); this.FixPos(); }
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); } } } }