mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-08-16 15:50:55 +02:00
Added PaintMode, toggle for stars, etc.
This commit is contained in:
parent
66a2b1a86f
commit
f859d8ed9c
5 changed files with 124 additions and 8 deletions
|
@ -142,6 +142,8 @@ float renderPitchRate = 0.f;
|
|||
glm::vec3 start_location(6.1f, 0, 1.4f);
|
||||
|
||||
int stats_on = 0; // Whether to show onscreen text overlay with stats
|
||||
bool starsOn = true; // Whether to display the stars
|
||||
bool paintOn = false; // Whether to paint voxels as you fly around
|
||||
|
||||
int noise_on = 0; // Whether to add random noise
|
||||
float noise = 1.0; // Overall magnitude scaling for random noise levels
|
||||
|
@ -250,11 +252,14 @@ void display_stats(void)
|
|||
// bitmap chars are about 10 pels high
|
||||
char legend[] = "/ - toggle this display, Q - exit, H - show head, M - show hand, T - test audio";
|
||||
drawtext(10, 15, 0.10f, 0, 1.0, 0, legend);
|
||||
|
||||
char legend2[] = "* - toggle stars, & - toggle paint mode";
|
||||
drawtext(10, 32, 0.10f, 0, 1.0, 0, legend2);
|
||||
|
||||
char stats[200];
|
||||
sprintf(stats, "FPS = %3.0f Pkts/s = %d Bytes/s = %d ",
|
||||
FPS, packets_per_second, bytes_per_second);
|
||||
drawtext(10, 30, 0.10f, 0, 1.0, 0, stats);
|
||||
drawtext(10, 49, 0.10f, 0, 1.0, 0, stats);
|
||||
if (serialPort.active) {
|
||||
sprintf(stats, "ADC samples = %d, LED = %d",
|
||||
serialPort.getNumSamples(), serialPort.getLED());
|
||||
|
@ -485,6 +490,34 @@ void simulateHead(float frametime)
|
|||
char broadcast_string[MAX_BROADCAST_STRING];
|
||||
int broadcast_bytes = myHead.getBroadcastData(broadcast_string);
|
||||
agentList.broadcastToAgents(broadcast_string, broadcast_bytes,AgentList::AGENTS_OF_TYPE_VOXEL_AND_INTERFACE);
|
||||
|
||||
// If I'm in paint mode, send a voxel out to VOXEL server agents.
|
||||
if (::paintOn) {
|
||||
|
||||
glm::vec3 headPos = myHead.getPos();
|
||||
|
||||
VoxelDetail paintingVoxel;
|
||||
paintingVoxel.x = headPos.z/10.0; // voxel space x is positive z head space
|
||||
paintingVoxel.y = headPos.y/-10.0; // voxel space y is negative y head space
|
||||
paintingVoxel.z = headPos.x/-10.0; // voxel space z is negative x head space
|
||||
paintingVoxel.s = 1.0/256;
|
||||
paintingVoxel.red = 0;
|
||||
paintingVoxel.green = 255;
|
||||
paintingVoxel.blue = 0;
|
||||
|
||||
unsigned char* bufferOut;
|
||||
int sizeOut;
|
||||
|
||||
if (paintingVoxel.x >= 0.0 && paintingVoxel.x <= 1.0 &&
|
||||
paintingVoxel.y >= 0.0 && paintingVoxel.y <= 1.0 &&
|
||||
paintingVoxel.z >= 0.0 && paintingVoxel.z <= 1.0) {
|
||||
|
||||
if (createVoxelEditMessage('I',0,1,&paintingVoxel,bufferOut,sizeOut)){
|
||||
agentList.broadcastToAgents((char*)bufferOut, sizeOut,AgentList::AGENTS_OF_TYPE_VOXEL);
|
||||
delete bufferOut;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int render_test_spot = WIDTH/2;
|
||||
|
@ -531,7 +564,9 @@ void display(void)
|
|||
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
stars.render(fov);
|
||||
if (::starsOn) {
|
||||
stars.render(fov);
|
||||
}
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
|
@ -642,6 +677,10 @@ void display(void)
|
|||
sprintf(agents, "Agents nearby: %ld\n", agentList.getAgents().size());
|
||||
drawtext(WIDTH-200,20, 0.10, 0, 1.0, 0, agents, 1, 1, 0);
|
||||
|
||||
if (::paintOn) {
|
||||
drawtext(WIDTH-200,40, 0.10, 0, 1.0, 0, "Paint ON", 1, 1, 0);
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
|
||||
|
@ -753,8 +792,9 @@ void key(unsigned char k, int x, int y)
|
|||
|
||||
// Process keypresses
|
||||
if (k == 'q') ::terminate();
|
||||
|
||||
if (k == '/') stats_on = !stats_on; // toggle stats
|
||||
if (k == '*') ::starsOn = !::starsOn; // toggle stars
|
||||
if (k == '&') ::paintOn = !::paintOn; // toggle paint
|
||||
if (k == 'n')
|
||||
{
|
||||
noise_on = !noise_on; // Toggle noise
|
||||
|
@ -810,11 +850,7 @@ void key(unsigned char k, int x, int y)
|
|||
}
|
||||
|
||||
// press the . key to get a new random sphere of voxels added
|
||||
if (k == '.')
|
||||
{
|
||||
addRandomSphere(wantColorRandomizer);
|
||||
//testPointToVoxel();
|
||||
}
|
||||
if (k == '.') addRandomSphere(wantColorRandomizer);
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -212,6 +212,7 @@ bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket,
|
|||
|
||||
const char* AgentList::AGENTS_OF_TYPE_HEAD = "H";
|
||||
const char* AgentList::AGENTS_OF_TYPE_VOXEL_AND_INTERFACE = "VI";
|
||||
const char* AgentList::AGENTS_OF_TYPE_VOXEL = "V";
|
||||
|
||||
void AgentList::broadcastToAgents(char *broadcastData, size_t dataBytes,const char* agentTypes) {
|
||||
for(std::vector<Agent>::iterator agent = agents.begin(); agent != agents.end(); agent++) {
|
||||
|
|
|
@ -69,6 +69,7 @@ public:
|
|||
|
||||
static const char* AGENTS_OF_TYPE_HEAD;
|
||||
static const char* AGENTS_OF_TYPE_VOXEL_AND_INTERFACE;
|
||||
static const char* AGENTS_OF_TYPE_VOXEL;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include "SharedUtil.h"
|
||||
#include "OctalCode.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
@ -124,6 +125,70 @@ bool cmdOptionExists(int argc, const char * argv[],const char* option) {
|
|||
return false;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Function: createVoxelEditMessage()
|
||||
// Description: creates an "insert" or "remove" voxel message for a voxel code
|
||||
// corresponding to the closest voxel which encloses a cube with
|
||||
// lower corners at x,y,z, having side of length S.
|
||||
// The input values x,y,z range 0.0 <= v < 1.0
|
||||
// message should be either 'I' for insert or 'R' for remove
|
||||
//
|
||||
// IMPORTANT: The buffer is returned to you a buffer which you MUST delete when you are
|
||||
// done with it.
|
||||
//
|
||||
// HACK ATTACK: Well, what if this is larger than the MTU? That's the caller's problem, we
|
||||
// just truncate the message
|
||||
// Usage:
|
||||
// unsigned char* voxelData = pointToVoxel(x,y,z,s,red,green,blue);
|
||||
// tree->readCodeColorBufferToTree(voxelData);
|
||||
// delete voxelData;
|
||||
//
|
||||
// Complaints: Brad :)
|
||||
#define GUESS_OF_VOXELCODE_SIZE 10
|
||||
#define MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE 1500
|
||||
#define SIZE_OF_COLOR_DATA 3
|
||||
bool createVoxelEditMessage(unsigned char command, short int sequence,
|
||||
int voxelCount, VoxelDetail* voxelDetails, unsigned char*& bufferOut, int& sizeOut) {
|
||||
|
||||
bool success = true; // assume the best
|
||||
int messageSize = MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE; // just a guess for now
|
||||
int actualMessageSize = 3;
|
||||
unsigned char* messageBuffer = new unsigned char[messageSize];
|
||||
unsigned short int* sequenceAt = (unsigned short int*)&messageBuffer[1];
|
||||
|
||||
messageBuffer[0]=command;
|
||||
*sequenceAt=sequence;
|
||||
unsigned char* copyAt = &messageBuffer[3];
|
||||
|
||||
for (int i=0;i<voxelCount && success;i++) {
|
||||
// get the coded voxel
|
||||
unsigned char* voxelData = pointToVoxel(voxelDetails[i].x,voxelDetails[i].y,voxelDetails[i].z,
|
||||
voxelDetails[i].s,voxelDetails[i].red,voxelDetails[i].green,voxelDetails[i].blue);
|
||||
|
||||
int lengthOfVoxelData = bytesRequiredForCodeLength(*voxelData)+SIZE_OF_COLOR_DATA;
|
||||
|
||||
// make sure we have room to copy this voxel
|
||||
if (actualMessageSize+lengthOfVoxelData > MAXIMUM_EDIT_VOXEL_MESSAGE_SIZE) {
|
||||
success=false;
|
||||
} else {
|
||||
// add it to our message
|
||||
memcpy(copyAt,voxelData,lengthOfVoxelData);
|
||||
copyAt+=lengthOfVoxelData+SIZE_OF_COLOR_DATA;
|
||||
actualMessageSize+=lengthOfVoxelData+SIZE_OF_COLOR_DATA;
|
||||
}
|
||||
// cleanup
|
||||
delete voxelData;
|
||||
}
|
||||
|
||||
if (success) {
|
||||
// finally, copy the result to the output
|
||||
bufferOut = new unsigned char[actualMessageSize];
|
||||
sizeOut=actualMessageSize;
|
||||
memcpy(bufferOut,messageBuffer,actualMessageSize);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Function: pointToVoxel()
|
||||
// Description: Given a universal point with location x,y,z this will return the voxel
|
||||
|
|
|
@ -35,6 +35,19 @@ void switchToResourcesIfRequired();
|
|||
|
||||
const char* getCmdOption(int argc, const char * argv[],const char* option);
|
||||
bool cmdOptionExists(int argc, const char * argv[],const char* option);
|
||||
|
||||
struct VoxelDetail {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float s;
|
||||
unsigned char red;
|
||||
unsigned char green;
|
||||
unsigned char blue;
|
||||
};
|
||||
|
||||
unsigned char* pointToVoxel(float x, float y, float z, float s, unsigned char r, unsigned char g, unsigned char b );
|
||||
bool createVoxelEditMessage(unsigned char command, short int sequence,
|
||||
int voxelCount, VoxelDetail* voxelDetails, unsigned char*& bufferOut, int& sizeOut);
|
||||
|
||||
#endif /* defined(__hifi__SharedUtil__) */
|
||||
|
|
Loading…
Reference in a new issue