mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 19:04:32 +02:00
More chat bits; basic functionality now working.
This commit is contained in:
parent
10a9f31d65
commit
675d06e4b9
7 changed files with 88 additions and 17 deletions
|
@ -51,9 +51,14 @@ void attachAvatarDataToAgent(Agent *newAgent) {
|
|||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
AgentList *agentList = AgentList::createInstance(AGENT_TYPE_AVATAR_MIXER, AVATAR_LISTEN_PORT);
|
||||
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));
|
||||
}
|
||||
setvbuf(stdout, NULL, _IOLBF, 0);
|
||||
|
||||
agentList->linkedDataCreateCallback = attachAvatarDataToAgent;
|
||||
|
|
|
@ -653,6 +653,35 @@ void Avatar::render(bool lookingInMirror) {
|
|||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
if (!_chatMessage.empty()) {
|
||||
float width = 0;
|
||||
for (string::iterator it = _chatMessage.begin(); it != _chatMessage.end(); it++) {
|
||||
width += glutStrokeWidth(GLUT_STROKE_ROMAN, *it)*0.0005;
|
||||
}
|
||||
glPushMatrix();
|
||||
|
||||
// extract the view direction from the modelview matrix: transform (0, 0, 1) by the
|
||||
// transpose of the modelview to get its direction in world space, then use the X/Z
|
||||
// components to determine the angle
|
||||
float modelview[16];
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, modelview);
|
||||
|
||||
glTranslatef(_position.x, _position.y + 0.7, _position.z);
|
||||
glRotatef(atan2(-modelview[2], -modelview[10]) * 180 / PI, 0, 1, 0);
|
||||
glTranslatef(width * 0.5, 0, 0);
|
||||
|
||||
// TODO: For no apparent reason, OpenGL is hiding the first character. This fixes it (it
|
||||
// gets hidden instead), but we should find and fix the underlying problem.
|
||||
glBegin(GL_LINE_STRIP);
|
||||
glVertex2f(0, 0);
|
||||
glVertex2f(0, 0);
|
||||
glEnd();
|
||||
|
||||
drawtext(0, 0, 0.0005, 180, 1.0, 0, _chatMessage.c_str(), 1, 1, 1);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,6 +12,13 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
const int MAX_CONTENT_LENGTH = 140;
|
||||
|
||||
void ChatEntry::clear () {
|
||||
contents.clear();
|
||||
cursorPos = 0;
|
||||
}
|
||||
|
||||
bool ChatEntry::key(unsigned char k) {
|
||||
switch (k) {
|
||||
case '\r':
|
||||
|
@ -25,8 +32,10 @@ bool ChatEntry::key(unsigned char k) {
|
|||
return true;
|
||||
|
||||
default:
|
||||
contents.insert(cursorPos, 1, k);
|
||||
cursorPos++;
|
||||
if (contents.size() != MAX_CONTENT_LENGTH) {
|
||||
contents.insert(cursorPos, 1, k);
|
||||
cursorPos++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ public:
|
|||
|
||||
const std::string& getContents () const { return contents; }
|
||||
|
||||
void clear ();
|
||||
|
||||
bool key(unsigned char k);
|
||||
|
||||
void specialKey(unsigned char k);
|
||||
|
|
|
@ -1373,8 +1373,9 @@ void keyUp(unsigned char k, int x, int y) {
|
|||
void key(unsigned char k, int x, int y)
|
||||
{
|
||||
if (::chatEntryOn) {
|
||||
if (!chatEntry.key()) {
|
||||
|
||||
if (!chatEntry.key(k)) {
|
||||
myAvatar.setChatMessage(chatEntry.getContents());
|
||||
chatEntry.clear();
|
||||
::chatEntryOn = false;
|
||||
}
|
||||
return;
|
||||
|
@ -1656,7 +1657,12 @@ int main(int argc, const char * argv[])
|
|||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
AgentList::createInstance(AGENT_TYPE_AVATAR);
|
||||
unsigned int listenPort = AGENT_SOCKET_LISTEN_PORT;
|
||||
const char* portStr = getCmdOption(argc, argv, "--listenPort");
|
||||
if (portStr) {
|
||||
listenPort = atoi(portStr);
|
||||
}
|
||||
AgentList::createInstance(AGENT_TYPE_AVATAR, listenPort);
|
||||
|
||||
gettimeofday(&applicationStartupTime, NULL);
|
||||
const char* domainIP = getCmdOption(argc, argv, "--domain");
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "AvatarData.h"
|
||||
#include "avatars_Log.h"
|
||||
|
||||
using namespace std;
|
||||
using avatars_lib::printLog;
|
||||
|
||||
|
||||
|
@ -112,10 +113,14 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
|
|||
memcpy(destinationBuffer, &_cameraFarClip, sizeof(_cameraFarClip));
|
||||
destinationBuffer += sizeof(_cameraFarClip);
|
||||
|
||||
// Key State
|
||||
memcpy(destinationBuffer, &_keyState, sizeof(char));
|
||||
destinationBuffer += sizeof(char);
|
||||
// key state
|
||||
*destinationBuffer++ = _keyState;
|
||||
|
||||
// chat message
|
||||
*destinationBuffer++ = _chatMessage.size();
|
||||
memcpy(destinationBuffer, _chatMessage.data(), _chatMessage.size() * sizeof(char));
|
||||
destinationBuffer += _chatMessage.size() * sizeof(char);
|
||||
|
||||
return destinationBuffer - bufferStart;
|
||||
}
|
||||
|
||||
|
@ -171,9 +176,13 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
|
|||
memcpy(&_cameraFarClip, sourceBuffer, sizeof(_cameraFarClip));
|
||||
sourceBuffer += sizeof(_cameraFarClip);
|
||||
|
||||
// Key State
|
||||
memcpy(&_keyState, sourceBuffer, sizeof(char));
|
||||
sourceBuffer += sizeof(char);
|
||||
// key state
|
||||
_keyState = (KeyState)*sourceBuffer++;
|
||||
|
||||
// the rest is a chat message
|
||||
int chatMessageSize = *sourceBuffer++;
|
||||
_chatMessage = string((char*)sourceBuffer, chatMessageSize);
|
||||
sourceBuffer += chatMessageSize * sizeof(char);
|
||||
|
||||
return sourceBuffer - startPosition;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
#ifndef __hifi__AvatarData__
|
||||
#define __hifi__AvatarData__
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <AgentData.h>
|
||||
|
@ -74,9 +76,15 @@ public:
|
|||
void setCameraNearClip(float nearClip) { _cameraNearClip = nearClip; }
|
||||
void setCameraFarClip(float farClip) { _cameraFarClip = farClip; }
|
||||
|
||||
// Key state
|
||||
void setKeyState(char s) { _keyState = s; }
|
||||
char keyState() const { return _keyState; }
|
||||
enum KeyState { NoKey, KeyDown, KeyUp, DeleteKey };
|
||||
|
||||
// key state
|
||||
void setKeyState(KeyState s) { _keyState = s; }
|
||||
KeyState keyState() const { return _keyState; }
|
||||
|
||||
// chat message
|
||||
void setChatMessage(const std::string& msg) { _chatMessage = msg; }
|
||||
const std::string& chatMessage () const { return _chatMessage; }
|
||||
|
||||
protected:
|
||||
glm::vec3 _position;
|
||||
|
@ -110,8 +118,11 @@ protected:
|
|||
float _cameraNearClip;
|
||||
float _cameraFarClip;
|
||||
|
||||
// Key state (nothing, down, up, backspace)
|
||||
char _keyState;
|
||||
// key state (nothing, down, up, backspace)
|
||||
KeyState _keyState;
|
||||
|
||||
// chat message
|
||||
std::string _chatMessage;
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__AvatarData__) */
|
||||
|
|
Loading…
Reference in a new issue