2013-06-08 2 views
-1

elcipes는 내 vertBuff.put (정점); --- Type FloatBuffer의이 putput (float f)은 인수 (Float [])에 적용 할 수 없습니다. 이 오류를 어떻게 수정합니까? vertBuff.put를 (이 을 heres 코드)어떻게하면 .put (float f)가 Float []을 사용할 수 있습니까?

 `public class Object { 

private float rgbaVals[] = { 1, 1, 0, .5f, .25f, 0, .85f, 1, 0, 1, 1, 1 }; 

private FloatBuffer colorBuff; 

private FloatBuffer vertBuff; 

public short[] pIndex = { 0, 1, 2 };// this is the array for the drawing 
            // order 

private ShortBuffer pBuff; 

    public void Line(Float vertex, Short Index){ 
     Float vertices = vertex; 
     Short pIndex = Index; 
    } 
public Object(Float[] vertices) { 

    ByteBuffer bBuff = ByteBuffer.allocateDirect(Float.SIZE * 4); 
    bBuff.order(ByteOrder.nativeOrder()); 
    vertBuff = bBuff.asFloatBuffer(); 
    vertBuff.put(vertices);  <--------------this is where the problem is at.   
    vertBuff.position(0); 

    ByteBuffer pbBuff = ByteBuffer.allocateDirect(Short.SIZE * 2); 
    pbBuff.order(ByteOrder.nativeOrder()); 
    pBuff = pbBuff.asShortBuffer(); 
    pBuff.put(pIndex); 
    pBuff.position(0); 

    ByteBuffer cBuff = ByteBuffer.allocateDirect(rgbaVals.length * 4); 
    cBuff.order(ByteOrder.nativeOrder()); 
    colorBuff = cBuff.asFloatBuffer(); 
    colorBuff.put(rgbaVals); 
    colorBuff.position(0); 
} 

public void draw(GL10 gl) { 
    // TODO Auto-generated method stub 
    gl.glFrontFace(GL10.GL_CW); 
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); 
    gl.glEnableClientState(GL10.GL_COLOR_ARRAY); 
    gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertBuff); 
    gl.glColorPointer(4, GL10.GL_FLOAT, 0, colorBuff); 
    gl.glDrawElements(GL10.GL_TRIANGLES, pIndex.length, 
      GL10.GL_UNSIGNED_SHORT, pBuff); 
    gl.glDisableClientState(GL10.GL_COLOR_ARRAY); 
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); 
} 

}`

을 heres MainActivity 클래스

public class MainActivity extends Activity implements OnClickListener { 
public ArrayList<Short> indexP = new ArrayList<Short>(); 
public ArrayList<Float> linep = new ArrayList<Float>(); 
public Float coords = (float) 0; 
public short p = 0; 
public int l = 0; 
GLSurfaceView ourSurface; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.cad); 
    ourSurface = new GLSurfaceView(this); 
    FrameLayout v = (FrameLayout) findViewById(R.id.display); 
    v.addView(ourSurface); 
    ourSurface.setRenderer(new GLRenderer()); 

    Button line = (Button) findViewById(R.id.line); 
    final Button enter = (Button) findViewById(R.id.enter); 
    EditText cl = (EditText) findViewById(R.id.cl); 
    final String value = cl.getText().toString(); 

    try { 
     coords = Float.parseFloat(value); 
    } catch (NumberFormatException e) { 
    } 
    ; 

    line.setOnClickListener(this); 
    enter.setOnClickListener(this); 

} 

public void onClick(View v) { 
    Short Index[]; 
    Float vertex[]; 
    TextView info = (TextView) findViewById(R.id.info); 
    switch (v.getId()) { 
    case R.id.line: 
     info.setText("Input X"); 
    case R.id.enter: 
     switch (l) { 
     case (0): 
      linep.add(coords); 
      l++; 
      info.setText("Input Y"); 
      break; 
     case (1): 
      linep.add(coords); 
      indexP.add(p); 
      l = 0; 
      p++; 
      vertex = linep.toArray(new Float[linep.size()]); 
      Index = indexP.toArray(new Short[indexP.size()]); 
      break; 
     } 
    } 

} 

public void Setvertex() { 

} 

@Override 
protected void onPause() { 
    // TODO Auto-generated method stub 
    super.onPause(); 
} 

@Override 
protected void onResume() { 
    // TODO Auto-generated method stub 
    super.onResume(); 
} 

}

답변

1

Floatfloat 같은 것이 아니다; 전은 autoboxing type입니다. 원시 객체를 래핑하여 Object로 전달하고 일반 유형으로 사용할 수있는 객체입니다.

배열을 선언/전달할 때 Float[] vertices은 배열이 Float임을 의미합니다. 이 배열을 프리미티브의 배열 인 float[]으로 사용할 수 없습니다. autoboxing은 배열 객체로 확장되지 않습니다.

FloatBufferput(float[])입니다. verticesFloat[] 대신 float[]을 사용해야합니다.

+0

알아요. 하지만 그때 나는 MainActivity 클래스에서 그것을 변경해야하고 그 다음 나는 arraylist와 함께 문제를 해결해야합니다. –