logo

Assignment on Virtual Reality

27 Pages3776 Words351 Views
   

Added on  2020-03-16

Assignment on Virtual Reality

   Added on 2020-03-16

ShareRelated Documents
VIRTUAL REALITYOverviewProject was to create a 2d and 3d view of solar system with many constraints. It needsto be done in unity software. Download and installation took around 1 hour.WorkA 3 dimensional view of our solar system is designed. The sun and the other planets are all made of sphere which is a 3d object. A single sphere can get all its properties from material under assets. For each and every sphere new material need to be created. If not the same property will inherit to all the other spheres. The texture is given to a particular sphere after creating a new material and it is dragged and dropped on the object. For each and every object separate materials will only define their texture, size and other 1
Assignment on Virtual Reality_1
properties. Now another solar system can be similarly designed by following the same procedure. The distance from the sun to other planets and name of the planets will be covered in future work.Source code for Planets:The code is attached hereSourcecode.rarThe same code is given below for quick view.usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassPlanets:MonoBehaviour{floatpanelHeight=0.1F;floatpanelWidth=30.0F;floatpanelDepth=0.1F;floatorbitWidth=0.01F;floathabWidth=0.03F;floatrevolutionSpeed=0.2F;floatpanelXScale=2.0F;floatorbitXScale=2.0F;//------------------------------------------------------------------------------------//voiddrawOrbit(stringorbitName,floatorbitRadius,ColororbitColor,floatmyWidth,GameObjectmyOrbits){GameObjectnewOrbit;GameObjectorbits;newOrbit=newGameObject(orbitName);newOrbit.AddComponent<Circle>();newOrbit.AddComponent<LineRenderer>();2
Assignment on Virtual Reality_2
newOrbit.GetComponent<Circle>().xradius=orbitRadius;newOrbit.GetComponent<Circle>().yradius=orbitRadius;varline=newOrbit.GetComponent<LineRenderer>();line.startWidth=myWidth;line.endWidth=myWidth;line.useWorldSpace=false;newOrbit.GetComponent<LineRenderer>().material.color=orbitColor;orbits=myOrbits;newOrbit.transform.parent=orbits.transform;}//------------------------------------------------------------------------------------//voiddealWithPlanets(string[,]planets,GameObjectthesePlanets,GameObjecttheseOrbits){GameObjectnewPlanetCenter;GameObjectnewPlanet;GameObjectsunRelated;MaterialplanetMaterial;intplanetCounter;for(planetCounter=0;planetCounter<planets.GetLength(0);planetCounter++){floatplanetDistance=float.Parse(planets[planetCounter,0])/149600000.0F*10.0F;floatplanetSize=float.Parse(planets[planetCounter,1])*2.0F/10000.0F;floatplanetSpeed=-1.0F/float.Parse(planets[planetCounter,2])*revolutionSpeed;stringtextureName=planets[planetCounter,3];stringplanetName=planets[planetCounter,4];newPlanetCenter=newGameObject(planetName+"Center");3
Assignment on Virtual Reality_3
newPlanetCenter.AddComponent<rotate>();newPlanet=GameObject.CreatePrimitive(PrimitiveType.Sphere);newPlanet.name=planetName;newPlanet.transform.position=newVector3(0,0,planetDistance*orbitXScale);newPlanet.transform.localScale=newVector3(planetSize,planetSize,planetSize);newPlanet.transform.parent=newPlanetCenter.transform;newPlanetCenter.GetComponent<rotate>().rotateSpeed=planetSpeed;planetMaterial=newMaterial(Shader.Find("Standard"));newPlanet.GetComponent<MeshRenderer>().material=planetMaterial;planetMaterial.mainTexture=Resources.Load(textureName)asTexture;drawOrbit(planetName+"orbit",planetDistance*orbitXScale,Color.white,orbitWidth,theseOrbits);sunRelated=thesePlanets;newPlanetCenter.transform.parent=sunRelated.transform;}}//------------------------------------------------------------------------------------//voidsideDealWithPlanets(string[,]planets,GameObjectthisSide,GameObjecttheseOrbits){GameObjectnewPlanet;GameObjectsunRelated;MaterialplanetMaterial;intplanetCounter;for(planetCounter=0;planetCounter<planets.GetLength(0);planetCounter++){floatplanetDistance=float.Parse(planets[planetCounter,0])/149600000.0F*10.0F;4
Assignment on Virtual Reality_4
floatplanetSize=float.Parse(planets[planetCounter,1])*1.0F/10000.0F;stringtextureName=planets[planetCounter,3];stringplanetName=planets[planetCounter,4];//limittheplanetstothewidthofthesideviewif((panelXScale*planetDistance)<panelWidth){newPlanet=GameObject.CreatePrimitive(PrimitiveType.Sphere);newPlanet.name=planetName;newPlanet.transform.position=newVector3(-0.5F*panelWidth+planetDistance*panelXScale,0,0);newPlanet.transform.localScale=newVector3(planetSize,planetSize,5.0F*panelDepth);planetMaterial=newMaterial(Shader.Find("Standard"));newPlanet.GetComponent<MeshRenderer>().material=planetMaterial;planetMaterial.mainTexture=Resources.Load(textureName)asTexture;sunRelated=thisSide;newPlanet.transform.parent=sunRelated.transform;}}}//------------------------------------------------------------------------------------//voidsideDealWithStar(string[]star,GameObjectthisSide,GameObjecttheseOrbits){GameObjectnewSidePanel;GameObjectnewSideSun;GameObjectsideSunText;GameObjecthabZone;MaterialsideSunMaterial,habMaterial;newSidePanel=GameObject.CreatePrimitive(PrimitiveType.Cube);newSidePanel.name="Side"+star[1]+"Panel";newSidePanel.transform.position=newVector3(0,0,0);5
Assignment on Virtual Reality_5
newSidePanel.transform.localScale=newVector3(panelWidth,panelHeight,panelDepth);newSidePanel.transform.parent=thisSide.transform;newSideSun=GameObject.CreatePrimitive(PrimitiveType.Cube);newSideSun.name="Side"+star[1]+"Star";newSideSun.transform.position=newVector3(-0.5F*panelWidth-0.5F,0,0);newSideSun.transform.localScale=newVector3(1.0F,panelHeight*40.0F,2.0F*panelDepth);newSideSun.transform.parent=thisSide.transform;sideSunMaterial=newMaterial(Shader.Find("Unlit/Texture"));newSideSun.GetComponent<MeshRenderer>().material=sideSunMaterial;sideSunMaterial.mainTexture=Resources.Load(star[2])asTexture;sideSunText=newGameObject();sideSunText.name="SideStarName";sideSunText.transform.position=newVector3(-0.47F*panelWidth,22.0F*panelHeight,0);sideSunText.transform.localScale=newVector3(0.1F,0.1F,0.1F);varsunTextMesh=sideSunText.AddComponent<TextMesh>();sunTextMesh.text=star[1];sunTextMesh.fontSize=150;sideSunText.transform.parent=thisSide.transform;floatinnerHab=float.Parse(star[4])*9.5F;floatouterHab=float.Parse(star[4])*14F;//needtotakepanelXScaleintoaccountforthehabzonehabZone=GameObject.CreatePrimitive(PrimitiveType.Cube);habZone.name="Hab";habZone.transform.position=newVector3((-0.5F*panelWidth)+((innerHab+outerHab)*0.5F*panelXScale),0,0);habZone.transform.localScale=newVector3((outerHab-innerHab)*panelXScale,40.0F*panelHeight,2.0F*panelDepth);habZone.transform.parent=thisSide.transform;6
Assignment on Virtual Reality_6

End of preview

Want to access all the pages? Upload your documents or become a member.