Karts in kkart selection screens are now animation aware and will display the center frame (though elephant still seems slightly off-center, not sure why)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4375 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2009-12-30 19:41:59 +00:00
parent 9859e0c4ad
commit 75149a100c
6 changed files with 65 additions and 18 deletions

View File

@@ -820,24 +820,50 @@ IrrDriver::RTTProvider::~RTTProvider()
* object inside the GUI. If there are multiple meshes, the first mesh is considered
* to be the root, and all following meshes will have their locations relative to
* the location of the first mesh.
*
* Parameters:
* \param mesh Vector of meshes to render.
* \param mesh_location For each mesh the location where it should be
* positioned.
*/
void IrrDriver::RTTProvider::setupRTTScene(ptr_vector<scene::IMesh, REF>& mesh,
std::vector<Vec3>& mesh_location)
{
m_rtt_main_node = irr_driver->getSceneManager()->addMeshSceneNode(mesh.get(0));
assert(m_rtt_main_node != NULL);
std::vector<Vec3>& mesh_location,
const std::vector<int>& model_frames)
{
if (model_frames[0] == -1)
{
scene::ISceneNode* node = irr_driver->getSceneManager()->addMeshSceneNode(mesh.get(0), NULL);
node->setPosition( mesh_location[0].toIrrVector() );
m_rtt_main_node = node;
}
else
{
scene::IAnimatedMeshSceneNode* node = irr_driver->getSceneManager()->addAnimatedMeshSceneNode((IAnimatedMesh*)mesh.get(0), NULL);
node->setPosition( mesh_location[0].toIrrVector() );
node->setFrameLoop(model_frames[0], model_frames[0]);
node->setAnimationSpeed(0);
m_rtt_main_node = node;
//std::cout << "(((( set frame " << model_frames[0] << " ))))\n";
}
assert(m_rtt_main_node != NULL);
assert(mesh.size() == (int)mesh_location.size());
assert(mesh.size() == (int)model_frames.size());
const int mesh_amount = mesh.size();
for (int n=1; n<mesh_amount; n++)
{
scene::ISceneNode* node = irr_driver->getSceneManager()->addMeshSceneNode(mesh.get(n), m_rtt_main_node);
node->setPosition( mesh_location[n].toIrrVector() );
node->updateAbsolutePosition();
if (model_frames[n] == -1)
{
scene::ISceneNode* node = irr_driver->getSceneManager()->addMeshSceneNode(mesh.get(n), m_rtt_main_node);
node->setPosition( mesh_location[n].toIrrVector() );
node->updateAbsolutePosition();
}
else
{
scene::IAnimatedMeshSceneNode* node = irr_driver->getSceneManager()->addAnimatedMeshSceneNode((IAnimatedMesh*)mesh.get(n), m_rtt_main_node);
node->setPosition( mesh_location[n].toIrrVector() );
node->setFrameLoop(model_frames[n], model_frames[n]);
node->setAnimationSpeed(0);
node->updateAbsolutePosition();
//std::cout << "(((( set frame " << model_frames[n] << " ))))\n";
}
}
m_rtt_main_node->setScale( core::vector3df(35.0f, 35.0f, 35.0f) );

View File

@@ -154,8 +154,23 @@ public:
~RTTProvider();
/**
* \brief Quick utility method to setup a scene from a plain list of models
*
* Sets up a given vector of meshes for render-to-texture. Ideal to embed a 3D
* object inside the GUI. If there are multiple meshes, the first mesh is considered
* to be the root, and all following meshes will have their locations relative to
* the location of the first mesh.
*
* \param mesh The list of meshes to add to the scene
* \param mesh_location Location of each fo these meshes
* \param model_frames For animated meshes, which frame to use (value can be -1 to set none)
* When frame is not -1, the corresponding IMesh must be an IAnimatedMesh.
* \precondition The 3 vectors have the same size.
*/
void setupRTTScene(ptr_vector<scene::IMesh, REF>& mesh,
std::vector<Vec3>& mesh_location);
std::vector<Vec3>& mesh_location,
const std::vector<int>& model_frames);
/** Optional 'angle' parameter will rotate the object added *through setupRTTScene* */
video::ITexture* renderToTexture(float angle=-1,

View File

@@ -63,15 +63,17 @@ void ModelViewWidget::clearModels()
{
m_models.clearWithoutDeleting();
m_model_location.clear();
m_model_frames.clear();
delete m_rtt_provider;
m_rtt_provider = NULL;
}
// -----------------------------------------------------------------------------
void ModelViewWidget::addModel(irr::scene::IMesh* mesh, const Vec3& location)
void ModelViewWidget::addModel(irr::scene::IMesh* mesh, const Vec3& location, const int frame)
{
m_models.push_back(mesh);
m_model_location.push_back(location);
m_model_frames.push_back(frame);
/*
((IGUIMeshViewer*)m_element)->setMesh( mesh );
@@ -138,7 +140,7 @@ void ModelViewWidget::update(float delta)
std::string name = "model view ";
name += m_properties[PROP_ID].c_str();
m_rtt_provider = new IrrDriver::RTTProvider(core::dimension2d< u32 >(512, 512), name );
m_rtt_provider->setupRTTScene(m_models, m_model_location);
m_rtt_provider->setupRTTScene(m_models, m_model_location, m_model_frames);
}
m_texture = m_rtt_provider->renderToTexture(angle);

View File

@@ -43,6 +43,7 @@ namespace GUIEngine
ptr_vector<scene::IMesh, REF> m_models;
std::vector<Vec3> m_model_location;
std::vector<int> m_model_frames;
video::ITexture* m_texture;
@@ -55,7 +56,7 @@ namespace GUIEngine
void add();
void clearModels();
void addModel(irr::scene::IMesh* mesh, const Vec3& location = Vec3(0,0,0));
void addModel(irr::scene::IMesh* mesh, const Vec3& location = Vec3(0,0,0), const int frame=-1);
void update(float delta);
/** Disables any model rotation */

View File

@@ -109,6 +109,9 @@ public:
scene::IMesh* getWheelModel(const int wheelID) const { return m_wheel_model[wheelID]; }
/** Since karts might be animated, we might need to know which base frame to use */
int getBaseFrame() const { return m_af_straight; }
/** Returns the position of a wheel relative to the kart.
* \param i Index of the wheel: 0=front right, 1 = front left, 2 = rear
* right, 3 = rear left. */

View File

@@ -281,7 +281,7 @@ FocusDispatcher* g_dispatcher = NULL;
const KartProperties* props = kart_properties_manager->getKart(default_kart);
KartModel* kartModel = props->getKartModel();
this->modelView->addModel( kartModel->getModel() );
this->modelView->addModel( kartModel->getModel(), Vec3(0,0,0), kartModel->getBaseFrame() );
this->modelView->addModel( kartModel->getWheelModel(0), kartModel->getWheelGraphicsPosition(0) );
this->modelView->addModel( kartModel->getWheelModel(1), kartModel->getWheelGraphicsPosition(1) );
this->modelView->addModel( kartModel->getWheelModel(2), kartModel->getWheelGraphicsPosition(2) );
@@ -659,7 +659,7 @@ public:
KartModel* kartModel = kart->getKartModel();
w3->clearModels();
w3->addModel( kartModel->getModel() );
w3->addModel( kartModel->getModel(), Vec3(0,0,0), kartModel->getBaseFrame() );
w3->addModel( kartModel->getWheelModel(0), kartModel->getWheelGraphicsPosition(0) );
w3->addModel( kartModel->getWheelModel(1), kartModel->getWheelGraphicsPosition(1) );
w3->addModel( kartModel->getWheelModel(2), kartModel->getWheelGraphicsPosition(2) );