⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 FreeWRLduneInputDevice和FreeWRL一起可以让用户用带有6DoF的输入设备检索3D VRML/X3D数据。它基于FreeWRL的"/tmp/inpdev"扩展传感器输入接口和w
💻 CPP
字号:
/* * main.cpp  * Mainprogram of a input device driver for FreeWRL, * Copyright (c) 2003 J. "MUFTI" Scheurich, based on *  * main.cpp of dune/white_dune * * Copyright (C) 1999 Stephen F. White *  * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program (see the file "COPYING" for details); if  * not, write to the Free Software Foundation, Inc., 675 Mass Ave,  * Cambridge, MA 02139, USA. */#include <stdio.h>#include <string.h>#include "FreeWRLinputDeviceApp.h"#include "WriteData.h"#include "miniswt.h"#define errorprintf fprintfextern bool parseCommandlineArgumentInputDevice(int & i,int argc, char** argv);extern FreeWRLinputDeviceApp *TheApp;int main(int argc, char *argv[]){#ifdef HAVE_XINPUT    swInitialize(&argc,argv);#endif    TheApp=new FreeWRLinputDeviceApp();    int i=1;    while (i<argc) {       parseCommandlineArgumentInputDevice(i,argc,argv);       i++;    }    TheApp->accoutMaxNumberAxesInputDevices();    if ((i>argc) || (argc == 1)) {       errorprintf(stderr,             "for usage see \"man %s\"\n",             argv[0]);       return 1;    }    TransformMode* tm = new TransformMode(TM_6D, TM_3D, TM_NEAR_FAR);    if (TheApp->getMaxNumberAxesInputDevices()<6)        tm = new TransformMode(TM_ROCKET, TM_3D, TM_NEAR_FAR);    if (TheApp->getMaxNumberAxesInputDevices()<4)        tm = new TransformMode(TM_HOVER, TM_3D, TM_NEAR_FAR);    // FreeWRL's input mechanism can only handle one viewpoint    // start with the default VRML viewpoint    Vec3f vec(0, 0, 10); // FreeWRL uses z,x,y instead of x,y,z ?    Quaternion oneQuat(0, 0, 0, 1);    Quaternion quat = oneQuat;    writedata(vec.z, vec.x, vec.y, -quat.x, -quat.y, -quat.z, quat.w);    // the following is from Scene3DView::Navigate3D() of white_dune    while (1) {        Quaternion viewrot=quat;        Quaternion newrot = oneQuat;        for (i=0;i<TheApp->getNumberInputDevices();i++)            if (TheApp->getInputDevice(i)->hasReadDelay())                TheApp->getInputDevice(i)->prepareRead();        for (i=0;i<TheApp->getNumberInputDevices();i++) {            InputDevice* inputDevice=TheApp->getInputDevice(i);            if (inputDevice==NULL)                fprintf(stderr,"internal error\n");            if (inputDevice->readInputDevice() && !(inputDevice->allzero())) {                if (tm->hasRotation()) {                    Quaternion inputrot=inputDevice->get_quaternion(tm);                    inputrot.z=-inputrot.z;                    newrot=inputrot*viewrot;                     quat=newrot;                }                if (tm->hasTranslation()) {                    Vec3f v= inputDevice->get_vector(tm);                    Vec3f xyz;                    if ((inputDevice->isTracker()) || (inputDevice->isWand()))                        xyz=newrot.conj()*(viewrot*v);                    else                        xyz=viewrot*v;                    v[0]=xyz.x;                    v[1]=xyz.y;                    v[2]=xyz.z;                    Vec3f vcamera=vec;                    v[0]=v[0]+vcamera.x;                    v[1]=v[1]+vcamera.y;                    v[2]=v[2]+vcamera.z;                    vec=v;                }                 writedata(vec.z, vec.x, vec.y,                           -quat.x, -quat.y, -quat.z, quat.w);            }        }    }    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -