开始翻译JME文档

第一次翻译,估计会很慢...

Introduction to SimpleGame

SimpleGame is a default application type that is included in the jME package. SimpleGame attempts to take care of everything for you. This makes it easy to get prototypes up and running. It sets up all the elements such as Camera, InputHandler, basic RenderStates, etc. I'll run through creating a simple application that draws a Sphere to the screen first, then the next tutorial we will create our own Application type to give you a better understanding of what is going on and better control.


第一个小例子SimpleGame是一个默认的程序类型,包括jme的包.SimpleGame帮你注意任何事情.它很容易的获取原型和运行.它已经设置好了包括Camera,输入帮助类,基本的渲染,等等.我将首先创建一个简单的程序,程序绘画一个球,然后创建一个我们自己的应用程序让我们更好的明白它是怎么运作的和如何更好的控制它.

First, we will create a new class that extends SimpleGame. In my case, I'm creating a class Lesson1:

 
 
public class Lesson1 extends SimpleGame {}

首先,我们创建一个类并继承SimpleGame,我创建了一个名字为Lesson1的类:

SimpleGame contains one abstract method: simpleInitGame. It is in this method that we will create the Sphere. Add the simpleInitGame method for now, we will come back to the Sphere later. First, we want to discuss the main method. This is the entry point for the jME application (just like any Java application). During creation, you must create your application and tell it to start executing the game loop. The Main Game Loop executes the update/render cycle until notified to exit and clean up. To start this loop a call to start is required.

SimpleGame包括一个抽象方法:simpleInitGame().这是一个用来创建球的方法.先加上simpleInitGame方法,我们将在后面调用它,首先我们说说main方法.main方法是jME程序的入口点(就像所有的java程序那样).在创建的时候,你必须创建你的应用程序然后告诉程序用start()方法开始执行程序.main方法执行更新/渲染的循环直到通知其结束和清理为止.启动程序必须调用start()方法.

To allow the user to specify the window parameters (resolution, fullscreen, etc), we will always display the PropertiesDialog. Do do this, we set the application behavior to ConfigShowMode.AlwaysShow.

程序允许用户指定窗口参数(分辨率,全屏,等等),我们希望一直显示会话属性那么设置程序的行为为ConfigShowMode.AlwaysShow.

下面是完整程序源码

import com.jme.app.SimpleGame;
?
public class Lesson1 extends SimpleGame {
/**
* Main method is the entry point for this lesson. It creates a
* SimpleGame and tells the dialog to always appear. It then
* starts the main loop.
* @param args
*/
public static void main(String[] args) {
Lesson1 app = new Lesson1();
app.setConfigShowMode(ConfigShowMode.AlwaysShow);
app.start();
}
?
protected void simpleInitGame() {
?
}
?
}

The above code should actually compile and run, creating a blank window (with exception to the framerate and triangle count text).

上面的代码是可以编译运行的,就是创建了一个空白的窗口(有异常输出,帧率,三角形)

Displaying Something

Now, we want to add to the simpleInitGame to display a textured Sphere. To do so, we need to:

  • Load the Sphere
  • Load an image
  • Apply the image to the Sphere as a texture
  • Add the Sphere to the scene
现在,我们想要添加 simpleInitGame()显示一个贴图的球型.做这个球,我们需要这样做:
  • 读取球
  • 读取图片
  • 应用图片到球身上
  • 添加这个贴图的球到场景

Creation of the Sphere is as simple as creating a new Sphere object.

创建这个球是很简单的,就是创建了一个球的对象(Sphere object.)

 
  
Sphere s = new Sphere("Sphere", 30, 30, 25);
s.setLocalTranslation(new Vector3f(0,0,-40));
s.setModelBound(new BoundingBox());
s.updateModelBound();

You define the number of sections on the vertical and the horizontal (in this case 30 and 30) and its radius (25). That is it. We now have a sphere. We can then manipulate the position of the Sphere. In this case, we want to move it along the negative Z direction (this is equivalent to moving it “into” the screen). We then set up the Bounding Volume of the Sphere. This allows the Camera's Frustum Culling to work. This means, if we turn the camera away from the Sphere, it will not be drawn (and you will see the statistics drop to 0).

你定义了几个零件它的垂直和水平参数(在这个例子里是30X30)它的半径是(25).现在我们有一个球了.然后我们可以操作求得位置,在这个例子里,我们希望移动它的Z坐标为负值(就相当于把它移进屏幕里).然后我们设置这个球的约束(Bounding Volume).这允许视角平移(??不确定).这意味着如果我们视角离开球,这个球就不再被绘画了(你将看到统计信息掉到0,.....不明白啥意思)

Next, we will load the Monkey.jpg image and apply it as a texture to the Sphere. To load an image and obtain a Texture, we make use of the TextureManager and its loadTexture method. We will load the image with basic Texture values.

接下来,我们将读取Monkey.jpg图片再应用其贴到那个球上去.读取图片和获取贴图我们使用TextureManager管理器的读取贴图的方法.我们将读取图片的基本贴图值

Texture texture = TextureManager.loadTexture(
Lesson1.class.getClassLoader().getResource(
"jmetest/data/images/Monkey.jpg"),
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear);

We then create a TextureState and set this texture to it. To create the TextureState we use DisplaySystem as a factory method. SimpleGame has a reference to the current DisplaySystem instance: 'display'.

然后我们创建一个TextureState.java设置贴图到其上.创建TextureState我们用DisplaySystem用工厂方法.SimpleGame参考当前DisplaySystem的实例'display'

 
  
TextureState ts = display.getRenderer().createTextureState();

Sets if this render state is enabled during rendering:

 
  
ts.setEnabled(true);

We then make use of the setTexture method to place the Texture of the Monkey.jpg image into the TextureState. The TextureState is now ready to be applied to the Sphere, and a call to setRenderState does this. Now that this TextureState is attached to the Sphere whenever the Sphere is rendered, it will use its texture coordinates and apply the image to itself.

然后我们用setTexture()方法任命贴图Monkey.jpg到TextureState上.那么现在调用setRenderState()方法来使得TextureState的贴图应用到球上.当球被渲染的时候TextureState已经附到球上了,它僵尸用贴图坐标和图片

 
  
ts.setTexture(texture);
s.setRenderState(ts);

Last, we attach the Sphere to the scene. SimpleGame provides an object call rootNode that represents the main scene. Attaching the Sphere to this Node prepares it for rendering. To attach, simply call:

最后,我们把球附给场景.SimpleGame提供了一个对象叫rootNode,表示主场景.把球附给这个Node准备渲染,方法为:

 
  
rootNode.attachChild(s);

With these few simple calls we have a textured Sphere rendered to the screen.

用以上的方法我们简单的把一个贴图了的球渲染到屏幕上了.

SimpleGame, like its name implies, makes things simple. However, for creating a full fledged game, we are going to want complete control. Next lesson will show us how to do this, by creating our own game type.

SimpleGame,就像名字一样,很简单.然而,做一个羽翼丰满的游戏,我们需要完全的控制,下一讲将讲述如何控制.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值