2013-06-04 2 views
2

jMonkey로 처음으로 작업하고 있습니다. 제 의도는 다른 세분으로 하나의 단일 삼각형 스트립으로 만든 쿼드를 만드는 것이 었습니다. 그래서 말할 수 있습니다 Subdivision x == 4;Subdivision y == 4; 이 경우 3 행의 삼각형과 3 개의 열이 있습니다.jMonkey Quad with TriangleStrip 캔트 변경 매개 변수

지금까지 문제가 해결되었지만 하위 번호를 변경하면 바로 예 : x==5, y==5 코드가 충돌합니다. 나는 누군가가 이것으로 나를 도울 수 있기를 바랍니다.

P.S : 내 영어 죄송합니다 지금 꽤 피곤 ^^

/* * [도구]이 템플릿을 변경하려면 | 템플릿 *을 선택하고 편집기에서 템플릿을 엽니 다. */ 패키지 jme3.objekte;

import com.jme3.app.SimpleApplication; 
import com.jme3.material.Material; 
import com.jme3.math.ColorRGBA; 
import com.jme3.math.Vector2f; 
import com.jme3.math.Vector3f; 
import com.jme3.scene.Geometry; 
import com.jme3.scene.Mesh; 
import com.jme3.scene.VertexBuffer; 
import com.jme3.scene.VertexBuffer.Type; 
import com.jme3.util.BufferUtils; 

/** 
* 
* @author Ronny 
*/ 
public class Rechteck2 extends SimpleApplication { 

    public static void main(String[] args) { 
     Rechteck2 app = new Rechteck2(); 
     app.start(); 
    } 

    @Override 
    public void simpleInitApp() { 
     Mesh mesh = new Mesh(); 
     int x_value = 4; //width_verteces 
     int y_value = 4; //heigth_verteces 
     int heigth = 3; //heigth 
     int width = 3; //width 
     float deltaX = width/(x_value-1); 
     float deltaY = heigth/(y_value-1); 
     int currentVertex = 0; 

     Vector3f[] vertices = new Vector3f[x_value*y_value]; 
      for (int y=0; y<y_value; y++){ //x als nummer des aktuellen vertex 
       for (int x=0; x<x_value; x++){ 
        vertices[currentVertex] = new Vector3f(x*deltaX, y*deltaY, 0); 
        currentVertex++; 
       } 
      } 
     Vector2f[] texCoord = new Vector2f[4]; 
     texCoord[0] = new Vector2f(0,0); 
     texCoord[1] = new Vector2f(1,0); 
     texCoord[2] = new Vector2f(0,1); 
     texCoord[3] = new Vector2f(1,1); 

     final int maxIndex = ((x_value-1)*(y_value-1)*6) + (y_value * 6); 
     int[] indexes = new int[maxIndex];   //[(x_value-1)*(y_value-1)*6+(y_value-1)*9]; 
     int a = 0; 
     int b = 1; 
     int c = x_value;  
     boolean direction = true; 
     boolean dirchange = false; 

     for (int i=0; i<(maxIndex/3); i++){  //((x_value-1)*(y_value-1)*6+((y_value-1)*9)); i++){ 

      if (direction){ 

       if (dirchange==true){ 
        indexes[i*3] = a; 
        indexes[i*3+1] = a+1; 
        indexes[i*3+2] = c; 
        a = indexes[i*3]; 
        b = indexes[i*3+1]; 
        c = indexes[i*3+2]; 
        dirchange = false; 
       } 
       else{ 
       indexes[i*3] = a; 
       indexes[i*3+1] = b; 
       indexes[i*3+2] = c; 
       } 
       if(i%2==1){ 
        a = b; 
        b = a+1; 
        c = c; 
       } 
       else{ 
        a = c; 
        b = b; 
        c = a+1; 
       } 
       if (b%x_value==0){ 
        i++; 
        indexes[i*3] = a; 
        indexes[i*3+1] = c; 
        indexes[i*3+2] = c; 
        i++; 
        indexes[i*3] = c; 
        indexes[i*3+1] = c; 
        indexes[i*3+2] = c; 
        if ((c+x_value)<= (x_value*y_value-1)){ 
         i++; 
         indexes[i*3] = c; 
         indexes[i*3+1] = c; 
         indexes[i*3+2] = c+x_value; 
         a = c; 
         b = c; 
         c = c+x_value; 
        } 
        direction = false; 
        dirchange = true; 
       } 
      } 
      else{ 
       if(dirchange==true){ 
        indexes[i*3] = c; 
        indexes[i*3+1] = c-1; 
        indexes[i*3+2] = a; 
        a = indexes[i*3]; 
        b = c-1; 
        c = indexes[i*3+2]; 
        dirchange = false; 
       } 
       else{ 
        indexes[i*3] = a; 
        indexes[i*3+1] = b; 
        indexes[i*3+2] = c; 
       } 
       if(i%2==0){ 
        a = b; 
        b = a-1; 
        c = c; 
       } 
       else{ 
        a = c; 
        b = b; 
        c = a-1; 
       } 
       if (a%x_value==0){ 
        i++; 
        indexes[i*3] = c; 
        indexes[i*3+1] = a; 
        indexes[i*3+2] = a; 
        i++; 
        indexes[i*3] = a; 
        indexes[i*3+1] = a; 
        indexes[i*3+2] = a; 
        if ((b+x_value) <= (x_value*y_value-1)){ 
         i++; 
         indexes[i*3] = a; 
         indexes[i*3+1] = a; 
         indexes[i*3+2] = a+x_value; 
         a = a; 
         b = a; 
         c = a+x_value; 
        } 
        direction = true; 
        dirchange = true; 
       } 
      } 
     } 
     mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices)); 
     mesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord)); 
     mesh.setBuffer(Type.Index, 3, BufferUtils.createIntBuffer(indexes)); 

     Geometry geo = new Geometry("MyMesh", mesh); 
     Material mat1 = new Material(assetManager, 
      "Common/MatDefs/Misc/Unshaded.j3md"); 
     mat1.setColor("Color", ColorRGBA.Green); 
     mat1.getAdditionalRenderState().setWireframe(true); 
     geo.setMaterial(mat1); 

     //mesh.setMode(Mesh.Mode.TriangleStrip); 
     mesh.updateBound(); 
     mesh.setStatic(); 

     Geometry lines = new Geometry("MyMesh", mesh); 
     lines.setMaterial(mat1); 

     rootNode.attachChild(lines); 
    } 

} 

답변

1

나는 코드를 테스트했습니다.

그냥 코드이 int x_value = 9; //width_verteces int y_value = 10; //heigth_verteces int heigth = y_value-1; //heigth int width = x_value-1; //width 의 작업을 잘