Improve flying mode

This commit is contained in:
Marianne Gagnon
2014-04-28 19:55:30 -04:00
parent 18aa119890
commit 389ec42bde
3 changed files with 46 additions and 30 deletions

View File

@@ -308,7 +308,16 @@ void Camera::setInitialTransform()
*/
void Camera::smoothMoveCamera(float dt)
{
Kart *kart = dynamic_cast<Kart*>(m_kart);
if (kart->isFlying())
{
Vec3 vec3 = m_kart->getXYZ() + Vec3(sin(m_kart->getHeading()) * -4.0f, 0.5f, cos(m_kart->getHeading()) * -4.0f);
m_camera->setTarget(m_kart->getXYZ().toIrrVector());
m_camera->setPosition(vec3.toIrrVector());
return;
}
core::vector3df current_position = m_camera->getPosition();
// Smoothly interpolate towards the position and target
const KartProperties *kp = m_kart->getKartProperties();
@@ -345,6 +354,7 @@ void Camera::smoothMoveCamera(float dt)
{
current_position += (wanted_position - current_position) * dt * 5;
}
if(m_mode!=CM_FALLING)
m_camera->setPosition(current_position);
m_camera->setTarget(current_target);//set new target

View File

@@ -2274,36 +2274,36 @@ void Kart::updateFlying()
{
if (m_controls.m_accel)
{
float orientation = getHeading();
m_body->applyCentralImpulse(btVector3(60.0f*sin(orientation), 0.0,
60.0f*cos(orientation)));
btVector3 velocity = m_body->getLinearVelocity();
if (velocity.length() < 50)
{
float orientation = getHeading();
m_body->applyCentralImpulse(btVector3(60.0f*sin(orientation), 0.0,
60.0f*cos(orientation)));
}
}
else if (m_controls.m_brake)
{
btVector3 velocity = m_body->getLinearVelocity();
if (velocity.length() > -15)
{
float orientation = getHeading();
m_body->applyCentralImpulse(btVector3(-60.0f*sin(orientation), 0.0,
-60.0f*cos(orientation)));
}
}
if (m_controls.m_steer != 0.0f)
{
m_body->applyTorque(btVector3(0.0, m_controls.m_steer * 3500.0f, 0.0));
}
if (m_controls.m_brake)
if (!m_controls.m_brake && !m_controls.m_accel && (m_controls.m_steer > -0.9f && m_controls.m_steer < 0.1f))
{
btVector3 velocity = m_body->getLinearVelocity();
const float x = velocity.x();
if (x > 0.2f) velocity.setX(x - 0.2f);
else if (x < -0.2f) velocity.setX(x + 0.2f);
else velocity.setX(0);
const float y = velocity.y();
if (y > 0.2f) velocity.setY(y - 0.2f);
else if (y < -0.2f) velocity.setY(y + 0.2f);
else velocity.setY(0);
const float z = velocity.z();
if (z > 0.2f) velocity.setZ(z - 0.2f);
else if (z < -0.2f) velocity.setZ(z + 0.2f);
else velocity.setZ(0);
velocity = velocity * 0.96f;
m_body->setLinearVelocity(velocity);
} // if brake
}
// dampen any roll while flying, makes the kart hard to control
btVector3 velocity = m_body->getAngularVelocity();

View File

@@ -78,6 +78,7 @@ enum DebugMenuCommand
DEBUG_ATTACHMENT_BOMB,
DEBUG_ATTACHMENT_ANVIL,
DEBUG_TOGGLE_GUI,
DEBUG_HIDE_KARTS,
DEBUG_THROTTLE_FPS,
DEBUG_TWEAK_SHADER_EXPOSURE,
DEBUG_TWEAK_SHADER_LWHITE
@@ -181,10 +182,10 @@ bool onEvent(const SEvent &event)
sub->addItem(L"Anvil", DEBUG_ATTACHMENT_ANVIL);
sub->addItem(L"Parachute", DEBUG_ATTACHMENT_PARACHUTE);
mnu->addItem(L"Adjust shaders >", -1, true, true);
sub = mnu->getSubMenu(3);
sub->addItem(L"Exposure", DEBUG_TWEAK_SHADER_EXPOSURE);
sub->addItem(L"LWhite", DEBUG_TWEAK_SHADER_LWHITE);
//mnu->addItem(L"Adjust shaders >", -1, true, true);
//sub = mnu->getSubMenu(3);
//sub->addItem(L"Exposure", DEBUG_TWEAK_SHADER_EXPOSURE);
//sub->addItem(L"LWhite", DEBUG_TWEAK_SHADER_LWHITE);
mnu->addItem(L"Profiler",DEBUG_PROFILER);
if (UserConfigParams::m_profiler_enabled)
@@ -194,6 +195,7 @@ bool onEvent(const SEvent &event)
mnu->addItem(L"Save replay", DEBUG_SAVE_REPLAY);
mnu->addItem(L"Save history", DEBUG_SAVE_HISTORY);
mnu->addItem(L"Toggle GUI", DEBUG_TOGGLE_GUI);
mnu->addItem(L"Hide karts", DEBUG_HIDE_KARTS);
g_debug_menu_visible = true;
@@ -393,13 +395,17 @@ bool onEvent(const SEvent &event)
if (world == NULL) return false;
RaceGUIBase* gui = world->getRaceGUI();
if (gui != NULL) gui->m_enabled = !gui->m_enabled;
}
else if (cmdID == DEBUG_HIDE_KARTS)
{
World* world = World::getWorld();
if (world == NULL) return false;
const int count = World::getWorld()->getNumKarts();
for (int n=0; n<count; n++)
for (int n = 0; n<count; n++)
{
AbstractKart* kart = world->getKart(n);
if (kart->getController()->isPlayerController())
kart->getNode()->setVisible(gui->m_enabled);
kart->getNode()->setVisible(false);
}
}
else if (cmdID == DEBUG_TWEAK_SHADER_EXPOSURE)