大家好,今天我将给大家演示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;
}
}
分享到:
相关推荐
Chalmers 理工大学采用Sun:trade_mark: Grid Engine ,该集群共配置80 颗CPU 和160 GB 存储系统。通过实施Sun Grid Engine 为学校快速实现和满足有效利用计算资源的需求。
matlab开发-SunPosition。太阳的地心赤道位置(单位[m]),参考ICRF。
Sun 宠物店例子
sge 源码安装包 分布式资源管理系统 The Oracle Grid Engine software is a distributed resource management (DRM) system that enables higher utilization, better workload throughput, and higher end-user ...
安装此插件: npm install -g homebridge-sun-position将SunPosition附件添加到Homebridge config.json ,提供您所在位置的经度和纬度: "accessories" : [ { "accessory" : "SunPosition", "name" : "Sun", ...
SUN公司为java程序员们给出的JAVA连接数据库方法,其中有代码实例
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 ...
防晒霜 不要直视Sun Grid Engine 要求 pip install click zenlog requests
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 ...
无论您是否已安装了 Grid Engine 软件的早期版本,还是首次安装,您都需要在解压缩 和安装软件之前进行规划。本节介绍了您必须做出的一些决定,可能时,还提供了做出 决定的标准。 必须做出的决定 计划安装软件之前...
Sun Engine是免费的3D游戏引擎,几乎支持制作游戏所需的所有内容。 它具有易于使用的界面,既简单又强大。
包内有一个jsf例子,多个struts tiles例子 是学习框架不错的例子!
sun sun 精华sun sun 精华sun sun 精华sun sun 精华sun sun 精华
新的网格将基于Solaris 10 操作系统、Sun N1 Grid Engine软件,采用306 部HTSun Fire x64 (x86, 64 位)服务器和Sun StorEdge L8500TH带库,运行复杂的、数据密集的应用程序,帮助LONI研究某些脑疾病的起因、治疗和...
sun 文档sun 文档sun 文档sun 文档sun 文档sun 文档sun 文档sun 文档sun 文档sun 文档sun 文档sun 文档sun 文档sun 文档sun 文档sun 文档sun 文档
不用介绍了吧! Sun J2EE 宠物店.rar ...Sun J2EE 宠物店例子介绍_1.doc Sun J2EE 宠物店例子介绍_2.doc 相关网址.txt 原始码追踪记(1).pdf 原始码追踪记(2)-Model 篇.pdf 原始码追踪记(3)-商业逻辑处理.pdf
sun产品手册sun产品手册sun产品手册sun产品手册sun产品手册
一个最基本也是最容易明白的例子,适合初学J2EE的人
最近项目实验发现导入工具程序后项目有错,查看发现sun.misc.BASE64Decoder和sun.misc.BASE64Encoder不可用,找不到相应的类。 二、原因分析 冲浪后发现JDK中的lib\tools.jar和JRE中的lib\rt.jar已从Java SE 9中...