Académique Documents
Professionnel Documents
Culture Documents
*/
/*!
/file PhysicsModel.h
/author Team42, Jiawei Gu
/e-mail jiawei.gu@digipen.edu
/date 11/24/2015
/Brief Copyright (C) 2015 DigiPen Institute of Technology. Reproduction or
disclosure of this file or its contents without the prior written consent of
DigiPen Institute of Technology is prohibited.
*/
/* End Header ******************************************************************
*/
#ifndef A_PHYSICS_MODEL
#define A_PHYSICS_MODEL
#include "../Kinematics/KinematicsModel.h"
#include "../Animation/Transform.h"
#include "../UI/EditorUnit.h"
namespace Anime
{
/// <summary>
/// Stick Base. Also used to represent anchor.
/// </summary>
class StickBase
{
protected:
/// <summary>
/// The center of the stick.
/// </summary>
Vector3 center;
/// <summary>
/// The total force of a stick.
/// </summary>
Vector3 netForce;
/// <summary>
/// The total torque of a stick.
/// </summary>
Vector3 netTorque;
/// <summary>
/// The current velocity of a stick.
/// </summary>
Vector3 velocity;
/// <summary>
/// The current angular velocity of a stick.
/// </summary>
Vector3 angularVelocity;
public:
/// <summary>
/// Initialize the stick base.
/// </summary>
/// <param name="center">The center of the stick.</param>
StickBase(const Vector3 & center);
/// <summary>
/// Get the left end of a stick.
/// </summary>
/// <returns>The left end of a stick.</returns>
virtual Vector3 GetLeftEnd();
/// <summary>
/// Get the right end of a stick.
/// </summary>
/// <returns>The right end of a stick.</returns>
virtual Vector3 GetRightEnd();
/// <summary>
/// Get the center of a stick.
/// </summary>
/// <returns>The center of a stick.</returns>
Vector3 GetCenter();
/// <summary>
/// Reset all the force and torque to 0.
/// </summary>
void ResetForce();
/// <summary>
/// Add force to the stick.
/// </summary>
/// <param name="addForce">The addtion force.</param>
void AddForce(const Vector3 & addForce);
/// <summary>
/// Add torque to the stick.
/// </summary>
/// <param name="addTorque">The addtion torque.</param>
void AddTorque(const Vector3 & addTorque);
friend class PhysicsModel;
};
/// <summary>
/// The concrete stick class.
/// </summary>
class Stick: public StickBase
{
private:
/// <summary>
/// The rotation angle.
/// </summary>
Radian rotationAngle;
/// <summary>
/// The rotation axis.
/// </summary>
const Vector3 rotationAxis;
/// <summary>
/// The stick length.
/// </summary>
float * length;
/// <summary>
/// <summary>
/// The right connection of a stick.
/// </summary>
StickBase * rightConnection;
/// <summary>
/// VAO and VBO.
/// </summary>
GLuint VAO, VBO;
/// <summary>
/// The k in Hooke's law.
/// </summary>
float * k;
/// <summary>
/// The length when the spring is not stretched.
/// </summary>
float * normalLength;
public:
/// <summary>
/// Initialize the spring.
/// </summary>
Spring();
/// <summary>
/// Finalize the spring.
/// </summary>
~Spring();
/// <summary>
/// Draw the spring.
/// </summary>
/// <param name="shader">The Shader.</param>
void Draw(Shader & shader);
/// <summary>
/// Calculate the spring force.
/// </summary>
void CalculateForce();
friend class PhysicsModel;
};
/// <summary>
/// The physics model.
/// </summary>
class PhysicsModel
{
private:
/// <summary>
/// The rigid boies which are sticks.
/// </summary>
std::vector<Stick> bodies;
/// <summary>
/// The springs.
/// </summary>
std::vector<Spring> springs;
/// <summary>
/// The start anchor.
/// </summary>
StickBase pinStart;
/// <summary>
/// The end anchor.
/// </summary>
StickBase pinEnd;
/// <summary>
/// VAO and VBO.
/// </summary>
GLuint VAO, VBO;
/// <summary>
/// The gravity.
/// </summary>
Vector3 gravity;
/// <summary>
/// The length of the sticks.
/// </summary>
float stickLength;
/// <summary>
/// The mass of the sticks.
/// </summary>
float stickMass;
/// <summary>
/// The length of the springs.
/// </summary>
float springLength;
/// <summary>
/// The strenth (k) of the springs.
/// </summary>
float springStrength;
/// <summary>
/// The damping.
/// </summary>
float damping;
/// <summary>
/// Flag to use RK4.
/// </summary>
bool useRK4;
public:
/// <summary>
/// Initialize the physics model.
/// </summary>
/// <param name="center">The number of the sticks.</param>
PhysicsModel(int bodyNum = 8);
/// <summary>
<summary>
Recalculate force for RK4.
</summary>
<param name="id">The delta time.</param>
<param name="newPos">The new position.</param>
<param name="newRotAng">The new rotation angle.</param>
<param name="force">The net force at the new position.</para
m>
/// <param name="torque">The net torque at the new position.</pa
ram>
void RecalculateForce(int id, Vector3 newPos, Radian newRotAng,
Vector3 & force, Vector3 & torque);
/// <summary>
/// Set the end anchor.
/// </summary>
/// <param name="newPos">The new position.</param>
void SetPinEnd(const Vector3 & newPos);
/// <summary>
/// Setup the editor for some parameters.
/// </summary>
/// <param name="editor">The editor unit.</param>
void SetupEditor(EditorUnit * editor);
};
}
#endif