summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Fedoskin <afedoskin3@gmail.com>2016-05-18 10:07:14 (GMT)
committerArtem Fedoskin <afedoskin3@gmail.com>2016-05-18 10:07:14 (GMT)
commitf3cbe01c7593f02609945694d1d37aa74fe79548 (patch)
tree830af8b91049a9142add47e8b2b170b319c195b5
parent0a1a6b9a8b98ad08b42da2feed6ff1aad9c0bcc5 (diff)
Added rotation to planet images. SkyNodes now changes their position
using matrix in QSGTransformnode rather than setting new rect with changed coordinates to their child nodes.
-rw-r--r--kstars/kstarslite/skyitems/nodes/planetnode.cpp46
-rw-r--r--kstars/kstarslite/skyitems/nodes/planetnode.h3
-rw-r--r--kstars/kstarslite/skyitems/nodes/pointnode.cpp6
-rw-r--r--kstars/kstarslite/skyitems/nodes/pointnode.h8
-rw-r--r--kstars/kstarslite/skyitems/nodes/pointsourcenode.cpp14
-rw-r--r--kstars/kstarslite/skyitems/nodes/pointsourcenode.h6
-rw-r--r--kstars/kstarslite/skyitems/nodes/skynode.h6
-rw-r--r--kstars/kstarslite/skyitems/planetsitem.cpp13
-rw-r--r--kstars/kstarslite/skyitems/planetsitem.h6
9 files changed, 71 insertions, 37 deletions
diff --git a/kstars/kstarslite/skyitems/nodes/planetnode.cpp b/kstars/kstarslite/skyitems/nodes/planetnode.cpp
index c44d38b..66fc47f 100644
--- a/kstars/kstarslite/skyitems/nodes/planetnode.cpp
+++ b/kstars/kstarslite/skyitems/nodes/planetnode.cpp
@@ -54,15 +54,16 @@ void PlanetNode::update() {
// pNode->hide(); //TODO
} else {
KSPlanetBase * planet = static_cast<KSPlanetBase *>(m_skyObject);
+ const Projector * proj = projector();
- if( !projector()->checkVisibility(planet) ) {
+ if( !proj->checkVisibility(planet) ) {
hide();
return;
}
bool visible = false;
- QPointF pos = projector()->toScreen(planet,true,&visible);
- if( !visible || !projector()->onScreen(pos) ) {
+ QPointF pos = proj->toScreen(planet,true,&visible);
+ if( !visible || !proj->onScreen(pos) ) {
hide();
return;
}
@@ -83,8 +84,8 @@ void PlanetNode::update() {
float size = planet->angSize() * dms::PI * Options::zoomFactor()/10800.0;
if( size < sizemin )
size = sizemin;
-
- if( Options::showPlanetImages() && !planet->image().isNull() ) {
+ //Options::showPlanetImages() &&
+ if( !planet->image().isNull() ) {
//Because Saturn has rings, we inflate its image size by a factor 2.5
if( planet->name() == "Saturn" )
size = int(2.5*size);
@@ -92,12 +93,6 @@ void PlanetNode::update() {
else if (planet->name() == "Pluto")
size = int(size*exp(1.5*size));
- /*save();
- translate(pos);
- rotate( projector()->findPA( planet, pos.x(), pos.y() ) );
- drawImage( QRect(-0.5*size, -0.5*size, size, size),
- planet->image() );
- restore();*/
setPlanetPicSize(size);
changePos(pos);
showPlanetPic();
@@ -138,21 +133,28 @@ void PlanetNode::hide() {
m_planetOpacity->setOpacity(0);
m_planetOpacity->markDirty(QSGNode::DirtyOpacity);
}
- if(m_point->opacity()) {
- m_point->setOpacity(0);
- m_point->markDirty(QSGNode::DirtyOpacity);
- }
+ m_point->hide();
}
void PlanetNode::changePos(QPointF pos) {
- //TODO: port it to transform matrix
- /*QMatrix4x4 m (1,0,0,pos.x(),
+ QSizeF size;
+ QMatrix4x4 m (1,0,0,pos.x(),
0,1,0,pos.y(),
- 0,0,0,1,
+ 0,0,1,0,
0,0,0,1);
- setMatrix(m);
- markDirty(QSGNode::DirtyMatrix);*/
- m_planetPic->setRect(QRect(pos.x(),pos.y(),m_planetPic->rect().size().width(),m_planetPic->rect().size().width()));
- m_point->changePos(pos);
+ if(m_planetOpacity->opacity()) {
+ size = m_planetPic->rect().size();
+ //Matrix has to be rotated between assigning x and y and translating it by the half
+ //of size of the planet. Otherwise the image will don't rotate at all or rotate around
+ //the top-left corner
+ m.rotate(projector()->findPA( m_skyObject, pos.x(), pos.y()), 0, 0, 1);
+ } else {
+ size = m_point->size();
+ }
+
+ m.translate(-0.5*size.width(), -0.5*size.height());
+
+ setMatrix(m);
+ markDirty(QSGNode::DirtyMatrix);
}
diff --git a/kstars/kstarslite/skyitems/nodes/planetnode.h b/kstars/kstarslite/skyitems/nodes/planetnode.h
index c59fb6c..de9b7b2 100644
--- a/kstars/kstarslite/skyitems/nodes/planetnode.h
+++ b/kstars/kstarslite/skyitems/nodes/planetnode.h
@@ -24,6 +24,7 @@ class QImage;
class KSPlanetBase;
class RootNode;
+
/** @class PlanetNode
*
* A SkyNode derived class used as a container for holding two other nodes: PointNode
@@ -66,7 +67,7 @@ public:
* @short changePos changes the position m_point and m_planetPic
* @param pos new position
*/
- void changePos(QPointF pos);
+ virtual void changePos(QPointF pos) override;
virtual void update() override;
virtual void hide() override;
diff --git a/kstars/kstarslite/skyitems/nodes/pointnode.cpp b/kstars/kstarslite/skyitems/nodes/pointnode.cpp
index 583c0ac..24ae9a8 100644
--- a/kstars/kstarslite/skyitems/nodes/pointnode.cpp
+++ b/kstars/kstarslite/skyitems/nodes/pointnode.cpp
@@ -30,17 +30,13 @@ PointNode::PointNode(RootNode* p, char sp, float size)
void PointNode::setSize(float size) {
int isize = qMin(static_cast<int>(size), 14);
texture->setTexture(parentNode->getCachedTexture(isize, spType));
+ //markDirty(QSGNode::DirtyMaterial);
QSize tSize = texture->texture()->textureSize();
QRectF oldRect = texture->rect();
texture->setRect(QRect(oldRect.x(),oldRect.y(),tSize.width(),tSize.height()));
}
-void PointNode::changePos(QPointF pos) { //TODO move it to SkyNodes
- QRectF oldRect = texture->rect();
- texture->setRect(QRect(pos.x(),pos.y(),oldRect.width(),oldRect.height()));
-}
-
void PointNode::show() {
if(!opacity()) {
setOpacity(1);
diff --git a/kstars/kstarslite/skyitems/nodes/pointnode.h b/kstars/kstarslite/skyitems/nodes/pointnode.h
index a4b664e..d2f3f80 100644
--- a/kstars/kstarslite/skyitems/nodes/pointnode.h
+++ b/kstars/kstarslite/skyitems/nodes/pointnode.h
@@ -46,11 +46,9 @@ public:
* @param size new size of PointNode
*/
void setSize(float size);
- /**
- * @short changePos changes position of PointNode to the one specified by pos
- * @param pos new position
- */
- void changePos(QPointF pos);
+
+ inline QSizeF size() const { return texture->rect().size(); }
+
void show();
void hide();
private:
diff --git a/kstars/kstarslite/skyitems/nodes/pointsourcenode.cpp b/kstars/kstarslite/skyitems/nodes/pointsourcenode.cpp
index 38bb8ed..69a70cf 100644
--- a/kstars/kstarslite/skyitems/nodes/pointsourcenode.cpp
+++ b/kstars/kstarslite/skyitems/nodes/pointsourcenode.cpp
@@ -48,6 +48,18 @@ float PointSourceNode::starWidth(float mag) const
return size;
}
+void PointSourceNode::changePos(QPointF pos) {
+ QSizeF size = m_point->size();
+ QMatrix4x4 m (1,0,0,pos.x(),
+ 0,1,0,pos.y(),
+ 0,0,1,0,
+ 0,0,0,1);
+ m.translate(-0.5*size.width(), -0.5*size.height());
+
+ setMatrix(m);
+ markDirty(QSGNode::DirtyMatrix);
+}
+
void PointSourceNode::update() {
if( !projector()->checkVisibility(m_skyObject) ) {
m_point->hide();
@@ -58,7 +70,7 @@ void PointSourceNode::update() {
QPointF pos = projector()->toScreen(m_skyObject,true,&visible);
if( visible && projector()->onScreen(pos) ) { // FIXME: onScreen here should use canvas size rather than SkyMap size, especially while printing in portrait mode!
m_point->setSize(starWidth(m_skyObject->mag()));
- m_point->changePos(pos);
+ changePos(pos);
m_point->show();
} else {
m_point->hide();
diff --git a/kstars/kstarslite/skyitems/nodes/pointsourcenode.h b/kstars/kstarslite/skyitems/nodes/pointsourcenode.h
index 20ab05b..cc3d907 100644
--- a/kstars/kstarslite/skyitems/nodes/pointsourcenode.h
+++ b/kstars/kstarslite/skyitems/nodes/pointsourcenode.h
@@ -47,6 +47,12 @@ public:
/** @short Get the width of a star of magnitude mag */
float starWidth(float mag) const;
+ /**
+ * @short changePos changes the position m_point
+ * @param pos new position
+ */
+ virtual void changePos(QPointF pos) override;
+
virtual void update() override;
virtual void hide() override;
private:
diff --git a/kstars/kstarslite/skyitems/nodes/skynode.h b/kstars/kstarslite/skyitems/nodes/skynode.h
index 2fd58d3..90e6147 100644
--- a/kstars/kstarslite/skyitems/nodes/skynode.h
+++ b/kstars/kstarslite/skyitems/nodes/skynode.h
@@ -61,6 +61,12 @@ public:
virtual void hide() =0;
/**
+ * @short changePos changes the position of SkyNode on SkyMapLite
+ * @param pos new position
+ */
+ virtual void changePos(QPointF pos) =0;
+
+ /**
* @short returns SkyObject associated with this SkyNode
* @return pointer to the object of type SkyObject
*/
diff --git a/kstars/kstarslite/skyitems/planetsitem.cpp b/kstars/kstarslite/skyitems/planetsitem.cpp
index f6fa094..b46cfde 100644
--- a/kstars/kstarslite/skyitems/planetsitem.cpp
+++ b/kstars/kstarslite/skyitems/planetsitem.cpp
@@ -35,6 +35,13 @@ void PlanetsItem::addPlanet(SolarSystemSingleComponent* planetComp) {
m_toAdd.append(planetComp);
}
+SolarSystemSingleComponent * PlanetsItem::getParentComponent(SkyObject * planet) {
+ foreach(SolarSystemSingleComponent * planetComp, m_planetComponents) {
+ if(planetComp->planet() == planet) return planetComp;
+ }
+ return nullptr;
+}
+
QSGNode* PlanetsItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) {
RootNode *n = static_cast<RootNode*>(oldNode);
Q_UNUSED(updatePaintNodeData);
@@ -67,10 +74,12 @@ QSGNode* PlanetsItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *upd
}
//Update clipping geometry. If m_clipPoly in SkyMapLite wasn't changed, geometry is not updated
n->updateClipPoly();
- //Traverse all children nodes of PlanetRootNode
+ //Traverse all children nodes of RootNode
for(int i = 0; i < n->skyNodesCount(); ++i) {
PlanetNode* pNode = static_cast<PlanetNode*>(n->skyNodeAtIndex(i));
- pNode->update();
+ bool selected = getParentComponent(pNode->getSkyObject())->selected();
+ if(selected) pNode->update();
+ else pNode->hide();
}
return n;
}
diff --git a/kstars/kstarslite/skyitems/planetsitem.h b/kstars/kstarslite/skyitems/planetsitem.h
index 89a8b7f..562d6f0 100644
--- a/kstars/kstarslite/skyitems/planetsitem.h
+++ b/kstars/kstarslite/skyitems/planetsitem.h
@@ -19,6 +19,7 @@
#include "skyitem.h"
class SolarSystemSingleComponent;
+class SkyObject;
class PlanetsItem : public SkyItem {
@@ -32,8 +33,11 @@ public:
*
* @param SolarSystemSingleComponent that should be displayed on SkyMapLite
*/
- //TODO change it to KSPlanetBase
+
void addPlanet(SolarSystemSingleComponent* planetComp);
+
+ SolarSystemSingleComponent * getParentComponent(SkyObject * planet);
+
protected:
virtual QSGNode* updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) override;
private: