Rajawali-天空盒的使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/liuyizhou95/article/details/79577180

距离上一篇rajawali初探过去很久了,一直没有更过,直接进入正题

与很多引擎一样,rajawali给天空盒的运用封装了一层api,直接调用即可

首先我们需要明确rajawali的使用:activity 、surface、 render是必须要有的

在render中我们要继承RajawaliRenderer并重写initScene方法,基本上所有的3D场景中的东西都在这个方法中实现


这里我们在场景中创建了一个球体,并贴上了地球的材质贴图,然后通过

getCurrentScene().setSkybox方法传入六张天空盒贴图
 public void initScene(){
        Material material = new Material();
        material.enableLighting(true);
        material.setDiffuseMethod(new DiffuseMethod.Lambert());
        material.setColor(0);
        earthSphere = new Sphere(1, 24, 24);
        earthSphere.setMaterial(material);
        getCurrentScene().addChild(earthSphere);
        getCurrentCamera().setZ(4.2f);
        Texture earthTexture = new Texture("Earth", R.drawable.earthtruecolor_nasa_big);
        try{
            material.addTexture(earthTexture);

        } catch (ATexture.TextureException error){
            Log.d("DEBUG", "TEXTURE ERROR");
        }
        try {
            getCurrentScene().setSkybox(R.drawable.posx, R.drawable.negx,
                    R.drawable.posy, R.drawable.negy, R.drawable.posz, R.drawable.negz);
        } catch (ATexture.TextureException e) {
            e.printStackTrace();
        }
        directionalLight = new DirectionalLight(1f, .2f, -1.0f);
        directionalLight.setColor(1.0f, 1.0f, 1.0f);
        directionalLight.setPower(2);
        getCurrentScene().addLight(directionalLight);

    }

到此一个最基本的rajawali的3d场景搭建完毕。

项目下载地址:https://download.csdn.net/download/liuyizhou95/10289815






猜你喜欢

转载自blog.csdn.net/liuyizhou95/article/details/79577180