I am quite new to android development, I know the basics activities, maps, sqlite, etc. I would like to be able to implement some 3D objects to be able to interact with within my apps. After a bit of searching I found that rajawali seems to be the best method. As you do I started with the first tutorial and reading the source code from the example docs. Where I have become lost is I have followed the tutorial word for word and and I cant run the application due to errors in the script. If anybody has used Rajawali before I would appreiate some pointers as to where I have gone wrong. (the tutorial was last updated 2 month ago so its quite recent). Tutorial
Here is my source code
MainActivity:
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);
}
}
Renderer:
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);
}
}
I don't realy want to be spoon feed code if I can help it but it appears that the error is in the 'DiffuseMaterial'. Why is this or is there a better way of manipulating 3D objects other than using min3D or Rajawali?
I also have been trying to run this rajawali tutorial using next code.
Class 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);
}
}
Class 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);
}
}
See that changes are:
sphere
object as Object3D
instead Sphere
.DiffuseMaterial
by Material
for material declaration.Texture
. First parameter is an custom identifier and second parameter is the resource id.material.setColorInfluence(0);
after load texture, if this line isn't added, the "heart" becomes red (I'm not sure why).sphere
object by scene object (accessing with getCurrentScene
method) to call addLight
method.material.addTexture()
as this method now throws a TextureExceptiongetCurrentCamera().setZ(4.2f);
to the end of initSceneIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With