This documentation provides an overview of the classes and their roles, each class plays a crucial role in achieving the interactive and dynamic cloth behavior. Use this documentation as a reference to understand the structure and purpose of each component in the project.
- ClothPainter Class
- Cloth Class
- Point Class
- Constraint Class
- Pointer Class
- Settings
- Inspiration
- License
The ClothPainter
class is responsible for painting the cloth on the canvas.
cloth
: An instance of theCloth
class representing the cloth.showHeatmap
: A boolean value indicating whether to display a heatmap effect.pointMode
: APointMode
enum value representing the point drawing mode.
paint(Canvas canvas, Size size)
: Paints the cloth on the canvas.shouldRepaint(CustomPainter oldDelegate)
: Determines if a repaint is required.
The Cloth
class represents the cloth and is responsible for its creation and simulation.
_points
: A list ofPoint
objects representing the cloth's points.
update()
: Updates the cloth's simulation.draw(Canvas canvas, Paint paint, bool showHeatmap, PointMode pointMode)
: Draws the cloth on the canvas.- Other helper methods to handle cloth simulation.
The Point
class represents a point in the cloth and handles its behavior.
position
: The position of the point.pointer
: An instance of thePointer
class representing user interaction.velocity
: The velocity of the point.pinPosition
: The position at which the point is pinned.
update(double delta)
: Updates the point's position.draw(Canvas canvas, Paint paint, PointMode pointMode)
: Draws the point on the canvas.resolveConstraints()
: Resolves constraints related to the point.- Other methods for point behavior.
The Constraint
class defines a constraint between two points in the cloth.
p1
: The firstPoint
involved in the constraint.p2
: The secondPoint
involved in the constraint.length
: The desired length of the constraint.
resolve()
: Resolves the constraint to maintain the desired length.draw(Canvas canvas, Paint paint, PointMode pointMode)
: Draws the constraint on the canvas.
The Pointer
class represents user interaction with the cloth.
pressed
: A boolean indicating if the pointer is pressed.isActionPressed
: A boolean indicating if the pointer is in an action (e.g., tearing the cloth).position
: The current position of the pointer.previousPosition
: The previous position of the pointer.
The Settings
class defines constants and settings for the cloth simulation.
const double canvasWidth = 800;
const double canvasHeight = 600;
const double clothWidth = 80;
const double clothHeight = 60;
const double gravity = 1200;
const int physicsAccuracy = 3;
const double friction = 0.98;
const double spacing = 5;
const double tearDistance = 50;
const Offset start = Offset(canvasWidth * 0.5 - (clothWidth * spacing) * 0.5, 20);
const double pointerInfluence = 40;
const double pointerCut = 7;
This project is inspired by Tearable Cloth by Dissimulate.
This project is licensed under the MIT License - see the LICENSE file for details.