Giter Site home page Giter Site logo

brandozhang / jello_cube_simulation Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 51.16 MB

This project simulates a jello cube as a mass-spring system. The jello cube can be influenced by bounding box/inclined plane, external force field, and real-time user drag.

Makefile 0.02% C++ 1.74% C 1.13% OpenEdge ABL 97.11%

jello_cube_simulation's Introduction

Simulating a Jello Cube

Overview

This project simulates a jello cube as a mass-spring system. The jello cube can be influenced by bounding box/inclined plane, external force field, and real-time user drag.

Contacting Bounding Box Real-time Interaction Rotated by Force Field
Contacting Bounding Box Real-time Interaction Rotated by Force Field

Functionalities

Core Accomplishments

  1. Model a cube of jello as a mass-spring system. The jello cube is modeled by 8x8x8 discrete mass point with equal mass, with structure/shear/bend springs connected between them. For each mass point, calculating the Elastic Force according to Hook's Law (F=kx) and Damping Force (F=-kv) as well. Finally, computing the acceleration of every mass point and applying either Euler or RK4 integrator to solve the next move.

  2. Simulate the dynamics of jello in an external force field. For a given external force field with resolution NxNxN (2 <= N <= 30), calculating the effect on the cube with tri-linear interpolation. The points outside external force field will be clamped.

  3. Handle the collision detection and response for the jello cube hitting any of the walls of the bounding box. When a mass point contacts the bounding box, generating a spring with rest length 0 between the collision point on wall and this mass point, then applying resulting Elastic Force and Damping Force to make it bounce off.

Additional Features

  1. Implement inclined plane display and collision detection. To display the inclined plane inside the Axis-Aligned Bounding Box (AABB), the ray-plane intersections are calculated and used as the vertices of section polygon. Since the jello can be initialized on any side of the plane, for collision detection, the program evaluates the side of both current mass point and that of jello center. If these two points are in different side of the plane, the program considers it as a collision and invokes collision response.

  2. Make the animation interactive. Implement a user-friendly UI to apply mouse-control force. Simply using the mouse and left button to select and drag the jello. If the jello is selected, a purple arrow will display, with origin always attached to the animated jello and heading to some point. The force will be applied only when user release the left button. To ease the selection, users are encourage to enable triangle display mode by pressing v first.

  3. Display coordinate. Press c to display x-axis, y-axis, and z-axis with arrows indicating the direction of increment.

  4. Display FPS. Press f to display current window resolution and estimated Frame Per Second (FPS) in console. Notice that this may only work on Windows Executable.

  5. Display translucent jello cube and inclined plane. To make the simulation more fancy, the program can display a translucent jello cube and inclined plane by adjusting alpha channel and enabling blending.

How to run

Both Windows (x86, Win 11) and macOS (x86, 12.6) executable are tested. Executable files (jello.exe or jello) are provided.

On Windows:

.\jello.exe <PATH_TO_WORLD_FILE>

# Example: 
# .\jello.exe .\world\jello.w

On macOS:

./jello <PATH_TO_WORLD_FILE>

# Example:
# ./jello ./world/gravity.w

Acknowledge

The starter code (i.e., API and window) comes from course CSCI 520 Computer Animation and Simulation, taught by Professor Jernej Barbič.

jello_cube_simulation's People

Contributors

brandozhang avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.