mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-05 16:30:22 +02:00
ahibfasubhdf
This commit is contained in:
parent
0be15231b9
commit
98dd83dde8
9 changed files with 165 additions and 37 deletions
|
@ -195,6 +195,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
||||||
_isTouchPressed(false),
|
_isTouchPressed(false),
|
||||||
_yawFromTouch(0.0f),
|
_yawFromTouch(0.0f),
|
||||||
_pitchFromTouch(0.0f),
|
_pitchFromTouch(0.0f),
|
||||||
|
_groundPlaneImpact(0.0f),
|
||||||
_mousePressed(false),
|
_mousePressed(false),
|
||||||
_mouseVoxelScale(1.0f / 1024.0f),
|
_mouseVoxelScale(1.0f / 1024.0f),
|
||||||
_justEditedVoxel(false),
|
_justEditedVoxel(false),
|
||||||
|
@ -2528,7 +2529,7 @@ void Application::displaySide(Camera& whichCamera) {
|
||||||
|
|
||||||
//draw a grid ground plane....
|
//draw a grid ground plane....
|
||||||
if (_renderGroundPlaneOn->isChecked()) {
|
if (_renderGroundPlaneOn->isChecked()) {
|
||||||
drawGroundPlaneGrid(EDGE_SIZE_GROUND_PLANE);
|
renderGroundPlaneGrid(EDGE_SIZE_GROUND_PLANE, _audio.getCollisionSoundMagnitude());
|
||||||
}
|
}
|
||||||
// Draw voxels
|
// Draw voxels
|
||||||
if (_renderVoxels->isChecked()) {
|
if (_renderVoxels->isChecked()) {
|
||||||
|
@ -2606,6 +2607,9 @@ void Application::displayOverlay() {
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
|
// Display a single screen-size quad to
|
||||||
|
renderCollisionOverlay(_glWidget->width(), _glWidget->height(), _audio.getCollisionSoundMagnitude());
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
_audio.render(_glWidget->width(), _glWidget->height());
|
_audio.render(_glWidget->width(), _glWidget->height());
|
||||||
if (_oscilloscopeOn->isChecked()) {
|
if (_oscilloscopeOn->isChecked()) {
|
||||||
|
|
|
@ -87,6 +87,7 @@ public:
|
||||||
void updateParticleSystem(float deltaTime);
|
void updateParticleSystem(float deltaTime);
|
||||||
|
|
||||||
Avatar* getAvatar() { return &_myAvatar; }
|
Avatar* getAvatar() { return &_myAvatar; }
|
||||||
|
Audio* getAudio() { return &_audio; }
|
||||||
Camera* getCamera() { return &_myCamera; }
|
Camera* getCamera() { return &_myCamera; }
|
||||||
ViewFrustum* getViewFrustum() { return &_viewFrustum; }
|
ViewFrustum* getViewFrustum() { return &_viewFrustum; }
|
||||||
VoxelSystem* getVoxels() { return &_voxels; }
|
VoxelSystem* getVoxels() { return &_voxels; }
|
||||||
|
@ -103,6 +104,9 @@ public:
|
||||||
QNetworkAccessManager* getNetworkAccessManager() { return _networkAccessManager; }
|
QNetworkAccessManager* getNetworkAccessManager() { return _networkAccessManager; }
|
||||||
GeometryCache* getGeometryCache() { return &_geometryCache; }
|
GeometryCache* getGeometryCache() { return &_geometryCache; }
|
||||||
|
|
||||||
|
void setGroundPlaneImpact(float groundPlaneImpact) { _groundPlaneImpact = groundPlaneImpact; }
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void timer();
|
void timer();
|
||||||
|
@ -208,7 +212,7 @@ private:
|
||||||
void deleteVoxelUnderCursor();
|
void deleteVoxelUnderCursor();
|
||||||
void eyedropperVoxelUnderCursor();
|
void eyedropperVoxelUnderCursor();
|
||||||
void resetSensors();
|
void resetSensors();
|
||||||
|
|
||||||
void setMenuShortcutsEnabled(bool enabled);
|
void setMenuShortcutsEnabled(bool enabled);
|
||||||
|
|
||||||
void updateCursor();
|
void updateCursor();
|
||||||
|
@ -348,6 +352,8 @@ private:
|
||||||
float _yawFromTouch;
|
float _yawFromTouch;
|
||||||
float _pitchFromTouch;
|
float _pitchFromTouch;
|
||||||
|
|
||||||
|
float _groundPlaneImpact;
|
||||||
|
|
||||||
VoxelDetail _mouseVoxelDragging;
|
VoxelDetail _mouseVoxelDragging;
|
||||||
glm::vec3 _voxelThrust;
|
glm::vec3 _voxelThrust;
|
||||||
bool _mousePressed; // true if mouse has been pressed (clear when finished)
|
bool _mousePressed; // true if mouse has been pressed (clear when finished)
|
||||||
|
|
|
@ -76,9 +76,12 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o
|
||||||
NodeList* nodeList = NodeList::getInstance();
|
NodeList* nodeList = NodeList::getInstance();
|
||||||
Application* interface = Application::getInstance();
|
Application* interface = Application::getInstance();
|
||||||
Avatar* interfaceAvatar = interface->getAvatar();
|
Avatar* interfaceAvatar = interface->getAvatar();
|
||||||
|
|
||||||
|
memset(outputLeft, 0, PACKET_LENGTH_BYTES_PER_CHANNEL);
|
||||||
|
memset(outputRight, 0, PACKET_LENGTH_BYTES_PER_CHANNEL);
|
||||||
|
|
||||||
// Add Procedural effects to input samples
|
// Add Procedural effects to input samples
|
||||||
addProceduralSounds(inputLeft, BUFFER_LENGTH_SAMPLES_PER_CHANNEL);
|
addProceduralSounds(inputLeft, outputLeft, outputRight, BUFFER_LENGTH_SAMPLES_PER_CHANNEL);
|
||||||
|
|
||||||
if (nodeList && inputLeft) {
|
if (nodeList && inputLeft) {
|
||||||
|
|
||||||
|
@ -135,12 +138,8 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o
|
||||||
+ leadingBytes);
|
+ leadingBytes);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(outputLeft, 0, PACKET_LENGTH_BYTES_PER_CHANNEL);
|
|
||||||
memset(outputRight, 0, PACKET_LENGTH_BYTES_PER_CHANNEL);
|
|
||||||
|
|
||||||
AudioRingBuffer* ringBuffer = &_ringBuffer;
|
AudioRingBuffer* ringBuffer = &_ringBuffer;
|
||||||
|
|
||||||
// if there is anything in the ring buffer, decide what to do:
|
// if there is anything in the ring buffer, decide what to do:
|
||||||
|
@ -251,11 +250,11 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifndef TEST_AUDIO_LOOPBACK
|
#ifndef TEST_AUDIO_LOOPBACK
|
||||||
outputLeft[s] = leftSample;
|
outputLeft[s] += leftSample;
|
||||||
outputRight[s] = rightSample;
|
outputRight[s] += rightSample;
|
||||||
#else
|
#else
|
||||||
outputLeft[s] = inputLeft[s];
|
outputLeft[s] += inputLeft[s];
|
||||||
outputRight[s] = inputLeft[s];
|
outputRight[s] += inputLeft[s];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
ringBuffer->setNextOutput(ringBuffer->getNextOutput() + PACKET_LENGTH_SAMPLES);
|
ringBuffer->setNextOutput(ringBuffer->getNextOutput() + PACKET_LENGTH_SAMPLES);
|
||||||
|
@ -333,7 +332,13 @@ Audio::Audio(Oscilloscope* scope, int16_t initialJitterBufferSamples) :
|
||||||
_lastYawMeasuredMaximum(0),
|
_lastYawMeasuredMaximum(0),
|
||||||
_flangeIntensity(0.0f),
|
_flangeIntensity(0.0f),
|
||||||
_flangeRate(0.0f),
|
_flangeRate(0.0f),
|
||||||
_flangeWeight(0.0f)
|
_flangeWeight(0.0f),
|
||||||
|
_collisionSoundMagnitude(0.0f),
|
||||||
|
_collisionSoundFrequency(0.0f),
|
||||||
|
_collisionSoundNoise(0.0f),
|
||||||
|
_collisionSoundDuration(0.0f),
|
||||||
|
_proceduralEffectSample(0),
|
||||||
|
_heartbeatMagnitude(0.0f)
|
||||||
{
|
{
|
||||||
outputPortAudioError(Pa_Initialize());
|
outputPortAudioError(Pa_Initialize());
|
||||||
|
|
||||||
|
@ -589,7 +594,10 @@ void Audio::lowPassFilter(int16_t* inputBuffer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take a pointer to the acquired microphone input samples and add procedural sounds
|
// Take a pointer to the acquired microphone input samples and add procedural sounds
|
||||||
void Audio::addProceduralSounds(int16_t* inputBuffer, int numSamples) {
|
void Audio::addProceduralSounds(int16_t* inputBuffer,
|
||||||
|
int16_t* outputLeft,
|
||||||
|
int16_t* outputRight,
|
||||||
|
int numSamples) {
|
||||||
const float MAX_AUDIBLE_VELOCITY = 6.0;
|
const float MAX_AUDIBLE_VELOCITY = 6.0;
|
||||||
const float MIN_AUDIBLE_VELOCITY = 0.1;
|
const float MIN_AUDIBLE_VELOCITY = 0.1;
|
||||||
const int VOLUME_BASELINE = 400;
|
const int VOLUME_BASELINE = 400;
|
||||||
|
@ -598,14 +606,48 @@ void Audio::addProceduralSounds(int16_t* inputBuffer, int numSamples) {
|
||||||
float speed = glm::length(_lastVelocity);
|
float speed = glm::length(_lastVelocity);
|
||||||
float volume = VOLUME_BASELINE * (1.f - speed / MAX_AUDIBLE_VELOCITY);
|
float volume = VOLUME_BASELINE * (1.f - speed / MAX_AUDIBLE_VELOCITY);
|
||||||
|
|
||||||
|
int sample;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Travelling noise
|
||||||
|
//
|
||||||
// Add a noise-modulated sinewave with volume that tapers off with speed increasing
|
// Add a noise-modulated sinewave with volume that tapers off with speed increasing
|
||||||
if ((speed > MIN_AUDIBLE_VELOCITY) && (speed < MAX_AUDIBLE_VELOCITY)) {
|
if ((speed > MIN_AUDIBLE_VELOCITY) && (speed < MAX_AUDIBLE_VELOCITY)) {
|
||||||
for (int i = 0; i < numSamples; i++) {
|
for (int i = 0; i < numSamples; i++) {
|
||||||
inputBuffer[i] += (int16_t)((sinf((float) i / SOUND_PITCH * speed) * randFloat()) * volume * speed);
|
inputBuffer[i] += (int16_t)(sinf((float) (_proceduralEffectSample + i) / SOUND_PITCH ) * volume * (1.f + randFloat() * 0.25f) * speed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const float COLLISION_SOUND_CUTOFF_LEVEL = 0.01f;
|
||||||
|
const float COLLISION_SOUND_MAX_VOLUME = 1000.f;
|
||||||
|
const float UP_MAJOR_FIFTH = powf(1.5f, 4.0f);
|
||||||
|
const float DOWN_TWO_OCTAVES = 4.f;
|
||||||
|
const float DOWN_FOUR_OCTAVES = 16.f;
|
||||||
|
float t;
|
||||||
|
if (_collisionSoundMagnitude > COLLISION_SOUND_CUTOFF_LEVEL) {
|
||||||
|
for (int i = 0; i < numSamples; i++) {
|
||||||
|
t = (float) _proceduralEffectSample + (float) i;
|
||||||
|
sample = sinf(t * _collisionSoundFrequency) +
|
||||||
|
sinf(t * _collisionSoundFrequency / DOWN_TWO_OCTAVES) +
|
||||||
|
sinf(t * _collisionSoundFrequency / DOWN_FOUR_OCTAVES * UP_MAJOR_FIFTH);
|
||||||
|
sample *= _collisionSoundMagnitude * COLLISION_SOUND_MAX_VOLUME;
|
||||||
|
inputBuffer[i] += sample;
|
||||||
|
outputLeft[i] += sample;
|
||||||
|
outputRight[i] += sample;
|
||||||
|
_collisionSoundMagnitude *= _collisionSoundDuration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_proceduralEffectSample += numSamples;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Starts a collision sound. magnitude is 0-1, with 1 the loudest possible sound.
|
||||||
|
//
|
||||||
|
void Audio::startCollisionSound(float magnitude, float frequency, float noise, float duration) {
|
||||||
|
_collisionSoundMagnitude = magnitude;
|
||||||
|
_collisionSoundFrequency = frequency;
|
||||||
|
_collisionSoundNoise = noise;
|
||||||
|
_collisionSoundDuration = duration;
|
||||||
|
}
|
||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
// Accoustic ping (audio system round trip time determination)
|
// Accoustic ping (audio system round trip time determination)
|
||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
|
|
|
@ -42,7 +42,11 @@ public:
|
||||||
int getJitterBufferSamples() { return _jitterBufferSamples; };
|
int getJitterBufferSamples() { return _jitterBufferSamples; };
|
||||||
|
|
||||||
void lowPassFilter(int16_t* inputBuffer);
|
void lowPassFilter(int16_t* inputBuffer);
|
||||||
|
|
||||||
|
void startCollisionSound(float magnitude, float frequency, float noise, float duration);
|
||||||
|
float getCollisionSoundMagnitude() { return _collisionSoundMagnitude; };
|
||||||
|
|
||||||
|
|
||||||
void ping();
|
void ping();
|
||||||
|
|
||||||
// Call periodically to eventually perform round trip time analysis,
|
// Call periodically to eventually perform round trip time analysis,
|
||||||
|
@ -80,7 +84,13 @@ private:
|
||||||
float _flangeIntensity;
|
float _flangeIntensity;
|
||||||
float _flangeRate;
|
float _flangeRate;
|
||||||
float _flangeWeight;
|
float _flangeWeight;
|
||||||
|
float _collisionSoundMagnitude;
|
||||||
|
float _collisionSoundFrequency;
|
||||||
|
float _collisionSoundNoise;
|
||||||
|
float _collisionSoundDuration;
|
||||||
|
int _proceduralEffectSample;
|
||||||
|
float _heartbeatMagnitude;
|
||||||
|
|
||||||
// Audio callback in class context.
|
// Audio callback in class context.
|
||||||
inline void performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* outputRight);
|
inline void performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* outputRight);
|
||||||
|
|
||||||
|
@ -92,7 +102,7 @@ private:
|
||||||
inline void analyzePing();
|
inline void analyzePing();
|
||||||
|
|
||||||
// Add sounds that we want the user to not hear themselves, by adding on top of mic input signal
|
// Add sounds that we want the user to not hear themselves, by adding on top of mic input signal
|
||||||
void addProceduralSounds(int16_t* inputBuffer, int numSamples);
|
void addProceduralSounds(int16_t* inputBuffer, int16_t* outputLeft, int16_t* outputRight, int numSamples);
|
||||||
|
|
||||||
|
|
||||||
// Audio callback called by portaudio. Calls 'performIO'.
|
// Audio callback called by portaudio. Calls 'performIO'.
|
||||||
|
|
|
@ -546,8 +546,8 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
||||||
_position += _scale * _gravity * (GRAVITY_EARTH * deltaTime) * deltaTime;
|
_position += _scale * _gravity * (GRAVITY_EARTH * deltaTime) * deltaTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCollisionWithEnvironment();
|
updateCollisionWithEnvironment(deltaTime);
|
||||||
updateCollisionWithVoxels();
|
updateCollisionWithVoxels(deltaTime);
|
||||||
updateAvatarCollisions(deltaTime);
|
updateAvatarCollisions(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -874,29 +874,41 @@ void Avatar::updateCollisionWithSphere(glm::vec3 position, float radius, float d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Avatar::updateCollisionWithEnvironment() {
|
void Avatar::updateCollisionWithEnvironment(float deltaTime) {
|
||||||
|
|
||||||
glm::vec3 up = getBodyUpDirection();
|
glm::vec3 up = getBodyUpDirection();
|
||||||
float radius = _height * 0.125f;
|
float radius = _height * 0.125f;
|
||||||
const float ENVIRONMENT_SURFACE_ELASTICITY = 1.0f;
|
const float ENVIRONMENT_SURFACE_ELASTICITY = 1.0f;
|
||||||
const float ENVIRONMENT_SURFACE_DAMPING = 0.01;
|
const float ENVIRONMENT_SURFACE_DAMPING = 0.01;
|
||||||
|
const float ENVIRONMENT_COLLISION_FREQUENCY = 0.05f;
|
||||||
|
const float VISIBLE_GROUND_COLLISION_VELOCITY = 0.2f;
|
||||||
glm::vec3 penetration;
|
glm::vec3 penetration;
|
||||||
if (Application::getInstance()->getEnvironment()->findCapsulePenetration(
|
if (Application::getInstance()->getEnvironment()->findCapsulePenetration(
|
||||||
_position - up * (_pelvisFloatingHeight - radius),
|
_position - up * (_pelvisFloatingHeight - radius),
|
||||||
_position + up * (_height - _pelvisFloatingHeight - radius), radius, penetration)) {
|
_position + up * (_height - _pelvisFloatingHeight - radius), radius, penetration)) {
|
||||||
|
float velocityTowardCollision = glm::dot(_velocity, glm::normalize(penetration));
|
||||||
|
if (velocityTowardCollision > VISIBLE_GROUND_COLLISION_VELOCITY) {
|
||||||
|
Application::getInstance()->setGroundPlaneImpact(1.0f);
|
||||||
|
}
|
||||||
|
updateCollisionSound(penetration, deltaTime, ENVIRONMENT_COLLISION_FREQUENCY);
|
||||||
|
|
||||||
applyHardCollision(penetration, ENVIRONMENT_SURFACE_ELASTICITY, ENVIRONMENT_SURFACE_DAMPING);
|
applyHardCollision(penetration, ENVIRONMENT_SURFACE_ELASTICITY, ENVIRONMENT_SURFACE_DAMPING);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Avatar::updateCollisionWithVoxels() {
|
void Avatar::updateCollisionWithVoxels(float deltaTime) {
|
||||||
float radius = _height * 0.125f;
|
float radius = _height * 0.125f;
|
||||||
const float VOXEL_ELASTICITY = 1.4f;
|
const float VOXEL_ELASTICITY = 1.4f;
|
||||||
const float VOXEL_DAMPING = 0.0;
|
const float VOXEL_DAMPING = 0.0;
|
||||||
|
const float VOXEL_COLLISION_FREQUENCY = 0.5f;
|
||||||
glm::vec3 penetration;
|
glm::vec3 penetration;
|
||||||
if (Application::getInstance()->getVoxels()->findCapsulePenetration(
|
if (Application::getInstance()->getVoxels()->findCapsulePenetration(
|
||||||
_position - glm::vec3(0.0f, _pelvisFloatingHeight - radius, 0.0f),
|
_position - glm::vec3(0.0f, _pelvisFloatingHeight - radius, 0.0f),
|
||||||
_position + glm::vec3(0.0f, _height - _pelvisFloatingHeight - radius, 0.0f), radius, penetration)) {
|
_position + glm::vec3(0.0f, _height - _pelvisFloatingHeight - radius, 0.0f), radius, penetration)) {
|
||||||
|
updateCollisionSound(penetration, deltaTime, VOXEL_COLLISION_FREQUENCY);
|
||||||
applyHardCollision(penetration, VOXEL_ELASTICITY, VOXEL_DAMPING);
|
applyHardCollision(penetration, VOXEL_ELASTICITY, VOXEL_DAMPING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -925,6 +937,36 @@ void Avatar::applyHardCollision(const glm::vec3& penetration, float elasticity,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Avatar::updateCollisionSound(const glm::vec3 &penetration, float deltaTime, float frequency) {
|
||||||
|
// consider whether to have the collision make a sound
|
||||||
|
const float AUDIBLE_COLLISION_THRESHOLD = 0.02f;
|
||||||
|
const float COLLISION_LOUDNESS = 1.f;
|
||||||
|
const float DURATION_SCALING = 0.004f;
|
||||||
|
const float NOISE_SCALING = 0.1f;
|
||||||
|
glm::vec3 velocity = _velocity;
|
||||||
|
glm::vec3 gravity = getGravity();
|
||||||
|
|
||||||
|
if (glm::length(gravity) > EPSILON) {
|
||||||
|
// If gravity is on, remove the effect of gravity on velocity for this
|
||||||
|
// frame, so that we are not constantly colliding with the surface
|
||||||
|
velocity -= _scale * glm::length(gravity) * GRAVITY_EARTH * deltaTime * glm::normalize(gravity);
|
||||||
|
}
|
||||||
|
float velocityTowardCollision = glm::dot(velocity, glm::normalize(penetration));
|
||||||
|
float velocityTangentToCollision = glm::length(velocity) - velocityTowardCollision;
|
||||||
|
|
||||||
|
if (velocityTowardCollision > AUDIBLE_COLLISION_THRESHOLD) {
|
||||||
|
// Volume is proportional to collision velocity
|
||||||
|
// Base frequency is modified upward by the angle of the collision
|
||||||
|
// Noise is a function of the angle of collision
|
||||||
|
// Duration of the sound is a function of both base frequency and velocity of impact
|
||||||
|
Application::getInstance()->getAudio()->startCollisionSound(
|
||||||
|
fmin(COLLISION_LOUDNESS * velocityTowardCollision, 1.f),
|
||||||
|
frequency * (1.f + velocityTangentToCollision / velocityTowardCollision),
|
||||||
|
fmin(velocityTangentToCollision / velocityTowardCollision * NOISE_SCALING, 1.f),
|
||||||
|
1.f - DURATION_SCALING * powf(frequency, 0.5f) / velocityTowardCollision);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Avatar::updateAvatarCollisions(float deltaTime) {
|
void Avatar::updateAvatarCollisions(float deltaTime) {
|
||||||
|
|
||||||
// Reset detector for nearest avatar
|
// Reset detector for nearest avatar
|
||||||
|
|
|
@ -162,6 +162,8 @@ public:
|
||||||
glm::quat getOrientation () const;
|
glm::quat getOrientation () const;
|
||||||
glm::quat getWorldAlignedOrientation() const;
|
glm::quat getWorldAlignedOrientation() const;
|
||||||
|
|
||||||
|
glm::vec3 getGravity () const { return _gravity; }
|
||||||
|
|
||||||
glm::vec3 getUprightHeadPosition() const;
|
glm::vec3 getUprightHeadPosition() const;
|
||||||
|
|
||||||
AvatarVoxelSystem* getVoxels() { return &_voxels; }
|
AvatarVoxelSystem* getVoxels() { return &_voxels; }
|
||||||
|
@ -262,9 +264,10 @@ private:
|
||||||
void updateAvatarCollisions(float deltaTime);
|
void updateAvatarCollisions(float deltaTime);
|
||||||
void updateArmIKAndConstraints( float deltaTime );
|
void updateArmIKAndConstraints( float deltaTime );
|
||||||
void updateCollisionWithSphere( glm::vec3 position, float radius, float deltaTime );
|
void updateCollisionWithSphere( glm::vec3 position, float radius, float deltaTime );
|
||||||
void updateCollisionWithEnvironment();
|
void updateCollisionWithEnvironment(float deltaTime);
|
||||||
void updateCollisionWithVoxels();
|
void updateCollisionWithVoxels(float deltaTime);
|
||||||
void applyHardCollision(const glm::vec3& penetration, float elasticity, float damping);
|
void applyHardCollision(const glm::vec3& penetration, float elasticity, float damping);
|
||||||
|
void updateCollisionSound(const glm::vec3& penetration, float deltaTime, float frequency);
|
||||||
void applyCollisionWithOtherAvatar( Avatar * other, float deltaTime );
|
void applyCollisionWithOtherAvatar( Avatar * other, float deltaTime );
|
||||||
void checkForMouseRayTouching();
|
void checkForMouseRayTouching();
|
||||||
};
|
};
|
||||||
|
|
|
@ -227,7 +227,8 @@ void Head::simulate(float deltaTime, bool isMine) {
|
||||||
const float CAMERA_FOLLOW_HEAD_RATE_MAX = 0.5f;
|
const float CAMERA_FOLLOW_HEAD_RATE_MAX = 0.5f;
|
||||||
const float CAMERA_FOLLOW_HEAD_RATE_RAMP_RATE = 1.05f;
|
const float CAMERA_FOLLOW_HEAD_RATE_RAMP_RATE = 1.05f;
|
||||||
const float CAMERA_STOP_TOLERANCE_DEGREES = 0.1f;
|
const float CAMERA_STOP_TOLERANCE_DEGREES = 0.1f;
|
||||||
const float CAMERA_START_TOLERANCE_DEGREES = 2.0f;
|
const float CAMERA_PITCH_START_TOLERANCE_DEGREES = 10.0f;
|
||||||
|
const float CAMERA_YAW_START_TOLERANCE_DEGREES = 3.0f;
|
||||||
float cameraHeadAngleDifference = glm::length(glm::vec2(_pitch - _cameraPitch, _yaw - _cameraYaw));
|
float cameraHeadAngleDifference = glm::length(glm::vec2(_pitch - _cameraPitch, _yaw - _cameraYaw));
|
||||||
if (_isCameraMoving) {
|
if (_isCameraMoving) {
|
||||||
_cameraFollowHeadRate = glm::clamp(_cameraFollowHeadRate * CAMERA_FOLLOW_HEAD_RATE_RAMP_RATE,
|
_cameraFollowHeadRate = glm::clamp(_cameraFollowHeadRate * CAMERA_FOLLOW_HEAD_RATE_RAMP_RATE,
|
||||||
|
@ -240,7 +241,8 @@ void Head::simulate(float deltaTime, bool isMine) {
|
||||||
_isCameraMoving = false;
|
_isCameraMoving = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (cameraHeadAngleDifference > CAMERA_START_TOLERANCE_DEGREES) {
|
if ((fabs(_pitch - _cameraPitch) > CAMERA_PITCH_START_TOLERANCE_DEGREES) ||
|
||||||
|
(fabs(_yaw - _cameraYaw) > CAMERA_YAW_START_TOLERANCE_DEGREES)) {
|
||||||
_isCameraMoving = true;
|
_isCameraMoving = true;
|
||||||
_cameraFollowHeadRate = CAMERA_FOLLOW_HEAD_RATE_START;
|
_cameraFollowHeadRate = CAMERA_FOLLOW_HEAD_RATE_START;
|
||||||
}
|
}
|
||||||
|
|
|
@ -325,22 +325,38 @@ void drawvec3(int x, int y, float scale, float rotate, float thick, int mono, gl
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void renderCollisionOverlay(int width, int height, float magnitude) {
|
||||||
|
const float MIN_VISIBLE_COLLISION = 0.01f;
|
||||||
|
if (magnitude > MIN_VISIBLE_COLLISION) {
|
||||||
|
glColor4f(0, 0, 0, magnitude);
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glVertex2f(0, 0);
|
||||||
|
glVertex2d(width, 0);
|
||||||
|
glVertex2d(width, height);
|
||||||
|
glVertex2d(0, height);
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void drawGroundPlaneGrid(float size) {
|
void renderGroundPlaneGrid(float size, float impact) {
|
||||||
glColor3f(0.4f, 0.5f, 0.3f);
|
|
||||||
glLineWidth(2.0);
|
glLineWidth(2.0);
|
||||||
|
glm::vec4 impactColor(1, 0, 0, 1);
|
||||||
|
glm::vec3 lineColor(0.4, 0.5, 0.3);
|
||||||
|
glm::vec4 surfaceColor(0.5, 0.5, 0.5, 0.4);
|
||||||
|
|
||||||
|
glColor3fv(&lineColor.x);
|
||||||
for (float x = 0; x <= size; x++) {
|
for (float x = 0; x <= size; x++) {
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
glVertex3f(x, 0.0f, 0);
|
glVertex3f(x, 0, 0);
|
||||||
glVertex3f(x, 0.0f, size);
|
glVertex3f(x, 0, size);
|
||||||
glVertex3f(0, 0.0f, x);
|
glVertex3f(0, 0, x);
|
||||||
glVertex3f(size, 0.0f, x);
|
glVertex3f(size, 0, x);
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a translucent quad just underneath the grid.
|
// Draw the floor, colored for recent impact
|
||||||
glColor4f(0.5, 0.5, 0.5, 0.4);
|
glm::vec4 floorColor = impact * impactColor + (1.f - impact) * surfaceColor;
|
||||||
|
glColor4fv(&floorColor.x);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glVertex3f(0, 0, 0);
|
glVertex3f(0, 0, 0);
|
||||||
glVertex3f(size, 0, 0);
|
glVertex3f(size, 0, 0);
|
||||||
|
|
|
@ -57,7 +57,10 @@ glm::quat safeMix(const glm::quat& q1, const glm::quat& q2, float alpha);
|
||||||
|
|
||||||
double diffclock(timeval *clock1,timeval *clock2);
|
double diffclock(timeval *clock1,timeval *clock2);
|
||||||
|
|
||||||
void drawGroundPlaneGrid(float size);
|
void renderGroundPlaneGrid(float size, float impact);
|
||||||
|
|
||||||
|
void renderCollisionOverlay(int width, int height, float magnitude);
|
||||||
|
|
||||||
|
|
||||||
void renderDiskShadow(glm::vec3 position, glm::vec3 upDirection, float radius, float darkness);
|
void renderDiskShadow(glm::vec3 position, glm::vec3 upDirection, float radius, float darkness);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue