KiCad PCB EDA Suite
ogl_legacy_utils.cpp File Reference
#include "../../common_ogl/openGL_includes.h"
#include "ogl_legacy_utils.h"
#include <trigo.h>
#include <wx/debug.h>

Go to the source code of this file.

Macros

#define RADPERDEG   0.0174533
 

Functions

void OGL_draw_arrow (SFVEC3F aPosition, SFVEC3F aTargetPos, float aSize)
 OGL_draw_arrow - draw a round arrow. More...
 
void OGL_draw_bbox (const CBBOX &aBBox)
 OGL_draw_bbox - draw the bounding box lines. More...
 
void OGL_draw_half_open_cylinder (unsigned int aNrSidesPerCircle)
 OGL_draw_half_open_cylinder - draws an open half cylinder with diameter 1.0f and Height 1.0f the bottom center is at (0,0,0) and top center is at (0,0,1) More...
 
void OGL_Draw_segment (const CROUNDSEGMENT2D &aSegment, unsigned int aNrSidesPerCircle)
 OGL_Draw_segment draws a thick segment with rounded ends. More...
 

Macro Definition Documentation

#define RADPERDEG   0.0174533

Definition at line 36 of file ogl_legacy_utils.cpp.

Referenced by OGL_draw_arrow(), and OGL_Draw_segment().

Function Documentation

void OGL_draw_arrow ( SFVEC3F  aPosition,
SFVEC3F  aTargetPos,
float  aSize 
)

OGL_draw_arrow - draw a round arrow.

Parameters
aPositionstart position of the arrow
aTargetPosend position of the arror
aSizediameter size

Definition at line 38 of file ogl_legacy_utils.cpp.

References RADPERDEG.

Referenced by C3D_MODEL_VIEWER::OnPaint(), and C3D_RENDER_OGL_LEGACY::render_3D_arrows().

39 {
40  wxASSERT( aSize > 0.0f );
41 
42  SFVEC3F vec = (aTargetPos - aPosition);
43  float length = glm::length( vec );
44 
45  GLUquadricObj *quadObj;
46 
47  glPushMatrix ();
48 
49  glTranslatef( aPosition.x, aPosition.y, aPosition.z );
50 
51  if( ( vec.x != 0.0f ) || ( vec.y != 0.0f ) )
52  {
53  glRotatef( atan2( vec.y, vec.x ) / RADPERDEG, 0.0f, 0.0f, 1.0f );
54  glRotatef( atan2( sqrt( vec.x * vec.x + vec.y * vec.y ), vec.z ) / RADPERDEG,
55  0.0f,
56  1.0f,
57  0.0f );
58 
59  } else if( vec.z < 0.0f )
60  {
61  glRotatef( 180.0f, 1.0f, 0.0f, 0.0f );
62  }
63 
64  glTranslatef( 0.0f, 0.0f, length - 4.0f * aSize );
65 
66  quadObj = gluNewQuadric();
67  gluQuadricDrawStyle( quadObj, GLU_FILL );
68  gluQuadricNormals( quadObj, GLU_SMOOTH );
69  gluCylinder( quadObj, 2.0 * aSize, 0.0, 4.0 * aSize, 12, 1 );
70  gluDeleteQuadric( quadObj );
71 
72  quadObj = gluNewQuadric();
73  gluQuadricDrawStyle( quadObj, GLU_FILL );
74  gluQuadricNormals( quadObj, GLU_SMOOTH );
75  gluDisk( quadObj, 0.0, 2.0 * aSize, 12, 1 );
76  gluDeleteQuadric( quadObj );
77 
78  quadObj = gluNewQuadric();
79  gluQuadricDrawStyle( quadObj, GLU_FILL );
80  gluQuadricNormals( quadObj, GLU_SMOOTH );
81  gluDisk( quadObj, 0.0, aSize, 12, 1 );
82  gluDeleteQuadric( quadObj );
83 
84 
85  quadObj = gluNewQuadric();
86  gluQuadricDrawStyle( quadObj, GLU_FILL );
87  gluQuadricNormals( quadObj, GLU_SMOOTH );
88  gluSphere( quadObj, aSize, 24, 24 );
89  gluDeleteQuadric( quadObj );
90 
91  glTranslatef( 0.0f , 0.0f ,-length + 4.0f * aSize );
92 
93  quadObj = gluNewQuadric();
94  gluQuadricDrawStyle( quadObj, GLU_FILL );
95  gluQuadricNormals( quadObj, GLU_SMOOTH );
96  gluCylinder( quadObj, aSize, aSize, length - 4.0 * aSize, 12, 1 );
97  gluDeleteQuadric( quadObj );
98 /*
99 
100  quadObj = gluNewQuadric();
101  gluQuadricDrawStyle( quadObj, GLU_FILL );
102  gluQuadricNormals( quadObj, GLU_SMOOTH );
103  gluSphere( quadObj, aSize, 24, 24 );
104  gluDeleteQuadric( quadObj );
105 */
106 
107  quadObj = gluNewQuadric();
108  gluQuadricDrawStyle( quadObj, GLU_FILL );
109  gluQuadricNormals( quadObj, GLU_SMOOTH );
110  gluDisk( quadObj, 0.0, aSize, 12, 1 );
111  gluDeleteQuadric( quadObj );
112 
113  glPopMatrix ();
114 }
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
#define RADPERDEG
void OGL_draw_bbox ( const CBBOX aBBox)

OGL_draw_bbox - draw the bounding box lines.

Parameters
aBBoxis the box to draw

Definition at line 117 of file ogl_legacy_utils.cpp.

References CBBOX::IsInitialized(), CBBOX::Max(), and CBBOX::Min().

Referenced by C_OGL_3DMODEL::Draw_bbox(), and C_OGL_3DMODEL::Draw_bboxes().

118 {
119  wxASSERT( aBBox.IsInitialized() );
120 
121  glBegin( GL_LINE_LOOP );
122  glVertex3f( aBBox.Min().x, aBBox.Min().y, aBBox.Min().z );
123  glVertex3f( aBBox.Max().x, aBBox.Min().y, aBBox.Min().z );
124  glVertex3f( aBBox.Max().x, aBBox.Max().y, aBBox.Min().z );
125  glVertex3f( aBBox.Min().x, aBBox.Max().y, aBBox.Min().z );
126  glEnd();
127 
128  glBegin( GL_LINE_LOOP );
129  glVertex3f( aBBox.Min().x, aBBox.Min().y, aBBox.Max().z );
130  glVertex3f( aBBox.Max().x, aBBox.Min().y, aBBox.Max().z );
131  glVertex3f( aBBox.Max().x, aBBox.Max().y, aBBox.Max().z );
132  glVertex3f( aBBox.Min().x, aBBox.Max().y, aBBox.Max().z );
133  glEnd();
134 
135  glBegin( GL_LINE_STRIP );
136  glVertex3f( aBBox.Min().x, aBBox.Min().y, aBBox.Min().z );
137  glVertex3f( aBBox.Min().x, aBBox.Min().y, aBBox.Max().z );
138  glEnd();
139 
140  glBegin( GL_LINE_STRIP );
141  glVertex3f( aBBox.Max().x, aBBox.Min().y, aBBox.Min().z );
142  glVertex3f( aBBox.Max().x, aBBox.Min().y, aBBox.Max().z );
143  glEnd();
144 
145  glBegin( GL_LINE_STRIP );
146  glVertex3f( aBBox.Max().x, aBBox.Max().y, aBBox.Min().z );
147  glVertex3f( aBBox.Max().x, aBBox.Max().y, aBBox.Max().z );
148  glEnd();
149 
150  glBegin( GL_LINE_STRIP );
151  glVertex3f( aBBox.Min().x, aBBox.Max().y, aBBox.Min().z );
152  glVertex3f( aBBox.Min().x, aBBox.Max().y, aBBox.Max().z );
153  glEnd();
154 }
const SFVEC3F & Min() const
Function Min return the minimun vertex pointer.
Definition: cbbox.h:205
bool IsInitialized() const
Function IsInitialized check if this bounding box is already initialized.
Definition: cbbox.cpp:87
const SFVEC3F & Max() const
Function Max return the maximum vertex pointer.
Definition: cbbox.h:212
void OGL_draw_half_open_cylinder ( unsigned int  aNrSidesPerCircle)

OGL_draw_half_open_cylinder - draws an open half cylinder with diameter 1.0f and Height 1.0f the bottom center is at (0,0,0) and top center is at (0,0,1)

Parameters
aNrSidesPerCircleis the number of segments to approximate a circle.

Definition at line 157 of file ogl_legacy_utils.cpp.

References delta, and RotatePoint().

Referenced by OGL_Draw_segment().

158 {
159  if( aNrSidesPerCircle > 1 )
160  {
161  const float radius = 0.5f;
162  const int delta = 3600 / aNrSidesPerCircle;
163 
164  // Generate bottom
165  glNormal3f( 0.0f, 0.0f,-1.0f );
166  glBegin( GL_TRIANGLE_FAN );
167  glVertex3f( 0.0, 0.0, 0.0 ); // This is the V0 of the FAN
168 
169  for( int ii = 0; ii < 1800; ii += delta )
170  {
171  SFVEC2D corner = SFVEC2D( 0.0, radius );
172  RotatePoint( &corner.x, &corner.y, ii );
173  glVertex3f( corner.x, corner.y, 0.0 );
174  }
175 
176  glVertex3d( 0.0, -radius, 0.0 );
177  glEnd();
178 
179  // Generate top
180  glNormal3f( 0.0f, 0.0f, 1.0f );
181  glBegin( GL_TRIANGLE_FAN );
182  glVertex3f( 0.0, 0.0, 1.0 ); // This is the V0 of the FAN
183 
184  for( int ii = 1800; ii > 0; ii -= delta )
185  {
186  SFVEC2D corner = SFVEC2D( 0.0, radius );
187 
188  RotatePoint( &corner.x, &corner.y, ii );
189  glVertex3f( corner.x, corner.y, 1.0 );
190  }
191 
192  glVertex3f( 0.0, radius, 1.0 );
193  glEnd();
194 
195  // Generate contours
196  glBegin( GL_QUAD_STRIP );
197 
198  for( int ii = 1800; ii > 0; ii -= delta )
199  {
200  SFVEC2D corner = SFVEC2D( 0.0, radius );
201 
202  RotatePoint( &corner.x, &corner.y, ii );
203  glNormal3f( corner.x * 2.0f, corner.y * 2.0f, 0.0f );
204  glVertex3f( corner.x, corner.y, 1.0 );
205  glVertex3f( corner.x, corner.y, 0.0 );
206  }
207 
208  glNormal3f( 0.0, 1.0f, 0.0f );
209  glVertex3d( 0.0, radius, 1.0 );
210  glVertex3d( 0.0, radius, 0.0 );
211  glEnd();
212  }
213 }
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
static const int delta[8][2]
Definition: solve.cpp:112
glm::dvec2 SFVEC2D
Definition: xv3d_types.h:46
void OGL_Draw_segment ( const CROUNDSEGMENT2D aSegment,
unsigned int  aNrSidesPerCircle 
)

OGL_Draw_segment draws a thick segment with rounded ends.

Parameters
aSegmentis the thick segment to draw
aNrSidesPerCircleis the number of segments to approximate a circle. used to draw the rounded ends of the segment

Definition at line 216 of file ogl_legacy_utils.cpp.

References CROUNDSEGMENT2D::GetEnd_minus_Start(), CROUNDSEGMENT2D::GetLength(), CROUNDSEGMENT2D::GetRadius(), CROUNDSEGMENT2D::GetStart(), CROUNDSEGMENT2D::GetWidth(), OGL_draw_half_open_cylinder(), and RADPERDEG.

218 {
219  glPushMatrix();
220 
221  const SFVEC2F start = aSegment.GetStart();
222  const SFVEC2F end_minus_start = aSegment.GetEnd_minus_Start();
223  const float radius = aSegment.GetRadius();
224  const float width = aSegment.GetWidth();
225  const float length = aSegment.GetLength();
226 
227  glTranslatef( start.x, start.y, 0.0f );
228 
229  if( ( end_minus_start.x != 0.0f ) || ( end_minus_start.y != 0.0f ) )
230  {
231  glRotatef( atan2( end_minus_start.y, end_minus_start.x ) / RADPERDEG,
232  0.0f,
233  0.0f,
234  1.0f );
235  }
236 
237  glPushMatrix();
238  glTranslatef( length, 0.0, 0.0f );
239  glScalef( width, width, 1.0f );
240  OGL_draw_half_open_cylinder( aNrSidesPerCircle );
241  glPopMatrix();
242 
243  glBegin( GL_QUADS );
244  glNormal3f( 0.0,-1.0, 0.0 );
245  glVertex3f( length,-radius, 1.0 );
246  glVertex3f( 0.0, -radius, 1.0 );
247  glVertex3f( 0.0, -radius, 0.0 );
248  glVertex3f( length,-radius, 0.0 );
249  glEnd();
250 
251  glBegin( GL_QUADS );
252  glNormal3f( 0.0, 1.0, 0.0 );
253  glVertex3f( length, radius, 0.0 );
254  glVertex3f( 0.0, radius, 0.0 );
255  glVertex3f( 0.0, radius, 1.0 );
256  glVertex3f( length, radius, 1.0 );
257  glEnd();
258 
259  glBegin( GL_QUADS );
260  glNormal3f( 0.0, 0.0, 1.0 );
261  glVertex3f( length, radius, 1.0 );
262  glVertex3f( 0.0, radius, 1.0 );
263  glVertex3f( 0.0, -radius, 1.0 );
264  glVertex3f( length,-radius, 1.0 );
265  glEnd();
266 
267  glBegin( GL_QUADS );
268  glNormal3f( 0.0, 0.0,-1.0 );
269  glVertex3f( length,-radius, 0.0 );
270  glVertex3f( 0.0, -radius, 0.0 );
271  glVertex3f( 0.0, radius, 0.0 );
272  glVertex3f( length, radius, 0.0 );
273  glEnd();
274 
275  glScalef( width, width, 1.0f );
276  glRotatef( 180, 0.0, 0.0, 1.0 );
277  OGL_draw_half_open_cylinder( aNrSidesPerCircle );
278 
279  glPopMatrix ();
280 }
const SFVEC2F & GetStart() const
float GetWidth() const
float GetLength() const
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
float GetRadius() const
void OGL_draw_half_open_cylinder(unsigned int aNrSidesPerCircle)
OGL_draw_half_open_cylinder - draws an open half cylinder with diameter 1.0f and Height 1...
const SFVEC2F & GetEnd_minus_Start() const
#define RADPERDEG