Merge pull request #3174 from wdings23/fix_new_avatar_light

Fix new avatar light
This commit is contained in:
Brad Hefta-Gaub 2014-07-16 12:03:21 -07:00
commit 8a1484ce68
6 changed files with 62 additions and 39 deletions

View file

@ -17,7 +17,7 @@ var currentSelection = 0;
var currentNumLights = 1;
var maxNumLights = 2;
var currentNumAvatars = 0;
var avatarHashIDs = [];
var changeDelta = 0.1;
function keyPressEvent(event) {
@ -40,7 +40,7 @@ function keyPressEvent(event) {
print("light selection = " + currentSelection);
}
else if (event.text == "5" ) {
localLightColors[currentSelection].x += 0.01;
localLightColors[currentSelection].x += changeDelta;
if ( localLightColors[currentSelection].x > 1.0) {
localLightColors[currentSelection].x = 0.0;
}
@ -49,7 +49,7 @@ function keyPressEvent(event) {
print("CHANGE RED light " + currentSelection + " color (" + localLightColors[currentSelection].x + ", " + localLightColors[currentSelection].y + ", " + localLightColors[currentSelection].z + " )" );
}
else if (event.text == "6" ) {
localLightColors[currentSelection].y += 0.01;
localLightColors[currentSelection].y += changeDelta;
if ( localLightColors[currentSelection].y > 1.0) {
localLightColors[currentSelection].y = 0.0;
}
@ -58,7 +58,7 @@ function keyPressEvent(event) {
print("CHANGE GREEN light " + currentSelection + " color (" + localLightColors[currentSelection].x + ", " + localLightColors[currentSelection].y + ", " + localLightColors[currentSelection].z + " )" );
}
else if (event.text == "7" ) {
localLightColors[currentSelection].z += 0.01;
localLightColors[currentSelection].z += changeDelta;
if ( localLightColors[currentSelection].z > 1.0) {
localLightColors[currentSelection].z = 0.0;
}
@ -67,7 +67,7 @@ function keyPressEvent(event) {
print("CHANGE BLUE light " + currentSelection + " color (" + localLightColors[currentSelection].x + ", " + localLightColors[currentSelection].y + ", " + localLightColors[currentSelection].z + " )" );
}
else if (event.text == "8" ) {
localLightDirections[currentSelection].x += 0.01;
localLightDirections[currentSelection].x += changeDelta;
if (localLightDirections[currentSelection].x > 1.0) {
localLightDirections[currentSelection].x = -1.0;
}
@ -76,7 +76,7 @@ function keyPressEvent(event) {
print("PLUS X light " + currentSelection + " direction (" + localLightDirections[currentSelection].x + ", " + localLightDirections[currentSelection].y + ", " + localLightDirections[currentSelection].z + " )" );
}
else if (event.text == "9" ) {
localLightDirections[currentSelection].x -= 0.01;
localLightDirections[currentSelection].x -= changeDelta;
if (localLightDirections[currentSelection].x < -1.0) {
localLightDirections[currentSelection].x = 1.0;
}
@ -85,7 +85,7 @@ function keyPressEvent(event) {
print("MINUS X light " + currentSelection + " direction (" + localLightDirections[currentSelection].x + ", " + localLightDirections[currentSelection].y + ", " + localLightDirections[currentSelection].z + " )" );
}
else if (event.text == "0" ) {
localLightDirections[currentSelection].y += 0.01;
localLightDirections[currentSelection].y += changeDelta;
if (localLightDirections[currentSelection].y > 1.0) {
localLightDirections[currentSelection].y = -1.0;
}
@ -94,7 +94,7 @@ function keyPressEvent(event) {
print("PLUS Y light " + currentSelection + " direction (" + localLightDirections[currentSelection].x + ", " + localLightDirections[currentSelection].y + ", " + localLightDirections[currentSelection].z + " )" );
}
else if (event.text == "-" ) {
localLightDirections[currentSelection].y -= 0.01;
localLightDirections[currentSelection].y -= changeDelta;
if (localLightDirections[currentSelection].y < -1.0) {
localLightDirections[currentSelection].y = 1.0;
}
@ -142,23 +142,12 @@ function updateLocalLights()
// new avatars, so add lights
var numAvatars = AvatarManager.getNumAvatars();
if (numAvatars != currentNumAvatars) {
for (var i = 0; i < numAvatars; i++) {
var id = AvatarManager.getAvatarHashKey(i);
var numLights = AvatarManager.getNumLightsInAvatar(i);
// check if avatar has already been registered
var hasRegistered = false;
for (var j = 0; j < numAvatars; j++) {
if (avatarHashIDs[j] == id) {
hasRegistered = true;
break;
}
}
// add new id and set light params
if (!hasRegistered) {
avatarHashIDs.push(id);
// check if new avatar has lights
if (numLights <= 0) {
AvatarManager.addAvatarLocalLight(i);
// set color and direction for new avatar

View file

@ -928,27 +928,34 @@ void Avatar::setShowDisplayName(bool showDisplayName) {
void Avatar::setLocalLightDirection(const glm::vec3& direction, int lightIndex) {
_localLightDirections[lightIndex] = direction;
qDebug( "set light %d direction ( %f, %f, %f )\n", lightIndex, direction.x, direction.y, direction.z );
}
void Avatar::setLocalLightColor(const glm::vec3& color, int lightIndex) {
_localLightColors[lightIndex] = color;
qDebug( "set light %d color ( %f, %f, %f )\n", lightIndex, color.x, color.y, color.z );
}
void Avatar::addLocalLight() {
if (_numLocalLights + 1 <= MAX_LOCAL_LIGHTS) {
++_numLocalLights;
}
qDebug("ADD LOCAL LIGHT (numLocalLights = %d)\n", _numLocalLights);
}
void Avatar::removeLocalLight() {
if (_numLocalLights - 1 >= 0) {
--_numLocalLights;
}
qDebug("REMOVE LOCAL LIGHT (numLocalLights = %d)\n", _numLocalLights);
}
int Avatar::getNumLocalLights() {
return _numLocalLights;
}
glm::vec3 Avatar::getLocalLightDirection(int lightIndex) {
return _localLightDirections[lightIndex];
}
glm::vec3 Avatar::getLocalLightColor(int lightIndex) {
return _localLightColors[lightIndex];
}

View file

@ -162,7 +162,10 @@ public slots:
void setLocalLightDirection(const glm::vec3& direction, int lightIndex);
void setLocalLightColor(const glm::vec3& color, int lightIndex);
void addLocalLight();
void removeLocalLight();
void removeLocalLight();
int getNumLocalLights();
glm::vec3 getLocalLightDirection(int lightIndex);
glm::vec3 getLocalLightColor(int lightIndex);
signals:
void collisionWithAvatar(const QUuid& myUUID, const QUuid& theirUUID, const CollisionInfo& collision);

View file

@ -200,14 +200,17 @@ void AvatarManager::setAvatarLightColor(const glm::vec3& color, int lightIndex,
}
}
int AvatarManager::getNumLightsInAvatar(int avatarIndex) {
int numLights = 0;
Avatar* avatar = getAvatarFromIndex(avatarIndex);
if (avatar) {
numLights = avatar->getNumLocalLights();
}
return numLights;
}
int AvatarManager::getNumAvatars() {
return _avatarHash.count();
}
QString AvatarManager::getAvatarHashKey(int index) {
QString id = ((_avatarHash.keys())[index]).toString();
std::string idString = id.toStdString();
return id;
}

View file

@ -42,8 +42,8 @@ public slots:
void setAvatarLightDirection(const glm::vec3& direction, int lightIndex, int avatarIndex);
void removeAvatarLocalLight(int avatarIndex);
void addAvatarLocalLight(int avatarIndex);
int getNumLightsInAvatar(int avatarIndex);
int getNumAvatars();
QString getAvatarHashKey(int index);
private:
AvatarManager(const AvatarManager& other);

View file

@ -812,5 +812,26 @@ void Stats::display(
drawText(horizontalOffset, verticalOffset, 0.10f, 0.f, 2.f, reflectionsStatus, color);
}
// draw local light stats
int numLocalLights = myAvatar->getNumLocalLights();
verticalOffset = 400;
horizontalOffset = 20;
char buffer[128];
for (int i = 0; i < numLocalLights; i++) {
glm::vec3 lightDirection = myAvatar->getLocalLightDirection(i);
snprintf(buffer, sizeof(buffer), "Light %d direction (%.2f, %.2f, %.2f)", i, lightDirection.x, lightDirection.y, lightDirection.z);
drawText(horizontalOffset, verticalOffset, scale, rotation, font, buffer, color);
verticalOffset += STATS_PELS_PER_LINE;
glm::vec3 lightColor = myAvatar->getLocalLightColor(i);
snprintf(buffer, sizeof(buffer), "Light %d color (%.2f, %.2f, %.2f)", i, lightColor.x, lightColor.y, lightColor.z);
drawText(horizontalOffset, verticalOffset, scale, rotation, font, buffer, color);
verticalOffset += STATS_PELS_PER_LINE;
}
}