Commit f3cbe01c authored by Artem Fedoskin's avatar Artem Fedoskin

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.
parent 0a1a6b9a
......@@ -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);
}
......@@ -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;
......
......@@ -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);
......
......@@ -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:
......
......@@ -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();
......
......@@ -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:
......
......@@ -60,6 +60,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
......
......@@ -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;
}
......@@ -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:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment