2007-05-27 12:01:53 -04:00
|
|
|
// $Id$
|
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
|
|
|
// Copyright (C) 2004-2005 Steve Baker <sjbaker1@airmail.net>
|
|
|
|
// Copyright (C) 2006 Joerg Henrichs, Steve Baker
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
2008-06-12 20:53:52 -04:00
|
|
|
// as published by the Free Software Foundation; either version 3
|
2007-05-27 12:01:53 -04:00
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
#include "player_kart.hpp"
|
|
|
|
#include "material_manager.hpp"
|
|
|
|
#include "material.hpp"
|
|
|
|
#include "user_config.hpp"
|
2008-10-28 23:41:01 -04:00
|
|
|
#include "coord.hpp"
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2008-10-06 09:40:11 -04:00
|
|
|
Moveable::Moveable()
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2007-12-08 08:04:56 -05:00
|
|
|
m_body = 0;
|
|
|
|
m_motion_state = 0;
|
|
|
|
m_shadow = 0;
|
|
|
|
m_first_time = true ;
|
|
|
|
m_model_transform = new ssgTransform();
|
2007-05-27 12:01:53 -04:00
|
|
|
|
2007-12-08 08:04:56 -05:00
|
|
|
m_model_transform->ref();
|
2007-05-27 12:01:53 -04:00
|
|
|
} // Moveable
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
Moveable::~Moveable()
|
|
|
|
{
|
2007-11-08 17:40:15 -05:00
|
|
|
// The body is being removed from the world in kart/projectile
|
2007-12-08 08:04:56 -05:00
|
|
|
if(m_body) delete m_body;
|
2007-09-30 10:17:28 -04:00
|
|
|
if(m_motion_state) delete m_motion_state;
|
2007-05-27 12:01:53 -04:00
|
|
|
// FIXME what about model?
|
|
|
|
} // ~Moveable
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2008-06-20 05:34:35 -04:00
|
|
|
// The reset position must be set before calling reset
|
2007-05-27 12:01:53 -04:00
|
|
|
void Moveable::reset ()
|
|
|
|
{
|
|
|
|
m_material_hot = NULL;
|
|
|
|
m_normal_hot = NULL;
|
2008-06-20 05:34:35 -04:00
|
|
|
if(m_body)
|
|
|
|
{
|
|
|
|
m_body->setLinearVelocity(btVector3(0.0, 0.0, 0.0));
|
|
|
|
m_body->setAngularVelocity(btVector3(0, 0, 0));
|
|
|
|
m_body->setCenterOfMassTransform(m_transform);
|
|
|
|
}
|
|
|
|
Coord c(m_transform);
|
|
|
|
m_hpr = c.getHPR();
|
2007-05-27 12:01:53 -04:00
|
|
|
} // reset
|
|
|
|
|
2007-09-30 10:17:28 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
2007-11-03 09:13:26 -04:00
|
|
|
void Moveable::createBody(float mass, btTransform& trans,
|
2008-01-30 00:30:10 -05:00
|
|
|
btCollisionShape *shape) {
|
2007-09-30 10:17:28 -04:00
|
|
|
|
2007-11-03 09:13:26 -04:00
|
|
|
btVector3 inertia;
|
|
|
|
shape->calculateLocalInertia(mass, inertia);
|
|
|
|
m_motion_state = new btDefaultMotionState(trans);
|
2007-09-30 10:17:28 -04:00
|
|
|
|
2008-01-31 07:40:22 -05:00
|
|
|
btRigidBody::btRigidBodyConstructionInfo info(mass, m_motion_state, shape, inertia);
|
2008-02-05 06:56:21 -05:00
|
|
|
info.m_restitution=0.5f;
|
2008-01-31 07:40:22 -05:00
|
|
|
|
2007-09-30 10:17:28 -04:00
|
|
|
// Then create a rigid body
|
|
|
|
// ------------------------
|
2008-01-31 07:40:22 -05:00
|
|
|
m_body = new btRigidBody(info);
|
2008-02-05 06:56:21 -05:00
|
|
|
// The value of user_pointer must be set from the actual class, otherwise this
|
2008-01-30 00:30:10 -05:00
|
|
|
// is only a pointer to moveable, not to (say) kart, and virtual
|
2008-02-05 06:56:21 -05:00
|
|
|
// functions are not called correctly. So only init the pointer to zero.
|
|
|
|
m_user_pointer.zero();
|
2008-01-30 00:30:10 -05:00
|
|
|
m_body->setUserPointer(&m_user_pointer);
|
2008-06-09 22:35:10 -04:00
|
|
|
const btMatrix3x3& basis=m_body->getWorldTransform().getBasis();
|
|
|
|
m_hpr.setHPR(basis);
|
2007-09-30 10:17:28 -04:00
|
|
|
} // createBody
|
2007-12-08 08:04:56 -05:00
|
|
|
|
2007-05-27 12:01:53 -04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void Moveable::update (float dt)
|
|
|
|
{
|
2008-06-20 05:34:35 -04:00
|
|
|
m_motion_state->getWorldTransform(m_transform);
|
|
|
|
m_velocityLC = getVelocity()*getTrans().getBasis();
|
|
|
|
m_hpr.setHPR(m_transform.getBasis());
|
|
|
|
|
|
|
|
updateGraphics(Vec3(0,0,0), Vec3(0,0,0));
|
2007-05-27 12:01:53 -04:00
|
|
|
m_first_time = false ;
|
|
|
|
} // update
|
|
|
|
|
2007-12-19 23:37:35 -05:00
|
|
|
//-----------------------------------------------------------------------------
|
2008-06-20 05:34:35 -04:00
|
|
|
void Moveable::updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr)
|
2007-12-19 23:37:35 -05:00
|
|
|
{
|
2008-06-20 05:34:35 -04:00
|
|
|
Vec3 xyz=getXYZ()+off_xyz;
|
|
|
|
Vec3 hpr=getHPR()+off_hpr;
|
|
|
|
sgCoord c=Coord(xyz, hpr).toSgCoord();
|
|
|
|
|
|
|
|
m_model_transform->setTransform(&c);
|
|
|
|
} // updateGraphics
|
2007-12-19 23:37:35 -05:00
|
|
|
|