mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Adding voxel thrust on grabbing/dragging to move avatar
This commit is contained in:
parent
57fcaceec2
commit
ad58d0aa23
3 changed files with 73 additions and 3 deletions
|
@ -721,6 +721,9 @@ void Application::mousePressEvent(QMouseEvent* event) {
|
|||
if (event->button() == Qt::LeftButton) {
|
||||
_mouseX = event->x();
|
||||
_mouseY = event->y();
|
||||
_mouseDragStartedX = _mouseX;
|
||||
_mouseDragStartedY = _mouseY;
|
||||
_mouseVoxelDragging = _mouseVoxel;
|
||||
_mousePressed = true;
|
||||
maybeEditVoxelUnderCursor();
|
||||
|
||||
|
@ -1003,6 +1006,12 @@ static void sendVoxelEditMessage(PACKET_HEADER header, VoxelDetail& detail) {
|
|||
}
|
||||
}
|
||||
|
||||
const glm::vec3 Application::getMouseVoxelWorldCoordinates(VoxelDetail _mouseVoxel) {
|
||||
return glm::vec3((_mouseVoxel.x + _mouseVoxel.s / 2.f) * TREE_SCALE,
|
||||
(_mouseVoxel.y + _mouseVoxel.s / 2.f) * TREE_SCALE,
|
||||
(_mouseVoxel.z + _mouseVoxel.s / 2.f) * TREE_SCALE);
|
||||
}
|
||||
|
||||
void Application::decreaseVoxelSize() {
|
||||
_mouseVoxelScale /= 2;
|
||||
}
|
||||
|
@ -1432,6 +1441,26 @@ void Application::update(float deltaTime) {
|
|||
// tell my avatar the posiion and direction of the ray projected ino the world based on the mouse position
|
||||
_myAvatar.setMouseRay(mouseRayOrigin, mouseRayDirection);
|
||||
|
||||
// If we are dragging on a voxel, add thrust according to the amount the mouse is dragging
|
||||
const float VOXEL_GRAB_THRUST = 10.0f;
|
||||
if (_mousePressed && (_mouseVoxel.s != 0)) {
|
||||
glm::vec2 mouseDrag(_mouseX - _mouseDragStartedX, _mouseY - _mouseDragStartedY);
|
||||
glm::quat orientation = _myAvatar.getOrientation();
|
||||
//glm::vec3 front = orientation * IDENTITY_FRONT;
|
||||
//glm::vec3 right = orientation * IDENTITY_RIGHT;
|
||||
glm::vec3 up = orientation * IDENTITY_UP;
|
||||
glm::vec3 towardVoxel = getMouseVoxelWorldCoordinates(_mouseVoxelDragging)
|
||||
- _myAvatar.getCameraPosition();
|
||||
glm::vec3 lateralToVoxel = glm::cross(up, glm::normalize(towardVoxel)) * glm::length(towardVoxel);
|
||||
_voxelThrust = glm::vec3(0, 0, 0);
|
||||
_voxelThrust += towardVoxel * VOXEL_GRAB_THRUST * deltaTime * mouseDrag.y;
|
||||
_voxelThrust += lateralToVoxel * VOXEL_GRAB_THRUST * deltaTime * mouseDrag.x;
|
||||
|
||||
// Add thrust from voxel grabbing to the avatar
|
||||
_myAvatar.addThrust(_voxelThrust);
|
||||
|
||||
}
|
||||
|
||||
_mouseVoxel.s = 0.0f;
|
||||
if (checkedVoxelModeAction() != 0 &&
|
||||
(fabs(_myAvatar.getVelocity().x) +
|
||||
|
@ -1951,6 +1980,10 @@ void Application::displaySide(Camera& whichCamera) {
|
|||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
// Enable to show line from me to the voxel I am touching
|
||||
//renderLineToTouchedVoxel();
|
||||
renderThrustAtVoxel(_voxelThrust);
|
||||
|
||||
// draw a red sphere
|
||||
float sphereRadius = 0.25f;
|
||||
glColor3f(1,0,0);
|
||||
|
@ -2167,6 +2200,32 @@ void Application::displayStats() {
|
|||
}
|
||||
}
|
||||
|
||||
void Application::renderThrustAtVoxel(glm::vec3 thrust) {
|
||||
if (_mousePressed) {
|
||||
glColor3f(1, 0, 0);
|
||||
glLineWidth(2.0f);
|
||||
glBegin(GL_LINES);
|
||||
glm::vec3 voxelTouched = getMouseVoxelWorldCoordinates(_mouseVoxelDragging);
|
||||
glVertex3f(voxelTouched.x, voxelTouched.y, voxelTouched.z);
|
||||
glVertex3f(voxelTouched.x + thrust.x, voxelTouched.y + thrust.y, voxelTouched.z + thrust.z);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
}
|
||||
void Application::renderLineToTouchedVoxel() {
|
||||
// Draw a teal line to the voxel I am currently dragging on
|
||||
if (_mousePressed) {
|
||||
glColor3f(0, 1, 1);
|
||||
glLineWidth(2.0f);
|
||||
glBegin(GL_LINES);
|
||||
glm::vec3 voxelTouched = getMouseVoxelWorldCoordinates(_mouseVoxelDragging);
|
||||
glVertex3f(voxelTouched.x, voxelTouched.y, voxelTouched.z);
|
||||
glm::vec3 headPosition = _myAvatar.getHeadJointPosition();
|
||||
glVertex3fv(&headPosition.x);
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
// renderViewFrustum()
|
||||
//
|
||||
|
|
|
@ -67,6 +67,8 @@ public:
|
|||
|
||||
void wheelEvent(QWheelEvent* event);
|
||||
|
||||
const glm::vec3 getMouseVoxelWorldCoordinates(VoxelDetail _mouseVoxel);
|
||||
|
||||
Avatar* getAvatar() { return &_myAvatar; }
|
||||
Camera* getCamera() { return &_myCamera; }
|
||||
ViewFrustum* getViewFrustum() { return &_viewFrustum; }
|
||||
|
@ -142,6 +144,9 @@ private:
|
|||
|
||||
void renderViewFrustum(ViewFrustum& viewFrustum);
|
||||
|
||||
void renderLineToTouchedVoxel();
|
||||
void renderThrustAtVoxel(glm::vec3 thrust);
|
||||
|
||||
void setupPaintingVoxel();
|
||||
void shiftPaintingColor();
|
||||
void maybeEditVoxelUnderCursor();
|
||||
|
@ -256,7 +261,12 @@ private:
|
|||
|
||||
int _mouseX;
|
||||
int _mouseY;
|
||||
int _mouseDragStartedX;
|
||||
int _mouseDragStartedY;
|
||||
VoxelDetail _mouseVoxelDragging;
|
||||
glm::vec3 _voxelThrust;
|
||||
bool _mousePressed; // true if mouse has been pressed (clear when finished)
|
||||
|
||||
|
||||
VoxelDetail _mouseVoxel; // details of the voxel under the mouse cursor
|
||||
float _mouseVoxelScale; // the scale for adding/removing voxels
|
||||
|
|
|
@ -412,9 +412,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
const float THRUST_MAG = 600.0f;
|
||||
|
||||
if (!_owningAgent) {
|
||||
|
||||
_thrust = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
|
||||
// Add Thrusts from keyboard
|
||||
if (_driveKeys[FWD ]) {_thrust += THRUST_MAG * deltaTime * front;}
|
||||
if (_driveKeys[BACK ]) {_thrust -= THRUST_MAG * deltaTime * front;}
|
||||
|
@ -468,6 +466,9 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
// add thrust to velocity
|
||||
_velocity += _thrust * deltaTime;
|
||||
|
||||
// Zero thrust out now that we've added it to velocity in this frame
|
||||
_thrust = glm::vec3(0, 0, 0);
|
||||
|
||||
// calculate speed
|
||||
_speed = glm::length(_velocity);
|
||||
|
||||
|
|
Loading…
Reference in a new issue