Debian Codegraph @

examples/deprecated_examples/glut_hybrid_dynamics/MyWindow.cpp

raw symbols SCIP
1 /*
2 * Copyright (c) 2011-2022, The DART development contributors
3 * All rights reserved.
4 *
5 * The list of contributors can be found at:
6 * https://github.com/dartsim/dart/blob/master/LICENSE
7 *
8 * This file is provided under the following "BSD-style" License:
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the following
11 * conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include "MyWindow.hpp"
34
35 //==============================================================================
36 MyWindow::MyWindow() : SimWindow(), mHarnessOn(false) {}
37
38 //==============================================================================
39 MyWindow::~MyWindow() {}
40
41 //==============================================================================
42 void MyWindow::timeStepping()
43 {
44 dart::dynamics::SkeletonPtr skel = mWorld->getSkeleton(1);
45
46 std::size_t index0 = skel->getJoint("j_scapula_left")->getIndexInSkeleton(0);
47 std::size_t index1 = skel->getJoint("j_scapula_right")->getIndexInSkeleton(0);
48 std::size_t index2 = skel->getJoint("j_forearm_left")->getIndexInSkeleton(0);
49 std::size_t index3 = skel->getJoint("j_forearm_right")->getIndexInSkeleton(0);
50
51 std::size_t index6 = skel->getJoint("j_shin_left")->getIndexInSkeleton(0);
52 std::size_t index7 = skel->getJoint("j_shin_right")->getIndexInSkeleton(0);
53
54 skel->setCommand(index0, 1.0 * std::sin(mWorld->getTime() * 4.0));
55 skel->setCommand(index1, -1.0 * std::sin(mWorld->getTime() * 4.0));
56 skel->setCommand(index2, 0.8 * std::sin(mWorld->getTime() * 4.0));
57 skel->setCommand(index3, 0.8 * std::sin(mWorld->getTime() * 4.0));
58
59 skel->setCommand(index6, 0.1 * std::sin(mWorld->getTime() * 2.0));
60 skel->setCommand(index7, 0.1 * std::sin(mWorld->getTime() * 2.0));
61
62 mWorld->step();
63 }
64
65 //==============================================================================
66 void MyWindow::drawWorld() const
67 {
68 glEnable(GL_LIGHTING);
69 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
70
71 SimWindow::drawWorld();
72 }
73
74 //==============================================================================
75 void MyWindow::keyboard(unsigned char _key, int _x, int _y)
76 {
77 switch (_key)
78 {
79 case ' ': // use space key to play or stop the motion
80 mSimulating = !mSimulating;
81 if (mSimulating)
82 mPlay = false;
83 break;
84 case 'p': // playBack
85 mPlay = !mPlay;
86 if (mPlay)
87 mSimulating = false;
88 break;
89 case '[': // step backward
90 if (!mSimulating)
91 {
92 mPlayFrame--;
93 if (mPlayFrame < 0)
94 mPlayFrame = 0;
95 glutPostRedisplay();
96 }
97 break;
98 case ']': // step forwardward
99 if (!mSimulating)
100 {
101 mPlayFrame++;
102 if (mPlayFrame >= mWorld->getRecording()->getNumFrames())
103 mPlayFrame = 0;
104 glutPostRedisplay();
105 }
106 break;
107 case 'v': // show or hide markers
108 mShowMarkers = !mShowMarkers;
109 break;
110 case 'h':
111 mHarnessOn = !mHarnessOn;
112 if (mHarnessOn)
113 {
114 dart::dynamics::Joint* joint
115 = mWorld->getSkeleton(1)->getBodyNode("h_pelvis")->getParentJoint();
116 joint->setActuatorType(dart::dynamics::Joint::LOCKED);
117 std::cout << "The pelvis is locked." << std::endl;
118 }
119 else
120 {
121 dart::dynamics::Joint* joint
122 = mWorld->getSkeleton(1)->getBodyNode("h_pelvis")->getParentJoint();
123 joint->setActuatorType(dart::dynamics::Joint::PASSIVE);
124 std::cout << "The pelvis is unlocked." << std::endl;
125 }
126 break;
127 default:
128 Win3D::keyboard(_key, _x, _y);
129 }
130 glutPostRedisplay();
131 }