Skip to content

Commit

Permalink
+ same code for correction of space position in host and device
Browse files Browse the repository at this point in the history
+ use no delta calculation for updating velocities
  • Loading branch information
chrxh committed Nov 6, 2024
1 parent 76a2d3b commit 92aba36
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 19 deletions.
14 changes: 7 additions & 7 deletions source/EngineGpuKernels/EditKernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ __global__ void cudaUpdateAngleAndAngularVelForSelection(ShallowUpdateSelectionD
data.cellMap.correctPosition(cell->pos);
}

if (updateData.angularVelDelta != 0) {
auto velDelta = relPos;
Math::rotateQuarterClockwise(velDelta);
velDelta = velDelta * updateData.angularVelDelta * Const::DEG_TO_RAD;
cell->vel = cell->vel + velDelta;
if (updateData.angularVel != 0) {
auto newVel = relPos;
Math::rotateQuarterClockwise(newVel);
newVel = newVel * updateData.angularVel * Const::DEG_TO_RAD;
cell->vel = newVel;
}
}
}
Expand Down Expand Up @@ -290,7 +290,7 @@ __global__ void cudaIncrementPosAndVelForSelection(ShallowUpdateSelectionData up
if (isSelected(cell, updateData.considerClusters)) {
cell->pos = cell->pos + float2{updateData.posDeltaX, updateData.posDeltaY};
data.cellMap.correctPosition(cell->pos);
cell->vel = cell->vel + float2{updateData.velDeltaX, updateData.velDeltaY};
cell->vel = float2{updateData.velX, updateData.velY};
}
}

Expand All @@ -300,7 +300,7 @@ __global__ void cudaIncrementPosAndVelForSelection(ShallowUpdateSelectionData up
if (0 != particle->selected) {
particle->absPos = particle->absPos + float2{updateData.posDeltaX, updateData.posDeltaY};
data.particleMap.correctPosition(particle->absPos);
particle->vel = particle->vel + float2{updateData.velDeltaX, updateData.velDeltaY};
particle->vel = float2{updateData.velX, updateData.velY};
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/EngineGpuKernels/EditKernelsLauncher.cu
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ void _EditKernelsLauncher::shallowUpdateSelectedObjects(
} while (1 == copyToHost(_cudaUpdateResult) && --counter > 0); //due to locking not all affecting connections may be removed at first => repeat
}

if (updateData.posDeltaX != 0 || updateData.posDeltaY != 0 || updateData.velDeltaX != 0 || updateData.velDeltaY != 0) {
if (updateData.posDeltaX != 0 || updateData.posDeltaY != 0 || updateData.velX != 0 || updateData.velY != 0) {
KERNEL_CALL(cudaIncrementPosAndVelForSelection, updateData, data);
}
if (updateData.angleDelta != 0 || updateData.angularVelDelta != 0) {
if (updateData.angleDelta != 0 || updateData.angularVel != 0) {
setValueToDevice(_cudaCenter, float2{0, 0});
setValueToDevice(_cudaNumEntities, 0);

Expand Down
6 changes: 3 additions & 3 deletions source/EngineInterface/ShallowUpdateSelectionData.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ struct ShallowUpdateSelectionData
bool considerClusters = true;
float posDeltaX = 0;
float posDeltaY = 0;
float velDeltaX = 0;
float velDeltaY = 0;
float velX = 0;
float velY = 0;
float angleDelta = 0;
float angularVelDelta = 0;
float angularVel = 0;
};
15 changes: 13 additions & 2 deletions source/EngineInterface/SpaceCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,21 @@ void SpaceCalculator::correctDisplacement(RealVector2D& displacement) const
displacement.y = intDisplacement.y + remainder.y;
}

namespace
{
void correctIntPosition(IntVector2D& pos, IntVector2D const& worldSize)
{
pos = {((pos.x % worldSize.x) + worldSize.x) % worldSize.x, ((pos.y % worldSize.y) + worldSize.y) % worldSize.y};
}

}

void SpaceCalculator::correctPosition(RealVector2D& pos) const
{
pos.x = std::fmod(std::fmod(pos.x, _worldSizeFloat.x) + _worldSizeFloat.x, _worldSizeFloat.x);
pos.y = std::fmod(std::fmod(pos.y, _worldSizeFloat.y) + _worldSizeFloat.y, _worldSizeFloat.y);
auto intPart = toIntVector2D(pos);
auto fracPart = RealVector2D{pos.x - toFloat(intPart.x), pos.y - toFloat(intPart.y)};
correctIntPosition(intPart, _worldSize);
pos = {static_cast<float>(intPart.x) + fracPart.x, static_cast<float>(intPart.y) + fracPart.y};
}

RealVector2D SpaceCalculator::getCorrectedPosition(RealVector2D const& pos) const
Expand Down
4 changes: 2 additions & 2 deletions source/Gui/EditorController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ void EditorController::onAccelerateSelectedObjects(RealVector2D const& viewPos,

ShallowUpdateSelectionData updateData;
updateData.considerClusters = true;
updateData.velDeltaX = delta.x / 10;
updateData.velDeltaY = delta.y / 10;
updateData.velX = delta.x / 10;
updateData.velY = delta.y / 10;
_simulationFacade->shallowUpdateSelectedObjects(updateData);
}

Expand Down
6 changes: 3 additions & 3 deletions source/Gui/PatternEditorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ void PatternEditorWindow::processIntern()
if (centerVelX != origCenterVelX || centerVelY != origCenterVelY) {
ShallowUpdateSelectionData updateData;
updateData.considerClusters = EditorModel::get().isRolloutToClusters();
updateData.velDeltaX = centerVelX - origCenterVelX;
updateData.velDeltaY = centerVelY - origCenterVelY;
updateData.velX = centerVelX;
updateData.velY = centerVelY;
_simulationFacade->shallowUpdateSelectedObjects(updateData);
EditorModel::get().update();
}
Expand All @@ -209,7 +209,7 @@ void PatternEditorWindow::processIntern()
if (_angularVel != origAngularVel) {
ShallowUpdateSelectionData updateData;
updateData.considerClusters = EditorModel::get().isRolloutToClusters();
updateData.angularVelDelta = _angularVel - origAngularVel;
updateData.angularVel = _angularVel;
_simulationFacade->shallowUpdateSelectedObjects(updateData);
EditorModel::get().update();
}
Expand Down

0 comments on commit 92aba36

Please sign in to comment.