// Geometric Tools, Inc.
// http://www.geometrictools.com
// Copyright (c) 1998-2005.  All Rights Reserved
//
// The Wild Magic Library (WM3) source code is supplied under the terms of
// the license agreement
//     http://www.geometrictools.com/License/WildMagic3License.pdf
// and may not be copied or disclosed except in accordance with the terms
// of that agreement.

#ifndef PHYSICSMODULE_H
#define PHYSICSMODULE_H

#include "Wm3MassSpringSurface.h"

class PhysicsModule : public Wm3::MassSpringSurface3f
{
public:
    // Construction and destruction.
    //
    // Gravity is controlled by the input rkGravity.
    //
    // Mass-spring systems tend to exhibit "stiffness" (in the sense of
    // numerical stability).  To remedy this problem, a small amount of
    // viscous friction is added to the external force.  This term is
    // of the form -fViscosity*velocity where fViscosity > 0.
    //
    // The initial wind force is specified by the caller.  The wind remains
    // in effect throughout the simulation.  To simulate oscillatory behavior
    // locally, random forces are applied at each mass in the direction
    // perpendicular to the plane of the wind and gravity vectors.  The
    // amplitudes are sinusoidal.  The phases are randomly generated.

    PhysicsModule (int iRows, int iCols, float fStep,
        const Wm3::Vector3f& rkGravity, const Wm3::Vector3f& rkWind,
        float fViscosity, float fAmplitude);

    virtual ~PhysicsModule ();

    // Acceleration is due to forces of gravitation, wind, and viscous
    // friction.  The wind forces are randomly generated.
    virtual Wm3::Vector3f ExternalAcceleration (int i, float fTime,
        const Wm3::Vector3f* akPosition, const Wm3::Vector3f* akVelocity);

protected:
    Wm3::Vector3f m_kGravity, m_kWind;
    float m_fViscosity;

    // sinusoidal forces
    float m_fAmplitude;
    float* m_afPhase;
    Wm3::Vector3f m_kDirection;
};

#endif



