`
czwangelo
  • 浏览: 72299 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

sun position的engine例子

阅读更多

大家好,今天我将给大家演示engine的一个例子,

这个例子非常小,但是却也非常有趣,是关于一个地球与太阳的例子,在我们的例子中,有一个太阳,有一个地球,

我们都知道如果太阳在地球的左边,那么地球的左边是白天,而右边没被晒到的部分都是黑夜.

我们从File->New -> Others ->

选中SunPosition

点击finish,我们可以在左边的package explorer看到

同时呢,我们可以在右边看到已经打开的SunPosition的源代码,

运行该源代码,

 

在左上角我们可以看到一个小图标,点击该小图标,我们可以对地图进行转动

 

点击左上解的set sun positon

然后在地球的旁边的某个位置点击一下,就可以设制为太阳的位置了,这样地球相反的某个方向就会出现影印了,

怎么样,这个例子就是这样的,是不是觉得很有趣啊??

 

接下来,我们就对代码进行分析了

 

/*
 Copyright 1995-2006 ESRI
 
 All rights reserved under the copyright laws of the United States.
 
 You may freely redistribute and use this sample code, with or without modification.
 
 Disclaimer: THE SAMPLE CODE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 
 WARRANTIES, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ESRI OR 
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 INTERRUPTION) SUSTAINED BY YOU OR A THIRD PARTY, HOWEVER CAUSED AND ON ANY 
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ARISING IN ANY 
 WAY OUT OF THE USE OF THIS SAMPLE CODE, EVEN IF ADVISED OF THE POSSIBILITY OF 
 SUCH DAMAGE.
 
 For additional information contact: Environmental Systems Research Institute, Inc.
 
 Attn: Contracts Dept.
 380 New York Street
 Redlands, California, U.S.A. 92373 
 Email: contracts@esri.com
 */
package arcgissamples.globecore.sunposition;


import java.awt.*;
import javax.swing.*;

import com.esri.arcgis.beans.globe.GlobeBean;
import com.esri.arcgis.beans.toolbar.ToolbarBean;
import com.esri.arcgis.controls.ControlsGlobeNavigateTool;
import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.esriLicenseExtensionCode;
import com.esri.arcgis.system.esriLicenseProductCode;
import com.esri.arcgis.systemUI.esriCommandStyles;
import com.esri.arcgis.interop.AutomationException;
//import com.esri.arcgis.interop.AutomationException;

import java.awt.event.*;
import java.io.File;
import java.io.IOException;

public class SunPosition extends JFrame {
	public static void main(String[] args) {
		System.out.println("Starting Sun Position - An ArcObjects Java SDK Developer Sample");
		String arcGISHome = null;
		arcGISHome = System.getenv("ARCGISHOME");
		if (arcGISHome == null || !(new File(arcGISHome).exists())) {
			System.out.println(((arcGISHome==null)?"ARCGISHOME environment variable":arcGISHome)+" does not exist.\nExiting...");
			System.exit(-1);
		}
		//
		// Change the following line if you want to use different data, or just pass in a
		// different 3DD file.
		//
		String globeTexture = arcGISHome + "java/samples/data/globe_data/Default_Document.3dd";
		if (args.length > 0) {
			globeTexture = args[0];
		}
		File globeTextureFile = new File(globeTexture);
		if (!globeTextureFile.exists()) {
			System.out.println("globeTexture file does not exist: " + globeTextureFile.getAbsolutePath());
			System.out.println("Continuing...");
		}
		try {
			EngineInitializer.initializeVisualBeans();
			AoInitialize aoInitializer = new AoInitialize();
			aoInitializer.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
			aoInitializer.checkOutExtension(esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst);
			SunPosition thisApp = new SunPosition();
			thisApp.initUI(globeTextureFile);
		} catch (Exception ex) {
			System.out.println("Sample failed: " + ex.getMessage());
			ex.printStackTrace();
		}
	}
	/**
	 * Initialize user interface.
	 */
	private void initUI(File globeTextureFile) throws AutomationException, IOException {
		//
		// set the attributes for the application's JFrame window
		//
		this.setTitle("Sun Position Sample Application");
		setSize(800, 800);
		//
		// Create the tools to be placed in the toolbar bean.
		//
		SunPositionTool sunPositionTool = new SunPositionTool();
		//
		// Create the toolbar bean for the tools and add the tools to it.
		//
		ToolbarBean toolbarBean = new ToolbarBean();
        toolbarBean.addItem(new ControlsGlobeNavigateTool(), 0, -1, false, 0, 1);
		toolbarBean.addItem(sunPositionTool, -1, -1, false, 0, esriCommandStyles.esriCommandStyleTextOnly);
		//
		// Set the layout scheme with a layout manager.
		//
		getContentPane().setLayout(new BorderLayout());
		//
		// Add the toolbar bean to the app's window frame's content pane
		//
		getContentPane().add(toolbarBean, BorderLayout.NORTH);  
		//
		// Create the globe bean and associate it with the toolbar bean.
		//
		GlobeBean globeBean = new GlobeBean();
		toolbarBean.setBuddyControl(globeBean);
		//
		// Add the globe bean to the app's window frame's content pane.
		//
		getContentPane().add(globeBean, BorderLayout.CENTER);
		//
		// Make the frame visible.  You must do this before you can load a 3D/texture file
		//
		setVisible(true);
		//
		// Load the globe texture.
		//
		String globeTexture = globeTextureFile.getAbsolutePath();
		if (globeBean.check3dFile(globeTexture)) {
			System.out.println("Loading 3D file " + globeTexture + " ... ");
			try {
				globeBean.load3dFile(globeTexture); // looks like this has to be done after setVisible(true) is called
				System.out.println("File loaded.");
			}
			catch (Exception e) {
				e.printStackTrace();
				System.out.println("Continuing ...");
			}
		}
		//
		// Add a window closing operation listener to shut down arcobjects and exit the app.
		//
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				try {
					new AoInitialize().shutdown();
				} catch (Exception e1) {
					e1.printStackTrace();
				}
				System.out.println("Done.");
				System.exit(0);
			}
		});
	}
}

 

 

 

 

 

/*
 Copyright 1995-2006 ESRI
 
 All rights reserved under the copyright laws of the United States.
 
 You may freely redistribute and use this sample code, with or without modification.
 
 Disclaimer: THE SAMPLE CODE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 
 WARRANTIES, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ESRI OR 
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 INTERRUPTION) SUSTAINED BY YOU OR A THIRD PARTY, HOWEVER CAUSED AND ON ANY 
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ARISING IN ANY 
 WAY OUT OF THE USE OF THIS SAMPLE CODE, EVEN IF ADVISED OF THE POSSIBILITY OF 
 SUCH DAMAGE.
 
 For additional information contact: Environmental Systems Research Institute, Inc.
 
 Attn: Contracts Dept.
 380 New York Street
 Redlands, California, U.S.A. 92373 
 Email: contracts@esri.com
 */
package arcgissamples.globecore.sunposition;

import com.esri.arcgis.analyst3d.ISceneViewer;
import com.esri.arcgis.controls.BaseTool;
import com.esri.arcgis.controls.GlobeHookHelper;
import com.esri.arcgis.globecore.GlobeCamera;
import com.esri.arcgis.globecore.GlobeDisplay;

class SunPositionTool extends BaseTool {
	GlobeHookHelper globeHookHelper;
	GlobeCamera globeCamera;
	GlobeDisplay globeDisplay;
	ISceneViewer sceneViwer;
	boolean isTrackingSun;
	
	public SunPositionTool() {
		this.caption = "Set Sun Position"; 
		this.category = "Java Samples"; 
		this.message = "set sun position tool"; 
		this.name = "Java Samples Sun Position"; 
		this.toolTip = "Set Sun Position Tool"; 
		this.cursorPath = "SunPositionTool.cur";
		this.enabled = true; 
	}
	
	/**
	 * When this tool is created, initialize the hook helper abd get the hook.
	 */
	public void onCreate(Object hook) {
		try {
			if (this.globeHookHelper == null) {
				this.globeHookHelper = new GlobeHookHelper();
			}
			this.globeHookHelper.setHookByRef(hook);
		} catch (Exception e) {
			System.out.println("Couldn't create the SunPosition tool");
			e.printStackTrace();
			System.exit(1);
		}
	}
	
	/**
	 * When this tool is clicked, set up the lighting.
	 */
	public void onClick() {
		try {
			this.globeCamera = (GlobeCamera) this.globeHookHelper.getCamera();
			this.globeDisplay = (GlobeDisplay) this.globeHookHelper.getGlobeDisplay();
			//
			// Enable the light source and set light characteristics
			//
			this.globeDisplay.setIsSunEnabled(true);
			this.globeDisplay.setAmbientLight(0.0005f);
			this.globeDisplay.setSunContrast(90);
			//
			// Update the scene viewer.
			//
			this.sceneViwer = this.globeHookHelper.getActiveViewer();
		} catch (Exception e) {
			System.out.println("Couldn't enable the sun's light");
			e.printStackTrace();
			System.exit(1);
		}
	}
	/**
	 * On initial mouse down, get it's position and from it set the sun's position.
	 */
	public void onMouseDown(int Button, int Shift, int X, int Y) {
		this.isTrackingSun = true;
		try {
			double[] lat = {0.0};
			double[] lon = {0.0};
			double[] alt = {0.0};
			this.globeCamera.windowToGeographic(this.globeDisplay, this.sceneViwer, X, Y, false, lon, lat, alt);
			this.globeDisplay.setSunPosition(lat[0], lon[0]);
			this.sceneViwer.redraw(false);
		} catch (Exception e) {
			//
			// An exception is thrown if mouse is clicked outside of the globe itself
			// We ignore that case.
			//
		}
	}
	/**
	 * Track mouse movement, updating the sun's position.
	 */
	public void onMouseMove(int Button, int Shift, int X, int Y) {
		//
		// Only track movement if a mouse button is down.
		//
		if (!this.isTrackingSun) {
			return;
		}
		try {
			double[] lat = {0.0};
			double[] lon = {0.0};
			double[] alt = {0.0};
			this.globeCamera.windowToGeographic(this.globeDisplay, this.sceneViwer, X, Y, false, lon, lat, alt);
			this.globeDisplay.setSunPosition(lat[0], lon[0]);
			this.sceneViwer.redraw(false);
		} catch (Exception e) {
			//
			// An exception is thrown if mouse is moved outside of the globe itself
			// while the mouse button is down.  We ignore that case.
			//
		}
	}
	/**
	 * Stop tracking the sun when the mouse button is released.
	 */
	public void onMouseUp(int Button, int Shift, int X, int Y) {
		this.isTrackingSun = false;
	}		
}

 

 

分享到:
评论

相关推荐

    matlab开发-SunPosition

    在MATLAB开发中,"SunPosition"项目涉及的是利用编程计算太阳的地心赤道位置,这一概念在天文学和地球科学中非常重要。太阳的地心赤道位置是指从地球的中心观察,太阳在天球赤道上的坐标,通常以国际天球参照系统...

    Sun Grid Engine助力瑞典Chalmers 理工大学

    Chalmers 理工大学采用Sun:trade_mark: Grid Engine ,该集群共配置80 颗CPU 和160 GB 存储系统。通过实施Sun Grid Engine 为学校快速实现和满足有效利用计算资源的需求。

    Sun 宠物店例子

    "Sun 宠物店例子" 是一个经典的 Java 教程示例,旨在帮助初学者理解面向对象编程的概念和 Java 语言的应用。在这个例子中,我们通常会看到如何使用 Java 来设计一个简单的宠物店系统,其中包括不同的宠物类,如 Dog...

    sun gridengine source package

    sge 源码安装包 分布式资源管理系统 The Oracle Grid Engine software is a distributed resource management (DRM) system that enables higher utilization, better workload throughput, and higher end-user ...

    homebridge-sun-position:Homebridge插件,用于公开太阳的位置以实现自动化

    安装此插件: npm install -g homebridge-sun-position将SunPosition附件添加到Homebridge config.json ,提供您所在位置的经度和纬度: "accessories" : [ { "accessory" : "SunPosition", "name" : "Sun", ...

    Sun Engine-开源

    Sun Engine 是一款面向游戏开发者的开源3D游戏引擎,它为开发者提供了丰富的功能,以便创建出高质量的3D游戏。这款引擎的特点在于其易用性和强大的功能,使得无论是初学者还是经验丰富的专业开发者都能轻松上手。...

    SUN给出JDBC代码例子

    在这个“SUN给出的JDBC代码例子”中,我们将探讨JDBC的基本概念、核心组件以及如何使用它们来实现数据库操作。 1. JDBC API概述 JDBC API主要包括以下关键类和接口: - DriverManager:管理数据库驱动程序,负责...

    SUN T7-1 固件 SUN T7-1 固件

    SUN T7-1 固件SUN T7-1 固件SUN T7-1 固件SUN T7-1 固件SUN T7-1 固件SUN T7-1 固件SUN T7-1 固件SUN T7-1 固件SUN T7-1 固件SUN T7-1 固件SUN T7-1 固件SUN T7-1 固件SUN T7-1 固件SUN T7-1 固件SUN T7-1 固件SUN ...

    sunblock:不要直视Sun Grid Engine

    Sunblock 是一个 Python 工具,其名称"不要直视Sun Grid Engine"暗示它与管理和操作 Sun Grid Engine (SGE) 相关。Sun Grid Engine,现在通常被称为 Oracle Grid Infrastructure,是一个分布式计算环境,用于管理和...

    Sun J2EE 宠物店例子

    《Sun J2EE宠物店例子》是一个经典的教程,它深入浅出地讲解了J2EE(Java 2 Platform, Enterprise Edition)技术在实际应用中的运用,特别是如何构建一个完整的电子商务平台。这个例子通过一个模拟的宠物商店应用,...

    SUN M10-4 固件 SUN M10-4 固件

    SUN M10-4 固件SUN M10-4 固件SUN M10-4 固件SUN M10-4 固件SUN M10-4 固件SUN M10-4 固件SUN M10-4 固件SUN M10-4 固件SUN M10-4 固件SUN M10-4 固件SUN M10-4 固件SUN M10-4 固件SUN M10-4 固件SUN M10-4 固件SUN ...

    Grid-Engine-6-用户指南

    _grid引擎是Sun Microsystems公司推出的集群作业调度系统,本用户指南提供Grid Engine 6的详细使用说明,它是一个功能强大的资源管理工具,特别适用于管理网格计算环境中的计算任务和资源。用户通过本指南可了解如何...

    N1 Grid Engine 6安装管理用户指南3合一.zip

    无论您是否已安装了 Grid Engine 软件的早期版本,还是首次安装,您都需要在解压缩 和安装软件之前进行规划。本节介绍了您必须做出的一些决定,可能时,还提供了做出 决定的标准。 必须做出的决定 计划安装软件之前...

    SUN 官方推荐JSF Struts 例子

    **JSF(JavaServer Faces)** 是Java平台上用于构建用户界面的一种组件模型,它简化了Web应用程序的开发,提供了一...同时,由于这些例子来自于SUN官方,因此它们代表了最佳实践和当时的技术标准,值得深入学习和研究。

    Java sun audio包

    Java的sun.audio包是Java标准库的一个组成部分,主要用于处理音频数据和播放音频文件。这个包在Java早期版本中被广泛使用,尽管在后续版本中,Java Sound API成为了更推荐的音频处理工具,但sun.audio包仍然保留,为...

    com.sun.pdfview.PDFRenderer

    import com.sun.pdfview.FullScreenWindow;import com.sun.pdfview.OutlineNode;import com.sun.pdfview.PDFDestination;import com.sun.pdfview.PDFFile;import com.sun.pdfview.PDFObject;import ...

Global site tag (gtag.js) - Google Analytics