mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 06:44:06 +02:00
Merge branch 'master' of https://github.com/worklist/hifi
This commit is contained in:
commit
d32511ee47
21 changed files with 240 additions and 83 deletions
|
@ -63,10 +63,31 @@ static void sendVoxelEditMessage(PACKET_HEADER header, VoxelDetail& detail) {
|
|||
}
|
||||
}
|
||||
|
||||
const float BUG_VOXEL_SIZE = 0.125f / TREE_SCALE;
|
||||
glm::vec3 bugPosition = glm::vec3(BUG_VOXEL_SIZE * 10.0, BUG_VOXEL_SIZE * 30.0, BUG_VOXEL_SIZE * 10.0);
|
||||
glm::vec3 rotatePoint(glm::vec3 point, float angle) {
|
||||
// First, create the quaternion based on this angle of rotation
|
||||
glm::quat q(glm::vec3(0, -angle, 0));
|
||||
|
||||
// Next, create a rotation matrix from that quaternion
|
||||
glm::mat4 rotation = glm::mat4_cast(q);
|
||||
|
||||
// Transform the original vectors by the rotation matrix to get the new vectors
|
||||
glm::vec4 quatPoint(point.x, point.y, point.z, 0);
|
||||
glm::vec4 newPoint = quatPoint * rotation;
|
||||
|
||||
return glm::vec3(newPoint.x, newPoint.y, newPoint.z);
|
||||
}
|
||||
|
||||
|
||||
const float BUG_VOXEL_SIZE = 0.0625f / TREE_SCALE;
|
||||
glm::vec3 bugPosition = glm::vec3(BUG_VOXEL_SIZE * 20.0, BUG_VOXEL_SIZE * 30.0, BUG_VOXEL_SIZE * 20.0);
|
||||
glm::vec3 bugDirection = glm::vec3(0, 0, 1);
|
||||
const int VOXELS_PER_BUG = 18;
|
||||
glm::vec3 bugPathCenter = glm::vec3(BUG_VOXEL_SIZE * 150.0, BUG_VOXEL_SIZE * 30.0, BUG_VOXEL_SIZE * 150.0);
|
||||
float bugPathRadius = BUG_VOXEL_SIZE * 140.0;
|
||||
float bugPathTheta = 0.0 * PI_OVER_180;
|
||||
float bugRotation = 0.0 * PI_OVER_180;
|
||||
float bugAngleDelta = 0.2 * PI_OVER_180;
|
||||
bool moveBugInLine = false;
|
||||
|
||||
class BugPart {
|
||||
public:
|
||||
|
@ -122,10 +143,15 @@ static void renderMovingBug() {
|
|||
// Generate voxels for where bug used to be
|
||||
for (int i = 0; i < VOXELS_PER_BUG; i++) {
|
||||
details[i].s = BUG_VOXEL_SIZE;
|
||||
details[i].x = bugPosition.x + (bugParts[i].partLocation.x * BUG_VOXEL_SIZE * (bugDirection.x < 0 ? -1 : 1));
|
||||
details[i].y = bugPosition.y + (bugParts[i].partLocation.y * BUG_VOXEL_SIZE * (bugDirection.y < 0 ? -1 : 1));
|
||||
details[i].z = bugPosition.z + (bugParts[i].partLocation.z * BUG_VOXEL_SIZE * (bugDirection.z < 0 ? -1 : 1));
|
||||
|
||||
glm::vec3 partAt = bugParts[i].partLocation * BUG_VOXEL_SIZE * (bugDirection.x < 0 ? -1.0f : 1.0f);
|
||||
glm::vec3 rotatedPartAt = rotatePoint(partAt, bugRotation);
|
||||
glm::vec3 offsetPartAt = rotatedPartAt + bugPosition;
|
||||
|
||||
details[i].x = offsetPartAt.x;
|
||||
details[i].y = offsetPartAt.y;
|
||||
details[i].z = offsetPartAt.z;
|
||||
|
||||
details[i].red = bugParts[i].partColor[0];
|
||||
details[i].green = bugParts[i].partColor[1];
|
||||
details[i].blue = bugParts[i].partColor[2];
|
||||
|
@ -146,17 +172,40 @@ static void renderMovingBug() {
|
|||
}
|
||||
|
||||
// Move the bug...
|
||||
bugPosition.x += (bugDirection.x * BUG_VOXEL_SIZE);
|
||||
bugPosition.y += (bugDirection.y * BUG_VOXEL_SIZE);
|
||||
bugPosition.z += (bugDirection.z * BUG_VOXEL_SIZE);
|
||||
if (moveBugInLine) {
|
||||
bugPosition.x += (bugDirection.x * BUG_VOXEL_SIZE);
|
||||
bugPosition.y += (bugDirection.y * BUG_VOXEL_SIZE);
|
||||
bugPosition.z += (bugDirection.z * BUG_VOXEL_SIZE);
|
||||
|
||||
// Check boundaries
|
||||
if (bugPosition.z > 1.0) {
|
||||
bugDirection.z = -1;
|
||||
}
|
||||
if (bugPosition.z < BUG_VOXEL_SIZE) {
|
||||
bugDirection.z = 1;
|
||||
// Check boundaries
|
||||
if (bugPosition.z > 1.0) {
|
||||
bugDirection.z = -1;
|
||||
}
|
||||
if (bugPosition.z < BUG_VOXEL_SIZE) {
|
||||
bugDirection.z = 1;
|
||||
}
|
||||
} else {
|
||||
|
||||
//printf("bugPathCenter=(%f,%f,%f)\n", bugPathCenter.x, bugPathCenter.y, bugPathCenter.z);
|
||||
|
||||
bugPathTheta += bugAngleDelta; // move slightly
|
||||
bugRotation -= bugAngleDelta; // rotate slightly
|
||||
|
||||
// If we loop past end of circle, just reset back into normal range
|
||||
if (bugPathTheta > (360.0f * PI_OVER_180)) {
|
||||
bugPathTheta = 0;
|
||||
bugRotation = 0;
|
||||
}
|
||||
|
||||
float x = bugPathCenter.x + bugPathRadius * cos(bugPathTheta);
|
||||
float z = bugPathCenter.z + bugPathRadius * sin(bugPathTheta);
|
||||
float y = bugPathCenter.y;
|
||||
|
||||
bugPosition = glm::vec3(x, y, z);
|
||||
//printf("bugPathTheta=%f\n", bugPathTheta);
|
||||
//printf("bugRotation=%f\n", bugRotation);
|
||||
}
|
||||
|
||||
//printf("bugPosition=(%f,%f,%f)\n", bugPosition.x, bugPosition.y, bugPosition.z);
|
||||
//printf("bugDirection=(%f,%f,%f)\n", bugDirection.x, bugDirection.y, bugDirection.z);
|
||||
// would be nice to add some randomness here...
|
||||
|
@ -164,10 +213,15 @@ static void renderMovingBug() {
|
|||
// Generate voxels for where bug is going to
|
||||
for (int i = 0; i < VOXELS_PER_BUG; i++) {
|
||||
details[i].s = BUG_VOXEL_SIZE;
|
||||
details[i].x = bugPosition.x + (bugParts[i].partLocation.x * BUG_VOXEL_SIZE * (bugDirection.x < 0 ? -1 : 1));
|
||||
details[i].y = bugPosition.y + (bugParts[i].partLocation.y * BUG_VOXEL_SIZE * (bugDirection.y < 0 ? -1 : 1));
|
||||
details[i].z = bugPosition.z + (bugParts[i].partLocation.z * BUG_VOXEL_SIZE * (bugDirection.z < 0 ? -1 : 1));
|
||||
|
||||
glm::vec3 partAt = bugParts[i].partLocation * BUG_VOXEL_SIZE * (bugDirection.x < 0 ? -1.0f : 1.0f);
|
||||
glm::vec3 rotatedPartAt = rotatePoint(partAt, bugRotation);
|
||||
glm::vec3 offsetPartAt = rotatedPartAt + bugPosition;
|
||||
|
||||
details[i].x = offsetPartAt.x;
|
||||
details[i].y = offsetPartAt.y;
|
||||
details[i].z = offsetPartAt.z;
|
||||
|
||||
details[i].red = bugParts[i].partColor[0];
|
||||
details[i].green = bugParts[i].partColor[1];
|
||||
details[i].blue = bugParts[i].partColor[2];
|
||||
|
|
|
@ -45,9 +45,9 @@ unsigned char *addAgentToBroadcastPacket(unsigned char *currentPosition, Agent *
|
|||
return currentPosition;
|
||||
}
|
||||
|
||||
void attachAvatarDataToAgent(Agent *newAgent) {
|
||||
void attachAvatarDataToAgent(Agent* newAgent) {
|
||||
if (newAgent->getLinkedData() == NULL) {
|
||||
newAgent->setLinkedData(new AvatarData());
|
||||
newAgent->setLinkedData(new AvatarData(newAgent));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ void *receiveAgentData(void *args) {
|
|||
|
||||
void createAvatarDataForAgent(Agent* agent) {
|
||||
if (!agent->getLinkedData()) {
|
||||
agent->setLinkedData(new AvatarData());
|
||||
agent->setLinkedData(new AvatarData(agent));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -128,7 +128,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
|||
_viewFrustumOffsetDistance(25.0),
|
||||
_viewFrustumOffsetUp(0.0),
|
||||
_audioScope(256, 200, true),
|
||||
_myAvatar(true),
|
||||
_manualFirstPerson(false),
|
||||
_mouseX(0),
|
||||
_mouseY(0),
|
||||
|
@ -884,7 +883,7 @@ void Application::idle() {
|
|||
|
||||
// Read serial port interface devices
|
||||
if (_serialPort.active) {
|
||||
_serialPort.readData();
|
||||
_serialPort.readData(deltaTime);
|
||||
}
|
||||
|
||||
// Sample hardware, update view frustum if needed, and send avatar data to mixer/agents
|
||||
|
@ -2098,9 +2097,9 @@ QAction* Application::checkedVoxelModeAction() const {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void Application::attachNewHeadToAgent(Agent *newAgent) {
|
||||
void Application::attachNewHeadToAgent(Agent* newAgent) {
|
||||
if (newAgent->getLinkedData() == NULL) {
|
||||
newAgent->setLinkedData(new Avatar(false));
|
||||
newAgent->setLinkedData(new Avatar(newAgent));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -67,10 +67,11 @@ float lightBlue [] = {0.7, 0.8, 1.0 };
|
|||
bool usingBigSphereCollisionTest = true;
|
||||
|
||||
float chatMessageScale = 0.0015;
|
||||
float chatMessageHeight = 0.10;
|
||||
float chatMessageHeight = 0.20;
|
||||
|
||||
Avatar::Avatar(bool isMine) :
|
||||
_isMine(isMine),
|
||||
Avatar::Avatar(Agent* owningAgent) :
|
||||
AvatarData(owningAgent),
|
||||
_head(this),
|
||||
_TEST_bigSphereRadius(0.4f),
|
||||
_TEST_bigSpherePosition(5.0f, _TEST_bigSphereRadius, 5.0f),
|
||||
_mousePressed(false),
|
||||
|
@ -229,7 +230,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
updateSkeleton();
|
||||
|
||||
//detect and respond to collisions with other avatars...
|
||||
if (_isMine) {
|
||||
if (!_owningAgent) {
|
||||
updateAvatarCollisions(deltaTime);
|
||||
}
|
||||
|
||||
|
@ -239,7 +240,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
_avatarTouch.simulate(deltaTime);
|
||||
|
||||
// apply gravity and collision with the ground/floor
|
||||
if (_isMine && USING_AVATAR_GRAVITY) {
|
||||
if (!_owningAgent && USING_AVATAR_GRAVITY) {
|
||||
_velocity += _gravity * (GRAVITY_SCALE * deltaTime);
|
||||
|
||||
updateCollisionWithEnvironment();
|
||||
|
@ -254,12 +255,12 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
}
|
||||
|
||||
// collision response with voxels
|
||||
if (_isMine) {
|
||||
if (!_owningAgent) {
|
||||
updateCollisionWithVoxels();
|
||||
}
|
||||
|
||||
// driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely)
|
||||
if (_isMine) {
|
||||
if (!_owningAgent) {
|
||||
|
||||
_thrust = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
|
@ -304,7 +305,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
}
|
||||
|
||||
// update body yaw by body yaw delta
|
||||
if (_isMine) {
|
||||
if (!_owningAgent) {
|
||||
_bodyPitch += _bodyPitchDelta * deltaTime;
|
||||
_bodyYaw += _bodyYawDelta * deltaTime;
|
||||
_bodyRoll += _bodyRollDelta * deltaTime;
|
||||
|
@ -365,7 +366,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
}
|
||||
|
||||
// If another avatar is near, dampen velocity as a function of closeness
|
||||
if (_isMine && (_distanceToNearestAvatar < PERIPERSONAL_RADIUS)) {
|
||||
if (!_owningAgent && (_distanceToNearestAvatar < PERIPERSONAL_RADIUS)) {
|
||||
float closeness = 1.0f - (_distanceToNearestAvatar / PERIPERSONAL_RADIUS);
|
||||
float drag = 1.0f - closeness * AVATAR_BRAKING_STRENGTH * deltaTime;
|
||||
if ( drag > 0.0f ) {
|
||||
|
@ -414,7 +415,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
}
|
||||
|
||||
// set head lookat position
|
||||
if (_isMine) {
|
||||
if (!_owningAgent) {
|
||||
if (_interactingOther) {
|
||||
_head.setLookAtPosition(_interactingOther->caclulateAverageEyePosition());
|
||||
} else {
|
||||
|
@ -427,7 +428,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
_head.setScale (_joint[ AVATAR_JOINT_HEAD_BASE ].radius);
|
||||
_head.setAudioLoudness(_audioLoudness);
|
||||
_head.setSkinColor(glm::vec3(skinColor[0], skinColor[1], skinColor[2]));
|
||||
_head.simulate(deltaTime, _isMine);
|
||||
_head.simulate(deltaTime, !_owningAgent);
|
||||
|
||||
// use speed and angular velocity to determine walking vs. standing
|
||||
if (_speed + fabs(_bodyYawDelta) > 0.2) {
|
||||
|
@ -466,7 +467,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) {
|
|||
|
||||
_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += transformedHandMovement;
|
||||
|
||||
if (_isMine) {
|
||||
if (!_owningAgent) {
|
||||
_avatarTouch.setMyBodyPosition(_position);
|
||||
|
||||
float closestDistance = std::numeric_limits<float>::max();
|
||||
|
@ -558,7 +559,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) {
|
|||
updateArmIKAndConstraints(deltaTime);
|
||||
|
||||
//Set right hand position and state to be transmitted, and also tell AvatarTouch about it
|
||||
if (_isMine) {
|
||||
if (!_owningAgent) {
|
||||
setHandPosition(_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position);
|
||||
|
||||
if (_mousePressed) {
|
||||
|
@ -727,7 +728,7 @@ void Avatar::setGravity(glm::vec3 gravity) {
|
|||
|
||||
void Avatar::render(bool lookingInMirror) {
|
||||
|
||||
if (_isMine && usingBigSphereCollisionTest) {
|
||||
if (!_owningAgent && usingBigSphereCollisionTest) {
|
||||
// show TEST big sphere
|
||||
glColor4f(0.5f, 0.6f, 0.8f, 0.7);
|
||||
glPushMatrix();
|
||||
|
@ -744,7 +745,7 @@ void Avatar::render(bool lookingInMirror) {
|
|||
renderBody(lookingInMirror);
|
||||
|
||||
// if this is my avatar, then render my interactions with the other avatar
|
||||
if (_isMine) {
|
||||
if (!_owningAgent) {
|
||||
_avatarTouch.render(getCameraPosition());
|
||||
}
|
||||
|
||||
|
@ -999,7 +1000,7 @@ void Avatar::updateSkeleton() {
|
|||
}
|
||||
|
||||
// if this is not my avatar, then hand position comes from transmitted data
|
||||
if (! _isMine) {
|
||||
if (_owningAgent) {
|
||||
_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _handPosition;
|
||||
}
|
||||
|
||||
|
@ -1135,12 +1136,12 @@ void Avatar::renderBody(bool lookingInMirror) {
|
|||
float distanceToCamera = glm::length(getCameraPosition() - _joint[b].position);
|
||||
// Always render other people, and render myself when beyond threshold distance
|
||||
if (b == AVATAR_JOINT_HEAD_BASE) { // the head is rendered as a special case
|
||||
if (lookingInMirror || !_isMine || distanceToCamera > RENDER_OPAQUE_BEYOND) {
|
||||
if (lookingInMirror || _owningAgent || distanceToCamera > RENDER_OPAQUE_BEYOND) {
|
||||
_head.render(lookingInMirror);
|
||||
}
|
||||
} else if (!_isMine || distanceToCamera > RENDER_TRANSLUCENT_BEYOND) {
|
||||
} else if (_owningAgent || distanceToCamera > RENDER_TRANSLUCENT_BEYOND) {
|
||||
// Render the sphere at the joint
|
||||
if (!_isMine) {
|
||||
if (_owningAgent) {
|
||||
glColor3f(skinColor[0] + _joint[b].touchForce * 0.3f,
|
||||
skinColor[1] - _joint[b].touchForce * 0.2f,
|
||||
skinColor[2] - _joint[b].touchForce * 0.1f);
|
||||
|
|
|
@ -76,7 +76,7 @@ enum AvatarJointID
|
|||
|
||||
class Avatar : public AvatarData {
|
||||
public:
|
||||
Avatar(bool isMine);
|
||||
Avatar(Agent* owningAgent = NULL);
|
||||
~Avatar();
|
||||
|
||||
void reset();
|
||||
|
@ -151,7 +151,6 @@ private:
|
|||
};
|
||||
|
||||
Head _head;
|
||||
bool _isMine;
|
||||
float _TEST_bigSphereRadius;
|
||||
glm::vec3 _TEST_bigSpherePosition;
|
||||
bool _mousePressed;
|
||||
|
|
|
@ -8,9 +8,11 @@
|
|||
#include "Util.h"
|
||||
#include <vector>
|
||||
#include <lodepng.h>
|
||||
#include <AgentList.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
const int MOHAWK_TRIANGLES = 50;
|
||||
const float EYE_RIGHT_OFFSET = 0.27f;
|
||||
const float EYE_UP_OFFSET = 0.36f;
|
||||
const float EYE_FRONT_OFFSET = 0.8f;
|
||||
|
@ -29,8 +31,8 @@ unsigned int IRIS_TEXTURE_WIDTH = 768;
|
|||
unsigned int IRIS_TEXTURE_HEIGHT = 498;
|
||||
vector<unsigned char> irisTexture;
|
||||
|
||||
Head::Head() :
|
||||
|
||||
Head::Head(Avatar* owningAvatar) :
|
||||
HeadData((AvatarData*)owningAvatar),
|
||||
yawRate(0.0f),
|
||||
_returnHeadToCenter(false),
|
||||
_audioLoudness(0.0f),
|
||||
|
@ -54,7 +56,10 @@ Head::Head() :
|
|||
_returnSpringScale(1.0f),
|
||||
_bodyRotation(0.0f, 0.0f, 0.0f),
|
||||
_headRotation(0.0f, 0.0f, 0.0f),
|
||||
_renderLookatVectors(false) {
|
||||
_renderLookatVectors(false),
|
||||
_mohawkTriangleFan(NULL),
|
||||
_mohawkColors(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
void Head::reset() {
|
||||
|
@ -175,6 +180,7 @@ void Head::render(bool lookingInMirror) {
|
|||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_RESCALE_NORMAL);
|
||||
|
||||
renderMohawk();
|
||||
renderHeadSphere();
|
||||
renderEyeBalls();
|
||||
renderEars();
|
||||
|
@ -186,6 +192,46 @@ void Head::render(bool lookingInMirror) {
|
|||
}
|
||||
}
|
||||
|
||||
void Head::createMohawk() {
|
||||
// int agentId = AgentList::getInstance()
|
||||
float height = 0.05f + randFloat() * 0.10f;
|
||||
float variance = 0.05 + randFloat() * 0.05f;
|
||||
const float RAD_PER_TRIANGLE = (2.3f + randFloat() * 0.2f) / (float)MOHAWK_TRIANGLES;
|
||||
_mohawkTriangleFan = new glm::vec3[MOHAWK_TRIANGLES];
|
||||
_mohawkColors = new glm::vec3[MOHAWK_TRIANGLES];
|
||||
_mohawkTriangleFan[0] = glm::vec3(0, 0, 0);
|
||||
glm::vec3 basicColor(randFloat(), randFloat(), randFloat());
|
||||
_mohawkColors[0] = basicColor;
|
||||
for (int i = 1; i < MOHAWK_TRIANGLES; i++) {
|
||||
_mohawkTriangleFan[i] = glm::vec3((randFloat() - 0.5f) * variance,
|
||||
height * cosf(i * RAD_PER_TRIANGLE - PI / 2.f)
|
||||
+ (randFloat() - 0.5f) * variance,
|
||||
height * sinf(i * RAD_PER_TRIANGLE - PI / 2.f)
|
||||
+ (randFloat() - 0.5f) * variance);
|
||||
_mohawkColors[i] = randFloat() * basicColor;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Head::renderMohawk() {
|
||||
if (!_mohawkTriangleFan) {
|
||||
createMohawk();
|
||||
} else {
|
||||
glPushMatrix();
|
||||
glTranslatef(_position.x, _position.y, _position.z);
|
||||
glRotatef(_bodyRotation.y, 0, 1, 0);
|
||||
glBegin(GL_TRIANGLE_FAN);
|
||||
for (int i = 0; i < MOHAWK_TRIANGLES; i++) {
|
||||
glColor3f(_mohawkColors[i].x, _mohawkColors[i].y, _mohawkColors[i].z);
|
||||
glVertex3fv(&_mohawkTriangleFan[i].x);
|
||||
glNormal3fv(&_mohawkColors[i].x);
|
||||
}
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Head::renderHeadSphere() {
|
||||
glPushMatrix();
|
||||
glTranslatef(_position.x, _position.y, _position.z); //translate to head position
|
||||
|
|
|
@ -24,13 +24,16 @@ enum eyeContactTargets
|
|||
MOUTH
|
||||
};
|
||||
|
||||
class Avatar;
|
||||
|
||||
class Head : public HeadData {
|
||||
public:
|
||||
Head();
|
||||
Head(Avatar* owningAvatar);
|
||||
|
||||
void reset();
|
||||
void simulate(float deltaTime, bool isMine);
|
||||
void render(bool lookingInMirror);
|
||||
void renderMohawk();
|
||||
|
||||
void setScale (float scale ) { _scale = scale; }
|
||||
void setPosition (glm::vec3 position ) { _position = position; }
|
||||
|
@ -80,8 +83,11 @@ private:
|
|||
glm::vec3 _bodyRotation;
|
||||
glm::vec3 _headRotation;
|
||||
bool _renderLookatVectors;
|
||||
glm::vec3* _mohawkTriangleFan;
|
||||
glm::vec3* _mohawkColors;
|
||||
|
||||
// private methods
|
||||
void createMohawk();
|
||||
void renderHeadSphere();
|
||||
void renderEyeBalls();
|
||||
void renderEyeBrows();
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
const short NO_READ_MAXIMUM_MSECS = 3000;
|
||||
const int GRAVITY_SAMPLES = 60; // Use the first few samples to baseline values
|
||||
const int LONG_TERM_RATE_SAMPLES = 1000;
|
||||
|
||||
const bool USING_INVENSENSE_MPU9150 = 1;
|
||||
|
||||
|
@ -136,6 +137,16 @@ void SerialInterface::renderLevels(int width, int height) {
|
|||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + getLastPitchRate(), LEVEL_CORNER_Y + 12);
|
||||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y + 27);
|
||||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + getLastRollRate(), LEVEL_CORNER_Y + 27);
|
||||
// Gyro Estimated Rotation
|
||||
glColor4f(0, 1, 1, 1);
|
||||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y - 1);
|
||||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + _estimatedRotation.y, LEVEL_CORNER_Y - 1);
|
||||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y + 14);
|
||||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + _estimatedRotation.z, LEVEL_CORNER_Y + 14);
|
||||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y + 29);
|
||||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + _estimatedRotation.x, LEVEL_CORNER_Y + 29);
|
||||
|
||||
|
||||
// Acceleration
|
||||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y + 42);
|
||||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + (int)((_lastAccelX - _gravity.x)* ACCEL_VIEW_SCALING),
|
||||
|
@ -169,7 +180,7 @@ void convertHexToInt(unsigned char* sourceBuffer, int& destinationInt) {
|
|||
|
||||
destinationInt = result;
|
||||
}
|
||||
void SerialInterface::readData() {
|
||||
void SerialInterface::readData(float deltaTime) {
|
||||
#ifdef __APPLE__
|
||||
|
||||
int initialSamples = totalSamples;
|
||||
|
@ -207,6 +218,11 @@ void SerialInterface::readData() {
|
|||
_lastYawRate = ((float) -yawRate) * LSB_TO_DEGREES_PER_SECOND;
|
||||
_lastPitchRate = ((float) -pitchRate) * LSB_TO_DEGREES_PER_SECOND;
|
||||
|
||||
// Update raw rotation estimates
|
||||
_estimatedRotation += deltaTime * glm::vec3(_lastRollRate - _averageGyroRates[0],
|
||||
_lastYawRate - _averageGyroRates[1],
|
||||
_lastPitchRate - _averageGyroRates[2]);
|
||||
|
||||
// Accumulate a set of initial baseline readings for setting gravity
|
||||
if (totalSamples == 0) {
|
||||
_averageGyroRates[0] = _lastRollRate;
|
||||
|
@ -216,17 +232,20 @@ void SerialInterface::readData() {
|
|||
_gravity.y = _lastAccelY;
|
||||
_gravity.z = _lastAccelZ;
|
||||
|
||||
}
|
||||
else if (totalSamples < GRAVITY_SAMPLES) {
|
||||
_gravity = (1.f - 1.f/(float)GRAVITY_SAMPLES) * _gravity +
|
||||
1.f/(float)GRAVITY_SAMPLES * glm::vec3(_lastAccelX, _lastAccelY, _lastAccelZ);
|
||||
|
||||
_averageGyroRates[0] = (1.f - 1.f/(float)GRAVITY_SAMPLES) * _averageGyroRates[0] +
|
||||
1.f/(float)GRAVITY_SAMPLES * _lastRollRate;
|
||||
_averageGyroRates[1] = (1.f - 1.f/(float)GRAVITY_SAMPLES) * _averageGyroRates[1] +
|
||||
1.f/(float)GRAVITY_SAMPLES * _lastYawRate;
|
||||
_averageGyroRates[2] = (1.f - 1.f/(float)GRAVITY_SAMPLES) * _averageGyroRates[2] +
|
||||
1.f/(float)GRAVITY_SAMPLES * _lastPitchRate;
|
||||
}
|
||||
else {
|
||||
// Cumulate long term average to (hopefully) take DC bias out of rotation rates
|
||||
_averageGyroRates[0] = (1.f - 1.f/(float)LONG_TERM_RATE_SAMPLES) * _averageGyroRates[0] +
|
||||
1.f/(float)LONG_TERM_RATE_SAMPLES * _lastRollRate;
|
||||
_averageGyroRates[1] = (1.f - 1.f/(float)LONG_TERM_RATE_SAMPLES) * _averageGyroRates[1] +
|
||||
1.f/(float)LONG_TERM_RATE_SAMPLES * _lastYawRate;
|
||||
_averageGyroRates[2] = (1.f - 1.f/(float)LONG_TERM_RATE_SAMPLES) * _averageGyroRates[2] +
|
||||
1.f/(float)LONG_TERM_RATE_SAMPLES * _lastPitchRate;
|
||||
|
||||
if (totalSamples < GRAVITY_SAMPLES) {
|
||||
_gravity = (1.f - 1.f/(float)GRAVITY_SAMPLES) * _gravity +
|
||||
1.f/(float)GRAVITY_SAMPLES * glm::vec3(_lastAccelX, _lastAccelY, _lastAccelZ);
|
||||
}
|
||||
}
|
||||
|
||||
totalSamples++;
|
||||
|
|
|
@ -38,7 +38,8 @@ class SerialInterface {
|
|||
public:
|
||||
SerialInterface() : active(false),
|
||||
_gravity(0,0,0),
|
||||
_averageGyroRates(0,0,0),
|
||||
_averageGyroRates(0, 0, 0),
|
||||
_estimatedRotation(0, 0, 0),
|
||||
_lastAccelX(0),
|
||||
_lastAccelY(0),
|
||||
_lastAccelZ(0),
|
||||
|
@ -47,7 +48,7 @@ public:
|
|||
_lastRollRate(0) {}
|
||||
|
||||
void pair();
|
||||
void readData();
|
||||
void readData(float deltaTime);
|
||||
|
||||
float getLastYawRate() const { return _lastYawRate - _averageGyroRates[1]; }
|
||||
float getLastPitchRate() const { return _lastPitchRate - _averageGyroRates[2]; }
|
||||
|
@ -68,6 +69,7 @@ private:
|
|||
timeval lastGoodRead;
|
||||
glm::vec3 _gravity;
|
||||
glm::vec3 _averageGyroRates;
|
||||
glm::vec3 _estimatedRotation;
|
||||
float _lastAccelX;
|
||||
float _lastAccelY;
|
||||
float _lastAccelZ;
|
||||
|
|
|
@ -44,7 +44,7 @@ GLubyte identityIndices[] = { 0,2,1, 0,3,2, // Z- .
|
|||
10,11,15, 10,15,14, // Y+
|
||||
4,5,6, 4,6,7 }; // Z+ .
|
||||
|
||||
VoxelSystem::VoxelSystem() {
|
||||
VoxelSystem::VoxelSystem() : AgentData(NULL) {
|
||||
_voxelsInReadArrays = _voxelsInWriteArrays = _voxelsUpdated = 0;
|
||||
_writeRenderFullVBO = true;
|
||||
_readRenderFullVBO = true;
|
||||
|
@ -372,7 +372,10 @@ int VoxelSystem::updateNodeInArraysAsFullVBO(VoxelNode* node) {
|
|||
_writeVoxelDirtyArray[nodeIndex] = true; // just in case we switch to Partial mode
|
||||
_voxelsInWriteArrays++; // our know vertices in the arrays
|
||||
return 1; // rendered
|
||||
}
|
||||
} else {
|
||||
node->setBufferIndex(GLBUFFER_INDEX_UNKNOWN);
|
||||
}
|
||||
|
||||
return 0; // not-rendered
|
||||
}
|
||||
|
||||
|
@ -978,6 +981,7 @@ public:
|
|||
shouldRenderNodes(0),
|
||||
coloredNodes(0),
|
||||
nodesInVBO(0),
|
||||
nodesInVBONotShouldRender(0),
|
||||
nodesInVBOOverExpectedMax(0),
|
||||
duplicateVBOIndex(0),
|
||||
leafNodes(0)
|
||||
|
@ -990,6 +994,7 @@ public:
|
|||
unsigned long shouldRenderNodes;
|
||||
unsigned long coloredNodes;
|
||||
unsigned long nodesInVBO;
|
||||
unsigned long nodesInVBONotShouldRender;
|
||||
unsigned long nodesInVBOOverExpectedMax;
|
||||
unsigned long duplicateVBOIndex;
|
||||
unsigned long leafNodes;
|
||||
|
@ -1032,6 +1037,11 @@ bool VoxelSystem::collectStatsForTreesAndVBOsOperation(VoxelNode* node, void* ex
|
|||
if (nodeIndex > args->expectedMax) {
|
||||
args->nodesInVBOOverExpectedMax++;
|
||||
}
|
||||
|
||||
// if it's in VBO but not-shouldRender, track that also...
|
||||
if (!node->getShouldRender()) {
|
||||
args->nodesInVBONotShouldRender++;
|
||||
}
|
||||
}
|
||||
|
||||
return true; // keep going!
|
||||
|
@ -1060,8 +1070,8 @@ void VoxelSystem::collectStatsForTreesAndVBOs() {
|
|||
printLog("stats: total %ld, leaves %ld, dirty %ld, colored %ld, shouldRender %ld, inVBO %ld\n",
|
||||
args.totalNodes, args.leafNodes, args.dirtyNodes, args.coloredNodes, args.shouldRenderNodes);
|
||||
|
||||
printLog("inVBO %ld, nodesInVBOOverExpectedMax %ld, duplicateVBOIndex %ld\n",
|
||||
args.nodesInVBO, args.nodesInVBOOverExpectedMax, args.duplicateVBOIndex);
|
||||
printLog("inVBO %ld, nodesInVBOOverExpectedMax %ld, duplicateVBOIndex %ld, nodesInVBONotShouldRender %ld\n",
|
||||
args.nodesInVBO, args.nodesInVBOOverExpectedMax, args.duplicateVBOIndex, args.nodesInVBONotShouldRender);
|
||||
|
||||
glBufferIndex minInVBO = GLBUFFER_INDEX_UNKNOWN;
|
||||
glBufferIndex maxInVBO = 0;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "AudioRingBuffer.h"
|
||||
|
||||
AudioRingBuffer::AudioRingBuffer(int ringSamples, int bufferSamples) :
|
||||
AgentData(NULL),
|
||||
_ringBufferLengthSamples(ringSamples),
|
||||
_bufferLengthSamples(bufferSamples),
|
||||
_endOfLastWrite(NULL),
|
||||
|
@ -20,7 +21,7 @@ AudioRingBuffer::AudioRingBuffer(int ringSamples, int bufferSamples) :
|
|||
_shouldBeAddedToMix(false),
|
||||
_shouldLoopbackForAgent(false),
|
||||
_streamIdentifier()
|
||||
{
|
||||
{
|
||||
_buffer = new int16_t[_ringBufferLengthSamples];
|
||||
_nextOutput = _buffer;
|
||||
};
|
||||
|
|
|
@ -31,7 +31,8 @@ int unpackFloatAngleFromTwoByte(uint16_t* byteAnglePointer, float* destinationPo
|
|||
return sizeof(uint16_t);
|
||||
}
|
||||
|
||||
AvatarData::AvatarData() :
|
||||
AvatarData::AvatarData(Agent* owningAgent) :
|
||||
AgentData(owningAgent),
|
||||
_handPosition(0,0,0),
|
||||
_bodyYaw(-90.0),
|
||||
_bodyPitch(0.0),
|
||||
|
@ -67,7 +68,7 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
|
|||
|
||||
// lazily allocate memory for HeadData in case we're not an Avatar instance
|
||||
if (!_headData) {
|
||||
_headData = new HeadData();
|
||||
_headData = new HeadData(this);
|
||||
}
|
||||
|
||||
// Body world position
|
||||
|
@ -148,7 +149,7 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
|
|||
|
||||
// lazily allocate memory for HeadData in case we're not an Avatar instance
|
||||
if (!_headData) {
|
||||
_headData = new HeadData();
|
||||
_headData = new HeadData(this);
|
||||
}
|
||||
|
||||
// increment to push past the packet header
|
||||
|
|
|
@ -22,14 +22,14 @@ const int WANT_DELTA_AT_BIT = 2;
|
|||
|
||||
enum KeyState
|
||||
{
|
||||
NO_KEY_DOWN,
|
||||
NO_KEY_DOWN,
|
||||
INSERT_KEY_DOWN,
|
||||
DELETE_KEY_DOWN
|
||||
};
|
||||
|
||||
class AvatarData : public AgentData {
|
||||
public:
|
||||
AvatarData();
|
||||
AvatarData(Agent* owningAgent = NULL);
|
||||
~AvatarData();
|
||||
|
||||
const glm::vec3& getPosition() const { return _position; }
|
||||
|
|
|
@ -8,13 +8,14 @@
|
|||
|
||||
#include "HeadData.h"
|
||||
|
||||
HeadData::HeadData() :
|
||||
HeadData::HeadData(AvatarData* owningAvatar) :
|
||||
_yaw(0.0f),
|
||||
_pitch(0.0f),
|
||||
_roll(0.0f),
|
||||
_lookAtPosition(0.0f, 0.0f, 0.0f),
|
||||
_leanSideways(0.0f),
|
||||
_leanForward(0.0f)
|
||||
_leanForward(0.0f),
|
||||
_owningAvatar(owningAvatar)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -20,9 +20,11 @@ const float MAX_HEAD_PITCH = 60;
|
|||
const float MIN_HEAD_ROLL = -50;
|
||||
const float MAX_HEAD_ROLL = 50;
|
||||
|
||||
class AvatarData;
|
||||
|
||||
class HeadData {
|
||||
public:
|
||||
HeadData();
|
||||
HeadData(AvatarData* owningAvatar);
|
||||
|
||||
float getLeanSideways() const { return _leanSideways; }
|
||||
void setLeanSideways(float leanSideways) { _leanSideways = leanSideways; }
|
||||
|
@ -55,6 +57,7 @@ protected:
|
|||
glm::vec3 _lookAtPosition;
|
||||
float _leanSideways;
|
||||
float _leanForward;
|
||||
AvatarData* _owningAvatar;
|
||||
private:
|
||||
// privatize copy ctor and assignment operator so copies of this object cannot be made
|
||||
HeadData(const HeadData&);
|
||||
|
|
|
@ -8,4 +8,10 @@
|
|||
|
||||
#include "AgentData.h"
|
||||
|
||||
AgentData::AgentData(Agent* owningAgent) :
|
||||
_owningAgent(owningAgent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AgentData::~AgentData() {}
|
|
@ -3,16 +3,24 @@
|
|||
// hifi
|
||||
//
|
||||
// Created by Stephen Birarda on 2/19/13.
|
||||
//
|
||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef hifi_AgentData_h
|
||||
#define hifi_AgentData_h
|
||||
|
||||
class Agent;
|
||||
|
||||
class AgentData {
|
||||
public:
|
||||
AgentData(Agent* owningAgent);
|
||||
|
||||
virtual ~AgentData() = 0;
|
||||
virtual int parseData(unsigned char* sourceBuffer, int numBytes) = 0;
|
||||
|
||||
Agent* getOwningAgent() { return _owningAgent; }
|
||||
protected:
|
||||
Agent* _owningAgent;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
#include <cstring>
|
||||
#include <cstdio>
|
||||
|
||||
VoxelAgentData::VoxelAgentData() :
|
||||
VoxelAgentData::VoxelAgentData(Agent* owningAgent) :
|
||||
AvatarData(owningAgent),
|
||||
_viewSent(false),
|
||||
_voxelPacketAvailableBytes(MAX_VOXEL_PACKET_SIZE),
|
||||
_maxSearchLevel(1),
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
class VoxelAgentData : public AvatarData {
|
||||
public:
|
||||
VoxelAgentData();
|
||||
VoxelAgentData(Agent* owningAgent);
|
||||
~VoxelAgentData();
|
||||
|
||||
void resetVoxelPacket(); // resets voxel packet to after "V" header
|
||||
|
|
|
@ -45,7 +45,7 @@ const float DEATH_STAR_RADIUS = 4.0;
|
|||
const float MAX_CUBE = 0.05f;
|
||||
|
||||
const int VOXEL_SEND_INTERVAL_USECS = 100 * 1000;
|
||||
int PACKETS_PER_CLIENT_PER_INTERVAL = 50;
|
||||
int PACKETS_PER_CLIENT_PER_INTERVAL = 30;
|
||||
|
||||
const int MAX_VOXEL_TREE_DEPTH_LEVELS = 4;
|
||||
|
||||
|
@ -450,9 +450,9 @@ void *distributeVoxelsToListeners(void *args) {
|
|||
pthread_exit(0);
|
||||
}
|
||||
|
||||
void attachVoxelAgentDataToAgent(Agent *newAgent) {
|
||||
void attachVoxelAgentDataToAgent(Agent* newAgent) {
|
||||
if (newAgent->getLinkedData() == NULL) {
|
||||
newAgent->setLinkedData(new VoxelAgentData());
|
||||
newAgent->setLinkedData(new VoxelAgentData(newAgent));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue