Welcome![Sign In][Sign Up]
Location:
Search - moon position

Search list

[GDI-Bitmap3D sun moon earth position

Description: 这是一款用JAVA编的3D效果的程序.程序中太阳,月亮和地球的位置可改变-This is a series with Java 3D effect of the procedure. Proceedings sun, the moon and the Earth's position may change
Platform: | Size: 21977 | Author: ying98 | Hits:

[Graph programydpd

Description: 这是一个运动图形检测程序。该程序采用地球与月球的相对运动图片进行检测,可以看到月球位置的相对变化。-This is a moving picture detection procedures. The program uses Earth and the moon relative motion picture detection, we can see the relative position of the moon changes.
Platform: | Size: 84990 | Author: 苏惑 | Hits:

[Internet-Network用D3D模拟地月系

Description:

 

 

 

  一、建立空窗体

  新建一个工程,添加引用,并导入名称空间。

  加入一个设备对象变量:

private Microsoft.DirectX.Direct3D.Device device = null;

  添加初始化图形函数,并在这里面对设备对象进行实例化:

public void InitializeGraphics()
{
 PresentParameters presentParams = new PresentParameters();
 presentParams.Windowed = true;
 presentParams.SwapEffect = SwapEffect.Flip;
 presentParams.AutoDepthStencilFormat = DepthFormat.D16;
 presentParams.EnableAutoDepthStencil = true;
 device = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, this,  CreateFlags.HardwareVertexProcessing, presentParams);
}

  当程序执行时,需要绘制场景,代码在这个函数里:

public void Render()

{
 // 清空设备,并准备显示下一帧。
 device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black , 1.0f, 0);
 // 设置照相机的位置
 SetupCamera();
 //开始场景
 device.BeginScene();
 if(meshLoaded)
 {
  mesh.Render(meshLoc);
 }
 device.EndScene();
 //显示设备内容。
 device.Present();
}

  设置照相机的位置:

private void SetupCamera()
{
 device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Height, 1.0f, 1000.00f);
 device.Transform.View = Matrix.LookAtLH(new Vector3(0.0f ,0.0f, 20.0f), new Vector3(0.0f,0.0f, 0.0f), new Vector3(0,1,0));
}

  现在改变主函数,调用我们写的初始化函数,并显示场景:

[STAThread]

static void Main()
{
 using (Form1 EarthForm = new Form1())
 {
  EarthForm.InitializeGraphics();
  EarthForm.Show();

  while(EarthForm.Created)
  {
   EarthForm.Render();
   Application.DoEvents();
  }
  EarthForm.Dispose();
}

  运行程序,会显示一个空的窗体。

  二、加入地球:

  在这一步里需创建一个3D网格对象,来作为要显示的地球,为此,在工程中新加入一个类Earth,此类可以包含所创建的网格对象的信息。

  加入一些相关变量,含义见注释:

public class Earth : BaseEarth
{
 private Material[] mMaterials; //保存材质
 private Texture[] mTextures; //保存纹理
 private Matrix locationOffset; //用来保存网格对象的相对位置
 private Mesh mMesh = null; //三角形网格对象
 private Device meshDevice; //需要显示在哪个设备上。
}

  在构造函数中,把Device设备拷贝到私有成员变量,这样就可以在这个类的其它方法内使用它,另外就是把位置变量进行赋值:

public Earth(ref Device device, Matrix location): base(ref device)
{
 meshDevice = device;
 locationOffset = location;
}

  下面这个函数是装入.X文件。

public bool LoadMesh(string meshfile)
{
 ExtendedMaterial[] mtrl;
 try
 {
  // 装载文件
  mMesh = Mesh.FromFile(meshfile, MeshFlags.Managed, meshDevice, out mtrl);
  // 如果有材质的话,装入它们
  if ((mtrl != null) && (mtrl.Length > 0))
  {
   mMaterials = new Material[mtrl.Length];
   mTextures = new Texture[mtrl.Length];

   // 得到材质和纹理

   for (int i = 0; i < mtrl.Length; i++)
   {
    mMaterials[i] = mtrl[i].Material3D;
    if ((mtrl[i].TextureFilename != null) && (mtrl[i].TextureFilename != string.Empty))

 

    {
     //前面得到的纹理的路径是相对路径,需要保存的是绝对路径,通过应用程序路径可以获得
     mTextures[i] = TextureLoader.FromFile(meshDevice, @"..\..\" + mtrl[i].TextureFilename);
    }
   }
  }
  return true;
 }
 catch
 {
  return false;
 }
}

  在这个方法内,使用Mesh.FromFile()这个方法,从给定的文件名中找到.X文件,并装入相关数据,一旦数据格式设置完成,可以从此文件中找到材质和贴图信息,并把它存放在数组中,并通过文件路径,得到纹理文件文件的路径,最后返回真值,如果整个过程出现错误,返回假值。

  下面这个Render()方法,是把此对象,即地球显示在设备对象上,此方法较简单,通过变形操作来得到网格对象的X,Y,Z坐标,接着设置网格对象的材质和纹理,最后,将每个材质和纹理应用到每个网格。

public void Render(Matrix worldTransform)
{
 /把位置变为世界坐标
 meshDevice.Transform.World = Matrix.Multiply(locationOffset, worldTransform);
 //绘制网格
 for (int i = 0; i < mMaterials.Length; i++)
 {
  meshDevice.Material = mMaterials[i];
  meshDevice.SetTexture(0, mTextures[i]);
  mMesh.DrawSubset(i);
 }
}

  现在回到窗体代码中,添加引用网格对象的相关变量:

private Earth mesh = null;
private Matrix meshLoc;
private bool meshLoaded = false;

  在图形初始化函数中,需要对网格对象进行初始化。加入下面的代码:

meshLoc = Matrix.Identity;
meshLoc.M41 = 2.0f;
mesh = new Earth(ref device, meshLoc);
if (mesh.LoadMesh(@"..\..\earth.x"))
{
 meshLoaded = true;
}

  代码第一句把网格对象的位置定为原点,接着偏移X轴2个单位,接下来从文件中得到此.X文件。如果成功设置,meshLoaded置为真。注意,这里有一个.X文件,在源代码中有此文件。

 


  在设置相机的函数中,加入一盏灯光:

device.Lights[0].Type = LightType.Directional;
device.Lights[0].Diffuse = Color.White;
device.Lights[0].Direction = new Vector3(0, -1, -1);
device.Lights[0].Update();
device.Lights[0].Enabled = true;


  此灯光较简单,仅为一个直射型白光灯。

最后,在Render()方法中,调用网格对象的Render()方法,以显示地球。

 

  三、使地球旋转

  前面用一个网格对象来建立地球,但此类没有平移,旋转及缩放等方法,下面就加入这些方法,因为这些方法具有通用性,因此可以新建一个类,把这些方法写在这些类中,使地球对象成为它的派生类。

  在工程中新添加一个类:BaseEarth;

  加入进行平移、旋转、缩放的变量:

 

private float xloc = 0.0f;
private float yloc = 0.0f;
private float zloc = 0.0f;
private float xrot = 0.0f;
private float yrot = 0.0f;
private float zrot = 0.0f;
private float xscale = 1.0f;
private float yscale = 1.0f;
private float zscale = 1.0f;


  加入相应的属性代码:

 

public float XLoc
{
 get
 {
  return xloc;
 }
 set
 {
  xloc = value;
 }
}
…………

 

  在Render()虚函数中,应用平移、旋转及缩放。
 

public virtual void Render()
{
 objdevice.MultiplyTransform(TransformType.World,Matrix.Translation(xloc, yloc, zloc));
 objdevice.MultiplyTransform(TransformType.World,Matrix.RotationAxis(new Vector3(1.0f, 0.0f, 0.0f), xrot));
 objdevice.MultiplyTransform(TransformType.World,Matrix.RotationAxis(new Vector3(0.0f, 1.0f, 0.0f), yrot));
 objdevice.MultiplyTransform(TransformType.World,Matrix.RotationAxis(new Vector3(0.0f, 0.0f, 1.0f), zrot));
 objdevice.MultiplyTransform(TransformType.World,Matrix.Scaling(xscale, yscale, zscale));
 return;
}

 

  现在回到地球类,需要将其改为新类的派生类,同时更改构造函数,另外,在Render()方法中,应先调用基类的Render()方法:


public override void Render()
{
 base.Render();
 //把位置变为世界坐标
 // meshDevice.Transform.World = Matrix.Multiply(locationOffset, worldTransform);
 //绘制网格
 。。。。。。
}

 


  现在,由于在基类中可以设置对象位置,因此,可以把与locationOffset相关,即与设置位置的变量及语句注释掉。

  四、加入月球

  在这一步加入月球,实际上是再创建一个网格对象新实例,只是把纹理进行更改即可,为了代码模块性更好,把两个对象放在一个新类CModel中,在工程中新添加一个类CModel,并声明对象实例。


public class cModel
{
 private cMeshObject mesh1 = null;
 private cMeshObject mesh2 = null;
 private bool modelloaded;
}


  把窗口代码中的Load()事件,放在CModel中,这次不仅生成了地球,而且生成了月球。

 


public void Load(ref Device device)
{
 mesh1 = new Earth(ref device);
 mesh2 = new Earth(ref device);
 if (mesh1.LoadMesh(@"..\..\earth2.x"))
 {
  modelloaded = true;
 }
 else
 {
  modelloaded = false;
 }
 if (mesh2.LoadMesh(@"..\..\moon.x"))
 {
  mesh2.XLoc += 20.0f;
  modelloaded = true;
 }
 else
 {
  modelloaded = false;
 }
}

 

  下面的Update()方法中,参数dir 用来判断是顺时针旋转还是逆时针旋转,另外,地球和月球绕Y轴增加的角度大小不同,也就决定了二者旋转的速度不同。


public void Update(int dir)
{
 if(dir > 0)
 {
  mesh1.YRot += 0.02f;
  mesh2.YRot += 0.05f;
 }
 else if(dir < 0)
 {
  mesh1.YRot -= 0.02f;
  mesh2.YRot -= 0.05f;
 }
}


  在下面的render()方法中,生成显示月球和地球:

 


public void Render(ref Device device)
{
 device.Transform.World = Matrix.Identity;
 if(modelloaded)
 {
  mesh1.Render();
  mesh2.Render();
 }
}


  把窗口代码中的加入灯光的方法,也放在此类中:


public void LoadLights(ref Device device)
{
 device.Lights[0].Type = LightType.Directional;
 device.Lights[0].Diffuse = Color.White;
 device.Lights[0].Position = new Vector3(0.0f, 0.0f, 25.0f);
 device.Lights[0].Direction = new Vector3(0, 0, -1);
}
public void Light(ref Device device)
{
 device.Lights[0].Update();
 device.Lights[0].Enabled = true;
}


  五、与鼠标交互操作

  为了实现与键盘、鼠标交互,新添加一个类:CMouse,添加引用Microsoft.DirectX.DirectInput,并添加命名空间。加入相关变量:


private Microsoft.DirectX.DirectInput.Device mouse = null;
public System.Threading.AutoResetEvent MouseUpdated;
private float x, y, z = 0.0f;
private byte[] buttons;

 

  在下面的构造函数代码中,首先创建鼠标设备,并初始化回调事件:


public CMouse(System.Windows.Forms.Control control)
{
 mouse = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Mouse);
 mouse.SetCooperativeLevel(control, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
 mouse.Properties.AxisModeAbsolute = false;
 MouseUpdated = new System.Threading.AutoResetEvent(false);
 mouse.SetEventNotification(MouseUpdated);
 mouse.Acquire();
 Update();

 


  下面的Update()方法中获得鼠标的坐标值,并赋给私有成员变量:

public void Update()
{
 MouseState state = mouse.CurrentMouseState;
 x = state.X;
 y = state.Y;
 z = state.Z;
 buttons = state.GetMouseButtons();
}


  还需要有一个函数来检测鼠标左键是否按下:

 


public bool LeftButtonDown
{
 get
 {
  bool a;
  return a = (buttons[0] != 0);
 }
}


  六、大结局

  现在已经做完了准备工作,返回到窗口代码中,需要对这里的代码重新进行一些调整:

  在图形初始化函数中创建一个CModel类及CMouse类:

 

private CModel model = null;
private CMouse mouse = null;
private bool leftbuttondown = false;
private float mousexloc;

 

  添加对鼠标初始化的方法:

 

网管联盟bitsCN@com


public void InitializeInput()
{
 mouse = new CMouse(this);
}


  添加UpdateInputState()方法,当按下鼠标左键时,将leftbuttondown值设置为真,当鼠标抬起时,将mousexloc置0:


private void UpdateInputState()
{
 mouse.Update();
 if (mouse.LeftButtonDown)
 {
  if(leftbuttondown == false)
  {
   mousexloc = 0.0f;
   leftbuttondown = true;
  }
  else
  {
   mousexloc = -mouse.X;
  }
 }
 else
 {
  leftbuttondown = false;
  mousexloc = 0.0f;
 }
}


  在此程序中,只对X值进行了操作,即只能左右转。

  Render()方法更新如下:

public void Render()
{
 UpdateInputState();
 device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.DarkGray, 1.0f, 0);
 SetupCamera();
 device.BeginScene();
 model.Update((int)mousexloc);
 model.Light(ref device);
 model.Render(ref device);
 device.EndScene();
 device.Present();
}

 

  最后更改Main()主函数:


static void Main()
{
 using (Form1 EarthForm = new Form1())
 {
  EarthForm.InitializeGraphics();
  EarthForm.InitializeInput();
  EarthForm.Show();
  while(EarthForm.Created)
  {
   EarthForm.Render();
   Application.DoEvents();
  }
  EarthForm.Dispose();
 }
 


Platform: | Size: 11817 | Author: mantoutou | Hits:

[GDI-Bitmap3D sun moon earth position

Description: 这是一款用JAVA编的3D效果的程序.程序中太阳,月亮和地球的位置可改变-This is a series with Java 3D effect of the procedure. Proceedings sun, the moon and the Earth's position may change
Platform: | Size: 21504 | Author: ying98 | Hits:

[Graph programydpd

Description: 这是一个运动图形检测程序。该程序采用地球与月球的相对运动图片进行检测,可以看到月球位置的相对变化。-This is a moving picture detection procedures. The program uses Earth and the moon relative motion picture detection, we can see the relative position of the moon changes.
Platform: | Size: 84992 | Author: 苏惑 | Hits:

[Editorearth

Description: 月亮绕地球运动,期间,地球会不断改变颜色。而在月亮位置上放置个聚光灯,照亮地球-Moon around the Earth campaign period, the Earth will continue to change color. And in the moon position to place a spotlight to illuminate the Earth
Platform: | Size: 1024 | Author: action | Hits:

[source in ebookmaze

Description: 用堆栈实现迷宫求解问题 基本思想: 若当前位置可以通过,则压入栈中,否则探求下一位置,若走不通,则回朔,迷宫大小:M*N.迷宫设置自定义。 求解迷宫问题的简单方法是:从入口出发,沿某一方向进行探索,若能走通,则继续向前走;否则沿原路返回,换一方向再进行探索,直到所有可能的通路都探索到为止。 为避免走回到已经进入的点(包括已在当前路径上的点和曾经在当前路径上的点),凡是进入过的点都应做上记号。-Maze with the stack to achieve the basic idea for solving the problem: If the current position can be adopted, in pressure, otherwise the next location to explore, if a dead end, then back to New Moon, the size of the maze: M* N. maze set up a custom. A simple maze to solve the problem is: starting from the entrance, along a certain direction to explore, can walk, then continue to move forward otherwise return along the same route, a direction for further exploration, until all possible pathways are exploring to date. In order to avoid going back to have access points (including the current path and current path in the point), all the points should be entered mark.
Platform: | Size: 34816 | Author: Tantan | Hits:

[Other Embeded programSunZip65

Description: Sun and moon day_night position on earth with lat long
Platform: | Size: 12333056 | Author: SHIBU SAHA | Hits:

[transportation applicationsLunarAzEl

Description: 月球方位角与高度预测 针对月球车提出了一种基于天文观测的自主位置姿态确定方法。建立了利用天体敏感器测量得到的天体高度和方位作为观测信息的量测方程,并利用月球车运动的三阶常加速-Azimuth and highly predictive of the moon rover for astronomical observations is proposed based on the independent position and attitude determining method. Established using the measured celestial objects in sensor height and location information as a measurement equation observed, and using third-order lunar rover constant acceleration motion
Platform: | Size: 4096 | Author: saihedy | Hits:

[OpenGL programopenGL2

Description: 1)理解OpenGL中的变换过程 (2)理解透视投影与平行投影的不同 (3)添加代码实现太阳、地球和月亮的运动模型 (4)了解深度测试 (5)通过变换调整观察的位置与方向 (6)加入光照模型-1) understand the transformation process in OpenGL (2) understand the perspective projection and parallel projection of the different (3) add the code to achieve the sun, Earth and Moon motion model (4) understand the depth of the test (5) adjusted by changing the position and direction of observation (6) by adding illumination model
Platform: | Size: 1286144 | Author: 周中锋 | Hits:

[Algorithmjpleph

Description: 计算太阳系行星/月球及部分小行星在惯性系下得相对位置-Calculation of the solar system planets/Moon and some asteroids relative position in the inertial system was under
Platform: | Size: 55183360 | Author: 王选 | Hits:

[OpenGL programsun-earth-moon

Description: 1.理解OpenGL中的变换过程 2.理解透视投影与平行投影的不同 3.了解深度测试 通过变换调整观察的位置与方向 加入光照模型 -Understand the transform OpenGL process Understand perspective projection and parallel projective different Understand the depth test Through the transformation of the position and orientation adjust observed Join lighting model
Platform: | Size: 1199104 | Author: zhou shun | Hits:

[Algorithmmoon-position

Description: 根据《天文算法》一书中提出的计算月球位置算法编写的fortran程序。-According to a book of astronomical algorithm to calculate the sun position algorithm written in fortran program.
Platform: | Size: 3072 | Author: zhaoqiang | Hits:

[OpenGL programSolarSys111

Description: 模拟太阳,地球和月亮的相对位置关系及其运动。-To simulate the sun, Earth and moon relative position and movement.
Platform: | Size: 1552384 | Author: yanxutao | Hits:

[Multimedia Developsolar

Description: 用OPENGL 模拟太阳系,建立9大行星,让它们围绕太阳运动,同时创建月亮围绕地球运动,且建立光源和给行星加上纹理。 用↑,↓,←,→键控制视点位置,用 W和S键控制视点的远近。 -OPENGL simulation of the solar system, the establishment of the nine planets around the sun, at the same time create the moon revolves around the earth, and the establishment of a light source and coupled to the planet texture. ↑, ↓, ← → keys to control the viewpoint position, with the W and S keys to control the proximity of the viewpoint.
Platform: | Size: 9505792 | Author: sophie | Hits:

[JSP/JavaLookAtSkyV02R02

Description: 虚拟场景下显示日月和星座位置。在firefox或者谷歌浏览器上打开index.html。手指在星空图上滑动,可以转换方位以及仰角,星空图下面显示观测的时间和地点。如果要更换观测时间或地点,点击“change location or time"-show location of sun, moon and Stellarium. open index.html on firefox or google browser. time, your position and view point can be changed.
Platform: | Size: 6296576 | Author: chen yu min | Hits:

[Game Server Simulatorogame

Description: 游戏将伺服器称之为「宇宙」,每个宇宙有银河系、每个银河系有四百九十九个太阳系,而每个太阳系有十五个行星。 每位玩家最初拥有一颗星球,称为「母星」(这个名字是可以被玩家重新命名的),该星球的位置随机分布于任意太阳系的4号~12号星球上。玩家首要任务是发展母星,并且对外殖民其它星球,每个玩家可以利用提昇研究等级增加可殖民星球数。所有的建筑、战斗都是发生在星球和月球上的。(某些建筑是不能在月球上建造的。)-Playing the server is called " cosmic" , each universe galaxy, the Milky Way has four hundred ninety-nine each solar system, and each solar system has fifteen planets. Each player has a planet was originally called the " Mother Star" (this name can be renamed by the player), the position of the planet in any solar system randomly distributed on the 4th- the 12th planet. Players first task is to develop the parent star, and of foreign colonization other planets, each player can use to enhance the research level to increase the number of available colonial planet. All the buildings, fighting occurred in the planet and the moon. (Some buildings can not be built on the moon.)
Platform: | Size: 10584064 | Author: 林吾到 | Hits:

[OpenGL programSunEarth

Description: 简单的太阳地球月亮的模型,并在太阳位置加上了光照-A sun, earth, moon model and enabled the lighting from the position of the sun.
Platform: | Size: 477184 | Author: 钟书成 | Hits:

[matlabexercise1

Description: 考虑章动、极移、岁差下历元时刻月球在瞬时平天球坐标系,J2000协议地固系,WGS-84坐标系下的位置速度矢量及转换的matlab源程序-Consider nutation, polar motion, precession next epoch in the instantaneous level of the moon celestial coordinate system, J2000 protocol to the solid line, the position and the velocity vector conversion WGS-84 coordinate system matlab source
Platform: | Size: 5120 | Author: 李涛 | Hits:

[WEB Codejieqi

Description: 0000-5000年间 二十四节气详细时间推算程序.本程序主要采用PHP语言实现。功能是推算0000年到5000年间二十四节气的详细更迭时间。二十四节气是中国古代订立的一种用来指导农事的补充历法,是在春秋战国时期形成的。 -由于中国农历是一种“阴阳合历”,即根据太阳也根据月亮的运行制定的,因此不能完全 -反映太阳运行周期,但中国又是一个农业社会,农业需要严格了解太阳运行情况,农事完 -全根据太阳进行,所以在历法中又加入了单独反映太阳运行周期的“二十四节气”,用作 -确定闰月的标准。二十四节气能反映季节的变化,指导农事活动,影响着千家万户的衣食 -住行。二十四节气是根据太阳在黄道(即地球绕太阳公转的轨道)上的位置来划分的。 ------------------------------二十四节气介绍----------------------------------------- 春分,清明,谷雨,立夏,小满,芒种,夏至,小暑,大暑,立秋,处暑,白露 秋分,寒露,霜降,立冬,小雪,大雪,冬至,小寒,大寒,立春,雨水,惊蛰-0000-5000 years, twenty-four solar time reckoning procedures in detail the procedures used mainly PHP language. Function is projected between 0000 and 5000 24 solar detailed change of time . Twenty-four solar calendar is a supplement to the guidance of Chinese ancient farming entered into , is formed in the Spring and Autumn Period . - As the Chinese Lunar New Year is a " lunisolar calendar" that, according to the Sun also developed under the moon run , it is not entirely - Reflect the sun cycle, but China is an agricultural community , to understand the need for strict sun agricultural operation , farming End - Full sun conducted in accordance with , so they added a separate calendar to reflect the sun cycle "Twenty-four solar terms " used - Determine the leap month standard. Twenty-four solar energy to reflect the change of seasons , guiding farming activities , affecting thousands of families of food and clothing - Live line . Twenty-four solar is based on the position of the s
Platform: | Size: 789504 | Author: zhang | Hits:
« 12 »

CodeBus www.codebus.net