Unity WebGL Player | Physics

Fullscreen
Physics

I: Requirements Documentation

1.1: Description of the Problem


Name: Cloth Simulation 
Problem Statement: Implement and calculate the various forces that take place in a cloth simulation. 
	
1.2: Input Information

Controls: Mouse and Keyboard 
	W - Enables/Disables Wind Controls GUI Elements 
	S - Enables/Disables Spring Controls GUI Elements 
	G - Enables/Disables Gravity Controls GUI Elements 
	P - Enables/Disables Pause Menu GUI Elements 
	R - Resets Camera 
	Right Mouse Button - Grabs Cloth 
	Left Mouse Button - Move Camera 
	Scroll Wheel - Rotate Camera 
	
1.3: Output Information

The program will display a simulation of what cloth should behave like in the real world we live in.
	
1.4: User Interface

Wind Controls Panel
	Wind Direction Sliders - Determines the direction the force of the wind will be applied in.
	Wind Speed Slider - Determines how hard the wind will be blowing.
Spring Controls Panel
	Spring Stiffness Slider - Adjusts the stiffness of the springs of the cloth. 
Gravity Controls Panel
	Gravity Modifier - Modifies the strength of gravity in the system.
Pause Menu
	Quit - Closes the application(Only if using .exe).
	Reload - Reloads the level.
Cloth Controls Panel
	Cloth Size Slider - Modifies the size the colth will be.
	Gen Cloth Button - Generates the cloth with the new size set by the slider.
	

II: Design Documentation

2.1: System Architecture Description


The program is divided up into 5 classes (SpringDamper.cs, ClothBehavior.cs, AeroDynamics,
GUI.cs and Node.cs).The ClothBehavior class is responsible for handling all calculations for both
the springs and the nodes in the simulation. The GUI handles all of the on screen sliders and HUD
element the user can interact with the adjust the behavior of the cloth.
		
File: Node.cs

	Name: m_Mass(float)
	Description: Hold the value that represents the mass of a node.
	
	Name: m_Velocity(Vector3)
	Description: Holds the value that represents the current velocity the node is moving at.

	Name: m_Acceleration(Vector3)
	Description: Holds the value that represents the current acceleration of the node.

	Name: m_Force(Vector3)
	Description: Hold the values that represents the strength of the force acting on the node.

	Name: locked(bool)
	Description: Boolean value to show if the node is locked at its starting position.
		
File: AeroDynamics.cs

	Name: p1 (Node)
	Description: Reference to the first node the triangle is connected to.

	Name: p2 (Node)
	Description: Reference to the second node the spring is connected to.

	Name: p3 (Node)
	Description: Reference to the third node the spring is connected to.
	
	Name: CreateTriangle(void)
	Arguments: Node, Node, Node	
	Description: Takes the nodes passed in through the arguments and assigns them to the Node variables declared in the class. 

	Name: DrawTriangle(void)
	Arguments: N/A
	Description: Draws lines that connect the three points of the triangle together.
	
File: SpringDamper.cs

	Name: l(float)
	Description: Holds the value used to represent the rest length of the spring.

	Name: p1 (Node)
	Description: Reference to the first node the spring is connected to. 

	Name: p2 (Node)
	Description: Reference to the second node the spring is connected to. 

	Name: MakeSpring(void)
	Arguments: Node, Node, float
	Description: Creates a spring based on the arguments based in when the spring is being created in the Spawn Springs function in Cloth Behavior class

	Name: DrawLines(void)
	Arguments: N/A
	Description: Draws the lines between nodes the spring is connected to
	
File: GUI.cs

	Name: Cloth (ClothBehavior)
	Description: Stores a reference to the cloth so we can adjust the coefficients of the various forces acting on the cloth.

	Name: WindControls(GameObject)
	Description: GameObject that is the parent for all the GUI elements that modify the wind forces.

	Name: VerticalWind(Slider)
	Description: Adjust the wind blowing from north and south.

	Name: HorizontalWind(Slider)
	Description: Adjusts the wind blowing from east and west.

	Name: WindSpeed(Slider)
	Description: Adjusts how strong the wind is blowing in the direction the user specifies with the Vertical and Horizontal wind sliders.

	Name: WindMph(Text)
	Description: Displays how fast the wind is blowing.

	Name: SpringControls(GameObject)
	Description: GameObject that is the parents for all GUI elements that modify the spring forces.

	Name: Stiffness(Slider)
	Description: Adjusts how stiff the springs of the cloth are.

	Name: GravityControls(GameObject)
	Description: GameObject that is the parent for all GUI elements that modify the force of gravity in the simulation.

	Name: Help(GameObject)
	Description: GameObject that is the parent for all GUI elements that provide controls and manage application flow.

	Name: windDirty(bool)
	Description: boolean value that is used to turn the wind GUI elements off.
		
	Name: springDirty(bool)
	Description: boolean value that is used to turn the spring GUI elements off.
	
	Name:gravDirty(bool)
	Description: boolean value that is used to turn the grvity GUI elements off.
		
	Name: helpDirty(bool)
	Description: boolean value that is used to turn the help GUI elements off.

	Name: OnGUI(void)
	Arguments: N/A
	Description: Calls in the following functions Wind(), Spring(), and Gravity().

	Name: Start(void)
	Arguments: N/A
	Description: Turns off all GUI displays and the mouse cursor.

	Name: Update(void)
	Arguments: N/A
	Description: Calls in the DisplaysOn function and checks to see if the mouse cursor should be displayed whether or not other GUI elements are turned on.

	Name: Wind(void)
	Arguments: N/A
	Description: Updates the wind coefficients in the ClothBehavior script based on the values of the all the sliders on the Wind Controls panel.

	Name: Spring(void)
	Arguments: N/A
	Description: Updates the spring coefficients in the ClothBehavior script based on the values of the all the sliders on the Spring Controls panel.
	
	Name: Gravity(void)
	Arguments: N/A
	Description: Updates the gravity coefficients in the ClothBehavior script based on the values of the all the sliders on the Gravity Controls panel.

	Name: Close(void)
	Arguments: N/A
	Description: Closes the application when the exit button is clicked (Only works when ran through exe not on the internet.)

	Name: Reload()
	Arguments: N/A
	Description: Reloads the scene with a fresh cloth for the user to interact with.

	Name:DisplaysOn(void)
	Arguments: N/A
	Description: Turns the displays on or off when the key that is assigned to them is pressed.
	
File: ClothBehavior.cs

	Name: NodePrefab(Node)
	Description: Holds a reference to the node prefab.

	Name: NODES (List)
	Description: List of all the nodes in the simulation.

	Name: SpringsPrefab(SpringDamper)
	Description: Holds a reference to the spring prefab

	Name: SPRINGS(List)
	Description: List of all the springs in the simulation
	Name: AeroPrefab(AeroDynamics)
	Description: Used to reference the prefab associated with the AeroDynamics class

	Name: TRIANGLES(List)
	Description: List of all the triangles in the simulation.

	Name: Height(int)
	Description: Holds the value the represents the height of the cloth.

	Name: Width(int)
	Description: Holds the value the represents the width of the cloth.

	Name: gCoefficient(float)
	Description: Coefficient used to modify the pull of gravity.

	Name: Gravity(Vector3)
	Description: Holds the values used to represent the pull of gravity.

	Name: k(float)
	Description: Coefficient used to adjust the stiffness of the springs in the simulation.


	Name: b(float)
	Description: Coefficient used to adjust the damping factor of the springs in the simulation

	Name: net(bool)
	Description: Check to set the way the nodes spawn in the system, in this case in the shape of a net.

	Name:drape(bool)
	Description: Check to set the way the nodes spawn in the system, in this case in the shape of a drape.


	Name: Start(void)
	Arguments: N/A
	Description: Calls in the SpawnNodes and SpawnSprings functions when the program starts.

	Name: SpawnSpring(void)
	Arguments: N/A
	Description: Spawns all springs in the simulation and links them to nodes that follow a set of case checks.

	Name: SpawnNodes(void)
	Arguments: N/A
	Description: Spawns all the Nodes in the simulation based on the width and height of the cloth
	Name: SpawnTriangles()
	Arguments: N/A
	Description: Spawns in all the triangles in the simulation

	Name: EulerIntergration(void)
	Arguments: Node
	Description: Integrates motion for each node in the simulation. These vectors are only calculated if the node is not locked in place

	Name: CalcSpringForce(void)
	Arguments: SpringDamper
	Description: Calculates the Spring Force of each spring in the simulation

	Name: FixedUpdate(void) 
	Arguments: N/A
	Description: Follows the steps of cloth simulation and repeats them every loop to achieve the look of cloth in a simulation.

	Name: TearCloth(void)
	Arguments: SpringDamper
	Description: Destroys a spring if the two nodes it is connected to spread to far apart from each other.

	Name: CursorMovement(void)
	Arguments: N/A
	Description: Moves the cursor around the screen and allows the user to grab the cloth and pull it around and tear pieces of it off.

	Name: CalcDis(float)
	Arguments: Vector3, Vector3
	Description: Calculates the distance between two vector3 values passed in as arguments