Merge pull request #993 from PhilipRosedale/master

Click on voxels as way of moving around
This commit is contained in:
ZappoMan 2013-09-30 09:30:37 -07:00
commit 86b4b7079d
4 changed files with 41 additions and 4 deletions

View file

@ -84,7 +84,7 @@ and features are available via menus in the Interface application.
Other components Other components
======== ========
voxel-server, animation-server, audio-mixer, avatar-mixer, domain-server, assignment-client, animation-server, domain-server,
pairing-server and space-server are architectural components that will allow pairing-server and space-server are architectural components that will allow
you to run the full stack of the virtual world should you choose to. you to run the full stack of the virtual world should you choose to.

View file

@ -1001,6 +1001,17 @@ void Application::mousePressEvent(QMouseEvent* event) {
_audio.startCollisionSound(1.0, frequency, 0.0, HOVER_VOXEL_DECAY); _audio.startCollisionSound(1.0, frequency, 0.0, HOVER_VOXEL_DECAY);
_isHoverVoxelSounding = true; _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()) { } else if (event->button() == Qt::RightButton && Menu::getInstance()->isVoxelModeActionChecked()) {

View file

@ -50,7 +50,9 @@ MyAvatar::MyAvatar(Node* owningNode) :
_lastCollisionPosition(0, 0, 0), _lastCollisionPosition(0, 0, 0),
_speedBrakes(false), _speedBrakes(false),
_isThrustOn(false), _isThrustOn(false),
_thrustMultiplier(1.0f) _thrustMultiplier(1.0f),
_moveTarget(0,0,0),
_moveTargetStepCounter(0)
{ {
for (int i = 0; i < MAX_DRIVE_KEYS; i++) { for (int i = 0; i < MAX_DRIVE_KEYS; i++) {
_driveKeys[i] = false; _driveKeys[i] = false;
@ -64,6 +66,11 @@ void MyAvatar::reset() {
_hand.reset(); _hand.reset();
} }
void MyAvatar::setMoveTarget(const glm::vec3 moveTarget) {
_moveTarget = moveTarget;
_moveTargetStepCounter = 0;
}
void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) { void MyAvatar::simulate(float deltaTime, Transmitter* transmitter) {
glm::quat orientation = getOrientation(); 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) { if (glm::length(_position - _lastCollisionPosition) > MIN_DISTANCE_AFTER_COLLISION_FOR_GRAVITY) {
_velocity += _scale * _gravity * (GRAVITY_EARTH * deltaTime); _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(); Camera* myCamera = Application::getInstance()->getCamera();
if (myCamera->getMode() == CAMERA_MODE_FIRST_PERSON && !OculusManager::isConnected()) { 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; const float MOVING_SPEED_THRESHOLD = 0.01f;
_moving = _speed > MOVING_SPEED_THRESHOLD; _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; _position += _velocity * deltaTime;
// Zero thrust out now that we've added it to velocity in this frame // Zero thrust out now that we've added it to velocity in this frame

View file

@ -31,6 +31,7 @@ public:
void setOrientation(const glm::quat& orientation); void setOrientation(const glm::quat& orientation);
void setNewScale(const float scale); void setNewScale(const float scale);
void setWantCollisionsOn(bool wantCollisionsOn) { _isCollisionsOn = wantCollisionsOn; } void setWantCollisionsOn(bool wantCollisionsOn) { _isCollisionsOn = wantCollisionsOn; }
void setMoveTarget(const glm::vec3 moveTarget);
// getters // getters
float getNewScale() const { return _newScale; } float getNewScale() const { return _newScale; }
@ -73,6 +74,8 @@ public:
bool _isThrustOn; bool _isThrustOn;
float _thrustMultiplier; float _thrustMultiplier;
float _collisionRadius; float _collisionRadius;
glm::vec3 _moveTarget;
int _moveTargetStepCounter;
// private methods // private methods
float getBallRenderAlpha(int ball, bool lookingInMirror) const; float getBallRenderAlpha(int ball, bool lookingInMirror) const;