Sunday, April 29, 2012

1. Background info: Origins, Tails, Chemistry

So I did some reading about comets, some example comets, bow shock, comet nuclei and the tails. Below, I relate that info to the appearance of comets.

2 posts coming up: (1) Orbits and Mathematics (for orbit, brightness, tails); (2) Design considerations


The dust tail (yellow, reflecting sunlight) and the ion tail (blue, fluorescence).

In the beginning, the Solar System was just dust and water rotating about the Sun. Dust clumped together, water clumped together, and planets were formed. The closest-to-the-Sun planets are largely made out of rock because the heat of the Sun didn't let ice stay around, while the rest of the planets are giant bodies of gas and ice. Comets are the latter planets' left overs. They're known as dirty snowballs because they're largely made of ice, carbon monoxide, and other gases like argon, ammonia, and such. This is contained in a dark crust of complex organic compounds, which absorbs light. Comet nuclei are actually some of the darkest observable material. We don't easily observe this because when the Sun isn't close enough to light up the comet, the nucleus is too small. When the Sun is, the nucleus will be obscured by a large coma. There is an even larger cloud of hydrogen, but this is not visible to the human eye.

There are thousands of comets hypothesized to exist in Oort's Cloud in the outer solar system and the Kuiper Belt, which rotate Oort's Cloud accounts for long period comets (> 200 years) and the comets can stay there, undetected, and remain stable far from the Sun. Kupier's Belt is nearer and accounts for short period comets (<= 200). The comets lay dormant in the cloud, but due the gravitational pull from the planets, its orbit became highly eccentric- an elongated ellipse.Trom the highly eccentric orbits of the comets, astronomers have extrapolated their existence. Jupiter and other massive bodies gravitational perturb the comets, comets collide with comets, and so, in this way, comets leave the Cloud or Belt.

As the comets near the Sun, they receive enough heat energy (especially with their dark crusts) to start outgassing. In other words, the frozen H20 and gases sublime from solid to gas, not via water since Space is a vacuum, and spew out of the comet. Sunlight and the photoelectric effect ionizes water molecules into Hydrogen ions and Oxygen ions. Meanwhile, a great deal of solar wind is coming at the comet. Solar winds are ionized particles from the Sun moving at such high speeds that they escape Sun's gravity. Since the comet is traveling at supersonic speeds relative to the solar wind, a bow shock is formed. In other words, the high solar wind speed dips drastically and ions from the Sun accumulate because they arrive faster at the bow shock than they can leave. A magnetic field (magnetosphere) flows around the comet like a stream around a rock, and the ionized plasma from the comet will form the ion tail. This ion tail is long and narrow, and will point directly away from the Sun because of the magnetic effect. The ion tail is actually made of plasma, and is blue because of CO+.

There was dust, mainly silicate, mixed into the gas and water, and they also spew out of the comet. This forms the coma, which can hide the nucleus. Radiation pressure bounces sunlight off the dust particles, creating the dust tail. It reflects a lot of light, making it shiny therefore observable. The dust tail doesn't directly extend away from the Sun like the ion tail, but curves. This is because the nucleus rotates, and so sunlight doesn't hit the nucleus uniformly: indirect sunlight, less outgassing; direct sunlight, more outgassing. Thus the tail curves along the trajectory. Depending on the nucleus' rotation, the comet can either be propelled or repelled, affecting its orbital radius. That's why Comet Encke's period decreases.

There can be other hard-to-detect tails, such as the faint 50Mkm long Sodium (Na) tail of Hale-Bopp's. Sometimes, a comet will have multiple ion tails (Comet Donati), or when it breaks apart it can have a fan of tails (Comet West).

All this material-spewing occurs at "vents", or puncture points in the comet's crust that cracked under the pressure of the volatile material wanting to get out. We prove the existence of vents by studying the tail. In Hale-Bopp, the moving tail showed that the comet was rotating because depending on which side was facing the Sun, the volatile materials would spew out from the vents on that side.

Now, for the composition of the comets. It was once hypothesized that Earth's water comes from comet collisions, since it was suspected that the Deuterium (isotope of H) to Hydrogen was the same in both bodies. Comets also reveal a lot about the Early Universe. The above theory, however, is dubious because it was later confirmed via samples that the ratio is different. A comet's chemistry can affect their color (the gas may fluorescence under UV rays). For example, yellow Sodium tails and Argon fluorescence. The main thing is that Comets is made of (1) crust: complex organic compounds, silicates (metal like Iron and Sodium, silicon to form rock); (2) volatiles: H20, CO mainly, then Na, CO2, OH, NH4, HCN, CH4, H2S, Ar, etc.

Friday, April 27, 2012

Building Stellarium for Mac, and running on Qt

Follow these instructions first. If they work out, good:)
Else:
- Install macports
- sudo port selfupdate to sync
- If selfupdate fails due to rsync, then find port’s dir and change source.conf like this. If permissions denied (e.g. buffer is read-only) then type “sudo emacs source.conf” and this will give you control
- Use macports to install gettext and bzr
- bzr launchpad-login <username>
- Continue to follow instructions
- If cmake fails because QMAKE not found, search for CMakeCache.txt, find ‘Qt’ and replace FILE_PATH_NOT_FOUND. Change FILEPATH to e.g. /Users/<your_mac_username>/QtSDK/Desktop/Qt/4.8.1/gcc/bin/qmake
- Then run cmake ../.. again
- Run make
- Run make install
- Run make macosx_bundle
- if macosx_bundle fails, go to CMakeFiles, emacs Makefile2
Delete line 136 after the colon
- Run macosx_bundle again

If you have any patches that need to be added, just run “bzr pull”



=== Qt ===
Use "bzr branch" and "bzr init-repo" to create your branches and shared repository. The directories that you create will be what's used for "Development/StelRepo/branches/testA" below, which is just an example; name it whatever you like.


Then: Follow these instructions

Except for
D:\stellarium\trunk\builds\msys
should just be the same folder as your branch
<address_until>/<branch_name> // Concrete example below

To RUN a new branch, must change Run Settings.
Under Projects (on the left panel), go to Run Settings:
working directory: /Users/<your_mac_username>/Development/StelRepo/branches/testA/src
change to: /Users/<your_mac_username>/Development/StelRepo/branches/testA/

Monday, April 16, 2012

Files that are directly relevant to Comet

StelApp (hpp) (cpp)

Has the recognizable OpenGL init(), draw(), resize() functions. Gets pointers to all the main Mgr classes which manage the functions such as Sky Culture. The Comet class will be managed the StelModuleMgr.

Initializes the StelObjectMgr, then the SolarSystemMgr, then all the more specific managers like Stars, Milky Way and Nebula.

Here, in StelApp::init(), I would put:

// init comet manager
CometMgr* comets = new CometMgr();
comets->init();
getModuleMgr.registerModule(comets);

In StelApp::update(), each module is updated, and CometMgr needs its own update() function that changes due to delta time. Similarly, each module needs its own mouse click, etc., handling in moduleMgr->getCallOrders(*action*). moduleMgr is StelApp's StelModuleMgr pointer and getModuleMgr() returns this pointer. The use of either seems arbitrary in StelApp.cpp.

StelMainGraphicsView

Sets up the window and background and loads the display buffers. Depth buffer is for determining which objects should be drawn, so that time is not wasted drawing objects behind objects. Double buffer is so that we don't have poor graphics during animation- there is a buffer for display, and a buffer to draw to. After a buffer is drawn to, it is swapped. This way, the viewer sees a continuously animated picture that doesn't look half drawn as it would be if there was only a single buffer to draw and display to.

Also receives window resizing and keyboard/ mouse events. StelApps does the actual handling privately.

I have to make sure that the Comet class doesn't have too expensive an O(n) that the display buffer will not be drawn to in time.

StelCore


Oversees the display in Stellarium w.r.t. time using the MovementMgr and SkyDrawerMgr. The modules refer to StelCore for all kinds of astronomical coordinate systems and timing (e.g. Julian time, time speed).

StelMovementMgr (hpp) (cpp)

Handles movement (e.g. zooming, selecting, panning left and right) of the mouse, etc. Tracks selected object by flagging it. Has virtual draw() and update() functions <=-- handled by modules?

StelSkyDrawer (hpp) (cpp)


Like MovementMgr, SkyDrawer  provides a unified way for objects to draw themselves with respect to the viewer. Here is where the star's textures are loaded. Since that's currently how comets are displayed, as suns, but we don't want that, the comet texture needs to be loaded here too.

So in the .hpp file we need to add comet's shader:
QGLShaderProgram* cometsShaderProgram;

In the .cpp file:
StelSkyDrawer::init() - load texture images
texDustTail = StelApp::getInstance().getTextureManager().createTexture("textures/comets/dustTail.png");
texIonTail = StelApp::getInstance().getTextureManager().createTexture("textures/comets/ionTail.png");
texNucleus = StelApp::getInstance().getTextureManager().createTexture("textures/comets/nucleus.png");
texComet = StelApp::getInstance().getTextureManager().createTexture("textures/comets/comet.png");

StelSkyDrawer::update() - Re-scale comet's display size

StelSkyDrawer::DrawPointSource() - Store comet's drawing positions and vertex arrays

StelSkyDrawer::postDrawPointSource() - bulk of comet drawing/ shading
Attribute vertex, color and texture to comet

Remember to bind texture (for openGL texture binding). E.g. texComet->bind(). bind() is a function in the StelTexture class.

StelUtils


Provides general functions like converting coordinates and time, and computing exp and acos(x)

StelVertexArray


For openGL compatible vertex arrays. Vertex arrays are used, for example, to conveniently make a polygon and assign it colors, etc., without individually creating a point then assigning a color to it.

VecMath


For openGL compatible vectors. E.g. 3 floats, a (4x4)-matrix, etc.

StelObject


StelObject will be the Abstract Base Class for Comet. We can polymorphically refer to the Comet with StelObjectP (StelObject*). Holds data general to all sky objects. So, for the Comet class, I'll have to find all the corresponding information.

Virtual StelObject::getCloseViewFov(). For when the viewer zooms in on a Comet, we have to define it in some way so that the viewer can see the Comet in better detail E.g. easier to see the nucleus and the actual non-spherical body of the comet.

SolarSystem


Comet/ Minor Planets derived from this class. Their .hpp files are included in this .cpp file.

In SolarSystem::loadPlanets(), the eccentricity, semi-major axis and other orbital information is loaded. Comet orbits are very flat ellipses. There is a special branch for comets in line 495 that calculates the orbit specifically. loadPlanet() gets all the data from a file for all kinds of planets, including asteroids and comets.

Because we have to add tails and perhaps other features, the code here will be more than just getting its orbit.

Includes Orbit class, which has a special derived class for comets which contains more variables, and does calculations already.

Planet


Current Comet is directly derived from this, and Planets do indeed share some features, but if we're to get photorealistic features, Comet doesn't have an exact radius when zoomed into because comet bodies are not spherical. The current Comet code doesn't capture information about tails or a nucleus either. To keep comet under the SolarSystem class, however, Comet needs to remain a "Planet".

StelPainter (hpp) (cpp)

Provides functions for openGL drawing, so the bulk of the openGL-type implementations are here. It is probably the most important class to use after Comet.

Color and Light

Chapters 4 and 5 of the Red Book.

RGB v. Color Indexing

In OpenGL, you can specify either RGB or Color Index modes. RGB is more suitable than color mapping for Stellarium because we want to generate colors that are smoothed out, and just picking a range of indexes might get wildly different colors that so happened to be beside each other on the color map. Meanwhile, in RGB changing the individual R, G, B components vary the color in an unsurprising way.

Lighting

Each component is separately considered, then summed together.

Ambient - light from no particular direction, heavily scattered
Diffuse - light from 1 direction, heavily scattered
Specular - light from 1 direction, reflected in 1 direction (shininess)
Emissive - light from the object

Saturday, April 14, 2012

Basic transformations for OpenGL

On to Chapter 3 Viewing of the Red Book. Matrices and Transformations determine how an object is shown on screen. To manipulate the different matrices, we first have to set the kind of matrix (texture, projection or modelview=default) with glMatrixMode(). And all transformations after that will apply to that particular matrix. Before every group of transformations, we have to initialize the matrix with glLoadIdentity() so that we work with a whole new matrix, not the previous matrix created.

Modelview

To rasterize 3-dimensional objects to the 2-d screen, the following kinds of matrixes are applied in this order:
(1) Viewing transformations
(2) Modeling transformations

Why this order? Transformations are applied to an object as functions, so if we let viewing matrix V be viewFn, modeling matrix M be modFn, and object be O, then the code will look like this:

viewFn();
modFn();
O;

In matrix form, it will look like this:
T(x) = VMx

This makes sense because we want to rotate an object, then look at it. The above matrices will make up the ModelView matrix.

Projection

The 3-D models are projected onto a screen. The projection can be:
(1) Perspective - Since further objects will seem smaller than nearer objects, we want to reflect this. One easy way to think about this is like a frustum, which has a larger base than the other side. The larger base is closer to us. We can transform the initial perspective matrix with glFrustum(). 
(2) Orthographic - The object is flattened directly onto the screen, regardless of the angle or distance that a viewer might see it in real life.

===

After drawing something, we can use gluLookAt() to see the scene from another angle. This is useful for when something looks correct from the front, but when seen at an elevated angle, is actually out of shape.

===

Matrix Stack

When creating multiple models that are related to each other, it would be useful to transform from one point at model_1 to make a model_2, then go back to the origin, and transform somewhere else to make another model_2. Thus, the two model_2s are created relative to model_1. This process of doing transform_1, undo, transform_2, undo, transform_3, undo can be contained LIFO-style, which is what a stack does.

Modelview stacks can contain 32 matrices, while Perspective stacks can hold 2 matrices.

===

Planet System tutorial

Demonstrated modelview and perspective transformations, matrix stacks and keyboard control.









Hello World with OpenGL and GLUT

So I followed the spin shape function (somewhat modified) from the OpenGL Programming Guide, a.k.a. the Red Book, and followed Chapters 1 and 2.

What it does is spin a square slowly. The original Red Book version spun really fast. And since I'm using a MacBook Pro, which only has a trackpad, the spinning pauses on Right-Click instead of Middle-Click.



Then, I modified the program to spin a 5-vertex polygon instead:



While the rest more or less follows the guide, here's the code that adds a vertex, reduces spin speed and changes button used:

About

<old> About the OpenGL-related posts: I won't go into details already covered by the Red Book, so the material here may not seem as comprehensive. I just uploaded stuff that I did while reading the Red Book and things that seemed especially pertinent. For complete coverage of the fundamentals and more advanced explanations, I'll go to Google or Red Book. </old>

UPDATE

This blog is now a project blog. Somehow, my proposal was accepted... It's my first time making something real, and I hope to complete what I set out to do. I'm excited about learning from my mentor and the Stellarium community, and contributing to open source.