mirror of https://github.com/buggins/dlangui.git
#247 move while mouse is down
This commit is contained in:
parent
eb3bd56e90
commit
1ad136f42e
|
@ -173,8 +173,9 @@ class UiWidget : VerticalLayout, CellVisitor {
|
||||||
default:
|
default:
|
||||||
case 1:
|
case 1:
|
||||||
case 4:
|
case 4:
|
||||||
_world.camPosition.forward(1);
|
//_world.camPosition.forward(1);
|
||||||
updateCamPosition();
|
//updateCamPosition();
|
||||||
|
startMoveAnimation(_world.camPosition.direction.forward);
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
case 3:
|
case 3:
|
||||||
|
@ -187,19 +188,24 @@ class UiWidget : VerticalLayout, CellVisitor {
|
||||||
updateCamPosition();
|
updateCamPosition();
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
_world.camPosition.backward(1);
|
//_world.camPosition.backward(1);
|
||||||
updateCamPosition();
|
//updateCamPosition();
|
||||||
|
startMoveAnimation(-_world.camPosition.direction.forward);
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
_world.camPosition.moveLeft();
|
//_world.camPosition.moveLeft();
|
||||||
updateCamPosition();
|
//updateCamPosition();
|
||||||
|
startMoveAnimation(_world.camPosition.direction.left);
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
_world.camPosition.moveRight();
|
//_world.camPosition.moveRight();
|
||||||
updateCamPosition();
|
//updateCamPosition();
|
||||||
|
startMoveAnimation(_world.camPosition.direction.right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (event.action == MouseAction.ButtonUp || event.action == MouseAction.Cancel) {
|
||||||
|
stopMoveAnimation();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -272,6 +278,19 @@ class UiWidget : VerticalLayout, CellVisitor {
|
||||||
|
|
||||||
bool flying = false;
|
bool flying = false;
|
||||||
bool enableMeshUpdate = true;
|
bool enableMeshUpdate = true;
|
||||||
|
Vector3d _moveAnimationDirection;
|
||||||
|
|
||||||
|
|
||||||
|
void animateMoving() {
|
||||||
|
if (_moveAnimationDirection != Vector3d(0,0,0)) {
|
||||||
|
Vector3d animPos = _world.camPosition.pos + _moveAnimationDirection;
|
||||||
|
vec3 p = vec3(animPos.x + 0.5f, animPos.y + 0.5f, animPos.z + 0.5f);
|
||||||
|
if ((_animatingPosition - p).length < 2) {
|
||||||
|
_world.camPosition.pos += _moveAnimationDirection;
|
||||||
|
updateCamPosition(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void updateCamPosition(bool animateIt = true) {
|
void updateCamPosition(bool animateIt = true) {
|
||||||
import std.string;
|
import std.string;
|
||||||
|
@ -280,6 +299,7 @@ class UiWidget : VerticalLayout, CellVisitor {
|
||||||
import std.format;
|
import std.format;
|
||||||
|
|
||||||
if (!flying) {
|
if (!flying) {
|
||||||
|
animateMoving();
|
||||||
while(_world.canPass(_world.camPosition.pos + Vector3d(0, -1, 0)))
|
while(_world.canPass(_world.camPosition.pos + Vector3d(0, -1, 0)))
|
||||||
_world.camPosition.pos += Vector3d(0, -1, 0);
|
_world.camPosition.pos += Vector3d(0, -1, 0);
|
||||||
if(!_world.canPass(_world.camPosition.pos + Vector3d(0, -1, 0))) {
|
if(!_world.canPass(_world.camPosition.pos + Vector3d(0, -1, 0))) {
|
||||||
|
@ -309,6 +329,16 @@ class UiWidget : VerticalLayout, CellVisitor {
|
||||||
updateMinerMesh();
|
updateMinerMesh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void startMoveAnimation(Vector3d direction) {
|
||||||
|
_moveAnimationDirection = direction;
|
||||||
|
updateCamPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
void stopMoveAnimation() {
|
||||||
|
_moveAnimationDirection = Vector3d(0, 0, 0);
|
||||||
|
updateCamPosition();
|
||||||
|
}
|
||||||
|
|
||||||
void updateMinerMesh() {
|
void updateMinerMesh() {
|
||||||
_minerMesh.reset();
|
_minerMesh.reset();
|
||||||
long ts = currentTimeMillis;
|
long ts = currentTimeMillis;
|
||||||
|
@ -350,6 +380,7 @@ class UiWidget : VerticalLayout, CellVisitor {
|
||||||
/// animates window; interval is time left from previous draw, in hnsecs (1/10000000 of second)
|
/// animates window; interval is time left from previous draw, in hnsecs (1/10000000 of second)
|
||||||
override void animate(long interval) {
|
override void animate(long interval) {
|
||||||
//Log.d("animating");
|
//Log.d("animating");
|
||||||
|
animateMoving();
|
||||||
if (_animatingAngle != _angle) {
|
if (_animatingAngle != _angle) {
|
||||||
float delta = _angle - _animatingAngle;
|
float delta = _angle - _animatingAngle;
|
||||||
if (delta > 180)
|
if (delta > 180)
|
||||||
|
|
Loading…
Reference in New Issue