root/juggler/branches/2.2/modules/gadgeteer/test/main.cpp

Revision 19729, 4.5 kB (checked in by patrick, 2 years ago)

Copyright update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
2  *
3  * VR Juggler is (C) Copyright 1998-2007 by Iowa State University
4  *
5  * Original Authors:
6  *   Allen Bierbaum, Christopher Just,
7  *   Patrick Hartling, Kevin Meinert,
8  *   Carolina Cruz-Neira, Albert Baker
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  *
25  *************** <auto-copyright.pl END do not edit this line> ***************/
26
27
28 // Minimal VPR includes
29 #include <vpr/vpr.h>
30 #include <vpr/System.h>
31 #include <vpr/Util/FileUtils.h>
32
33 // Minimal JCCL includes
34 #include <jccl/Config/ParseUtil.h>
35 #include <jccl/Config/ElementFactory.h>
36 #include <jccl/RTRC/ConfigManager.h>
37
38 // Interfaces to devices
39 #include <gadget/InputManager.h>
40 #include <gadget/Type/PositionInterface.h>
41
42 #include <gmtl/Matrix.h>
43 #include <gmtl/Output.h>
44
45 #include <string>
46
47 using namespace gmtl;
48
49 // Set some default configuration. Based on the initialiser for vrj::Kernel.
50 // Last taken from 2.0alpha4
51
52 void configuration()
53 {
54    // Load in the configuration definitions
55    std::string def_path;
56    if ( ! vpr::System::getenv("JCCL_DEFINITION_PATH", def_path).success() )
57    {
58       def_path = "${VJ_BASE_DIR}/share/vrjuggler/data/definitions";
59       vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
60          << "JCCL_DEFINITION_PATH environment variable not set.\n"
61          << vprDEBUG_FLUSH;
62       vprDEBUG_NEXT(vprDBG_ALL, vprDBG_WARNING_LVL)
63          << "Defaulting to " << def_path << std::endl << vprDEBUG_FLUSH;
64    }
65    jccl::ElementFactory::instance()->loadDefs(def_path);
66    
67    std::string cfg_path;
68
69    // Set the configuration file directory
70    if ( ! vpr::System::getenv("JCCL_CFG_PATH", cfg_path).success() )
71    {
72       if ( vpr::System::getenv("VJ_CFG_PATH", cfg_path).success() )
73       {
74          vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
75             << "JCCL_CFG_PATH environment variable not set.\n"
76             << vprDEBUG_FLUSH;
77          vprDEBUG_NEXT(vprDBG_ALL, vprDBG_WARNING_LVL)
78             << "Using VJ_CFG_PATH instead.\n" << vprDEBUG_FLUSH;
79       }
80       // Neither $JCCL_CFG_PATH nor $VJ_CFG_PATH is set, so use what basically
81       // amounts to a hard-coded default.
82       else
83       {
84          cfg_path = "${VJ_BASE_DIR}/share/vrjuggler/data/configFiles";
85          vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
86             << "Neither JCCL_CFG_PATH nor VJ_CFG_PATH is set.\n"
87             << vprDEBUG_FLUSH;
88          vprDEBUG_NEXT(vprDBG_ALL, vprDBG_WARNING_LVL)
89             << "Defaulting to " << cfg_path << std::endl << vprDEBUG_FLUSH;
90          cfg_path = vpr::replaceEnvVars(cfg_path);
91       }
92       jccl::ParseUtil::setCfgSearchPath(cfg_path);
93    }
94 }
95
96 int main(int argc, char* argv[])
97 {
98
99    // Set some default configuration variables
100    configuration();
101
102    // Load in the configuration file
103    for( int i = 1; i < argc; ++i )
104    {
105       jccl::Configuration cfg;
106       std::cout << "Loading config file: " << argv[i] << std::endl;
107       cfg.load(argv[i]);
108       jccl::ConfigManager::instance()->addConfigurationAdditions(&cfg);
109    }
110  
111    // Create the input manager
112    gadget::InputManager* input_manager = gadget::InputManager::instance();
113
114    // Associate it with the config files
115    jccl::ConfigManager::instance()->addConfigElementHandler(input_manager);
116
117    // Do the configuration
118    while(jccl::ConfigManager::instance()->attemptReconfiguration())
119    {
120       ;
121    }
122
123    // Create the input devices
124    gadget::PositionInterface wand;   
125    gadget::PositionInterface head;   
126
127    wand.init("VJWand");
128    head.init("VJHead");
129
130    Matrix44f wand_matrix;
131    Matrix44f head_matrix;
132
133    while(1)
134    {
135       vpr::System::sleep(1);
136       std::cout << "Updating All Data .. " << std::endl;
137       input_manager->updateAllData();
138
139       wand_matrix = wand->getData();
140       std::cout << "Wand pos: \n" << wand_matrix << std::endl;
141
142       head_matrix = head->getData();
143       std::cout << "Head pos: \n" << head_matrix << std::endl;
144
145    }
146
147    return 0;
148 }
Note: See TracBrowser for help on using the browser.