mirror of
https://github.com/nasa/trick.git
synced 2024-12-18 20:57:55 +00:00
Minor improvement to SIM_billiards
This commit is contained in:
parent
3cd2a1606f
commit
b69475175d
@ -4,7 +4,7 @@ trick.exec_set_software_frame(0.01)
|
||||
trick.itimer_enable()
|
||||
|
||||
trick.exec_set_enable_freeze(True)
|
||||
trick.exec_set_freeze_command(True)
|
||||
# trick.exec_set_freeze_command(True)
|
||||
|
||||
simControlPanel = trick.SimControlPanel()
|
||||
trick.add_external_application(simControlPanel)
|
||||
|
31
trick_sims/SIM_billiards/README.md
Normal file
31
trick_sims/SIM_billiards/README.md
Normal file
@ -0,0 +1,31 @@
|
||||
# Billiards Sim
|
||||
|
||||
Playable simulation of a billiards table. Includes friction, impulse collision handling, and cue forces currently.
|
||||
|
||||
Angular forces on cue ball, user control of parameters, and detailed physics writeup coming soon :)
|
||||
|
||||
|
||||
<br><br>
|
||||
|
||||
# Pool Table Display
|
||||
|
||||
Located in models/graphics/cpp, uses the Libigl library for visualization.
|
||||
|
||||
## Compile
|
||||
|
||||
libigl must be downloaded from Github : https://github.com/libigl/libigl
|
||||
|
||||
Clone it somewhere accessible, like your home directory. It does not need to be compiled.
|
||||
|
||||
libigl depends on Eigen3, which may (or may not) need to be downloaded and installed : https://eigen.tuxfamily.org/index.php?title=Main_Page
|
||||
|
||||
To compile:
|
||||
```
|
||||
cd models/graphics/cpp
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
```
|
||||
|
||||
The provided input files will automatically run and connect to the display.
|
@ -521,132 +521,6 @@ std::vector<int> parseTrickResponseInt(std::vector<std::string> list) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// void launchViewer (igl::opengl::glfw::Viewer *viewer) {
|
||||
// std::cout << "About to launch the viewer" << std::endl;
|
||||
// viewer->launch();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// std::queue<std::string> messageQueue;
|
||||
// std::mutex messageLock;
|
||||
|
||||
// std::mutex renderLock;
|
||||
|
||||
|
||||
// igl::opengl::glfw::imgui::ImGuiMenu* menu;
|
||||
|
||||
// bool mouse_down (igl::opengl::glfw::Viewer& viewer, int button, int modifier) {
|
||||
// mousePressed = true;
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// bool mouse_up (igl::opengl::glfw::Viewer& viewer, int button, int modifier) {
|
||||
// mousePressed = false;
|
||||
// std::string cueRequest = "";
|
||||
// std::string templateString = "dyn.table.applyCueForce(%.3f, %.3f) \n";
|
||||
|
||||
// char buf[128];
|
||||
// sprintf(buf, templateString.c_str(), mouseX, mouseY);
|
||||
// cueRequest += std::string(buf);
|
||||
|
||||
// messageLock.lock();
|
||||
// messageQueue.push(cueRequest);
|
||||
// messageLock.unlock();
|
||||
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// bool mouse_move (igl::opengl::glfw::Viewer& viewer, int mouse_x, int mouse_y) {
|
||||
// Eigen::Vector3f pos(mouse_x, mouse_y, 0);
|
||||
// Eigen::Matrix4f model = viewer.core().view;
|
||||
// Eigen::Vector3f unproj = igl::unproject(pos, model, viewer.core().proj, viewer.core().viewport);
|
||||
// mouseX = unproj[0];
|
||||
// mouseY = -unproj[1];
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// bool pre_draw (igl::opengl::glfw::Viewer& viewer) {
|
||||
|
||||
// std::string reply;
|
||||
// socket >> reply;
|
||||
|
||||
// // std::cout << "Got data: " << reply << std::endl;
|
||||
// std::vector<double> replyData = parseTrickResponse(split(reply, '\t'));
|
||||
// // numBalls = (int)replyData[0];
|
||||
|
||||
// if (replyData.size() <= 1) {
|
||||
// // std::cout << "Received bad reply" << std::endl;
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// table.clearMovingShapes();
|
||||
|
||||
// Eigen::Vector2d cueBallPos(0,0);
|
||||
// int cueBallIndex = 0;
|
||||
|
||||
|
||||
// for (int i = 0; i < numBalls; i++) {
|
||||
// double inPlay = replyData[1+(i*3 + 2)];
|
||||
// if (inPlay == 0) {
|
||||
// continue;
|
||||
// }
|
||||
// std::vector<double> circleData = {replyData[1+(i*3)], replyData[1+(i*3 + 1)], radii[i]};
|
||||
// Eigen::Vector3d circleColor;
|
||||
// if (i == cueBallIndex) {
|
||||
// circleColor = Eigen::Vector3d(1,1,1);
|
||||
// cueBallPos = Eigen::Vector2d(replyData[1+(i*2)], replyData[1+(i*2 + 1)]);
|
||||
// } else {
|
||||
// circleColor = ball_colors[i % ball_colors.size()];
|
||||
|
||||
// }
|
||||
// table.addShape(circleData, circleColor, false, CIRCLE, layer_BALL);
|
||||
// }
|
||||
|
||||
// if (mousePressed) {
|
||||
// // Draw the cue
|
||||
// double cue_width = 0.03;
|
||||
// Eigen::Vector2d cue_end(mouseX, mouseY);
|
||||
// Eigen::Vector2d vec = (cue_end - cueBallPos).normalized();
|
||||
// Eigen::Vector2d off1(-vec(1), vec(0));
|
||||
// Eigen::Vector2d off2(vec(1), -vec(0));
|
||||
// Eigen::Vector2d point1 = cue_end + (off1 * cue_width);
|
||||
// Eigen::Vector2d point2 = cue_end + (off2 * cue_width);
|
||||
// std::vector<double> triangleData = {cueBallPos(0), cueBallPos(1), point1(0), point1(1), point2(0), point2(1)};
|
||||
// table.addShape(triangleData, Eigen::Vector3d(0, 0, 0), false, TRIANGLE, layer_CUE);
|
||||
// }
|
||||
|
||||
// renderLock.lock();
|
||||
// std::tie(V, F, C) = table.getMesh();
|
||||
|
||||
// renderLock.lock();
|
||||
|
||||
// viewer.data().clear();
|
||||
// viewer.core().orthographic = true;
|
||||
// viewer.data().show_lines = false;
|
||||
// viewer.data().set_face_based(false);
|
||||
// viewer.data().double_sided = true;
|
||||
// viewer.core().is_animating = true;
|
||||
// viewer.core().camera_zoom = 2;
|
||||
// viewer.data().set_mesh(V, F);
|
||||
// viewer.data().set_colors(C);
|
||||
|
||||
// renderLock.unlock();
|
||||
// }
|
||||
|
||||
// void draw_viewer_menu () {
|
||||
// ImGui::Text("Menu");
|
||||
// if (ImGui::Button("Reset Cue Ball", ImVec2(-1, 0)))
|
||||
// {
|
||||
// std::string message = "dyn.table.resetCueBall() \n";
|
||||
// messageLock.lock();
|
||||
// messageQueue.push(message);
|
||||
// messageLock.unlock();
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Parse socket number out of argv
|
||||
@ -837,7 +711,6 @@ int main(int argc, char *argv[])
|
||||
plugin->widgets.push_back(menu);
|
||||
|
||||
view->callback_mouse_down = [&](igl::opengl::glfw::Viewer& viewer, int button, int modifier) -> bool {
|
||||
std::cout << "Mouse down" << std::endl;
|
||||
mousePressed = true;
|
||||
return false;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user