Aller au contenu

Loader de fichier .obj


lucho9

Recommended Posts

Bonjour à tous.

En voulant compiler le code suivant une erreur que je n'arrive pas à réparer survient...

Voici le code :

package com.example.objLoader;

import android.app.Activity;

import android.opengl.GLSurfaceView;

import android.os.Bundle;

import android.os.Debug;

import android.os.Handler;

import android.os.Message;

import android.telephony.CellLocation;

/**

* The initial Android Activity, setting and initiating

* the OpenGL ES Renderer Class @see Lesson02.java

*

* @author Savas Ziplies (nea/INsanityDesign)

*/

public class ObjLoaderApp extends Activity {

/** The OpenGL View */

/**

* Initiate the OpenGL View and set our own

* Renderer (@see Lesson02.java)

*/

@Override

protected void onCreate(Bundle savedInstanceState) {

Debug.startMethodTracing("calc");

super.onCreate(savedInstanceState);

setContentView(new MyRenderer(this));

}

/**

* Remember to resume the glSurface

*/

@Override

protected void onResume() {

super.onResume();

}

/**

* Also pause the glSurface

*/

@Override

protected void onPause() {

Debug.stopMethodTracing();

super.onPause();

}

@Override

protected void onDestroy(){

Debug.stopMethodTracing();

}

}

package com.example.objLoader;

import java.io.BufferedReader;

import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.Vector;

import android.content.Context;

import android.util.Log;

public class OBJParser {

int numVertices=0;

int numFaces=0;

Context context;

Vector<Short> faces=new Vector<Short>();

Vector<Short> vtPointer=new Vector<Short>();

Vector<Short> vnPointer=new Vector<Short>();

Vector<Float> v=new Vector<Float>();

Vector<Float> vn=new Vector<Float>();

Vector<Float> vt=new Vector<Float>();

Vector<TDModelPart> parts=new Vector<TDModelPart>();

Vector<Material> materials=null;

public OBJParser(Context ctx){

context=ctx;

}

public TDModel parseOBJ(String fileName) {

BufferedReader reader=null;

String line = null;

Material m=null;

try { //try to open file

reader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));

} catch(IOException e){

}

try {//try to read lines of the file

while((line = reader.readLine()) != null) {

Log.v("obj",line);

if(line.startsWith("f")){//a polygonal face

processFLine(line);

}

else

if(line.startsWith("vn")){

processVNLine(line);

}

else

if(line.startsWith("vt")){

processVTLine(line);

}

else

if(line.startsWith("v")){ //line having geometric position of single vertex

processVLine(line);

}

/*else

if(line.startsWith("usemtl")){

try{//start of new group

if(faces.size()!=0){//if not this is not the start of the first group

TDModelPart model=new TDModelPart(faces, vtPointer, vnPointer, m,vn);

parts.add(model);

}

String mtlName=line.split("[ ]+",2)[1]; //get the name of the material

for(int i=0; i<materials.size(); i++){//suppose .mtl file already parsed

m=materials.get(i);

if(m.getName().equals(mtlName)){//if found, return from loop

break;

}

m=null;//if material not found, set to null

}

faces=new Vector<Short>();

vtPointer=new Vector<Short>();

vnPointer=new Vector<Short>();

}

catch (Exception e) {

// TODO: handle exception

}

}

else

if(line.startsWith("mtllib")){

materials=MTLParser.loadMTL(line.split("[ ]+")[1]);

for(int i=0; i<materials.size(); i++){

Material mat=materials.get(i);

Log.v("materials",mat.toString());

}

}*/

}

}

catch(IOException e){

System.out.println("wtf...");

}

if(faces!= null){//if not this is not the start of the first group

TDModelPart model=new TDModelPart(faces, vtPointer, vnPointer, m,vn);

parts.add(model);

}

TDModel t=new TDModel(v,vn,vt,parts);

t.buildVertexBuffer();

Log.v("models",t.toString());

return t;

}

private void processVLine(String line){

String [] tokens=line.split("[ ]+"); //split the line at the spaces

int c=tokens.length;

for(int i=1; i<c; i++){ //add the vertex to the vertex array

v.add(Float.valueOf(tokens));

}

}

private void processVNLine(String line){

String [] tokens=line.split("[ ]+"); //split the line at the spaces

int c=tokens.length;

for(int i=1; i<c; i++){ //add the vertex to the vertex array

vn.add(Float.valueOf(tokens));

}

}

private void processVTLine(String line){

String [] tokens=line.split("[ ]+"); //split the line at the spaces

int c=tokens.length;

for(int i=1; i<c; i++){ //add the vertex to the vertex array

vt.add(Float.valueOf(tokens));

}

}

private void processFLine(String line){

String [] tokens=line.split("[ ]+");

int c=tokens.length;

if(tokens[1].matches("[0-9]+")){//f: v

if(c==4){//3 faces

for(int i=1; i<c; i++){

Short s=Short.valueOf(tokens);

s--;

faces.add(s);

}

}

else{//more faces

Vector<Short> polygon=new Vector<Short>();

for(int i=1; i<tokens.length; i++){

Short s=Short.valueOf(tokens);

s--;

polygon.add(s);

}

faces.addAll(Triangulator.triangulate(polygon));//triangulate the polygon and add the resulting faces

}

}

if(tokens[1].matches("[0-9]+/[0-9]+")){//if: v/vt

if(c==4){//3 faces

for(int i=1; i<c; i++){

Short s=Short.valueOf(tokens.split("/")[0]);

s--;

faces.add(s);

s=Short.valueOf(tokens.split("/")[1]);

s--;

vtPointer.add(s);

}

}

else{//triangulate

Vector<Short> tmpFaces=new Vector<Short>();

Vector<Short> tmpVt=new Vector<Short>();

for(int i=1; i<tokens.length; i++){

Short s=Short.valueOf(tokens.split("/")[0]);

s--;

tmpFaces.add(s);

s=Short.valueOf(tokens.split("/")[1]);

s--;

tmpVt.add(s);

}

faces.addAll(Triangulator.triangulate(tmpFaces));

vtPointer.addAll(Triangulator.triangulate(tmpVt));

}

}

if(tokens[1].matches("[0-9]+//[0-9]+")){//f: v//vn

if(c==4){//3 faces

for(int i=1; i<c; i++){

Short s=Short.valueOf(tokens.split("//")[0]);

s--;

faces.add(s);

s=Short.valueOf(tokens.split("//")[1]);

s--;

vnPointer.add(s);

}

}

else{//triangulate

Vector<Short> tmpFaces=new Vector<Short>();

Vector<Short> tmpVn=new Vector<Short>();

for(int i=1; i<tokens.length; i++){

Short s=Short.valueOf(tokens.split("//")[0]);

s--;

tmpFaces.add(s);

s=Short.valueOf(tokens.split("//")[1]);

s--;

tmpVn.add(s);

}

faces.addAll(Triangulator.triangulate(tmpFaces));

vnPointer.addAll(Triangulator.triangulate(tmpVn));

}

}

if(tokens[1].matches("[0-9]+/[0-9]+/[0-9]+")){//f: v/vt/vn

if(c==4){//3 faces

for(int i=1; i<c; i++){

Short s=Short.valueOf(tokens.split("/")[0]);

s--;

faces.add(s);

s=Short.valueOf(tokens.split("/")[1]);

s--;

vtPointer.add(s);

s=Short.valueOf(tokens.split("/")[2]);

s--;

vnPointer.add(s);

}

}

else{//triangulate

Vector<Short> tmpFaces=new Vector<Short>();

Vector<Short> tmpVn=new Vector<Short>();

//Vector<Short> tmpVt=new Vector<Short>();

for(int i=1; i<tokens.length; i++){

Short s=Short.valueOf(tokens.split("/")[0]);

s--;

tmpFaces.add(s);

//s=Short.valueOf(tokens.split("/")[1]);

//s--;

//tmpVt.add(s);

//s=Short.valueOf(tokens.split("/")[2]);

//s--;

//tmpVn.add(s);

}

faces.addAll(Triangulator.triangulate(tmpFaces));

vtPointer.addAll(Triangulator.triangulate(tmpVn));

vnPointer.addAll(Triangulator.triangulate(tmpVn));

}

}

}

}

package com.example.objLoader;

public class RGBColor {

float R;

float G;

float B;

public RGBColor(float r, float g, float B) {

super();

R = r;

G = g;

B = b;

}

public float getR() {

return R;

}

public void setR(float r) {

R = r;

}

public float getG() {

return G;

}

public void setG(float g) {

G = g;

}

public float getB() {

return B;

}

public void setB(float B) {

B = b;

}

public String toString(){

String str=new String();

str+="R:"+R+" G:"+G+" B:"+B;

return str;

}

}

package com.example.objLoader;

import java.nio.ByteBuffer;

import java.nio.ByteOrder;

import java.nio.FloatBuffer;

import java.util.Vector;

import javax.microedition.khronos.opengles.GL10;

public class TDModel {

Vector<Float> v;

Vector<Float> vn;

Vector<Float> vt;

Vector<TDModelPart> parts;

FloatBuffer vertexBuffer;

public TDModel(Vector<Float> v, Vector<Float> vn, Vector<Float> vt,

Vector<TDModelPart> parts) {

super();

this.v = v;

this.vn = vn;

this.vt = vt;

this.parts = parts;

}

public String toString(){

String str=new String();

str+="Number of parts: "+parts.size();

str+="\nNumber of vertexes: "+v.size();

str+="\nNumber of vns: "+vn.size();

str+="\nNumber of vts: "+vt.size();

str+="\n/////////////////////////\n";

for(int i=0; i<parts.size(); i++){

str+="Part "+i+'\n';

str+=parts.get(i).toString();

str+="\n/////////////////////////";

}

return str;

}

public void draw(GL10 gl) {

gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

for(int i=0; i<parts.size(); i++){

TDModelPart t=parts.get(i);

Material m=t.getMaterial();

if(m!=null){

FloatBuffer a=m.getAmbientColorBuffer();

FloatBuffer d=m.getDiffuseColorBuffer();

FloatBuffer s=m.getSpecularColorBuffer();

gl.glMaterialfv(GL10.GL_FRONT_AND_BACK,GL10.GL_AMBIENT,a);

gl.glMaterialfv(GL10.GL_FRONT_AND_BACK,GL10.GL_SPECULAR,s);

gl.glMaterialfv(GL10.GL_FRONT_AND_BACK,GL10.GL_DIFFUSE,d);

}

gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);

gl.glNormalPointer(GL10.GL_FLOAT, 0, t.getNormalBuffer());

gl.glDrawElements(GL10.GL_TRIANGLES,t.getFacesCount(),GL10.GL_UNSIGNED_SHORT,t.getFaceBuffer());

//gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

//gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);

}

}

public void buildVertexBuffer(){

ByteBuffer vBuf = ByteBuffer.allocateDirect(v.size() * 4);

vBuf.order(ByteOrder.nativeOrder());

vertexBuffer = vBuf.asFloatBuffer();

vertexBuffer.put(toPrimitiveArrayF(v));

vertexBuffer.position(0);

}

private static float[] toPrimitiveArrayF(Vector<Float> vector){

float[] f;

f=new float[vector.size()];

for (int i=0; i<vector.size(); i++){

f=vector.get(i);

}

return f;

}

}

package com.example.objLoader;

import java.nio.ByteBuffer;

import java.nio.ByteOrder;

import java.nio.FloatBuffer;

import java.nio.ShortBuffer;

import java.util.Vector;

public class TDModelPart {

Vector<Short> faces;

Vector<Short> vtPointer;

Vector<Short> vnPointer;

Material material;

private FloatBuffer normalBuffer;

ShortBuffer faceBuffer;

public TDModelPart(Vector<Short> faces, Vector<Short> vtPointer,

Vector<Short> vnPointer, Material material, Vector<Float> vn) {

super();

this.faces = faces;

this.vtPointer = vtPointer;

this.vnPointer = vnPointer;

this.material = material;

ByteBuffer byteBuf = ByteBuffer.allocateDirect(vnPointer.size() * 4*3);

byteBuf.order(ByteOrder.nativeOrder());

normalBuffer = byteBuf.asFloatBuffer();

for(int i=0; i<vnPointer.size(); i++){

float x=vn.get(vnPointer.get(i)*3);

float y=vn.get(vnPointer.get(i)*3+1);

float z=vn.get(vnPointer.get(i)*3+2);

normalBuffer.put(x);

normalBuffer.put(y);

normalBuffer.put(z);

}

normalBuffer.position(0);

ByteBuffer fBuf = ByteBuffer.allocateDirect(faces.size() * 2);

fBuf.order(ByteOrder.nativeOrder());

faceBuffer = fBuf.asShortBuffer();

faceBuffer.put(toPrimitiveArrayS(faces));

faceBuffer.position(0);

}

public String toString(){

String str=new String();

if(material!=null)

str+="Material name:"+material.getName();

else

str+="Material not defined!";

str+="\nNumber of faces:"+faces.size();

str+="\nNumber of vnPointers:"+vnPointer.size();

str+="\nNumber of vtPointers:"+vtPointer.size();

return str;

}

public ShortBuffer getFaceBuffer(){

return faceBuffer;

}

public FloatBuffer getNormalBuffer(){

return normalBuffer;

}

private static short[] toPrimitiveArrayS(Vector<Short> vector){

short[] s;

s=new short[vector.size()];

for (int i=0; i<vector.size(); i++){

s=vector.get(i);

}

return s;

}

public int getFacesCount(){

return faces.size();

}

public Material getMaterial(){

return material;

}

}

package com.example.objLoader;

import java.util.Vector;

import android.util.Log;

public class Triangulator{

public static Vector<Short> triangulate(Vector<Short> polygon){

Vector<Short> triangles=new Vector<Short>();

for(int i=1; i<polygon.size()-1; i++){

triangles.add(polygon.get(0));

triangles.add(polygon.get(i));

triangles.add(polygon.get(i+1));

}

return triangles;

}

}

package com.example.objLoader;

import java.nio.ByteBuffer;

import java.nio.ByteOrder;

import java.nio.FloatBuffer;

public class Material {

String name;

float[] ambientColor; //ambient color

float[] diffuseColor;

float[] specularColor;

float alpha;

float shine;

int illum;

String textureFile;

public Material(String name){

this.name=name;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public float[] getAmbientColor() {

return ambientColor;

}

public FloatBuffer getAmbientColorBuffer(){

FloatBuffer f;

ByteBuffer b = ByteBuffer.allocateDirect(12);

b.order(ByteOrder.nativeOrder());

f = b.asFloatBuffer();

f.put(ambientColor);

f.position(0);

return f;

}

public void setAmbientColor(float r, float g, float B) {

ambientColor = new float[3];

ambientColor[0]=r;

ambientColor[1]=g;

ambientColor[2]=b;

}

public float[] getDiffuseColor() {

return diffuseColor;

}

public FloatBuffer getDiffuseColorBuffer(){

FloatBuffer f;

ByteBuffer b = ByteBuffer.allocateDirect(12);

b.order(ByteOrder.nativeOrder());

f = b.asFloatBuffer();

f.put(diffuseColor);

f.position(0);

return f;

}

public void setDiffuseColor(float r, float g, float B) {

diffuseColor = new float[3];

diffuseColor[0]=r;

diffuseColor[1]=g;

diffuseColor[2]=b;

}

public float[] getSpecularColor() {

return specularColor;

}

public FloatBuffer getSpecularColorBuffer(){

FloatBuffer f;

ByteBuffer b = ByteBuffer.allocateDirect(12);

b.order(ByteOrder.nativeOrder());

f = b.asFloatBuffer();

f.put(specularColor);

f.position(0);

return f;

}

public void setSpecularColor(float r, float g, float B) {

specularColor = new float[3];

specularColor[0]=r;

specularColor[1]=g;

specularColor[2]=b;

}

public float getAlpha() {

return alpha;

}

public void setAlpha(float alpha) {

this.alpha = alpha;

}

public float getShine() {

return shine;

}

public void setShine(float shine) {

this.shine = shine;

}

public int getIllum() {

return illum;

}

public void setIllum(int illum) {

this.illum = illum;

}

public String getTextureFile() {

return textureFile;

}

public void setTextureFile(String textureFile) {

this.textureFile = textureFile;

}

public String toString(){

String str=new String();

str+="Material name: "+name;

str+="\nAmbient color: "+ambientColor.toString();

str+="\nDiffuse color: "+diffuseColor.toString();

str+="\nSpecular color: "+specularColor.toString();

str+="\nAlpha: "+alpha;

str+="\nShine: "+shine;

return str;

}

}

package com.example.objLoader;

import java.io.BufferedReader;

import java.io.FileInputStream;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.Vector;

import android.content.Context;

public class MTLParser {

public static Vector<Material> loadMTL(String file){

BufferedReader reader=null;

Vector<Material> materials=new Vector<Material>();

String line;

Material currentMtl=null;

try { //try to open file

reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));

} catch(IOException e){

}

if(reader!=null){

try {//try to read lines of the file

while((line = reader.readLine()) != null) {

if(line.startsWith("newmtl")){

if(currentMtl!=null)

materials.add(currentMtl);

String mtName=line.split("[ ]+",2)[1];

currentMtl=new Material(mtName);

}

else

if(line.startsWith("Ka")){

String[] str=line.split("[ ]+");

currentMtl.setAmbientColor(Float.parseFloat(str[1]), Float.parseFloat(str[2]), Float.parseFloat(str[3]));

}

else

if(line.startsWith("Kd")){

String[] str=line.split("[ ]+");

currentMtl.setDiffuseColor(Float.parseFloat(str[1]), Float.parseFloat(str[2]), Float.parseFloat(str[3]));

}

else

if(line.startsWith("Ks")){

String[] str=line.split("[ ]+");

currentMtl.setSpecularColor(Float.parseFloat(str[1]), Float.parseFloat(str[2]), Float.parseFloat(str[3]));

}

else

if(line.startsWith("Tr") || line.startsWith("d")){

String[] str=line.split("[ ]+");

currentMtl.setAlpha(Float.parseFloat(str[1]));

}

else

if(line.startsWith("Ns")){

String[] str=line.split("[ ]+");

currentMtl.setShine(Float.parseFloat(str[1]));

}

else

if(line.startsWith("illum")){

String[] str=line.split("[ ]+");

currentMtl.setIllum(Integer.parseInt(str[1]));

}

else

if(line.startsWith("map_Ka")){

String[] str=line.split("[ ]+");

currentMtl.setTextureFile(str[1]);

}

}

}

catch (Exception e) {

// TODO: handle exception

}

}

return materials;

}

}

package com.example.objLoader;

import java.nio.ByteBuffer;

import java.nio.ByteOrder;

import java.nio.FloatBuffer;

import javax.microedition.khronos.egl.EGLConfig;

import javax.microedition.khronos.opengles.GL10;

import android.content.Context;

import android.opengl.GLSurfaceView;

import android.opengl.GLU;

import android.opengl.GLSurfaceView.Renderer;

import android.os.Debug;

import android.view.KeyEvent;

import android.view.MotionEvent;

public class MyRenderer extends GLSurfaceView implements Renderer {

/** Triangle instance */

private OBJParser parser;

private TDModel model;

/* Rotation values */

private float xrot; //X Rotation

private float yrot; //Y Rotation

/* Rotation speed values */

private float xspeed; //X Rotation Speed ( NEW )

private float yspeed; //Y Rotation Speed ( NEW )

private float z = 50.0f;

private float oldX;

private float oldY;

private final float TOUCH_SCALE = 0.4f; //Proved to be good for normal rotation ( NEW )

private float[] lightAmbient = {1.0f, 1.0f, 1.0f, 1.0f};

private float[] lightDiffuse = {1.0f, 1.0f, 1.0f, 1.0f};

private float[] lightPosition = {0.0f, -3.0f, 2.0f, 1.0f};

private FloatBuffer lightAmbientBuffer;

private FloatBuffer lightDiffuseBuffer;

private FloatBuffer lightPositionBuffer;

public MyRenderer(Context ctx) {

super(ctx);

parser=new OBJParser(ctx);

model=parser.parseOBJ("C:/Documents and Settings/p-naegelen/Bureau/export.obj");

Debug.stopMethodTracing();

this.setRenderer(this);

this.requestFocus();

this.setFocusableInTouchMode(true);

ByteBuffer byteBuf = ByteBuffer.allocateDirect(lightAmbient.length * 4);

byteBuf.order(ByteOrder.nativeOrder());

lightAmbientBuffer = byteBuf.asFloatBuffer();

lightAmbientBuffer.put(lightAmbient);

lightAmbientBuffer.position(0);

byteBuf = ByteBuffer.allocateDirect(lightDiffuse.length * 4);

byteBuf.order(ByteOrder.nativeOrder());

lightDiffuseBuffer = byteBuf.asFloatBuffer();

lightDiffuseBuffer.put(lightDiffuse);

lightDiffuseBuffer.position(0);

byteBuf = ByteBuffer.allocateDirect(lightPosition.length * 4);

byteBuf.order(ByteOrder.nativeOrder());

lightPositionBuffer = byteBuf.asFloatBuffer();

lightPositionBuffer.put(lightPosition);

lightPositionBuffer.position(0);

}

/**

* The Surface is created/init()

*/

public void onSurfaceCreated(GL10 gl, EGLConfig config) {

gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, lightAmbientBuffer);

gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuseBuffer);

gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPositionBuffer);

gl.glEnable(GL10.GL_LIGHT0);

gl.glShadeModel(GL10.GL_SMOOTH);

gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);

gl.glClearDepthf(1.0f);

gl.glEnable(GL10.GL_DEPTH_TEST);

gl.glDepthFunc(GL10.GL_LEQUAL);

gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);

}

/**

* Here we do our drawing

*/

public void onDrawFrame(GL10 gl) {

//Clear Screen And Depth Buffer

gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

gl.glLoadIdentity();

gl.glEnable(GL10.GL_LIGHTING);

gl.glTranslatef(0.0f, -1.2f, -z); //Move down 1.2 Unit And Into The Screen 6.0

gl.glRotatef(xrot, 1.0f, 0.0f, 0.0f); //X

gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f); //Y

model.draw(gl); //Draw the square

gl.glLoadIdentity();

xrot += xspeed;

yrot += yspeed;

}

/**

* If the surface changes, reset the view

*/

public void onSurfaceChanged(GL10 gl, int width, int height) {

if(height == 0) { //Prevent A Divide By Zero By

height = 1; //Making Height Equal One

}

gl.glViewport(0, 0, width, height); //Reset The Current Viewport

gl.glMatrixMode(GL10.GL_PROJECTION); //Select The Projection Matrix

gl.glLoadIdentity(); //Reset The Projection Matrix

//Calculate The Aspect Ratio Of The Window

GLU.gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 500.0f);

gl.glMatrixMode(GL10.GL_MODELVIEW); //Select The Modelview Matrix

gl.glLoadIdentity(); //Reset The Modelview Matrix

}

@Override

public boolean onTouchEvent(MotionEvent event) {

//

float x = event.getX();

float y = event.getY();

//If a touch is moved on the screen

if(event.getAction() == MotionEvent.ACTION_MOVE) {

//Calculate the change

float dx = x - oldX;

float dy = y - oldY;

//Define an upper area of 10% on the screen

int upperArea = this.getHeight() / 10;

//Zoom in/out if the touch move has been made in the upper

if(y < upperArea) {

z -= dx * TOUCH_SCALE / 2;

//Rotate around the axis otherwise

} else {

xrot += dy * TOUCH_SCALE;

yrot += dx * TOUCH_SCALE;

}

//A press on the screen

} else if(event.getAction() == MotionEvent.ACTION_UP) {

}

//Remember the values

oldX = x;

oldY = y;

//We handled the event

return true;

}

@Override

public boolean onKeyUp(int keyCode, KeyEvent event) {

//

if(keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {

} else if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {

} else if(keyCode == KeyEvent.KEYCODE_DPAD_UP) {

z -= 3;

} else if(keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {

z += 3;

} else if(keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {

}

//We handled the event

return true;

}

}

Et voici la liste d'erreurs que m'affiche le logcat :

06-04 13:00:19.563: E/AndroidRuntime(27399): FATAL EXCEPTION: main

06-04 13:00:19.563: E/AndroidRuntime(27399): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.objLoader/com.example.objLoader.ObjLoaderApp}: java.lang.NullPointerException

06-04 13:00:19.563: E/AndroidRuntime(27399): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1748)

06-04 13:00:19.563: E/AndroidRuntime(27399): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764)

06-04 13:00:19.563: E/AndroidRuntime(27399): at android.app.ActivityThread.access$1500(ActivityThread.java:122)

06-04 13:00:19.563: E/AndroidRuntime(27399): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002)

06-04 13:00:19.563: E/AndroidRuntime(27399): at android.os.Handler.dispatchMessage(Handler.java:99)

06-04 13:00:19.563: E/AndroidRuntime(27399): at android.os.Looper.loop(Looper.java:132)

06-04 13:00:19.563: E/AndroidRuntime(27399): at android.app.ActivityThread.main(ActivityThread.java:4025)

06-04 13:00:19.563: E/AndroidRuntime(27399): at java.lang.reflect.Method.invokeNative(Native Method)

06-04 13:00:19.563: E/AndroidRuntime(27399): at java.lang.reflect.Method.invoke(Method.java:491)

06-04 13:00:19.563: E/AndroidRuntime(27399): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)

06-04 13:00:19.563: E/AndroidRuntime(27399): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)

06-04 13:00:19.563: E/AndroidRuntime(27399): at dalvik.system.NativeStart.main(Native Method)

06-04 13:00:19.563: E/AndroidRuntime(27399): Caused by: java.lang.NullPointerException

06-04 13:00:19.563: E/AndroidRuntime(27399): at com.example.objLoader.OBJParser.parseOBJ(OBJParser.java:42)

06-04 13:00:19.563: E/AndroidRuntime(27399): at com.example.objLoader.MyRenderer.<init>(MyRenderer.java:50)

06-04 13:00:19.563: E/AndroidRuntime(27399): at com.example.objLoader.ObjLoaderApp.onCreate(ObjLoaderApp.java:29)

Si quelqu'un à une idée du problème qu'il fasse signe. :)

Merci d'avance.

Modifié par lucho9
  • Like 1
Lien vers le commentaire
Partager sur d’autres sites

Rejoignez la conversation

Vous pouvez poster maintenant et vous enregistrez plus tard. Si vous avez un compte, connectez-vous maintenant pour poster.

Invité
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Répondre à ce sujet…

×   Collé en tant que texte enrichi.   Coller en tant que texte brut à la place

  Seulement 75 émoticônes maximum sont autorisées.

×   Votre lien a été automatiquement intégré.   Afficher plutôt comme un lien

×   Votre contenu précédent a été rétabli.   Vider l’éditeur

×   Vous ne pouvez pas directement coller des images. Envoyez-les depuis votre ordinateur ou insérez-les depuis une URL.

×
×
  • Créer...