Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Protected Attributes | Private Attributes
Moveable Class Reference

#include <moveable.hpp>

Inheritance diagram for Moveable:
Inheritance graph
[legend]
Collaboration diagram for Moveable:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Moveable (bool bHasHistory=false)
virtual ~Moveable ()
ssgTransform * getModelTransform ()
virtual const btVector3getVelocity () const
const btVector3getVelocityLC () const
virtual void setVelocity (const btVector3 &v)
sgCoord * getCoord ()
const btVector3 getPos () const
const sgCoord * getCoord () const
const sgVec4 * getNormalHOT () const
void setCoord (sgCoord *pos)
virtual void placeModel ()
virtual void handleZipper ()
virtual void reset ()
virtual void update (float dt)
void WriteHistory (char *s, int kartNumber, int indx)
void ReadHistory (char *s, int kartNumber, int indx)
btRigidBodygetBody () const
void createBody (float mass, btTransform &trans, btCollisionShape *shape)
const btTransformgetTrans () const
void setTrans (btTransform &t)

Protected Attributes

UserPointer m_user_pointer
sgCoord m_reset_pos
sgCoord m_curr_pos
sgVec4 * m_normal_hot
Materialm_material_hot
ssgTransform * m_model_transform
ssgTransform * m_shadow
int m_collided
int m_crashed
sgVec3 m_surface_avoidance_vector
int m_first_time
sgCoord * m_history_velocity
sgCoord * m_history_position
btRigidBodym_body
btDefaultMotionStatem_motion_state
btTransform m_transform

Private Attributes

btVector3 m_velocityLC

Detailed Description

Definition at line 35 of file moveable.hpp.


Constructor & Destructor Documentation

Moveable::Moveable ( bool  bHasHistory = false)

Definition at line 28 of file moveable.cpp.

{
    m_body            = 0;
    m_motion_state    = 0;
    m_shadow          = 0;
    m_first_time      = true ;
    m_model_transform = new ssgTransform();

    m_model_transform->ref();

    sgZeroVec3 ( m_reset_pos.xyz ) ; sgZeroVec3 ( m_reset_pos.hpr ) ;

    reset ();
    if(bHasHistory)
    {
        m_history_velocity = new sgCoord[history->GetSize()];
        m_history_position = new sgCoord[history->GetSize()];
    }
    else
    {
        m_history_velocity = NULL;
        m_history_position = NULL;
    }
}   // Moveable

Here is the call graph for this function:

Moveable::~Moveable ( ) [virtual]

Definition at line 54 of file moveable.cpp.

{
    // The body is being removed from the world in kart/projectile
    if(m_body)         delete m_body;
    if(m_motion_state) delete m_motion_state;
    if(m_history_velocity)
    {
        delete [] m_history_velocity;
        delete [] m_history_position;
    }
    // FIXME what about model?
}   // ~Moveable

Member Function Documentation

void Moveable::createBody ( float  mass,
btTransform trans,
btCollisionShape shape 
)

Definition at line 80 of file moveable.cpp.

                                                   {
    
    btVector3 inertia;
    shape->calculateLocalInertia(mass, inertia);
    m_motion_state = new btDefaultMotionState(trans);

    btRigidBody::btRigidBodyConstructionInfo info(mass, m_motion_state, shape, inertia);
    info.m_restitution=0.5f;

    // Then create a rigid body
    // ------------------------
    m_body = new btRigidBody(info);
    // The value of user_pointer must be set from the actual class, otherwise this
    // is only a pointer to moveable, not to (say) kart, and virtual 
    // functions are not called correctly. So only init the pointer to zero.
    m_user_pointer.zero();
    m_body->setUserPointer(&m_user_pointer);
}   // createBody

Here is the call graph for this function:

Here is the caller graph for this function:

btRigidBody* Moveable::getBody ( ) const [inline]

Definition at line 77 of file moveable.hpp.

{return m_body; }

Here is the caller graph for this function:

sgCoord* Moveable::getCoord ( ) [inline]

Definition at line 66 of file moveable.hpp.

{return &m_curr_pos;                }

Here is the caller graph for this function:

const sgCoord* Moveable::getCoord ( ) const [inline]

Definition at line 68 of file moveable.hpp.

{return &m_curr_pos;                }
ssgTransform* Moveable::getModelTransform ( ) [inline]

Definition at line 62 of file moveable.hpp.

{return m_model_transform;          }

Here is the caller graph for this function:

const sgVec4* Moveable::getNormalHOT ( ) const [inline]

Definition at line 69 of file moveable.hpp.

{return m_normal_hot;               }
const btVector3 Moveable::getPos ( ) const [inline]

Definition at line 67 of file moveable.hpp.

{return m_transform.getOrigin();    }

Here is the call graph for this function:

Here is the caller graph for this function:

const btTransform& Moveable::getTrans ( ) const [inline]

Definition at line 80 of file moveable.hpp.

{return m_transform;}

Here is the caller graph for this function:

virtual const btVector3& Moveable::getVelocity ( ) const [inline, virtual]

Reimplemented in Homing.

Definition at line 63 of file moveable.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

const btVector3& Moveable::getVelocityLC ( ) const [inline]

Definition at line 64 of file moveable.hpp.

{return m_velocityLC;               }

Here is the caller graph for this function:

virtual void Moveable::handleZipper ( ) [inline, virtual]

Reimplemented in Kart, and PlayerKart.

Definition at line 72 of file moveable.hpp.

{};
void Moveable::placeModel ( ) [virtual]

Reimplemented in Kart, and Flyable.

Definition at line 168 of file moveable.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Moveable::ReadHistory ( char *  s,
int  kartNumber,
int  indx 
)

Definition at line 193 of file moveable.cpp.

{
    int k;
    sscanf(s, "Kart %d: v=%f,%f,%f,%f,%f,%f, p=%f,%f,%f,%f,%f,%f", &k,
           m_history_velocity[indx].xyz+0,
           m_history_velocity[indx].xyz+1,
           m_history_velocity[indx].xyz+2,
           m_history_velocity[indx].hpr+0,
           m_history_velocity[indx].hpr+1,
           m_history_velocity[indx].hpr+2,
           m_history_position[indx].xyz+0,
           m_history_position[indx].xyz+1,
           m_history_position[indx].xyz+2,
           m_history_position[indx].hpr+0,
           m_history_position[indx].hpr+1,
           m_history_position[indx].hpr+2);
    if(k!=kartNumber)
    {
        fprintf(stderr,"WARNING: tried reading data for kart %d, found:\n",
                kartNumber);
        fprintf(stderr,"%s\n",s);
        exit(-2);
    }
}   // ReadHistory

Here is the caller graph for this function:

void Moveable::reset ( ) [virtual]

Reimplemented in Kart, DefaultRobot, Flyable, PlayerKart, and EmptyRobot.

Definition at line 68 of file moveable.cpp.

{
    m_collided         = false;
    m_crashed          = false;
    m_material_hot     = NULL;
    m_normal_hot       = NULL;
    if(m_body) m_body->setLinearVelocity(btVector3(0.0, 0.0, 0.0));
    sgCopyCoord ( &m_curr_pos, &m_reset_pos ) ;

}   // reset

Here is the call graph for this function:

Here is the caller graph for this function:

void Moveable::setCoord ( sgCoord *  pos) [inline]

Definition at line 70 of file moveable.hpp.

{sgCopyCoord ( &m_curr_pos,pos);    }
void Moveable::setTrans ( btTransform t) [inline]

Definition at line 81 of file moveable.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void Moveable::setVelocity ( const btVector3 v) [inline, virtual]

Reimplemented in Homing.

Definition at line 65 of file moveable.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Moveable::update ( float  dt) [virtual]

Reimplemented in TrafficDriver, Kart, DefaultRobot, Flyable, PlayerKart, Homing, Spark, EmptyRobot, and Missile.

Definition at line 101 of file moveable.cpp.

{
    if(m_history_velocity)
    {
        if(user_config->m_replay_history)
        {
            sgCoord tmp;
            sgCopyCoord(&tmp, &(m_history_velocity[history->GetCurrentIndex()]));
            //printf("m_velocity=%f,%f,%f,%f,%f,%f\n",
            //     m_velocity.xyz[0],m_velocity.xyz[1],m_velocity.xyz[2],
            //     m_velocity.hpr[0],m_velocity.hpr[1],m_velocity.hpr[2]);
            //printf("tmp     =%f,%f,%f,%f,%f,%f\n",
            //     tmp.xyz[0],tmp.xyz[1],tmp.xyz[2],
            //     tmp.hpr[0],tmp.hpr[1],tmp.hpr[2]);

#undef IGNORE_Z_IN_HISTORY
#ifdef IGNORE_Z_IN_HISTORY
            const float DUMMY=m_velocity.xyz[2];
            sgCopyCoord(&m_velocity, &tmp);
            m_velocity.xyz[2]=DUMMY;
#else
            m_velocityLC.setValue(tmp.xyz[0],tmp.xyz[1],tmp.xyz[2]);
#endif
        }
        else
        {
            m_history_velocity[history->GetCurrentIndex()].xyz[0]=m_velocityLC.getX();
            m_history_velocity[history->GetCurrentIndex()].xyz[1]=m_velocityLC.getY();
            m_history_velocity[history->GetCurrentIndex()].xyz[2]=m_velocityLC.getZ();
        }
    }   // if m_history_velocity

    if(m_history_position)
    {
        if(user_config->m_replay_history)
        {
            sgCoord tmp;
            sgCopyCoord(&tmp, &(m_history_position[history->GetCurrentIndex()]));
            //printf("m_curr_pos=%f,%f,%f,%f,%f,%f\n",
            //     m_curr_pos.xyz[0],m_curr_pos.xyz[1],m_curr_pos.xyz[2],
            //     m_curr_pos.hpr[0],m_curr_pos.hpr[1],m_curr_pos.hpr[2]);
            //printf("tmp     =%f,%f,%f,%f,%f,%f --> %d\n",
            //     tmp.xyz[0],tmp.xyz[1],tmp.xyz[2],
            //     tmp.hpr[0],tmp.hpr[1],tmp.hpr[2],
            //     history->GetCurrentIndex());

#ifdef IGNORE_Z_IN_HISTORY
            const float DUMMY=m_curr_pos.xyz[2];
            sgCopyCoord(&m_curr_pos, &tmp);
            m_curr_pos.xyz[2]=DUMMY;
#else
            sgCopyCoord(&m_curr_pos, &tmp);
#endif

        }
        else
        {
            sgCopyCoord(&(m_history_position[history->GetCurrentIndex()]), &m_curr_pos);
        }
    }   // if m_history_position

    m_velocityLC = getVelocity()*getTrans().getBasis();
    placeModel();
    m_first_time = false ;
}   // update

Here is the call graph for this function:

void Moveable::WriteHistory ( char *  s,
int  kartNumber,
int  indx 
)

Definition at line 175 of file moveable.cpp.

{
    sprintf(s, "Kart %d: v=%f,%f,%f,%f,%f,%f, p=%f,%f,%f,%f,%f,%f", kartNumber,
            m_history_velocity[indx].xyz[0],
            m_history_velocity[indx].xyz[1],
            m_history_velocity[indx].xyz[2],
            m_history_velocity[indx].hpr[0],
            m_history_velocity[indx].hpr[1],
            m_history_velocity[indx].hpr[2],
            m_history_position[indx].xyz[0],
            m_history_position[indx].xyz[1],
            m_history_position[indx].xyz[2],
            m_history_position[indx].hpr[0],
            m_history_position[indx].hpr[1],
            m_history_position[indx].hpr[2]);
}   // WriteHistory

Here is the caller graph for this function:


Member Data Documentation

Definition at line 53 of file moveable.hpp.

int Moveable::m_collided [protected]

Definition at line 47 of file moveable.hpp.

int Moveable::m_crashed [protected]

Definition at line 48 of file moveable.hpp.

sgCoord Moveable::m_curr_pos [protected]

Definition at line 42 of file moveable.hpp.

int Moveable::m_first_time [protected]

Definition at line 50 of file moveable.hpp.

sgCoord* Moveable::m_history_position [protected]

Definition at line 52 of file moveable.hpp.

sgCoord* Moveable::m_history_velocity [protected]

Definition at line 51 of file moveable.hpp.

Definition at line 44 of file moveable.hpp.

ssgTransform* Moveable::m_model_transform [protected]

Definition at line 45 of file moveable.hpp.

Definition at line 54 of file moveable.hpp.

sgVec4* Moveable::m_normal_hot [protected]

Definition at line 43 of file moveable.hpp.

sgCoord Moveable::m_reset_pos [protected]

Definition at line 41 of file moveable.hpp.

ssgTransform* Moveable::m_shadow [protected]

Definition at line 46 of file moveable.hpp.

Definition at line 49 of file moveable.hpp.

Definition at line 55 of file moveable.hpp.

Definition at line 40 of file moveable.hpp.

Definition at line 38 of file moveable.hpp.


The documentation for this class was generated from the following files: