纯Java游戏引擎JME3入门
2018-11-26 07:57:41来源:博客园 阅读 ()
学安全方面久了,有点无聊,今天闲来无事
查了下除了Unity以外还有什么好用的游戏引擎,我尤其关注了Java写的游戏引擎
果然有,jMonkeyEngine,于是打算看看
JME简介:
package mygame; import com.jme3.app.SimpleApplication; import com.jme3.light.DirectionalLight; import com.jme3.scene.Mesh; import com.jme3.scene.shape.Box; import com.jme3.material.Material; import com.jme3.math.Vector3f; import com.jme3.scene.Geometry; public class Main extends SimpleApplication { public static void main(String[] args) { Main app = new Main(); app.start(); } @Override public void simpleInitApp() { Mesh box=new Box(1,1,1); Material mat=new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md"); Geometry geom = new Geometry("Box"); geom.setMesh(box); geom.setMaterial(mat); DirectionalLight sun =new DirectionalLight(); sun.setDirection(new Vector3f(-1,-2,-3)); rootNode.attachChild(geom); rootNode.addLight(sun); } }
cam.setLocation(new Vector3f(4.4114223f, 3.3620508f, 7.5415998f)); cam.setRotation(new Quaternion(-0.046265673f, 0.9518722f, -0.1815604f, -0.2425582f));
public static void main(String[] args) { AppSettings settings = new AppSettings(true); settings.setTitle("一个正方体"); settings.setResolution(1280, 1024); Main app = new Main(); app.setSettings(settings); app.setShowSettings(false); app.start(); }
package mygame; import com.jme3.app.SimpleApplication; import com.jme3.light.DirectionalLight; import com.jme3.scene.Mesh; import com.jme3.scene.shape.Box; import com.jme3.material.Material; import com.jme3.math.FastMath; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import com.jme3.scene.Geometry; import com.jme3.system.AppSettings; public class Main extends SimpleApplication { private Geometry geom; public static void main(String[] args) { AppSettings settings = new AppSettings(true); settings.setTitle("一个正方体"); settings.setResolution(1280, 1024); Main app = new Main(); app.setSettings(settings); app.setShowSettings(false); app.start(); } @Override public void simpleInitApp() { Mesh box = new Box(1, 1, 1); Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); geom = new Geometry("Box"); geom.setMesh(box); geom.setMaterial(mat); DirectionalLight sun = new DirectionalLight(); sun.setDirection(new Vector3f(-1, -2, -3)); rootNode.attachChild(geom); rootNode.addLight(sun); cam.setLocation(new Vector3f(4.4114223f, 3.3620508f, 7.5415998f)); cam.setRotation(new Quaternion(-0.046265673f, 0.9518722f, -0.1815604f, -0.2425582f)); } @Override public void simpleUpdate(float deltaTime) { float speed = FastMath.TWO_PI; geom.rotate(0, deltaTime * speed, 0); } }
package mygame; import com.jme3.app.SimpleApplication; import com.jme3.light.AmbientLight; import com.jme3.light.DirectionalLight; import com.jme3.math.ColorRGBA; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import com.jme3.scene.Geometry; import com.jme3.scene.Spatial; import com.jme3.system.AppSettings; public class Main extends SimpleApplication { private Geometry geom; public static void main(String[] args) { AppSettings settings = new AppSettings(true); settings.setTitle("诺手"); settings.setResolution(1280, 1024); Main app = new Main(); app.setSettings(settings); app.setShowSettings(false); app.start(); } @Override public void simpleInitApp() { cam.setLocation(new Vector3f(0.41600543f, 3.2057908f, 6.6927643f)); cam.setRotation(new Quaternion(-0.00414816f, 0.9817784f, -0.18875499f, -0.021575727f)); flyCam.setMoveSpeed(10); viewPort.setBackgroundColor(ColorRGBA.LightGray); Spatial model = assetManager.loadModel("Models/demo/Darius.obj"); model.scale(0.03f); model.center(); //定向光 DirectionalLight sun = new DirectionalLight(); sun.setDirection(new Vector3f(-1, -2, -3)); //环境光 AmbientLight ambient = new AmbientLight(); //调整光照亮度 ColorRGBA lightColor = new ColorRGBA(); sun.setColor(lightColor.mult(0.6f)); ambient.setColor(lightColor.mult(0.4f)); rootNode.attachChild(model); rootNode.addLight(sun); rootNode.addLight(ambient); } }
只有模型,没有贴图,可能是我没有导入吧。。。
无所谓了,我不是专业搞游戏的,今天只是想到了,随便看看
继续我的Kali学习之路。
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- 国外程序员整理的Java资源大全(全部是干货) 2020-06-12
- 2020年深圳中国平安各部门Java中级面试真题合集(附答案) 2020-06-11
- 2020年java就业前景 2020-06-11
- 04.Java基础语法 2020-06-11
- Java--反射(框架设计的灵魂)案例 2020-06-11
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash