Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
Missile Class Reference

#include <missile.hpp>

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

List of all members.

Public Member Functions

 Missile (Kart *kart)
virtual void update (float dt)
virtual void hitTrack ()
virtual void update (const btVector3 &pos)
void placeModel ()
void explode (Kart *kart, MovingPhysics *moving_physics=NULL)
bool hasHit ()
void reset ()
ssgTransform * getModelTransform ()
virtual const btVector3getVelocity () const
const btVector3getVelocityLC () const
virtual void setVelocity (const btVector3 &v)
sgCoord * getCoord ()
const sgCoord * getCoord () const
const btVector3 getPos () const
const sgVec4 * getNormalHOT () const
void setCoord (sgCoord *pos)
virtual void handleZipper ()
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)
float getHoT () const
const MaterialgetMaterial () const
const btVector3getNormal () const
float getTerrainPitch (float heading) const
 Returns the pitch of the terrain depending on the heading.

Static Public Member Functions

static void init (const lisp::Lisp *lisp, ssgEntity *missile)
static void init (const lisp::Lisp *lisp, ssgEntity *model, CollectableType type)

Protected Member Functions

void getClosestKart (const Kart **minKart, float *minDist, btVector3 *minDelta) const
void createPhysics (float y_offset, const btVector3 velocity, btCollisionShape *shape)

Protected Attributes

const Kartm_owner
btCollisionShapem_shape
float m_max_height
float m_min_height
float m_average_height
float m_force_updown
float m_speed
float m_mass
btVector3 m_extend
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

Static Protected Attributes

static float m_st_speed [COLLECT_MAX]
static ssgEntity * m_st_model [COLLECT_MAX]
static float m_st_min_height [COLLECT_MAX]
static float m_st_max_height [COLLECT_MAX]
static float m_st_force_updown [COLLECT_MAX]
static btVector3 m_st_extend [COLLECT_MAX]

Detailed Description

Definition at line 25 of file missile.hpp.


Constructor & Destructor Documentation

Missile::Missile ( Kart kart)

Definition at line 24 of file missile.cpp.

                           : Flyable(kart, COLLECT_MISSILE)
{
    float y_offset=kart->getKartLength()+2.0f*m_extend.getY();
    createPhysics(y_offset, btVector3(0.0f, m_speed, 0.0f),
                  new btCylinderShape(0.5f*m_extend));
}   // Missile

Here is the call graph for this function:


Member Function Documentation

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

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:

void Flyable::createPhysics ( float  y_offset,
const btVector3  velocity,
btCollisionShape shape 
) [protected, inherited]

Definition at line 63 of file flyable.cpp.

{
    // The actual transform is determined as follows:
    // 1) Compute the heading of the kart
    // 2) Compute the pitch of the terrain. This avoids the problem of the
    //    rocket hitting the floor (e.g. if the kart is braking and therefore
    //    pointing downwards).
    btTransform trans = m_owner->getTrans();

    // get heading=trans.getBasis*(0,1,0) ... so save the multiplication:
    btVector3 direction(trans.getBasis()[0][1],
                        trans.getBasis()[1][1],
                        trans.getBasis()[2][1]);
    float heading=atan2(-direction.getX(), direction.getY());

    TerrainInfo::update(trans.getOrigin());
    float pitch = getTerrainPitch(heading);

    btMatrix3x3 m;
    m.setEulerZYX(pitch, 0.0f, heading);
    trans.setBasis(m);

    // Apply rotation and offset
    btTransform offset_transform;
    offset_transform.setIdentity();
    btVector3 offset=btVector3(0,y_offset,m_average_height);
    offset_transform.setOrigin(offset);
        
    trans  *= offset_transform;

    m_shape = shape;
    createBody(m_mass, trans, m_shape);
    m_user_pointer.set(this);
    world->getPhysics()->addBody(getBody());

    // Simplified rockets: no gravity
    m_body->setGravity(btVector3(0.0f, 0.0f, 0.0f));

    // Rotate velocity to point in the right direction
    btVector3 v=trans.getBasis()*velocity;

    if(m_mass!=0.0f)  // Don't set velocity for kinematic or static objects
    {
        m_body->setLinearVelocity(v);
        m_body->setAngularFactor(0.0f);   // prevent rotations
    }
    m_body->setCollisionFlags(btCollisionObject::CF_NO_CONTACT_RESPONSE);

}   // createPhysics

Here is the call graph for this function:

Here is the caller graph for this function:

void Flyable::explode ( Kart kart,
MovingPhysics moving_physics = NULL 
) [inherited]

Definition at line 201 of file flyable.cpp.

{
       if(m_exploded) return;

    m_has_hit_something=true;
    // Notify the projectile manager that this rocket has hit something.
    // The manager will create the appropriate explosion object.
    projectile_manager->explode();

    // Now remove this projectile from the graph:
    ssgTransform *m = getModelTransform();
    m->removeAllKids();
    scene->remove(m);

    // The explosion is a bit higher in the air
    btVector3 pos_explosion=getPos();
    pos_explosion.setZ(pos_explosion.getZ()+1.2f);
    world->getPhysics()->removeBody(getBody());
       m_exploded=true;

    for ( unsigned int i = 0 ; i < race_manager->getNumKarts() ; i++ )
    {
        Kart *kart = world->getKart(i);
        // Handle the actual explosion. The kart that fired a flyable will 
        // only be affected if it's a direct hit. This allows karts to use
        // rockets on short distance.
        if(m_owner!=kart || m_owner==kart_hit) 
        {
            // Set a flag it if was a direct hit.
            kart->handleExplosion(getPos(), kart==kart_hit);
        }
    }
    callback_manager->handleExplosion(pos_explosion, moving_physics);
}   // explode

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 77 of file moveable.hpp.

{return m_body; }

Here is the caller graph for this function:

void Flyable::getClosestKart ( const Kart **  minKart,
float *  minDist,
btVector3 minDelta 
) const [protected, inherited]

Definition at line 142 of file flyable.cpp.

{
    btTransform tProjectile=getTrans();
    *minDist = 99999.9f;
    for(unsigned int i=0 ; i<race_manager->getNumKarts(); i++ )
    {
        Kart *kart = world -> getKart(i);
        if(kart->isEliminated() || kart == m_owner) continue;
        btTransform t=kart->getTrans();
       
        btVector3 delta = t.getOrigin()-tProjectile.getOrigin();
        float distance2 = delta.length2();

        if(distance2 < *minDist)
        {
            *minDist  = sqrt(distance2);
            *minKart  = kart;
            *minDelta = delta;
        }
    }  // for i<getNumKarts
}   // getClosestKart

Here is the call graph for this function:

Here is the caller graph for this function:

sgCoord* Moveable::getCoord ( ) [inline, inherited]

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, inherited]

Definition at line 68 of file moveable.hpp.

{return &m_curr_pos;                }
float TerrainInfo::getHoT ( ) const [inline, inherited]

Definition at line 44 of file terrain_info.hpp.

{ return m_HoT;      }

Here is the caller graph for this function:

const Material* TerrainInfo::getMaterial ( ) const [inline, inherited]

Definition at line 45 of file terrain_info.hpp.

{ return m_material; }

Here is the caller graph for this function:

ssgTransform* Moveable::getModelTransform ( ) [inline, inherited]

Definition at line 62 of file moveable.hpp.

{return m_model_transform;          }

Here is the caller graph for this function:

const btVector3& TerrainInfo::getNormal ( ) const [inline, inherited]

Definition at line 46 of file terrain_info.hpp.

{ return m_normal;   }
const sgVec4* Moveable::getNormalHOT ( ) const [inline, inherited]

Definition at line 69 of file moveable.hpp.

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

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:

float TerrainInfo::getTerrainPitch ( float  heading) const [inherited]

Returns the pitch of the terrain depending on the heading.

Definition at line 49 of file terrain_info.cpp.

                                                      {
    if(m_HoT==Track::NOHIT) return 0.0f;

    const float X =-sin(heading);
    const float Y = cos(heading);
    // Compute the angle between the normal of the plane and the line to
    // (x,y,0).  (x,y,0) is normalised, so are the coordinates of the plane,
    // simplifying the computation of the scalar product.
    float pitch = ( m_normal.getX()*X + m_normal.getY()*Y );  // use ( x,y,0)
        
    // The actual angle computed above is between the normal and the (x,y,0)
    // line, so to compute the actual angles 90 degrees must be subtracted.
    pitch = acosf(pitch) - NINETY_DEGREE_RAD;
    return pitch;
}   // getTerrainPitch

Here is the call graph for this function:

Here is the caller graph for this function:

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

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, inherited]

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, inherited]

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, inherited]

Reimplemented in Kart, and PlayerKart.

Definition at line 72 of file moveable.hpp.

{};
bool Flyable::hasHit ( ) [inline, inherited]

Definition at line 72 of file flyable.hpp.

{ return m_has_hit_something; }
virtual void Missile::hitTrack ( ) [inline, virtual]

Reimplemented from Flyable.

Definition at line 31 of file missile.hpp.

{ explode(NULL); }

Here is the call graph for this function:

void Missile::init ( const lisp::Lisp lisp,
ssgEntity *  missile 
) [static]

Definition at line 32 of file missile.cpp.

{
    Flyable::init(lisp, missile, COLLECT_MISSILE);
}   // init

Here is the caller graph for this function:

void Flyable::init ( const lisp::Lisp lisp,
ssgEntity *  model,
CollectableType  type 
) [static, inherited]

Definition at line 115 of file flyable.cpp.

{
    m_st_speed[type]        = 25.0f;
    m_st_max_height[type]   = 1.0f;
    m_st_min_height[type]   = 3.0f;
    m_st_force_updown[type] = 15.0f;
    lisp->get("speed",           m_st_speed[type]       );
    lisp->get("min-height",      m_st_min_height[type]  );
    lisp->get("max-height",      m_st_max_height[type]  );
    lisp->get("force-updown",    m_st_force_updown[type]);

    // Store the size of the model
    float x_min, x_max, y_min, y_max, z_min, z_max;
    MinMax(model, &x_min, &x_max, &y_min, &y_max, &z_min, &z_max);
    m_st_extend[type] = btVector3(x_max-x_min,y_max-y_min, z_max-z_min);
    m_st_model[type]  = model;
}   // init

Here is the call graph for this function:

void Flyable::placeModel ( ) [virtual, inherited]

Reimplemented from Moveable.

Definition at line 191 of file flyable.cpp.

{
       btTransform t=getTrans();
    float m[4][4];
    t.getOpenGLMatrix((float*)&m);
    sgSetCoord(&m_curr_pos, m);
    Moveable::placeModel();
}  // placeModel

Here is the call graph for this function:

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

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 Flyable::reset ( ) [inline, virtual, inherited]

Reimplemented from Moveable.

Definition at line 73 of file flyable.hpp.

                                { Moveable::reset();
                                  sgCopyCoord(&m_last_pos,&m_reset_pos );   }
void Moveable::setCoord ( sgCoord *  pos) [inline, inherited]

Definition at line 70 of file moveable.hpp.

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

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, inherited]

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 Missile::update ( float  dt) [virtual]

Reimplemented from Flyable.

Definition at line 38 of file missile.cpp.

{
    Flyable::update(dt);
}   // update
void TerrainInfo::update ( const btVector3 pos) [virtual, inherited]

Definition at line 34 of file terrain_info.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

float Flyable::m_average_height [protected, inherited]

Definition at line 40 of file flyable.hpp.

btRigidBody* Moveable::m_body [protected, inherited]

Definition at line 53 of file moveable.hpp.

int Moveable::m_collided [protected, inherited]

Definition at line 47 of file moveable.hpp.

int Moveable::m_crashed [protected, inherited]

Definition at line 48 of file moveable.hpp.

sgCoord Moveable::m_curr_pos [protected, inherited]

Definition at line 42 of file moveable.hpp.

btVector3 Flyable::m_extend [protected, inherited]

Definition at line 44 of file flyable.hpp.

int Moveable::m_first_time [protected, inherited]

Definition at line 50 of file moveable.hpp.

float Flyable::m_force_updown [protected, inherited]

Definition at line 41 of file flyable.hpp.

sgCoord* Moveable::m_history_position [protected, inherited]

Definition at line 52 of file moveable.hpp.

sgCoord* Moveable::m_history_velocity [protected, inherited]

Definition at line 51 of file moveable.hpp.

float Flyable::m_mass [protected, inherited]

Definition at line 43 of file flyable.hpp.

Material* Moveable::m_material_hot [protected, inherited]

Definition at line 44 of file moveable.hpp.

float Flyable::m_max_height [protected, inherited]

Definition at line 38 of file flyable.hpp.

float Flyable::m_min_height [protected, inherited]

Definition at line 39 of file flyable.hpp.

ssgTransform* Moveable::m_model_transform [protected, inherited]

Definition at line 45 of file moveable.hpp.

Definition at line 54 of file moveable.hpp.

sgVec4* Moveable::m_normal_hot [protected, inherited]

Definition at line 43 of file moveable.hpp.

const Kart* Flyable::m_owner [protected, inherited]

Definition at line 36 of file flyable.hpp.

sgCoord Moveable::m_reset_pos [protected, inherited]

Definition at line 41 of file moveable.hpp.

ssgTransform* Moveable::m_shadow [protected, inherited]

Definition at line 46 of file moveable.hpp.

btCollisionShape* Flyable::m_shape [protected, inherited]

Definition at line 37 of file flyable.hpp.

float Flyable::m_speed [protected, inherited]

Definition at line 42 of file flyable.hpp.

btVector3 Flyable::m_st_extend [static, protected, inherited]

Definition at line 54 of file flyable.hpp.

float Flyable::m_st_force_updown [static, protected, inherited]

Definition at line 53 of file flyable.hpp.

float Flyable::m_st_max_height [static, protected, inherited]

Definition at line 52 of file flyable.hpp.

float Flyable::m_st_min_height [static, protected, inherited]

Definition at line 51 of file flyable.hpp.

ssgEntity * Flyable::m_st_model [static, protected, inherited]

Definition at line 50 of file flyable.hpp.

float Flyable::m_st_speed [static, protected, inherited]

Definition at line 49 of file flyable.hpp.

sgVec3 Moveable::m_surface_avoidance_vector [protected, inherited]

Definition at line 49 of file moveable.hpp.

btTransform Moveable::m_transform [protected, inherited]

Definition at line 55 of file moveable.hpp.

UserPointer Moveable::m_user_pointer [protected, inherited]

Definition at line 40 of file moveable.hpp.


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