[Kstars-devel] KDE/kdeedu/kstars/kstars
Alexey Khudyakov
alexey.skladnoy at gmail.com
Mon Feb 8 16:34:23 CET 2010
SVN commit 1087143 by khudyakov:
Refactor code for drawing of planet images
* Remove unused KSPlanetBase::rotateImage
* Change KSPlanetBase::scaleRotateImage so that it resize to target
planet diameter not to target image width. They are not the same if
angle isn't zero. Also
* Remove code which accounts for effect mentioned above. Much nicer this
way
* Remove firewalling againist accidental NaNs when determining
image size. At this stage it's better to encounter crash and debug
it than have non-sensical planet size.
CCMAIL: kstars-devel at kde.org
CCBUG: 154650
M +12 -31 skycomponents/solarsystemsinglecomponent.cpp
M +3 -7 skyobjects/ksplanetbase.cpp
M +2 -7 skyobjects/ksplanetbase.h
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/solarsystemsinglecomponent.cpp #1087142:1087143
@@ -118,6 +118,7 @@
float fakeStarSize = ( 10.0 + log10( Options::zoomFactor() ) - log10( MINZOOM ) ) * ( 10 - m_Planet->mag() ) / 10;
if( fakeStarSize > 15.0 )
fakeStarSize = 15.0;
+
float size = m_Planet->angSize() * map->scale() * dms::PI * Options::zoomFactor()/10800.0;
if( size < fakeStarSize && m_Planet->name() != "Sun" && m_Planet->name() != "Moon" ) {
// Draw them as bright stars of appropriate color instead of images
@@ -132,47 +133,27 @@
StarObject::drawStar( psky, spType, o, fakeStarSize);
} else {
//Draw planet image if:
- if( size < sizemin )
+ if ( size < sizemin )
size = sizemin;
- if( Options::showPlanetImages() && //user wants them,
+ if ( Options::showPlanetImages() && //user wants them,
//FIXME: int(Options::zoomFactor()) >= int(zoommin) && //zoomed in enough,
- ! m_Planet->image()->isNull() && //image loaded ok,
- size < Width ) { //and size isn't too big.
+ !m_Planet->image()->isNull() && //image loaded ok,
+ size < Width ) //and size isn't too big.
+ {
+ dms pa = map->findPA( m_Planet, o.x(), o.y() );
- //Image size must be modified to account for possibility that rotated image's
- //size is bigger than original image size. The rotated image is a square
- //superscribed on the original image. The superscribed square is larger than
- //the original square by a factor of (cos(t) + sin(t)) where t is the angle by
- //which the two squares are rotated (in our case, equal to the position angle +
- //the north angle, reduced between 0 and 90 degrees).
- //The proof is left as an exercise to the student :)
- dms pa( map->findPA( m_Planet, o.x(), o.y() ) );
- double spa, cpa;
- pa.SinCos( spa, cpa );
- cpa = fabs(cpa);
- spa = fabs(spa);
- size = size * (cpa + spa);
+ //FIXME: Need to figure out why the size is sometimes NaN.
+ Q_ASSERT( !isnan( size ) && "Core dumps are good for you NaNs");
- //Quick and dirty fix to prevent a crash.
- //FIXME: Need to figure out why the size is sometimes NaN
- if ( isnan( size ) ) {
- size = 10.0;
- }
-
//Because Saturn has rings, we inflate its image size by a factor 2.5
- if ( m_Planet->name() == "Saturn" ) size = int(2.5*size);
+ if( m_Planet->name() == "Saturn" )
+ size = int(2.5*size);
- //FIXME: resize_mult ??
- // if (resize_mult != 1) {
- // size *= resize_mult;
- // }
-
m_Planet->scaleRotateImage( size, pa.Degrees() );
float x1 = o.x() - 0.5*m_Planet->image()->width();
float y1 = o.y() - 0.5*m_Planet->image()->height();
psky.drawImage( QPointF(x1, y1), *( m_Planet->image() ) );
- }
- else { //Otherwise, draw a simple circle.
+ } else { //Otherwise, draw a simple circle.
psky.drawEllipse( QRectF(o.x()-0.5*size, o.y()-0.5*size, size, size) );
}
}
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/ksplanetbase.cpp #1087142:1087143
@@ -284,18 +284,14 @@
return 0.5*size + 4.;
}
-void KSPlanetBase::rotateImage( double imAngle ) {
+void KSPlanetBase::scaleRotateImage( float size, double imAngle ) {
QMatrix m;
m.rotate( imAngle );
+ double scale = size / Image0.width();
+ m.scale( scale, scale );
Image = Image0.transformed( m );
}
-void KSPlanetBase::scaleRotateImage( float size, double imAngle ) {
- QMatrix m;
- m.rotate( imAngle );
- Image = Image0.transformed( m ).scaledToWidth( int(size) );
-}
-
void KSPlanetBase::findPhase() {
/* Compute the phase of the planet in degrees */
double earthSun = KStarsData::Instance()->skyComposite()->earth()->rsun();
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/ksplanetbase.h #1087142:1087143
@@ -236,14 +236,9 @@
/** @return true if the KSPlanet is one of the eight major planets */
bool isMajorPlanet() const;
- /**@short rotate Planet image
- * @param imageAngle the new angle of rotation for the image
- */
- void rotateImage( double imageAngle );
-
/**@short scale and rotate Planet image
- * @param scale the scaling factor
- * @param imageAngle the new angle of rotation for the image
+ * @param scale desired planet diameter in pixels
+ * @param imageAngle angle in degrees to rotate image
*/
void scaleRotateImage( float scale, double imageAngle );
More information about the Kstars-devel
mailing list