Pau*_*ger 5 java android opengl-es-2.0 rajawali
我对Android开发很新,我知道基本活动,地图,sqlite等.我希望能够实现一些3D对象,以便能够在我的应用程序中进行交互.经过一番搜索,我发现rajawali似乎是最好的方法.正如您所做的那样,我从第一篇教程开始,并从示例文档中读取源代码.我迷失的地方是我逐字逐句地遵循了教程,由于脚本中的错误,我无法运行应用程序.如果有人使用Rajawali之前我会指出一些关于我哪里出错的指示.(该教程最后更新于2个月前,因此它最近更新).教程
这是我的源代码
主要活动:
package rajawali.tutorials;
import rajawali.RajawaliActivity;
import android.os.Bundle;
import android.view.Menu;
public class MainActivity extends RajawaliActivity {
private Renderer mRenderer;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mRenderer = new Renderer(this);
mRenderer.setSurfaceView(mSurfaceView);
super.setRenderer(mRenderer);
}
}
Run Code Online (Sandbox Code Playgroud)
渲染:
package rajawali.tutorials;
import javax.microedition.khronos.opengles.GL10;
import android.content.Context;
import rajawali.lights.DirectionalLight;
import rajawali.materials.textures.ATexture.TextureException;
import rajawali.materials.textures.Texture;
import rajawali.primitives.Sphere;
import rajawali.renderer.RajawaliRenderer;
public class Renderer extends RajawaliRenderer {
private DirectionalLight mLight;
Sphere mSphere;
public Renderer(Context context) {
super(context);
setFrameRate(60);
}
public void initScene() {
mLight = new DirectionalLight(1f, 0.2f, -1.0f);
mLight.setColor(1.0f, 1.0f, 1.0f);
mLight.setPower(2);
try {
*DiffuseMaterial* material = new *DiffuseMaterial*(); //there is an error here (DiffuseMaterial cannot be rsolved as a type)
material.addTexture(new *Texture(R.drawable.earthtruecolor_nasa_big)*); //here (constructor Texture(int) cannot be defined)
mSphere = new Sphere(1, 24, 24);
mSphere.setMaterial(material);
mSphere.*addLight(mLight)*; //and here (The method addLight(DirectionalLight) is undefined for the type Sphere)
addChild(mSphere);
} catch (TextureException e) {
e.printStackTrace();
}
getCurrentCamera().setZ(4.2f);
}
@Override
public void onDrawFrame(GL10 glUnused) {
super.onDrawFrame(glUnused);
mSphere.setRotY(mSphere.getRotY() + 1);
}
}
Run Code Online (Sandbox Code Playgroud)
如果我可以提供帮助,我真的不想成为勺子饲料代码,但似乎错误出现在'DiffuseMaterial'中.除了使用min3D或Rajawali之外,为什么还有更好的方法来操作3D对象?
小智 7
我也一直试图使用下一个代码来运行这个rajawali教程.
类RajawaliTutorialActivity
package rajawali.tutorials;
import rajawali.RajawaliActivity;
import android.os.Bundle;
public class RajawaliTutorialActivity extends RajawaliActivity {
public RajawaliTutorialRenderer mRenderer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mRenderer = new RajawaliTutorialRenderer(this);
mRenderer.setSurfaceView(mSurfaceView);
super.setRenderer(mRenderer);
}
}
Run Code Online (Sandbox Code Playgroud)
类RajawaliTutorialRenderer
package rajawali.tutorials;
import javax.microedition.khronos.opengles.GL10;
import android.content.Context;
import rajawali.Camera;
import rajawali.Object3D;
import rajawali.lights.DirectionalLight;
import rajawali.materials.Material;
import rajawali.materials.textures.ATexture.TextureException;
import rajawali.materials.textures.Texture;
import rajawali.primitives.Sphere;
import rajawali.renderer.RajawaliRenderer;
public class RajawaliTutorialRenderer extends RajawaliRenderer {
public DirectionalLight light;
public Object3D sphere;
public Context context;
public Camera camera;
public RajawaliTutorialRenderer(Context context) {
super(context);
this.context = context;
setFrameRate(60);
}
public void initScene() {
light = new DirectionalLight(1f, 0.2f, -1.0f); // set the direction
light.setColor(1.0f, 1.0f, 1.0f);
light.setPower(2);
try{
Material material = new Material();
material.addTexture(new Texture("earthColors", R.drawable.earthtruecolor_nasa_big));
material.setColorInfluence(0);
sphere = new Sphere(1, 24, 24);
sphere.setMaterial(material);
getCurrentScene().addLight(light);
super.addChild(sphere);
} catch (TextureException e){
e.printStackTrace();
}
getCurrentCamera().setZ(4.2f);
}
@Override
public void onDrawFrame(GL10 glUnused) {
super.onDrawFrame(glUnused);
sphere.setRotY(sphere.getRotY() + 1);
}
}
Run Code Online (Sandbox Code Playgroud)
看到更改是:
sphere对象.Object3DSphereDiffuseMaterial通过Material对材料的申报.Texture.第一个参数是自定义标识符,第二个参数是资源ID.material.setColorInfluence(0);在加载纹理后添加该行,如果未添加此行,则"heart"变为红色(我不知道为什么).sphere场景对象替换对象(用getCurrentScene方法访问)来调用addLight方法.material.addTexture()因为此方法现在抛出TextureExceptiongetCurrentCamera().setZ(4.2f);到initScene的末尾| 归档时间: |
|
| 查看次数: |
6201 次 |
| 最近记录: |