1 | ///
|
---|
2 | /// This file is part of ILNumerics Community Edition.
|
---|
3 | ///
|
---|
4 | /// ILNumerics Community Edition - high performance computing for applications.
|
---|
5 | /// Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
|
---|
6 | ///
|
---|
7 | /// ILNumerics Community Edition is free software: you can redistribute it and/or modify
|
---|
8 | /// it under the terms of the GNU General Public License version 3 as published by
|
---|
9 | /// the Free Software Foundation.
|
---|
10 | ///
|
---|
11 | /// ILNumerics Community Edition is distributed in the hope that it will be useful,
|
---|
12 | /// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | /// GNU General Public License for more details.
|
---|
15 | ///
|
---|
16 | /// You should have received a copy of the GNU General Public License
|
---|
17 | /// along with ILNumerics Community Edition. See the file License.txt in the root
|
---|
18 | /// of your distribution package. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | ///
|
---|
20 | /// In addition this software uses the following components and/or licenses:
|
---|
21 | ///
|
---|
22 | /// =================================================================================
|
---|
23 | /// The Open Toolkit Library License
|
---|
24 | ///
|
---|
25 | /// Copyright (c) 2006 - 2009 the Open Toolkit library.
|
---|
26 | ///
|
---|
27 | /// Permission is hereby granted, free of charge, to any person obtaining a copy
|
---|
28 | /// of this software and associated documentation files (the "Software"), to deal
|
---|
29 | /// in the Software without restriction, including without limitation the rights to
|
---|
30 | /// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
---|
31 | /// the Software, and to permit persons to whom the Software is furnished to do
|
---|
32 | /// so, subject to the following conditions:
|
---|
33 | ///
|
---|
34 | /// The above copyright notice and this permission notice shall be included in all
|
---|
35 | /// copies or substantial portions of the Software.
|
---|
36 | ///
|
---|
37 | /// =================================================================================
|
---|
38 | ///
|
---|
39 |
|
---|
40 | using System;
|
---|
41 | using System.Collections.Generic;
|
---|
42 | using System.Text;
|
---|
43 | using System.Drawing;
|
---|
44 | using OpenTK;
|
---|
45 | using OpenTK.Graphics;
|
---|
46 | using OpenTK.Graphics.OpenGL;
|
---|
47 | using OpenTK.Graphics.OpenGL.Enums;
|
---|
48 | using ILNumerics.Drawing;
|
---|
49 | using ILNumerics.Drawing.Interfaces;
|
---|
50 | using ILNumerics.Drawing.Labeling;
|
---|
51 |
|
---|
52 |
|
---|
53 | namespace ILNumerics.Drawing.Platform.OpenGL {
|
---|
54 | /// <summary>
|
---|
55 | /// OpenGL implementation of ILAxis (X axis)
|
---|
56 | /// </summary>
|
---|
57 | class ILOGLXAxis : ILOGLAxis {
|
---|
58 |
|
---|
59 | /// <summary>
|
---|
60 | /// Constructor - this class should be created only from within ILNumerics assemblies!
|
---|
61 | /// </summary>
|
---|
62 | /// <param name="clippingView">panels clipping view</param>
|
---|
63 | /// <param name="layout">instance with layout informations</param>
|
---|
64 | /// <param name="panel">the panel containing the axis</param>
|
---|
65 | internal ILOGLXAxis (ILClippingData clippingView,
|
---|
66 | ILLayoutData layout,
|
---|
67 | ILOGLPanel panel)
|
---|
68 | : base (AxisNames.XAxis,clippingView,layout,panel) {}
|
---|
69 |
|
---|
70 | /// <summary>
|
---|
71 | /// draw all lines for the x axis
|
---|
72 | /// </summary>
|
---|
73 | /// <param name="p">render properties</param>
|
---|
74 | /// <param name="background">true: draw lines in the back only, false: draw foreground lines</param>
|
---|
75 | protected override void iDrawAxis(ILRenderProperties p, bool background) {
|
---|
76 | // create vertex data: main axis and ticks
|
---|
77 | if (m_visible) {
|
---|
78 | float tickLen;
|
---|
79 | float x,y,z
|
---|
80 | ,xmin = m_clipping.XMin
|
---|
81 | ,xmax = m_clipping.XMax
|
---|
82 | ,ymin = m_clipping.YMin
|
---|
83 | ,ymax = m_clipping.YMax
|
---|
84 | ,zmin = m_clipping.ZMin
|
---|
85 | ,zmax = m_clipping.ZMax;
|
---|
86 | tickLen = m_labeledTicks.TickFraction
|
---|
87 | * ((m_labeledTicks.Direction == TickDirection.Inside) ? m_clipping.HeightF : -m_clipping.HeightF);
|
---|
88 | // must draw ticks?
|
---|
89 | bool drawticks = false, drawLines = false;
|
---|
90 | if (m_labeledTicks.Display == TickDisplay.BothSides) {
|
---|
91 | drawticks = true;
|
---|
92 | } else {
|
---|
93 | drawticks = (background && !m_layoutData.CameraPosition.LooksFromTop)
|
---|
94 | ||(!background && m_layoutData.CameraPosition.LooksFromTop);
|
---|
95 | }
|
---|
96 | x = xmin; z = zmin;
|
---|
97 | // determine which axis to draw: find front
|
---|
98 | if (!m_layoutData.CameraPosition.LooksFromFront) {
|
---|
99 | tickLen *= -1.0f;
|
---|
100 | y = ymax;
|
---|
101 | } else {
|
---|
102 | y = ymin;
|
---|
103 | }
|
---|
104 | if (background) {
|
---|
105 | if (m_farLines.Visible) {
|
---|
106 | ILOGLPanel.SetupLineStyle(m_farLines);
|
---|
107 | drawLines = true;
|
---|
108 | }
|
---|
109 | if (y == ymax) y = ymin; else y = ymax;
|
---|
110 | GL.Disable(EnableCap.DepthTest);
|
---|
111 | tickLen *= -1.0f;
|
---|
112 | } else {
|
---|
113 | if (m_nearLines.Visible) {
|
---|
114 | ILOGLPanel.SetupLineStyle(m_nearLines);
|
---|
115 | drawLines = true;
|
---|
116 | }
|
---|
117 | }
|
---|
118 | if (drawLines) {
|
---|
119 | GL.Begin(BeginMode.Lines);
|
---|
120 | GL.Vertex3(x,y,z);
|
---|
121 | x = xmax;
|
---|
122 | GL.Vertex3(x,y,z);
|
---|
123 | if (m_layoutData.CameraPosition.SinRho > 1e-5) {
|
---|
124 | z = zmax;
|
---|
125 | GL.Vertex3(x,y,z);
|
---|
126 | x = xmin;
|
---|
127 | GL.Vertex3(x,y,z);
|
---|
128 | }
|
---|
129 | GL.End();
|
---|
130 | }
|
---|
131 | GL.Enable(EnableCap.DepthTest);
|
---|
132 | if (drawticks && drawLines) {
|
---|
133 | #region create ticks
|
---|
134 | if (!m_layoutData.CameraPosition.LooksFromTop) {
|
---|
135 | //tickLen *= -1.0f;
|
---|
136 | //y *= -1.0f;
|
---|
137 | if (background)
|
---|
138 | GL.Color3(m_labeledTicks.NearColor);
|
---|
139 | else
|
---|
140 | GL.Color3(m_labeledTicks.FarColor);
|
---|
141 | } else {
|
---|
142 | if (background)
|
---|
143 | GL.Color3(m_labeledTicks.FarColor);
|
---|
144 | else
|
---|
145 | GL.Color3(m_labeledTicks.NearColor);
|
---|
146 |
|
---|
147 | }
|
---|
148 | //scale = m_clipping.ScaleToUnitCube().X;
|
---|
149 | //offse = m_clipping.CenterToUnitCube().X;
|
---|
150 | GL.Disable(EnableCap.LineStipple);
|
---|
151 | GL.Begin(BeginMode.Lines);
|
---|
152 | foreach (LabeledTick tick in m_labeledTicks) {
|
---|
153 | if (tick.Position >= xmin
|
---|
154 | && tick.Position <= xmax) {
|
---|
155 | x = tick.Position;
|
---|
156 | if (m_layoutData.CameraPosition.SinRho > 1e-5) {
|
---|
157 | z = zmax;
|
---|
158 | GL.Vertex3(x, y, z);
|
---|
159 | y += tickLen;
|
---|
160 | GL.Vertex3(x, y, z);
|
---|
161 | } else {
|
---|
162 | y += tickLen;
|
---|
163 | }
|
---|
164 | z = zmin;
|
---|
165 | GL.Vertex3(x,y,z);
|
---|
166 | y -= tickLen;
|
---|
167 | GL.Vertex3(x,y,z);
|
---|
168 | }
|
---|
169 | }
|
---|
170 | GL.End();
|
---|
171 | #endregion
|
---|
172 | }
|
---|
173 | if (background && m_grid.Visible)
|
---|
174 | drawGrid();
|
---|
175 | }
|
---|
176 | }
|
---|
177 |
|
---|
178 | /// <summary>
|
---|
179 | /// draw all grid lines for axis
|
---|
180 | /// </summary>
|
---|
181 | protected override void drawGrid() {
|
---|
182 | float x,y,z;
|
---|
183 | float zmax = m_clipping.ZMax;
|
---|
184 | float zmin = m_clipping.ZMin;
|
---|
185 | float ymin = m_clipping.YMin;
|
---|
186 | float ymax = m_clipping.YMax;
|
---|
187 | bool drawBottom = m_layoutData.CameraPosition.LooksFromTop;
|
---|
188 | ILOGLPanel.SetupLineStyle(m_grid);
|
---|
189 | GL.Disable(EnableCap.DepthTest);
|
---|
190 | GL.Enable(EnableCap.Blend);
|
---|
191 | GL.Begin(BeginMode.Lines);
|
---|
192 | if (m_layoutData.CameraPosition.LooksFromFront) {
|
---|
193 | y = ymax;
|
---|
194 | } else {
|
---|
195 | y = ymin;
|
---|
196 | }
|
---|
197 | foreach (LabeledTick tick in m_labeledTicks) {
|
---|
198 | if (tick.Position > m_clipping.XMin
|
---|
199 | && tick.Position < m_clipping.XMax) {
|
---|
200 | x = tick.Position;
|
---|
201 | if (!m_layoutData.CameraPosition.Is2DView) {
|
---|
202 | z = zmax;
|
---|
203 | GL.Vertex3(x, y, z);
|
---|
204 | z = zmin;
|
---|
205 | GL.Vertex3(x, y, z);
|
---|
206 | } else {
|
---|
207 | z = zmin;
|
---|
208 | }
|
---|
209 | if (drawBottom) {
|
---|
210 | GL.Vertex3(x,y,z);
|
---|
211 | if (y == ymin) y = ymax; else y = ymin;
|
---|
212 | GL.Vertex3(x,y,z);
|
---|
213 | if (y == ymin) y = ymax; else y = ymin;
|
---|
214 | }
|
---|
215 | }
|
---|
216 | }
|
---|
217 | GL.End();
|
---|
218 | }
|
---|
219 |
|
---|
220 |
|
---|
221 |
|
---|
222 | }
|
---|
223 | }
|
---|