From 1fcf787991f6caa782c6c6244ece347017a8c3ed Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 29 May 2013 15:42:29 -0700 Subject: [PATCH] dance floor --- animation-server/src/main.cpp | 108 +++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 1 deletion(-) diff --git a/animation-server/src/main.cpp b/animation-server/src/main.cpp index a26b1a4674..1922864632 100644 --- a/animation-server/src/main.cpp +++ b/animation-server/src/main.cpp @@ -33,6 +33,7 @@ bool includeBillboard = true; bool includeBorderTracer = true; bool includeMovingBug = true; bool includeBlinkingVoxel = false; +bool includeDanceFloor = true; const int ANIMATION_LISTEN_PORT = 40107; @@ -392,6 +393,105 @@ static void sendBlinkingStringOfLights() { } } +bool danceFloorInitialized = false; +const float DANCE_FLOOR_LIGHT_SIZE = 1.0f / TREE_SCALE; // approximately 1 meter +const int DANCE_FLOOR_LENGTH = 10; +const int DANCE_FLOOR_WIDTH = 10; +//const int DANCE_FLOOR_HEIGHT = 10; +glm::vec3 danceFloorPosition(100.0f / TREE_SCALE, 30.0f / TREE_SCALE, 10.0f / TREE_SCALE); //(1.0f - (DANCE_FLOOR_WIDTH * DANCE_FLOOR_LIGHT_SIZE), 0, 0); +glm::vec3 danceFloorLights[DANCE_FLOOR_LENGTH][DANCE_FLOOR_WIDTH]; +unsigned char danceFloorOffColor[3] = { 240, 240, 240 }; +unsigned char danceFloorOnColorA[3] = { 0, 0, 255 }; +unsigned char danceFloorOnColorB[3] = { 0, 255, 0 }; +float danceFloorGradient = 0.5f; +float danceFloorGradientIncrement = 0.01f; +const float DANCE_FLOOR_MAX_GRADIENT = 1.0f; +const float DANCE_FLOOR_MIN_GRADIENT = 0.0f; +const int DANCE_FLOOR_VOXELS_PER_PACKET = 100; +const int PACKETS_PER_DANCE_FLOOR = DANCE_FLOOR_VOXELS_PER_PACKET / (DANCE_FLOOR_WIDTH * DANCE_FLOOR_LENGTH); +bool danceFloorColors[DANCE_FLOOR_WIDTH][DANCE_FLOOR_LENGTH] = { + { 0,1,0,1,0,1,0,1,0,1 }, + { 1,0,1,0,1,0,1,0,1,0 }, + { 0,1,0,1,0,1,0,1,0,1 }, + { 1,0,1,0,1,0,1,0,1,0 }, + { 0,1,0,1,0,1,0,1,0,1 }, + { 1,0,1,0,1,0,1,0,1,0 }, + { 0,1,0,1,0,1,0,1,0,1 }, + { 1,0,1,0,1,0,1,0,1,0 }, + { 0,1,0,1,0,1,0,1,0,1 }, + { 1,0,1,0,1,0,1,0,1,0 }, +}; + + +void sendDanceFloor() { + PACKET_HEADER message = PACKET_HEADER_SET_VOXEL_DESTRUCTIVE; // we're a bully! + float lightScale = DANCE_FLOOR_LIGHT_SIZE; + static VoxelDetail details[DANCE_FLOOR_VOXELS_PER_PACKET]; + unsigned char* bufferOut; + int sizeOut; + + // first initialized the billboard of lights if needed... + if (!danceFloorInitialized) { + for (int i = 0; i < DANCE_FLOOR_WIDTH; i++) { + for (int j = 0; j < DANCE_FLOOR_LENGTH; j++) { + danceFloorLights[i][j] = danceFloorPosition + glm::vec3(i * DANCE_FLOOR_LIGHT_SIZE, 0, j * DANCE_FLOOR_LIGHT_SIZE); + } + } + danceFloorInitialized = true; + } + + ::danceFloorGradient += ::danceFloorGradientIncrement; + + if (::danceFloorGradient >= DANCE_FLOOR_MAX_GRADIENT) { + ::danceFloorGradient = DANCE_FLOOR_MAX_GRADIENT; + ::danceFloorGradientIncrement = -::danceFloorGradientIncrement; + } + if (::danceFloorGradient <= DANCE_FLOOR_MIN_GRADIENT) { + ::danceFloorGradient = DANCE_FLOOR_MIN_GRADIENT; + ::danceFloorGradientIncrement = -::danceFloorGradientIncrement; + } + + for (int i = 0; i < DANCE_FLOOR_LENGTH; i++) { + for (int j = 0; j < DANCE_FLOOR_WIDTH; j++) { + + int nthVoxel = ((i * DANCE_FLOOR_WIDTH) + j); + int item = nthVoxel % DANCE_FLOOR_VOXELS_PER_PACKET; + + danceFloorLights[i][j] = danceFloorPosition + glm::vec3(i * DANCE_FLOOR_LIGHT_SIZE, 0, j * DANCE_FLOOR_LIGHT_SIZE); + + //printf("danceFloorLights[%d][%d] = %f,%f,%f\n",i,j, danceFloorLights[i][j].x, danceFloorLights[i][j].y, danceFloorLights[i][j].z); + + + details[item].s = lightScale; + details[item].x = danceFloorLights[i][j].x; + details[item].y = danceFloorLights[i][j].y; + details[item].z = danceFloorLights[i][j].z; + + if (danceFloorColors[i][j]) { + details[item].red = (danceFloorOnColorA[0] + ((danceFloorOnColorB[0] - danceFloorOnColorA[0]) * ::danceFloorGradient)); + details[item].green = (danceFloorOnColorA[1] + ((danceFloorOnColorB[1] - danceFloorOnColorA[1]) * ::danceFloorGradient)); + details[item].blue = (danceFloorOnColorA[2] + ((danceFloorOnColorB[2] - danceFloorOnColorA[2]) * ::danceFloorGradient)); + } else { + details[item].red = danceFloorOffColor[0]; + details[item].green = danceFloorOffColor[1]; + details[item].blue = danceFloorOffColor[2]; + } + + if (item == DANCE_FLOOR_VOXELS_PER_PACKET - 1) { + if (createVoxelEditMessage(message, 0, DANCE_FLOOR_VOXELS_PER_PACKET, (VoxelDetail*)&details, bufferOut, sizeOut)){ + ::packetsSent++; + ::bytesSent += sizeOut; + if (::shouldShowPacketsPerSecond) { + printf("sending packet of size=%d\n", sizeOut); + } + AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1); + delete[] bufferOut; + } + } + } + } +} + bool billboardInitialized = false; const int BILLBOARD_HEIGHT = 9; const int BILLBOARD_WIDTH = 45; @@ -405,7 +505,7 @@ float billboardGradientIncrement = 0.01f; const float BILLBOARD_MAX_GRADIENT = 1.0f; const float BILLBOARD_MIN_GRADIENT = 0.0f; const float BILLBOARD_LIGHT_SIZE = 0.125f / TREE_SCALE; // approximately 1/8 meter per light -const int VOXELS_PER_PACKET = 135; +const int VOXELS_PER_PACKET = 100; const int PACKETS_PER_BILLBOARD = VOXELS_PER_PACKET / (BILLBOARD_HEIGHT * BILLBOARD_WIDTH); @@ -514,6 +614,9 @@ void* animateVoxels(void* args) { if (::includeBlinkingVoxel) { sendVoxelBlinkMessage(); } + if (::includeDanceFloor) { + sendDanceFloor(); + } double end = usecTimestampNow(); double elapsedSeconds = (end - ::start) / 1000000.0; @@ -555,6 +658,9 @@ int main(int argc, const char * argv[]) const char* INCLUDE_BLINKING_VOXEL = "--includeBlinkingVoxel"; ::includeBlinkingVoxel = cmdOptionExists(argc, argv, INCLUDE_BLINKING_VOXEL); + const char* NO_DANCE_FLOOR = "--NoDanceFloor"; + ::includeDanceFloor = !cmdOptionExists(argc, argv, NO_DANCE_FLOOR); + // Handle Local Domain testing with the --local command line const char* showPPS = "--showPPS"; ::shouldShowPacketsPerSecond = cmdOptionExists(argc, argv, showPPS);