mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 22:16:39 +02:00
Merge branch 'master' of https://github.com/worklist/hifi
This commit is contained in:
commit
0ab27d5ecf
7 changed files with 131 additions and 60 deletions
|
@ -99,6 +99,10 @@ find_package(OpenNI)
|
||||||
find_package(UVCCameraControl)
|
find_package(UVCCameraControl)
|
||||||
find_package(ZLIB)
|
find_package(ZLIB)
|
||||||
|
|
||||||
|
# link the stk library
|
||||||
|
set(STK_ROOT_DIR ${ROOT_DIR}/externals/stk)
|
||||||
|
find_package(STK REQUIRED)
|
||||||
|
|
||||||
# let the source know that we have OpenNI/NITE for Kinect
|
# let the source know that we have OpenNI/NITE for Kinect
|
||||||
if (OPENNI_FOUND)
|
if (OPENNI_FOUND)
|
||||||
add_definitions(-DHAVE_OPENNI)
|
add_definitions(-DHAVE_OPENNI)
|
||||||
|
@ -122,6 +126,7 @@ include_directories(
|
||||||
${LEAP_INCLUDE_DIRS}
|
${LEAP_INCLUDE_DIRS}
|
||||||
${MOTIONDRIVER_INCLUDE_DIRS}
|
${MOTIONDRIVER_INCLUDE_DIRS}
|
||||||
${OPENCV_INCLUDE_DIRS}
|
${OPENCV_INCLUDE_DIRS}
|
||||||
|
${STK_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${OPENCV_INCLUDE_DIRS}")
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${OPENCV_INCLUDE_DIRS}")
|
||||||
|
@ -131,6 +136,7 @@ target_link_libraries(
|
||||||
${MOTIONDRIVER_LIBRARIES}
|
${MOTIONDRIVER_LIBRARIES}
|
||||||
${OPENCV_LIBRARIES}
|
${OPENCV_LIBRARIES}
|
||||||
${ZLIB_LIBRARIES}
|
${ZLIB_LIBRARIES}
|
||||||
|
${STK_LIBRARIES}
|
||||||
fervor
|
fervor
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -183,6 +183,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
||||||
_touchAvgX(0.0f),
|
_touchAvgX(0.0f),
|
||||||
_touchAvgY(0.0f),
|
_touchAvgY(0.0f),
|
||||||
_isTouchPressed(false),
|
_isTouchPressed(false),
|
||||||
|
_yawFromTouch(0.0f),
|
||||||
|
_pitchFromTouch(0.0f),
|
||||||
_mousePressed(false),
|
_mousePressed(false),
|
||||||
_mouseVoxelScale(1.0f / 1024.0f),
|
_mouseVoxelScale(1.0f / 1024.0f),
|
||||||
_justEditedVoxel(false),
|
_justEditedVoxel(false),
|
||||||
|
@ -969,6 +971,9 @@ void Application::idle() {
|
||||||
gettimeofday(&check, NULL);
|
gettimeofday(&check, NULL);
|
||||||
|
|
||||||
// Only run simulation code if more than IDLE_SIMULATE_MSECS have passed since last time we ran
|
// Only run simulation code if more than IDLE_SIMULATE_MSECS have passed since last time we ran
|
||||||
|
sendPostedEvents(NULL, QEvent::TouchBegin);
|
||||||
|
sendPostedEvents(NULL, QEvent::TouchUpdate);
|
||||||
|
sendPostedEvents(NULL, QEvent::TouchEnd);
|
||||||
|
|
||||||
double timeSinceLastUpdate = diffclock(&_lastTimeUpdated, &check);
|
double timeSinceLastUpdate = diffclock(&_lastTimeUpdated, &check);
|
||||||
if (timeSinceLastUpdate > IDLE_SIMULATE_MSECS) {
|
if (timeSinceLastUpdate > IDLE_SIMULATE_MSECS) {
|
||||||
|
@ -978,9 +983,6 @@ void Application::idle() {
|
||||||
// This is necessary because id the idle() call takes longer than the
|
// This is necessary because id the idle() call takes longer than the
|
||||||
// interval between idle() calls, the event loop never gets to run,
|
// interval between idle() calls, the event loop never gets to run,
|
||||||
// and touch events get delayed.
|
// and touch events get delayed.
|
||||||
sendPostedEvents(NULL, QEvent::TouchBegin);
|
|
||||||
sendPostedEvents(NULL, QEvent::TouchUpdate);
|
|
||||||
sendPostedEvents(NULL, QEvent::TouchEnd);
|
|
||||||
|
|
||||||
const float BIGGEST_DELTA_TIME_SECS = 0.25f;
|
const float BIGGEST_DELTA_TIME_SECS = 0.25f;
|
||||||
update(glm::clamp((float)timeSinceLastUpdate / 1000.f, 0.f, BIGGEST_DELTA_TIME_SECS));
|
update(glm::clamp((float)timeSinceLastUpdate / 1000.f, 0.f, BIGGEST_DELTA_TIME_SECS));
|
||||||
|
@ -1902,12 +1904,9 @@ void Application::update(float deltaTime) {
|
||||||
if (_isTouchPressed) {
|
if (_isTouchPressed) {
|
||||||
float TOUCH_YAW_SCALE = -50.0f;
|
float TOUCH_YAW_SCALE = -50.0f;
|
||||||
float TOUCH_PITCH_SCALE = -50.0f;
|
float TOUCH_PITCH_SCALE = -50.0f;
|
||||||
_myAvatar.getHead().addYaw((_touchAvgX - _lastTouchAvgX)
|
_yawFromTouch += ((_touchAvgX - _lastTouchAvgX) * TOUCH_YAW_SCALE * deltaTime);
|
||||||
* TOUCH_YAW_SCALE
|
_pitchFromTouch += ((_touchAvgY - _lastTouchAvgY) * TOUCH_PITCH_SCALE * deltaTime);
|
||||||
* deltaTime);
|
|
||||||
_myAvatar.getHead().addPitch((_touchAvgY - _lastTouchAvgY)
|
|
||||||
* TOUCH_PITCH_SCALE
|
|
||||||
* deltaTime);
|
|
||||||
_lastTouchAvgX = _touchAvgX;
|
_lastTouchAvgX = _touchAvgX;
|
||||||
_lastTouchAvgY = _touchAvgY;
|
_lastTouchAvgY = _touchAvgY;
|
||||||
}
|
}
|
||||||
|
@ -2011,11 +2010,20 @@ void Application::update(float deltaTime) {
|
||||||
|
|
||||||
void Application::updateAvatar(float deltaTime) {
|
void Application::updateAvatar(float deltaTime) {
|
||||||
|
|
||||||
|
// When head is rotated via touch/mouse look, slowly turn body to follow
|
||||||
|
const float BODY_FOLLOW_HEAD_RATE = 0.5f;
|
||||||
|
// update body yaw by body yaw delta
|
||||||
|
_myAvatar.setOrientation(_myAvatar.getOrientation()
|
||||||
|
* glm::quat(glm::vec3(0, _yawFromTouch * deltaTime * BODY_FOLLOW_HEAD_RATE, 0) * deltaTime));
|
||||||
|
_yawFromTouch -= _yawFromTouch * deltaTime * BODY_FOLLOW_HEAD_RATE;
|
||||||
|
|
||||||
// Update my avatar's state from gyros and/or webcam
|
// Update my avatar's state from gyros and/or webcam
|
||||||
_myAvatar.updateFromGyrosAndOrWebcam(_gyroLook->isChecked(),
|
_myAvatar.updateFromGyrosAndOrWebcam(_gyroLook->isChecked(),
|
||||||
glm::vec3(_headCameraPitchYawScale,
|
glm::vec3(_headCameraPitchYawScale,
|
||||||
_headCameraPitchYawScale,
|
_headCameraPitchYawScale,
|
||||||
_headCameraPitchYawScale));
|
_headCameraPitchYawScale),
|
||||||
|
_yawFromTouch,
|
||||||
|
_pitchFromTouch);
|
||||||
|
|
||||||
if (_serialHeadSensor.isActive()) {
|
if (_serialHeadSensor.isActive()) {
|
||||||
|
|
||||||
|
@ -2055,8 +2063,8 @@ void Application::updateAvatar(float deltaTime) {
|
||||||
float yaw, pitch, roll;
|
float yaw, pitch, roll;
|
||||||
OculusManager::getEulerAngles(yaw, pitch, roll);
|
OculusManager::getEulerAngles(yaw, pitch, roll);
|
||||||
|
|
||||||
_myAvatar.getHead().setYaw(yaw);
|
_myAvatar.getHead().setYaw(yaw + _yawFromTouch);
|
||||||
_myAvatar.getHead().setPitch(pitch);
|
_myAvatar.getHead().setPitch(pitch + _pitchFromTouch);
|
||||||
_myAvatar.getHead().setRoll(roll);
|
_myAvatar.getHead().setRoll(roll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -332,6 +332,8 @@ private:
|
||||||
float _touchDragStartedAvgX;
|
float _touchDragStartedAvgX;
|
||||||
float _touchDragStartedAvgY;
|
float _touchDragStartedAvgY;
|
||||||
bool _isTouchPressed; // true if multitouch has been pressed (clear when finished)
|
bool _isTouchPressed; // true if multitouch has been pressed (clear when finished)
|
||||||
|
float _yawFromTouch;
|
||||||
|
float _pitchFromTouch;
|
||||||
|
|
||||||
VoxelDetail _mouseVoxelDragging;
|
VoxelDetail _mouseVoxelDragging;
|
||||||
glm::vec3 _voxelThrust;
|
glm::vec3 _voxelThrust;
|
||||||
|
|
|
@ -16,12 +16,14 @@
|
||||||
#include "Hand.h"
|
#include "Hand.h"
|
||||||
#include "Head.h"
|
#include "Head.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "Physics.h"
|
||||||
#include "ui/TextRenderer.h"
|
#include "ui/TextRenderer.h"
|
||||||
#include <NodeList.h>
|
#include <NodeList.h>
|
||||||
#include <NodeTypes.h>
|
#include <NodeTypes.h>
|
||||||
#include <PacketHeaders.h>
|
#include <PacketHeaders.h>
|
||||||
#include <OculusManager.h>
|
#include <OculusManager.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
const bool BALLS_ON = false;
|
const bool BALLS_ON = false;
|
||||||
|
@ -285,7 +287,10 @@ void Avatar::reset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update avatar head rotation with sensor data
|
// Update avatar head rotation with sensor data
|
||||||
void Avatar::updateFromGyrosAndOrWebcam(bool gyroLook, const glm::vec3& amplifyAngle) {
|
void Avatar::updateFromGyrosAndOrWebcam(bool gyroLook,
|
||||||
|
const glm::vec3& amplifyAngle,
|
||||||
|
float yawFromTouch,
|
||||||
|
float pitchFromTouch) {
|
||||||
SerialInterface* gyros = Application::getInstance()->getSerialHeadSensor();
|
SerialInterface* gyros = Application::getInstance()->getSerialHeadSensor();
|
||||||
Webcam* webcam = Application::getInstance()->getWebcam();
|
Webcam* webcam = Application::getInstance()->getWebcam();
|
||||||
glm::vec3 estimatedPosition, estimatedRotation;
|
glm::vec3 estimatedPosition, estimatedRotation;
|
||||||
|
@ -296,6 +301,8 @@ void Avatar::updateFromGyrosAndOrWebcam(bool gyroLook, const glm::vec3& amplifyA
|
||||||
estimatedRotation = webcam->getEstimatedRotation();
|
estimatedRotation = webcam->getEstimatedRotation();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
_head.setPitch(pitchFromTouch);
|
||||||
|
_head.setYaw(yawFromTouch);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (webcam->isActive()) {
|
if (webcam->isActive()) {
|
||||||
|
@ -316,8 +323,8 @@ void Avatar::updateFromGyrosAndOrWebcam(bool gyroLook, const glm::vec3& amplifyA
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_head.setPitch(estimatedRotation.x * amplifyAngle.x);
|
_head.setPitch(estimatedRotation.x * amplifyAngle.x + pitchFromTouch);
|
||||||
_head.setYaw(estimatedRotation.y * amplifyAngle.y);
|
_head.setYaw(estimatedRotation.y * amplifyAngle.y + yawFromTouch);
|
||||||
_head.setRoll(estimatedRotation.z * amplifyAngle.z);
|
_head.setRoll(estimatedRotation.z * amplifyAngle.z);
|
||||||
_head.setCameraFollowsHead(gyroLook);
|
_head.setCameraFollowsHead(gyroLook);
|
||||||
|
|
||||||
|
@ -356,16 +363,16 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) {
|
||||||
//
|
//
|
||||||
// Gather thrust information from keyboard and sensors to apply to avatar motion
|
// Gather thrust information from keyboard and sensors to apply to avatar motion
|
||||||
//
|
//
|
||||||
glm::quat orientation = getOrientation();
|
glm::quat orientation = getHead().getOrientation();
|
||||||
glm::vec3 front = orientation * IDENTITY_FRONT;
|
glm::vec3 front = orientation * IDENTITY_FRONT;
|
||||||
glm::vec3 right = orientation * IDENTITY_RIGHT;
|
glm::vec3 right = orientation * IDENTITY_RIGHT;
|
||||||
glm::vec3 up = orientation * IDENTITY_UP;
|
glm::vec3 up = orientation * IDENTITY_UP;
|
||||||
|
|
||||||
const float THRUST_MAG_UP = 800.0f;
|
const float THRUST_MAG_UP = 800.0f;
|
||||||
const float THRUST_MAG_DOWN = 200.f;
|
const float THRUST_MAG_DOWN = 300.f;
|
||||||
const float THRUST_MAG_FWD = 300.f;
|
const float THRUST_MAG_FWD = 500.f;
|
||||||
const float THRUST_MAG_BACK = 150.f;
|
const float THRUST_MAG_BACK = 300.f;
|
||||||
const float THRUST_MAG_LATERAL = 200.f;
|
const float THRUST_MAG_LATERAL = 250.f;
|
||||||
const float THRUST_JUMP = 120.f;
|
const float THRUST_JUMP = 120.f;
|
||||||
|
|
||||||
// Add Thrusts from keyboard
|
// Add Thrusts from keyboard
|
||||||
|
@ -443,9 +450,6 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
||||||
glm::vec3 oldVelocity = getVelocity();
|
glm::vec3 oldVelocity = getVelocity();
|
||||||
|
|
||||||
if (isMyAvatar()) {
|
if (isMyAvatar()) {
|
||||||
// update position by velocity
|
|
||||||
_position += _velocity * deltaTime;
|
|
||||||
|
|
||||||
// calculate speed
|
// calculate speed
|
||||||
_speed = glm::length(_velocity);
|
_speed = glm::length(_velocity);
|
||||||
}
|
}
|
||||||
|
@ -480,7 +484,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
||||||
enableHandMovement &= (it->jointID != AVATAR_JOINT_RIGHT_WRIST);
|
enableHandMovement &= (it->jointID != AVATAR_JOINT_RIGHT_WRIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update avatar skeleton
|
// update avatar skeleton
|
||||||
_skeleton.update(deltaTime, getOrientation(), _position);
|
_skeleton.update(deltaTime, getOrientation(), _position);
|
||||||
|
|
||||||
//determine the lengths of the body springs now that we have updated the skeleton at least once
|
//determine the lengths of the body springs now that we have updated the skeleton at least once
|
||||||
|
@ -501,41 +505,40 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
||||||
_ballSpringsInitialized = true;
|
_ballSpringsInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// if this is not my avatar, then hand position comes from transmitted data
|
// if this is not my avatar, then hand position comes from transmitted data
|
||||||
if (!isMyAvatar()) {
|
if (!isMyAvatar()) {
|
||||||
_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _handPosition;
|
_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _handPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
//detect and respond to collisions with other avatars...
|
|
||||||
if (isMyAvatar()) {
|
|
||||||
updateAvatarCollisions(deltaTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
//update the movement of the hand and process handshaking with other avatars...
|
//update the movement of the hand and process handshaking with other avatars...
|
||||||
updateHandMovementAndTouching(deltaTime, enableHandMovement);
|
updateHandMovementAndTouching(deltaTime, enableHandMovement);
|
||||||
_avatarTouch.simulate(deltaTime);
|
_avatarTouch.simulate(deltaTime);
|
||||||
|
|
||||||
// apply gravity and collision with the ground/floor
|
|
||||||
if (isMyAvatar() && USING_AVATAR_GRAVITY) {
|
|
||||||
_velocity += _gravity * (GRAVITY_EARTH * deltaTime);
|
|
||||||
}
|
|
||||||
if (isMyAvatar()) {
|
if (isMyAvatar()) {
|
||||||
|
|
||||||
|
// apply gravity
|
||||||
|
if (USING_AVATAR_GRAVITY) {
|
||||||
|
// For gravity, always move the avatar by the amount driven by gravity, so that the collision
|
||||||
|
// routines will detect it and collide every frame when pulled by gravity to a surface
|
||||||
|
//
|
||||||
|
_velocity += _gravity * (GRAVITY_EARTH * deltaTime);
|
||||||
|
_position += _gravity * (GRAVITY_EARTH * deltaTime) * deltaTime;
|
||||||
|
}
|
||||||
|
|
||||||
updateCollisionWithEnvironment();
|
updateCollisionWithEnvironment();
|
||||||
|
updateCollisionWithVoxels();
|
||||||
|
updateAvatarCollisions(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update body balls
|
// update body balls
|
||||||
updateBodyBalls(deltaTime);
|
updateBodyBalls(deltaTime);
|
||||||
|
|
||||||
|
|
||||||
// test for avatar collision response with the big sphere
|
// test for avatar collision response with the big sphere
|
||||||
if (usingBigSphereCollisionTest) {
|
if (usingBigSphereCollisionTest) {
|
||||||
updateCollisionWithSphere(_TEST_bigSpherePosition, _TEST_bigSphereRadius, deltaTime);
|
updateCollisionWithSphere(_TEST_bigSpherePosition, _TEST_bigSphereRadius, deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
// collision response with voxels
|
|
||||||
if (isMyAvatar()) {
|
|
||||||
updateCollisionWithVoxels();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isMyAvatar()) {
|
if (isMyAvatar()) {
|
||||||
|
|
||||||
|
@ -545,7 +548,6 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
||||||
// update body yaw by body yaw delta
|
// update body yaw by body yaw delta
|
||||||
orientation = orientation * glm::quat(glm::radians(
|
orientation = orientation * glm::quat(glm::radians(
|
||||||
glm::vec3(_bodyPitchDelta, _bodyYawDelta, _bodyRollDelta) * deltaTime));
|
glm::vec3(_bodyPitchDelta, _bodyYawDelta, _bodyRollDelta) * deltaTime));
|
||||||
|
|
||||||
// decay body rotation momentum
|
// decay body rotation momentum
|
||||||
float bodySpinMomentum = 1.0 - BODY_SPIN_FRICTION * deltaTime;
|
float bodySpinMomentum = 1.0 - BODY_SPIN_FRICTION * deltaTime;
|
||||||
if (bodySpinMomentum < 0.0f) { bodySpinMomentum = 0.0f; }
|
if (bodySpinMomentum < 0.0f) { bodySpinMomentum = 0.0f; }
|
||||||
|
@ -553,21 +555,13 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
||||||
_bodyYawDelta *= bodySpinMomentum;
|
_bodyYawDelta *= bodySpinMomentum;
|
||||||
_bodyRollDelta *= bodySpinMomentum;
|
_bodyRollDelta *= bodySpinMomentum;
|
||||||
|
|
||||||
// Decay velocity. If velocity is really low, increase decay to simulate static friction
|
const float MAX_STATIC_FRICTION_VELOCITY = 0.5f;
|
||||||
const float VELOCITY_DECAY_UNDER_THRUST = 0.2;
|
const float STATIC_FRICTION_STRENGTH = 20.f;
|
||||||
const float VELOCITY_FAST_DECAY = 0.6;
|
applyStaticFriction(deltaTime, _velocity, MAX_STATIC_FRICTION_VELOCITY, STATIC_FRICTION_STRENGTH);
|
||||||
const float VELOCITY_SLOW_DECAY = 3.0;
|
|
||||||
const float VELOCITY_FAST_THRESHOLD = 2.0f;
|
const float LINEAR_DAMPING_STRENGTH = 3.0f;
|
||||||
float decayConstant, decay;
|
const float SQUARED_DAMPING_STRENGTH = 0.2f;
|
||||||
if (glm::length(_thrust) > 0.f) {
|
applyDamping(deltaTime, _velocity, LINEAR_DAMPING_STRENGTH, SQUARED_DAMPING_STRENGTH);
|
||||||
decayConstant = VELOCITY_DECAY_UNDER_THRUST;
|
|
||||||
} else if (glm::length(_velocity) > VELOCITY_FAST_THRESHOLD) {
|
|
||||||
decayConstant = VELOCITY_FAST_DECAY;
|
|
||||||
} else {
|
|
||||||
decayConstant = VELOCITY_SLOW_DECAY;
|
|
||||||
}
|
|
||||||
decay = glm::clamp(1.0f - decayConstant * deltaTime, 0.0f, 1.0f);
|
|
||||||
_velocity *= decay;
|
|
||||||
|
|
||||||
//pitch and roll the body as a function of forward speed and turning delta
|
//pitch and roll the body as a function of forward speed and turning delta
|
||||||
const float BODY_PITCH_WHILE_WALKING = -20.0;
|
const float BODY_PITCH_WHILE_WALKING = -20.0;
|
||||||
|
@ -659,6 +653,9 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
||||||
_mode = AVATAR_MODE_INTERACTING;
|
_mode = AVATAR_MODE_INTERACTING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update position by velocity, and subtract the change added earlier for gravity
|
||||||
|
_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
|
||||||
_thrust = glm::vec3(0, 0, 0);
|
_thrust = glm::vec3(0, 0, 0);
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,10 @@ public:
|
||||||
void reset();
|
void reset();
|
||||||
void simulate(float deltaTime, Transmitter* transmitter);
|
void simulate(float deltaTime, Transmitter* transmitter);
|
||||||
void updateThrust(float deltaTime, Transmitter * transmitter);
|
void updateThrust(float deltaTime, Transmitter * transmitter);
|
||||||
void updateFromGyrosAndOrWebcam(bool gyroLook, const glm::vec3& amplifyAngles);
|
void updateFromGyrosAndOrWebcam(bool gyroLook,
|
||||||
|
const glm::vec3& amplifyAngle,
|
||||||
|
float yawFromTouch,
|
||||||
|
float pitchFromTouch);
|
||||||
void addBodyYaw(float y) {_bodyYaw += y;};
|
void addBodyYaw(float y) {_bodyYaw += y;};
|
||||||
void render(bool lookingInMirror, bool renderAvatarBalls);
|
void render(bool lookingInMirror, bool renderAvatarBalls);
|
||||||
|
|
||||||
|
|
40
interface/src/Physics.cpp
Normal file
40
interface/src/Physics.cpp
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
//
|
||||||
|
// Physics.cpp
|
||||||
|
// hifi
|
||||||
|
//
|
||||||
|
// Created by Philip on July 11, 2013
|
||||||
|
//
|
||||||
|
// Routines to help with doing virtual world physics
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <SharedUtil.h>
|
||||||
|
|
||||||
|
#include "Util.h"
|
||||||
|
#include "world.h"
|
||||||
|
#include "Physics.h"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Applies static friction: maxVelocity is the largest velocity for which there
|
||||||
|
// there is friction, and strength is the amount of friction force applied to reduce
|
||||||
|
// velocity.
|
||||||
|
//
|
||||||
|
void applyStaticFriction(float deltaTime, glm::vec3& velocity, float maxVelocity, float strength) {
|
||||||
|
float v = glm::length(velocity);
|
||||||
|
if (v < maxVelocity) {
|
||||||
|
velocity *= glm::clamp((1.0f - deltaTime * strength * (1.f - v / maxVelocity)), 0.0f, 1.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Applies velocity damping, with a strength value for linear and squared velocity damping
|
||||||
|
//
|
||||||
|
|
||||||
|
void applyDamping(float deltaTime, glm::vec3& velocity, float linearStrength, float squaredStrength) {
|
||||||
|
if (squaredStrength == 0.f) {
|
||||||
|
velocity *= glm::clamp(1.f - deltaTime * linearStrength, 0.f, 1.f);
|
||||||
|
} else {
|
||||||
|
velocity *= glm::clamp(1.f - deltaTime * (linearStrength + glm::length(velocity) * squaredStrength), 0.f, 1.f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
15
interface/src/Physics.h
Normal file
15
interface/src/Physics.h
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
//
|
||||||
|
// Balls.h
|
||||||
|
// hifi
|
||||||
|
//
|
||||||
|
// Created by Philip on 4/25/13.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_Physics_h
|
||||||
|
#define hifi_Physics_h
|
||||||
|
|
||||||
|
void applyStaticFriction(float deltaTime, glm::vec3& velocity, float maxVelocity, float strength);
|
||||||
|
void applyDamping(float deltaTime, glm::vec3& velocity, float linearStrength, float squaredStrength);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue