mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 08:04:01 +02:00
Merge remote-tracking branch 'upstream/master' into synthesis
This commit is contained in:
commit
4348702dd2
27 changed files with 1523 additions and 1396 deletions
|
@ -52,9 +52,18 @@ void attachAvatarDataToAgent(Agent* newAgent) {
|
|||
}
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
|
||||
AgentList* agentList = AgentList::createInstance(AGENT_TYPE_AVATAR_MIXER, AVATAR_LISTEN_PORT);
|
||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||
|
||||
// Handle Local Domain testing with the --local command line
|
||||
const char* local = "--local";
|
||||
if (cmdOptionExists(argc, argv, local)) {
|
||||
printf("Local Domain MODE!\n");
|
||||
int ip = getLocalAddress();
|
||||
sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));
|
||||
}
|
||||
|
||||
agentList->linkedDataCreateCallback = attachAvatarDataToAgent;
|
||||
|
||||
agentList->startDomainServerCheckInThread();
|
||||
|
|
|
@ -1,48 +1,106 @@
|
|||
#version 120
|
||||
|
||||
//
|
||||
// For licensing information, see http://http.developer.nvidia.com/GPUGems/gpugems_app01.html:
|
||||
//
|
||||
// NVIDIA Statement on the Software
|
||||
//
|
||||
// The source code provided is freely distributable, so long as the NVIDIA header remains unaltered and user modifications are
|
||||
// detailed.
|
||||
//
|
||||
// No Warranty
|
||||
//
|
||||
// THE SOFTWARE AND ANY OTHER MATERIALS PROVIDED BY NVIDIA ON THE ENCLOSED CD-ROM ARE PROVIDED "AS IS." NVIDIA DISCLAIMS ALL
|
||||
// WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
//
|
||||
// Limitation of Liability
|
||||
//
|
||||
// NVIDIA SHALL NOT BE LIABLE TO ANY USER, DEVELOPER, DEVELOPER'S CUSTOMERS, OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH OR
|
||||
// UNDER DEVELOPER FOR ANY LOSS OF PROFITS, INCOME, SAVINGS, OR ANY OTHER CONSEQUENTIAL, INCIDENTAL, SPECIAL, PUNITIVE, DIRECT
|
||||
// OR INDIRECT DAMAGES (WHETHER IN AN ACTION IN CONTRACT, TORT OR BASED ON A WARRANTY), EVEN IF NVIDIA HAS BEEN ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF THE ESSENTIAL PURPOSE OF ANY
|
||||
// LIMITED REMEDY. IN NO EVENT SHALL NVIDIA'S AGGREGATE LIABILITY TO DEVELOPER OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH
|
||||
// OR UNDER DEVELOPER EXCEED THE AMOUNT OF MONEY ACTUALLY PAID BY DEVELOPER TO NVIDIA FOR THE SOFTWARE OR ANY OTHER MATERIALS.
|
||||
//
|
||||
|
||||
//
|
||||
// Atmospheric scattering fragment shader
|
||||
//
|
||||
// Author: Sean O'Neil
|
||||
//
|
||||
// Copyright (c) 2004 Sean O'Neil
|
||||
//
|
||||
|
||||
uniform vec3 v3LightPos;
|
||||
uniform float g;
|
||||
uniform float g2;
|
||||
|
||||
varying vec3 v3Direction;
|
||||
|
||||
|
||||
void main (void)
|
||||
{
|
||||
float fCos = dot(v3LightPos, v3Direction) / length(v3Direction);
|
||||
float fMiePhase = 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos*fCos) / pow(1.0 + g2 - 2.0*g*fCos, 1.5);
|
||||
gl_FragColor = gl_Color + fMiePhase * gl_SecondaryColor;
|
||||
gl_FragColor.a = gl_FragColor.b;
|
||||
}
|
||||
#version 120
|
||||
|
||||
//
|
||||
// For licensing information, see http://http.developer.nvidia.com/GPUGems/gpugems_app01.html:
|
||||
//
|
||||
// NVIDIA Statement on the Software
|
||||
//
|
||||
// The source code provided is freely distributable, so long as the NVIDIA header remains unaltered and user modifications are
|
||||
// detailed.
|
||||
//
|
||||
// No Warranty
|
||||
//
|
||||
// THE SOFTWARE AND ANY OTHER MATERIALS PROVIDED BY NVIDIA ON THE ENCLOSED CD-ROM ARE PROVIDED "AS IS." NVIDIA DISCLAIMS ALL
|
||||
// WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
//
|
||||
// Limitation of Liability
|
||||
//
|
||||
// NVIDIA SHALL NOT BE LIABLE TO ANY USER, DEVELOPER, DEVELOPER'S CUSTOMERS, OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH OR
|
||||
// UNDER DEVELOPER FOR ANY LOSS OF PROFITS, INCOME, SAVINGS, OR ANY OTHER CONSEQUENTIAL, INCIDENTAL, SPECIAL, PUNITIVE, DIRECT
|
||||
// OR INDIRECT DAMAGES (WHETHER IN AN ACTION IN CONTRACT, TORT OR BASED ON A WARRANTY), EVEN IF NVIDIA HAS BEEN ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF THE ESSENTIAL PURPOSE OF ANY
|
||||
// LIMITED REMEDY. IN NO EVENT SHALL NVIDIA'S AGGREGATE LIABILITY TO DEVELOPER OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH
|
||||
// OR UNDER DEVELOPER EXCEED THE AMOUNT OF MONEY ACTUALLY PAID BY DEVELOPER TO NVIDIA FOR THE SOFTWARE OR ANY OTHER MATERIALS.
|
||||
//
|
||||
|
||||
//
|
||||
// Atmospheric scattering fragment shader
|
||||
//
|
||||
// Author: Sean O'Neil
|
||||
//
|
||||
// Copyright (c) 2004 Sean O'Neil
|
||||
//
|
||||
|
||||
uniform vec3 v3CameraPos; // The camera's current position
|
||||
uniform vec3 v3InvWavelength; // 1 / pow(wavelength, 4) for the red, green, and blue channels
|
||||
uniform float fInnerRadius; // The inner (planetary) radius
|
||||
uniform float fKrESun; // Kr * ESun
|
||||
uniform float fKmESun; // Km * ESun
|
||||
uniform float fKr4PI; // Kr * 4 * PI
|
||||
uniform float fKm4PI; // Km * 4 * PI
|
||||
uniform float fScale; // 1 / (fOuterRadius - fInnerRadius)
|
||||
uniform float fScaleDepth; // The scale depth (i.e. the altitude at which the atmosphere's average density is found)
|
||||
uniform float fScaleOverScaleDepth; // fScale / fScaleDepth
|
||||
|
||||
const int nSamples = 2;
|
||||
const float fSamples = 2.0;
|
||||
|
||||
uniform vec3 v3LightPos;
|
||||
uniform float g;
|
||||
uniform float g2;
|
||||
|
||||
varying vec3 position;
|
||||
|
||||
float scale(float fCos)
|
||||
{
|
||||
float x = 1.0 - fCos;
|
||||
return fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));
|
||||
}
|
||||
|
||||
void main (void)
|
||||
{
|
||||
// Get the ray from the camera to the vertex, and its length (which is the far point of the ray passing through the atmosphere)
|
||||
vec3 v3Pos = position;
|
||||
vec3 v3Ray = v3Pos - v3CameraPos;
|
||||
float fFar = length(v3Ray);
|
||||
v3Ray /= fFar;
|
||||
|
||||
// Calculate the ray's starting position, then calculate its scattering offset
|
||||
vec3 v3Start = v3CameraPos;
|
||||
float fHeight = length(v3Start);
|
||||
float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight));
|
||||
float fStartAngle = dot(v3Ray, v3Start) / fHeight;
|
||||
float fStartOffset = fDepth * scale(fStartAngle);
|
||||
|
||||
// Initialize the scattering loop variables
|
||||
//gl_FrontColor = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
float fSampleLength = fFar / fSamples;
|
||||
float fScaledLength = fSampleLength * fScale;
|
||||
vec3 v3SampleRay = v3Ray * fSampleLength;
|
||||
vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5;
|
||||
|
||||
// Now loop through the sample rays
|
||||
vec3 v3FrontColor = vec3(0.0, 0.0, 0.0);
|
||||
for(int i=0; i<nSamples; i++)
|
||||
{
|
||||
float fHeight = length(v3SamplePoint);
|
||||
float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight));
|
||||
float fLightAngle = dot(v3LightPos, v3SamplePoint) / fHeight;
|
||||
float fCameraAngle = dot((v3Ray), v3SamplePoint) / fHeight * 0.99;
|
||||
float fScatter = (fStartOffset + fDepth * (scale(fLightAngle) - scale(fCameraAngle)));
|
||||
vec3 v3Attenuate = exp(-fScatter * (v3InvWavelength * fKr4PI + fKm4PI));
|
||||
v3FrontColor += v3Attenuate * (fDepth * fScaledLength);
|
||||
v3SamplePoint += v3SampleRay;
|
||||
}
|
||||
|
||||
// Finally, scale the Mie and Rayleigh colors and set up the varying variables for the pixel shader
|
||||
vec3 secondaryFrontColor = v3FrontColor * fKmESun;
|
||||
vec3 frontColor = v3FrontColor * (v3InvWavelength * fKrESun);
|
||||
vec3 v3Direction = v3CameraPos - v3Pos;
|
||||
|
||||
float fCos = dot(v3LightPos, v3Direction) / length(v3Direction);
|
||||
float fMiePhase = 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos*fCos) / pow(1.0 + g2 - 2.0*g*fCos, 1.5);
|
||||
gl_FragColor.rgb = frontColor.rgb + fMiePhase * secondaryFrontColor.rgb;
|
||||
gl_FragColor.a = gl_FragColor.b;
|
||||
}
|
||||
|
|
|
@ -1,100 +1,65 @@
|
|||
#version 120
|
||||
|
||||
//
|
||||
// For licensing information, see http://http.developer.nvidia.com/GPUGems/gpugems_app01.html:
|
||||
//
|
||||
// NVIDIA Statement on the Software
|
||||
//
|
||||
// The source code provided is freely distributable, so long as the NVIDIA header remains unaltered and user modifications are
|
||||
// detailed.
|
||||
//
|
||||
// No Warranty
|
||||
//
|
||||
// THE SOFTWARE AND ANY OTHER MATERIALS PROVIDED BY NVIDIA ON THE ENCLOSED CD-ROM ARE PROVIDED "AS IS." NVIDIA DISCLAIMS ALL
|
||||
// WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
//
|
||||
// Limitation of Liability
|
||||
//
|
||||
// NVIDIA SHALL NOT BE LIABLE TO ANY USER, DEVELOPER, DEVELOPER'S CUSTOMERS, OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH OR
|
||||
// UNDER DEVELOPER FOR ANY LOSS OF PROFITS, INCOME, SAVINGS, OR ANY OTHER CONSEQUENTIAL, INCIDENTAL, SPECIAL, PUNITIVE, DIRECT
|
||||
// OR INDIRECT DAMAGES (WHETHER IN AN ACTION IN CONTRACT, TORT OR BASED ON A WARRANTY), EVEN IF NVIDIA HAS BEEN ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF THE ESSENTIAL PURPOSE OF ANY
|
||||
// LIMITED REMEDY. IN NO EVENT SHALL NVIDIA'S AGGREGATE LIABILITY TO DEVELOPER OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH
|
||||
// OR UNDER DEVELOPER EXCEED THE AMOUNT OF MONEY ACTUALLY PAID BY DEVELOPER TO NVIDIA FOR THE SOFTWARE OR ANY OTHER MATERIALS.
|
||||
//
|
||||
|
||||
//
|
||||
// Atmospheric scattering vertex shader
|
||||
//
|
||||
// Author: Sean O'Neil
|
||||
//
|
||||
// Copyright (c) 2004 Sean O'Neil
|
||||
//
|
||||
|
||||
uniform vec3 v3CameraPos; // The camera's current position
|
||||
uniform vec3 v3LightPos; // The direction vector to the light source
|
||||
uniform vec3 v3InvWavelength; // 1 / pow(wavelength, 4) for the red, green, and blue channels
|
||||
uniform float fInnerRadius; // The inner (planetary) radius
|
||||
uniform float fKrESun; // Kr * ESun
|
||||
uniform float fKmESun; // Km * ESun
|
||||
uniform float fKr4PI; // Kr * 4 * PI
|
||||
uniform float fKm4PI; // Km * 4 * PI
|
||||
uniform float fScale; // 1 / (fOuterRadius - fInnerRadius)
|
||||
uniform float fScaleDepth; // The scale depth (i.e. the altitude at which the atmosphere's average density is found)
|
||||
uniform float fScaleOverScaleDepth; // fScale / fScaleDepth
|
||||
|
||||
const int nSamples = 2;
|
||||
const float fSamples = 2.0;
|
||||
|
||||
varying vec3 v3Direction;
|
||||
|
||||
|
||||
float scale(float fCos)
|
||||
{
|
||||
float x = 1.0 - fCos;
|
||||
return fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
// Get the ray from the camera to the vertex, and its length (which is the far point of the ray passing through the atmosphere)
|
||||
vec3 v3Pos = gl_Vertex.xyz;
|
||||
vec3 v3Ray = v3Pos - v3CameraPos;
|
||||
float fFar = length(v3Ray);
|
||||
v3Ray /= fFar;
|
||||
|
||||
// Calculate the ray's starting position, then calculate its scattering offset
|
||||
vec3 v3Start = v3CameraPos;
|
||||
float fHeight = length(v3Start);
|
||||
float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight));
|
||||
float fStartAngle = dot(v3Ray, v3Start) / fHeight;
|
||||
float fStartOffset = fDepth * scale(fStartAngle);
|
||||
|
||||
// Initialize the scattering loop variables
|
||||
//gl_FrontColor = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
float fSampleLength = fFar / fSamples;
|
||||
float fScaledLength = fSampleLength * fScale;
|
||||
vec3 v3SampleRay = v3Ray * fSampleLength;
|
||||
vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5;
|
||||
|
||||
// Now loop through the sample rays
|
||||
vec3 v3FrontColor = vec3(0.0, 0.0, 0.0);
|
||||
for(int i=0; i<nSamples; i++)
|
||||
{
|
||||
float fHeight = length(v3SamplePoint);
|
||||
float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight));
|
||||
float fLightAngle = dot(v3LightPos, v3SamplePoint) / fHeight;
|
||||
float fCameraAngle = dot(v3Ray, v3SamplePoint) / fHeight;
|
||||
float fScatter = (fStartOffset + fDepth * (scale(fLightAngle) - scale(fCameraAngle)));
|
||||
vec3 v3Attenuate = exp(-fScatter * (v3InvWavelength * fKr4PI + fKm4PI));
|
||||
v3FrontColor += v3Attenuate * (fDepth * fScaledLength);
|
||||
v3SamplePoint += v3SampleRay;
|
||||
}
|
||||
|
||||
// Finally, scale the Mie and Rayleigh colors and set up the varying variables for the pixel shader
|
||||
gl_FrontSecondaryColor.rgb = v3FrontColor * fKmESun;
|
||||
gl_FrontColor.rgb = v3FrontColor * (v3InvWavelength * fKrESun);
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
v3Direction = v3CameraPos - v3Pos;
|
||||
}
|
||||
#version 120
|
||||
|
||||
//
|
||||
// For licensing information, see http://http.developer.nvidia.com/GPUGems/gpugems_app01.html:
|
||||
//
|
||||
// NVIDIA Statement on the Software
|
||||
//
|
||||
// The source code provided is freely distributable, so long as the NVIDIA header remains unaltered and user modifications are
|
||||
// detailed.
|
||||
//
|
||||
// No Warranty
|
||||
//
|
||||
// THE SOFTWARE AND ANY OTHER MATERIALS PROVIDED BY NVIDIA ON THE ENCLOSED CD-ROM ARE PROVIDED "AS IS." NVIDIA DISCLAIMS ALL
|
||||
// WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
//
|
||||
// Limitation of Liability
|
||||
//
|
||||
// NVIDIA SHALL NOT BE LIABLE TO ANY USER, DEVELOPER, DEVELOPER'S CUSTOMERS, OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH OR
|
||||
// UNDER DEVELOPER FOR ANY LOSS OF PROFITS, INCOME, SAVINGS, OR ANY OTHER CONSEQUENTIAL, INCIDENTAL, SPECIAL, PUNITIVE, DIRECT
|
||||
// OR INDIRECT DAMAGES (WHETHER IN AN ACTION IN CONTRACT, TORT OR BASED ON A WARRANTY), EVEN IF NVIDIA HAS BEEN ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF THE ESSENTIAL PURPOSE OF ANY
|
||||
// LIMITED REMEDY. IN NO EVENT SHALL NVIDIA'S AGGREGATE LIABILITY TO DEVELOPER OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH
|
||||
// OR UNDER DEVELOPER EXCEED THE AMOUNT OF MONEY ACTUALLY PAID BY DEVELOPER TO NVIDIA FOR THE SOFTWARE OR ANY OTHER MATERIALS.
|
||||
//
|
||||
|
||||
//
|
||||
// Atmospheric scattering vertex shader
|
||||
//
|
||||
// Author: Sean O'Neil
|
||||
//
|
||||
// Copyright (c) 2004 Sean O'Neil
|
||||
//
|
||||
|
||||
uniform vec3 v3CameraPos; // The camera's current position
|
||||
uniform vec3 v3LightPos; // The direction vector to the light source
|
||||
uniform vec3 v3InvWavelength; // 1 / pow(wavelength, 4) for the red, green, and blue channels
|
||||
uniform float fInnerRadius; // The inner (planetary) radius
|
||||
uniform float fKrESun; // Kr * ESun
|
||||
uniform float fKmESun; // Km * ESun
|
||||
uniform float fKr4PI; // Kr * 4 * PI
|
||||
uniform float fKm4PI; // Km * 4 * PI
|
||||
uniform float fScale; // 1 / (fOuterRadius - fInnerRadius)
|
||||
uniform float fScaleDepth; // The scale depth (i.e. the altitude at which the atmosphere's average density is found)
|
||||
uniform float fScaleOverScaleDepth; // fScale / fScaleDepth
|
||||
|
||||
const int nSamples = 2;
|
||||
const float fSamples = 2.0;
|
||||
|
||||
varying vec3 position;
|
||||
|
||||
|
||||
float scale(float fCos)
|
||||
{
|
||||
float x = 1.0 - fCos;
|
||||
return fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
// Get the ray from the camera to the vertex, and its length (which is the far point of the ray passing through the atmosphere)
|
||||
position = gl_Vertex.xyz;
|
||||
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
}
|
||||
|
|
|
@ -1,48 +1,113 @@
|
|||
#version 120
|
||||
|
||||
//
|
||||
// For licensing information, see http://http.developer.nvidia.com/GPUGems/gpugems_app01.html:
|
||||
//
|
||||
// NVIDIA Statement on the Software
|
||||
//
|
||||
// The source code provided is freely distributable, so long as the NVIDIA header remains unaltered and user modifications are
|
||||
// detailed.
|
||||
//
|
||||
// No Warranty
|
||||
//
|
||||
// THE SOFTWARE AND ANY OTHER MATERIALS PROVIDED BY NVIDIA ON THE ENCLOSED CD-ROM ARE PROVIDED "AS IS." NVIDIA DISCLAIMS ALL
|
||||
// WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
//
|
||||
// Limitation of Liability
|
||||
//
|
||||
// NVIDIA SHALL NOT BE LIABLE TO ANY USER, DEVELOPER, DEVELOPER'S CUSTOMERS, OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH OR
|
||||
// UNDER DEVELOPER FOR ANY LOSS OF PROFITS, INCOME, SAVINGS, OR ANY OTHER CONSEQUENTIAL, INCIDENTAL, SPECIAL, PUNITIVE, DIRECT
|
||||
// OR INDIRECT DAMAGES (WHETHER IN AN ACTION IN CONTRACT, TORT OR BASED ON A WARRANTY), EVEN IF NVIDIA HAS BEEN ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF THE ESSENTIAL PURPOSE OF ANY
|
||||
// LIMITED REMEDY. IN NO EVENT SHALL NVIDIA'S AGGREGATE LIABILITY TO DEVELOPER OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH
|
||||
// OR UNDER DEVELOPER EXCEED THE AMOUNT OF MONEY ACTUALLY PAID BY DEVELOPER TO NVIDIA FOR THE SOFTWARE OR ANY OTHER MATERIALS.
|
||||
//
|
||||
|
||||
//
|
||||
// Atmospheric scattering fragment shader
|
||||
//
|
||||
// Author: Sean O'Neil
|
||||
//
|
||||
// Copyright (c) 2004 Sean O'Neil
|
||||
//
|
||||
|
||||
uniform vec3 v3LightPos;
|
||||
uniform float g;
|
||||
uniform float g2;
|
||||
|
||||
varying vec3 v3Direction;
|
||||
|
||||
|
||||
void main (void)
|
||||
{
|
||||
float fCos = dot(v3LightPos, v3Direction) / length(v3Direction);
|
||||
float fMiePhase = 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos*fCos) / pow(1.0 + g2 - 2.0*g*fCos, 1.5);
|
||||
gl_FragColor = gl_Color + fMiePhase * gl_SecondaryColor;
|
||||
gl_FragColor.a = gl_FragColor.b;
|
||||
}
|
||||
#version 120
|
||||
|
||||
//
|
||||
// For licensing information, see http://http.developer.nvidia.com/GPUGems/gpugems_app01.html:
|
||||
//
|
||||
// NVIDIA Statement on the Software
|
||||
//
|
||||
// The source code provided is freely distributable, so long as the NVIDIA header remains unaltered and user modifications are
|
||||
// detailed.
|
||||
//
|
||||
// No Warranty
|
||||
//
|
||||
// THE SOFTWARE AND ANY OTHER MATERIALS PROVIDED BY NVIDIA ON THE ENCLOSED CD-ROM ARE PROVIDED "AS IS." NVIDIA DISCLAIMS ALL
|
||||
// WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
//
|
||||
// Limitation of Liability
|
||||
//
|
||||
// NVIDIA SHALL NOT BE LIABLE TO ANY USER, DEVELOPER, DEVELOPER'S CUSTOMERS, OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH OR
|
||||
// UNDER DEVELOPER FOR ANY LOSS OF PROFITS, INCOME, SAVINGS, OR ANY OTHER CONSEQUENTIAL, INCIDENTAL, SPECIAL, PUNITIVE, DIRECT
|
||||
// OR INDIRECT DAMAGES (WHETHER IN AN ACTION IN CONTRACT, TORT OR BASED ON A WARRANTY), EVEN IF NVIDIA HAS BEEN ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF THE ESSENTIAL PURPOSE OF ANY
|
||||
// LIMITED REMEDY. IN NO EVENT SHALL NVIDIA'S AGGREGATE LIABILITY TO DEVELOPER OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH
|
||||
// OR UNDER DEVELOPER EXCEED THE AMOUNT OF MONEY ACTUALLY PAID BY DEVELOPER TO NVIDIA FOR THE SOFTWARE OR ANY OTHER MATERIALS.
|
||||
//
|
||||
|
||||
//
|
||||
// Atmospheric scattering fragment shader
|
||||
//
|
||||
// Author: Sean O'Neil
|
||||
//
|
||||
// Copyright (c) 2004 Sean O'Neil
|
||||
//
|
||||
|
||||
uniform vec3 v3CameraPos; // The camera's current position
|
||||
uniform vec3 v3LightPos; // The direction vector to the light source
|
||||
uniform vec3 v3InvWavelength; // 1 / pow(wavelength, 4) for the red, green, and blue channels
|
||||
uniform float fCameraHeight2; // fCameraHeight^2
|
||||
uniform float fOuterRadius; // The outer (atmosphere) radius
|
||||
uniform float fOuterRadius2; // fOuterRadius^2
|
||||
uniform float fInnerRadius; // The inner (planetary) radius
|
||||
uniform float fKrESun; // Kr * ESun
|
||||
uniform float fKmESun; // Km * ESun
|
||||
uniform float fKr4PI; // Kr * 4 * PI
|
||||
uniform float fKm4PI; // Km * 4 * PI
|
||||
uniform float fScale; // 1 / (fOuterRadius - fInnerRadius)
|
||||
uniform float fScaleDepth; // The scale depth (i.e. the altitude at which the atmosphere's average density is found)
|
||||
uniform float fScaleOverScaleDepth; // fScale / fScaleDepth
|
||||
|
||||
uniform float g;
|
||||
uniform float g2;
|
||||
|
||||
const int nSamples = 2;
|
||||
const float fSamples = 2.0;
|
||||
|
||||
varying vec3 position;
|
||||
|
||||
float scale(float fCos)
|
||||
{
|
||||
float x = 1.0 - fCos;
|
||||
return fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));
|
||||
}
|
||||
|
||||
|
||||
void main (void)
|
||||
{
|
||||
// Get the ray from the camera to the vertex and its length (which is the far point of the ray passing through the atmosphere)
|
||||
vec3 v3Pos = position;
|
||||
vec3 v3Ray = v3Pos - v3CameraPos;
|
||||
float fFar = length(v3Ray);
|
||||
v3Ray /= fFar;
|
||||
|
||||
// Calculate the closest intersection of the ray with the outer atmosphere (which is the near point of the ray passing through the atmosphere)
|
||||
float B = 2.0 * dot(v3CameraPos, v3Ray);
|
||||
float C = fCameraHeight2 - fOuterRadius2;
|
||||
float fDet = max(0.0, B*B - 4.0 * C);
|
||||
float fNear = 0.5 * (-B - sqrt(fDet));
|
||||
|
||||
// Calculate the ray's starting position, then calculate its scattering offset
|
||||
vec3 v3Start = v3CameraPos + v3Ray * fNear;
|
||||
fFar -= fNear;
|
||||
float fStartAngle = dot(v3Ray, v3Start) / fOuterRadius;
|
||||
float fStartDepth = exp(-1.0 / fScaleDepth);
|
||||
float fStartOffset = fStartDepth * scale(fStartAngle);
|
||||
|
||||
// Initialize the scattering loop variables
|
||||
//gl_FrontColor = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
float fSampleLength = fFar / fSamples;
|
||||
float fScaledLength = fSampleLength * fScale;
|
||||
vec3 v3SampleRay = v3Ray * fSampleLength;
|
||||
vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5;
|
||||
|
||||
// Now loop through the sample rays
|
||||
vec3 v3FrontColor = vec3(0.0, 0.0, 0.0);
|
||||
for(int i=0; i<nSamples; i++)
|
||||
{
|
||||
float fHeight = length(v3SamplePoint);
|
||||
float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight));
|
||||
float fLightAngle = dot(v3LightPos, v3SamplePoint) / fHeight;
|
||||
float fCameraAngle = dot((v3Ray), v3SamplePoint) / fHeight * 0.99;
|
||||
float fScatter = (fStartOffset + fDepth * (scale(fLightAngle) - scale(fCameraAngle)));
|
||||
vec3 v3Attenuate = exp(-fScatter * (v3InvWavelength * fKr4PI + fKm4PI));
|
||||
v3FrontColor += v3Attenuate * (fDepth * fScaledLength);
|
||||
v3SamplePoint += v3SampleRay;
|
||||
}
|
||||
vec3 v3Direction = v3CameraPos - v3Pos;
|
||||
float fCos = dot(v3LightPos, v3Direction) / length(v3Direction);
|
||||
float fMiePhase = 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos*fCos) / pow(1.0 + g2 - 2.0*g*fCos, 1.5);
|
||||
vec3 color = v3FrontColor * (v3InvWavelength * fKrESun);
|
||||
vec3 secondaryColor = v3FrontColor * fKmESun;
|
||||
gl_FragColor.rgb = color + fMiePhase * secondaryColor;
|
||||
gl_FragColor.a = gl_FragColor.b;
|
||||
}
|
||||
|
|
|
@ -1,109 +1,41 @@
|
|||
#version 120
|
||||
|
||||
//
|
||||
// For licensing information, see http://http.developer.nvidia.com/GPUGems/gpugems_app01.html:
|
||||
//
|
||||
// NVIDIA Statement on the Software
|
||||
//
|
||||
// The source code provided is freely distributable, so long as the NVIDIA header remains unaltered and user modifications are
|
||||
// detailed.
|
||||
//
|
||||
// No Warranty
|
||||
//
|
||||
// THE SOFTWARE AND ANY OTHER MATERIALS PROVIDED BY NVIDIA ON THE ENCLOSED CD-ROM ARE PROVIDED "AS IS." NVIDIA DISCLAIMS ALL
|
||||
// WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
//
|
||||
// Limitation of Liability
|
||||
//
|
||||
// NVIDIA SHALL NOT BE LIABLE TO ANY USER, DEVELOPER, DEVELOPER'S CUSTOMERS, OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH OR
|
||||
// UNDER DEVELOPER FOR ANY LOSS OF PROFITS, INCOME, SAVINGS, OR ANY OTHER CONSEQUENTIAL, INCIDENTAL, SPECIAL, PUNITIVE, DIRECT
|
||||
// OR INDIRECT DAMAGES (WHETHER IN AN ACTION IN CONTRACT, TORT OR BASED ON A WARRANTY), EVEN IF NVIDIA HAS BEEN ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF THE ESSENTIAL PURPOSE OF ANY
|
||||
// LIMITED REMEDY. IN NO EVENT SHALL NVIDIA'S AGGREGATE LIABILITY TO DEVELOPER OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH
|
||||
// OR UNDER DEVELOPER EXCEED THE AMOUNT OF MONEY ACTUALLY PAID BY DEVELOPER TO NVIDIA FOR THE SOFTWARE OR ANY OTHER MATERIALS.
|
||||
//
|
||||
|
||||
//
|
||||
// Atmospheric scattering vertex shader
|
||||
//
|
||||
// Author: Sean O'Neil
|
||||
//
|
||||
// Copyright (c) 2004 Sean O'Neil
|
||||
//
|
||||
|
||||
uniform vec3 v3CameraPos; // The camera's current position
|
||||
uniform vec3 v3LightPos; // The direction vector to the light source
|
||||
uniform vec3 v3InvWavelength; // 1 / pow(wavelength, 4) for the red, green, and blue channels
|
||||
uniform float fCameraHeight2; // fCameraHeight^2
|
||||
uniform float fOuterRadius; // The outer (atmosphere) radius
|
||||
uniform float fOuterRadius2; // fOuterRadius^2
|
||||
uniform float fInnerRadius; // The inner (planetary) radius
|
||||
uniform float fKrESun; // Kr * ESun
|
||||
uniform float fKmESun; // Km * ESun
|
||||
uniform float fKr4PI; // Kr * 4 * PI
|
||||
uniform float fKm4PI; // Km * 4 * PI
|
||||
uniform float fScale; // 1 / (fOuterRadius - fInnerRadius)
|
||||
uniform float fScaleDepth; // The scale depth (i.e. the altitude at which the atmosphere's average density is found)
|
||||
uniform float fScaleOverScaleDepth; // fScale / fScaleDepth
|
||||
|
||||
const int nSamples = 2;
|
||||
const float fSamples = 2.0;
|
||||
|
||||
varying vec3 v3Direction;
|
||||
|
||||
|
||||
float scale(float fCos)
|
||||
{
|
||||
float x = 1.0 - fCos;
|
||||
return fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
// Get the ray from the camera to the vertex and its length (which is the far point of the ray passing through the atmosphere)
|
||||
vec3 v3Pos = gl_Vertex.xyz;
|
||||
vec3 v3Ray = v3Pos - v3CameraPos;
|
||||
float fFar = length(v3Ray);
|
||||
v3Ray /= fFar;
|
||||
|
||||
// Calculate the closest intersection of the ray with the outer atmosphere (which is the near point of the ray passing through the atmosphere)
|
||||
float B = 2.0 * dot(v3CameraPos, v3Ray);
|
||||
float C = fCameraHeight2 - fOuterRadius2;
|
||||
float fDet = max(0.0, B*B - 4.0 * C);
|
||||
float fNear = 0.5 * (-B - sqrt(fDet));
|
||||
|
||||
// Calculate the ray's starting position, then calculate its scattering offset
|
||||
vec3 v3Start = v3CameraPos + v3Ray * fNear;
|
||||
fFar -= fNear;
|
||||
float fStartAngle = dot(v3Ray, v3Start) / fOuterRadius;
|
||||
float fStartDepth = exp(-1.0 / fScaleDepth);
|
||||
float fStartOffset = fStartDepth * scale(fStartAngle);
|
||||
|
||||
// Initialize the scattering loop variables
|
||||
//gl_FrontColor = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
float fSampleLength = fFar / fSamples;
|
||||
float fScaledLength = fSampleLength * fScale;
|
||||
vec3 v3SampleRay = v3Ray * fSampleLength;
|
||||
vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5;
|
||||
|
||||
// Now loop through the sample rays
|
||||
vec3 v3FrontColor = vec3(0.0, 0.0, 0.0);
|
||||
for(int i=0; i<nSamples; i++)
|
||||
{
|
||||
float fHeight = length(v3SamplePoint);
|
||||
float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight));
|
||||
float fLightAngle = dot(v3LightPos, v3SamplePoint) / fHeight;
|
||||
float fCameraAngle = dot(v3Ray, v3SamplePoint) / fHeight;
|
||||
float fScatter = (fStartOffset + fDepth * (scale(fLightAngle) - scale(fCameraAngle)));
|
||||
vec3 v3Attenuate = exp(-fScatter * (v3InvWavelength * fKr4PI + fKm4PI));
|
||||
v3FrontColor += v3Attenuate * (fDepth * fScaledLength);
|
||||
v3SamplePoint += v3SampleRay;
|
||||
}
|
||||
|
||||
// Finally, scale the Mie and Rayleigh colors and set up the varying variables for the pixel shader
|
||||
gl_FrontSecondaryColor.rgb = v3FrontColor * fKmESun;
|
||||
gl_FrontColor.rgb = v3FrontColor * (v3InvWavelength * fKrESun);
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
v3Direction = v3CameraPos - v3Pos;
|
||||
}
|
||||
#version 120
|
||||
|
||||
//
|
||||
// For licensing information, see http://http.developer.nvidia.com/GPUGems/gpugems_app01.html:
|
||||
//
|
||||
// NVIDIA Statement on the Software
|
||||
//
|
||||
// The source code provided is freely distributable, so long as the NVIDIA header remains unaltered and user modifications are
|
||||
// detailed.
|
||||
//
|
||||
// No Warranty
|
||||
//
|
||||
// THE SOFTWARE AND ANY OTHER MATERIALS PROVIDED BY NVIDIA ON THE ENCLOSED CD-ROM ARE PROVIDED "AS IS." NVIDIA DISCLAIMS ALL
|
||||
// WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
//
|
||||
// Limitation of Liability
|
||||
//
|
||||
// NVIDIA SHALL NOT BE LIABLE TO ANY USER, DEVELOPER, DEVELOPER'S CUSTOMERS, OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH OR
|
||||
// UNDER DEVELOPER FOR ANY LOSS OF PROFITS, INCOME, SAVINGS, OR ANY OTHER CONSEQUENTIAL, INCIDENTAL, SPECIAL, PUNITIVE, DIRECT
|
||||
// OR INDIRECT DAMAGES (WHETHER IN AN ACTION IN CONTRACT, TORT OR BASED ON A WARRANTY), EVEN IF NVIDIA HAS BEEN ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF THE ESSENTIAL PURPOSE OF ANY
|
||||
// LIMITED REMEDY. IN NO EVENT SHALL NVIDIA'S AGGREGATE LIABILITY TO DEVELOPER OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH
|
||||
// OR UNDER DEVELOPER EXCEED THE AMOUNT OF MONEY ACTUALLY PAID BY DEVELOPER TO NVIDIA FOR THE SOFTWARE OR ANY OTHER MATERIALS.
|
||||
//
|
||||
|
||||
//
|
||||
// Atmospheric scattering vertex shader
|
||||
//
|
||||
// Author: Sean O'Neil
|
||||
//
|
||||
// Copyright (c) 2004 Sean O'Neil
|
||||
//
|
||||
|
||||
varying vec3 position;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
position = gl_Vertex.xyz;
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
}
|
||||
|
|
|
@ -254,8 +254,6 @@ void Application::initializeGL() {
|
|||
printLog("Network receive thread created.\n");
|
||||
}
|
||||
|
||||
_myAvatar.readAvatarDataFromFile();
|
||||
|
||||
// call terminate before exiting
|
||||
connect(this, SIGNAL(aboutToQuit()), SLOT(terminate()));
|
||||
|
||||
|
@ -269,6 +267,8 @@ void Application::initializeGL() {
|
|||
connect(idleTimer, SIGNAL(timeout()), SLOT(idle()));
|
||||
idleTimer->start(0);
|
||||
|
||||
readSettings();
|
||||
|
||||
if (_justStarted) {
|
||||
float startupTime = (usecTimestampNow() - usecTimestamp(&_applicationStartupTime))/1000000.0;
|
||||
_justStarted = false;
|
||||
|
@ -288,33 +288,22 @@ void Application::paintGL() {
|
|||
if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
|
||||
_myCamera.setTightness (100.0f);
|
||||
_myCamera.setTargetPosition(_myAvatar.getSpringyHeadPosition());
|
||||
_myCamera.setTargetRotation(_myAvatar.getBodyYaw() - 180.0f,
|
||||
0.0f,
|
||||
0.0f);
|
||||
_myCamera.setTargetRotation(_myAvatar.getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));
|
||||
|
||||
} else if (OculusManager::isConnected()) {
|
||||
_myCamera.setUpShift (0.0f);
|
||||
_myCamera.setDistance (0.0f);
|
||||
_myCamera.setTightness (100.0f);
|
||||
_myCamera.setTargetPosition(_myAvatar.getHeadPosition());
|
||||
_myCamera.setTargetRotation(_myAvatar.getAbsoluteHeadYaw(),
|
||||
_myAvatar.getHead().getPitch(),
|
||||
-_myAvatar.getHead().getRoll());
|
||||
_myCamera.setTargetRotation(_myAvatar.getHead().getOrientation());
|
||||
|
||||
} else if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) {
|
||||
_myCamera.setTargetPosition(_myAvatar.getSpringyHeadPosition());
|
||||
_myCamera.setTargetRotation(_myAvatar.getAbsoluteHeadYaw(),
|
||||
_myAvatar.getAbsoluteHeadPitch(),
|
||||
0.0f);
|
||||
// Take a look at whether we are inside head, don't render it if so.
|
||||
const float HEAD_RENDER_DISTANCE = 0.5;
|
||||
glm::vec3 distanceToHead(_myCamera.getPosition() - _myAvatar.getSpringyHeadPosition());
|
||||
_myCamera.setTargetRotation(_myAvatar.getHead().getWorldAlignedOrientation());
|
||||
|
||||
if (glm::length(distanceToHead) < HEAD_RENDER_DISTANCE) {
|
||||
}
|
||||
} else if (_myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
|
||||
_myCamera.setTargetPosition(_myAvatar.getHeadPosition());
|
||||
_myCamera.setTargetRotation(_myAvatar.getAbsoluteHeadYaw(),
|
||||
_myAvatar.getAbsoluteHeadPitch(),
|
||||
0.0f);
|
||||
_myCamera.setTargetRotation(_myAvatar.getHead().getWorldAlignedOrientation());
|
||||
}
|
||||
|
||||
// important...
|
||||
|
@ -344,11 +333,12 @@ void Application::paintGL() {
|
|||
if (_viewFrustumFromOffset->isChecked() && _frustumOn->isChecked()) {
|
||||
|
||||
// set the camera to third-person view but offset so we can see the frustum
|
||||
_viewFrustumOffsetCamera.setTargetYaw(_viewFrustumOffsetYaw + _myAvatar.getBodyYaw());
|
||||
_viewFrustumOffsetCamera.setPitch (_viewFrustumOffsetPitch );
|
||||
_viewFrustumOffsetCamera.setRoll (_viewFrustumOffsetRoll );
|
||||
_viewFrustumOffsetCamera.setTargetPosition(_myCamera.getTargetPosition());
|
||||
_viewFrustumOffsetCamera.setTargetRotation(_myCamera.getTargetRotation() * glm::quat(glm::radians(glm::vec3(
|
||||
_viewFrustumOffsetPitch, _viewFrustumOffsetYaw, _viewFrustumOffsetRoll))));
|
||||
_viewFrustumOffsetCamera.setUpShift (_viewFrustumOffsetUp );
|
||||
_viewFrustumOffsetCamera.setDistance (_viewFrustumOffsetDistance);
|
||||
_viewFrustumOffsetCamera.initialize(); // force immediate snap to ideal position and orientation
|
||||
_viewFrustumOffsetCamera.update(1.f/_fps);
|
||||
whichCamera = _viewFrustumOffsetCamera;
|
||||
}
|
||||
|
@ -733,7 +723,178 @@ void Application::wheelEvent(QWheelEvent* event) {
|
|||
decreaseVoxelSize();
|
||||
}
|
||||
}
|
||||
|
||||
const char AVATAR_DATA_FILENAME[] = "avatar.ifd";
|
||||
|
||||
void Application::readSettingsFile() {
|
||||
FILE* settingsFile = fopen(AVATAR_DATA_FILENAME, "rt");
|
||||
|
||||
if (settingsFile) {
|
||||
char line[LINE_MAX];
|
||||
|
||||
while (fgets(line, LINE_MAX, settingsFile) != NULL)
|
||||
{
|
||||
if (strcmp(line, " \n") > 0) {
|
||||
char* token = NULL;
|
||||
char* settingLine = NULL;
|
||||
char* toFree = NULL;
|
||||
|
||||
settingLine = strdup(line);
|
||||
|
||||
if (settingLine != NULL) {
|
||||
toFree = settingLine;
|
||||
|
||||
int i = 0;
|
||||
|
||||
char key[128];
|
||||
char value[128];
|
||||
|
||||
|
||||
while ((token = strsep(&settingLine, "=")) != NULL)
|
||||
{
|
||||
switch (i) {
|
||||
case 0:
|
||||
strcpy(key, token);
|
||||
_settingsTable[key] = "";
|
||||
break;
|
||||
|
||||
case 1:
|
||||
strcpy(value, token);
|
||||
_settingsTable[key] = token;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
free(toFree);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose(settingsFile);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::saveSettingsFile() {
|
||||
FILE* settingsFile = fopen(AVATAR_DATA_FILENAME, "wt");
|
||||
|
||||
if (settingsFile) {
|
||||
for (std::map<std::string, std::string>::iterator i = _settingsTable.begin(); i != _settingsTable.end(); i++)
|
||||
{
|
||||
fprintf(settingsFile, "\n%s=%s", i->first.data(), i->second.data());
|
||||
}
|
||||
}
|
||||
|
||||
fclose(settingsFile);
|
||||
}
|
||||
|
||||
bool Application::getSetting(const char* setting, bool& value, const bool defaultSetting) const {
|
||||
std::map<std::string, std::string>::const_iterator iter = _settingsTable.find(setting);
|
||||
|
||||
if (iter != _settingsTable.end()) {
|
||||
int readBool;
|
||||
|
||||
int res = sscanf(iter->second.data(), "%d", &readBool);
|
||||
|
||||
const char EXPECTED_ITEMS = 1;
|
||||
|
||||
if (res == EXPECTED_ITEMS) {
|
||||
if (readBool == 1) {
|
||||
value = true;
|
||||
} else if (readBool == 0) {
|
||||
value = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
value = defaultSetting;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Application::getSetting(const char* setting, float& value, const float defaultSetting) const {
|
||||
std::map<std::string, std::string>::const_iterator iter = _settingsTable.find(setting);
|
||||
|
||||
if (iter != _settingsTable.end()) {
|
||||
float readFloat;
|
||||
|
||||
int res = sscanf(iter->second.data(), "%f", &readFloat);
|
||||
|
||||
const char EXPECTED_ITEMS = 1;
|
||||
|
||||
if (res == EXPECTED_ITEMS) {
|
||||
if (!isnan(readFloat)) {
|
||||
value = readFloat;
|
||||
} else {
|
||||
value = defaultSetting;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
value = defaultSetting;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
value = defaultSetting;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Application::getSetting(const char* setting, glm::vec3& value, const glm::vec3& defaultSetting) const {
|
||||
std::map<std::string, std::string>::const_iterator iter = _settingsTable.find(setting);
|
||||
|
||||
if (iter != _settingsTable.end()) {
|
||||
glm::vec3 readVec;
|
||||
|
||||
int res = sscanf(iter->second.data(), "%f,%f,%f", &readVec.x, &readVec.y, &readVec.z);
|
||||
|
||||
const char EXPECTED_ITEMS = 3;
|
||||
|
||||
if (res == EXPECTED_ITEMS) {
|
||||
if (!isnan(readVec.x) && !isnan(readVec.y) && !isnan(readVec.z)) {
|
||||
value = readVec;
|
||||
} else {
|
||||
value = defaultSetting;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
value = defaultSetting;
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
value = defaultSetting;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const short MAX_SETTINGS_LENGTH = 128;
|
||||
|
||||
void Application::setSetting(const char* setting, const bool value) {
|
||||
char settingValues[MAX_SETTINGS_LENGTH];
|
||||
sprintf(settingValues, "%d", value);
|
||||
_settingsTable[setting] = settingValues;
|
||||
}
|
||||
|
||||
void Application::setSetting(const char* setting, const float value) {
|
||||
char settingValues[MAX_SETTINGS_LENGTH];
|
||||
sprintf(settingValues, "%f", value);
|
||||
_settingsTable[setting] = settingValues;
|
||||
}
|
||||
|
||||
void Application::setSetting(const char* setting, const glm::vec3& value) {
|
||||
char settingValues[MAX_SETTINGS_LENGTH];
|
||||
sprintf(settingValues, "%f,%f,%f", value.x, value.y, value.z);
|
||||
_settingsTable[setting] = settingValues;
|
||||
}
|
||||
|
||||
// Every second, check the frame rates and other stuff
|
||||
void Application::timer() {
|
||||
gettimeofday(&_timerEnd, NULL);
|
||||
|
@ -887,6 +1048,8 @@ void Application::idle() {
|
|||
_serialPort.readData(deltaTime);
|
||||
}
|
||||
|
||||
// Update transmitter
|
||||
|
||||
// Sample hardware, update view frustum if needed, and send avatar data to mixer/agents
|
||||
updateAvatar(deltaTime);
|
||||
|
||||
|
@ -937,7 +1100,7 @@ void Application::idle() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Update audio stats for procedural sounds
|
||||
#ifndef _WIN32
|
||||
_audio.setLastAcceleration(_myAvatar.getThrust());
|
||||
|
@ -953,7 +1116,7 @@ void Application::terminate() {
|
|||
// Close serial port
|
||||
// close(serial_fd);
|
||||
|
||||
_myAvatar.writeAvatarDataToFile();
|
||||
saveSettings();
|
||||
|
||||
if (_enableNetworkThread) {
|
||||
_stopNetworkReceiveThread = true;
|
||||
|
@ -1122,7 +1285,7 @@ void Application::initMenu() {
|
|||
_window->setMenuBar(menuBar);
|
||||
|
||||
QMenu* fileMenu = menuBar->addMenu("File");
|
||||
fileMenu->addAction("Quit", this, SLOT(quit()), (Qt::Key_Q || Qt::Key_Control));
|
||||
fileMenu->addAction("Quit", this, SLOT(quit()), Qt::CTRL | Qt::Key_Q);
|
||||
|
||||
QMenu* pairMenu = menuBar->addMenu("Pair");
|
||||
pairMenu->addAction("Pair", this, SLOT(pair()));
|
||||
|
@ -1284,7 +1447,7 @@ void Application::init() {
|
|||
|
||||
void Application::updateAvatar(float deltaTime) {
|
||||
// Update my avatar's head position from gyros
|
||||
_myAvatar.updateHeadFromGyros(deltaTime, &_serialPort, &_gravity);
|
||||
_myAvatar.updateHeadFromGyros(deltaTime, &_serialPort);
|
||||
|
||||
// Grab latest readings from the gyros
|
||||
float measuredPitchRate = _serialPort.getLastPitchRate();
|
||||
|
@ -1379,10 +1542,6 @@ void Application::updateAvatar(float deltaTime) {
|
|||
void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) {
|
||||
// We will use these below, from either the camera or head vectors calculated above
|
||||
glm::vec3 position;
|
||||
glm::vec3 direction;
|
||||
glm::vec3 up;
|
||||
glm::vec3 right;
|
||||
float fov, nearClip, farClip;
|
||||
|
||||
// Camera or Head?
|
||||
if (_cameraFrustum->isChecked()) {
|
||||
|
@ -1391,15 +1550,14 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) {
|
|||
position = _myAvatar.getHeadPosition();
|
||||
}
|
||||
|
||||
fov = camera.getFieldOfView();
|
||||
nearClip = camera.getNearClip();
|
||||
farClip = camera.getFarClip();
|
||||
float fov = camera.getFieldOfView();
|
||||
float nearClip = camera.getNearClip();
|
||||
float farClip = camera.getFarClip();
|
||||
|
||||
Orientation o = camera.getOrientation();
|
||||
|
||||
direction = o.getFront();
|
||||
up = o.getUp();
|
||||
right = o.getRight();
|
||||
glm::quat rotation = camera.getRotation();
|
||||
glm::vec3 direction = rotation * AVATAR_FRONT;
|
||||
glm::vec3 up = rotation * AVATAR_UP;
|
||||
glm::vec3 right = rotation * AVATAR_RIGHT;
|
||||
|
||||
/*
|
||||
printf("position.x=%f, position.y=%f, position.z=%f\n", position.x, position.y, position.z);
|
||||
|
@ -1585,11 +1743,10 @@ void Application::displaySide(Camera& whichCamera) {
|
|||
// transform view according to whichCamera
|
||||
// could be myCamera (if in normal mode)
|
||||
// or could be viewFrustumOffsetCamera if in offset mode
|
||||
// I changed the ordering here - roll is FIRST (JJV)
|
||||
|
||||
glRotatef ( whichCamera.getRoll(), IDENTITY_FRONT.x, IDENTITY_FRONT.y, IDENTITY_FRONT.z);
|
||||
glRotatef ( whichCamera.getPitch(), IDENTITY_RIGHT.x, IDENTITY_RIGHT.y, IDENTITY_RIGHT.z);
|
||||
glRotatef (180.0 - whichCamera.getYaw(), IDENTITY_UP.x, IDENTITY_UP.y, IDENTITY_UP.z );
|
||||
glm::quat rotation = whichCamera.getRotation();
|
||||
glm::vec3 axis = glm::axis(rotation);
|
||||
glRotatef(-glm::angle(rotation), axis.x, axis.y, axis.z);
|
||||
|
||||
glTranslatef(-whichCamera.getPosition().x, -whichCamera.getPosition().y, -whichCamera.getPosition().z);
|
||||
|
||||
|
@ -1683,13 +1840,13 @@ void Application::displaySide(Camera& whichCamera) {
|
|||
for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
|
||||
if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) {
|
||||
Avatar *avatar = (Avatar *)agent->getLinkedData();
|
||||
avatar->render(false, _myCamera.getPosition());
|
||||
avatar->render(false);
|
||||
}
|
||||
}
|
||||
agentList->unlock();
|
||||
|
||||
// Render my own Avatar
|
||||
_myAvatar.render(_lookingInMirror->isChecked(), _myCamera.getPosition());
|
||||
_myAvatar.render(_lookingInMirror->isChecked());
|
||||
_myAvatar.setDisplayingLookatVectors(_renderLookatOn->isChecked());
|
||||
}
|
||||
|
||||
|
@ -2200,3 +2357,95 @@ void* Application::networkReceive(void* args) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void Application::saveSettings()
|
||||
{
|
||||
// Handle any persistent settings saving here when we get a call to terminate.
|
||||
// This should probably be moved to a map stored in memory at some point to cache settings.
|
||||
_myAvatar.writeAvatarDataToFile();
|
||||
|
||||
setSetting("_gyroLook", _gyroLook->isChecked());
|
||||
|
||||
setSetting("_mouseLook", _mouseLook->isChecked());
|
||||
|
||||
setSetting("_transmitterDrives", _transmitterDrives->isChecked());
|
||||
|
||||
setSetting("_renderVoxels", _renderVoxels->isChecked());
|
||||
|
||||
setSetting("_renderVoxelTextures", _renderVoxelTextures->isChecked());
|
||||
|
||||
setSetting("_renderStarsOn", _renderStarsOn->isChecked());
|
||||
|
||||
setSetting("_renderAtmosphereOn", _renderAtmosphereOn->isChecked());
|
||||
|
||||
setSetting("_renderAvatarsOn", _renderAvatarsOn->isChecked());
|
||||
|
||||
setSetting("_renderStatsOn", _renderStatsOn->isChecked());
|
||||
|
||||
setSetting("_renderFrameTimerOn", _renderFrameTimerOn->isChecked());
|
||||
|
||||
setSetting("_renderLookatOn", _renderLookatOn->isChecked());
|
||||
|
||||
setSetting("_logOn", _logOn->isChecked());
|
||||
|
||||
setSetting("_frustumOn", _frustumOn->isChecked());
|
||||
|
||||
setSetting("_viewFrustumFromOffset", _viewFrustumFromOffset->isChecked());
|
||||
|
||||
setSetting("_cameraFrustum", _cameraFrustum->isChecked());
|
||||
|
||||
saveSettingsFile();
|
||||
}
|
||||
|
||||
void Application::readSettings()
|
||||
{
|
||||
readSettingsFile();
|
||||
_myAvatar.readAvatarDataFromFile();
|
||||
|
||||
bool settingState;
|
||||
getSetting("_gyroLook", settingState, _gyroLook->isChecked());
|
||||
_gyroLook->setChecked(settingState);
|
||||
|
||||
getSetting("_mouseLook", settingState, _mouseLook->isChecked());
|
||||
_mouseLook->setChecked(settingState);
|
||||
|
||||
getSetting("_transmitterDrives", settingState, _transmitterDrives->isChecked());
|
||||
_transmitterDrives->setChecked(settingState);
|
||||
|
||||
getSetting("_renderVoxels", settingState, _renderVoxels->isChecked());
|
||||
_renderVoxels->setChecked(settingState);
|
||||
|
||||
getSetting("_renderVoxelTextures", settingState, _renderVoxelTextures->isChecked());
|
||||
_renderVoxelTextures->setChecked(settingState);
|
||||
|
||||
getSetting("_renderStarsOn", settingState, _renderStarsOn->isChecked());
|
||||
_renderStarsOn->setChecked(settingState);
|
||||
|
||||
getSetting("_renderAtmosphereOn", settingState, _renderAtmosphereOn->isChecked());
|
||||
_renderAtmosphereOn->setChecked(settingState);
|
||||
|
||||
getSetting("_renderAvatarsOn", settingState, _renderAvatarsOn->isChecked());
|
||||
_renderAvatarsOn->setChecked(settingState);
|
||||
|
||||
getSetting("_renderStatsOn", settingState, _renderStatsOn->isChecked());
|
||||
_renderStatsOn->setChecked(settingState);
|
||||
|
||||
getSetting("_renderFrameTimerOn", settingState, _renderFrameTimerOn->isChecked());
|
||||
_renderFrameTimerOn->setChecked(settingState);
|
||||
|
||||
getSetting("_renderLookatOn", settingState, _renderLookatOn->isChecked());
|
||||
_renderLookatOn->setChecked(settingState);
|
||||
|
||||
getSetting("_logOn", settingState, _logOn->isChecked());
|
||||
_logOn->setChecked(settingState);
|
||||
|
||||
getSetting("_frustumOn", settingState, _frustumOn->isChecked());
|
||||
_frustumOn->setChecked(settingState);
|
||||
|
||||
getSetting("_viewFrustumFromOffset", settingState, _viewFrustumFromOffset->isChecked());
|
||||
_viewFrustumFromOffset->setChecked(settingState);
|
||||
|
||||
getSetting("_cameraFrustum", settingState, _cameraFrustum->isChecked());
|
||||
_cameraFrustum->setChecked(settingState);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
#include <map>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QAction>
|
||||
|
@ -63,9 +64,61 @@ public:
|
|||
void wheelEvent(QWheelEvent* event);
|
||||
|
||||
Avatar* getAvatar() { return &_myAvatar; }
|
||||
Camera* getCamera() { return &_myCamera; }
|
||||
VoxelSystem* getVoxels() { return &_voxels; }
|
||||
Environment* getEnvironment() { return &_environment; }
|
||||
bool shouldEchoAudio() { return _echoAudioMode->isChecked(); }
|
||||
|
||||
/*!
|
||||
@fn getSettingBool
|
||||
@brief A function for getting boolean settings from the settings file.
|
||||
@param settingName The desired setting to get the value for.
|
||||
@param boolSetting The referenced variable where the setting will be stored.
|
||||
@param defaultSetting The default setting to assign to boolSetting if this function fails to find the appropriate setting. Defaults to false.
|
||||
*/
|
||||
bool getSetting(const char* setting, bool &value, const bool defaultSetting = false) const;
|
||||
|
||||
/*!
|
||||
@fn getSettingFloat
|
||||
@brief A function for getting float settings from the settings file.
|
||||
@param settingName The desired setting to get the value for.
|
||||
@param floatSetting The referenced variable where the setting will be stored.
|
||||
@param defaultSetting The default setting to assign to boolSetting if this function fails to find the appropriate setting. Defaults to 0.0f.
|
||||
*/
|
||||
bool getSetting(const char* setting, float &value, const float defaultSetting = 0.0f) const;
|
||||
|
||||
/*!
|
||||
@fn getSettingVec3
|
||||
@brief A function for getting boolean settings from the settings file.
|
||||
@param settingName The desired setting to get the value for.
|
||||
@param vecSetting The referenced variable where the setting will be stored.
|
||||
@param defaultSetting The default setting to assign to boolSetting if this function fails to find the appropriate setting. Defaults to <0.0f, 0.0f, 0.0f>
|
||||
*/
|
||||
bool getSetting(const char* setting, glm::vec3 &value, const glm::vec3& defaultSetting = glm::vec3(0.0f, 0.0f, 0.0f)) const;
|
||||
|
||||
/*!
|
||||
@fn setSettingBool
|
||||
@brief A function for setting boolean setting values when saving the settings file.
|
||||
@param settingName The desired setting to populate a value for.
|
||||
@param boolSetting The value to set.
|
||||
*/
|
||||
void setSetting(const char* setting, const bool value);
|
||||
|
||||
/*!
|
||||
@fn setSettingFloat
|
||||
@brief A function for setting boolean setting values when saving the settings file.
|
||||
@param settingName The desired setting to populate a value for.
|
||||
@param floatSetting The value to set.
|
||||
*/
|
||||
void setSetting(const char* setting, const float value);
|
||||
|
||||
/*!
|
||||
@fn setSettingVec3
|
||||
@brief A function for setting boolean setting values when saving the settings file.
|
||||
@param settingName The desired setting to populate a value for.
|
||||
@param vecSetting The value to set.
|
||||
*/
|
||||
void setSetting(const char* setting, const glm::vec3& value);
|
||||
|
||||
private slots:
|
||||
|
||||
|
@ -136,6 +189,13 @@ private:
|
|||
static void attachNewHeadToAgent(Agent *newAgent);
|
||||
static void* networkReceive(void* args);
|
||||
|
||||
// These two functions are technically not necessary, but they help keep things in one place.
|
||||
void readSettings(); //! This function is largely to help consolidate getting settings in one place.
|
||||
void saveSettings(); //! This function is to consolidate any settings setting in one place.
|
||||
|
||||
void readSettingsFile(); //! This function reads data from the settings file, splitting data into key value pairs using '=' as a delimiter.
|
||||
void saveSettingsFile(); //! This function writes all changes in the settings table to the settings file, serializing all settings added through the setSetting functions.
|
||||
|
||||
QMainWindow* _window;
|
||||
QGLWidget* _glWidget;
|
||||
|
||||
|
@ -254,6 +314,12 @@ private:
|
|||
int _packetsPerSecond;
|
||||
int _bytesPerSecond;
|
||||
int _bytesCount;
|
||||
|
||||
/*!
|
||||
* Store settings in a map, storing keys and values as strings.
|
||||
* Interpret values as needed on demand. through the appropriate getters and setters.
|
||||
*/
|
||||
std::map<std::string, std::string> _settingsTable;
|
||||
};
|
||||
|
||||
#endif /* defined(__interface__Application__) */
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -11,7 +11,6 @@
|
|||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <AvatarData.h>
|
||||
#include <Orientation.h>
|
||||
#include "world.h"
|
||||
#include "AvatarTouch.h"
|
||||
#include "InterfaceConfig.h"
|
||||
|
@ -31,15 +30,15 @@ enum DriveKeys
|
|||
DOWN,
|
||||
ROT_LEFT,
|
||||
ROT_RIGHT,
|
||||
MAX_DRIVE_KEYS
|
||||
MAX_DRIVE_KEYS
|
||||
};
|
||||
|
||||
enum AvatarMode
|
||||
{
|
||||
AVATAR_MODE_STANDING = 0,
|
||||
AVATAR_MODE_WALKING,
|
||||
AVATAR_MODE_INTERACTING,
|
||||
NUM_AVATAR_MODES
|
||||
AVATAR_MODE_STANDING = 0,
|
||||
AVATAR_MODE_WALKING,
|
||||
AVATAR_MODE_INTERACTING,
|
||||
NUM_AVATAR_MODES
|
||||
};
|
||||
|
||||
class Avatar : public AvatarData {
|
||||
|
@ -49,10 +48,10 @@ public:
|
|||
|
||||
void reset();
|
||||
void simulate(float deltaTime, Transmitter* transmitter);
|
||||
void updateHeadFromGyros(float frametime, SerialInterface * serialInterface, glm::vec3 * gravity);
|
||||
void updateHeadFromGyros(float frametime, SerialInterface * serialInterface);
|
||||
void updateFromMouse(int mouseX, int mouseY, int screenWidth, int screenHeight);
|
||||
void addBodyYaw(float y) {_bodyYaw += y;};
|
||||
void render(bool lookingInMirror, glm::vec3 cameraPosition);
|
||||
void render(bool lookingInMirror);
|
||||
|
||||
//setters
|
||||
void setMousePressed (bool mousePressed ) { _mousePressed = mousePressed;}
|
||||
|
@ -62,22 +61,31 @@ public:
|
|||
void setDisplayingLookatVectors(bool displayingLookatVectors) { _head.setRenderLookatVectors(displayingLookatVectors);}
|
||||
void setGravity (glm::vec3 gravity);
|
||||
void setMouseRay (const glm::vec3 &origin, const glm::vec3 &direction);
|
||||
void setOrientation (const glm::quat& orientation);
|
||||
|
||||
//getters
|
||||
|
||||
float getHeadYawRate () const { return _head.yawRate;}
|
||||
float getBodyYaw () const { return _bodyYaw;}
|
||||
float getBodyYaw () const { return _bodyYaw;}
|
||||
bool getIsNearInteractingOther() const { return _avatarTouch.getAbleToReachOtherAvatar();}
|
||||
const glm::vec3& getHeadPosition () const { return _joint[ AVATAR_JOINT_HEAD_BASE ].position;}
|
||||
const glm::vec3& getSpringyHeadPosition () const { return _joint[ AVATAR_JOINT_HEAD_BASE ].springyPosition;}
|
||||
const glm::vec3& getJointPosition (AvatarJointID j) const { return _joint[j].springyPosition;}
|
||||
const glm::vec3& getBodyUpDirection () const { return _orientation.getUp();}
|
||||
const glm::vec3& getVelocity () const { return _velocity;}
|
||||
float getSpeed () const { return _speed;}
|
||||
float getHeight () const { return _height;}
|
||||
AvatarMode getMode () const { return _mode;}
|
||||
float getAbsoluteHeadYaw () const;
|
||||
float getAbsoluteHeadPitch () const;
|
||||
Head& getHead () {return _head; }
|
||||
const glm::vec3& getHeadPosition () const { return _skeleton.joint[ AVATAR_JOINT_HEAD_BASE ].position;}
|
||||
const glm::vec3& getSpringyHeadPosition () const { return _bodyBall[ AVATAR_JOINT_HEAD_BASE ].position;}
|
||||
const glm::vec3& getJointPosition (AvatarJointID j) const { return _bodyBall[j].position;}
|
||||
|
||||
glm::vec3 getBodyRightDirection () const { return getOrientation() * AVATAR_RIGHT; }
|
||||
glm::vec3 getBodyUpDirection () const { return getOrientation() * AVATAR_UP; }
|
||||
glm::vec3 getBodyFrontDirection () const { return getOrientation() * AVATAR_FRONT; }
|
||||
|
||||
|
||||
const glm::vec3& getVelocity () const { return _velocity;}
|
||||
float getSpeed () const { return _speed;}
|
||||
float getHeight () const { return _height;}
|
||||
AvatarMode getMode () const { return _mode;}
|
||||
float getAbsoluteHeadYaw () const;
|
||||
float getAbsoluteHeadPitch () const;
|
||||
Head& getHead () {return _head; }
|
||||
glm::quat getOrientation () const;
|
||||
glm::quat getWorldAlignedOrientation() const;
|
||||
|
||||
// Set what driving keys are being pressed to control thrust levels
|
||||
void setDriveKeys(int key, bool val) { _driveKeys[key] = val; };
|
||||
|
@ -96,23 +104,14 @@ private:
|
|||
Avatar(const Avatar&);
|
||||
Avatar& operator= (const Avatar&);
|
||||
|
||||
struct AvatarJoint
|
||||
struct AvatarBall
|
||||
{
|
||||
AvatarJointID parent; // which joint is this joint connected to?
|
||||
glm::vec3 position; // the position at the "end" of the joint - in global space
|
||||
glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the "T-pose"
|
||||
glm::vec3 springyPosition; // used for special effects (a 'flexible' variant of position)
|
||||
glm::vec3 springyVelocity; // used for special effects ( the velocity of the springy position)
|
||||
float springBodyTightness; // how tightly the springy position tries to stay on the position
|
||||
glm::quat rotation; // this will eventually replace yaw, pitch and roll (and maybe orientation)
|
||||
float yaw; // the yaw Euler angle of the joint rotation off the parent
|
||||
float pitch; // the pitch Euler angle of the joint rotation off the parent
|
||||
float roll; // the roll Euler angle of the joint rotation off the parent
|
||||
Orientation orientation; // three orthogonal normals determined by yaw, pitch, roll
|
||||
float length; // the length of vector connecting the joint and its parent
|
||||
float radius; // used for detecting collisions for certain physical effects
|
||||
bool isCollidable; // when false, the joint position will not register a collision
|
||||
float touchForce; // if being touched, what's the degree of influence? (0 to 1)
|
||||
glm::vec3 position;
|
||||
glm::vec3 velocity;
|
||||
float jointTightness;
|
||||
float radius;
|
||||
bool isCollidable;
|
||||
float touchForce;
|
||||
};
|
||||
|
||||
Head _head;
|
||||
|
@ -125,15 +124,14 @@ private:
|
|||
float _bodyRollDelta;
|
||||
glm::vec3 _movedHandOffset;
|
||||
glm::quat _rotation; // the rotation of the avatar body as a whole expressed as a quaternion
|
||||
AvatarJoint _joint[ NUM_AVATAR_JOINTS ];
|
||||
AvatarBall _bodyBall[ NUM_AVATAR_JOINTS ];
|
||||
AvatarMode _mode;
|
||||
glm::vec3 _cameraPosition;
|
||||
glm::vec3 _handHoldingPosition;
|
||||
glm::vec3 _velocity;
|
||||
glm::vec3 _thrust;
|
||||
glm::vec3 _thrust;
|
||||
float _speed;
|
||||
float _maxArmLength;
|
||||
Orientation _orientation;
|
||||
float _maxArmLength;
|
||||
glm::quat _righting;
|
||||
int _driveKeys[MAX_DRIVE_KEYS];
|
||||
float _pelvisStandingHeight;
|
||||
|
@ -143,6 +141,7 @@ private:
|
|||
AvatarTouch _avatarTouch;
|
||||
float _distanceToNearestAvatar; // How close is the nearest avatar?
|
||||
glm::vec3 _gravity;
|
||||
glm::vec3 _worldUpDirection;
|
||||
glm::vec3 _mouseRayOrigin;
|
||||
glm::vec3 _mouseRayDirection;
|
||||
Avatar* _interactingOther;
|
||||
|
@ -151,11 +150,11 @@ private:
|
|||
|
||||
// private methods...
|
||||
glm::vec3 caclulateAverageEyePosition() { return _head.caclulateAverageEyePosition(); } // get the position smack-dab between the eyes (for lookat)
|
||||
glm::quat computeRotationFromBodyToWorldUp(float proportion = 1.0f) const;
|
||||
void renderBody(bool lookingInMirror);
|
||||
void initializeSkeleton();
|
||||
void updateSkeleton();
|
||||
void initializeBodySprings();
|
||||
void updateBodySprings( float deltaTime );
|
||||
void initializeBodyBalls();
|
||||
void resetBodyBalls();
|
||||
void updateBodyBalls( float deltaTime );
|
||||
void calculateBoneLengths();
|
||||
void readSensors();
|
||||
void updateHandMovementAndTouching(float deltaTime);
|
||||
|
|
|
@ -29,8 +29,6 @@ AvatarTouch::AvatarTouch() {
|
|||
_canReachToOtherAvatar = false;
|
||||
_handsCloseEnoughToGrasp = false;
|
||||
_hasInteractingOther = false;
|
||||
_myOrientation.setToIdentity();
|
||||
_yourOrientation.setToIdentity();
|
||||
|
||||
for (int p=0; p<NUM_PARTICLE_POINTS; p++) {
|
||||
_point[p] = glm::vec3(0.0, 0.0, 0.0);
|
||||
|
@ -45,16 +43,25 @@ void AvatarTouch::simulate (float deltaTime) {
|
|||
|
||||
glm::vec3 vectorBetweenBodies = _yourBodyPosition - _myBodyPosition;
|
||||
float distanceBetweenBodies = glm::length(vectorBetweenBodies);
|
||||
|
||||
//KEEP THIS - it is another variation that we are considering getting rid of
|
||||
//the following code take into account of the two avatars are facing each other
|
||||
/*
|
||||
glm::vec3 directionBetweenBodies = vectorBetweenBodies / distanceBetweenBodies;
|
||||
|
||||
bool facingEachOther = false;
|
||||
|
||||
if (( glm::dot(_myOrientation.getFront(), _yourOrientation.getFront()) < -AVATAR_FACING_THRESHOLD) // we're facing each other
|
||||
&& ( glm::dot(_myOrientation.getFront(), directionBetweenBodies ) > AVATAR_FACING_THRESHOLD)) { // I'm facing you
|
||||
glm::vec3 myFront = _myOrientation * AVATAR_FRONT;
|
||||
glm::vec3 yourFront = _yourOrientation * AVATAR_FRONT;
|
||||
|
||||
if (( glm::dot(myFront, yourFront ) < -AVATAR_FACING_THRESHOLD) // we're facing each other
|
||||
&& ( glm::dot(myFront, directionBetweenBodies ) > AVATAR_FACING_THRESHOLD)) { // I'm facing you
|
||||
facingEachOther = true;
|
||||
}
|
||||
|
||||
if (distanceBetweenBodies < _reachableRadius) {
|
||||
*/
|
||||
|
||||
if (distanceBetweenBodies < _reachableRadius)
|
||||
{
|
||||
_canReachToOtherAvatar = true;
|
||||
|
||||
_vectorBetweenHands = _yourHandPosition - _myHandPosition;
|
||||
|
|
|
@ -9,7 +9,9 @@
|
|||
#define __interface__AvatarTouch__
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include "Orientation.h"
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
#include <AvatarData.h>
|
||||
|
||||
enum AvatarHandState
|
||||
{
|
||||
|
@ -31,8 +33,8 @@ public:
|
|||
void setHasInteractingOther(bool hasInteractingOther) { _hasInteractingOther = hasInteractingOther;}
|
||||
void setMyHandPosition (glm::vec3 position ) { _myHandPosition = position;}
|
||||
void setYourHandPosition (glm::vec3 position ) { _yourHandPosition = position;}
|
||||
void setMyOrientation (Orientation orientation ) { _myOrientation = orientation;}
|
||||
void setYourOrientation (Orientation orientation ) { _yourOrientation = orientation;}
|
||||
void setMyOrientation (glm::quat orientation ) { _myOrientation = orientation;}
|
||||
void setYourOrientation (glm::quat orientation ) { _yourOrientation = orientation;}
|
||||
void setMyBodyPosition (glm::vec3 position ) { _myBodyPosition = position;}
|
||||
void setYourBodyPosition (glm::vec3 position ) { _yourBodyPosition = position;}
|
||||
void setMyHandState (int state ) { _myHandState = state;}
|
||||
|
@ -55,8 +57,8 @@ private:
|
|||
glm::vec3 _yourBodyPosition;
|
||||
glm::vec3 _myHandPosition;
|
||||
glm::vec3 _yourHandPosition;
|
||||
Orientation _myOrientation;
|
||||
Orientation _yourOrientation;
|
||||
glm::quat _myOrientation;
|
||||
glm::quat _yourOrientation;
|
||||
glm::vec3 _vectorBetweenHands;
|
||||
int _myHandState;
|
||||
int _yourHandState;
|
||||
|
|
|
@ -4,12 +4,14 @@
|
|||
//
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
#include <SharedUtil.h>
|
||||
#include <VoxelConstants.h>
|
||||
#include <OculusManager.h>
|
||||
// #include "Log.h"
|
||||
#include "Log.h"
|
||||
|
||||
#include "Camera.h"
|
||||
#include "Util.h"
|
||||
|
||||
const float CAMERA_MINIMUM_MODE_SHIFT_RATE = 0.5f;
|
||||
|
||||
|
@ -30,7 +32,7 @@ Camera::Camera() {
|
|||
_needsToInitialize = true;
|
||||
_frustumNeedsReshape = true;
|
||||
|
||||
_modeShift = 0.0f;
|
||||
_modeShift = 1.0f;
|
||||
_modeShiftRate = 1.0f;
|
||||
_linearModeShift = 0.0f;
|
||||
_mode = CAMERA_MODE_THIRD_PERSON;
|
||||
|
@ -38,9 +40,6 @@ Camera::Camera() {
|
|||
_fieldOfView = 60.0f; // default
|
||||
_nearClip = 0.08f; // default
|
||||
_farClip = 50.0f * TREE_SCALE; // default
|
||||
_yaw = 0.0f;
|
||||
_pitch = 0.0f;
|
||||
_roll = 0.0f;
|
||||
_upShift = 0.0f;
|
||||
_distance = 0.0f;
|
||||
_previousUpShift = 0.0f;
|
||||
|
@ -49,13 +48,9 @@ Camera::Camera() {
|
|||
_newUpShift = 0.0f;
|
||||
_newDistance = 0.0f;
|
||||
_newTightness = 0.0f;
|
||||
_idealYaw = 0.0f;
|
||||
_idealPitch = 0.0f;
|
||||
_idealRoll = 0.0f;
|
||||
_targetPosition = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
_position = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
_idealPosition = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
_orientation.setToIdentity();
|
||||
}
|
||||
|
||||
void Camera::update(float deltaTime) {
|
||||
|
@ -64,17 +59,6 @@ void Camera::update(float deltaTime) {
|
|||
// use iterative forces to push the camera towards the target position and angle
|
||||
updateFollowMode(deltaTime);
|
||||
}
|
||||
|
||||
// do this AFTER making any changes to yaw pitch and roll....
|
||||
generateOrientation();
|
||||
}
|
||||
|
||||
// generate the ortho-normals for the orientation based on the three Euler angles
|
||||
void Camera::generateOrientation() {
|
||||
_orientation.setToIdentity();
|
||||
_orientation.pitch(_pitch);
|
||||
_orientation.yaw (_yaw );
|
||||
_orientation.roll (_roll );
|
||||
}
|
||||
|
||||
// use iterative forces to keep the camera at the desired position and angle
|
||||
|
@ -104,26 +88,15 @@ void Camera::updateFollowMode(float deltaTime) {
|
|||
t = 1.0;
|
||||
}
|
||||
|
||||
// update Euler angles (before position!)
|
||||
// update rotation (before position!)
|
||||
if (_needsToInitialize || OculusManager::isConnected()) {
|
||||
_yaw = _idealYaw;
|
||||
_pitch = _idealPitch;
|
||||
_roll = _idealRoll;
|
||||
_rotation = _targetRotation;
|
||||
} else {
|
||||
// pull Euler angles towards ideal Euler angles
|
||||
_yaw += (_idealYaw - _yaw ) * t;
|
||||
_pitch += (_idealPitch - _pitch) * t;
|
||||
_roll += (_idealRoll - _roll ) * t;
|
||||
// pull rotation towards ideal
|
||||
_rotation = safeMix(_rotation, _targetRotation, t);
|
||||
}
|
||||
|
||||
float radian = (_yaw / 180.0) * PIE;
|
||||
|
||||
// update _position
|
||||
double x = -_distance * sin(radian);
|
||||
double z = -_distance * cos(radian);
|
||||
double y = _upShift;
|
||||
|
||||
_idealPosition = _targetPosition + glm::vec3(x, y, z);
|
||||
_idealPosition = _targetPosition + _rotation * glm::vec3(0.0f, _upShift, _distance);
|
||||
|
||||
if (_needsToInitialize) {
|
||||
_position = _idealPosition;
|
||||
|
@ -171,10 +144,8 @@ void Camera::setMode(CameraMode m) {
|
|||
}
|
||||
|
||||
|
||||
void Camera::setTargetRotation( float yaw, float pitch, float roll ) {
|
||||
_idealYaw = yaw;
|
||||
_idealPitch = pitch;
|
||||
_idealRoll = roll;
|
||||
void Camera::setTargetRotation( const glm::quat& targetRotation ) {
|
||||
_targetRotation = targetRotation;
|
||||
}
|
||||
|
||||
void Camera::setFieldOfView(float f) {
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#ifndef __interface__camera__
|
||||
#define __interface__camera__
|
||||
|
||||
#include "Orientation.h"
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
|
@ -30,40 +29,36 @@ public:
|
|||
|
||||
void update( float deltaTime );
|
||||
|
||||
void setYaw ( float y ) { _yaw = y; }
|
||||
void setPitch ( float p ) { _pitch = p; }
|
||||
void setRoll ( float r ) { _roll = r; }
|
||||
void setUpShift ( float u ) { _upShift = u; }
|
||||
void setDistance ( float d ) { _distance = d; }
|
||||
void setTargetPosition( glm::vec3 t ) { _targetPosition = t; }
|
||||
void setTargetYaw ( float y ) { _idealYaw = y; }
|
||||
void setPosition ( glm::vec3 p ) { _position = p; }
|
||||
void setTightness ( float t ) { _tightness = t; }
|
||||
void setTargetRotation( float yaw, float pitch, float roll );
|
||||
void setUpShift ( float u ) { _upShift = u; }
|
||||
void setDistance ( float d ) { _distance = d; }
|
||||
void setTargetPosition( const glm::vec3& t ) { _targetPosition = t; }
|
||||
void setPosition ( const glm::vec3& p ) { _position = p; }
|
||||
void setTightness ( float t ) { _tightness = t; }
|
||||
void setTargetRotation( const glm::quat& rotation );
|
||||
|
||||
void setMode ( CameraMode m );
|
||||
void setModeShiftRate ( float r );
|
||||
void setFieldOfView ( float f );
|
||||
void setAspectRatio ( float a );
|
||||
void setNearClip ( float n );
|
||||
void setFarClip ( float f );
|
||||
void setEyeOffsetPosition ( const glm::vec3& p);
|
||||
void setEyeOffsetOrientation ( const glm::quat& o);
|
||||
|
||||
float getYaw () { return _yaw; }
|
||||
float getPitch () { return _pitch; }
|
||||
float getRoll () { return _roll; }
|
||||
glm::vec3 getPosition () { return _position; }
|
||||
Orientation getOrientation() { return _orientation; }
|
||||
CameraMode getMode () { return _mode; }
|
||||
float getFieldOfView() { return _fieldOfView; }
|
||||
float getAspectRatio() { return _aspectRatio; }
|
||||
float getNearClip () { return _nearClip; }
|
||||
float getFarClip () { return _farClip; }
|
||||
glm::vec3 getEyeOffsetPosition () { return _eyeOffsetPosition; }
|
||||
glm::quat getEyeOffsetOrientation () { return _eyeOffsetOrientation; }
|
||||
bool getFrustumNeedsReshape(); // call to find out if the view frustum needs to be reshaped
|
||||
void setFrustumWasReshaped(); // call this after reshaping the view frustum.
|
||||
void setMode ( CameraMode m );
|
||||
void setModeShiftRate ( float r );
|
||||
void setFieldOfView ( float f );
|
||||
void setAspectRatio ( float a );
|
||||
void setNearClip ( float n );
|
||||
void setFarClip ( float f );
|
||||
void setEyeOffsetPosition ( const glm::vec3& p );
|
||||
void setEyeOffsetOrientation( const glm::quat& o );
|
||||
|
||||
const glm::vec3& getTargetPosition () { return _targetPosition; }
|
||||
const glm::vec3& getPosition () { return _position; }
|
||||
const glm::quat& getTargetRotation () { return _targetRotation; }
|
||||
const glm::quat& getRotation () { return _rotation; }
|
||||
CameraMode getMode () { return _mode; }
|
||||
float getFieldOfView () { return _fieldOfView; }
|
||||
float getAspectRatio () { return _aspectRatio; }
|
||||
float getNearClip () { return _nearClip; }
|
||||
float getFarClip () { return _farClip; }
|
||||
const glm::vec3& getEyeOffsetPosition () { return _eyeOffsetPosition; }
|
||||
const glm::quat& getEyeOffsetOrientation () { return _eyeOffsetOrientation; }
|
||||
|
||||
bool getFrustumNeedsReshape(); // call to find out if the view frustum needs to be reshaped
|
||||
void setFrustumWasReshaped(); // call this after reshaping the view frustum.
|
||||
|
||||
private:
|
||||
|
||||
|
@ -79,12 +74,8 @@ private:
|
|||
float _farClip;
|
||||
glm::vec3 _eyeOffsetPosition;
|
||||
glm::quat _eyeOffsetOrientation;
|
||||
float _yaw;
|
||||
float _pitch;
|
||||
float _roll;
|
||||
float _idealYaw;
|
||||
float _idealPitch;
|
||||
float _idealRoll;
|
||||
glm::quat _rotation;
|
||||
glm::quat _targetRotation;
|
||||
float _upShift;
|
||||
float _distance;
|
||||
float _tightness;
|
||||
|
@ -94,12 +85,10 @@ private:
|
|||
float _newUpShift;
|
||||
float _newDistance;
|
||||
float _newTightness;
|
||||
Orientation _orientation;
|
||||
float _modeShift;
|
||||
float _linearModeShift;
|
||||
float _modeShiftRate;
|
||||
|
||||
void generateOrientation();
|
||||
void updateFollowMode( float deltaTime );
|
||||
};
|
||||
|
||||
|
|
|
@ -58,11 +58,17 @@ void Environment::renderAtmospheres(Camera& camera) {
|
|||
}
|
||||
|
||||
glm::vec3 Environment::getGravity (const glm::vec3& position) {
|
||||
// the "original gravity"
|
||||
glm::vec3 gravity;
|
||||
if (position.x > 0.0f && position.x < EDGE_SIZE_GROUND_PLANE && position.y > 0.0f &&
|
||||
position.y < 3.0f && position.z > 0.0f && position.z < EDGE_SIZE_GROUND_PLANE) {
|
||||
gravity = glm::vec3(0.0f, -1.0f, 0.0f);
|
||||
//
|
||||
// 'Default' gravity pulls you downward in Y when you are near the X/Z plane
|
||||
const glm::vec3 DEFAULT_GRAVITY(0.f, -1.f, 0.f);
|
||||
glm::vec3 gravity(DEFAULT_GRAVITY);
|
||||
float DEFAULT_SURFACE_RADIUS = 30.f;
|
||||
float gravityStrength;
|
||||
|
||||
// Weaken gravity with height
|
||||
if (position.y > 0.f) {
|
||||
gravityStrength = 1.f / powf((DEFAULT_SURFACE_RADIUS + position.y) / DEFAULT_SURFACE_RADIUS, 2.f);
|
||||
gravity *= gravityStrength;
|
||||
}
|
||||
|
||||
// get the lock for the duration of the call
|
||||
|
@ -71,11 +77,18 @@ glm::vec3 Environment::getGravity (const glm::vec3& position) {
|
|||
foreach (const ServerData& serverData, _data) {
|
||||
foreach (const EnvironmentData& environmentData, serverData) {
|
||||
glm::vec3 vector = environmentData.getAtmosphereCenter() - position;
|
||||
if (glm::length(vector) < environmentData.getAtmosphereOuterRadius()) {
|
||||
float surfaceRadius = environmentData.getAtmosphereInnerRadius();
|
||||
if (glm::length(vector) <= surfaceRadius) {
|
||||
// At or inside a planet, gravity is as set for the planet
|
||||
gravity += glm::normalize(vector) * environmentData.getGravity();
|
||||
} else {
|
||||
// Outside a planet, the gravity falls off with distance
|
||||
gravityStrength = 1.f / powf(glm::length(vector) / surfaceRadius, 2.f);
|
||||
gravity += glm::normalize(vector) * environmentData.getGravity() * gravityStrength;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return gravity;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
//
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
#include "Avatar.h"
|
||||
#include "Head.h"
|
||||
#include "Util.h"
|
||||
#include <vector>
|
||||
|
@ -18,7 +20,6 @@ const float EYE_RIGHT_OFFSET = 0.27f;
|
|||
const float EYE_UP_OFFSET = 0.36f;
|
||||
const float EYE_FRONT_OFFSET = 0.8f;
|
||||
const float EAR_RIGHT_OFFSET = 1.0;
|
||||
//const float MOUTH_FRONT_OFFSET = 0.9f;
|
||||
const float MOUTH_UP_OFFSET = -0.3f;
|
||||
const float HEAD_MOTION_DECAY = 0.1;
|
||||
const float MINIMUM_EYE_ROTATION_DOT = 0.5f; // based on a dot product: 1.0 is straight ahead, 0.0 is 90 degrees off
|
||||
|
@ -62,6 +63,7 @@ Head::Head(Avatar* owningAvatar) :
|
|||
_audioAttack(0.0f),
|
||||
_returnSpringScale(1.0f),
|
||||
_bodyRotation(0.0f, 0.0f, 0.0f),
|
||||
_lookingInMirror(false),
|
||||
_renderLookatVectors(false),
|
||||
_mohawkTriangleFan(NULL),
|
||||
_mohawkColors(NULL)
|
||||
|
@ -84,13 +86,14 @@ void Head::reset() {
|
|||
|
||||
|
||||
void Head::resetHairPhysics() {
|
||||
glm::vec3 up = getUpDirection();
|
||||
for (int t = 0; t < NUM_HAIR_TUFTS; t ++) {
|
||||
|
||||
_hairTuft[t].length = HAIR_LENGTH;
|
||||
_hairTuft[t].thickness = HAIR_THICKNESS;
|
||||
_hairTuft[t].basePosition = _position + _orientation.getUp() * _scale * 0.9f;
|
||||
_hairTuft[t].midPosition = _hairTuft[t].basePosition + _orientation.getUp() * _hairTuft[t].length * ONE_HALF;
|
||||
_hairTuft[t].endPosition = _hairTuft[t].midPosition + _orientation.getUp() * _hairTuft[t].length * ONE_HALF;
|
||||
_hairTuft[t].basePosition = _position + up * _scale * 0.9f;
|
||||
_hairTuft[t].midPosition = _hairTuft[t].basePosition + up * _hairTuft[t].length * ONE_HALF;
|
||||
_hairTuft[t].endPosition = _hairTuft[t].midPosition + up * _hairTuft[t].length * ONE_HALF;
|
||||
_hairTuft[t].midVelocity = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
_hairTuft[t].endVelocity = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
|
@ -156,7 +159,7 @@ void Head::determineIfLookingAtSomething() {
|
|||
_lookingAtSomething = false;
|
||||
} else {
|
||||
glm::vec3 targetLookatAxis = glm::normalize(_lookAtPosition - caclulateAverageEyePosition());
|
||||
float dot = glm::dot(targetLookatAxis, _orientation.getFront());
|
||||
float dot = glm::dot(targetLookatAxis, getFrontDirection());
|
||||
if (dot < MINIMUM_EYE_ROTATION_DOT) { // too far off from center for the eyes to rotate
|
||||
_lookingAtSomething = false;
|
||||
} else {
|
||||
|
@ -165,57 +168,48 @@ void Head::determineIfLookingAtSomething() {
|
|||
}
|
||||
}
|
||||
|
||||
void Head::calculateGeometry(bool lookingInMirror) {
|
||||
//generate orientation directions based on Euler angles...
|
||||
|
||||
float pitch = _pitch;
|
||||
float yaw = _yaw;
|
||||
float roll = _roll;
|
||||
|
||||
if (lookingInMirror) {
|
||||
yaw = -_yaw;
|
||||
roll = -_roll;
|
||||
}
|
||||
|
||||
_orientation.setToIdentity();
|
||||
_orientation.roll (_bodyRotation.z + roll );
|
||||
_orientation.pitch(_bodyRotation.x + pitch);
|
||||
_orientation.yaw (_bodyRotation.y + yaw );
|
||||
void Head::calculateGeometry() {
|
||||
//generate orientation directions
|
||||
glm::quat orientation = getOrientation();
|
||||
glm::vec3 right = orientation * AVATAR_RIGHT;
|
||||
glm::vec3 up = orientation * AVATAR_UP;
|
||||
glm::vec3 front = orientation * AVATAR_FRONT;
|
||||
|
||||
//calculate the eye positions
|
||||
_leftEyePosition = _position
|
||||
- _orientation.getRight() * _scale * EYE_RIGHT_OFFSET
|
||||
+ _orientation.getUp () * _scale * EYE_UP_OFFSET
|
||||
+ _orientation.getFront() * _scale * EYE_FRONT_OFFSET;
|
||||
- right * _scale * EYE_RIGHT_OFFSET
|
||||
+ up * _scale * EYE_UP_OFFSET
|
||||
+ front * _scale * EYE_FRONT_OFFSET;
|
||||
_rightEyePosition = _position
|
||||
+ _orientation.getRight() * _scale * EYE_RIGHT_OFFSET
|
||||
+ _orientation.getUp () * _scale * EYE_UP_OFFSET
|
||||
+ _orientation.getFront() * _scale * EYE_FRONT_OFFSET;
|
||||
+ right * _scale * EYE_RIGHT_OFFSET
|
||||
+ up * _scale * EYE_UP_OFFSET
|
||||
+ front * _scale * EYE_FRONT_OFFSET;
|
||||
|
||||
//calculate the eyebrow positions
|
||||
_leftEyeBrowPosition = _leftEyePosition;
|
||||
_rightEyeBrowPosition = _rightEyePosition;
|
||||
|
||||
//calculate the ear positions
|
||||
_leftEarPosition = _position - _orientation.getRight() * _scale * EAR_RIGHT_OFFSET;
|
||||
_rightEarPosition = _position + _orientation.getRight() * _scale * EAR_RIGHT_OFFSET;
|
||||
_leftEarPosition = _position - right * _scale * EAR_RIGHT_OFFSET;
|
||||
_rightEarPosition = _position + right * _scale * EAR_RIGHT_OFFSET;
|
||||
|
||||
//calculate the mouth position
|
||||
_mouthPosition = _position + _orientation.getUp () * _scale * MOUTH_UP_OFFSET
|
||||
+ _orientation.getFront() * _scale;
|
||||
_mouthPosition = _position + up * _scale * MOUTH_UP_OFFSET
|
||||
+ front * _scale;
|
||||
}
|
||||
|
||||
|
||||
void Head::render(bool lookingInMirror, glm::vec3 cameraPosition, float alpha) {
|
||||
|
||||
_renderAlpha = alpha;
|
||||
_lookingInMirror = lookingInMirror;
|
||||
|
||||
calculateGeometry(lookingInMirror);
|
||||
calculateGeometry();
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_RESCALE_NORMAL);
|
||||
|
||||
renderMohawk(lookingInMirror, cameraPosition);
|
||||
renderMohawk(cameraPosition);
|
||||
renderHeadSphere();
|
||||
renderEyeBalls();
|
||||
renderEars();
|
||||
|
@ -259,7 +253,7 @@ void Head::createMohawk() {
|
|||
}
|
||||
}
|
||||
|
||||
void Head::renderMohawk(bool lookingInMirror, glm::vec3 cameraPosition) {
|
||||
void Head::renderMohawk(glm::vec3 cameraPosition) {
|
||||
|
||||
if (!_mohawkTriangleFan) {
|
||||
createMohawk();
|
||||
|
@ -281,7 +275,7 @@ void Head::renderMohawk(bool lookingInMirror, glm::vec3 cameraPosition) {
|
|||
glm::vec3 mid2 = _hairTuft[t].midPosition + midPerpendicular * _hairTuft[t].thickness * ONE_HALF * ONE_HALF;
|
||||
|
||||
glColor3f(_mohawkColors[t].x, _mohawkColors[t].y, _mohawkColors[t].z);
|
||||
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
glVertex3f(base1.x, base1.y, base1.z );
|
||||
glVertex3f(base2.x, base2.y, base2.z );
|
||||
|
@ -297,8 +291,8 @@ void Head::renderMohawk(bool lookingInMirror, glm::vec3 cameraPosition) {
|
|||
} else {
|
||||
glPushMatrix();
|
||||
glTranslatef(_position.x, _position.y, _position.z);
|
||||
glRotatef((lookingInMirror ? (_bodyRotation.y - _yaw) : (_bodyRotation.y + _yaw)), 0, 1, 0);
|
||||
glRotatef(lookingInMirror ? _roll: -_roll, 0, 0, 1);
|
||||
glRotatef((_lookingInMirror ? (_bodyRotation.y - _yaw) : (_bodyRotation.y + _yaw)), 0, 1, 0);
|
||||
glRotatef(_lookingInMirror ? _roll: -_roll, 0, 0, 1);
|
||||
glRotatef(-_pitch - _bodyRotation.x, 1, 0, 0);
|
||||
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
|
@ -312,6 +306,16 @@ void Head::renderMohawk(bool lookingInMirror, glm::vec3 cameraPosition) {
|
|||
}
|
||||
}
|
||||
|
||||
glm::quat Head::getOrientation() const {
|
||||
return glm::quat(glm::radians(_bodyRotation)) * glm::quat(glm::radians(_lookingInMirror ?
|
||||
glm::vec3(_pitch, -_yaw, -_roll) : glm::vec3(_pitch, _yaw, _roll)));
|
||||
}
|
||||
|
||||
glm::quat Head::getWorldAlignedOrientation () const {
|
||||
Avatar* owningAvatar = static_cast<Avatar*>(_owningAvatar);
|
||||
return owningAvatar->getWorldAlignedOrientation() * glm::quat(glm::radians(_lookingInMirror ?
|
||||
glm::vec3(_pitch, -_yaw, -_roll) : glm::vec3(_pitch, _yaw, _roll)));
|
||||
}
|
||||
|
||||
void Head::renderHeadSphere() {
|
||||
glPushMatrix();
|
||||
|
@ -341,9 +345,14 @@ void Head::renderMouth() {
|
|||
|
||||
float s = sqrt(_averageLoudness);
|
||||
|
||||
glm::vec3 r = _orientation.getRight() * _scale * (0.30f + s * 0.0014f );
|
||||
glm::vec3 u = _orientation.getUp () * _scale * (0.05f + s * 0.0040f );
|
||||
glm::vec3 f = _orientation.getFront() * _scale * 0.09f;
|
||||
glm::quat orientation = getOrientation();
|
||||
glm::vec3 right = orientation * AVATAR_RIGHT;
|
||||
glm::vec3 up = orientation * AVATAR_UP;
|
||||
glm::vec3 front = orientation * AVATAR_FRONT;
|
||||
|
||||
glm::vec3 r = right * _scale * (0.30f + s * 0.0014f );
|
||||
glm::vec3 u = up * _scale * (0.05f + s * 0.0040f );
|
||||
glm::vec3 f = front * _scale * 0.09f;
|
||||
|
||||
glm::vec3 middle = _mouthPosition;
|
||||
glm::vec3 leftCorner = _mouthPosition - r * 1.0f;
|
||||
|
@ -364,7 +373,7 @@ void Head::renderMouth() {
|
|||
rightTop = _position + glm::normalize(rightTop - _position) * constrainedRadius;
|
||||
leftBottom = _position + glm::normalize(leftBottom - _position) * constrainedRadius;
|
||||
rightBottom = _position + glm::normalize(rightBottom - _position) * constrainedRadius;
|
||||
|
||||
|
||||
glColor3f(0.2f, 0.0f, 0.0f);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
|
@ -403,11 +412,16 @@ void Head::renderEyeBrows() {
|
|||
glm::vec3 rightTop = _leftEyePosition;
|
||||
glm::vec3 leftBottom = _leftEyePosition;
|
||||
glm::vec3 rightBottom = _leftEyePosition;
|
||||
|
||||
glm::vec3 r = _orientation.getRight() * length;
|
||||
glm::vec3 u = _orientation.getUp() * height;
|
||||
glm::vec3 t = _orientation.getUp() * (height + width);
|
||||
glm::vec3 f = _orientation.getFront() * _scale * -0.1f;
|
||||
|
||||
glm::quat orientation = getOrientation();
|
||||
glm::vec3 right = orientation * AVATAR_RIGHT;
|
||||
glm::vec3 up = orientation * AVATAR_UP;
|
||||
glm::vec3 front = orientation * AVATAR_FRONT;
|
||||
|
||||
glm::vec3 r = right * length;
|
||||
glm::vec3 u = up * height;
|
||||
glm::vec3 t = up * (height + width);
|
||||
glm::vec3 f = front * _scale * -0.1f;
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
|
||||
|
@ -475,6 +489,8 @@ void Head::renderEyeBalls() {
|
|||
gluSphere(irisQuadric, EYEBALL_RADIUS, 30, 30);
|
||||
glPopMatrix();
|
||||
|
||||
glm::vec3 front = getFrontDirection();
|
||||
|
||||
// render left iris
|
||||
glPushMatrix(); {
|
||||
glTranslatef(_leftEyePosition.x, _leftEyePosition.y, _leftEyePosition.z); //translate to eyeball position
|
||||
|
@ -485,20 +501,20 @@ void Head::renderEyeBalls() {
|
|||
|
||||
//rotate the eyeball to aim towards the lookat position
|
||||
glm::vec3 targetLookatAxis = glm::normalize(_lookAtPosition - _leftEyePosition); // the lookat direction
|
||||
glm::vec3 rotationAxis = glm::cross(targetLookatAxis, IDENTITY_UP);
|
||||
float angle = 180.0f - angleBetween(targetLookatAxis, IDENTITY_UP);
|
||||
glm::vec3 rotationAxis = glm::cross(targetLookatAxis, AVATAR_UP);
|
||||
float angle = 180.0f - angleBetween(targetLookatAxis, AVATAR_UP);
|
||||
glRotatef(angle, rotationAxis.x, rotationAxis.y, rotationAxis.z);
|
||||
glRotatef(180.0, 0.0f, 1.0f, 0.0f); //adjust roll to correct after previous rotations
|
||||
} else {
|
||||
|
||||
//rotate the eyeball to aim straight ahead
|
||||
glm::vec3 rotationAxisToHeadFront = glm::cross(_orientation.getFront(), IDENTITY_UP);
|
||||
float angleToHeadFront = 180.0f - angleBetween(_orientation.getFront(), IDENTITY_UP);
|
||||
glm::vec3 rotationAxisToHeadFront = glm::cross(front, AVATAR_UP);
|
||||
float angleToHeadFront = 180.0f - angleBetween(front, AVATAR_UP);
|
||||
glRotatef(angleToHeadFront, rotationAxisToHeadFront.x, rotationAxisToHeadFront.y, rotationAxisToHeadFront.z);
|
||||
|
||||
//set the amount of roll (for correction after previous rotations)
|
||||
float rollRotation = angleBetween(_orientation.getFront(), IDENTITY_FRONT);
|
||||
float dot = glm::dot(_orientation.getFront(), -IDENTITY_RIGHT);
|
||||
float rollRotation = angleBetween(front, AVATAR_FRONT);
|
||||
float dot = glm::dot(front, -AVATAR_RIGHT);
|
||||
if ( dot < 0.0f ) { rollRotation = -rollRotation; }
|
||||
glRotatef(rollRotation, 0.0f, 1.0f, 0.0f); //roll the iris or correct roll about the lookat vector
|
||||
}
|
||||
|
@ -529,21 +545,21 @@ void Head::renderEyeBalls() {
|
|||
|
||||
//rotate the eyeball to aim towards the lookat position
|
||||
glm::vec3 targetLookatAxis = glm::normalize(_lookAtPosition - _rightEyePosition);
|
||||
glm::vec3 rotationAxis = glm::cross(targetLookatAxis, IDENTITY_UP);
|
||||
float angle = 180.0f - angleBetween(targetLookatAxis, IDENTITY_UP);
|
||||
glm::vec3 rotationAxis = glm::cross(targetLookatAxis, AVATAR_UP);
|
||||
float angle = 180.0f - angleBetween(targetLookatAxis, AVATAR_UP);
|
||||
glRotatef(angle, rotationAxis.x, rotationAxis.y, rotationAxis.z);
|
||||
glRotatef(180.0f, 0.0f, 1.0f, 0.0f); //adjust roll to correct after previous rotations
|
||||
|
||||
} else {
|
||||
|
||||
//rotate the eyeball to aim straight ahead
|
||||
glm::vec3 rotationAxisToHeadFront = glm::cross(_orientation.getFront(), IDENTITY_UP);
|
||||
float angleToHeadFront = 180.0f - angleBetween(_orientation.getFront(), IDENTITY_UP);
|
||||
glm::vec3 rotationAxisToHeadFront = glm::cross(front, AVATAR_UP);
|
||||
float angleToHeadFront = 180.0f - angleBetween(front, AVATAR_UP);
|
||||
glRotatef(angleToHeadFront, rotationAxisToHeadFront.x, rotationAxisToHeadFront.y, rotationAxisToHeadFront.z);
|
||||
|
||||
//set the amount of roll (for correction after previous rotations)
|
||||
float rollRotation = angleBetween(_orientation.getFront(), IDENTITY_FRONT);
|
||||
float dot = glm::dot(_orientation.getFront(), -IDENTITY_RIGHT);
|
||||
float rollRotation = angleBetween(front, AVATAR_FRONT);
|
||||
float dot = glm::dot(front, -AVATAR_RIGHT);
|
||||
if ( dot < 0.0f ) { rollRotation = -rollRotation; }
|
||||
glRotatef(rollRotation, 0.0f, 1.0f, 0.0f); //roll the iris or correct roll about the lookat vector
|
||||
}
|
||||
|
@ -578,6 +594,11 @@ void Head::renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosi
|
|||
|
||||
void Head::updateHairPhysics(float deltaTime) {
|
||||
|
||||
glm::quat orientation = getOrientation();
|
||||
glm::vec3 right = orientation * AVATAR_RIGHT;
|
||||
glm::vec3 up = orientation * AVATAR_UP;
|
||||
glm::vec3 front = orientation * AVATAR_FRONT;
|
||||
|
||||
for (int t = 0; t < NUM_HAIR_TUFTS; t ++) {
|
||||
|
||||
float fraction = (float)t / (float)(NUM_HAIR_TUFTS - 1);
|
||||
|
@ -586,8 +607,8 @@ void Head::updateHairPhysics(float deltaTime) {
|
|||
|
||||
float radian = angle * PI_OVER_180;
|
||||
glm::vec3 baseDirection
|
||||
= _orientation.getFront() * sinf(radian)
|
||||
+ _orientation.getUp() * cosf(radian);
|
||||
= front * sinf(radian)
|
||||
+ up * cosf(radian);
|
||||
|
||||
_hairTuft[t].basePosition = _position + _scale * 0.9f * baseDirection;
|
||||
|
||||
|
@ -603,13 +624,13 @@ void Head::updateHairPhysics(float deltaTime) {
|
|||
if (midLength > 0.0f) {
|
||||
midDirection = midAxis / midLength;
|
||||
} else {
|
||||
midDirection = _orientation.getUp();
|
||||
midDirection = up;
|
||||
}
|
||||
|
||||
if (endLength > 0.0f) {
|
||||
endDirection = endAxis / endLength;
|
||||
} else {
|
||||
endDirection = _orientation.getUp();
|
||||
endDirection = up;
|
||||
}
|
||||
|
||||
// add spring force
|
||||
|
@ -654,13 +675,13 @@ void Head::updateHairPhysics(float deltaTime) {
|
|||
if (newMidLength > 0.0f) {
|
||||
newMidDirection = newMidVector/newMidLength;
|
||||
} else {
|
||||
newMidDirection = _orientation.getUp();
|
||||
newMidDirection = up;
|
||||
}
|
||||
|
||||
if (newEndLength > 0.0f) {
|
||||
newEndDirection = newEndVector/newEndLength;
|
||||
} else {
|
||||
newEndDirection = _orientation.getUp();
|
||||
newEndDirection = up;
|
||||
}
|
||||
|
||||
_hairTuft[t].endPosition = _hairTuft[t].midPosition + newEndDirection * _hairTuft[t].length * ONE_HALF;
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "world.h"
|
||||
#include "InterfaceConfig.h"
|
||||
#include "SerialInterface.h"
|
||||
#include "Orientation.h"
|
||||
#include <SharedUtil.h>
|
||||
|
||||
enum eyeContactTargets
|
||||
|
@ -35,7 +34,7 @@ public:
|
|||
void reset();
|
||||
void simulate(float deltaTime, bool isMine);
|
||||
void render(bool lookingInMirror, glm::vec3 cameraPosition, float alpha);
|
||||
void renderMohawk(bool lookingInMirror, glm::vec3 cameraPosition);
|
||||
void renderMohawk(glm::vec3 cameraPosition);
|
||||
|
||||
void setScale (float scale ) { _scale = scale; }
|
||||
void setPosition (glm::vec3 position ) { _position = position; }
|
||||
|
@ -46,7 +45,14 @@ public:
|
|||
void setAverageLoudness(float averageLoudness ) { _averageLoudness = averageLoudness; }
|
||||
void setReturnToCenter (bool returnHeadToCenter) { _returnHeadToCenter = returnHeadToCenter; }
|
||||
void setRenderLookatVectors(bool onOff ) { _renderLookatVectors = onOff; }
|
||||
|
||||
|
||||
glm::quat getOrientation() const;
|
||||
glm::quat getWorldAlignedOrientation () const;
|
||||
|
||||
glm::vec3 getRightDirection() const { return getOrientation() * AVATAR_RIGHT; }
|
||||
glm::vec3 getUpDirection () const { return getOrientation() * AVATAR_UP; }
|
||||
glm::vec3 getFrontDirection() const { return getOrientation() * AVATAR_FRONT; }
|
||||
|
||||
const bool getReturnToCenter() const { return _returnHeadToCenter; } // Do you want head to try to return to center (depends on interface detected)
|
||||
float getAverageLoudness() {return _averageLoudness;};
|
||||
glm::vec3 caclulateAverageEyePosition() { return _leftEyePosition + (_rightEyePosition - _leftEyePosition ) * ONE_HALF; }
|
||||
|
@ -91,8 +97,8 @@ private:
|
|||
float _averageLoudness;
|
||||
float _audioAttack;
|
||||
float _returnSpringScale; //strength of return springs
|
||||
Orientation _orientation;
|
||||
glm::vec3 _bodyRotation;
|
||||
bool _lookingInMirror;
|
||||
bool _renderLookatVectors;
|
||||
HairTuft _hairTuft[NUM_HAIR_TUFTS];
|
||||
glm::vec3* _mohawkTriangleFan;
|
||||
|
@ -106,7 +112,7 @@ private:
|
|||
void renderEars();
|
||||
void renderMouth();
|
||||
void renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosition, glm::vec3 lookatPosition);
|
||||
void calculateGeometry( bool lookingInMirror);
|
||||
void calculateGeometry();
|
||||
void determineIfLookingAtSomething();
|
||||
void resetHairPhysics();
|
||||
void updateHairPhysics(float deltaTime);
|
||||
|
|
|
@ -6,15 +6,129 @@
|
|||
|
||||
#include "Skeleton.h"
|
||||
|
||||
const float BODY_SPRING_DEFAULT_TIGHTNESS = 1000.0f;
|
||||
const float FLOATING_HEIGHT = 0.13f;
|
||||
|
||||
Skeleton::Skeleton() {
|
||||
}
|
||||
|
||||
void Skeleton::initialize() {
|
||||
|
||||
for (int b=0; b<NUM_AVATAR_JOINTS; b++) {
|
||||
joint[b].parent = AVATAR_JOINT_NULL;
|
||||
joint[b].position = glm::vec3(0.0, 0.0, 0.0);
|
||||
joint[b].defaultPosePosition = glm::vec3(0.0, 0.0, 0.0);
|
||||
joint[b].rotation = glm::quat(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
joint[b].length = 0.0;
|
||||
}
|
||||
|
||||
// specify the parental hierarchy
|
||||
joint[ AVATAR_JOINT_PELVIS ].parent = AVATAR_JOINT_NULL;
|
||||
joint[ AVATAR_JOINT_TORSO ].parent = AVATAR_JOINT_PELVIS;
|
||||
joint[ AVATAR_JOINT_CHEST ].parent = AVATAR_JOINT_TORSO;
|
||||
joint[ AVATAR_JOINT_NECK_BASE ].parent = AVATAR_JOINT_CHEST;
|
||||
joint[ AVATAR_JOINT_HEAD_BASE ].parent = AVATAR_JOINT_NECK_BASE;
|
||||
joint[ AVATAR_JOINT_HEAD_TOP ].parent = AVATAR_JOINT_HEAD_BASE;
|
||||
joint[ AVATAR_JOINT_LEFT_COLLAR ].parent = AVATAR_JOINT_CHEST;
|
||||
joint[ AVATAR_JOINT_LEFT_SHOULDER ].parent = AVATAR_JOINT_LEFT_COLLAR;
|
||||
joint[ AVATAR_JOINT_LEFT_ELBOW ].parent = AVATAR_JOINT_LEFT_SHOULDER;
|
||||
joint[ AVATAR_JOINT_LEFT_WRIST ].parent = AVATAR_JOINT_LEFT_ELBOW;
|
||||
joint[ AVATAR_JOINT_LEFT_FINGERTIPS ].parent = AVATAR_JOINT_LEFT_WRIST;
|
||||
joint[ AVATAR_JOINT_RIGHT_COLLAR ].parent = AVATAR_JOINT_CHEST;
|
||||
joint[ AVATAR_JOINT_RIGHT_SHOULDER ].parent = AVATAR_JOINT_RIGHT_COLLAR;
|
||||
joint[ AVATAR_JOINT_RIGHT_ELBOW ].parent = AVATAR_JOINT_RIGHT_SHOULDER;
|
||||
joint[ AVATAR_JOINT_RIGHT_WRIST ].parent = AVATAR_JOINT_RIGHT_ELBOW;
|
||||
joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].parent = AVATAR_JOINT_RIGHT_WRIST;
|
||||
joint[ AVATAR_JOINT_LEFT_HIP ].parent = AVATAR_JOINT_PELVIS;
|
||||
joint[ AVATAR_JOINT_LEFT_KNEE ].parent = AVATAR_JOINT_LEFT_HIP;
|
||||
joint[ AVATAR_JOINT_LEFT_HEEL ].parent = AVATAR_JOINT_LEFT_KNEE;
|
||||
joint[ AVATAR_JOINT_LEFT_TOES ].parent = AVATAR_JOINT_LEFT_HEEL;
|
||||
joint[ AVATAR_JOINT_RIGHT_HIP ].parent = AVATAR_JOINT_PELVIS;
|
||||
joint[ AVATAR_JOINT_RIGHT_KNEE ].parent = AVATAR_JOINT_RIGHT_HIP;
|
||||
joint[ AVATAR_JOINT_RIGHT_HEEL ].parent = AVATAR_JOINT_RIGHT_KNEE;
|
||||
joint[ AVATAR_JOINT_RIGHT_TOES ].parent = AVATAR_JOINT_RIGHT_HEEL;
|
||||
|
||||
// specify the default pose position
|
||||
joint[ AVATAR_JOINT_PELVIS ].defaultPosePosition = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
joint[ AVATAR_JOINT_TORSO ].defaultPosePosition = glm::vec3( 0.0, 0.09, -0.01 );
|
||||
joint[ AVATAR_JOINT_CHEST ].defaultPosePosition = glm::vec3( 0.0, 0.09, -0.01 );
|
||||
joint[ AVATAR_JOINT_NECK_BASE ].defaultPosePosition = glm::vec3( 0.0, 0.14, 0.01 );
|
||||
joint[ AVATAR_JOINT_HEAD_BASE ].defaultPosePosition = glm::vec3( 0.0, 0.04, 0.00 );
|
||||
|
||||
joint[ AVATAR_JOINT_LEFT_COLLAR ].defaultPosePosition = glm::vec3( -0.06, 0.04, 0.01 );
|
||||
joint[ AVATAR_JOINT_LEFT_SHOULDER ].defaultPosePosition = glm::vec3( -0.05, 0.0, 0.01 );
|
||||
joint[ AVATAR_JOINT_LEFT_ELBOW ].defaultPosePosition = glm::vec3( 0.0, -0.16, 0.0 );
|
||||
joint[ AVATAR_JOINT_LEFT_WRIST ].defaultPosePosition = glm::vec3( 0.0, -0.117, 0.0 );
|
||||
joint[ AVATAR_JOINT_LEFT_FINGERTIPS ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 );
|
||||
|
||||
joint[ AVATAR_JOINT_RIGHT_COLLAR ].defaultPosePosition = glm::vec3( 0.06, 0.04, 0.01 );
|
||||
joint[ AVATAR_JOINT_RIGHT_SHOULDER ].defaultPosePosition = glm::vec3( 0.05, 0.0, 0.01 );
|
||||
joint[ AVATAR_JOINT_RIGHT_ELBOW ].defaultPosePosition = glm::vec3( 0.0, -0.16, 0.0 );
|
||||
joint[ AVATAR_JOINT_RIGHT_WRIST ].defaultPosePosition = glm::vec3( 0.0, -0.117, 0.0 );
|
||||
joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].defaultPosePosition = glm::vec3( 0.0, -0.1, 0.0 );
|
||||
|
||||
joint[ AVATAR_JOINT_LEFT_HIP ].defaultPosePosition = glm::vec3( -0.05, 0.0, 0.02 );
|
||||
joint[ AVATAR_JOINT_LEFT_KNEE ].defaultPosePosition = glm::vec3( 0.01, -0.25, -0.03 );
|
||||
joint[ AVATAR_JOINT_LEFT_HEEL ].defaultPosePosition = glm::vec3( 0.01, -0.22, 0.08 );
|
||||
joint[ AVATAR_JOINT_LEFT_TOES ].defaultPosePosition = glm::vec3( 0.00, -0.03, -0.05 );
|
||||
|
||||
joint[ AVATAR_JOINT_RIGHT_HIP ].defaultPosePosition = glm::vec3( 0.05, 0.0, 0.02 );
|
||||
joint[ AVATAR_JOINT_RIGHT_KNEE ].defaultPosePosition = glm::vec3( -0.01, -0.25, -0.03 );
|
||||
joint[ AVATAR_JOINT_RIGHT_HEEL ].defaultPosePosition = glm::vec3( -0.01, -0.22, 0.08 );
|
||||
joint[ AVATAR_JOINT_RIGHT_TOES ].defaultPosePosition = glm::vec3( 0.00, -0.03, -0.05 );
|
||||
|
||||
// calculate bone length
|
||||
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
|
||||
joint[b].length = glm::length(joint[b].defaultPosePosition);
|
||||
}
|
||||
}
|
||||
|
||||
void Skeleton::render() {
|
||||
// calculate positions and rotations of all bones by traversing the skeleton tree:
|
||||
void Skeleton::update(float deltaTime, const glm::quat& orientation, glm::vec3 position) {
|
||||
|
||||
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
|
||||
if (joint[b].parent == AVATAR_JOINT_NULL) {
|
||||
joint[b].rotation = orientation;
|
||||
joint[b].position = position;
|
||||
}
|
||||
else {
|
||||
joint[b].rotation = joint[ joint[b].parent ].rotation;
|
||||
joint[b].position = joint[ joint[b].parent ].position;
|
||||
}
|
||||
|
||||
glm::vec3 rotatedJointVector = joint[b].rotation * joint[b].defaultPosePosition;
|
||||
joint[b].position += rotatedJointVector;
|
||||
}
|
||||
}
|
||||
|
||||
void Skeleton::simulate(float deltaTime) {
|
||||
float Skeleton::getArmLength() {
|
||||
return joint[ AVATAR_JOINT_RIGHT_ELBOW ].length
|
||||
+ joint[ AVATAR_JOINT_RIGHT_WRIST ].length
|
||||
+ joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].length;
|
||||
}
|
||||
|
||||
float Skeleton::getHeight() {
|
||||
return
|
||||
joint[ AVATAR_JOINT_LEFT_HEEL ].length +
|
||||
joint[ AVATAR_JOINT_LEFT_KNEE ].length +
|
||||
joint[ AVATAR_JOINT_PELVIS ].length +
|
||||
joint[ AVATAR_JOINT_TORSO ].length +
|
||||
joint[ AVATAR_JOINT_CHEST ].length +
|
||||
joint[ AVATAR_JOINT_NECK_BASE ].length +
|
||||
joint[ AVATAR_JOINT_HEAD_BASE ].length;
|
||||
}
|
||||
|
||||
float Skeleton::getPelvisStandingHeight() {
|
||||
return joint[ AVATAR_JOINT_LEFT_HEEL ].length +
|
||||
joint[ AVATAR_JOINT_LEFT_KNEE ].length;
|
||||
}
|
||||
|
||||
float Skeleton::getPelvisFloatingHeight() {
|
||||
return joint[ AVATAR_JOINT_LEFT_HEEL ].length +
|
||||
joint[ AVATAR_JOINT_LEFT_KNEE ].length +
|
||||
FLOATING_HEIGHT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
#ifndef hifi_Skeleton_h
|
||||
#define hifi_Skeleton_h
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
enum AvatarJointID
|
||||
{
|
||||
AVATAR_JOINT_NULL = -1,
|
||||
|
@ -45,10 +48,24 @@ public:
|
|||
Skeleton();
|
||||
|
||||
void initialize();
|
||||
void simulate(float deltaTime);
|
||||
void update(float deltaTime, const glm::quat&, glm::vec3 position);
|
||||
void render();
|
||||
|
||||
private:
|
||||
};
|
||||
float getArmLength();
|
||||
float getHeight();
|
||||
float getPelvisStandingHeight();
|
||||
float getPelvisFloatingHeight();
|
||||
|
||||
struct AvatarJoint
|
||||
{
|
||||
AvatarJointID parent; // which joint is this joint connected to?
|
||||
glm::vec3 position; // the position at the "end" of the joint - in global space
|
||||
glm::vec3 defaultPosePosition; // the parent relative position when the avatar is in the "T-pose"
|
||||
glm::quat rotation; // the parent-relative rotation (orientation) of the joint as a quaternion
|
||||
float length; // the length of vector connecting the joint and its parent
|
||||
};
|
||||
|
||||
AvatarJoint joint[ NUM_AVATAR_JOINTS ];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -20,11 +20,25 @@ Transmitter::Transmitter() :
|
|||
_isConnected(false),
|
||||
_lastRotationRate(0,0,0),
|
||||
_lastAcceleration(0,0,0),
|
||||
_estimatedRotation(0,0,0)
|
||||
_estimatedRotation(0,0,0),
|
||||
_lastReceivedPacket(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Transmitter::checkForLostTransmitter() {
|
||||
// If we are in motion, check for loss of transmitter packets
|
||||
if (glm::length(_estimatedRotation) > 0.f) {
|
||||
timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
const int TIME_TO_ASSUME_LOST_MSECS = 2000;
|
||||
int msecsSinceLast = diffclock(_lastReceivedPacket, &now);
|
||||
if (msecsSinceLast > TIME_TO_ASSUME_LOST_MSECS) {
|
||||
resetLevels();
|
||||
printLog("Transmitter signal lost.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
void Transmitter::resetLevels() {
|
||||
_lastRotationRate *= 0.f;
|
||||
_estimatedRotation *= 0.f;
|
||||
|
@ -34,6 +48,11 @@ void Transmitter::processIncomingData(unsigned char* packetData, int numBytes) {
|
|||
const int PACKET_HEADER_SIZE = 1; // Packet's first byte is 'T'
|
||||
const int ROTATION_MARKER_SIZE = 1; // 'R' = Rotation (clockwise about x,y,z)
|
||||
const int ACCELERATION_MARKER_SIZE = 1; // 'A' = Acceleration (x,y,z)
|
||||
if (!_lastReceivedPacket) {
|
||||
_lastReceivedPacket = new timeval;
|
||||
}
|
||||
gettimeofday(_lastReceivedPacket, NULL);
|
||||
|
||||
if (numBytes == PACKET_HEADER_SIZE + ROTATION_MARKER_SIZE + ACCELERATION_MARKER_SIZE
|
||||
+ sizeof(_lastRotationRate) + sizeof(_lastAcceleration)
|
||||
+ sizeof(_touchState.x) + sizeof(_touchState.y) + sizeof(_touchState.state)) {
|
||||
|
@ -71,12 +90,12 @@ void Transmitter::processIncomingData(unsigned char* packetData, int numBytes) {
|
|||
_estimatedRotation.y *= (1.f - DECAY_RATE * DELTA_TIME);
|
||||
|
||||
if (!_isConnected) {
|
||||
printf("Transmitter V2 Connected.\n");
|
||||
printLog("Transmitter Connected.\n");
|
||||
_isConnected = true;
|
||||
_estimatedRotation *= 0.0;
|
||||
}
|
||||
} else {
|
||||
printf("Transmitter V2 packet read error, %d bytes.\n", numBytes);
|
||||
printLog("Transmitter packet read error, %d bytes.\n", numBytes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ class Transmitter
|
|||
public:
|
||||
Transmitter();
|
||||
void render();
|
||||
void checkForLostTransmitter();
|
||||
void resetLevels();
|
||||
void renderLevels(int width, int height);
|
||||
bool isConnected() { return _isConnected; };
|
||||
|
@ -41,6 +42,7 @@ private:
|
|||
glm::vec3 _lastAcceleration;
|
||||
glm::vec3 _estimatedRotation;
|
||||
TouchState _touchState;
|
||||
timeval* _lastReceivedPacket;
|
||||
|
||||
#endif /* defined(__hifi__Transmitter__) */
|
||||
};
|
||||
|
|
|
@ -12,7 +12,8 @@
|
|||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/noise.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
#include <AvatarData.h>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "Log.h"
|
||||
|
@ -71,6 +72,65 @@ float angleBetween(const glm::vec3& v1, const glm::vec3& v2) {
|
|||
return acos((glm::dot(v1, v2)) / (glm::length(v1) * glm::length(v2))) * 180.f / PIf;
|
||||
}
|
||||
|
||||
// Safe version of glm::eulerAngles; uses the factorization method described in David Eberly's
|
||||
// http://www.geometrictools.com/Documentation/EulerAngles.pdf (via Clyde,
|
||||
// https://github.com/threerings/clyde/blob/master/src/main/java/com/threerings/math/Quaternion.java)
|
||||
glm::vec3 safeEulerAngles(const glm::quat& q) {
|
||||
float sy = 2.0f * (q.y * q.w - q.x * q.z);
|
||||
if (sy < 1.0f - EPSILON) {
|
||||
if (sy > -1.0f + EPSILON) {
|
||||
return glm::degrees(glm::vec3(
|
||||
atan2f(q.y * q.z + q.x * q.w, 0.5f - (q.x * q.x + q.y * q.y)),
|
||||
asinf(sy),
|
||||
atan2f(q.x * q.y + q.z * q.w, 0.5f - (q.y * q.y + q.z * q.z))));
|
||||
|
||||
} else {
|
||||
// not a unique solution; x + z = atan2(-m21, m11)
|
||||
return glm::degrees(glm::vec3(
|
||||
0.0f,
|
||||
PIf * -0.5f,
|
||||
atan2f(q.x * q.w - q.y * q.z, 0.5f - (q.x * q.x + q.z * q.z))));
|
||||
}
|
||||
} else {
|
||||
// not a unique solution; x - z = atan2(-m21, m11)
|
||||
return glm::degrees(glm::vec3(
|
||||
0.0f,
|
||||
PIf * 0.5f,
|
||||
-atan2f(q.x * q.w - q.y * q.z, 0.5f - (q.x * q.x + q.z * q.z))));
|
||||
}
|
||||
}
|
||||
|
||||
// Safe version of glm::mix; based on the code in Nick Bobick's article,
|
||||
// http://www.gamasutra.com/features/19980703/quaternions_01.htm (via Clyde,
|
||||
// https://github.com/threerings/clyde/blob/master/src/main/java/com/threerings/math/Quaternion.java)
|
||||
glm::quat safeMix(const glm::quat& q1, const glm::quat& q2, float proportion) {
|
||||
float cosa = q1.x * q2.x + q1.y * q2.y + q1.z * q2.z + q1.w * q2.w;
|
||||
float ox = q2.x, oy = q2.y, oz = q2.z, ow = q2.w, s0, s1;
|
||||
|
||||
// adjust signs if necessary
|
||||
if (cosa < 0.0f) {
|
||||
cosa = -cosa;
|
||||
ox = -ox;
|
||||
oy = -oy;
|
||||
oz = -oz;
|
||||
ow = -ow;
|
||||
}
|
||||
|
||||
// calculate coefficients; if the angle is too close to zero, we must fall back
|
||||
// to linear interpolation
|
||||
if ((1.0f - cosa) > EPSILON) {
|
||||
float angle = acosf(cosa), sina = sinf(angle);
|
||||
s0 = sinf((1.0f - proportion) * angle) / sina;
|
||||
s1 = sinf(proportion * angle) / sina;
|
||||
|
||||
} else {
|
||||
s0 = 1.0f - proportion;
|
||||
s1 = proportion;
|
||||
}
|
||||
|
||||
return glm::normalize(glm::quat(s0 * q1.w + s1 * ow, s0 * q1.x + s1 * ox, s0 * q1.y + s1 * oy, s0 * q1.z + s1 * oz));
|
||||
}
|
||||
|
||||
// Draw a 3D vector floating in space
|
||||
void drawVector(glm::vec3 * vector) {
|
||||
glDisable(GL_LIGHTING);
|
||||
|
@ -333,10 +393,10 @@ void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int
|
|||
}
|
||||
|
||||
|
||||
void renderOrientationDirections(glm::vec3 position, Orientation orientation, float size) {
|
||||
glm::vec3 pRight = position + orientation.getRight() * size;
|
||||
glm::vec3 pUp = position + orientation.getUp () * size;
|
||||
glm::vec3 pFront = position + orientation.getFront() * size;
|
||||
void renderOrientationDirections(glm::vec3 position, const glm::quat& orientation, float size) {
|
||||
glm::vec3 pRight = position + orientation * AVATAR_RIGHT * size;
|
||||
glm::vec3 pUp = position + orientation * AVATAR_UP * size;
|
||||
glm::vec3 pFront = position + orientation * AVATAR_FRONT * size;
|
||||
|
||||
glColor3f(1.0f, 0.0f, 0.0f);
|
||||
glBegin(GL_LINE_STRIP);
|
||||
|
@ -364,126 +424,5 @@ bool closeEnoughForGovernmentWork(float a, float b) {
|
|||
}
|
||||
|
||||
|
||||
void testOrientationClass() {
|
||||
printLog("\n----------\ntestOrientationClass()\n----------\n\n");
|
||||
|
||||
oTestCase tests[] = {
|
||||
// - inputs ------------, outputs -------------------- ------------------- ----------------------------
|
||||
// -- front -------------------, -- up -------------, -- right -------------------
|
||||
// ( yaw , pitch, roll , front.x , front.y , front.z , up.x , up.y , up.z , right.x , right.y , right.z )
|
||||
|
||||
// simple yaw tests
|
||||
oTestCase( 0.f , 0.f , 0.f , 0.f , 0.f , 1.0f , 0.f , 1.0f , 0.f , -1.0f , 0.f , 0.f ),
|
||||
oTestCase(45.0f , 0.f , 0.f , 0.707107f , 0.f , 0.707107f , 0.f , 1.0f , 0.f , -0.707107f, 0.f , 0.707107f),
|
||||
oTestCase( 90.0f, 0.f , 0.f , 1.0f , 0.f , 0.f , 0.f , 1.0f , 0.f , 0.0f , 0.f , 1.0f ),
|
||||
oTestCase(135.0f, 0.f , 0.f , 0.707107f , 0.f ,-0.707107f , 0.f , 1.0f , 0.f , 0.707107f, 0.f , 0.707107f),
|
||||
oTestCase(180.0f, 0.f , 0.f , 0.f , 0.f , -1.0f , 0.f , 1.0f , 0.f , 1.0f , 0.f , 0.f ),
|
||||
oTestCase(225.0f, 0.f , 0.f , -0.707107f , 0.f ,-0.707107f , 0.f , 1.0f , 0.f , 0.707107f, 0.f , -0.707107f),
|
||||
oTestCase(270.0f, 0.f , 0.f , -1.0f , 0.f , 0.f , 0.f , 1.0f , 0.f , 0.0f , 0.f , -1.0f ),
|
||||
oTestCase(315.0f, 0.f , 0.f , -0.707107f , 0.f , 0.707107f , 0.f , 1.0f , 0.f , -0.707107f, 0.f , -0.707107f),
|
||||
oTestCase(-45.0f, 0.f , 0.f , -0.707107f , 0.f , 0.707107f , 0.f , 1.0f , 0.f , -0.707107f, 0.f , -0.707107f),
|
||||
oTestCase(-90.0f, 0.f , 0.f , -1.0f , 0.f , 0.f , 0.f , 1.0f , 0.f , 0.0f , 0.f , -1.0f ),
|
||||
oTestCase(-135.0f,0.f , 0.f , -0.707107f , 0.f ,-0.707107f , 0.f , 1.0f , 0.f , 0.707107f, 0.f , -0.707107f),
|
||||
oTestCase(-180.0f,0.f , 0.f , 0.f , 0.f , -1.0f , 0.f , 1.0f , 0.f , 1.0f , 0.f , 0.f ),
|
||||
oTestCase(-225.0f,0.f , 0.f , 0.707107f , 0.f ,-0.707107f , 0.f , 1.0f , 0.f , 0.707107f, 0.f , 0.707107f),
|
||||
oTestCase(-270.0f,0.f , 0.f , 1.0f , 0.f , 0.f , 0.f , 1.0f , 0.f , 0.0f , 0.f , 1.0f ),
|
||||
oTestCase(-315.0f,0.f , 0.f , 0.707107f , 0.f , 0.707107f , 0.f , 1.0f , 0.f , -0.707107f, 0.f , 0.707107f),
|
||||
|
||||
// simple pitch tests
|
||||
oTestCase( 0.f , 0.f , 0.f , 0.f, 0.f , 1.0f , 0.f , 1.0f , 0.f , -1.0f , 0.f , 0.f ),
|
||||
oTestCase( 0.f ,45.0f , 0.f , 0.f, 0.707107f , 0.707107f, 0.f ,0.707107f, -0.707107f, -1.0f , 0.f , 0.f ),
|
||||
oTestCase( 0.f ,90.f , 0.f , 0.f, 1.0f , 0.0f , 0.f ,0.0f , -1.0f , -1.0f , 0.f , 0.f ),
|
||||
oTestCase( 0.f ,135.0f, 0.f , 0.f, 0.707107f , -0.707107f, 0.f ,-0.707107f, -0.707107f, -1.0f , 0.f , 0.f ),
|
||||
oTestCase( 0.f ,180.f , 0.f , 0.f, 0.0f ,-1.0f , 0.f ,-1.0f , 0.f , -1.0f , 0.f , 0.f ),
|
||||
oTestCase( 0.f ,225.0f, 0.f , 0.f,-0.707107f , -0.707107f, 0.f ,-0.707107f, 0.707107f, -1.0f , 0.f , 0.f ),
|
||||
oTestCase( 0.f ,270.f , 0.f , 0.f,-1.0f , 0.0f , 0.f ,0.0f , 1.0f , -1.0f , 0.f , 0.f ),
|
||||
oTestCase( 0.f ,315.0f, 0.f , 0.f,-0.707107f , 0.707107f, 0.f , 0.707107f, 0.707107f, -1.0f , 0.f , 0.f ),
|
||||
|
||||
// simple roll tests
|
||||
oTestCase( 0.f , 0.f , 0.f , 0.f , 0.f , 1.0f , 0.f , 1.0f ,0.0f , -1.0f , 0.f , 0.0f ),
|
||||
oTestCase( 0.f , 0.f ,45.0f , 0.f , 0.f , 1.0f , 0.707107f , 0.707107f ,0.0f , -0.707107f, 0.707107f, 0.0f ),
|
||||
oTestCase( 0.f , 0.f ,90.f , 0.f , 0.f , 1.0f , 1.0f , 0.0f ,0.0f , 0.0f , 1.0f , 0.0f ),
|
||||
oTestCase( 0.f , 0.f ,135.0f , 0.f , 0.f , 1.0f , 0.707107f , -0.707107f,0.0f , 0.707107f , 0.707107f, 0.0f ),
|
||||
oTestCase( 0.f , 0.f ,180.f , 0.f , 0.f , 1.0f , 0.0f , -1.0f ,0.0f , 1.0f , 0.0f , 0.0f ),
|
||||
oTestCase( 0.f , 0.f ,225.0f , 0.f , 0.f , 1.0f , -0.707107f, -0.707107f,0.0f , 0.707107f ,-0.707107f, 0.0f ),
|
||||
oTestCase( 0.f , 0.f ,270.f , 0.f , 0.f , 1.0f , -1.0f , 0.0f ,0.0f , 0.0f , -1.0f , 0.0f ),
|
||||
oTestCase( 0.f , 0.f ,315.0f , 0.f , 0.f , 1.0f , -0.707107f, 0.707107f ,0.0f , -0.707107f,-0.707107f, 0.0f ),
|
||||
|
||||
// yaw combo tests
|
||||
oTestCase( 90.f , 90.f , 0.f , 0.f , 1.0f , 0.0f , -1.0f , 0.0f , 0.f , 0.0f , 0.f , 1.0f ),
|
||||
oTestCase( 90.f , 0.f , 90.f , 1.0f , 0.0f, 0.f , 0.0f , 0.0f , -1.f , 0.0f , 1.0f , 0.0f ),
|
||||
};
|
||||
|
||||
int failedCount = 0;
|
||||
int totalTests = sizeof(tests)/sizeof(oTestCase);
|
||||
|
||||
for (int i=0; i < totalTests; i++) {
|
||||
|
||||
bool passed = true; // I'm an optimist!
|
||||
|
||||
float yaw = tests[i].yaw;
|
||||
float pitch = tests[i].pitch;
|
||||
float roll = tests[i].roll;
|
||||
|
||||
Orientation o1;
|
||||
o1.setToIdentity();
|
||||
o1.yaw(yaw);
|
||||
o1.pitch(pitch);
|
||||
o1.roll(roll);
|
||||
|
||||
glm::vec3 front = o1.getFront();
|
||||
glm::vec3 up = o1.getUp();
|
||||
glm::vec3 right = o1.getRight();
|
||||
|
||||
printLog("\n-----\nTest: %d - yaw=%f , pitch=%f , roll=%f \n",i+1,yaw,pitch,roll);
|
||||
|
||||
printLog("\nFRONT\n");
|
||||
printLog(" + received: front.x=%f, front.y=%f, front.z=%f\n",front.x,front.y,front.z);
|
||||
|
||||
if (closeEnoughForGovernmentWork(front.x, tests[i].frontX)
|
||||
&& closeEnoughForGovernmentWork(front.y, tests[i].frontY)
|
||||
&& closeEnoughForGovernmentWork(front.z, tests[i].frontZ)) {
|
||||
printLog(" front vector PASSES!\n");
|
||||
} else {
|
||||
printLog(" expected: front.x=%f, front.y=%f, front.z=%f\n",tests[i].frontX,tests[i].frontY,tests[i].frontZ);
|
||||
printLog(" front vector FAILED! \n");
|
||||
passed = false;
|
||||
}
|
||||
|
||||
printLog("\nUP\n");
|
||||
printLog(" + received: up.x=%f, up.y=%f, up.z=%f\n",up.x,up.y,up.z);
|
||||
if (closeEnoughForGovernmentWork(up.x, tests[i].upX)
|
||||
&& closeEnoughForGovernmentWork(up.y, tests[i].upY)
|
||||
&& closeEnoughForGovernmentWork(up.z, tests[i].upZ)) {
|
||||
printLog(" up vector PASSES!\n");
|
||||
} else {
|
||||
printLog(" expected: up.x=%f, up.y=%f, up.z=%f\n",tests[i].upX,tests[i].upY,tests[i].upZ);
|
||||
printLog(" up vector FAILED!\n");
|
||||
passed = false;
|
||||
}
|
||||
|
||||
|
||||
printLog("\nRIGHT\n");
|
||||
printLog(" + received: right.x=%f, right.y=%f, right.z=%f\n",right.x,right.y,right.z);
|
||||
if (closeEnoughForGovernmentWork(right.x, tests[i].rightX)
|
||||
&& closeEnoughForGovernmentWork(right.y, tests[i].rightY)
|
||||
&& closeEnoughForGovernmentWork(right.z, tests[i].rightZ)) {
|
||||
printLog(" right vector PASSES!\n");
|
||||
} else {
|
||||
printLog(" expected: right.x=%f, right.y=%f, right.z=%f\n",tests[i].rightX,tests[i].rightY,tests[i].rightZ);
|
||||
printLog(" right vector FAILED!\n");
|
||||
passed = false;
|
||||
}
|
||||
|
||||
if (!passed) {
|
||||
printLog("\n-----\nTest: %d - FAILED! \n----------\n\n",i+1);
|
||||
failedCount++;
|
||||
}
|
||||
}
|
||||
printLog("\n-----\nTotal Failed: %d out of %d \n----------\n\n",failedCount,totalTests);
|
||||
printLog("\n----------DONE----------\n\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
#endif
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <Orientation.h>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
// the standard sans serif font family
|
||||
#define SANS_FONT_FAMILY "Helvetica"
|
||||
|
@ -46,50 +45,19 @@ void drawVector(glm::vec3* vector);
|
|||
|
||||
float angleBetween(const glm::vec3& v1, const glm::vec3& v2);
|
||||
|
||||
glm::vec3 safeEulerAngles(const glm::quat& q);
|
||||
|
||||
glm::quat safeMix(const glm::quat& q1, const glm::quat& q2, float alpha);
|
||||
|
||||
double diffclock(timeval *clock1,timeval *clock2);
|
||||
|
||||
void drawGroundPlaneGrid(float size);
|
||||
|
||||
void renderDiskShadow(glm::vec3 position, glm::vec3 upDirection, float radius, float darkness);
|
||||
|
||||
void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size );
|
||||
void renderOrientationDirections( glm::vec3 position, const glm::quat& orientation, float size );
|
||||
|
||||
void renderSphereOutline(glm::vec3 position, float radius, int numSides, glm::vec3 cameraPosition);
|
||||
void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int numSides );
|
||||
|
||||
|
||||
class oTestCase {
|
||||
public:
|
||||
float yaw;
|
||||
float pitch;
|
||||
float roll;
|
||||
|
||||
float frontX;
|
||||
float frontY;
|
||||
float frontZ;
|
||||
|
||||
float upX;
|
||||
float upY;
|
||||
float upZ;
|
||||
|
||||
float rightX;
|
||||
float rightY;
|
||||
float rightZ;
|
||||
|
||||
oTestCase(
|
||||
float yaw, float pitch, float roll,
|
||||
float frontX, float frontY, float frontZ,
|
||||
float upX, float upY, float upZ,
|
||||
float rightX, float rightY, float rightZ
|
||||
) :
|
||||
yaw(yaw),pitch(pitch),roll(roll),
|
||||
frontX(frontX),frontY(frontY),frontZ(frontZ),
|
||||
upX(upX),upY(upY),upZ(upZ),
|
||||
rightX(rightX),rightY(rightY),rightZ(rightZ)
|
||||
{};
|
||||
};
|
||||
|
||||
|
||||
void testOrientationClass();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
|
||||
const float WORLD_SIZE = 10.0;
|
||||
#define PIf 3.14159265f
|
||||
#define GRAVITY_EARTH 9.80665f;
|
||||
|
||||
const float GRAVITY_EARTH = 9.80665f;
|
||||
const float EDGE_SIZE_GROUND_PLANE = 20.f;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -20,6 +20,11 @@ const int WANT_RESIN_AT_BIT = 0;
|
|||
const int WANT_COLOR_AT_BIT = 1;
|
||||
const int WANT_DELTA_AT_BIT = 2;
|
||||
|
||||
// this is where the coordinate system is represented
|
||||
const glm::vec3 AVATAR_RIGHT = glm::vec3(1.0f, 0.0f, 0.0f);
|
||||
const glm::vec3 AVATAR_UP = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
const glm::vec3 AVATAR_FRONT = glm::vec3(0.0f, 0.0f, -1.0f);
|
||||
|
||||
enum KeyState
|
||||
{
|
||||
NO_KEY_DOWN,
|
||||
|
|
|
@ -1,121 +0,0 @@
|
|||
//-----------------------------------------------------------
|
||||
//
|
||||
// Created by Jeffrey Ventrella
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
//-----------------------------------------------------------
|
||||
|
||||
#include "Orientation.h"
|
||||
#include "SharedUtil.h"
|
||||
|
||||
static const bool USING_QUATERNIONS = true;
|
||||
|
||||
Orientation::Orientation() {
|
||||
setToIdentity();
|
||||
}
|
||||
|
||||
void Orientation::setToIdentity() {
|
||||
|
||||
quat = glm::quat();
|
||||
right = glm::vec3(IDENTITY_RIGHT);
|
||||
up = glm::vec3(IDENTITY_UP );
|
||||
front = glm::vec3(IDENTITY_FRONT);
|
||||
}
|
||||
|
||||
void Orientation::set(Orientation o) {
|
||||
|
||||
quat = o.quat;
|
||||
right = o.right;
|
||||
up = o.up;
|
||||
front = o.front;
|
||||
}
|
||||
|
||||
void Orientation::yaw(float angle) {
|
||||
|
||||
float radian = angle * PI_OVER_180;
|
||||
|
||||
if (USING_QUATERNIONS) {
|
||||
rotateAndGenerateDirections(glm::quat(glm::vec3(0.0f, -radian, 0.0f)));
|
||||
} else {
|
||||
float s = sin(radian);
|
||||
float c = cos(radian);
|
||||
|
||||
glm::vec3 cosineFront = front * c;
|
||||
glm::vec3 cosineRight = right * c;
|
||||
glm::vec3 sineFront = front * s;
|
||||
glm::vec3 sineRight = right * s;
|
||||
|
||||
front = cosineFront - sineRight;
|
||||
right = cosineRight + sineFront;
|
||||
}
|
||||
}
|
||||
|
||||
void Orientation::pitch(float angle) {
|
||||
|
||||
float radian = angle * PI_OVER_180;
|
||||
|
||||
if (USING_QUATERNIONS) {
|
||||
rotateAndGenerateDirections(glm::quat(glm::vec3(radian, 0.0f, 0.0f)));
|
||||
} else {
|
||||
float s = sin(radian);
|
||||
float c = cos(radian);
|
||||
|
||||
glm::vec3 cosineUp = up * c;
|
||||
glm::vec3 cosineFront = front * c;
|
||||
glm::vec3 sineUp = up * s;
|
||||
glm::vec3 sineFront = front * s;
|
||||
|
||||
up = cosineUp - sineFront;
|
||||
front = cosineFront + sineUp;
|
||||
}
|
||||
}
|
||||
|
||||
void Orientation::roll(float angle) {
|
||||
|
||||
float radian = angle * PI_OVER_180;
|
||||
|
||||
if (USING_QUATERNIONS) {
|
||||
rotateAndGenerateDirections(glm::quat(glm::vec3(0.0f, 0.0f, radian)));
|
||||
} else {
|
||||
float s = sin(radian);
|
||||
float c = cos(radian);
|
||||
|
||||
glm::vec3 cosineUp = up * c;
|
||||
glm::vec3 cosineRight = right * c;
|
||||
glm::vec3 sineUp = up * s;
|
||||
glm::vec3 sineRight = right * s;
|
||||
|
||||
up = cosineUp - sineRight;
|
||||
right = cosineRight + sineUp;
|
||||
}
|
||||
}
|
||||
|
||||
void Orientation::rotate(float pitch_change, float yaw_change, float roll_change) {
|
||||
pitch(pitch_change);
|
||||
yaw (yaw_change);
|
||||
roll (roll_change);
|
||||
}
|
||||
|
||||
void Orientation::rotate(glm::vec3 eulerAngles) {
|
||||
|
||||
//this needs to be optimized!
|
||||
pitch(eulerAngles.x);
|
||||
yaw (eulerAngles.y);
|
||||
roll (eulerAngles.z);
|
||||
}
|
||||
|
||||
void Orientation::rotate( glm::quat rotation ) {
|
||||
rotateAndGenerateDirections(rotation);
|
||||
}
|
||||
|
||||
|
||||
void Orientation::rotateAndGenerateDirections(glm::quat rotation) {
|
||||
|
||||
quat = quat * rotation;
|
||||
|
||||
glm::mat4 rotationMatrix = glm::mat4_cast(quat);
|
||||
|
||||
right = glm::vec3(glm::vec4(IDENTITY_RIGHT, 0.0f) * rotationMatrix);
|
||||
up = glm::vec3(glm::vec4(IDENTITY_UP, 0.0f) * rotationMatrix);
|
||||
front = glm::vec3(glm::vec4(IDENTITY_FRONT, 0.0f) * rotationMatrix);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
//-----------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
//-----------------------------------------------------------
|
||||
|
||||
#ifndef __interface__orientation__
|
||||
#define __interface__orientation__
|
||||
|
||||
#include <cmath>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
// this is where the coordinate system is represented
|
||||
const glm::vec3 IDENTITY_RIGHT = glm::vec3(-1.0f, 0.0f, 0.0f);
|
||||
const glm::vec3 IDENTITY_UP = glm::vec3( 0.0f, 1.0f, 0.0f);
|
||||
const glm::vec3 IDENTITY_FRONT = glm::vec3( 0.0f, 0.0f, 1.0f);
|
||||
|
||||
class Orientation
|
||||
{
|
||||
public:
|
||||
Orientation();
|
||||
|
||||
void set(Orientation);
|
||||
void setToIdentity();
|
||||
|
||||
void pitch(float pitch_change);
|
||||
void yaw (float yaw_change);
|
||||
void roll (float roll_change);
|
||||
|
||||
void rotate(float pitch, float yaw, float roll);
|
||||
void rotate(glm::vec3 EulerAngles);
|
||||
void rotate(glm::quat quaternion);
|
||||
|
||||
const glm::quat& getQuat() const {return quat;}
|
||||
|
||||
const glm::vec3& getRight() const {return right;}
|
||||
const glm::vec3& getUp () const {return up; }
|
||||
const glm::vec3& getFront() const {return front;}
|
||||
|
||||
const glm::vec3& getIdentityRight() const {return IDENTITY_RIGHT;}
|
||||
const glm::vec3& getIdentityUp () const {return IDENTITY_UP;}
|
||||
const glm::vec3& getIdentityFront() const {return IDENTITY_FRONT;}
|
||||
|
||||
private:
|
||||
|
||||
glm::quat quat;
|
||||
glm::vec3 right;
|
||||
glm::vec3 up;
|
||||
glm::vec3 front;
|
||||
|
||||
void rotateAndGenerateDirections(glm::quat rotation);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -10,6 +10,7 @@
|
|||
#define __hifi__SharedUtil__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
|
Loading…
Reference in a new issue