1 Star 0 Fork 1

upczap/vrpn

forked from ianaxe/vrpn 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
vrpn_ForceDeviceServer.C 19.16 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
// vrpn_ForceDeviceServer.cpp: implementation of the vrpn_ForceDeviceServer
// class.
//
//////////////////////////////////////////////////////////////////////
#include <stdio.h> // for fprintf, stderr, NULL
#include "vrpn_Connection.h" // for vrpn_HANDLERPARAM, etc
#include "vrpn_ForceDeviceServer.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
vrpn_ForceDeviceServer::vrpn_ForceDeviceServer(const char *name,
vrpn_Connection *c)
: vrpn_ForceDevice(name, c)
{
if (register_autodeleted_handler(addObject_message_id,
handle_addObject_message, this,
vrpn_ForceDevice::d_sender_id)) {
fprintf(stderr, "vrpn_Phantom:can't register handler\n");
vrpn_ForceDevice::d_connection = NULL;
}
if (register_autodeleted_handler(addObjectExScene_message_id,
handle_addObjectExScene_message, this,
vrpn_ForceDevice::d_sender_id)) {
fprintf(stderr, "vrpn_Phantom:can't register handler\n");
vrpn_ForceDevice::d_connection = NULL;
}
if (register_autodeleted_handler(setVertex_message_id,
handle_setVertex_message, this,
vrpn_ForceDevice::d_sender_id)) {
fprintf(stderr, "vrpn_Phantom:can't register handler\n");
vrpn_ForceDevice::d_connection = NULL;
}
if (register_autodeleted_handler(setNormal_message_id,
handle_setNormal_message, this,
vrpn_ForceDevice::d_sender_id)) {
fprintf(stderr, "vrpn_Phantom:can't register handler\n");
vrpn_ForceDevice::d_connection = NULL;
}
if (register_autodeleted_handler(setTriangle_message_id,
handle_setTriangle_message, this,
vrpn_ForceDevice::d_sender_id)) {
fprintf(stderr, "vrpn_Phantom:can't register handler\n");
vrpn_ForceDevice::d_connection = NULL;
}
if (register_autodeleted_handler(removeTriangle_message_id,
handle_removeTriangle_message, this,
vrpn_ForceDevice::d_sender_id)) {
fprintf(stderr, "vrpn_Phantom:can't register handler\n");
vrpn_ForceDevice::d_connection = NULL;
}
if (register_autodeleted_handler(updateTrimeshChanges_message_id,
handle_updateTrimeshChanges_message, this,
vrpn_ForceDevice::d_sender_id)) {
fprintf(stderr, "vrpn_Phantom:can't register handler\n");
vrpn_ForceDevice::d_connection = NULL;
}
if (register_autodeleted_handler(transformTrimesh_message_id,
handle_transformTrimesh_message, this,
vrpn_ForceDevice::d_sender_id)) {
fprintf(stderr, "vrpn_Phantom:can't register handler\n");
vrpn_ForceDevice::d_connection = NULL;
}
if (register_autodeleted_handler(setTrimeshType_message_id,
handle_setTrimeshType_message, this,
vrpn_ForceDevice::d_sender_id)) {
fprintf(stderr, "vrpn_Phantom:can't register handler\n");
vrpn_ForceDevice::d_connection = NULL;
}
if (register_autodeleted_handler(setObjectPosition_message_id,
handle_setObjectPosition_message, this,
vrpn_ForceDevice::d_sender_id)) {
fprintf(stderr, "vrpn_Phantom:can't register handler\n");
vrpn_ForceDevice::d_connection = NULL;
}
if (register_autodeleted_handler(setObjectOrientation_message_id,
handle_setObjectOrientation_message, this,
vrpn_ForceDevice::d_sender_id)) {
fprintf(stderr, "vrpn_Phantom:can't register handler\n");
vrpn_ForceDevice::d_connection = NULL;
}
if (register_autodeleted_handler(setObjectScale_message_id,
handle_setObjectScale_message, this,
vrpn_ForceDevice::d_sender_id)) {
fprintf(stderr, "vrpn_Phantom:can't register handler\n");
vrpn_ForceDevice::d_connection = NULL;
}
if (register_autodeleted_handler(removeObject_message_id,
handle_removeObject_message, this,
vrpn_ForceDevice::d_sender_id)) {
fprintf(stderr, "vrpn_Phantom:can't register handler\n");
vrpn_ForceDevice::d_connection = NULL;
}
if (register_autodeleted_handler(moveToParent_message_id,
handle_moveToParent_message, this,
vrpn_ForceDevice::d_sender_id)) {
fprintf(stderr, "vrpn_Phantom:can't register handler\n");
vrpn_ForceDevice::d_connection = NULL;
}
if (register_autodeleted_handler(setHapticOrigin_message_id,
handle_setHapticOrigin_message, this,
vrpn_ForceDevice::d_sender_id)) {
fprintf(stderr, "vrpn_Phantom:can't register handler\n");
vrpn_ForceDevice::d_connection = NULL;
}
if (register_autodeleted_handler(setHapticScale_message_id,
handle_setHapticScale_message, this,
vrpn_ForceDevice::d_sender_id)) {
fprintf(stderr, "vrpn_Phantom:can't register handler\n");
vrpn_ForceDevice::d_connection = NULL;
}
if (register_autodeleted_handler(setSceneOrigin_message_id,
handle_setSceneOrigin_message, this,
vrpn_ForceDevice::d_sender_id)) {
fprintf(stderr, "vrpn_Phantom:can't register handler\n");
vrpn_ForceDevice::d_connection = NULL;
}
if (register_autodeleted_handler(setObjectIsTouchable_message_id,
handle_setObjectIsTouchable_message, this,
vrpn_ForceDevice::d_sender_id)) {
fprintf(stderr, "vrpn_Phantom:can't register handler\n");
vrpn_ForceDevice::d_connection = NULL;
}
if (register_autodeleted_handler(clearTrimesh_message_id,
handle_clearTrimesh_message, this,
vrpn_ForceDevice::d_sender_id)) {
fprintf(stderr, "vrpn_Phantom:can't register handler\n");
vrpn_ForceDevice::d_connection = NULL;
}
}
vrpn_ForceDeviceServer::~vrpn_ForceDeviceServer() {}
int vrpn_ForceDeviceServer::handle_addObject_message(void *userdata,
vrpn_HANDLERPARAM p)
{
vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;
vrpn_int32 objNum, parentNum;
decode_addObject(p.buffer, p.payload_len, &objNum, &parentNum);
#ifdef VRPN_USE_HDAPI
struct timeval now;
vrpn_gettimeofday(&now, NULL);
me->send_text_message("Trimesh not supported under HDAPI", now,
vrpn_TEXT_ERROR);
return 0;
#else
if (me->addObject(objNum, parentNum)) {
return 0;
}
else {
fprintf(stderr, "vrpn_Phantom: error in trimesh::addObject\n");
return -1;
}
#endif
}
int vrpn_ForceDeviceServer::handle_addObjectExScene_message(void *userdata,
vrpn_HANDLERPARAM p)
{
vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;
vrpn_int32 objNum;
decode_addObjectExScene(p.buffer, p.payload_len, &objNum);
#ifdef VRPN_USE_HDAPI
struct timeval now;
vrpn_gettimeofday(&now, NULL);
me->send_text_message("Trimesh not supported under HDAPI", now,
vrpn_TEXT_ERROR);
return 0;
#else
if (me->addObjectExScene(objNum)) {
return 0;
}
else {
fprintf(stderr, "vrpn_Phantom: error in trimesh::addObjectExScene\n");
return -1;
}
#endif
}
int vrpn_ForceDeviceServer::handle_setVertex_message(void *userdata,
vrpn_HANDLERPARAM p)
{
vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;
vrpn_int32 temp;
vrpn_int32 objNum;
int vertNum;
float x, y, z;
decode_vertex(p.buffer, p.payload_len, &objNum, &temp, &x, &y, &z);
vertNum = temp;
#ifdef VRPN_USE_HDAPI
struct timeval now;
vrpn_gettimeofday(&now, NULL);
me->send_text_message("Trimesh not supported under HDAPI", now,
vrpn_TEXT_ERROR);
return 0;
#else
if (me->setVertex(objNum, vertNum, x, y, z)) {
return 0;
}
else {
fprintf(stderr, "vrpn_Phantom: error in trimesh::setVertex\n");
return -1;
}
#endif
}
int vrpn_ForceDeviceServer::handle_setNormal_message(void *userdata,
vrpn_HANDLERPARAM p)
{
vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;
vrpn_int32 temp;
vrpn_int32 objNum;
int normNum;
float x, y, z;
decode_normal(p.buffer, p.payload_len, &objNum, &temp, &x, &y, &z);
normNum = temp;
#ifdef VRPN_USE_HDAPI
struct timeval now;
vrpn_gettimeofday(&now, NULL);
me->send_text_message("Trimesh not supported under HDAPI", now,
vrpn_TEXT_ERROR);
return 0;
#else
if (me->setNormal(objNum, normNum, x, y, z))
return 0;
else {
fprintf(stderr, "vrpn_Phantom: error in trimesh::setNormal\n");
return -1;
}
#endif
}
int vrpn_ForceDeviceServer::handle_setTriangle_message(void *userdata,
vrpn_HANDLERPARAM p)
{
vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;
vrpn_int32 triNum, v0, v1, v2, n0, n1, n2;
vrpn_int32 objNum;
decode_triangle(p.buffer, p.payload_len, &objNum, &triNum, &v0, &v1, &v2,
&n0, &n1, &n2);
#ifdef VRPN_USE_HDAPI
struct timeval now;
vrpn_gettimeofday(&now, NULL);
me->send_text_message("Trimesh not supported under HDAPI", now,
vrpn_TEXT_ERROR);
return 0;
#else
if (me->setTriangle(objNum, triNum, v0, v1, v2, n0, n1, n2))
return 0;
else {
fprintf(stderr, "vrpn_Phantom: error in trimesh::setTriangle\n");
return -1;
}
#endif
}
int vrpn_ForceDeviceServer::handle_removeTriangle_message(void *userdata,
vrpn_HANDLERPARAM p)
{
vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;
vrpn_int32 triNum;
vrpn_int32 objNum;
decode_removeTriangle(p.buffer, p.payload_len, &objNum, &triNum);
#ifdef VRPN_USE_HDAPI
struct timeval now;
vrpn_gettimeofday(&now, NULL);
me->send_text_message("Trimesh not supported under HDAPI", now,
vrpn_TEXT_ERROR);
return 0;
#else
if (me->removeTriangle(objNum, triNum))
return 0;
else {
fprintf(stderr, "vrpn_Phantom: error in trimesh::removeTriangle\n");
return -1;
}
#endif
}
int vrpn_ForceDeviceServer::handle_updateTrimeshChanges_message(
void *userdata, vrpn_HANDLERPARAM p)
{
vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;
float SurfaceKspring, SurfaceKdamping, SurfaceFdynamic, SurfaceFstatic;
vrpn_int32 objNum;
decode_updateTrimeshChanges(p.buffer, p.payload_len, &objNum,
&SurfaceKspring, &SurfaceKdamping,
&SurfaceFdynamic, &SurfaceFstatic);
#ifdef VRPN_USE_HDAPI
struct timeval now;
vrpn_gettimeofday(&now, NULL);
me->send_text_message("Trimesh not supported under HDAPI", now,
vrpn_TEXT_ERROR);
return 0;
#else
me->updateTrimeshChanges(objNum, SurfaceKspring, SurfaceFstatic,
SurfaceFdynamic, SurfaceKdamping);
return 0;
#endif
}
int vrpn_ForceDeviceServer::handle_setTrimeshType_message(void *userdata,
vrpn_HANDLERPARAM p)
{
vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;
vrpn_int32 temp;
vrpn_int32 objNum;
decode_setTrimeshType(p.buffer, p.payload_len, &objNum, &temp);
#ifdef VRPN_USE_HDAPI
struct timeval now;
vrpn_gettimeofday(&now, NULL);
me->send_text_message("Trimesh not supported under HDAPI", now,
vrpn_TEXT_ERROR);
return 0;
#else
me->setTrimeshType(objNum, temp);
return 0;
#endif
}
int vrpn_ForceDeviceServer::handle_clearTrimesh_message(void *userdata,
vrpn_HANDLERPARAM p)
{
vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;
vrpn_int32 objNum;
decode_clearTrimesh(p.buffer, p.payload_len, &objNum);
#ifdef VRPN_USE_HDAPI
struct timeval now;
vrpn_gettimeofday(&now, NULL);
me->send_text_message("Trimesh not supported under HDAPI", now,
vrpn_TEXT_ERROR);
return 0;
#else
me->clearTrimesh(objNum);
return 0;
#endif
}
int vrpn_ForceDeviceServer::handle_transformTrimesh_message(void *userdata,
vrpn_HANDLERPARAM p)
{
vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;
float xformMatrix[16];
vrpn_int32 objNum;
decode_trimeshTransform(p.buffer, p.payload_len, &objNum, xformMatrix);
#ifdef VRPN_USE_HDAPI
struct timeval now;
vrpn_gettimeofday(&now, NULL);
me->send_text_message("Trimesh not supported under HDAPI", now,
vrpn_TEXT_ERROR);
return 0;
#else
me->setTrimeshTransform(objNum, xformMatrix);
return 0;
#endif
}
int vrpn_ForceDeviceServer::handle_setObjectPosition_message(
void *userdata, vrpn_HANDLERPARAM p)
{
vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;
vrpn_int32 objNum;
vrpn_float32 pos[3];
decode_objectPosition(p.buffer, p.payload_len, &objNum, pos);
#ifdef VRPN_USE_HDAPI
struct timeval now;
vrpn_gettimeofday(&now, NULL);
me->send_text_message("Trimesh not supported under HDAPI", now,
vrpn_TEXT_ERROR);
return 0;
#else
me->setObjectPosition(objNum, pos);
return 0;
#endif
}
int vrpn_ForceDeviceServer::handle_setObjectOrientation_message(
void *userdata, vrpn_HANDLERPARAM p)
{
vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;
vrpn_int32 objNum;
vrpn_float32 axis[3];
vrpn_float32 angle;
decode_objectOrientation(p.buffer, p.payload_len, &objNum, axis, &angle);
#ifdef VRPN_USE_HDAPI
struct timeval now;
vrpn_gettimeofday(&now, NULL);
me->send_text_message("Trimesh not supported under HDAPI", now,
vrpn_TEXT_ERROR);
return 0;
#else
me->setObjectOrientation(objNum, axis, angle);
return 0;
#endif
}
int vrpn_ForceDeviceServer::handle_setObjectScale_message(void *userdata,
vrpn_HANDLERPARAM p)
{
vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;
vrpn_float32 scale[3];
vrpn_int32 objNum;
decode_objectScale(p.buffer, p.payload_len, &objNum, scale);
#ifdef VRPN_USE_HDAPI
struct timeval now;
vrpn_gettimeofday(&now, NULL);
me->send_text_message("Trimesh not supported under HDAPI", now,
vrpn_TEXT_ERROR);
return 0;
#else
me->setObjectScale(objNum, scale);
return 0;
#endif
}
int vrpn_ForceDeviceServer::handle_removeObject_message(void *userdata,
vrpn_HANDLERPARAM p)
{
vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;
vrpn_int32 objNum;
decode_removeObject(p.buffer, p.payload_len, &objNum);
#ifdef VRPN_USE_HDAPI
struct timeval now;
vrpn_gettimeofday(&now, NULL);
me->send_text_message("Trimesh not supported under HDAPI", now,
vrpn_TEXT_ERROR);
return 0;
#else
me->removeObject(objNum);
return 0;
#endif
}
int vrpn_ForceDeviceServer::handle_moveToParent_message(void *userdata,
vrpn_HANDLERPARAM p)
{
vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;
vrpn_int32 objNum, parentNum;
decode_moveToParent(p.buffer, p.payload_len, &objNum, &parentNum);
#ifdef VRPN_USE_HDAPI
struct timeval now;
vrpn_gettimeofday(&now, NULL);
me->send_text_message("Trimesh not supported under HDAPI", now,
vrpn_TEXT_ERROR);
return 0;
#else
me->moveToParent(objNum, parentNum);
return 0;
#endif
}
int vrpn_ForceDeviceServer::handle_setHapticOrigin_message(void *userdata,
vrpn_HANDLERPARAM p)
{
vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;
vrpn_float32 pos[3];
vrpn_float32 axis[3], angle;
decode_setHapticOrigin(p.buffer, p.payload_len, pos, axis, &angle);
#ifdef VRPN_USE_HDAPI
struct timeval now;
vrpn_gettimeofday(&now, NULL);
me->send_text_message("Trimesh not supported under HDAPI", now,
vrpn_TEXT_ERROR);
return 0;
#else
me->setHapticOrigin(pos, axis, angle);
return 0;
#endif
}
int vrpn_ForceDeviceServer::handle_setHapticScale_message(void *userdata,
vrpn_HANDLERPARAM p)
{
vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;
vrpn_float32 scale;
decode_setHapticScale(p.buffer, p.payload_len, &scale);
#ifdef VRPN_USE_HDAPI
struct timeval now;
vrpn_gettimeofday(&now, NULL);
me->send_text_message("Trimesh not supported under HDAPI", now,
vrpn_TEXT_ERROR);
return 0;
#else
me->setHapticScale(scale);
return 0;
#endif
}
int vrpn_ForceDeviceServer::handle_setSceneOrigin_message(void *userdata,
vrpn_HANDLERPARAM p)
{
vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;
vrpn_float32 pos[3];
vrpn_float32 axis[3], angle;
decode_setSceneOrigin(p.buffer, p.payload_len, pos, axis, &angle);
#ifdef VRPN_USE_HDAPI
struct timeval now;
vrpn_gettimeofday(&now, NULL);
me->send_text_message("Trimesh not supported under HDAPI", now,
vrpn_TEXT_ERROR);
return 0;
#else
me->setSceneOrigin(pos, axis, angle);
return 0;
#endif
}
int vrpn_ForceDeviceServer::handle_setObjectIsTouchable_message(
void *userdata, vrpn_HANDLERPARAM p)
{
vrpn_ForceDeviceServer *me = (vrpn_ForceDeviceServer *)userdata;
vrpn_bool touch;
vrpn_int32 objNum;
decode_setObjectIsTouchable(p.buffer, p.payload_len, &objNum, &touch);
#ifdef VRPN_USE_HDAPI
struct timeval now;
vrpn_gettimeofday(&now, NULL);
me->send_text_message("Trimesh not supported under HDAPI", now,
vrpn_TEXT_ERROR);
return 0;
#else
me->setObjectIsTouchable(objNum, touch);
return 0;
#endif
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/jari/vrpn.git
[email protected]:jari/vrpn.git
jari
vrpn
vrpn
master

搜索帮助