• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
skyglpainter.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 Henry de Valence <hdevalence@gmail.com>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 
18 */
19 
20 #ifdef _WIN32
21 #include <windows.h>
22 #endif
23 #include "skyglpainter.h"
24 
25 #include <cstddef>
26 #include <Eigen/Core>
27 #include <Eigen/Geometry>
28 USING_PART_OF_NAMESPACE_EIGEN
29 using Eigen::Rotation2Df;
30 
31 #include <GL/gl.h>
32 #include <QGLWidget>
33 
34 #include "skymap.h"
35 #include "kstarsdata.h"
36 #include "Options.h"
37 
38 #include "texturemanager.h"
39 
40 #include "skycomponents/linelist.h"
41 #include "skycomponents/skiplist.h"
42 #include "skycomponents/linelistlabel.h"
43 #include "skycomponents/skymapcomposite.h"
44 #include "skycomponents/flagcomponent.h"
45 #include "skycomponents/satellitescomponent.h"
46 #include "skycomponents/supernovaecomponent.h"
47 
48 #include "skyobjects/deepskyobject.h"
49 #include "skyobjects/kscomet.h"
50 #include "skyobjects/ksasteroid.h"
51 #include "skyobjects/trailobject.h"
52 #include "skyobjects/satellite.h"
53 #include "skyobjects/supernova.h"
54 
55 Vector2f SkyGLPainter::m_vertex[NUMTYPES][6*BUFSIZE];
56 Vector2f SkyGLPainter::m_texcoord[NUMTYPES][6*BUFSIZE];
57 Vector3f SkyGLPainter::m_color[NUMTYPES][6*BUFSIZE];
58 int SkyGLPainter::m_idx[NUMTYPES];
59 bool SkyGLPainter::m_init = false;
60 
61 
62 
63 SkyGLPainter::SkyGLPainter( QGLWidget *widget ) :
64  SkyPainter()
65 {
66  m_widget = widget;
67  if( !m_init ) {
68  kDebug() << "Initializing texcoord arrays...\n";
69  for(int i = 0; i < NUMTYPES; ++i) {
70  m_idx[i] = 0;
71  for(int j = 0; j < BUFSIZE; ++j) {
72  m_texcoord[i][6*j +0] = Vector2f(0,0);
73  m_texcoord[i][6*j +1] = Vector2f(1,0);
74  m_texcoord[i][6*j +2] = Vector2f(0,1);
75  m_texcoord[i][6*j +3] = Vector2f(0,1);
76  m_texcoord[i][6*j +4] = Vector2f(1,0);
77  m_texcoord[i][6*j +5] = Vector2f(1,1);
78  }
79  }
80  //Generate textures that were loaded before the SkyMap was
81  m_init = true;
82  }
83 }
84 
85 void SkyGLPainter::drawBuffer(int type)
86 {
87  // Prevent crash if type > UNKNOWN
88  if (type > SkyObject::TYPE_UNKNOWN)
89  type = SkyObject::TYPE_UNKNOWN;
90 
91  //printf("Drawing buffer for type %d, has %d objects\n", type, m_idx[type]);
92  if( m_idx[type] == 0 ) return;
93 
94  glEnable(GL_TEXTURE_2D);
95  switch( type ) {
96  case 3: case 13: TextureManager::bindTexture("open-cluster", m_widget); break;
97  case 4: TextureManager::bindTexture("globular-cluster", m_widget); break;
98  case 6: TextureManager::bindTexture("planetary-nebula", m_widget); break;
99  case 5: case 7: case 15: TextureManager::bindTexture("gaseous-nebula", m_widget); break;
100  case 8: case 16: TextureManager::bindTexture("galaxy", m_widget); break;
101  case 14: TextureManager::bindTexture("galaxy-cluster", m_widget); break;
102  case 0: case 1: default: TextureManager::bindTexture("star", m_widget); break;
103  }
104 
105  glEnable( GL_BLEND );
106  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
107  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
108  glEnableClientState(GL_VERTEX_ARRAY);
109  glEnableClientState(GL_COLOR_ARRAY);
110  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
111 
112  glVertexPointer (2,GL_FLOAT,0, &m_vertex[type]);
113  glTexCoordPointer(2,GL_FLOAT,0, &m_texcoord[type]);
114  glColorPointer (3,GL_FLOAT,0, &m_color[type]);
115 
116  glDrawArrays(GL_TRIANGLES, 0, 6*m_idx[type]);
117  m_idx[type] = 0;
118 
119  glDisableClientState(GL_VERTEX_ARRAY);
120  glDisableClientState(GL_COLOR_ARRAY);
121  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
122 }
123 
124 bool SkyGLPainter::addItem(SkyPoint* p, int type, float width, char sp)
125 {
126  bool visible = false;
127  Vector2f vec = m_proj->toScreenVec(p,true,&visible);
128  if(!visible) return false;
129 
130  // Prevent crash if type > UNKNOWN
131  if (type > SkyObject::TYPE_UNKNOWN)
132  type = SkyObject::TYPE_UNKNOWN;
133 
134  //If the buffer is full, flush it
135  if(m_idx[type] == BUFSIZE) {
136  drawBuffer(type);
137  }
138 
139  int i = 6*m_idx[type];
140  float w = width/2.;
141 
142  m_vertex[type][i + 0] = vec + Vector2f(-w,-w);
143  m_vertex[type][i + 1] = vec + Vector2f( w,-w);
144  m_vertex[type][i + 2] = vec + Vector2f(-w, w);
145  m_vertex[type][i + 3] = vec + Vector2f(-w, w);
146  m_vertex[type][i + 4] = vec + Vector2f( w,-w);
147  m_vertex[type][i + 5] = vec + Vector2f( w, w);
148 
149  Vector3f c(1.,1.,1.);
150  if( sp != 'x' && Options::starColorMode() != 0 ) {
151  // We have a star and aren't drawing real star colors
152  switch( Options::starColorMode() ) {
153  case 1: // solid red
154  c = Vector3f( 255./255., 0., 0. ); break;
155  case 2: // solid black
156  c = Vector3f( 0., 0., 0. ); break;
157  case 3: // Solid white
158  c = Vector3f( 1., 1., 1. ); break;
159  }
160  }
161  else {
162  QColor starColor;
163 
164  // Set RGB values into QColor
165  switch(sp) {
166  case 'o': case 'O': starColor.setRgb( 153, 153, 255); break;
167  case 'b': case 'B': starColor.setRgb( 151, 233, 255); break;
168  case 'a': case 'A': starColor.setRgb( 153, 255, 255); break;
169  case 'f': case 'F': starColor.setRgb( 219, 255, 135); break;
170  case 'g': case 'G': starColor.setRgb( 255, 255, 153); break;
171  case 'k': case 'K': starColor.setRgb( 255, 193, 153); break;
172  case 'm': case 'M': starColor.setRgb( 255, 153, 153); break;
173  case 'x': starColor.setRgb( m_pen[0] * 255, m_pen[1] * 255, m_pen[2] *255 ); break;
174  default: starColor.setRgb( 153, 255, 255); break; // If we don't know what spectral type, we use the same as 'A' (See SkyQPainter)
175  }
176 
177  // Convert to HSV space using QColor's methods and adjust saturation.
178  int h, s, v;
179  starColor.getHsv( &h, &s, &v );
180  s = ( Options::starColorIntensity() / 10. ) * 200.; // Rewrite the saturation based on the star color intensity setting, 200 is the hard-wired max saturation, just to approximately match up with QPainter mode.
181  starColor.setHsv( h, s, v );
182 
183  // Get RGB ratios and put them in 'c'
184  c = Vector3f( starColor.redF(), starColor.greenF(), starColor.blueF() );
185 
186  }
187  for(int j = 0; j < 6; ++j) {
188  m_color[type][i+j] = c;
189  }
190 
191  ++m_idx[type];
192  return true;
193 }
194 
195 void SkyGLPainter::drawTexturedRectangle( const QImage& img,
196  const Vector2f& pos, const float angle,
197  const float sizeX, const float sizeY )
198 {
199  // Set up texture
200  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
201  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
202  glEnable(GL_TEXTURE_2D);
203  TextureManager::bindFromImage( img, m_widget );
204 
205  // Render rectangle
206  glPushMatrix();
207  glTranslatef( pos.x(), pos.y(), 0 );
208  glRotatef( angle, 0, 0, 1 );
209  glScalef( sizeX, sizeY, 1 );
210 
211  glBegin(GL_QUADS);
212  // Note! Y coordinate of texture is mirrored w.r.t. to
213  // vertex coordinates to account for difference between
214  // OpenGL and QPainter coordinate system.
215  // Otherwise image would appear mirrored
216  glTexCoord2f( 0, 1 );
217  glVertex2f( -0.5, -0.5 );
218 
219  glTexCoord2f( 1, 1 );
220  glVertex2f( 0.5, -0.5 );
221 
222  glTexCoord2f( 1, 0 );
223  glVertex2f( 0.5, 0.5 );
224 
225  glTexCoord2f( 0, 0 );
226  glVertex2f( -0.5, 0.5 );
227  glEnd();
228 
229  glPopMatrix();
230 }
231 
232 bool SkyGLPainter::drawPlanet(KSPlanetBase* planet)
233 {
234  //If it's surely not visible, just stop now
235  if( !m_proj->checkVisibility(planet) )
236  return false;
237 
238  float zoom = Options::zoomFactor();
239  float fakeStarSize = ( 10.0 + log10( zoom ) - log10( MINZOOM ) ) * ( 10 - planet->mag() ) / 10;
240  fakeStarSize = qMin(fakeStarSize, 20.f);
241 
242  float size = planet->angSize() * dms::PI * zoom/10800.0;
243  if( size < fakeStarSize || planet->image().isNull() )
244  {
245  // Draw them as bright stars of appropriate color instead of images
246  char spType;
247  //FIXME: do these need i18n?
248  if( planet->name() == i18n( "Sun" ) ) {
249  spType = 'G';
250  } else if( planet->name() == i18n("Mars") ) {
251  spType = 'K';
252  } else if( planet->name() == i18n("Jupiter") || planet->name() == i18n("Mercury") || planet->name() == i18n("Saturn") ) {
253  spType = 'F';
254  } else {
255  spType = 'B';
256  }
257  return addItem(planet, planet->type(), qMin(fakeStarSize,(float)20.),spType);
258  } else {
259  // Draw them as textures
260  bool visible = false;
261  Vector2f pos = m_proj->toScreenVec(planet,true,&visible);
262  if( !visible )
263  return false;
264 
265  //Because Saturn has rings, we inflate its image size by a factor 2.5
266  if( planet->name() == "Saturn" )
267  size *= 2.5;
268 
269  drawTexturedRectangle( planet->image(),
270  pos, m_proj->findPA(planet, pos.x(), pos.y()),
271  size, size );
272  return true;
273  }
274 }
275 
276 bool SkyGLPainter::drawDeepSkyObject(DeepSkyObject* obj, bool drawImage)
277 {
278  //If it's surely not visible, just stop now
279  if( !m_proj->checkVisibility(obj) )
280  return false;
281  int type = obj->type();
282 
283  // Prevent crash if type > UNKNOWN
284  if (type > SkyObject::TYPE_UNKNOWN)
285  type = SkyObject::TYPE_UNKNOWN;
286 
287  //addItem(obj, type, obj->a() * dms::PI * Options::zoomFactor() / 10800.0);
288 
289  //If it's a star, add it like a star
290  if( type < 2 )
291  return addItem(obj, type, starWidth(obj->mag()));
292 
293  bool visible = false;
294  Vector2f vec = m_proj->toScreenVec(obj,true,&visible);
295  if(!visible)
296  return false;
297 
298  float width = obj->a() * dms::PI * Options::zoomFactor() / 10800.0;
299  float pa = m_proj->findPA(obj, vec[0], vec[1]) * (M_PI/180.0);
300  Rotation2Df r(pa);
301  float w = width/2.;
302  float h = w * obj->e();
303 
304  // Fake a small, finite width / height if the objects have
305  // undefined sizes (in pixels, does not scale) at high zooms
306  if( Options::zoomFactor() > 10800.0 ) { // This means 1 arcmin maps to 2 pi pixels or something like that
307  if( w == 0 ) {
308  w = 7;
309  }
310  if( h == 0 ) {
311  h = 7;
312  }
313  }
314 
315  //Init texture if it doesn't exist and we would be drawing it anyways
316  if( drawImage && !obj->image().isNull() ) {
317  drawTexturedRectangle( obj->image(), vec, pa, w, h);
318  } else {
319  //If the buffer is full, flush it
320  if(m_idx[type] == BUFSIZE)
321  drawBuffer(type);
322 
323  const int i = 6*m_idx[type];
324  m_vertex[type][i + 0] = vec + r * Vector2f(-w,-h);
325  m_vertex[type][i + 1] = vec + r * Vector2f( w,-h);
326  m_vertex[type][i + 2] = vec + r * Vector2f(-w, h);
327  m_vertex[type][i + 3] = vec + r * Vector2f(-w, h);
328  m_vertex[type][i + 4] = vec + r * Vector2f( w,-h);
329  m_vertex[type][i + 5] = vec + r * Vector2f( w, h);
330  Vector3f c( m_pen[0], m_pen[1], m_pen[2] );
331 
332  for(int j = 0; j < 6; ++j)
333  m_color[type][i+j] = c;
334 
335  ++m_idx[type];
336  }
337  return true;
338 }
339 
340 bool SkyGLPainter::drawPointSource(SkyPoint* loc, float mag, char sp)
341 {
342  //If it's surely not visible, just stop now
343  if( !m_proj->checkVisibility(loc) ) return false;
344  return addItem(loc, SkyObject::STAR, starWidth(mag), sp);
345 }
346 
347 void SkyGLPainter::drawSkyPolygon(LineList* list)
348 {
349  SkyList *points = list->points();
350  bool isVisible, isVisibleLast;
351  SkyPoint* pLast = points->last();
352  Vector2f oLast = m_proj->toScreenVec( pLast, true, &isVisibleLast );
353  // & with the result of checkVisibility to clip away things below horizon
354  isVisibleLast &= m_proj->checkVisibility(pLast);
355 
356  //Guess that we will require around the same number of items as in points.
357  QVector<Vector2f> polygon;
358  polygon.reserve(points->size());
359  for ( int i = 0; i < points->size(); ++i ) {
360  SkyPoint* pThis = points->at( i );
361  Vector2f oThis = m_proj->toScreenVec( pThis, true, &isVisible );
362  // & with the result of checkVisibility to clip away things below horizon
363  isVisible &= m_proj->checkVisibility(pThis);
364 
365  if ( isVisible && isVisibleLast ) {
366  polygon << oThis;
367  } else if ( isVisibleLast ) {
368  Vector2f oMid = m_proj->clipLineVec( pLast, pThis );
369  polygon << oMid;
370  } else if ( isVisible ) {
371  Vector2f oMid = m_proj->clipLineVec( pThis, pLast );
372  polygon << oMid;
373  polygon << oThis;
374  }
375 
376  pLast = pThis;
377  oLast = oThis;
378  isVisibleLast = isVisible;
379  }
380 
381  // false -> makes kstars slower but is always accurate
382  // true -> faster but potentially results in incorrect rendering
383  #define KSTARS_ASSUME_CONVEXITY false
384  if ( polygon.size() ) {
385  drawPolygon(polygon, KSTARS_ASSUME_CONVEXITY);
386  }
387 }
388 
389 void SkyGLPainter::drawPolygon(const QVector<Vector2f>& polygon, bool convex, bool flush_buffers)
390 {
391  //Flush all buffers
392  if( flush_buffers ) {
393  for(int i = 0; i < NUMTYPES; ++i) {
394  drawBuffer(i);
395  }
396  }
397  glDisable(GL_TEXTURE_2D);
398  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
399  if( !convex ) {
400  //Set up the stencil buffer and disable the color buffer
401  glClear(GL_STENCIL_BUFFER_BIT);
402  glColorMask(0,0,0,0);
403  glEnable(GL_STENCIL_TEST);
404  glStencilFunc(GL_ALWAYS, 0, 0);
405  glStencilOp(GL_INVERT, GL_INVERT, GL_INVERT);
406  //Now draw a triangle fan. Because of the GL_INVERT,
407  //this will fill the stencil buffer with odd-even fill.
408  glEnableClientState(GL_VERTEX_ARRAY);
409  glVertexPointer(2,GL_FLOAT,0, polygon.data() );
410  glDrawArrays(GL_TRIANGLE_FAN, 0, polygon.size());
411  glDisableClientState(GL_VERTEX_ARRAY);
412 
413  //Now draw the stencil:
414  glStencilFunc(GL_NOTEQUAL, 0, 0xffffffff);
415  glColorMask(1,1,1,1);
416  glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
417  glBegin(GL_QUADS);
418  glVertex2f(0,0);
419  glVertex2f(0,m_widget->height());
420  glVertex2f(m_widget->width(),m_widget->height());
421  glVertex2f(m_widget->width(),0);
422  glEnd();
423  glDisable(GL_STENCIL_TEST);
424  } else {
425  glEnableClientState(GL_VERTEX_ARRAY);
426  glVertexPointer(2,GL_FLOAT,0, polygon.data() );
427  glDrawArrays(GL_POLYGON, 0, polygon.size());
428  glDisableClientState(GL_VERTEX_ARRAY);
429  }
430 }
431 
432 void SkyGLPainter::drawHorizon(bool filled, SkyPoint* labelPoint, bool* drawLabel)
433 {
434  QVector<Vector2f> ground = m_proj->groundPoly( labelPoint, drawLabel );
435 
436  if( ground.size() ) {
437  if( filled ) {
438  glDisableClientState( GL_COLOR_ARRAY );
439  drawPolygon( ground, false, false );
440  } else {
441  glDisable( GL_TEXTURE_2D );
442  glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
443  glEnableClientState( GL_VERTEX_ARRAY );
444  glVertexPointer( 2, GL_FLOAT, 0, ground.data() );
445  glDrawArrays( GL_LINE_LOOP, 0, ground.size() );
446  glDisableClientState( GL_VERTEX_ARRAY );
447  }
448  }
449 }
450 
451 //This implementation is *correct* but slow.
452 void SkyGLPainter::drawSkyPolyline(LineList* list, SkipList* skipList, LineListLabel* label)
453 {
454  glDisable(GL_TEXTURE_2D);
455  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
456  glBegin(GL_LINE_STRIP);
457  SkyList *points = list->points();
458  bool isVisible, isVisibleLast;
459  Vector2f oLast = m_proj->toScreenVec(points->first(), true, &isVisibleLast);
460  // & with the result of checkVisibility to clip away things below horizon
461  isVisibleLast &= m_proj->checkVisibility(points->first());
462  if( isVisibleLast ) { glVertex2fv(oLast.data()); }
463 
464  for(int i = 1; i < points->size(); ++i) {
465  Vector2f oThis = m_proj->toScreenVec( points->at(i), true, &isVisible);
466  // & with the result of checkVisibility to clip away things below horizon
467  isVisible &= m_proj->checkVisibility(points->at(i));
468 
469  bool doSkip = (skipList ? skipList->skip(i) : false);
470  //This tells us whether we need to end the current line or whether we
471  //are to keep drawing into it. If we skip, then we are going to have to end.
472  bool shouldEnd = doSkip;
473 
474  if( !doSkip ) {
475  if( isVisible && isVisibleLast ) {
476  glVertex2fv(oThis.data());
477  if( label ) {
478  label->updateLabelCandidates(oThis.x(), oThis.y(), list, i);
479  }
480  } else if( isVisibleLast ) {
481  Vector2f oMid = m_proj->clipLineVec( points->at(i-1), points->at(i) );
482  glVertex2fv(oMid.data());
483  //If the last point was visible but this one isn't we are at
484  //the end of a strip, so we need to end
485  shouldEnd = true;
486  } else if( isVisible ) {
487  Vector2f oMid = m_proj->clipLineVec( points->at(i), points->at(i-1) );
488  glVertex2fv(oMid.data());
489  glVertex2fv(oThis.data());
490  }
491  }
492 
493  if(shouldEnd) {
494  glEnd();
495  glBegin(GL_LINE_STRIP);
496  if( isVisible ) {
497  glVertex2fv(oThis.data());
498  }
499  }
500 
501  isVisibleLast = isVisible;
502  }
503  glEnd();
504 }
505 
506 //FIXME: implement these two
507 
508 void SkyGLPainter::drawObservingList(const QList< SkyObject* >& obs)
509 {
510 
511  // TODO: Generalize to drawTargetList or something like that. Make
512  // texture changeable etc.
513  // TODO: Draw labels when required
514 
515  foreach( SkyObject *obj, obs ) {
516  if( !m_proj->checkVisibility(obj) ) continue;
517  bool visible;
518  Vector2f vec = m_proj->toScreenVec(obj, true, &visible);
519  if( !visible || !m_proj->onScreen(vec) ) continue;
520  const float size = 30.;
521  QImage obsmarker = TextureManager::getImage("obslistsymbol");
522  drawTexturedRectangle( obsmarker, vec, 0,size,size );
523  }
524 
525 }
526 
527 void SkyGLPainter::drawFlags()
528 {
529  KStarsData *data = KStarsData::Instance();
530  SkyPoint* point;
531  QImage image;
532  const QString label;
533  bool visible = false;
534  Vector2f vec;
535  int i;
536 
537  for ( i=0; i<data->skyComposite()->flags()->size(); i++ ) {
538  point = data->skyComposite()->flags()->pointList().at( i );
539  image = data->skyComposite()->flags()->image( i );
540 
541  // Set Horizontal coordinates
542  point->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
543 
544  // Get flag position on screen
545  vec = m_proj->toScreenVec( point, true, &visible );
546 
547  // Return if flag is not visible
548  if( !visible || !m_proj->onScreen( vec ) )
549  continue;
550 
551  const QImage& img = data->skyComposite()->flags()->imageName( i ) == "Default"
552  ? TextureManager::getImage("defaultflag")
553  : image;
554 
555  drawTexturedRectangle( img, vec, 0, img.width(), img.height() );
556  drawText( vec.x(), vec.y(),
557  data->skyComposite()->flags()->label( i ),
558  QFont( "Courier New", 10, QFont::Bold ),
559  data->skyComposite()->flags()->labelColor( i ) );
560  }
561 }
562 
563 void SkyGLPainter::drawText( int x, int y, const QString text, QFont font, QColor color )
564 {
565  // Return if text is empty
566  if ( text.isEmpty() )
567  return;
568 
569  int longest, tex_size = 2;
570 
571  // Get size of text
572  QFontMetrics fm( font );
573  const QRect bounding_rect = fm.boundingRect( text );
574 
575  // Compute texture size
576  if ( bounding_rect.width() > bounding_rect.height() )
577  longest = bounding_rect.width();
578  else
579  longest = bounding_rect.height();
580 
581  while ( tex_size < longest ) {
582  tex_size *= 2;
583  }
584 
585  // Create image of text
586  QImage text_image( tex_size, tex_size, QImage::Format_ARGB32 );
587  text_image.fill( Qt::transparent );
588  QPainter p( &text_image );
589  p.setFont( font );
590  p.setPen( color );
591  p.drawText( 0, tex_size/2, text );
592  p.end();
593 
594  // Create texture
595  float w = text_image.width();
596  float h = text_image.height();
597  float vx = x + 0.5*w + 10;
598  float vy = y - 10;
599  drawTexturedRectangle( text_image, Vector2f(vx,vy), 0, w, h );
600 }
601 
602 void SkyGLPainter::drawSkyLine(SkyPoint* a, SkyPoint* b)
603 {
604  bool aVisible, bVisible;
605  Vector2f aScreen = m_proj->toScreenVec( a, true, &aVisible );
606  Vector2f bScreen = m_proj->toScreenVec( b, true, &bVisible );
607 
608  glDisable( GL_TEXTURE_2D );
609  glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
610  glBegin( GL_LINE_STRIP );
611 
612  //THREE CASES:
613  if( aVisible && bVisible ) {
614  //Both a,b visible, so paint the line normally:
615  glVertex2fv( aScreen.data() );
616  glVertex2fv( bScreen.data() );
617  } else if( aVisible ) {
618  //a is visible but b isn't:
619  glVertex2fv( aScreen.data() );
620  glVertex2fv( m_proj->clipLineVec( a, b ).data() );
621  } else if( bVisible ) {
622  //b is visible but a isn't:
623  glVertex2fv( bScreen.data() );
624  glVertex2fv( m_proj->clipLineVec( b, a ).data() );
625  } //FIXME: what if both are offscreen but the line isn't?
626 
627  glEnd();
628 }
629 
630 void SkyGLPainter::drawSkyBackground()
631 {
632  glDisable(GL_TEXTURE_2D);
633  QColor bg = KStarsData::Instance()->colorScheme()->colorNamed( "SkyColor" );
634  glClearColor( bg.redF(), bg.greenF(), bg.blueF(), bg.alphaF() );
635  glClear(GL_COLOR_BUFFER_BIT);
636 }
637 
638 void SkyGLPainter::end()
639 {
640  for(int i = 0; i < NUMTYPES; ++i) {
641  drawBuffer(i);
642  }
643 }
644 
645 void SkyGLPainter::begin()
646 {
647  m_proj = m_sm->projector();
648 
649  //Load ortho projection
650  glViewport(0,0,m_widget->width(),m_widget->height());
651  glMatrixMode(GL_PROJECTION);
652  glLoadIdentity();
653  glOrtho(0,m_widget->width(), m_widget->height(),0, -1,1);
654 
655  //reset modelview matrix
656  glMatrixMode(GL_MODELVIEW);
657  glLoadIdentity();
658 
659  //Set various parameters
660  glDisable(GL_LIGHTING);
661  glDisable(GL_COLOR_MATERIAL);
662  glDisable(GL_CULL_FACE);
663  glDisable(GL_DEPTH_TEST);
664  glDepthMask(GL_FALSE);
665  glPointSize(1.);
666  glEnable(GL_POINT_SMOOTH);
667  glEnable(GL_LINE_SMOOTH);
668  glEnable(GL_POLYGON_SMOOTH);
669  glLineStipple(1,0xCCCC);
670  glEnable(GL_BLEND);
671 
672  glClearStencil(0);
673 }
674 
675 void SkyGLPainter::setBrush(const QBrush& brush)
676 {
677  Q_UNUSED(brush);
678  /*
679  QColor c = brush.color();
680  m_pen = Vector4f( c.redF(), c.greenF(), c.blueF(), c.alphaF() );
681  glColor4fv( m_pen.data() );
682  */
683 }
684 
685 void SkyGLPainter::setPen(const QPen& pen)
686 {
687  QColor c = pen.color();
688  m_pen = Vector4f( c.redF(), c.greenF(), c.blueF(), c.alphaF() );
689  glColor4fv( m_pen.data() );
690  glLineWidth(pen.widthF());
691  if( pen.style() != Qt::SolidLine ) {
692  glEnable(GL_LINE_STIPPLE);
693  } else {
694  glDisable(GL_LINE_STIPPLE);
695  }
696 
697 }
698 
699 void SkyGLPainter::drawSatellite( Satellite* sat ) {
700  KStarsData *data = KStarsData::Instance();
701  bool visible = false;
702  Vector2f pos, vertex;
703 
704  sat->HorizontalToEquatorial( data->lst(), data->geo()->lat() );
705 
706  pos = m_proj->toScreenVec( sat, true, &visible );
707 
708  if( !visible || !m_proj->onScreen( pos ) )
709  return;
710 
711  if ( Options::drawSatellitesLikeStars() ) {
712  drawPointSource(sat, 3.5, 'B');
713  } else {
714  if ( sat->isVisible() )
715  setPen( data->colorScheme()->colorNamed( "VisibleSatColor" ) );
716  else
717  setPen( data->colorScheme()->colorNamed( "SatColor" ) );
718 
719  glDisable( GL_TEXTURE_2D );
720  glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
721  glBegin( GL_QUADS );
722 
723  vertex = pos + Vector2f( -1.0, -1.0 );
724  glVertex2fv(vertex.data());
725  vertex = pos + Vector2f( 1.0, -1.0 );
726  glVertex2fv(vertex.data());
727  vertex = pos + Vector2f( 1.0, 1.0 );
728  glVertex2fv(vertex.data());
729  vertex = pos + Vector2f( -1.0, 1.0 );
730  glVertex2fv(vertex.data());
731 
732  glEnd();
733  }
734 
735  if ( Options::showSatellitesLabels() )
736  data->skyComposite()->satellites()->drawLabel( sat, QPointF( pos.x(), pos.y() ) );
737 }
738 
739 bool SkyGLPainter::drawSupernova(Supernova* sup)
740 {
741  KStarsData *data = KStarsData::Instance();
742  bool visible = false;
743  Vector2f pos, vertex;
744 
745  sup->HorizontalToEquatorial( data->lst(), data->geo()->lat() );
746 
747  pos = m_proj->toScreenVec( sup, true, &visible );
748 
749  if( !visible || !m_proj->onScreen( pos ) )
750  return false;
751  setPen( data->colorScheme()->colorNamed( "SupernovaColor" ) );
752 
753  glDisable( GL_TEXTURE_2D );
754  glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
755 
756  glBegin( GL_LINES );
757  vertex = pos + Vector2f( 2.0, 0.0 );
758  glVertex2fv(vertex.data());
759  vertex = pos + Vector2f( -2.0, 0.0 );
760  glVertex2fv(vertex.data());
761  glEnd();
762 
763  glBegin( GL_LINES );
764  vertex = pos + Vector2f( 0.0, 2.0 );
765  glVertex2fv(vertex.data());
766  vertex = pos + Vector2f( 0.0, -2.0 );
767  glVertex2fv(vertex.data());
768  glEnd();
769 
770  return true;
771 }
772 
FlagComponent::size
int size()
Return the numbers of flags.
Definition: flagcomponent.cpp:213
satellitescomponent.h
FlagComponent::imageName
QString imageName(int index)
Get image name.
Definition: flagcomponent.cpp:253
SkyGLPainter::SkyGLPainter
SkyGLPainter(QGLWidget *widget)
Definition: skyglpainter.cpp:63
Projector::onScreen
bool onScreen(const QPointF &p) const
Check whether the projected point is on-screen.
Definition: projector.cpp:98
Projector::toScreenVec
virtual Vector2f toScreenVec(const SkyPoint *o, bool oRefract=true, bool *onVisibleHemisphere=0) const
Given the coordinates of the SkyPoint argument, determine the pixel coordinates in the SkyMap...
Definition: projector.cpp:402
Projector::groundPoly
virtual QVector< Vector2f > groundPoly(SkyPoint *labelpoint=0, bool *drawLabel=0) const
Get the ground polygon.
Definition: projector.cpp:252
SkyGLPainter::drawSupernova
virtual bool drawSupernova(Supernova *sup)
Draw a Supernova.
Definition: skyglpainter.cpp:739
SkyList
QVector< SkyPoint * > SkyList
Definition: skycomponents/typedef.h:45
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
supernova.h
skiplist.h
SkyObject::TYPE_UNKNOWN
Definition: skyobject.h:112
KStarsData::colorScheme
ColorScheme * colorScheme()
Definition: kstarsdata.h:149
LineListLabel
Definition: linelistlabel.h:36
deepskyobject.h
SkyGLPainter::drawFlags
virtual void drawFlags()
Draw flags.
Definition: skyglpainter.cpp:527
KStarsData::lst
dms * lst()
Definition: kstarsdata.h:161
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
skyglpainter.h
SkyGLPainter::drawHorizon
virtual void drawHorizon(bool filled, SkyPoint *labelPoint=0, bool *drawLabel=0)
Definition: skyglpainter.cpp:432
ColorScheme::colorNamed
QColor colorNamed(const QString &name) const
Retrieve a color by name.
Definition: colorscheme.cpp:97
SkyGLPainter::end
virtual void end()
End and finalize painting.
Definition: skyglpainter.cpp:638
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
SkyPainter::m_sm
SkyMap * m_sm
Definition: skypainter.h:158
TextureManager::getImage
static const QImage & getImage(const QString &name)
Return texture image.
Definition: texturemanager.cpp:44
LineList
Definition: linelist.h:35
Projector::checkVisibility
bool checkVisibility(SkyPoint *p) const
Determine if the skypoint p is likely to be visible in the display window.
Definition: projector.cpp:181
SkyGLPainter::drawText
void drawText(int x, int y, const QString text, QFont font, QColor color)
Definition: skyglpainter.cpp:563
Options::showSatellitesLabels
static bool showSatellitesLabels()
Get Draw satellite labels?
Definition: Options.h:4369
SkyMapComposite::satellites
SatellitesComponent * satellites()
Definition: skymapcomposite.cpp:609
NaN::f
const float f
Definition: nan.h:36
Projector::findPA
double findPA(SkyObject *o, float x, float y) const
Determine the on-screen position angle of a SkyObject.
Definition: projector.cpp:227
LineList::points
SkyList * points()
Definition: linelist.h:53
FlagComponent::image
QImage image(int index)
Get image.
Definition: flagcomponent.cpp:241
texturemanager.h
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
SkyMapComposite::flags
FlagComponent * flags()
Definition: skymapcomposite.cpp:605
SkyPainter::starWidth
float starWidth(float mag) const
Get the width of a star of magnitude mag.
Definition: skypainter.cpp:50
DeepSkyObject::a
float a() const
Definition: deepskyobject.h:132
linelist.h
skymapcomposite.h
MINZOOM
#define MINZOOM
Definition: kstarsdata.h:38
FlagComponent::label
QString label(int index)
Get label.
Definition: flagcomponent.cpp:225
linelistlabel.h
KSPlanetBase::angSize
double angSize() const
Definition: ksplanetbase.h:171
Options::starColorIntensity
static uint starColorIntensity()
Get Saturation level of star colors.
Definition: Options.h:2944
Supernova
Represents the supernova object.
Definition: supernova.h:44
skymap.h
SkyPoint::HorizontalToEquatorial
void HorizontalToEquatorial(const dms *LST, const dms *lat)
Determine the (RA, Dec) coordinates of the SkyPoint from its (Altitude, Azimuth) coordinates, given the local sidereal time and the observer's latitude.
Definition: skypoint.cpp:102
Projector::clipLineVec
Vector2f clipLineVec(SkyPoint *p1, SkyPoint *p2) const
ASSUMES *p1 did not clip but *p2 did.
Definition: projector.cpp:115
SkyGLPainter::drawSkyPolygon
virtual void drawSkyPolygon(LineList *list)
Draw a polygon in the sky.
Definition: skyglpainter.cpp:347
trailobject.h
KStarsData::skyComposite
SkyMapComposite * skyComposite()
Definition: kstarsdata.h:146
SkyGLPainter::drawSkyBackground
virtual void drawSkyBackground()
Draw the sky background.
Definition: skyglpainter.cpp:630
SkyGLPainter::drawDeepSkyObject
virtual bool drawDeepSkyObject(DeepSkyObject *obj, bool drawImage=false)
Draw a deep sky object.
Definition: skyglpainter.cpp:276
QGLWidget
PointListComponent::pointList
QList< SkyPoint * > & pointList()
Definition: pointlistcomponent.h:58
SkyPoint::EquatorialToHorizontal
void EquatorialToHorizontal(const dms *LST, const dms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates, given the local sidereal time and the observer's latitude.
Definition: skypoint.cpp:55
DeepSkyObject::image
const QImage & image() const
Definition: deepskyobject.h:161
Options.h
SkyObject::mag
float mag(void) const
Definition: skyobject.h:182
DeepSkyObject
Provides all necessary information about a deep-sky object: data inherited from SkyObject (coordinate...
Definition: deepskyobject.h:43
SkyGLPainter::drawSkyPolyline
virtual void drawSkyPolyline(LineList *list, SkipList *skipList=0, LineListLabel *label=0)
Draw a polyline in the sky.
Definition: skyglpainter.cpp:452
SkyGLPainter::drawPointSource
virtual bool drawPointSource(SkyPoint *loc, float mag, char sp= 'A')
Draw a point source (e.g., a star).
Definition: skyglpainter.cpp:340
GeoLocation::lat
const dms * lat() const
Definition: geolocation.h:79
Options::drawSatellitesLikeStars
static bool drawSatellitesLikeStars()
Get If selected, satellites will be draw like stars, otherwise, draw satellites as small colored squa...
Definition: Options.h:4350
SatellitesComponent::drawLabel
void drawLabel(Satellite *sat, QPointF pos)
Draw label of a satellite.
Definition: satellitescomponent.cpp:100
SkyObject::type
int type(void) const
Definition: skyobject.h:164
kscomet.h
Satellite::isVisible
bool isVisible()
Definition: satellite.cpp:1196
SkyGLPainter::drawPlanet
virtual bool drawPlanet(KSPlanetBase *planet)
Draw a planet.
Definition: skyglpainter.cpp:232
FlagComponent::labelColor
QColor labelColor(int index)
Get label color.
Definition: flagcomponent.cpp:233
PI
#define PI
Definition: satellite.cpp:43
SkipList::skip
bool skip(int i)
Definition: skiplist.h:51
Options::zoomFactor
static double zoomFactor()
Get Zoom Factor, in pixels per radian.
Definition: Options.h:2531
satellite.h
KSTARS_ASSUME_CONVEXITY
#define KSTARS_ASSUME_CONVEXITY
Options::starColorMode
static uint starColorMode()
Get Mode for rendering stars.
Definition: Options.h:2918
SkyGLPainter::drawSkyLine
virtual void drawSkyLine(SkyPoint *a, SkyPoint *b)
Draw a line between points in the sky.
Definition: skyglpainter.cpp:602
Satellite
Represents an artificial satellites.
Definition: satellite.h:35
KSPlanetBase
A subclass of TrailObject that provides additional information needed for most solar system objects...
Definition: ksplanetbase.h:63
ksasteroid.h
SkyGLPainter::setPen
virtual void setPen(const QPen &pen)
Set the pen of the painter.
Definition: skyglpainter.cpp:685
SkyGLPainter::drawObservingList
virtual void drawObservingList(const QList< SkyObject * > &obs)
Draw the symbols for the observing list.
Definition: skyglpainter.cpp:508
kstarsdata.h
DeepSkyObject::e
float e() const
Definition: deepskyobject.cpp:81
KSPlanetBase::image
const QImage & image()
Definition: ksplanetbase.h:123
SkyObject::name
virtual QString name(void) const
Definition: skyobject.h:124
SkyObject::STAR
Definition: skyobject.h:108
SkyObject
Provides all necessary information about an object in the sky: its coordinates, name(s), type, magnitude, and QStringLists of URLs for images and webpages regarding the object.
Definition: skyobject.h:46
SkyGLPainter::drawSatellite
virtual void drawSatellite(Satellite *sat)
Draw a satellite.
Definition: skyglpainter.cpp:699
SkyMap::projector
const Projector * projector() const
Get the current projector.
Definition: skymap.h:264
SkyPainter
Draws things on the sky, without regard to backend.
Definition: skypainter.h:47
SkyGLPainter::begin
virtual void begin()
Begin painting.
Definition: skyglpainter.cpp:645
flagcomponent.h
SkyGLPainter::setBrush
virtual void setBrush(const QBrush &brush)
Set the brush of the painter.
Definition: skyglpainter.cpp:675
SkipList
Definition: SkipList.h:17
QList
LineListLabel::updateLabelCandidates
void updateLabelCandidates(qreal x, qreal y, LineList *lineList, int i)
Definition: linelistlabel.cpp:62
supernovaecomponent.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal