Click here to Skip to main content
15,895,084 members
Articles / Mobile Apps / Android

One-Touch Casual 3D Game Based on OpenGL ES 2.0 3D Engine with Lua, Bullet, and Vorbis Support

Rate me:
Please Sign up or sign in to vote.
4.75/5 (7 votes)
8 Nov 2012CPOL5 min read 50.5K   3.3K   18  
Android-x86 native game-engine - without JNI
#ifndef PHYSICSSPRINGCONSTRAINT_H_
#define PHYSICSSPRINGCONSTRAINT_H_

#include "PhysicsGenericConstraint.h"

namespace gameplay
{

/**
 * Represents a generic spring constraint between two
 * rigid bodies (or one rigid body and the world)
 * where the spring strength and damping can be set
 * for all six degrees of freedom.
 */
class PhysicsSpringConstraint : public PhysicsGenericConstraint
{
    friend class PhysicsController;

public:

    /**
     * Sets the angular damping along the constraint's local X axis.
     * 
     * @param damping The angular damping value.
     */
    inline void setAngularDampingX(float damping);

    /**
     * Sets the angular damping along the constraint's local Y axis.
     * 
     * @param damping The angular damping value.
     */
    inline void setAngularDampingY(float damping);

    /**
     * Sets the angular damping along the constraint's local Z axis.
     * 
     * @param damping The angular damping value.
     */
    inline void setAngularDampingZ(float damping);

    /**
     * Sets the angular strength along the constraint's local X axis.
     *
     * Note: setting the strength to a non-zero value enables the
     * spring for angular movement about the X axis (setting to zero disables it).
     * 
     * @param strength The angular strength value.
     */
    inline void setAngularStrengthX(float strength);

    /**
     * Sets the angular strength along the constraint's local Y axis.
     *
     * Note: setting the strength to a non-zero value enables the
     * spring for angular movement about the Y axis (setting to zero disables it).
     * 
     * @param strength The angular strength value.
     */
    inline void setAngularStrengthY(float strength);

    /**
     * Sets the angular strength along the constraint's local Z axis.
     *
     * Note: setting the strength to a non-zero value enables the
     * spring for angular movement about the Z axis (setting to zero disables it).
     * 
     * @param strength The angular strength value.
     */
    inline void setAngularStrengthZ(float strength);

    /**
     * Sets the linear damping along the constraint's local X axis.
     * 
     * @param damping The linear damping value.
     */
    inline void setLinearDampingX(float damping);

    /**
     * Sets the linear damping along the constraint's local Y axis.
     * 
     * @param damping The linear damping value.
     */
    inline void setLinearDampingY(float damping);

    /**
     * Sets the linear damping along the constraint's local Z axis.
     * 
     * @param damping The linear damping value.
     */
    inline void setLinearDampingZ(float damping);

    /**
     * Sets the linear strength along the constraint's local X axis.
     *
     * Note: setting the strength to a non-zero value enables the
     * spring for linear movement along the X axis (setting to zero disables it).
     * 
     * @param strength The linear strength value.
     */
    inline void setLinearStrengthX(float strength);

    /**
     * Sets the linear strength along the constraint's local Y axis.
     *
     * Note: setting the strength to a non-zero value enables the
     * spring for linear movement along the Y axis (setting to zero disables it).
     * 
     * @param strength The linear strength value.
     */
    inline void setLinearStrengthY(float strength);

    /**
     * Sets the linear strength along the constraint's local Z axis.
     *
     * Note: setting the strength to a non-zero value enables the
     * spring for linear movement along the Z axis (setting to zero disables it).
     * 
     * @param strength The linear strength value.
     */
    inline void setLinearStrengthZ(float strength);

private:

    // Represents the different properties that
    // can be set on the spring constraint.
    // 
    // (Note: the values map to the index parameter
    // used in the member functions of the Bullet
    // class btGeneric6DofSpringConstraint.)
    enum SpringProperty
    {
        LINEAR_X = 0,
        LINEAR_Y,
        LINEAR_Z,
        ANGULAR_X,
        ANGULAR_Y,
        ANGULAR_Z
    };

    /**
     * Creates a spring constraint so that the rigid body (or bodies) is
     * (are) constrained using its (their) current world position(s) for
     * the translation offset(s) to the constraint.
     * 
     * @param a The first (possibly only) rigid body to constrain. If this is the only rigid
     *      body specified the constraint applies between it and the global physics world object.
     * @param b The second rigid body to constrain (optional).
     */
    PhysicsSpringConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b);

    /**
     * Creates a spring constraint.
     * 
     * @param a The first (possibly only) rigid body to constrain. If this is the only rigid
     *      body specified the constraint applies between it and the global physics world object.
     * @param rotationOffsetA The rotation offset for the first rigid body 
     *      (in its local space) with respect to the constraint joint.
     * @param translationOffsetA The translation offset for the first rigid body
     *      (in its local space) with respect to the constraint joint.
     * @param b The second rigid body to constrain (optional).
     * @param rotationOffsetB The rotation offset for the second rigid body
     *      (in its local space) with respect to the constraint joint (optional).
     * @param translationOffsetB The translation offset for the second rigid body
     *      (in its local space) with respect to the constraint joint (optional).
     */
    PhysicsSpringConstraint(PhysicsRigidBody* a, const Quaternion& rotationOffsetA, const Vector3& translationOffsetA,
                            PhysicsRigidBody* b, const Quaternion& rotationOffsetB, const Vector3& translationOffsetB);

    /**
     * Destructor.
     */
    ~PhysicsSpringConstraint();

    // Sets the strength for the given angular/linear 
    // X/Y/Z axis combination determined by the given index.
    // 
    // See the Bullet class btGeneric6DofSpringConstraint
    // for more information.
    void setStrength(SpringProperty property, float strength);

    // Sets the damping for the given angular/linear 
    // X/Y/Z axis combination determined by the given index.
    // 
    // See the Bullet class btGeneric6DofSpringConstraint
    // for more information.
    void setDamping(SpringProperty property, float damping);
};

}

#include "PhysicsSpringConstraint.inl"

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions