diff --git a/Examples/ObjectControllerDummyClient/CMakeLists.txt b/Examples/ObjectControllerDummyClient/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..743203d45ac5d1739efc3dc2dba8bd4374c9b453 --- /dev/null +++ b/Examples/ObjectControllerDummyClient/CMakeLists.txt @@ -0,0 +1,36 @@ +########################################################################### +# +# Copyright (c) Kitware, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +########################################################################### + +project(Example-ObjectControllerDummyClient) + +#----------------------------------------------------------------------------- +# Create executable +#----------------------------------------------------------------------------- +add_executable(${PROJECT_NAME} ObjectControllerDummyClient.cpp) + +#----------------------------------------------------------------------------- +# Add shaders +#----------------------------------------------------------------------------- +include(imstkCopyAndCompileShaders) +CopyAndCompileShaders() + +#----------------------------------------------------------------------------- +# Link libraries to executable +#----------------------------------------------------------------------------- +target_link_libraries(${PROJECT_NAME} SimulationManager) + diff --git a/Examples/ObjectControllerDummyClient/ObjectControllerDummyClient.cpp b/Examples/ObjectControllerDummyClient/ObjectControllerDummyClient.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3d33e397230811b2a4648f59d6c9510185746b5a --- /dev/null +++ b/Examples/ObjectControllerDummyClient/ObjectControllerDummyClient.cpp @@ -0,0 +1,86 @@ +/*========================================================================= + + Library: iMSTK + + Copyright (c) Kitware, Inc. & Center for Modeling, Simulation, + & Imaging in Medicine, Rensselaer Polytechnic Institute. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0.txt + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +=========================================================================*/ + +#include "imstkSimulationManager.h" +#include "imstkCube.h" +#include "imstkDummyClient.h" +#include "imstkSceneObjectController.h" + +using namespace imstk; + +/// +/// \brief This example demonstrates controlling the object +/// using external device. NOTE: Requires GeoMagic Touch device +/// +int main() +{ + // SDK and Scene + auto sdk = std::make_shared<SimulationManager>(); + auto scene = sdk->createNewScene("ObjectControllerDummyClient"); + + // Device Client + auto client = std::make_shared<DummyClient>("DummyClient"); + + // Object + auto geom = std::make_shared<Cube>(); + geom->setPosition(0, 1, 0); + geom->setWidth(2); + + auto object = std::make_shared<CollidingObject>("VirtualObject"); + object->setVisualGeometry(geom); + object->setCollidingGeometry(geom); + scene->addSceneObject(object); + + auto trackCtrl = std::make_shared<DeviceTracker>(client); + trackCtrl->setTranslationScaling(0.1); + auto controller = std::make_shared<SceneObjectController>(object, trackCtrl); + scene->addObjectController(controller); + + // Supply translation to dummy client frame + auto translateFunc = + [&client](Module* module) + { + Vec3d p = client->getPosition() + Vec3d(1.0e-4, 0, 0); + if (p.x() > 50.) + { + p = Vec3d(0, 0, 0); + } + client->setPosition(p); + }; + sdk->getSceneManager(scene)->setPostUpdateCallback(translateFunc); + + // Update Camera position + auto cam = scene->getCamera(); + cam->setPosition(Vec3d(0, 0, 10)); + cam->setFocalPoint(geom->getPosition()); + + // Light + auto light = std::make_shared<DirectionalLight>("light"); + light->setFocalPoint(Vec3d(5, -8, -5)); + light->setIntensity(1); + scene->addLight(light); + + // Run + sdk->setActiveScene(scene); + sdk->startSimulation(SimulationStatus::RUNNING); + + return 0; +}