Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sun calculator #655

Closed
wants to merge 3 commits into from
Closed

Sun calculator #655

wants to merge 3 commits into from

Conversation

Gustl22
Copy link

@Gustl22 Gustl22 commented Feb 12, 2019

Sun calculator with accuracy of ~1 minute.
Can test actual sun position with: BuildingLayer.getExtrusionRenderer().enableCurrentSunPos(true);

Or to see the whole day cycle use this in MapsforgeTest.createLayers():

BuildingLayer extrusionLayer;
if (s3db) {
    extrusionLayer = new S3DBLayer(mMap, l);
} else
    extrusionLayer = new BuildingLayer(mMap, l);

final ExtrusionRenderer extrusionRenderer = extrusionLayer.getExtrusionRenderer();

mMap.layers().add(extrusionLayer);

extrusionRenderer.enableCurrentSunPos(false);
mMap.events.bind(new Map.UpdateListener() {
    @Override
    public void onMapEvent(Event e, MapPosition mapPosition) {
        long t = System.currentTimeMillis();
        float progress = (((t % 2000) / 1000f));

        extrusionRenderer.getSun().setProgress(progress);
        extrusionRenderer.getSun().updatePosition();
        extrusionRenderer.getSun().updateColor(); // only relevant for shadow implementation

        mMap.updateMap(true);
    }
});

See #575.


public ExtrusionRenderer(boolean mesh, boolean translucent) {
mMesh = mesh;
mTranslucent = translucent;

mSun = new Sun();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick comment: since the feature is optional, better have a lazy initialization of any feature objects, specially if they carry collections.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean lazy init the sun, or the collection?
Probably can achieve lazy init collection when calling updateColor() the first time.
Yes it's a feature, but fully customizable. Storing in another attribute next to the sun would be confusing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Sun class.
Can use getSun everywhere and if null at first call, just create it there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we have to specify light position in any case?

Copy link
Collaborator

@devemux86 devemux86 Feb 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't shadows optional?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All parameters in sun are optional. So why make an option of an option, which in fact gives the same results and only makes it more complicated.

Yes this whole construct is needed for shadows, too. But also gives new options for extrusion renderer only.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think storing 5 values more has impact on performance or memory. It's a more physical based way to specify lights position.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wait to be reviewed then. Most concern is with users who simply don't care for light or shadows and want to continue with same fast rendering without new possible GL issues.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any regression here. If somebody don't care for new features, can stay on tested versions.

@devemux86
Copy link
Collaborator

I don't see any regression here.

Regressions can be seen with extensive testing. 🙂

If somebody don't care for new features, can stay on tested versions.

That cannot be an answer to users: if don't need a feature, use previous lib version.
Proper answer is: can enable the new optional feature, if need via the XYZ method.

@Gustl22
Copy link
Author

Gustl22 commented Feb 13, 2019

Regressions can be seen with extensive testing.

Of course, there always can be an issue. But in this case the position parameter only moved to Sun and will not change after initialization by default.

Proper answer is: can enable the new optional feature, if need via the XYZ method.

You're right, but not all implementations can be optional, only if they offer a different and reasonable result. And I added a bunch of methods to make it all customizable. So e.g. can set the position simply via setPosition.

BTW: I removed one TODO...already working.

@devemux86 devemux86 added this to the 0.11.0 milestone Feb 19, 2019
devemux86 pushed a commit that referenced this pull request Feb 19, 2019
@devemux86
Copy link
Collaborator

Thanks, merged via eb3efa7.

@devemux86 devemux86 closed this Feb 19, 2019
devemux86 added a commit that referenced this pull request Feb 19, 2019
@devemux86
Copy link
Collaborator

I also added the above test in MapsforgeTest.

@Gustl22
Copy link
Author

Gustl22 commented Feb 19, 2019

Nice thanks!

@Gustl22 Gustl22 deleted the sun branch February 19, 2019 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants