2012-06-26 20:23:05 +00:00
|
|
|
// * This file is part of the COLOBOT source code
|
|
|
|
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
|
|
|
// *
|
|
|
|
// * This program is free software: you can redistribute it and/or modify
|
|
|
|
// * it under the terms of the GNU General Public License as published by
|
|
|
|
// * the Free Software Foundation, either version 3 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, see http://www.gnu.org/licenses/.
|
|
|
|
|
|
|
|
// motion.cpp
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "object/motion/motion.h"
|
|
|
|
|
|
|
|
#include "common/iman.h"
|
|
|
|
#include "script/cmdtoken.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Object's constructor.
|
|
|
|
|
|
|
|
CMotion::CMotion(CInstanceManager* iMan, CObject* object)
|
|
|
|
{
|
|
|
|
m_iMan = iMan;
|
|
|
|
m_iMan->AddInstance(CLASS_MOTION, this, 100);
|
|
|
|
|
2012-09-11 20:45:48 +00:00
|
|
|
m_engine = static_cast< Gfx::CEngine* >(m_iMan->SearchInstance(CLASS_ENGINE));
|
|
|
|
m_light = static_cast< Gfx::CLight* >(m_iMan->SearchInstance(CLASS_LIGHT));
|
2012-09-13 15:40:39 +00:00
|
|
|
m_particle = static_cast< Gfx::CParticle* >(m_iMan->SearchInstance(CLASS_PARTICULE));
|
2012-09-11 20:45:48 +00:00
|
|
|
m_terrain = static_cast< Gfx::CTerrain* >(m_iMan->SearchInstance(CLASS_TERRAIN));
|
|
|
|
m_water = static_cast< Gfx::CWater* >(m_iMan->SearchInstance(CLASS_WATER));
|
|
|
|
m_camera = static_cast< Gfx::CCamera* >(m_iMan->SearchInstance(CLASS_CAMERA));
|
|
|
|
m_main = static_cast< CRobotMain* >(m_iMan->SearchInstance(CLASS_MAIN));
|
|
|
|
m_sound = static_cast< CSoundInterface* >(m_iMan->SearchInstance(CLASS_SOUND));
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
m_object = object;
|
|
|
|
m_physics = 0;
|
|
|
|
m_brain = 0;
|
|
|
|
|
|
|
|
m_actionType = -1;
|
|
|
|
m_actionTime = 0.0f;
|
|
|
|
m_progress = 0.0f;
|
|
|
|
|
|
|
|
m_linVibration = Math::Vector(0.0f, 0.0f, 0.0f);
|
|
|
|
m_cirVibration = Math::Vector(0.0f, 0.0f, 0.0f);
|
|
|
|
m_inclinaison = Math::Vector(0.0f, 0.0f, 0.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Object's destructor.
|
|
|
|
|
|
|
|
CMotion::~CMotion()
|
|
|
|
{
|
|
|
|
m_iMan->DeleteInstance(CLASS_MOTION, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deletes the object.
|
|
|
|
|
|
|
|
void CMotion::DeleteObject(bool bAll)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CMotion::SetPhysics(CPhysics* physics)
|
|
|
|
{
|
|
|
|
m_physics = physics;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMotion::SetBrain(CBrain* brain)
|
|
|
|
{
|
|
|
|
m_brain = brain;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Creates.
|
|
|
|
|
|
|
|
bool CMotion::Create(Math::Vector pos, float angle, ObjectType type, float power)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Management of an event.
|
|
|
|
|
|
|
|
bool CMotion::EventProcess(const Event &event)
|
|
|
|
{
|
|
|
|
Math::Vector pos, dir;
|
|
|
|
float time;
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
if ( m_object->GetType() != OBJECT_TOTO &&
|
|
|
|
m_engine->GetPause() ) return true;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-11 20:45:48 +00:00
|
|
|
if ( event.type != EVENT_FRAME ) return true;
|
2012-06-26 21:01:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
m_progress += event.rTime*m_actionTime;
|
|
|
|
if ( m_progress > 1.0f ) m_progress = 1.0f; // (*)
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
pos = m_object->GetPosition(0);
|
|
|
|
if ( pos.y < m_water->GetLevel(m_object) ) // underwater?
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
time = event.rTime*3.0f; // everything is slower
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
time = event.rTime*10.0f;
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
dir = m_object->GetLinVibration();
|
2012-06-26 20:23:05 +00:00
|
|
|
dir.x = Math::Smooth(dir.x, m_linVibration.x, time);
|
|
|
|
dir.y = Math::Smooth(dir.y, m_linVibration.y, time);
|
|
|
|
dir.z = Math::Smooth(dir.z, m_linVibration.z, time);
|
|
|
|
m_object->SetLinVibration(dir);
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
dir = m_object->GetCirVibration();
|
2012-06-26 20:23:05 +00:00
|
|
|
dir.x = Math::Smooth(dir.x, m_cirVibration.x, time);
|
|
|
|
dir.y = Math::Smooth(dir.y, m_cirVibration.y, time);
|
|
|
|
dir.z = Math::Smooth(dir.z, m_cirVibration.z, time);
|
|
|
|
m_object->SetCirVibration(dir);
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
dir = m_object->GetInclinaison();
|
2012-06-26 20:23:05 +00:00
|
|
|
dir.x = Math::Smooth(dir.x, m_inclinaison.x, time);
|
|
|
|
dir.y = Math::Smooth(dir.y, m_inclinaison.y, time);
|
|
|
|
dir.z = Math::Smooth(dir.z, m_inclinaison.z, time);
|
|
|
|
m_object->SetInclinaison(dir);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// (*) Avoids the bug of ants returned by the thumper and
|
|
|
|
// whose abdomen grown to infinity!
|
|
|
|
|
|
|
|
|
|
|
|
// Start an action.
|
|
|
|
|
|
|
|
Error CMotion::SetAction(int action, float time)
|
|
|
|
{
|
|
|
|
m_actionType = action;
|
|
|
|
m_actionTime = 1.0f/time;
|
|
|
|
m_progress = 0.0f;
|
|
|
|
return ERR_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
// Geturns the current action.
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
int CMotion::GetAction()
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
return m_actionType;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Specifies a special parameter.
|
|
|
|
|
|
|
|
bool CMotion::SetParam(int rank, float value)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
float CMotion::GetParam(int rank)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Saves all parameters of the object.
|
|
|
|
|
|
|
|
bool CMotion::Write(char *line)
|
|
|
|
{
|
|
|
|
char name[100];
|
|
|
|
|
|
|
|
if ( m_actionType == -1 ) return false;
|
|
|
|
|
|
|
|
sprintf(name, " mType=%d", m_actionType);
|
|
|
|
strcat(line, name);
|
|
|
|
|
|
|
|
sprintf(name, " mTime=%.2f", m_actionTime);
|
|
|
|
strcat(line, name);
|
|
|
|
|
|
|
|
sprintf(name, " mProgress=%.2f", m_progress);
|
|
|
|
strcat(line, name);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restores all parameters of the object.
|
|
|
|
|
|
|
|
bool CMotion::Read(char *line)
|
|
|
|
{
|
|
|
|
m_actionType = OpInt(line, "mType", -1);
|
|
|
|
m_actionTime = OpFloat(line, "mTime", 0.0f);
|
|
|
|
m_progress = OpFloat(line, "mProgress", 0.0f);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-11 18:59:35 +00:00
|
|
|
// Getes the linear vibration.
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
void CMotion::SetLinVibration(Math::Vector dir)
|
|
|
|
{
|
|
|
|
m_linVibration = dir;
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
Math::Vector CMotion::GetLinVibration()
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
return m_linVibration;
|
|
|
|
}
|
|
|
|
|
2012-08-11 18:59:35 +00:00
|
|
|
// Getes the circular vibration.
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
void CMotion::SetCirVibration(Math::Vector dir)
|
|
|
|
{
|
|
|
|
m_cirVibration = dir;
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
Math::Vector CMotion::GetCirVibration()
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
return m_cirVibration;
|
|
|
|
}
|
|
|
|
|
2012-08-11 18:59:35 +00:00
|
|
|
// Getes the tilt.
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
void CMotion::SetInclinaison(Math::Vector dir)
|
|
|
|
{
|
|
|
|
m_inclinaison = dir;
|
|
|
|
}
|
|
|
|
|
2012-09-10 21:29:38 +00:00
|
|
|
Math::Vector CMotion::GetInclinaison()
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
return m_inclinaison;
|
|
|
|
}
|
|
|
|
|