( Note: the starter tutorials in this wiki are not always up to date
with the latest development version of jME. You can find up to date
source files for the tutorials here: https://jme.dev.java.net/source/browse/jme/src/jmetest/TutorialGuide/
)
This program introduces Nodes, Bounding Volumes, Sphere, Colors, Translation and Scaling.
(注解:这份指南在wiki上并不一定是跟最新的jME开发版本一样.你可以在http://code.google.com/p/jmonkeyengine/source/browse/#svn/trunk/src/jmetest/TutorialGuide
找到最新的源码文件)
这里我们将介绍Nodes, Bounding Volumes, Sphere, Colors, Translation and Scaling.
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.LightState;
/**
* Started Date: Jul 20, 2004<br><br>
*
* Simple Node object with a few Geometry manipulators.
*
* @author Jack Lindamood
*/
public class HelloNode extends SimpleGame {
public static void main(String[] args) {
HelloNode app = new HelloNode();
app.setConfigShowMode(ConfigShowMode.AlwaysShow);
app.start();
}
protected void simpleInitGame() {
Box b=new Box("My Box",new Vector3f(0,0,0),new Vector3f(1,1,1));
// Give the box a bounds object to allow it to be culled
b.setModelBound(new BoundingSphere());
// Calculate the best bounds for the object you gave it
b.updateModelBound();
// Move the box 2 in the y direction up
b.setLocalTranslation(new Vector3f(0,2,0));
// Give the box a solid color of blue.
b.setDefaultColor(ColorRGBA.blue.clone());
Sphere s=new Sphere("My sphere",10,10,1f);
// Do bounds for the sphere, but we'll use a BoundingBox this time
s.setModelBound(new BoundingBox());
s.updateModelBound();
// Give the sphere random colors
s.setRandomColors();
// Make a node and give it children
Node n=new Node("My Node");
n.attachChild(b);
n.attachChild(s);
// Make the node and all its children 5 times larger.
n.setLocalScale(5);
// Remove lighting for rootNode so that it will use our
//basic colors.
rootNode.setLightCombineMode(Spatial.LightCombineMode.Off);
rootNode.attachChild(n);
}
}
The first new thing you see is:
首先你会看到的是
// Give the box a bounds object to allow it to be culled
b.setModelBound(new BoundingSphere());
Bounding Volumes (such as BoundingSphere and BoundingBox) are the key
to speed in jME. What happens is your object is surrounded by a bounds,
and this bounds allows jME to do a quick, easy test to see if your
object is even viewable. So in your game, you’ll make this really
complex person and surround him with a sphere, for instance. A sphere
is a really easy object mathematically, so jME can tell very fast if
the sphere around your object is visible. If the sphere surrounding
your guy isn’t visible (which is an easy test), then jME doesn’t even
bother trying to draw your really large, very complex person. In this
example, I surround my box with a sphere, but it makes more sense to
surround it with a BoundingBox. Why? Well trying to draw a sphere
around a box isn’t as tight a fit as a Box around a Box (obviously).
I'd just use a sphere as an example.
边界设定(类似BoundingSphere(球形边界) 和 BoundingBox(盒子边界))以加速jMe.对象被边界包裹,这个边界使jME快捷,简单的测试对象是否可见.在游戏中创建更加复杂的人物和被边界包裹的sphere,这里就是一个例子.
TODO,这段不太会翻...汗啊
就是边界,碰撞检测之类的东西.程序运行起来的时候按"B"可以看的到包裹的边界的.
// Calculate the best bounds for the object you gave it
b.updateModelBound();
When I start, I give my Box object bounds, but it’s an empty bounds.
I now have to “update” the bounds so that it surrounds the object
correctly. Now we’ll move it up:
我刚开始给了Box对象一个范围,并不是空的范围.我现在不得不"更新"范伟以便对象可以正确.我现在移动它
// Move the box 2 in the y direction up
b.setLocalTranslation(new Vector3f(0,2,0));
Now we start moving our object. Vector3f has the format x, y, z, so
this moves the object 2 units up. Remember how our Box looks above the
Sphere? That’s because I moved it up some. If I had used
Vector3f(0,-2,0) then it would have moved down two. Moving objects in
jME is extremely simple. Now color it:
现
在我们开始移动我们的对象.Vector3f有x,y,z这样的格式,所以这就把对象向上移动了2个单位.记住我们怎么把对象移动的看起来像是向上(向屏
幕外)了,如果是用Vector3f(0,-2,0)就是把对象向下(向屏幕里)移动了.在jMe移动对象是非常简单的.现在给对象上色:
// Give the box a solid color of blue.
b.setDefaultColor(ColorRGBA.blue.clone());
Just looking at the function, you can tell I give my box a solid
color. As you can guess by the color type, the color is blue.
ColorRGBA.red would make it… red! You can also use new
ColorRGBA(0,1,0,1). These four numbers are: Red/Green/Blue/Alpha and
are percentages from 0 to 1. Alpha is lingo for how opaque it is. (The
opposite of opaque is transparent. Opaque would be a wall; not opaque
would be a window.) So, an alpha of 0 would mean we couldn’t see it at
all, while .5 would mean we see half way through it. New
ColorRGBA(0,1,1,1) would create a color that is green and blue. Now
let’s make a sphere:
就
像方法写的那样,可以给box一个统一的颜色.你可以猜猜看颜色的种类.这里我们用的是蓝色.ColorRGBA.red就是上红色!也可以用
ColorRGBA(0,1,0,1).这四个数字的意思是:红/绿/蓝/Alpha和百分比0到1.Alpha是表示是不是透明的.(相反不透明是透明
的,不透明的将是一个墙;没有不透明的将是一个窗口).因此,一个字母的0将意味着它是透明的,而0.5意味着我们看到一半。新ColorRGBA (
0,1,1,1 )将建立一个颜色,绿色和蓝色。现在让我们做一个sphere:
Sphere s=new Sphere("My sphere",10,10,1f);
jME can’t draw curves. It draws triangles. It’s very hard to draw a
circle with triangles, isn’t it? Because of this, you have to get as
close to a circle as you can. The first two numbers represent that
closeness. If you change 10, 10 to 5,5 you’ll see a pretty bad looking
sphere. If you make them 30, 30 you’ll see a very round looking sphere
but the problem is that it’s made of a lot of triangles. More triangles
mean slower FPS. The last number, 1, is the radius of the sphere. Just
like my Node and my Box, Sphere needs a name which I give “My sphere”.
For our sphere, let’s be a bit prettier with colors:
jME
不能画曲线.可以画三角形.用三角形画圆是很困难的,是吗?正因为如此,你必须得到接近圆形的.头两个数字是控制接近圆形的.如果你把10改成5那么你会
看到一个五角星,如果你改成30你会看到一个很圆的圆形,但是这样会画很多个三角形,三角形多了意味着拖慢FPS.最后一个数字,1,是圆形的半径,就像
Node和BOx那样,Sphere需要一个名字,像"My sphere".下来为我们的圆球上点颜色:
// Give the sphere random colors
s.setRandomColors();
This gives each vertex of the sphere a random color, which creates that psychodelic effect you saw. Now on to the node:
随机的给顶点上颜色,弄出了一个迷幻的效果.下来附到Node上去:
// Make a node and give it children
Node n=new Node("My Node");
n.attachChild(b);
n.attachChild(s);
Instead of attaching our box and sphere to the rootNode, we create a
new node n to attach them too. I also wanted n (and all its children)
to be five times bigger, so I did this:
我们创建了一个Node用来承载我们的box和sphere,然后把node附到rootNode上去.我还希望node(其上所有的元素)都变成5倍大,看下面:
// Make the node and all its children 5 times larger.
n.setLocalScale(5);
You’ll notice it’s similar to the function call setLocalTranslation
in name. There’s also a setLocalRotation, which we’ll get into later.
As the name suggests, this makes everything five times larger. Finally,
you’ll notice a strange line at the end of my code:
你会注意到这很像setLocalTranslation()方法.这儿还有一个叫setLocalRotation()的方法,之后我们会讲到.看名字就知道这个方法是的所有的元素都放大五倍了.最后,会注意到最后一行很气怪的代码:
// Remove lighting for rootNode so that it will use our
//basic colors.
rootNode.setLightCombineMode(Spatial.LightCombineMode.Off);
You see, per vertex colors (which is what I’m doing here) isn’t
really lighting. It’s a cheap, easy way to create colors. You’ll notice
there’s no shading for these colors at all. If you don’t use this line,
jME won’t try to use per vertex colors. The scene graph looks like
this:
你看,每个顶点的颜色并没有点亮.这是着色的简单方法.你会注意到这些颜色都没有底纹.如果你不写这一行,jME就不会为每一个顶点着色.现在场景的结构像下面这样:
rootNode |
“My Node” made 5x bigger |
“My box” moved 2 up. |
“My sphere” |
You’ll notice that because “My box” and “My sphere” are children of
“My Node”, they are made five times bigger as well. If I move “My Node”
down 10, then “My Box” and “My sphere” would move down 10, as well.
This is the ease of making a game with a scene graph.
你会注意到 “My box” 和 “My sphere” 是依附于
“My Node”的,他们都放大了5倍了.如果我向下移动"My Node"10个单位,那么“My Box”和“My sphere”都向下移动10个单位.
While you’re running the program, press “B” to see the bounding in
action. It is a neat way to visualize the parent/child scene graph
relationship. You can see the BoundingSphere around your box, the
BoundingBox around your sphere, and the automatic BoundingSphere around
“My node”:
当你运行程序的时候,按"B"就会看见元素的边界.用这个方法可以很好的看到场景内元素的依附关系.可以看到BoundingSphere(球形边界)包裹着你box,BoundingBox(盒子边界)包裹着sphere,
相关推荐
JME,以前被称为Java 2 Micro Edition,是Java平台的一个子集,用于嵌入式设备和移动设备,如智能手机和小型家电。ant-jme.jar可能包含了JME开发所需的特定任务或类库,使得开发者能够在这些资源有限的平台上使用Ant...
标题中的“联想的JME2207P键盘驱动”是指专门为联想品牌的一款键盘型号为JME2207P的设备设计的驱动程序。在计算机硬件系统中,驱动程序是连接操作系统与硬件设备的关键软件,它使得操作系统能够识别并控制特定硬件,...
标题中的“联想FN功能键 jme2207p键盘驱动. XP windows7”表明这是一个针对联想笔记本电脑的FN功能键以及JME2207P型号键盘的驱动程序,适用于Windows XP和Windows 7操作系统。FN键是许多笔记本电脑上常见的辅助功能...
联想键盘 LXB JME 7155P 驱动 功能键有效亲测 有音量调节键 邮件 关机 网页 各种功能键全部有效
RPG手机游戏开发代码,是一个完整的开发代码
jme-3.0.10 兼容): 版本:1.+ 分支:jme_3.0 JME3-JFX 需要 java 8,但是可以使用 java 7 在纹理上绘制视频。对于 jME SDK,您应该创建一个 java 8 平台,但是 java8 支持非常糟糕(因为它基于 netbeans 7)。 ...
Oracle JME SDK (Java Micro Edition Software Development Kit) 是Oracle公司为开发Java ME应用程序提供的一套工具集。这个压缩包"oracle-jmesdk-8-0-rr-nb-plugins.zip"包含了用于NetBeans集成开发环境(IDE)的插件...
"flash-cards-jme" 是一个基于 JavaScript 开发的项目,其主要目的是创建一款角形设计的闪存卡片工具,用于学习和记忆各种知识点。在第一天的开发阶段,这个项目可能涉及了基础的前端开发技术和JavaScript语言的核心...
标题中的"dgwqo.rar_JME"可能是指一个RAR压缩文件,其中包含了与JME(Java Micro Edition)相关的代码或资源。JME是Java平台的一个子集,主要用于开发移动设备、嵌入式系统和物联网(IoT)应用。这个压缩文件可能是...
《塔防游戏TankBattle3D-jMEGame:Java技术与Libgdx-ai-jme的融合创新》 在游戏开发领域,Java语言以其强大的跨平台能力和丰富的库支持,成为许多开发者的选择。本项目"TankBattle3D-jMEGame"正是这样一个以Java为...
### JME中文教程知识点概述 #### 一、jMonkeyEngine3简介 - **定义与特点**:jMonkeyEngine3(简称JME3)是一款纯Java编写的免费3D游戏引擎,具备丰富的功能集,适用于各类游戏开发需求。该引擎不仅功能全面,其...
标题 "jme5.5.zip" 提供的信息表明这是一个与Java Media Engine(JME)相关的压缩文件,版本为5.5。Java Media Engine是Java平台上的一个组件,用于处理多媒体内容,如音频、视频和图像。它允许开发者在Java应用程序...
用于更改联想的流媒体键盘的功能键F1~F12,恢复功能键的正常使用功能,该软件用于X64(64位)系统。
2. **配置文件**:Gradle构建文件(build.gradle)会包含JME3和JOGL的依赖项,以及自定义的构建任务。 3. **主类**:通常有一个启动类,它创建JME3的应用实例,设置窗口属性,并初始化场景。 4. **场景管理**:...
### JME3游戏开发引擎中文学习指南 #### 引言 JME3,全称jMonkeyEngine3,是一款开源的3D游戏开发引擎,专为Java开发者设计,旨在简化3D游戏和应用程序的开发过程。本文档将详细介绍如何在Netbeans6.x环境下搭建...
com.jme3.animation com.jme3.app com.jme3.app.state com.jme3.asset com.jme3.asset.pack com.jme3.asset.plugins com.jme3.audio com.jme3.audio.joal ...jme3tools.preview
代码测试环境:JME-2核心板+1T指令周期的STC单片机(51内核 STC12LE5A60S2)+33M晶振 单片机工作电压3.3V 程序默认IO连接方式: 控制线:RS-P3^5; WR-P3^6; RD-P3^7; CS-P1^0; REST-P1^2; 数据线: DB0-DB7依次连接P0^0...
**2. Java游戏开发** Java语言以其“一次编写,到处运行”的特性,在游戏开发领域找到了一席之地。jme3利用Java的面向对象特性和丰富的库资源,为开发者提供了便捷的3D游戏开发环境。在“Rise of Mutants”这款游戏...
标题中的"jme.rar_pcie"暗示我们正在讨论与JMicron JMC2x0系列PCI Express(PCIe)以太网适配器在Linux操作系统中的设备驱动程序有关的内容。这个压缩包可能包含了驱动程序的主要源代码文件,即"jme.c"和头文件"jme....