mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:44:01 +02:00
Click on voxels as way of moving around
This commit is contained in:
parent
abee08c91a
commit
9645cd9831
3 changed files with 40 additions and 3 deletions
|
@ -1001,6 +1001,17 @@ void Application::mousePressEvent(QMouseEvent* event) {
|
|||
|
||||
_audio.startCollisionSound(1.0, frequency, 0.0, HOVER_VOXEL_DECAY);
|
||||
_isHoverVoxelSounding = true;
|
||||
|
||||
const float PERCENTAGE_TO_MOVE_TOWARD = 0.90f;
|
||||
glm::vec3 newTarget = getMouseVoxelWorldCoordinates(_hoverVoxel);
|
||||
glm::vec3 myPosition = _myAvatar.getPosition();
|
||||
|
||||
// If there is not an action tool set (add, delete, color), move to this voxel
|
||||
if (!(Menu::getInstance()->isOptionChecked(MenuOption::VoxelAddMode) ||
|
||||
Menu::getInstance()->isOptionChecked(MenuOption::VoxelDeleteMode) ||
|
||||
Menu::getInstance()->isOptionChecked(MenuOption::VoxelColorMode))) {
|
||||
_myAvatar.setMoveTarget(myPosition + (newTarget - myPosition) * PERCENTAGE_TO_MOVE_TOWARD);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (event->button() == Qt::RightButton && Menu::getInstance()->isVoxelModeActionChecked()) {
|
||||
|
|
|
@ -50,7 +50,9 @@ MyAvatar::MyAvatar(Node* owningNode) :
|
|||
_lastCollisionPosition(0, 0, 0),
|
||||
_speedBrakes(false),
|
||||
_isThrustOn(false),
|
||||
_thrustMultiplier(1.0f)
|
||||
_thrustMultiplier(1.0f),
|
||||
_moveTarget(0,0,0),
|
||||
_moveTargetStepCounter(0)
|
||||
{
|
||||
for (int i = 0; i < MAX_DRIVE_KEYS; i++) {
|
||||
_driveKeys[i] = false;
|
||||
|
@ -64,6 +66,11 @@ void MyAvatar::reset() {
|
|||
_hand.reset();
|
||||
}
|
||||
|
||||
void MyAvatar::setMoveTarget(const glm::vec3 moveTarget) {
|
||||
_moveTarget = moveTarget;
|
||||
_moveTargetStepCounter = 0;
|
||||
}
|
||||
|
||||
void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) {
|
||||
|
||||
glm::quat orientation = getOrientation();
|
||||
|
@ -165,8 +172,10 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
if (glm::length(_position - _lastCollisionPosition) > MIN_DISTANCE_AFTER_COLLISION_FOR_GRAVITY) {
|
||||
_velocity += _scale * _gravity * (GRAVITY_EARTH * deltaTime);
|
||||
}
|
||||
|
||||
// Only collide if we are not moving to a target
|
||||
if (_isCollisionsOn && (glm::length(_moveTarget) < EPSILON)) {
|
||||
|
||||
if (_isCollisionsOn) {
|
||||
Camera* myCamera = Application::getInstance()->getCamera();
|
||||
|
||||
if (myCamera->getMode() == CAMERA_MODE_FIRST_PERSON && !OculusManager::isConnected()) {
|
||||
|
@ -324,7 +333,21 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
const float MOVING_SPEED_THRESHOLD = 0.01f;
|
||||
_moving = _speed > MOVING_SPEED_THRESHOLD;
|
||||
|
||||
// update position by velocity, and subtract the change added earlier for gravity
|
||||
// If a move target is set, update position explicitly
|
||||
const float MOVE_FINISHED_TOLERANCE = 0.1f;
|
||||
const float MOVE_SPEED_FACTOR = 2.f;
|
||||
const int MOVE_TARGET_MAX_STEPS = 250;
|
||||
if ((glm::length(_moveTarget) > EPSILON) && (_moveTargetStepCounter < MOVE_TARGET_MAX_STEPS)) {
|
||||
if (glm::length(_position - _moveTarget) > MOVE_FINISHED_TOLERANCE) {
|
||||
_position += (_moveTarget - _position) * (deltaTime * MOVE_SPEED_FACTOR);
|
||||
_moveTargetStepCounter++;
|
||||
} else {
|
||||
// Move completed
|
||||
_moveTarget = glm::vec3(0,0,0);
|
||||
_moveTargetStepCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
_position += _velocity * deltaTime;
|
||||
|
||||
// Zero thrust out now that we've added it to velocity in this frame
|
||||
|
|
|
@ -31,6 +31,7 @@ public:
|
|||
void setOrientation(const glm::quat& orientation);
|
||||
void setNewScale(const float scale);
|
||||
void setWantCollisionsOn(bool wantCollisionsOn) { _isCollisionsOn = wantCollisionsOn; }
|
||||
void setMoveTarget(const glm::vec3 moveTarget);
|
||||
|
||||
// getters
|
||||
float getNewScale() const { return _newScale; }
|
||||
|
@ -73,6 +74,8 @@ public:
|
|||
bool _isThrustOn;
|
||||
float _thrustMultiplier;
|
||||
float _collisionRadius;
|
||||
glm::vec3 _moveTarget;
|
||||
int _moveTargetStepCounter;
|
||||
|
||||
// private methods
|
||||
float getBallRenderAlpha(int ball, bool lookingInMirror) const;
|
||||
|
|
Loading…
Reference in a new issue