Really fix model view widget

This commit is contained in:
Benau 2016-10-11 09:09:09 +08:00
parent 6750fb3c94
commit 28f1e45f79
3 changed files with 19 additions and 20 deletions

View File

@ -50,6 +50,7 @@ IconButtonWidget(IconButtonWidget::SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO, false,
m_old_rtt_provider = NULL; m_old_rtt_provider = NULL;
m_rotation_mode = ROTATE_OFF; m_rotation_mode = ROTATE_OFF;
m_render_info = new RenderInfo(); m_render_info = new RenderInfo();
m_angle = 0;
// so that the base class doesn't complain there is no icon defined // so that the base class doesn't complain there is no icon defined
m_properties[PROP_ICON]="gui/main_help.png"; m_properties[PROP_ICON]="gui/main_help.png";
@ -85,8 +86,6 @@ void ModelViewWidget::add()
*/ */
GUIEngine::needsUpdate.push_back(this); GUIEngine::needsUpdate.push_back(this);
angle = 0;
} // add } // add
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -133,28 +132,28 @@ void ModelViewWidget::update(float delta)
if (m_rotation_mode == ROTATE_CONTINUOUSLY) if (m_rotation_mode == ROTATE_CONTINUOUSLY)
{ {
angle += delta*m_rotation_speed; m_angle += delta*m_rotation_speed;
if (angle > 360) angle -= 360; if (m_angle > 360) m_angle -= 360;
} }
else if (m_rotation_mode == ROTATE_TO) else if (m_rotation_mode == ROTATE_TO)
{ {
// check if we should rotate clockwise or counter-clockwise to reach the target faster // check if we should rotate clockwise or counter-clockwise to reach the target faster
// (taking wrap-arounds into account) // (taking wrap-arounds into account)
const int angle_distance_from_end = (int)(360 - angle); const int angle_distance_from_end = (int)(360 - m_angle);
const int target_distance_from_end = (int)(360 - angle); const int target_distance_from_end = (int)(360 - m_angle);
int distance_with_positive_rotation; int distance_with_positive_rotation;
int distance_with_negative_rotation; int distance_with_negative_rotation;
if (angle < m_rotation_target) if (m_angle < m_rotation_target)
{ {
distance_with_positive_rotation = (int)(m_rotation_target - angle); distance_with_positive_rotation = (int)(m_rotation_target - m_angle);
distance_with_negative_rotation = (int)(angle + target_distance_from_end); distance_with_negative_rotation = (int)(m_angle + target_distance_from_end);
} }
else else
{ {
distance_with_positive_rotation = (int)(angle_distance_from_end + m_rotation_target); distance_with_positive_rotation = (int)(angle_distance_from_end + m_rotation_target);
distance_with_negative_rotation = (int)(angle - m_rotation_target); distance_with_negative_rotation = (int)(m_angle - m_rotation_target);
} }
//Log::info("ModelViewWidget", "distance_with_positive_rotation = %d; " //Log::info("ModelViewWidget", "distance_with_positive_rotation = %d; "
@ -163,17 +162,17 @@ void ModelViewWidget::update(float delta)
if (distance_with_positive_rotation < distance_with_negative_rotation) if (distance_with_positive_rotation < distance_with_negative_rotation)
{ {
angle += m_rotation_speed * delta*(3.0f + std::min(distance_with_positive_rotation, distance_with_negative_rotation)*2.0f); m_angle += m_rotation_speed * delta*(3.0f + std::min(distance_with_positive_rotation, distance_with_negative_rotation)*2.0f);
} }
else else
{ {
angle -= m_rotation_speed * delta*(3.0f + std::min(distance_with_positive_rotation, distance_with_negative_rotation)*2.0f); m_angle -= m_rotation_speed * delta*(3.0f + std::min(distance_with_positive_rotation, distance_with_negative_rotation)*2.0f);
} }
if (angle > 360) angle -= 360; if (m_angle > 360) m_angle -= 360;
if (angle < 0) angle += 360; if (m_angle < 0) m_angle += 360;
// stop rotating when target reached // stop rotating when target reached
if (fabsf(angle - m_rotation_target) < 2.0f) m_rotation_mode = ROTATE_OFF; if (fabsf(m_angle - m_rotation_target) < 2.0f) m_rotation_mode = ROTATE_OFF;
} }
if (CVS->isGLSL()) if (CVS->isGLSL())
@ -188,7 +187,7 @@ void ModelViewWidget::update(float delta)
setupRTTScene(); setupRTTScene();
} }
m_rtt_main_node->setRotation(core::vector3df(0.0f, angle, 0.0f)); m_rtt_main_node->setRotation(core::vector3df(0.0f, m_angle, 0.0f));
m_rtt_main_node->setVisible(true); m_rtt_main_node->setVisible(true);
@ -206,7 +205,7 @@ void ModelViewWidget::update(float delta)
m_old_rtt_provider->setupRTTScene(m_models, m_model_location, m_model_scale, m_model_frames); m_old_rtt_provider->setupRTTScene(m_models, m_model_location, m_model_scale, m_model_frames);
} }
m_texture = m_old_rtt_provider->renderToTexture(angle); m_texture = m_old_rtt_provider->renderToTexture(m_angle);
if (m_texture == NULL) if (m_texture == NULL)
{ {

View File

@ -56,7 +56,7 @@ namespace GUIEngine
RTT* m_rtt_provider; RTT* m_rtt_provider;
IrrDriver::RTTProvider* m_old_rtt_provider; IrrDriver::RTTProvider* m_old_rtt_provider;
float angle; float m_angle;
bool m_rtt_unsupported; bool m_rtt_unsupported;

View File

@ -39,7 +39,7 @@
using namespace GUIEngine; using namespace GUIEngine;
DEFINE_SCREEN_SINGLETON( SoccerSetupScreen ); DEFINE_SCREEN_SINGLETON( SoccerSetupScreen );
#define KART_CONTINUOUS_ROTATION_SPEED 20.f #define KART_CONTINUOUS_ROTATION_SPEED 35.f
#define KART_CONFIRMATION_ROTATION_SPEED 4.f #define KART_CONFIRMATION_ROTATION_SPEED 4.f
#define KART_CONFIRMATION_TARGET_ANGLE 10.f #define KART_CONFIRMATION_TARGET_ANGLE 10.f
@ -137,7 +137,7 @@ void SoccerSetupScreen::beforeAddingWidget()
kart_view->m_y = 0; kart_view->m_y = 0;
kart_view->m_w = 200; kart_view->m_w = 200;
kart_view->m_h = 200; kart_view->m_h = 200;
kart_view->add(); kart_view->clearModels();
// Record info about it for further update // Record info about it for further update
KartViewInfo info; KartViewInfo info;