⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ccamera.java

📁 一个3D的保龄球的源代码
💻 JAVA
字号:


/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class CCamera {


  public int []m_eye = {0, -500, 150}; //position of camera
  public int [] m_dir = {0, 100, 0};   //camera direction

  //steps
  boolean m_bNeedMove; // indicate the camera need to move in steps
  private int []m_targetEye = new int[3];
  private int []m_eyeStep = {0, 0, 0};
  private int []m_targetDir = new int[3];
  private int []m_dirStep = {0, 0, 0};
  private int m_frameCpt = 0;


  //indicate the camera changed or not in this frame
  boolean m_bChanged = false;

  public CCamera() {
  }

  /**
   * put the camera to another position with defined direction directly.
   * @param pos int[]
   * @param dir int[]
   */
  void JumpTo(int [] pos, int [] dir)
  {
    m_eye = pos;
    m_dir = dir;
    m_bChanged = true;
  }

  /**
   * Move camera from current position and direction to new position and direction in defined frames.
   * @param pos int[]: new position
   * @param dir int[]: new direction
   * @param frameCount int: the frame count of moving
   */
  void MoveTo(int [] pos, int []dir, int frameCount)
  {
    m_bNeedMove = true;
    m_targetEye = pos;
    m_targetDir = dir;
    m_frameCpt = frameCount;
    for (int i=0; i<3; i++)
    {
      m_eyeStep[i] = (pos[i]-m_eye[i])/frameCount;
      m_dirStep[i] = (dir[i]-m_dir[i])/frameCount;
    }
  }
  /**
   * Update camera pos and dir if it should step move
   */
  void Update()
  {
    m_bChanged = false;
    if (m_bNeedMove)
    {
      m_frameCpt--;
      if (m_frameCpt == 0)
      {
        m_bNeedMove = false;
        m_eye = m_targetEye;
        m_dir = m_targetDir;
      }
      else
      {
        for (int i = 0; i < 3; i++) {
          m_eye[i] += m_eyeStep[i];
          m_dir[i] += m_dirStep[i];
        }
      }
      m_bChanged = true;
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -