create fold able paper

Started by
-1 comments, last by alireza.pir 9 years, 3 months ago

Hello every one, i'm working on a game, i have been working with game engines like UDK and Unity for many years, now I come into Android and eclipse,
i have a question and im really confused, lets describe.
i want to make an android game which is something like origami, the main problem is how to simulate the paper behavior, i mean folding the paper dynamically,

i have searched times and time different options and ideas, i now think that i have this options to chose:

1- use bitmapmesh in android-

with this option, i have some problems and questions about DrawBitmapMesh! i founded this code:


public class MainView extends SurfaceView implements SurfaceHolder.Callback, Runnable {
  private SurfaceHolder holder=null;
  private Thread thread=null;
  private int isDrag;
  private Paint paint;
  private Bitmap bmp;
  private float[] vers;
  private ArrayList<Circle> container;

  public MainView(Context context)
  {
     super(context);
     getHolder().addCallback(this);

     isDrag = -1;
     container = new ArrayList<Circle>();
     paint = new Paint();
     paint.setAntiAlias(true);
     paint.setColor(Color.rgb(200, 0, 0));
     bmp =  BitmapFactory.decodeResource(getResources(),R.drawable.img); 
  }

  public void surfaceDestroyed(SurfaceHolder holder)
  {
     thread = null;
  }

  public void surfaceCreated(SurfaceHolder holder)
  {
     this.holder = holder;
     thread = new Thread(this);
  }

  public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
  {
     // Place the circle to the four corners of the image
     Circle c1 = new Circle(25f, 10f, 10f);
     container.add(c1);
     Circle c2 = new Circle(25f, bmp.getWidth()+10, 10f);
     container.add(c2);
     Circle c3 = new Circle(25f, 10f, bmp.getHeight()+10);
     container.add(c3);
     Circle c4 = new Circle(25f, bmp.getWidth()+10, bmp.getHeight()+10);
     container.add(c4);

     // Create a containing array of coordinates
     vers = new float[]{c1.x, c1.y, c2.x, c2.y, c3.x, c3.y, c4.x, c4.y};
     if(thread != null) thread.start();
  }

  public void run()
  {
     while (thread != null)
     {
        // Fill
        Canvas canvas = holder.lockCanvas();
        canvas.drawColor(Color.BLACK);

        // Draw image
        canvas.drawBitmapMesh(bmp, 1, 1, vers, 0, null, 0, null);

        // And draw a circle
        int size = container.size();
        for(int i=0 ; i< size ; i++)
        {
           Circle c = container.get(i);
           canvas.drawCircle(c.x, c.y, c.radius, paint);
        }
        holder.unlockCanvasAndPost(canvas);
     }
  }

  // Click at the time of the event
  public boolean onTouchEvent(MotionEvent event)
  {
     float x = event.getX();
     float y = event.getY();

     // When touch screen
     if(event.getAction() == MotionEvent.ACTION_DOWN)
     {
        int size = container.size();
        for(int i=0 ; i<size ; i++)
        {
           Circle c = container.get(i);
           if((c.x-x)*(c.x-x) + (c.y-y)*(c.y-y) < c.radius*c.radius)
           {
              isDrag = i;
              break;
           }
        }
     }

     // During a drag
     else if (event.getAction() == MotionEvent.ACTION_MOVE)
     {
        if(isDrag != -1)
        {
           Circle c = container.get(isDrag);
           c.x = x;
           c.y = y;
           vers[isDrag*2] = c.x;
           vers[isDrag*2+1] = c.y;
        }
     }

     // When you release your finger
     else if(event.getAction() == MotionEvent.ACTION_UP)
     {
        isDrag = -1;
     }

     return true;
  }
}

and these are the Circle and mainActivity classes:


public class Circle
{
   public float radius;
   public float x;
   public float y;
    
   public Circle(float radius, float x, float y)
   {
      this.radius = radius;
      this.x = x;
      this.y = y;
   }
}

public class MainActivity extends Activity {

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);            
       setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
         setContentView(new MainView(this));
   }

   @Override
   public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
   }

}

this option result is something like this:

Untitled_c8b1c.png

this is not what i want, but it is some Shadow of it. the problem about this is that, it scales the bitmap, but i want to FOLD the paper! is it possible to complete this surface view and make something like this:

1_9c12c.png

?

2- use OpenGl in andorid-

another option is to use openGl to make a shape and then Implement the folding behavior

3- Create Custom meshes and -

one other option is to make custom meshes, Those are just triangles and then giving them correct uv coordinates,


i dont know which one of these options are available to Implement , could any one help me which one (or any!) of these ways should i follow and how?

any suggestions will be helpful,

thanks,
alireza.

This topic is closed to new replies.

Advertisement