Virtual Reality of the Milky Way
Hi! I’m Debjani, a rising junior at The Brearley School, and my main project was to create a virtual reality (VR) experience of the Milky Way Galaxy using Unity3D and Google Cardboard. I also created a physical controller so that a user could navigate through the VR using a 5-way button.
Engineer
Debjani D.
Area of Interest
Aerospace Engineering/ Computer Science
School
Brearley School
Grade
Rising Junior
Reflection
I learned how to use all my resources so that I could solve my issue as quickly as possible— that meant posting on three different forums, asking my peers and instructors for advice, and sometimes, just thinking out loud or with pen and paper. In the end, I decided that the realm of hardware wasn’t for me, but I’m glad that I tried it out; I certainly enjoyed pushing my own boundaries and seeing how much I could accomplish these three weeks.
Final Milestone
Challenges:
- Incorrect wiring
- Solution: Understanding how pull-up resistors work and adding them to the circuit
- Panning worked on Unity editor but not on phone
- Solution: Moving the objects in the scene instead of the player (player settings were overriding my own code)
- Solution: Understanding how pull-up resistors work and adding them to the circuit
- Solution: Moving the objects in the scene instead of the player (player settings were overriding my own code)
Next Steps:
- 3D print a case for the controller to improve user experience!
//this is the code that runs on the ESP8266
//associating the directions to the input pins
int upPin = 2; //d4
int leftPin = 4; //d2
int centerPin = 5; //d1
int rightPin = 14; //d5
int downPin = 0; //d3
// Replace with network credentials
const char* ssid = "***";
const char* password = "***";
// Set web server port number to 80
ESP8266WebServer server( 80 );
void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
server.on("/", button);
server.begin();
Serial.println("HTTP server started");
}
void loop(void)
{
server.handleClient();
button();
}
void button()
{
if (digitalRead(rightPin) == LOW)
{
server.send(200, "text/html", "<html>\
<head>\
<meta http-equiv='refresh' content='1'/>\
<title>ESP8266 Demo</title>\
<style>\
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
</style>\
</head>\
<body>\
<p>*R^</p>\
</body>\
</html>");
}
//and likewise for the other four directions
}
//this is the code that Unity runs
private string textFromWWW;
private string url = "<INSERT IP ADDRESS>";
//this retrieves the direction printed onto the webpage by the ESP...
IEnumerator GetTextFromWWW()
{
WWW www = new WWW(url);
yield return www;
if (www.error != null)
{
Debug.Log("Ooops, something went wrong...");
Debug.Log(www.error);
}
else
{
//...and stores the string into a variable
textFromWWW = www.text;
Debug.Log(textFromWWW);
}
}
void Update(){
try{
//this converts the text found on the webpage into
//a single letter string that we can read
string stringText = Convert.ToString(textFromWWW);
string substring = stringText.Split('^')[0];
int index = ((substring.Length) - 1);
string reading = Convert.ToString(substring[index]);
//this runs the motion function depending on the direction
while (up && reading.Equals("U")){
movein();
up = false;
}
//and likewise for the other four directions
}
}
Second Milestone
// Update is called once per frame
void Update()
{
OrbitAround();
}
void OrbitAround()
{
foreach (GameObject key in planetList) //planetList contains the name of each plotted planet
{
int index = planetList.IndexOf(key);
var targetCoord = starList[index];//starList contains the coordinates of each plotted star
Debug.Log("PLANET:" + key);
Debug.Log("TARGETCOORD:" + targetCoord);
key.transform.RotateAround(targetCoord, Vector3.up, speed * Time.deltaTime);
//turns out that this last line contained the error!
//instead of "key.transform.RotateAround()"...
//I had written "transform.RotateAround()"...
//so Unity didn't know what should orbit!
}
}
//see the GIF (right) to see this code in action!
Challenges:
- Getting the planets to rotate around the correct stars
- The planets were rotating, but their center was not the appropriate star
- Solution: Fixing the very last line of the code shown below– turns out that the error was omitting the word “key”!
- The planets were rotating, but their center was not the appropriate star
- Solution: Fixing the very last line of the code shown below– turns out that the error was omitting the word “key”!
Next Steps:
- Build the physical controller and get the controller’s navigation button to pan through the VR
First Milestone
//Loop through Pointlist, a list holding all the values from CSV file
for (var i = 0; i < pointList.Count; i++)
{
object distType = pointList[i][columnDist].GetType();
object teffType = pointList[i][columnTeff].GetType();
Type a = typeof(System.String);
//if the distance is NaN, removes info from that row
if (distType.Equals(a)) {
}
else {
// Get value in poinList at ith "row", in "column" Name
distance = Convert.ToSingle(pointList[i][columnDist]);
//ra (right ascension) and dec (declination) are star coordinates
ra = Convert.ToSingle(pointList[i][columnRa]);
dec = Convert.ToSingle(pointList[i][columnDec]);
}
//Convert above values from cartesian to spherical coordinates
float x = Convert.ToSingle(distance * Math.Cos(dec) * Math.Cos(ra));
float y = Convert.ToSingle(distance * Math.Cos(dec) * Math.Sin(ra));
float z = Convert.ToSingle(distance * Math.Sin(dec));
// Instantiate as gameobject variable so that it can be manipulated within loop
GameObject dataPoint = Instantiate(
PointPrefab,
new Vector3(x, y, z),
Quaternion.identity);
// Make child of PointHolder object, to keep points within container in hierarchy
dataPoint.transform.parent = PointHolder.transform;
string starName = Convert.ToString(pointList[i][columnStarName]);
// Assigns original values to dataPointName
string dataPointName = starName;
// Assigns name to the prefab
dataPoint.transform.name = dataPointName;
Challenges:
- Eliminating NaNs (non-numbers) from the dataset
- Existing C# method .isNaN() checks for NaNs but only for number (float or int) data types
- The NaNs in my dataset were showing up as strings
- Solution: Writing a function that checks for string values in the column and eliminating them
- Existing C# method .isNaN() checks for NaNs but only for number (float or int) data types
- The NaNs in my dataset were showing up as strings
- Solution: Writing a function that checks for string values in the column and eliminating them