将相机移动到它面对的方向
Move camera to the direction it's facing
我的相机有 X、Y 和 Z 坐标。
相机也有偏航和俯仰。
int cameraX = Camera.getX();
int cameraY = Camera.getY();
int cameraZ = Camera.getZ();
int cameraYaw = Camera.getYaw();
int cameraPitch = Camera.getPitch();
偏航在 360 度有 2048 个单位,因此在 160 度时 getYaw() 方法将 return 1024。
目前我通过在每个循环中设置 Y + 1 来向前移动相机。
Camera.setY(Camera.getY() + 1);
如何将相机 X 和 Y 设置为我面对的方向(偏航)?
我不想在这种情况下使用俯仰,只是偏航。
如果我对你的问题的理解正确,你是在试图让相机朝你正在看的方向移动(在 2D 中 space,你只是水平移动)。
我为 C++ 制作了一个小的 LookAt 头文件库,但这里是用 Java 重写的一部分。这段代码的作用是进行旋转和距离计算,然后计算您需要移动多远(在 x 和 y 坐标中)才能到达那里。
// Returns how far you need to move in X and Y to get to where you're looking
// Rotation is in degrees, distance is how far you want to move
public static double PolarToCartesianX(double rotation, double distance) {
return distance * Math.cos(rotation * (Math.PI / 180.0D));
}
public static double PolarToCartesianY(double rotation, double distance) {
return distance * Math.sin(rotation * (Math.PI / 180.0D));
}
我的相机有 X、Y 和 Z 坐标。
相机也有偏航和俯仰。
int cameraX = Camera.getX();
int cameraY = Camera.getY();
int cameraZ = Camera.getZ();
int cameraYaw = Camera.getYaw();
int cameraPitch = Camera.getPitch();
偏航在 360 度有 2048 个单位,因此在 160 度时 getYaw() 方法将 return 1024。
目前我通过在每个循环中设置 Y + 1 来向前移动相机。
Camera.setY(Camera.getY() + 1);
如何将相机 X 和 Y 设置为我面对的方向(偏航)? 我不想在这种情况下使用俯仰,只是偏航。
如果我对你的问题的理解正确,你是在试图让相机朝你正在看的方向移动(在 2D 中 space,你只是水平移动)。
我为 C++ 制作了一个小的 LookAt 头文件库,但这里是用 Java 重写的一部分。这段代码的作用是进行旋转和距离计算,然后计算您需要移动多远(在 x 和 y 坐标中)才能到达那里。
// Returns how far you need to move in X and Y to get to where you're looking
// Rotation is in degrees, distance is how far you want to move
public static double PolarToCartesianX(double rotation, double distance) {
return distance * Math.cos(rotation * (Math.PI / 180.0D));
}
public static double PolarToCartesianY(double rotation, double distance) {
return distance * Math.sin(rotation * (Math.PI / 180.0D));
}