Skip to content

Commit d0fba82

Browse files
committed
fix elevator buttons on landings
renumber correctly
1 parent 2947e2f commit d0fba82

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

src/OpenCOVER/plugins/hlrs/Revit/Elevators.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ int ElevatorPart::hit(vrui::vruiHit *hit)
7171
else if (buttons->wasReleased(vruiButtons::ACTION_BUTTON))
7272
{
7373
// left Button was released
74-
elevator->cabin->goTo(levelNumber);
74+
if (buttonLanding)
75+
{
76+
elevator->cabin->goTo(buttonLanding->levelNumber);
77+
}
78+
else
79+
{
80+
elevator->cabin->goTo(levelNumber);
81+
}
7582
}
7683

7784
return vrui::coAction::Result::ACTION_DONE;
@@ -216,7 +223,7 @@ bool ElevatorPart::update(osg::Vec3& viewerPosition)
216223
v = 0;
217224
}
218225
osg::Matrix newTrans = transformNode->getMatrix();
219-
newTrans.setTrans(initialTranslation + osg::Vec3(0, 0, carPos));
226+
newTrans.setTrans(initialTranslation + osg::Vec3(0, 0, carPos - heightOffset));
220227
transformNode->setMatrix(newTrans);
221228
}
222229
else // we are there
@@ -251,7 +258,7 @@ bool ElevatorPart::update(osg::Vec3& viewerPosition)
251258
float doorPos = direction * doorFraction * openingDistance * (doorNumber+1);
252259

253260
osg::Matrix newTrans = transformNode->getMatrix();
254-
newTrans.setTrans(initialTranslation + osg::Vec3(doorPos, 0, 0));
261+
newTrans.setTrans(initialTranslation + osg::Vec3(doorPos, 0, -heightOffset));
255262
transformNode->setMatrix(newTrans);
256263
}
257264
else // we are there
@@ -280,7 +287,7 @@ bool ElevatorPart::update(osg::Vec3& viewerPosition)
280287
float doorPos = direction * doorFraction * openingDistance * (doorNumber + 1);
281288

282289
osg::Matrix newTrans = transformNode->getMatrix();
283-
newTrans.setTrans(initialTranslation + osg::Vec3(doorPos, 0, 0));
290+
newTrans.setTrans(initialTranslation + osg::Vec3(doorPos, 0, -heightOffset));
284291
transformNode->setMatrix(newTrans);
285292
}
286293
else // we are there
@@ -378,7 +385,7 @@ void Elevator::addPart(const std::string &familyName, const std::string &subType
378385
{
379386
ep->type = ElevatorPart::Cabin;
380387
cabin = ep;
381-
cabin->destinationY = cabin->carPos = cabin->elevation; // car is on this elevation
388+
cabin->destinationY = cabin->carPos = cabin->heightOffset = cabin->elevation; // car is on this elevation
382389

383390
int levelNumber = 0;
384391
for (const auto &landingPart : landings)
@@ -441,6 +448,12 @@ void Elevator::addPart(const std::string &familyName, const std::string &subType
441448
std::sort(landings.begin(), landings.end(),
442449
[](ElevatorPart *const &a, ElevatorPart *const &b)
443450
{ return a->elevation < b->elevation; });
451+
int levelNumber = 0;
452+
for (const auto &landingPart : landings)
453+
{
454+
landingPart->levelNumber = levelNumber;
455+
levelNumber++;
456+
}
444457
// update cabin level numbers
445458
if (cabin)
446459
{

src/OpenCOVER/plugins/hlrs/Revit/Elevators.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class ElevatorPart: public vrui::coAction
5656
PartType type = PartUdefined;
5757
std::vector<ElevatorPart *> doors;
5858
int levelNumber;
59-
ElevatorPart *buttonLanding; // landing this button is for.
59+
ElevatorPart *buttonLanding=nullptr; // landing this button is for.
6060
int doorNumber;
6161
int direction = 1;
6262
virtual int hit(vrui::vruiHit *hit);
@@ -70,6 +70,7 @@ class ElevatorPart: public vrui::coAction
7070
CabinState oldTravelDirection = MoveUp;
7171
int currentLanding=0;
7272
float carPos = 0;
73+
float heightOffset = 0;
7374
float destinationY = 0;
7475
float startingY = 0;
7576
float v = 0;

0 commit comments

Comments
 (0)