我正在尝试创建一个InputProcessor,它将做很多事情。我有一个触摸屏设置,我试图移动相机沿x和y轴。
tBounds = new Sprite(Assets.touchpadBounds);
tBounds.setSize(tBounds.getWidth() * scale, tBounds.getHeight() * scale);
tKnob = new Sprite(Assets.touchpad);
tKnob.setSize(tKnob.getWidth() * scale, tKnob.getHeight() * scale);
touchpad = new Skin();
touchpad.add("boundary", tBounds);
touchpad.add("circle", tKnob);
touchpadStyle = new TouchpadStyle();
bounds = touchpad.getDrawable("boundary");
knob = touchpad.getDrawable("circle");
touchpadStyle.background = bounds;
touchpadStyle.knob = knob;
pad = new Touchpad(10, touchpadStyle);
stage.addActor(pad);
//Setting Bounds
pad.setBounds(width / 14, height / 10, tBounds.getHeight(),
tBounds.getWidth());
private void setKnobAction() {
camera.position.set(camera.position.x + (pad.getKnobPercentX() * 0.1f),
camera.position.y + 0,
camera.position.z - (pad.getKnobPercentY() * 0.1f));
camera.update();
}我使用setKnobAction()的问题是,它根据它所面临的初始方向移动相机。我希望它朝着它目前面临的方向前进。
发布于 2014-10-26 18:27:09
我已经想明白了。我所需要做的是向前和向后运动,增加或减去方向矢量的比例为1到位置矢量。
// To move forward
camera.position.add(camera.direction.scl(1f));
camera.update();
// To move backwards
camera.position.sub(camera.direction.scl(1f));
camera.update();
// To move to the right
Vector3 right = camera.direction.cpy().crs(Vector3.Y).nor();
camera.position.add(right.scl(1));
camera.update();
// To move to the left
Vector3 right = camera.direction.cpy().crs(Vector3.Y).nor();
camera.position.sub(right.scl(1));
camera.update();要扫射(向左或向右移动,而相机正向前),我需要增加或减去相机的方向矢量和相机的向上向量之间的交叉乘积。
发布于 2014-10-24 11:21:40
问题是,您将camera相对论性移动到世界轴。
如果你旋转你的相机,世界轴保持不变,只有相机的方向矢量改变。
因此,你需要把你的camera相对于它的方向向量。
我想在玩PerspectiveCamera和3D游戏之前,你应该先读几本教程。
这里是一个教程,它描述一个FirstPersonCamera。
基本上,您需要为相机存储一个规范化的方向矢量:
Vector3 direction = new Vector3(1, 0, 0); //You are looking in x-Direction如果你旋转,你需要旋转这个向量围绕世界Y轴或camera的向上轴(取决于情况,在链接教程中解释):
direction.rotate(Vector3.Y, degrees).nor(); // Not sure if "nor()" is needed, it limits the length to 1, as it only gives the direction, not the speed. 为了向前走,您只需添加方向矢量,按速度缩放到位置。
camera.position.add(direction.scl(speed))之后,您需要通过再次调用direction来重置nor()的长度。
希望能帮上忙。
https://stackoverflow.com/questions/26540802
复制相似问题