2013-09-12 4 views
1

Я хотел бы добавить функцию масштабирования к своей сцене. Как это сделать?Добавление функции масштабирования в сцену jPCT

Это мой код на данный момент:

private static float touchTurn = 0; 
private static float touchTurnUp = 0; 

private static float xpos = -1; 
private static float ypos = -1; 

static class ClearGLSurfaceView extends GLSurfaceView { 
    public ClearGLSurfaceView(Context context) { 
     super(myContext); 
    } 

@Override 
    public boolean onTouchEvent(MotionEvent me) { 
     if (me.getAction() == MotionEvent.ACTION_DOWN) { 
      xpos = me.getX(); 
      ypos = me.getY(); 
      return true; 
     } 

     if (me.getAction() == MotionEvent.ACTION_UP) { 
      xpos = -1; 
      ypos = -1; 
      touchTurn = 0; 
      touchTurnUp = 0; 
      return true; 
     } 

     if (me.getAction() == MotionEvent.ACTION_MOVE) { 
      float xd = me.getX() - xpos; 
      float yd = me.getY() - ypos; 

      xpos = me.getX(); 
      ypos = me.getY(); 

      touchTurn = xd/100f; 
      touchTurnUp = yd/100f; 
      return true; 
     } 

     try { 
      Thread.sleep(15); 
     } catch (Exception e) { 
      // Doesn't matter here... 
     } 

     return super.onTouchEvent(me); 
    } 
} 

static class MyRenderer implements GLSurfaceView.Renderer { 

     private long time = System.currentTimeMillis(); 

     public MyRenderer() { 
     } 

     public void onSurfaceChanged(GL10 gl, int w, int h) { 
      if (fb != null) { 
       fb.dispose(); 
      } 
      fb = new FrameBuffer(gl, w, h); 

      if (master == null) { 

       world = new World(); 
       world.setAmbientLight(20, 20, 20); 

       sun = new Light(world); 
       sun.setIntensity(250, 250, 250); 

       try { 
        cube = loadModel(thingName, thingScale); 
       } catch (UnsupportedEncodingException e) { 
        e.printStackTrace(); 
       } 

       cube.build(); 

       world.addObject(cube); 

       Camera cam = world.getCamera(); 
       cam.moveCamera(Camera.CAMERA_MOVEOUT, 50); 
       cam.lookAt(cube.getTransformedCenter()); 

       SimpleVector sv = new SimpleVector(); 
       sv.set(cube.getTransformedCenter()); 
       sv.y -= 100; 
       sv.z -= 100; 
       sun.setPosition(sv); 
       MemoryHelper.compact(); 

       if (master == null) { 
        Logger.log("Saving master Activity!"); 
        // master = fr; 
       } 
      } 
     } 

     public void onSurfaceCreated(GL10 gl, EGLConfig config) { 
     } 

     public void onDrawFrame(GL10 gl) { 
      if (touchTurn != 0) { 
       cube.rotateY(touchTurn); 
       touchTurn = 0; 
      } 

      if (touchTurnUp != 0) { 
       cube.rotateX(touchTurnUp); 
       touchTurnUp = 0; 
      } 

      fb.clear(back); 
      world.renderScene(fb); 
      world.draw(fb); 
      fb.display(); 

      if (System.currentTimeMillis() - time >= 1000) { 
       Logger.log(fps + "fps"); 
       fps = 0; 
       time = System.currentTimeMillis(); 
      } 
      fps++; 
     } 

Если вам нужна дополнительная информация, дайте мне знать.

ответ

0

Вы можете увеличить/уменьшить размер камеры.

Смежные вопросы