Merge branch 'fix_186'

This commit is contained in:
Benau 2017-01-16 08:48:06 +08:00
commit 93ad594ff2
7 changed files with 72 additions and 24 deletions

View File

@ -31,6 +31,9 @@
#include <IMeshSceneNode.h>
#include <algorithm>
#ifndef SERVER_ONLY
#include "../../lib/irrlicht/source/Irrlicht/os.h"
#endif
using namespace GUIEngine;
using namespace irr::core;
@ -89,6 +92,7 @@ void ModelViewWidget::clearModels()
m_model_scale.clear();
m_model_frames.clear();
m_model_render_info_affected.clear();
m_model_animation_speed.clear();
if (m_rtt_main_node != NULL) m_rtt_main_node->remove();
if (m_light != NULL) m_light->remove();
@ -103,16 +107,18 @@ void ModelViewWidget::clearModels()
// -----------------------------------------------------------------------------
void ModelViewWidget::addModel(irr::scene::IMesh* mesh, const Vec3& location,
const Vec3& scale, const int frame,
bool all_parts_colorized)
const Vec3& scale, const int start_loop_frame,
const int end_loop_frame,
bool all_parts_colorized, float animation_speed)
{
if(!mesh) return;
m_models.push_back(mesh);
m_model_location.push_back(location);
m_model_scale.push_back(scale);
m_model_frames.push_back(frame);
m_model_frames.emplace_back(start_loop_frame, end_loop_frame);
m_model_render_info_affected.push_back(all_parts_colorized);
m_model_animation_speed.push_back(animation_speed);
#ifndef SERVER_ONLY
if (!CVS->isGLSL())
m_render_target = NULL;
@ -187,6 +193,10 @@ void ModelViewWidget::update(float delta)
m_rtt_main_node->setRotation(core::vector3df(0.0f, m_angle, 0.0f));
m_rtt_main_node->setVisible(true);
#ifndef SERVER_ONLY
if (UserConfigParams::m_show_steering_animations != 0)
m_rtt_main_node->OnAnimate(os::Timer::getTime());
#endif
m_render_target->renderToTexture(m_camera, GUIEngine::getLatestDt());
@ -210,7 +220,7 @@ void ModelViewWidget::setupRTTScene()
irr_driver->clearLights();
if (m_model_frames[0] == -1)
if (m_model_frames[0].first == -1)
{
scene::ISceneNode* node = irr_driver->addMesh(m_models.get(0), "rtt_mesh",
NULL, m_render_info, m_model_render_info_affected[0]);
@ -225,8 +235,8 @@ void ModelViewWidget::setupRTTScene()
irr_driver->addAnimatedMesh((scene::IAnimatedMesh*)m_models.get(0), "rtt_mesh",
NULL, m_render_info, m_model_render_info_affected[0]);
node->setPosition(m_model_location[0].toIrrVector());
node->setFrameLoop(m_model_frames[0], m_model_frames[0]);
node->setAnimationSpeed(0);
node->setFrameLoop(m_model_frames[0].first, m_model_frames[0].second);
node->setAnimationSpeed(m_model_animation_speed[0]);
node->setScale(m_model_scale[0].toIrrVector());
node->setMaterialFlag(video::EMF_FOG_ENABLE, false);
m_rtt_main_node = node;
@ -237,11 +247,12 @@ void ModelViewWidget::setupRTTScene()
assert(m_models.size() == m_model_frames.size());
assert(m_models.size() == m_model_scale.size());
assert(m_models.size() == m_model_render_info_affected.size());
assert(m_models.size() == m_model_animation_speed.size());
const int mesh_amount = m_models.size();
for (int n = 1; n<mesh_amount; n++)
{
if (m_model_frames[n] == -1)
if (m_model_frames[n].first == -1)
{
scene::ISceneNode* node =
irr_driver->addMesh(m_models.get(n), "rtt_node", m_rtt_main_node,
@ -257,8 +268,8 @@ void ModelViewWidget::setupRTTScene()
"modelviewrtt", m_rtt_main_node, m_render_info,
m_model_render_info_affected[n]);
node->setPosition(m_model_location[n].toIrrVector());
node->setFrameLoop(m_model_frames[n], m_model_frames[n]);
node->setAnimationSpeed(0);
node->setFrameLoop(m_model_frames[n].first, m_model_frames[n].second);
node->setAnimationSpeed(m_model_animation_speed[n]);
node->updateAbsolutePosition();
node->setScale(m_model_scale[n].toIrrVector());
//Log::info("ModelViewWidget", "Set frame %d", m_model_frames[n]);

View File

@ -50,8 +50,9 @@ namespace GUIEngine
PtrVector<scene::IMesh, REF> m_models;
AlignedArray<Vec3> m_model_location;
AlignedArray<Vec3> m_model_scale;
std::vector<int> m_model_frames;
std::vector<std::pair<int, int> > m_model_frames;
std::vector<bool> m_model_render_info_affected;
std::vector<float> m_model_animation_speed;
std::unique_ptr<RenderTarget> m_render_target;
float m_angle;
@ -77,8 +78,10 @@ namespace GUIEngine
void addModel(irr::scene::IMesh* mesh,
const Vec3& location = Vec3(0,0,0),
const Vec3& scale = Vec3(1,1,1),
const int frame=-1,
bool all_parts_colorized = false);
const int start_loop_frame=-1,
const int end_loop_frame=-1,
bool all_parts_colorized = false,
float animation_speed=0.0f);
void update(float delta);

View File

@ -195,6 +195,7 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent,
m_model_view->addModel( kart_model.getModel(), Vec3(0,0,0),
Vec3(scale, scale, scale),
kart_model.getBaseFrame(),
kart_model.getBaseFrame() );
m_model_view->addModel( kart_model.getWheelModel(0),
kart_model.getWheelGraphicsPosition(0) );

View File

@ -181,6 +181,8 @@ void KartModel::loadInfo(const XMLNode &node)
animation_node->get("backpedal-right",&m_animation_frame[AF_BACK_RIGHT]);
animation_node->get("start-speed-weighted", &m_animation_frame[AF_SPEED_WEIGHTED_START]);
animation_node->get("end-speed-weighted", &m_animation_frame[AF_SPEED_WEIGHTED_END] );
animation_node->get("selection-start", &m_animation_frame[AF_SELECTION_START]);
animation_node->get("selection-end", &m_animation_frame[AF_SELECTION_END] );
animation_node->get("speed", &m_animation_speed );
}

View File

@ -114,9 +114,11 @@ public:
AF_WIN_START, // Begin of win animation
AF_WIN_LOOP_START, // Begin of win loop animation
AF_WIN_END, // End of win animation
AF_BACK_LEFT, // Going back left
AF_BACK_STRAIGHT, // Going back straight
AF_BACK_RIGHT, // Going back right
AF_SELECTION_START, // Start frame in kart selection screen
AF_SELECTION_END, // End frame in kart selection screen
AF_BACK_LEFT, // Going back left
AF_BACK_STRAIGHT, // Going back straight
AF_BACK_RIGHT, // Going back right
AF_SPEED_WEIGHTED_START, // Start of speed-weighted animation
AF_SPEED_WEIGHTED_END, // End of speed-weighted animation
AF_END=AF_SPEED_WEIGHTED_END, // Last animation frame
@ -271,6 +273,10 @@ public:
* to use. */
int getBaseFrame() const { return m_animation_frame[AF_STRAIGHT]; }
// ------------------------------------------------------------------------
int getFrame(AnimationFrameType f) const { return m_animation_frame[f]; }
// ------------------------------------------------------------------------
float getAnimationSpeed() const { return m_animation_speed; }
// ------------------------------------------------------------------------
/** 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

@ -875,9 +875,29 @@ void KartSelectionScreen::updateKartWidgetModel(int widget_id,
}
w3->clearModels();
const bool has_win_anime =
UserConfigParams::m_show_steering_animations != 0 &&
(((kart_model.getFrame(KartModel::AF_WIN_LOOP_START) > -1 ||
kart_model.getFrame(KartModel::AF_WIN_START) > -1) &&
kart_model.getFrame(KartModel::AF_WIN_END) > -1) ||
(kart_model.getFrame(KartModel::AF_SELECTION_START) > -1 &&
kart_model.getFrame(KartModel::AF_SELECTION_END) > -1));
w3->addModel( kart_model.getModel(), Vec3(0,0,0),
Vec3(scale, scale, scale),
kart_model.getBaseFrame() );
has_win_anime ?
kart_model.getFrame(KartModel::AF_SELECTION_START) > -1 ?
kart_model.getFrame(KartModel::AF_SELECTION_START) :
kart_model.getFrame(KartModel::AF_WIN_LOOP_START) > -1 ?
kart_model.getFrame(KartModel::AF_WIN_LOOP_START) :
kart_model.getFrame(KartModel::AF_WIN_START) :
kart_model.getBaseFrame(),
has_win_anime ?
kart_model.getFrame(KartModel::AF_SELECTION_END) > -1 ?
kart_model.getFrame(KartModel::AF_SELECTION_END) :
kart_model.getFrame(KartModel::AF_WIN_END) :
kart_model.getBaseFrame(),
false/*all_parts_colorized*/,
kart_model.getAnimationSpeed());
w3->addModel( kart_model.getWheelModel(0),
kart_model.getWheelGraphicsPosition(0) );
w3->addModel( kart_model.getWheelModel(1),

View File

@ -155,31 +155,35 @@ void SoccerSetupScreen::beforeAddingWidget()
}
// Add the kart model (including wheels and speed weight objects)
kart_view->addModel( kart_model.getModel(), Vec3(0,0,0),
Vec3(35.0f, 35.0f, 35.0f),
kart_model.getBaseFrame() );
kart_view->addModel(kart_model.getModel(), Vec3(0, 0, 0),
Vec3(35.0f, 35.0f, 35.0f), kart_model.getBaseFrame(),
kart_model.getBaseFrame());
kart_view->addModel( kart_model.getWheelModel(0),
kart_model.getWheelGraphicsPosition(0),
Vec3(1, 1, 1), /*scale*/
-1, /*frame*/
-1, /*start_loop_frame*/
-1, /*end_loop_frame*/
true /*all_parts_colorized*/);
kart_view->addModel( kart_model.getWheelModel(1),
kart_model.getWheelGraphicsPosition(1),
Vec3(1, 1, 1), /*scale*/
-1, /*frame*/
-1, /*start_loop_frame*/
-1, /*end_loop_frame*/
true /*all_parts_colorized*/);
kart_view->addModel( kart_model.getWheelModel(2),
kart_model.getWheelGraphicsPosition(2),
Vec3(1, 1, 1), /*scale*/
-1, /*frame*/
-1, /*start_loop_frame*/
-1, /*end_loop_frame*/
true /*all_parts_colorized*/);
kart_view->addModel( kart_model.getWheelModel(3),
kart_model.getWheelGraphicsPosition(3),
Vec3(1, 1, 1), /*scale*/
-1, /*frame*/
-1, /*start_loop_frame*/
-1, /*end_loop_frame*/
true /*all_parts_colorized*/);
for (size_t i = 0; i < kart_model.getSpeedWeightedObjectsCount(); i++)
@ -187,7 +191,8 @@ void SoccerSetupScreen::beforeAddingWidget()
const SpeedWeightedObject& obj = kart_model.getSpeedWeightedObject((int)i);
kart_view->addModel(obj.m_model, obj.m_position,
Vec3(1, 1, 1), /*scale*/
-1, /*frame*/
-1, /*start_loop_frame*/
-1, /*end_loop_frame*/
true /*all_parts_colorized*/);
}