Skip to content

Commit

Permalink
restore drag in rotational motion, object mass distributed through pa… (
Browse files Browse the repository at this point in the history
#111)

* restore drag in rotational motion, object mass distributed through particles

mesh.lua correctly placing mesh points for concave polygons
  • Loading branch information
Jerboa-app authored Nov 24, 2023
1 parent ae58812 commit fb7114d
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 181 deletions.
36 changes: 21 additions & 15 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ DEMO=0
ANDROID_NDK=""
BENCHMARK=0
STANDALONE=0
CLEAN=1

while [[ $# -gt 0 ]]; do
case $1 in
Expand Down Expand Up @@ -109,6 +110,10 @@ while [[ $# -gt 0 ]]; do
BENCHMARK=1
shift
;;
-c|--continue)
CLEAN=0
shift
;;
-*|--*)
echo "Unknown option $1"
exit 1
Expand All @@ -120,24 +125,22 @@ while [[ $# -gt 0 ]]; do
esac
done

for file in build CMakeFiles cmake_install.cmake CMakeCache.txt Makefile Jerboa
do
if [ -d $file ];
then
rm -rf $file
fi
if [ -f $file ];
if [[ $CLEAN -eq 1 ]];
then
if [ -d build ];
then
rm $file
rm -rf build
fi
done
cmake -E make_directory build
fi

echo "release ${RELEASE}"

if [[ $WINDOWS -eq 0 ]];
then
cmake -E make_directory build
cmake -E chdir build cmake .. -D WINDOWS=ON -D STANDALONE=$STANDALONE -D BUILD_DEMOS=$DEMO -D RELEASE=$RELEASE -D BENCHMARK=$BENCHMARK -D TEST_SUITE=$TEST -D SYNTAX_ONLY=$SYNTAX -D SANITISE=$SANITISE -D CMAKE_TOOLCHAIN_FILE=./windows.cmake && make -j 8 -C build
cd build
cmake .. -D WINDOWS=ON -D STANDALONE=$STANDALONE -D BUILD_DEMOS=$DEMO -D RELEASE=$RELEASE -D BENCHMARK=$BENCHMARK -D TEST_SUITE=$TEST -D SYNTAX_ONLY=$SYNTAX -D SANITISE=$SANITISE -D CMAKE_TOOLCHAIN_FILE=./windows.cmake && make -j 8
cd ..
# now copy dlls
PREFIX="x86_64-w64-mingw32"

Expand Down Expand Up @@ -179,10 +182,12 @@ then
cp demo/desktop/include/SFML-2.5.1-mingw64/bin/sfml-window-d-2.dll build/
cp demo/desktop/include/SFML-2.5.1-mingw64/bin/sfml-graphics-d-2.dll build/
fi
cd ..
elif [[ $OSX -eq 0 ]];
then
cmake -E make_directory build
cmake -E chdir build cmake .. -D OSX=ON -D STANDALONE=$STANDALONE -D BUILD_DEMOS=$DEMO -D RELEASE=$RELEASE -D BENCHMARK=$BENCHMARK -D TEST_SUITE=$TEST -D SYNTAX_ONLY=$SYNTAX -D SANITISE=$SANITISE -D CMAKE_TOOLCHAIN_FILE=./osx.cmake && make -j 8 -C build
cd build
cmake .. -D OSX=ON -D STANDALONE=$STANDALONE -D BUILD_DEMOS=$DEMO -D RELEASE=$RELEASE -D BENCHMARK=$BENCHMARK -D TEST_SUITE=$TEST -D SYNTAX_ONLY=$SYNTAX -D SANITISE=$SANITISE -D CMAKE_TOOLCHAIN_FILE=./osx.cmake && make -j 8
cd ..
elif [[ ! -z "$ANDROID_NDK" ]]
then
TOOL_CHAIN="$ANDROID_NDK/build/cmake/android.toolchain.cmake"
Expand All @@ -200,8 +205,9 @@ then
buildAndroid x86_64

else
cmake -E make_directory build
cmake -E chdir build cmake -D BUILD_DEMOS=$DEMO -D STANDALONE=$STANDALONE -D RELEASE=$RELEASE -D BENCHMARK=$BENCHMARK -D TEST_SUITE=$TEST -D SANITISE=$SANITISE -D SYNTAX_ONLY=$SYNTAX .. && make -j 8 -C build
cd build
cmake -D BUILD_DEMOS=$DEMO -D STANDALONE=$STANDALONE -D RELEASE=$RELEASE -D BENCHMARK=$BENCHMARK -D TEST_SUITE=$TEST -D SANITISE=$SANITISE -D SYNTAX_ONLY=$SYNTAX .. && make -j 8
cd ..
fi


Expand Down
2 changes: 1 addition & 1 deletion config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ config =
{
["timeStep"] = 1.0/1800.0,
["subSample"] = 2,
["cofr"] = 0.75
["cofr"] = 0.75
}

hop.configure(config);
4 changes: 2 additions & 2 deletions include/Debug/collisionMeshDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ namespace Hop::Debugging
"texCoord = pos;\n"
"parameters.xy = rot * a_parameters.xy;\n"
"parameters.zw = rot * a_parameters.zw;\n"
"oColour = vec4(0.0,0.0,1.0,1.0);\n"
"oColour = vec4(200.0/255.0,200.0/255.0,250.0/255.0,1.0);\n"
"th = a_thickness;\n"
"}";

Expand All @@ -173,7 +173,7 @@ namespace Hop::Debugging
"q = mat2(d.x,-d.y,d.y,d.x)*q;\n"
"q = abs(q)-vec2(l*0.5,th);\n"
"float sd = length(max(q,0.0)) + min(max(q.x,q.y),0.0);"
"float alpha = 0.1;"
"float alpha = 1.0;"
"if (sd <= 0.0) { colour = vec4(oColour.rgb,0.5); }"
//"if (sd <= 0.1){ alpha = 1.0-smoothstep(0.0,0.1,sd); colour = vec4(oColour.rgb,alpha); }"
"else { colour = vec4(oColour.rgb,alpha); }"
Expand Down
2 changes: 1 addition & 1 deletion src/Collision/collisionMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace Hop::System::Physics
}
}

return m;
return m * (1.0/float(size()));
}

std::ostream & operator<<(std::ostream & o, Rectangle const & r)
Expand Down
56 changes: 6 additions & 50 deletions src/System/sPhysics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,11 @@ namespace Hop::System::Physics
void sPhysics::update(EntityComponentSystem * m, ThreadPool * workers)
{

// if (workers != nullptr)
// {
// updateThreaded(m, workers);
// return;
// }

ComponentArray<cCollideable> & collideables = m->getComponentArray<cCollideable>();
ComponentArray<cPhysics> & physics = m->getComponentArray<cPhysics>();
ComponentArray<cTransform> & transforms = m->getComponentArray<cTransform>();

double nx, ny, ntheta, at, bt, ct, sticktion, r, dx, dy, d;
double nx, ny, ntheta, at, bt, ct, sticktion, r, dx, dy, d, ar, br, cr;

double DT_OVER_TWICE_MASS = dt / (2.0*PARTICLE_MASS);

Expand All @@ -184,23 +178,13 @@ namespace Hop::System::Physics
bt = 1.0/(1.0+ct);
at = (1.0-ct)*bt;

if (collideables.hasComponent(*it))
{
cCollideable & data = collideables.get(*it);
r = data.mesh.getRadius();
dataP.tau -= dataP.phi * 50.0 * r*r;
}

sticktion = std::sqrt(dataP.fx*dataP.fx+dataP.fy*dataP.fy);

if (sticktion > 0.0){

nx = 2.0*bt*dataT.x - at*dataP.lastX + bt*dataP.fx*dtdt/PARTICLE_MASS;
ny = 2.0*bt*dataT.y - at*dataP.lastY + bt*dataP.fy*dtdt/PARTICLE_MASS;

// nx = 2.0*dataT.x - dataP.lastX + dataP.fx*dtdt / PARTICLE_MASS;
// ny = 2.0*dataT.y - dataP.lastY + dataP.fy*dtdt / PARTICLE_MASS;

if (r > 0)
{
dx = nx - dataT.x;
Expand Down Expand Up @@ -234,18 +218,11 @@ namespace Hop::System::Physics

dataP.omega += dataP.tau;

// cr = dt * dataP.rotationalDrag / (2.0*dataP.momentOfInertia);
// br = 1.0/(1.0+cr);
// ar = (1.0-cr)*br;

// std::cout << dataP.omega << "\n";
// if (sticktion < 9.81){
// dataP.omega *= std::min((dataP.omega * dataP.omega), 1.0);
// }

ntheta = 2.0*dataT.theta - dataP.lastTheta + dtdt*dataP.omega/dataP.momentOfInertia;
cr = dt * dataP.rotationalDrag / (2.0*dataP.momentOfInertia);
br = 1.0/(1.0+cr);
ar = (1.0-cr)*br;

// ntheta = 2.0*br*dataT.theta-ar*dataP.lastTheta+br*dataP.omega*dtdt/dataP.momentOfInertia;
ntheta = 2.0*br*dataT.theta-ar*dataP.lastTheta+br*dataP.omega*dtdt/dataP.momentOfInertia;

dataP.phi = (ntheta-dataP.lastTheta)/(2.0*dt);

Expand Down Expand Up @@ -294,28 +271,7 @@ namespace Hop::System::Physics

dataP.fx += fx;
dataP.fy += fy;

// if (m->hasComponent<cCollideable>(it->id))
// {
// cCollideable & dataC = m->getComponent<cCollideable>(it->id);

// for (unsigned i = 0; i < dataC.mesh.size(); i++)
// {
// std::shared_ptr<CollisionPrimitive> p = dataC.mesh[i];
// Rectangle * r = dynamic_cast<Rectangle*>(p.get());

// if (r == nullptr)
// {
// dataP.fx += fx;
// dataP.fy += fy;
// }
// else
// {
// dataP.fx += fx;
// dataP.fy += fy;
// }
// }
// }

}

}
Expand Down
58 changes: 1 addition & 57 deletions tests/DEM.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,7 @@ D_vertices =
{0.08, -0.5}
}

E_vertices =
{
{0.1, -0.5},
{-0.5, -0.5},
{-0.5, 0.5},
{0.25, 0.5},
{},
{-0.5, 0.0},
{0.25, 0.0},
{}
}

M_vertices =
{
{-0.5, -0.5},
{-0.5, 0.5},
{0.0, 0.0},
{0.5, 0.5},
{0.5, -0.5},
{}
}

E_mesh = createMesh(E_vertices, 0.1)
-- table.remove(E_mesh, 1)
D_mesh = createMesh(D_vertices, 0.1)
M_mesh = createMesh(M_vertices, 0.1)

s = 6.8*hop.maxCollisionPrimitiveSize()

Expand All @@ -57,7 +32,7 @@ for i = 1, 8 do
o = {

["transform"] = {x,y,0.0,s},
-- ["colour"] = {200/255,200/255,250/255,1.0},
["colour"] = {200/255,200/255,250/255,1.0},
-- ["shader"] = "circleObjectShader",
-- ["shader"] = "lineSegmentObjectShader",
["moveable"] = true,
Expand All @@ -68,35 +43,4 @@ for i = 1, 8 do

hop.loadObject(o)

x = x + s

o = {

["transform"] = {x,y,0.0,s},
-- ["colour"] = {200/255,200/255,250/255,1.0},
-- ["shader"] = "circleObjectShader",
-- ["shader"] = "lineSegmentObjectShader",
["moveable"] = true,
["collisionMesh"] = E_mesh,
["name"] = ""

}

hop.loadObject(o)

x = x + s*0.75

o = {

["transform"] = {x,y,0.0,s},
-- ["colour"] = {200/255,200/255,250/255,1.0},
-- ["shader"] = "circleObjectShader",
-- ["shader"] = "lineSegmentObjectShader",
["moveable"] = true,
["collisionMesh"] = M_mesh,
["name"] = ""

}

hop.loadObject(o)
end
Loading

0 comments on commit fb7114d

Please sign in to comment.