public void DrawTool() { GL.PushMatrix(); Matrix4 mat = transform; GL.MultMatrix(ref mat); switch (Form1.current_tool) { case Tools.Select: break; case Tools.Move: ToolModels.DrawMoveTool(model.size.maxS * 2); break; case Tools.Rotate: ToolModels.DrawRotateTool(model.size.maxS * 2); break; case Tools.Scale: ToolModels.DrawScaleTool(model.size.maxS * 2); break; case Tools.Snap: ToolModels.DrawConnectTool(model.size.maxS * 2); break; case Tools.Decorate: break; } GL.PopMatrix(); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); DateTime t = DateTime.Now.AddSeconds(1 / 60.0); if (_targetObj != null) { if (_transtime < 0) { _transtime = 0; cam.pivot = _targetObj.position; if (_panzoom) { cam.position = _fromcampos - _frompos + _targetObj.position; } cam.zoom = _targetObj.model.size.maxS * 4F; _targetObj = null; } else { cam.pivot = Vector3.Lerp(_targetObj.position, _frompos, _smoothtranstime); if (_panzoom) { cam.position = Vector3.Lerp(_fromcampos - _frompos + _targetObj.position, _fromcampos, _smoothtranstime); } cam.zoom = lerp(_targetObj.model.size.maxS * 4F, _fromzoom, _smoothtranstime); } } if (Forward) { Vector3 vel = new Vector3(0, 0, -cam.zoom / 40F); Matrix4 rotmtx = cam.look_at_mtx.ClearTranslation(); cam.pivot += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation(); cam.position += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation(); } if (Backward) { Vector3 vel = new Vector3(0, 0, cam.zoom / 40F); Matrix4 rotmtx = cam.look_at_mtx.ClearTranslation(); cam.pivot += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation(); cam.position += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation(); } if (SideLeft) { Vector3 vel = new Vector3(-cam.zoom / 40F, 0, 0); Matrix4 rotmtx = cam.look_at_mtx.ClearTranslation(); cam.pivot += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation(); cam.position += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation(); } if (SideRight) { Vector3 vel = new Vector3(cam.zoom / 40F, 0, 0); Matrix4 rotmtx = cam.look_at_mtx.ClearTranslation(); cam.pivot += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation(); cam.position += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation(); } if (SideUp) { Vector3 vel = new Vector3(0, cam.zoom / 40F, 0); Matrix4 rotmtx = cam.look_at_mtx.ClearTranslation(); cam.pivot += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation(); cam.position += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation(); } if (SideDown) { Vector3 vel = new Vector3(0, -cam.zoom / 40F, 0); Matrix4 rotmtx = cam.look_at_mtx.ClearTranslation(); cam.pivot += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation(); cam.position += (Matrix4.CreateTranslation(vel) * rotmtx.Inverted()).ExtractTranslation(); } if (!DesignMode) { GL.MatrixMode(MatrixMode.Modelview); //Import Objects if necessary if (_ObjectsToLoad.Count > 0) { foreach (string objectpath in _ObjectsToLoad) { Object3D obj = new Object3D(objectpath); if (_AttachmentToAttachTo == null) { goto no; } if (!obj.attachTo(_AttachmentToAttachTo, Object3D.Active_Object)) { goto no; } goto yes; no :; obj.position = cam.pivot; yes :; GoToObject(obj, true); Object3D.database.Add(obj); Object3D.Active_Object = obj; } _ObjectsToLoad = new List <string>(); } //End of Import Matrix4 mtx = cam.matrix; GL.LoadMatrix(ref mtx); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Clear(ClearBufferMask.DepthBufferBit); for (float i = -100; i <= 100; i += 10) { GL.Color3(Color.Green); GL.LineWidth(0.5F); GL.Begin(PrimitiveType.Lines); GL.Vertex3(i, 100, 0); GL.Vertex3(i, -100, 0); GL.End(); GL.Begin(PrimitiveType.Lines); GL.Vertex3(100, i, 0); GL.Vertex3(-100, i, 0); GL.End(); } GL.LineWidth(1F); /*GL.Begin(PrimitiveType.Polygon); * GL.Color3(Color.Red); * for (int i = 0; i < 360; i += 60) * { * GL.Vertex3(Math.Sin(i * Math.PI / 180) * 30 + mx - Width / 2, Math.Cos(i * Math.PI / 180) * 30 - my + Height / 2, -8); * } * GL.End(); * GL.Begin(PrimitiveType.Polygon); * GL.Color3(Color.White); * for (int i = 0; i < 360; i += 60) * { * GL.Vertex3(Math.Sin(i * Math.PI / 180) * 20 + mx - Width / 2, Math.Cos(i * Math.PI / 180) * 20 - my + Height / 2, -5); * } * GL.End();*/ foreach (Object3D obj in Object3D.database) { obj.DrawObject(_pgm, _coll, _wf, inSight(obj, cam)); } switch (Form1.current_tool) { case Tools.Select: if (tr.Hit) { GL.Color3(0.8F, 0.8F, 0.8F); ToolModels.DrawBall(tr.HitPos, cam.zoom / 120F, 16); } break; case Tools.Decorate: if (tr.Hit) { GL.Color3(1F, 0, 0); ToolModels.DrawBall(tr.HitPos, cam.zoom / 50F, 16); GL.Color3(1F, 1F, 0); GL.LineWidth(2F); GL.Begin(PrimitiveType.Lines); GL.Vertex3(tr.HitPos); GL.Vertex3(tr.HitPos + tr.HitNormal * cam.zoom / 15F); GL.End(); } break; } GL.Clear(ClearBufferMask.DepthBufferBit); if (Object3D.Active_Object != null) { Object3D.Active_Object.DrawTool(); } SwapBuffers(); } if (Forward || Backward || SideLeft || SideRight || SideUp || SideDown || (_targetObj != null)) { while (DateTime.Now < t) { } _transtime -= 1 / 30F; Invalidate(); } }