Code Monkey home page Code Monkey logo

unity-planetarium's Introduction

Unity Planetarium

Demo 01

C# / Unity class for an accurate (~ -1°/+1°) generation of our universe (stars, planets, moon and the sun) depending on a given location (lat/long) and time.

The main script is CelestialCoordinates.cs - you can use it in your own project.

The script CelestialManager.cs is an example on how you can use the above script to generate a skymap corresponding to your location and time.

Note that we calculate the position of every objects from a given location on Earth, therefore planets will rotate around the Earth and not from the Sun.

Demo 02

How it works

The class returns the horizontal coordinates (azimuth + altitude), in degrees, of a celestial object, by taking into account the given location and the current time.

For planets (Moon and Sun included), the methods return a Vector3 where x = altitude (in °), y = azimuth (in °) and z = distance (in AU) from Earth to the celestial object. For stars, it returns a Vector2 with altitude and azimuth; the distance should be provided by the database you are using (i.e.: HYG)

For the stars, you will need its right ascension (RA) and declination (DEC). The HYG database contains the RA and DEC of almost 120'000 stars.

The latitude will be positive in North / negative in South. The longitude will be positive in East and negative in West.

Assuming that you want to get the coordinates of a celestial object above Beijing (Lat: 39.9 / Long: 116.4), for the current time:

// Get coordinates of the Moon when located in Beijing
// moon.x = altitude, moon.y = azimuth, moon.z = distance (in AU) from Earth to the Moon
Vector3 moon = CelestialCoordinates.CalculateHorizontalCoordinatesMoon(116.4f, 39.9f, DateTime.UtcNow);

// Get coordinates of Neptune when located in Beijing
Vector3 neptune = CelestialCoordinates.CalculateHorizontalCoordinatesPlanets(116.4f, 39.9f, Planet.NEPTUNE, DateTime.UtcNow);

//Get coordinates of Polaris (RA = 2.52975 / DEC = 89.264109) when located in Beijing
Vector2 polaris = CelestialCoordinates.CalculateHorizontalCoordinatesStar(116.4f, 39.9f, 2.52975f, 89.264109f, DateTime.UtcNow);

From Altitude/Azimuth to Unity World Space

To convert your altitude and azimuth to your Unity world space, do the following:

Vector3 moon = CelestialCoordinates.CalculateHorizontalCoordinatesMoon(116.4f, 39.9f, DateTime.UtcNow);

Vector3 position = Quaternion.Euler(-moon.x, moon.y, 0) * new Vector3(0, 0, moon.z);
moonGO.transform.position = position;

You can also refer to the provided example script CelestialManager.cs for more information on how to use the results provided by CelestialCoordinates.


MIT License

Copyright (c) 2020 Matthieu Cherubini

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

unity-planetarium's People

Contributors

mchrbn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

unity-planetarium's Issues

64 Errors Occur

Hai there,
Thanks for the project, however, 64 errors appear, which can be divided into three kinds.
1.Rebuilding Library because the metadata folder could not be found!
2.meta confilcts, such as :
GUID [d3b47ff860a51904395688d633cb1018] for asset 'Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Templates/BuildSurfaceDescriptionInputs.template.hlsl.meta' conflicts with:
'Packages/com.unity.shadergraph/Editor/Generation/Templates/BuildSurfaceDescriptionInputs.template.hlsl.meta'
3.type or namespace name can't be found, such as:
Library\PackageCache\[email protected]\Editor\ShaderGraph\SubShaders\UniversalPBRSubShader.cs(9,7): error CS0246: The type or namespace name 'Data' could not be found (are you missing a using directive or an assembly reference?)

image
image

Hope to get your reply.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.