colobot/src/object/motion/motionvehicle.cpp

2079 lines
76 KiB
C++
Raw Normal View History

// * 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/.
#include "object/motion/motionvehicle.h"
#include "app/app.h"
2012-09-13 15:40:39 +00:00
#include "graphics/engine/modelfile.h"
#include "graphics/engine/particle.h"
#include "graphics/engine/terrain.h"
#include "math/geometry.h"
#include "object/brain.h"
#include "physics/physics.h"
#include <stdio.h>
#include <string.h>
// Object's constructor.
CMotionVehicle::CMotionVehicle(CInstanceManager* iMan, CObject* object)
: CMotion(iMan, object)
{
int i;
for ( i=0 ; i<4 ; i++ )
{
m_wheelTurn[i] = 0.0f;
}
for ( i=0 ; i<3 ; i++ )
{
m_flyPaw[i] = 0.0f;
}
m_posTrackLeft = 0.0f;
m_posTrackRight = 0.0f;
m_partiReactor = -1;
m_armTimeAbs = 1000.0f;
m_armMember = 1000.0f;
m_canonTime = 0.0f;
m_lastTimeCanon = 0.0f;
m_wheelLastPos = Math::Vector(0.0f, 0.0f, 0.0f);
m_wheelLastAngle = Math::Vector(0.0f, 0.0f, 0.0f);
m_posKey = Math::Vector(0.0f, 0.0f, 0.0f);
m_bFlyFix = false;
m_bTraceDown = false;
m_traceColor = 1; // black
m_traceWidth = 0.5f;
}
// Object's destructor.
CMotionVehicle::~CMotionVehicle()
{
}
// Removes an object.
void CMotionVehicle::DeleteObject(bool bAll)
{
if ( m_partiReactor != -1 )
{
2012-09-13 15:40:39 +00:00
m_particle->DeleteParticle(m_partiReactor);
m_partiReactor = -1;
}
}
// Creates a vehicle traveling any lands on the ground.
bool CMotionVehicle::Create(Math::Vector pos, float angle, ObjectType type,
float power)
{
2012-09-13 15:40:39 +00:00
Gfx::CModelFile* pModFile;
CObject* pPower;
int rank, i, j, parent;
2012-09-13 15:40:39 +00:00
Gfx::Color color;
char name[50];
2012-09-13 15:40:39 +00:00
// if ( m_engine->GetRestCreate() < 1+5+18+1 ) return false;
2012-09-13 15:40:39 +00:00
pModFile = new Gfx::CModelFile(m_iMan);
m_object->SetType(type);
// Creates the main base.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_VEHICULE); // this is a moving object
m_object->SetObjectRank(0, rank);
if ( type == OBJECT_MOBILEfa ||
type == OBJECT_MOBILEfc ||
type == OBJECT_MOBILEfi ||
type == OBJECT_MOBILEfs )
{
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem1f.mod"));
}
if ( type == OBJECT_MOBILEta ||
type == OBJECT_MOBILEtc ||
type == OBJECT_MOBILEti ||
type == OBJECT_MOBILEts )
{
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem1t.mod"));
}
if ( type == OBJECT_MOBILEwa ||
type == OBJECT_MOBILEwc ||
type == OBJECT_MOBILEwi ||
type == OBJECT_MOBILEws )
{
2012-09-13 15:40:39 +00:00
if ( m_object->GetTrainer() )
{
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem1wt.mod"));
}
else
{
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem1w.mod"));
}
}
if ( type == OBJECT_MOBILEia ||
type == OBJECT_MOBILEic ||
type == OBJECT_MOBILEii ||
type == OBJECT_MOBILEis )
{
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem1i.mod"));
}
if ( type == OBJECT_MOBILErt ||
type == OBJECT_MOBILErc ||
type == OBJECT_MOBILErr ||
type == OBJECT_MOBILErs )
{
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller1.mod"));
}
if ( type == OBJECT_MOBILEsa )
{
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "subm1.mod"));
}
if ( type == OBJECT_MOBILEtg )
{
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "target.mod"));
}
if ( type == OBJECT_MOBILEwt )
{
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "trainerw.mod"));
}
if ( type == OBJECT_MOBILEft )
{
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "trainerf.mod"));
}
if ( type == OBJECT_MOBILEtt )
{
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "trainert.mod"));
}
if ( type == OBJECT_MOBILEit )
{
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "traineri.mod"));
}
if ( type == OBJECT_MOBILEdr )
{
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "drawer1.mod"));
}
if ( type == OBJECT_APOLLO2 )
{
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj1.mod"));
}
pModFile->CreateEngineObject(rank);
m_object->SetPosition(0, pos);
m_object->SetAngleY(0, angle);
// A vehicle must have a obligatory collision
// with a sphere of center (0, y, 0) (see GetCrashSphere).
if ( type == OBJECT_MOBILErt ||
type == OBJECT_MOBILErc ||
type == OBJECT_MOBILErr ||
type == OBJECT_MOBILErs )
{
m_object->CreateCrashSphere(Math::Vector(0.0f, 4.0f, 0.0f), 6.5f, SOUND_BOUMm, 0.45f);
m_object->SetGlobalSphere(Math::Vector(0.0f, 3.0f, 0.0f), 7.0f);
}
else if ( type == OBJECT_MOBILEsa )
{
m_object->CreateCrashSphere(Math::Vector(0.0f, 3.0f, 0.0f), 4.5f, SOUND_BOUMm, 0.45f);
m_object->SetGlobalSphere(Math::Vector(0.0f, 3.0f, 0.0f), 6.0f);
}
else if ( type == OBJECT_MOBILEdr )
{
m_object->CreateCrashSphere(Math::Vector(0.0f, 3.0f, 0.0f), 5.0f, SOUND_BOUMm, 0.45f);
m_object->SetGlobalSphere(Math::Vector(0.0f, 3.0f, 0.0f), 7.0f);
}
else if ( type == OBJECT_APOLLO2 )
{
m_object->CreateCrashSphere(Math::Vector(0.0f, 0.0f, 0.0f), 8.0f, SOUND_BOUMm, 0.45f);
}
else
{
m_object->CreateCrashSphere(Math::Vector(0.0f, 3.0f, 0.0f), 4.5f, SOUND_BOUMm, 0.45f);
m_object->SetGlobalSphere(Math::Vector(0.0f, 4.0f, 0.0f), 6.0f);
}
if ( type == OBJECT_MOBILEfa ||
type == OBJECT_MOBILEta ||
type == OBJECT_MOBILEwa ||
type == OBJECT_MOBILEia )
{
// Creates the arm.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(1, Math::Vector(0.0f, 5.3f, 0.0f));
m_object->SetAngleZ(1, ARM_NEUTRAL_ANGLE1);
// Creates the forearm.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 1);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem3.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(2, Math::Vector(5.0f, 0.0f, 0.0f));
m_object->SetAngleZ(2, ARM_NEUTRAL_ANGLE2);
// Creates the hand.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(3, rank);
m_object->SetObjectParent(3, 2);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem4.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(3, Math::Vector(3.5f, 0.0f, 0.0f));
m_object->SetAngleZ(3, ARM_NEUTRAL_ANGLE3);
m_object->SetAngleX(3, Math::PI/2.0f);
// Creates the close clamp.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(4, rank);
m_object->SetObjectParent(4, 3);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem5.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(4, Math::Vector(1.5f, 0.0f, 0.0f));
m_object->SetAngleZ(4, -Math::PI*0.10f);
// Creates the remote clamp.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(5, rank);
m_object->SetObjectParent(5, 3);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem6.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(5, Math::Vector(1.5f, 0.0f, 0.0f));
m_object->SetAngleZ(5, Math::PI*0.10f);
}
if ( type == OBJECT_MOBILEfs ||
type == OBJECT_MOBILEts ||
type == OBJECT_MOBILEws ||
type == OBJECT_MOBILEis )
{
// Creates the arm.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(1, Math::Vector(0.0f, 5.3f, 0.0f));
m_object->SetAngleZ(1, 110.0f*Math::PI/180.0f);
// Creates the forearm.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 1);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem3.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(2, Math::Vector(5.0f, 0.0f, 0.0f));
m_object->SetAngleZ(2, -110.0f*Math::PI/180.0f);
// Creates the sensor.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(3, rank);
m_object->SetObjectParent(3, 2);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem4s.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(3, Math::Vector(3.5f, 0.0f, 0.0f));
m_object->SetAngleZ(3, -65.0f*Math::PI/180.0f);
}
if ( type == OBJECT_MOBILEfc ||
type == OBJECT_MOBILEtc ||
type == OBJECT_MOBILEwc ||
type == OBJECT_MOBILEic )
{
// Creates the cannon.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "canon.mod"));
pModFile->CreateEngineObject(rank);
//? m_object->SetPosition(1, Math::Vector(0.0f, 5.3f, 0.0f));
m_object->SetPosition(1, Math::Vector(0.0f, 5.3f, 0.0f));
m_object->SetAngleZ(1, 0.0f);
}
if ( type == OBJECT_MOBILEfi ||
type == OBJECT_MOBILEti ||
type == OBJECT_MOBILEwi ||
type == OBJECT_MOBILEii )
{
// Creates the insect cannon.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "canoni1.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(1, Math::Vector(0.0f, 5.3f, 0.0f));
m_object->SetAngleZ(1, 0.0f);
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 1);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "canoni2.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(2, Math::Vector(0.0f, 2.5f, 0.0f));
m_object->SetAngleZ(2, 0.0f);
}
if ( type == OBJECT_MOBILEwa ||
type == OBJECT_MOBILEwc ||
type == OBJECT_MOBILEws ||
type == OBJECT_MOBILEwi ||
type == OBJECT_MOBILEwt )
{
// Creates the right-back wheel.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(6, Math::Vector(-3.0f, 1.0f, -3.0f));
// Creates the left-back wheel.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(7, Math::Vector(-3.0f, 1.0f, 3.0f));
m_object->SetAngleY(7, Math::PI);
// Creates the right-front wheel.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(8, rank);
m_object->SetObjectParent(8, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(8, Math::Vector(2.0f, 1.0f, -3.0f));
// Creates the left-front wheel.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(9, rank);
m_object->SetObjectParent(9, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(9, Math::Vector(2.0f, 1.0f, 3.0f));
m_object->SetAngleY(9, Math::PI);
}
if ( type == OBJECT_MOBILEtg )
{
// Creates the right-back wheel.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(6, Math::Vector(-2.0f, 1.0f, -3.0f));
// Creates the left-back wheel.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(7, Math::Vector(-2.0f, 1.0f, 3.0f));
m_object->SetAngleY(7, Math::PI);
// Creates the right-front wheel.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(8, rank);
m_object->SetObjectParent(8, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(8, Math::Vector(3.0f, 1.0f, -3.0f));
// Creates the left-front wheel.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(9, rank);
m_object->SetObjectParent(9, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2w.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(9, Math::Vector(3.0f, 1.0f, 3.0f));
m_object->SetAngleY(9, Math::PI);
}
if ( type == OBJECT_MOBILEta ||
type == OBJECT_MOBILEtc ||
type == OBJECT_MOBILEti ||
type == OBJECT_MOBILEts ) // caterpillars?
{
// Creates the right caterpillar.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2t.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(6, Math::Vector(0.0f, 2.0f, -3.0f));
// Creates the left caterpillar.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem3t.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(7, Math::Vector(0.0f, 2.0f, 3.0f));
}
if ( type == OBJECT_MOBILErt ||
type == OBJECT_MOBILErc ||
type == OBJECT_MOBILErr ||
type == OBJECT_MOBILErs ) // large caterpillars?
{
// Creates the right caterpillar.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller2.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(6, Math::Vector(0.0f, 2.0f, -3.0f));
// Creates the left caterpillar.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller3.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(7, Math::Vector(0.0f, 2.0f, 3.0f));
}
if ( type == OBJECT_MOBILEsa ) // underwater caterpillars?
{
// Creates the right caterpillar.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "subm4.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(6, Math::Vector(0.0f, 1.0f, -3.0f));
// Creates the left caterpillar.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "subm5.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(7, Math::Vector(0.0f, 1.0f, 3.0f));
}
if ( type == OBJECT_MOBILEdr ) // caterpillars?
{
// Creates the right caterpillar.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "drawer2.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(6, Math::Vector(0.0f, 1.0f, -3.0f));
// Creates the left caterpillar.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "drawer3.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(7, Math::Vector(0.0f, 1.0f, 3.0f));
}
if ( type == OBJECT_MOBILEfa ||
type == OBJECT_MOBILEfc ||
type == OBJECT_MOBILEfs ||
type == OBJECT_MOBILEfi ||
type == OBJECT_MOBILEft ) // flying?
{
// Creates the front foot.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2f.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(6, Math::Vector(1.7f, 3.0f, 0.0f));
// Creates the right-back foot.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2f.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(7, Math::Vector(-1.8f, 3.0f, -1.5f));
m_object->SetAngleY(7, 120.0f*Math::PI/180.0f);
// Creates the left-back foot.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(8, rank);
m_object->SetObjectParent(8, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "lem2f.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(8, Math::Vector(-1.8f, 3.0f, 1.5f));
m_object->SetAngleY(8, -120.0f*Math::PI/180.0f);
}
if ( type == OBJECT_MOBILEia ||
type == OBJECT_MOBILEic ||
type == OBJECT_MOBILEis ||
type == OBJECT_MOBILEii ) // insect legs?
{
float table[] =
{
// x y z
-1.5f, 1.2f, -0.7f, // back leg
0.0f, 0.0f, -1.0f,
0.0f, 0.0f, -2.0f,
0.0f, 1.2f, -0.9f, // middle leg
0.0f, 0.0f, -1.0f,
0.0f, 0.0f, -2.0f,
1.5f, 1.2f, -0.7f, // front leg
0.0f, 0.0f, -1.0f,
0.0f, 0.0f, -2.0f,
};
for ( i=0 ; i<3 ; i++ )
{
for ( j=0 ; j<3 ; j++ )
{
std::string baseName = m_app->GetDataFilePath(DIR_MODEL, "ant%d.mod");
sprintf(name, baseName.c_str(), j+4); // 4..6
// Creates the right leg.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6+i*3+j, rank);
if ( j == 0 ) parent = 0;
else parent = 6+i*3+j-1;
m_object->SetObjectParent(6+i*3+j, parent);
pModFile->ReadModel(name);
pModFile->CreateEngineObject(rank);
pos.x = table[i*9+j*3+0];
pos.y = table[i*9+j*3+1];
pos.z = table[i*9+j*3+2];
m_object->SetPosition(6+i*3+j, pos);
// Creates the left leg.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(15+i*3+j, rank);
if ( j == 0 ) parent = 0;
else parent = 15+i*3+j-1;
m_object->SetObjectParent(15+i*3+j, parent);
pModFile->ReadModel(name);
pModFile->Mirror();
pModFile->CreateEngineObject(rank);
pos.x = table[i*9+j*3+0];
pos.y = table[i*9+j*3+1];
pos.z = -table[i*9+j*3+2];
m_object->SetPosition(15+i*3+j, pos);
}
}
}
if ( type == OBJECT_MOBILErt )
{
// Creates the holder.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller2t.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(1, Math::Vector(0.0f, 0.0f, 0.0f));
m_object->SetAngleZ(1, 0.0f);
// Creates the pestle.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller3t.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(2, Math::Vector(9.0f, 4.0f, 0.0f));
m_object->SetAngleZ(2, 0.0f);
}
if ( type == OBJECT_MOBILErc )
{
// Creates the holder.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller2c.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(1, Math::Vector(3.0f, 4.6f, 0.0f));
m_object->SetAngleZ(1, Math::PI/8.0f);
// Creates the cannon.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller3p.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(2, Math::Vector(7.0f, 6.5f, 0.0f));
m_object->SetAngleZ(2, 0.0f);
}
if ( type == OBJECT_MOBILErr )
{
// Creates the holder.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "recover1.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(1, Math::Vector(2.0f, 5.0f, 0.0f));
// Creates the right arm.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 1);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "recover2.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(2, Math::Vector(0.1f, 0.0f, -5.0f));
m_object->SetAngleZ(2, 126.0f*Math::PI/180.0f);
// Creates the right forearm.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(3, rank);
m_object->SetObjectParent(3, 2);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "recover3.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(3, Math::Vector(5.0f, 0.0f, -0.5f));
m_object->SetAngleZ(3, -144.0f*Math::PI/180.0f);
// Creates the left arm.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(4, rank);
m_object->SetObjectParent(4, 1);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "recover2.mod"));
pModFile->Mirror();
pModFile->CreateEngineObject(rank);
m_object->SetPosition(4, Math::Vector(0.1f, 0.0f, 5.0f));
m_object->SetAngleZ(4, 126.0f*Math::PI/180.0f);
// Creates the left forearm.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(5, rank);
m_object->SetObjectParent(5, 4);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "recover3.mod"));
pModFile->Mirror();
pModFile->CreateEngineObject(rank);
m_object->SetPosition(5, Math::Vector(5.0f, 0.0f, 0.5f));
m_object->SetAngleZ(5, -144.0f*Math::PI/180.0f);
}
if ( type == OBJECT_MOBILErs )
{
// Creates the holder.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller2s.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(1, Math::Vector(0.0f, 0.0f, 0.0f));
m_object->SetAngleZ(1, 0.0f);
// Creates the intermediate piston.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 1);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller3s.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(2, Math::Vector(7.0f, 4.5f, 0.0f));
m_object->SetAngleZ(2, 0.0f);
// Creates the piston with the sphere.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(3, rank);
m_object->SetObjectParent(3, 2);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "roller4s.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(3, Math::Vector(0.0f, 1.0f, 0.0f));
m_object->SetAngleZ(3, 0.0f);
}
if ( type == OBJECT_MOBILEsa )
{
// Creates the holder.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "subm2.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(1, Math::Vector(4.2f, 3.0f, 0.0f));
// Creates the right tong.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 1);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "subm3.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(2, Math::Vector(0.5f, 0.0f, -1.5f));
// Creates the left tong.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(3, rank);
m_object->SetObjectParent(3, 1);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "subm3.mod"));
pModFile->Mirror();
pModFile->CreateEngineObject(rank);
m_object->SetPosition(3, Math::Vector(0.5f, 0.0f, 1.5f));
}
if ( type == OBJECT_MOBILEdr )
{
// Creates the carousel.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "drawer4.mod"));
pModFile->CreateEngineObject(rank);
m_object->SetPosition(1, Math::Vector(-3.0f, 3.0f, 0.0f));
// Creates the key.
2012-09-13 15:40:39 +00:00
if ( m_object->GetToy() )
{
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "drawer5.mod"));
pModFile->CreateEngineObject(rank);
m_posKey = Math::Vector(3.0f, 5.7f, 0.0f);
m_object->SetPosition(2, m_posKey);
m_object->SetAngleY(2, 90.0f*Math::PI/180.0f);
}
// Creates pencils.
for ( i=0 ; i<8 ; i++ )
{
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(10+i, rank);
m_object->SetObjectParent(10+i, 1);
std::string baseName = m_app->GetDataFilePath(DIR_MODEL, "drawer%d.mod");
sprintf(name, baseName.c_str(), 10+i);
pModFile->ReadModel(name);
pModFile->CreateEngineObject(rank);
m_object->SetPosition(10+i, Math::Vector(0.0f, 0.0f, 0.0f));
m_object->SetAngleY(10+i, 45.0f*Math::PI/180.0f*i);
}
}
if ( type == OBJECT_MOBILEwt )
{
// Creates the key.
2012-09-13 15:40:39 +00:00
if ( m_object->GetToy() )
{
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "drawer5.mod"));
pModFile->CreateEngineObject(rank);
m_posKey = Math::Vector(0.2f, 4.1f, 0.0f);
m_object->SetPosition(2, m_posKey);
m_object->SetAngleY(2, 90.0f*Math::PI/180.0f);
}
}
if ( type == OBJECT_APOLLO2 )
{
// Creates the accessories.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(1, rank);
m_object->SetObjectParent(1, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj2.mod")); // antenna
pModFile->CreateEngineObject(rank);
m_object->SetPosition(1, Math::Vector(5.5f, 8.8f, 2.0f));
m_object->SetAngleY(1, -120.0f*Math::PI/180.0f);
m_object->SetAngleZ(1, 45.0f*Math::PI/180.0f);
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(2, rank);
m_object->SetObjectParent(2, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj3.mod")); // camera
pModFile->CreateEngineObject(rank);
m_object->SetPosition(2, Math::Vector(5.5f, 2.8f, -2.0f));
m_object->SetAngleY(2, 30.0f*Math::PI/180.0f);
// Creates the wheels.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(6, rank);
m_object->SetObjectParent(6, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel
pModFile->CreateEngineObject(rank);
m_object->SetPosition(6, Math::Vector(-5.75f, 1.65f, -5.0f));
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(7, rank);
m_object->SetObjectParent(7, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel
pModFile->CreateEngineObject(rank);
m_object->SetPosition(7, Math::Vector(-5.75f, 1.65f, 5.0f));
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(8, rank);
m_object->SetObjectParent(8, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel
pModFile->CreateEngineObject(rank);
m_object->SetPosition(8, Math::Vector(5.75f, 1.65f, -5.0f));
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(9, rank);
m_object->SetObjectParent(9, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj4.mod")); // wheel
pModFile->CreateEngineObject(rank);
m_object->SetPosition(9, Math::Vector(5.75f, 1.65f, 5.00f));
// Creates mud guards.
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(10, rank);
m_object->SetObjectParent(10, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj6.mod")); // wheel
pModFile->CreateEngineObject(rank);
m_object->SetPosition(10, Math::Vector(-5.75f, 1.65f, -5.0f));
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(11, rank);
m_object->SetObjectParent(11, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj6.mod")); // wheel
pModFile->CreateEngineObject(rank);
m_object->SetPosition(11, Math::Vector(-5.75f, 1.65f, 5.0f));
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(12, rank);
m_object->SetObjectParent(12, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj5.mod")); // wheel
pModFile->CreateEngineObject(rank);
m_object->SetPosition(12, Math::Vector(5.75f, 1.65f, -5.0f));
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_DESCENDANT);
m_object->SetObjectRank(13, rank);
m_object->SetObjectParent(13, 0);
pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "apolloj5.mod")); // wheel
pModFile->CreateEngineObject(rank);
m_object->SetPosition(13, Math::Vector(5.75f, 1.65f, 5.00f));
}
#if 1
if ( type == OBJECT_MOBILErt ||
type == OBJECT_MOBILErc ||
type == OBJECT_MOBILErr ||
type == OBJECT_MOBILErs )
{
m_object->CreateShadowCircle(6.0f, 1.0f);
}
else if ( type == OBJECT_MOBILEta ||
type == OBJECT_MOBILEtc ||
type == OBJECT_MOBILEti ||
type == OBJECT_MOBILEts ||
type == OBJECT_MOBILEsa )
{
m_object->CreateShadowCircle(5.0f, 1.0f);
}
else if ( type == OBJECT_MOBILEdr )
{
m_object->CreateShadowCircle(4.5f, 1.0f);
}
else if ( type == OBJECT_APOLLO2 )
{
m_object->CreateShadowCircle(7.0f, 0.8f);
}
else
{
m_object->CreateShadowCircle(4.0f, 1.0f);
}
#else
if ( type == OBJECT_MOBILErt ||
type == OBJECT_MOBILErc ||
type == OBJECT_MOBILErr ||
type == OBJECT_MOBILErs )
{
m_object->CreateShadowCircle(6.0f, 1.0f, D3DSHADOWTANK);
}
else if ( type == OBJECT_MOBILEta ||
type == OBJECT_MOBILEtc ||
type == OBJECT_MOBILEti ||
type == OBJECT_MOBILEts )
{
m_object->CreateShadowCircle(4.0f, 1.0f, D3DSHADOWTANK);
}
else if ( type == OBJECT_MOBILEfa ||
type == OBJECT_MOBILEfc ||
type == OBJECT_MOBILEfi ||
type == OBJECT_MOBILEfs )
{
m_object->CreateShadowCircle(4.0f, 1.0f, D3DSHADOWFLY);
}
else if ( type == OBJECT_MOBILEwa ||
type == OBJECT_MOBILEwc ||
type == OBJECT_MOBILEwi ||
type == OBJECT_MOBILEws )
{
m_object->CreateShadowCircle(4.0f, 1.0f, D3DSHADOWWHEEL);
}
else if ( type == OBJECT_APOLLO2 )
{
m_object->CreateShadowCircle(6.0f, 0.8f);
}
else
{
m_object->CreateShadowCircle(4.0f, 1.0f, D3DSHADOWNORM);
}
#endif
if ( type == OBJECT_MOBILEfa ||
type == OBJECT_MOBILEfc ||
type == OBJECT_MOBILEfi ||
type == OBJECT_MOBILEfs ||
type == OBJECT_MOBILEft ) // flying?
{
//? color.r = 0.5f-1.0f;
//? color.g = 0.2f-1.0f;
//? color.b = 0.0f-1.0f; // orange
//? color.r = 0.8f;
//? color.g = 0.6f;
//? color.b = 0.0f; // yellow-orange
color.r = 0.0f;
color.g = 0.4f;
color.b = 0.8f; // blue
color.a = 0.0f;
m_object->CreateShadowLight(50.0f, color);
}
CreatePhysics(type);
m_object->SetFloorHeight(0.0f);
if ( power > 0.0f &&
type != OBJECT_MOBILEdr &&
type != OBJECT_APOLLO2 )
{
color.r = 1.0f;
color.g = 1.0f;
color.b = 0.0f; // yellow
color.a = 0.0f;
m_object->CreateEffectLight(20.0f, color);
// Creates the battery.
pPower = new CObject(m_iMan);
pPower->SetType(power<=1.0f?OBJECT_POWER:OBJECT_ATOMIC);
rank = m_engine->CreateObject();
2012-09-13 15:40:39 +00:00
m_engine->SetObjectType(rank, Gfx::ENG_OBJTYPE_FIX);
pPower->SetObjectRank(0, rank);
if ( power <= 1.0f ) pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "power.mod"));
else pModFile->ReadModel(m_app->GetDataFilePath(DIR_MODEL, "atomic.mod"));
pModFile->CreateEngineObject(rank);
2012-09-13 15:40:39 +00:00
pPower->SetPosition(0, m_object->GetCharacter()->posPower);
pPower->CreateCrashSphere(Math::Vector(0.0f, 1.0f, 0.0f), 1.0f, SOUND_BOUMm, 0.45f);
pPower->SetGlobalSphere(Math::Vector(0.0f, 1.0f, 0.0f), 1.5f);
pPower->SetTruck(m_object);
m_object->SetPower(pPower);
if ( power <= 1.0f ) pPower->SetEnergy(power);
else pPower->SetEnergy(power/100.0f);
}
2012-09-13 15:40:39 +00:00
pos = m_object->GetPosition(0);
m_object->SetPosition(0, pos); //to display the shadows immediately
2012-09-13 15:40:39 +00:00
m_engine->LoadAllTextures();
delete pModFile;
return true;
}
// Creates the physics of the object.
void CMotionVehicle::CreatePhysics(ObjectType type)
{
Character* character;
2012-09-13 15:40:39 +00:00
character = m_object->GetCharacter();
if ( type == OBJECT_MOBILEwa ||
type == OBJECT_MOBILEwc ||
type == OBJECT_MOBILEwi ||
type == OBJECT_MOBILEws ||
type == OBJECT_MOBILEwt ) // wheels?
{
m_physics->SetType(TYPE_ROLLING);
character->wheelFront = 3.0f;
character->wheelBack = 4.0f;
character->wheelLeft = 4.0f;
character->wheelRight = 4.0f;
character->posPower = Math::Vector(-3.2f, 3.0f, 0.0f);
m_physics->SetLinMotionX(MO_ADVSPEED, 20.0f);
m_physics->SetLinMotionX(MO_RECSPEED, 10.0f);
m_physics->SetLinMotionX(MO_ADVACCEL, 40.0f);
m_physics->SetLinMotionX(MO_RECACCEL, 20.0f);
m_physics->SetLinMotionX(MO_STOACCEL, 40.0f);
m_physics->SetLinMotionX(MO_TERSLIDE, 5.0f);
m_physics->SetLinMotionZ(MO_TERSLIDE, 5.0f);
m_physics->SetLinMotionX(MO_TERFORCE, 50.0f);
m_physics->SetLinMotionZ(MO_TERFORCE, 30.0f);
m_physics->SetLinMotionZ(MO_MOTACCEL, 20.0f);
m_physics->SetCirMotionY(MO_ADVSPEED, 0.8f*Math::PI);
m_physics->SetCirMotionY(MO_RECSPEED, 0.8f*Math::PI);
m_physics->SetCirMotionY(MO_ADVACCEL, 8.0f);
m_physics->SetCirMotionY(MO_RECACCEL, 8.0f);
m_physics->SetCirMotionY(MO_STOACCEL, 12.0f);
}
if ( type == OBJECT_MOBILEtg )
{
m_physics->SetType(TYPE_ROLLING);
character->wheelFront = 4.0f;
character->wheelBack = 3.0f;
character->wheelLeft = 4.0f;
character->wheelRight = 4.0f;
character->posPower = Math::Vector(-3.2f, 3.0f, 0.0f);
m_physics->SetLinMotionX(MO_ADVSPEED, 20.0f);
m_physics->SetLinMotionX(MO_RECSPEED, 10.0f);
m_physics->SetLinMotionX(MO_ADVACCEL, 40.0f);
m_physics->SetLinMotionX(MO_RECACCEL, 20.0f);
m_physics->SetLinMotionX(MO_STOACCEL, 40.0f);
m_physics->SetLinMotionX(MO_TERSLIDE, 5.0f);
m_physics->SetLinMotionZ(MO_TERSLIDE, 5.0f);
m_physics->SetLinMotionX(MO_TERFORCE, 50.0f);
m_physics->SetLinMotionZ(MO_TERFORCE, 20.0f);
m_physics->SetLinMotionZ(MO_MOTACCEL, 20.0f);
m_physics->SetCirMotionY(MO_ADVSPEED, 0.8f*Math::PI);
m_physics->SetCirMotionY(MO_RECSPEED, 0.8f*Math::PI);
m_physics->SetCirMotionY(MO_ADVACCEL, 10.0f);
m_physics->SetCirMotionY(MO_RECACCEL, 10.0f);
m_physics->SetCirMotionY(MO_STOACCEL, 15.0f);
}
if ( type == OBJECT_MOBILEta ||
type == OBJECT_MOBILEtc ||
type == OBJECT_MOBILEti ||
type == OBJECT_MOBILEts ) // caterpillars?
{
m_physics->SetType(TYPE_ROLLING);
character->wheelFront = 4.0f;
character->wheelBack = 4.0f;
character->wheelLeft = 4.8f;
character->wheelRight = 4.8f;
character->posPower = Math::Vector(-3.2f, 3.0f, 0.0f);
m_physics->SetLinMotionX(MO_ADVSPEED, 15.0f);
m_physics->SetLinMotionX(MO_RECSPEED, 8.0f);
m_physics->SetLinMotionX(MO_ADVACCEL, 15.0f);
m_physics->SetLinMotionX(MO_RECACCEL, 8.0f);
m_physics->SetLinMotionX(MO_STOACCEL, 40.0f);
m_physics->SetLinMotionX(MO_TERSLIDE, 5.0f);
m_physics->SetLinMotionZ(MO_TERSLIDE, 5.0f);
m_physics->SetLinMotionX(MO_TERFORCE, 20.0f);
m_physics->SetLinMotionZ(MO_TERFORCE, 10.0f);
m_physics->SetLinMotionZ(MO_MOTACCEL, 40.0f);
m_physics->SetCirMotionY(MO_ADVSPEED, 0.5f*Math::PI);
m_physics->SetCirMotionY(MO_RECSPEED, 0.5f*Math::PI);
m_physics->SetCirMotionY(MO_ADVACCEL, 10.0f);
m_physics->SetCirMotionY(MO_RECACCEL, 10.0f);
m_physics->SetCirMotionY(MO_STOACCEL, 6.0f);
}
if ( type == OBJECT_MOBILEia ||
type == OBJECT_MOBILEic ||
type == OBJECT_MOBILEii ||
type == OBJECT_MOBILEis ) // legs?
{
m_physics->SetType(TYPE_ROLLING);
character->wheelFront = 4.0f;
character->wheelBack = 4.0f;
character->wheelLeft = 5.0f;
character->wheelRight = 5.0f;
character->posPower = Math::Vector(-3.2f, 3.0f, 0.0f);
m_physics->SetLinMotionX(MO_ADVSPEED, 15.0f);
m_physics->SetLinMotionX(MO_RECSPEED, 8.0f);
m_physics->SetLinMotionX(MO_ADVACCEL, 40.0f);
m_physics->SetLinMotionX(MO_RECACCEL, 20.0f);
m_physics->SetLinMotionX(MO_STOACCEL, 40.0f);
m_physics->SetLinMotionX(MO_TERSLIDE, 5.0f);
m_physics->SetLinMotionZ(MO_TERSLIDE, 5.0f);
m_physics->SetLinMotionX(MO_TERFORCE, 10.0f);
//? m_physics->SetLinMotionX(MO_TERFORCE, 15.0f);
m_physics->SetLinMotionZ(MO_TERFORCE, 10.0f);
m_physics->SetLinMotionZ(MO_MOTACCEL, 40.0f);
m_physics->SetCirMotionY(MO_ADVSPEED, 0.5f*Math::PI);
m_physics->SetCirMotionY(MO_RECSPEED, 0.5f*Math::PI);
m_physics->SetCirMotionY(MO_ADVACCEL, 10.0f);
m_physics->SetCirMotionY(MO_RECACCEL, 10.0f);
m_physics->SetCirMotionY(MO_STOACCEL, 15.0f);
}
if ( type == OBJECT_MOBILEfa ||
type == OBJECT_MOBILEfc ||
type == OBJECT_MOBILEfi ||
type == OBJECT_MOBILEfs ||
type == OBJECT_MOBILEft ) // flying?
{
m_physics->SetType(TYPE_FLYING);
character->wheelFront = 5.0f;
character->wheelBack = 4.0f;
character->wheelLeft = 4.5f;
character->wheelRight = 4.5f;
character->posPower = Math::Vector(-3.2f, 3.0f, 0.0f);
m_physics->SetLinMotionX(MO_ADVSPEED, 50.0f);
m_physics->SetLinMotionX(MO_RECSPEED, 50.0f);
m_physics->SetLinMotionX(MO_ADVACCEL, 20.0f);
m_physics->SetLinMotionX(MO_RECACCEL, 20.0f);
m_physics->SetLinMotionX(MO_STOACCEL, 20.0f);
m_physics->SetLinMotionX(MO_TERSLIDE, 5.0f);
m_physics->SetLinMotionZ(MO_TERSLIDE, 5.0f);
m_physics->SetLinMotionX(MO_TERFORCE, 50.0f);
m_physics->SetLinMotionZ(MO_TERFORCE, 50.0f);
m_physics->SetLinMotionZ(MO_MOTACCEL, 40.0f);
m_physics->SetLinMotionY(MO_ADVSPEED, 60.0f);
m_physics->SetLinMotionY(MO_RECSPEED, 60.0f);
m_physics->SetLinMotionY(MO_ADVACCEL, 20.0f);
m_physics->SetLinMotionY(MO_RECACCEL, 50.0f);
m_physics->SetLinMotionY(MO_STOACCEL, 50.0f);
m_physics->SetCirMotionY(MO_ADVSPEED, 0.4f*Math::PI);
m_physics->SetCirMotionY(MO_RECSPEED, 0.4f*Math::PI);
m_physics->SetCirMotionY(MO_ADVACCEL, 2.0f);
m_physics->SetCirMotionY(MO_RECACCEL, 2.0f);
m_physics->SetCirMotionY(MO_STOACCEL, 2.0f);
}
if ( type == OBJECT_MOBILErt ||
type == OBJECT_MOBILErc ||
type == OBJECT_MOBILErr ||
type == OBJECT_MOBILErs ) // large caterpillars?
{
m_physics->SetType(TYPE_ROLLING);
character->wheelFront = 5.0f;
character->wheelBack = 5.0f;
character->wheelLeft = 6.0f;
character->wheelRight = 6.0f;
character->posPower = Math::Vector(-5.8f, 4.0f, 0.0f);
m_physics->SetLinMotionX(MO_ADVSPEED, 10.0f);
m_physics->SetLinMotionX(MO_RECSPEED, 5.0f);
m_physics->SetLinMotionX(MO_ADVACCEL, 10.0f);
m_physics->SetLinMotionX(MO_RECACCEL, 5.0f);
m_physics->SetLinMotionX(MO_STOACCEL, 40.0f);
m_physics->SetLinMotionX(MO_TERSLIDE, 5.0f);
m_physics->SetLinMotionZ(MO_TERSLIDE, 5.0f);
m_physics->SetLinMotionX(MO_TERFORCE, 20.0f);
m_physics->SetLinMotionZ(MO_TERFORCE, 10.0f);
m_physics->SetLinMotionZ(MO_MOTACCEL, 40.0f);
m_physics->SetCirMotionY(MO_ADVSPEED, 0.3f*Math::PI);
m_physics->SetCirMotionY(MO_RECSPEED, 0.3f*Math::PI);
m_physics->SetCirMotionY(MO_ADVACCEL, 2.0f);
m_physics->SetCirMotionY(MO_RECACCEL, 2.0f);
m_physics->SetCirMotionY(MO_STOACCEL, 4.0f);
}
if ( type == OBJECT_MOBILEsa )
{
m_physics->SetType(TYPE_ROLLING);
character->wheelFront = 4.0f;
character->wheelBack = 4.0f;
character->wheelLeft = 4.0f;
character->wheelRight = 4.0f;
character->posPower = Math::Vector(-5.0f, 3.0f, 0.0f);
m_physics->SetLinMotionX(MO_ADVSPEED, 15.0f);
m_physics->SetLinMotionX(MO_RECSPEED, 10.0f);
m_physics->SetLinMotionX(MO_ADVACCEL, 20.0f);
m_physics->SetLinMotionX(MO_RECACCEL, 10.0f);
m_physics->SetLinMotionX(MO_STOACCEL, 40.0f);
m_physics->SetLinMotionX(MO_TERSLIDE, 5.0f);
m_physics->SetLinMotionZ(MO_TERSLIDE, 5.0f);
m_physics->SetLinMotionX(MO_TERFORCE, 20.0f);
m_physics->SetLinMotionZ(MO_TERFORCE, 10.0f);
m_physics->SetLinMotionZ(MO_MOTACCEL, 40.0f);
m_physics->SetCirMotionY(MO_ADVSPEED, 0.5f*Math::PI);
m_physics->SetCirMotionY(MO_RECSPEED, 0.5f*Math::PI);
m_physics->SetCirMotionY(MO_ADVACCEL, 5.0f);
m_physics->SetCirMotionY(MO_RECACCEL, 5.0f);
m_physics->SetCirMotionY(MO_STOACCEL, 10.0f);
}
if ( type == OBJECT_MOBILEdr )
{
m_physics->SetType(TYPE_ROLLING);
character->wheelFront = 4.0f;
character->wheelBack = 4.0f;
character->wheelLeft = 4.0f;
character->wheelRight = 4.0f;
character->posPower = Math::Vector(-5.0f, 3.0f, 0.0f);
m_physics->SetLinMotionX(MO_ADVSPEED, 15.0f);
m_physics->SetLinMotionX(MO_RECSPEED, 10.0f);
m_physics->SetLinMotionX(MO_ADVACCEL, 20.0f);
m_physics->SetLinMotionX(MO_RECACCEL, 10.0f);
m_physics->SetLinMotionX(MO_STOACCEL, 40.0f);
m_physics->SetLinMotionX(MO_TERSLIDE, 5.0f);
m_physics->SetLinMotionZ(MO_TERSLIDE, 5.0f);
m_physics->SetLinMotionX(MO_TERFORCE, 20.0f);
m_physics->SetLinMotionZ(MO_TERFORCE, 10.0f);
m_physics->SetLinMotionZ(MO_MOTACCEL, 40.0f);
m_physics->SetCirMotionY(MO_ADVSPEED, 0.5f*Math::PI);
m_physics->SetCirMotionY(MO_RECSPEED, 0.5f*Math::PI);
m_physics->SetCirMotionY(MO_ADVACCEL, 5.0f);
m_physics->SetCirMotionY(MO_RECACCEL, 5.0f);
m_physics->SetCirMotionY(MO_STOACCEL, 10.0f);
}
if ( type == OBJECT_APOLLO2 ) // jeep?
{
m_physics->SetType(TYPE_ROLLING);
character->wheelFront = 6.0f;
character->wheelBack = 6.0f;
character->wheelLeft = 5.0f;
character->wheelRight = 5.0f;
m_physics->SetLinMotionX(MO_ADVSPEED, 15.0f);
m_physics->SetLinMotionX(MO_RECSPEED, 10.0f);
m_physics->SetLinMotionX(MO_ADVACCEL, 20.0f);
m_physics->SetLinMotionX(MO_RECACCEL, 20.0f);
m_physics->SetLinMotionX(MO_STOACCEL, 40.0f);
m_physics->SetLinMotionX(MO_TERSLIDE, 2.0f);
m_physics->SetLinMotionZ(MO_TERSLIDE, 2.0f);
m_physics->SetLinMotionX(MO_TERFORCE, 30.0f);
m_physics->SetLinMotionZ(MO_TERFORCE, 10.0f);
m_physics->SetLinMotionZ(MO_MOTACCEL, 20.0f);
m_physics->SetCirMotionY(MO_ADVSPEED, 0.4f*Math::PI);
m_physics->SetCirMotionY(MO_RECSPEED, 0.4f*Math::PI);
m_physics->SetCirMotionY(MO_ADVACCEL, 2.0f);
m_physics->SetCirMotionY(MO_RECACCEL, 2.0f);
m_physics->SetCirMotionY(MO_STOACCEL, 4.0f);
}
}
// Management of an event.
bool CMotionVehicle::EventProcess(const Event &event)
{
CMotion::EventProcess(event);
2012-09-13 15:40:39 +00:00
if ( event.type == EVENT_FRAME )
{
return EventFrame(event);
}
2012-09-13 15:40:39 +00:00
if ( event.type == EVENT_KEY_DOWN )
{
}
return true;
}
// Management of an event.
bool CMotionVehicle::EventFrame(const Event &event)
{
Math::Matrix* mat;
Character* character;
Math::Vector pos, angle, floor;
ObjectType type;
float s, a, speedBL, speedBR, speedFL, speedFR, h, a1, a2;
float back, front, dist, radius, limit[2];
2012-09-13 15:40:39 +00:00
if ( m_engine->GetPause() ) return true;
if ( !m_engine->IsVisiblePoint(m_object->GetPosition(0)) ) return true;
2012-09-13 15:40:39 +00:00
type = m_object->GetType();
if ( type == OBJECT_MOBILEwa ||
type == OBJECT_MOBILEwc ||
type == OBJECT_MOBILEwi ||
type == OBJECT_MOBILEws ||
type == OBJECT_MOBILEwt ||
type == OBJECT_MOBILEtg ||
type == OBJECT_APOLLO2 ) // wheels?
{
2012-09-13 15:40:39 +00:00
s = m_physics->GetLinMotionX(MO_MOTSPEED)*1.0f;
a = m_physics->GetCirMotionY(MO_MOTSPEED)*3.0f;
if ( type == OBJECT_APOLLO2 ) s *= 0.5f;
speedBR = -s+a;
speedBL = s+a;
speedFR = -s+a;
speedFL = s+a;
2012-09-13 15:40:39 +00:00
m_object->SetAngleZ(6, m_object->GetAngleZ(6)+event.rTime*speedBR); // turning the wheels
m_object->SetAngleZ(7, m_object->GetAngleZ(7)+event.rTime*speedBL);
m_object->SetAngleZ(8, m_object->GetAngleZ(8)+event.rTime*speedFR);
m_object->SetAngleZ(9, m_object->GetAngleZ(9)+event.rTime*speedFL);
if ( s > 0.0f )
{
m_wheelTurn[0] = -a*0.05f;
m_wheelTurn[1] = -a*0.05f+Math::PI;
m_wheelTurn[2] = a*0.05f;
m_wheelTurn[3] = a*0.05f+Math::PI;
}
else if ( s < 0.0f )
{
m_wheelTurn[0] = a*0.05f;
m_wheelTurn[1] = a*0.05f+Math::PI;
m_wheelTurn[2] = -a*0.05f;
m_wheelTurn[3] = -a*0.05f+Math::PI;
}
else
{
m_wheelTurn[0] = fabs(a)*0.05f;
m_wheelTurn[1] = -fabs(a)*0.05f+Math::PI;
m_wheelTurn[2] = -fabs(a)*0.05f;
m_wheelTurn[3] = fabs(a)*0.05f+Math::PI;
}
2012-09-13 15:40:39 +00:00
m_object->SetAngleY(6, m_object->GetAngleY(6)+(m_wheelTurn[0]-m_object->GetAngleY(6))*event.rTime*8.0f);
m_object->SetAngleY(7, m_object->GetAngleY(7)+(m_wheelTurn[1]-m_object->GetAngleY(7))*event.rTime*8.0f);
m_object->SetAngleY(8, m_object->GetAngleY(8)+(m_wheelTurn[2]-m_object->GetAngleY(8))*event.rTime*8.0f);
m_object->SetAngleY(9, m_object->GetAngleY(9)+(m_wheelTurn[3]-m_object->GetAngleY(9))*event.rTime*8.0f);
if ( type == OBJECT_APOLLO2 )
{
2012-09-13 15:40:39 +00:00
m_object->SetAngleY(10, m_object->GetAngleY(6)+(m_wheelTurn[0]-m_object->GetAngleY(6))*event.rTime*8.0f);
m_object->SetAngleY(11, m_object->GetAngleY(7)+(m_wheelTurn[1]-m_object->GetAngleY(7))*event.rTime*8.0f+Math::PI);
m_object->SetAngleY(12, m_object->GetAngleY(8)+(m_wheelTurn[2]-m_object->GetAngleY(8))*event.rTime*8.0f);
m_object->SetAngleY(13, m_object->GetAngleY(9)+(m_wheelTurn[3]-m_object->GetAngleY(9))*event.rTime*8.0f+Math::PI);
}
2012-09-13 15:40:39 +00:00
pos = m_object->GetPosition(0);
angle = m_object->GetAngle(0);
if ( pos.x != m_wheelLastPos.x ||
pos.y != m_wheelLastPos.y ||
pos.z != m_wheelLastPos.z ||
angle.x != m_wheelLastAngle.x ||
angle.y != m_wheelLastAngle.y ||
angle.z != m_wheelLastAngle.z )
{
m_wheelLastPos = pos;
m_wheelLastAngle = angle;
if ( type == OBJECT_MOBILEtg )
{
back = -2.0f; // back wheels position
front = 3.0f; // front wheels position
dist = 3.0f; // distancing wheels Z
radius = 1.0f;
}
else if ( type == OBJECT_APOLLO2 )
{
back = -5.75f; // back wheels position
front = 5.75f; // front wheels position
dist = 5.00f; // distancing wheels Z
radius = 1.65f;
}
else
{
back = -3.0f; // back wheels position
front = 2.0f; // front wheels position
dist = 3.0f; // distancing wheels Z
radius = 1.0f;
}
2012-09-13 15:40:39 +00:00
if ( Math::Distance(pos, m_engine->GetEyePt()) < 50.0f ) // suspension?
{
2012-09-13 15:40:39 +00:00
character = m_object->GetCharacter();
mat = m_object->GetWorldMatrix(0);
pos.x = -character->wheelBack; // right back wheel
pos.z = -character->wheelRight;
pos.y = 0.0f;
pos = Math::Transform(*mat, pos);
2012-09-13 15:40:39 +00:00
h = m_terrain->GetHeightToFloor(pos);
if ( h > 0.5f ) h = 0.5f;
if ( h < -0.5f ) h = -0.5f;
pos.x = back;
pos.y = radius-h;
pos.z = -dist;
m_object->SetPosition(6, pos);
if ( type == OBJECT_APOLLO2 ) m_object->SetPosition(10, pos);
pos.x = -character->wheelBack; // left back wheel
pos.z = character->wheelLeft;
pos.y = 0.0f;
pos = Math::Transform(*mat, pos);
2012-09-13 15:40:39 +00:00
h = m_terrain->GetHeightToFloor(pos);
if ( h > 0.5f ) h = 0.5f;
if ( h < -0.5f ) h = -0.5f;
pos.x = back;
pos.y = radius-h;
pos.z = dist;
m_object->SetPosition(7, pos);
if ( type == OBJECT_APOLLO2 ) m_object->SetPosition(11, pos);
pos.x = character->wheelFront; // right front wheel
pos.z = -character->wheelRight;
pos.y = 0.0f;
pos = Math::Transform(*mat, pos);
2012-09-13 15:40:39 +00:00
h = m_terrain->GetHeightToFloor(pos);
if ( h > 0.5f ) h = 0.5f;
if ( h < -0.5f ) h = -0.5f;
pos.x = front;
pos.y = radius-h;
pos.z = -dist;
m_object->SetPosition(8, pos);
if ( type == OBJECT_APOLLO2 ) m_object->SetPosition(12, pos);
pos.x = character->wheelFront; // left front wheel
pos.z = character->wheelLeft;
pos.y = 0.0f;
pos = Math::Transform(*mat, pos);
2012-09-13 15:40:39 +00:00
h = m_terrain->GetHeightToFloor(pos);
if ( h > 0.5f ) h = 0.5f;
if ( h < -0.5f ) h = -0.5f;
pos.x = front;
pos.y = radius-h;
pos.z = dist;
m_object->SetPosition(9, pos);
if ( type == OBJECT_APOLLO2 ) m_object->SetPosition(13, pos);
}
else
{
m_object->SetPosition(6, Math::Vector(back, radius, -dist));
m_object->SetPosition(7, Math::Vector(back, radius, dist));
m_object->SetPosition(8, Math::Vector(front, radius, -dist));
m_object->SetPosition(9, Math::Vector(front, radius, dist));
if ( type == OBJECT_APOLLO2 )
{
m_object->SetPosition(10, Math::Vector(back, radius, -dist));
m_object->SetPosition(11, Math::Vector(back, radius, dist));
m_object->SetPosition(12, Math::Vector(front, radius, -dist));
m_object->SetPosition(13, Math::Vector(front, radius, dist));
}
}
}
}
if ( type == OBJECT_MOBILEta ||
type == OBJECT_MOBILEtc ||
type == OBJECT_MOBILEti ||
type == OBJECT_MOBILEts ||
type == OBJECT_MOBILErt ||
type == OBJECT_MOBILErc ||
type == OBJECT_MOBILErr ||
type == OBJECT_MOBILErs ||
type == OBJECT_MOBILEsa ||
type == OBJECT_MOBILEdr ) // caterpillars?
{
2012-09-13 15:40:39 +00:00
s = m_physics->GetLinMotionX(MO_MOTSPEED)*0.7f;
a = m_physics->GetCirMotionY(MO_MOTSPEED)*2.5f;
m_posTrackLeft += event.rTime*(s+a);
m_posTrackRight += event.rTime*(s-a);
UpdateTrackMapping(m_posTrackLeft, m_posTrackRight, type);
2012-09-13 15:40:39 +00:00
pos = m_object->GetPosition(0);
angle = m_object->GetAngle(0);
if ( pos.x != m_wheelLastPos.x ||
pos.y != m_wheelLastPos.y ||
pos.z != m_wheelLastPos.z ||
angle.x != m_wheelLastAngle.x ||
angle.y != m_wheelLastAngle.y ||
angle.z != m_wheelLastAngle.z )
{
m_wheelLastPos = pos;
m_wheelLastAngle = angle;
if ( type == OBJECT_MOBILEta ||
type == OBJECT_MOBILEtc ||
type == OBJECT_MOBILEti ||
type == OBJECT_MOBILEts )
{
limit[0] = 8.0f*Math::PI/180.0f;
limit[1] = -12.0f*Math::PI/180.0f;
}
else if ( type == OBJECT_MOBILEsa )
{
limit[0] = 15.0f*Math::PI/180.0f;
limit[1] = -15.0f*Math::PI/180.0f;
}
else if ( type == OBJECT_MOBILEdr )
{
limit[0] = 10.0f*Math::PI/180.0f;
limit[1] = -10.0f*Math::PI/180.0f;
}
else
{
limit[0] = 15.0f*Math::PI/180.0f;
limit[1] = -10.0f*Math::PI/180.0f;
}
2012-09-13 15:40:39 +00:00
if ( Math::Distance(pos, m_engine->GetEyePt()) < 50.0f ) // suspension?
{
2012-09-13 15:40:39 +00:00
character = m_object->GetCharacter();
mat = m_object->GetWorldMatrix(0);
pos.x = character->wheelFront; // right front wheel
pos.z = -character->wheelRight;
pos.y = 0.0f;
pos = Transform(*mat, pos);
2012-09-13 15:40:39 +00:00
a1 = atanf(m_terrain->GetHeightToFloor(pos)/character->wheelFront);
pos.x = -character->wheelBack; // right back wheel
pos.z = -character->wheelRight;
pos.y = 0.0f;
pos = Transform(*mat, pos);
2012-09-13 15:40:39 +00:00
a2 = atanf(m_terrain->GetHeightToFloor(pos)/character->wheelBack);
a = (a2-a1)/2.0f;
if ( a > limit[0] ) a = limit[0];
if ( a < limit[1] ) a = limit[1];
m_object->SetAngleZ(6, a);
pos.x = character->wheelFront; // left front wheel
pos.z = character->wheelLeft;
pos.y = 0.0f;
pos = Transform(*mat, pos);
2012-09-13 15:40:39 +00:00
a1 = atanf(m_terrain->GetHeightToFloor(pos)/character->wheelFront);
pos.x = -character->wheelBack; // left back wheel
pos.z = character->wheelLeft;
pos.y = 0.0f;
pos = Transform(*mat, pos);
2012-09-13 15:40:39 +00:00
a2 = atanf(m_terrain->GetHeightToFloor(pos)/character->wheelBack);
a = (a2-a1)/2.0f;
if ( a > limit[0] ) a = limit[0];
if ( a < limit[1] ) a = limit[1];
m_object->SetAngleZ(7, a);
}
else
{
m_object->SetAngleZ(6, 0.0f);
m_object->SetAngleZ(7, 0.0f);
}
}
}
if ( type == OBJECT_MOBILEwt ||
type == OBJECT_MOBILEdr ) // toy is key?
{
pos = m_posKey;
2012-09-13 15:40:39 +00:00
if ( m_object->GetSelect() &&
m_camera->GetType() == Gfx::CAM_TYPE_ONBOARD )
{
pos.y += 10.0f; // out of sight!
}
m_object->SetPosition(2, pos);
2012-09-13 15:40:39 +00:00
s = -fabs(m_physics->GetLinMotionX(MO_MOTSPEED)*0.1f);
s += -fabs(m_physics->GetCirMotionY(MO_MOTSPEED)*1.5f);
m_object->SetAngleY(2, m_object->GetAngleY(2)+event.rTime*s); // turns the key
}
if ( type == OBJECT_MOBILEfa ||
type == OBJECT_MOBILEfc ||
type == OBJECT_MOBILEfi ||
type == OBJECT_MOBILEfs ||
type == OBJECT_MOBILEft ) // flying?
{
EventFrameFly(event);
}
if ( type == OBJECT_MOBILEia ||
type == OBJECT_MOBILEic ||
type == OBJECT_MOBILEii ||
type == OBJECT_MOBILEis ) // legs?
{
EventFrameInsect(event);
}
if ( type == OBJECT_MOBILEwi ||
type == OBJECT_MOBILEti ||
type == OBJECT_MOBILEfi ||
type == OBJECT_MOBILEii ) // insect cannon?
{
EventFrameCanoni(event);
}
return true;
}
// Managing an event for a flying robot.
bool CMotionVehicle::EventFrameFly(const Event &event)
{
Math::Matrix* mat;
Math::Vector pos, angle, paw[3];
float hope[3], actual, final, h, a;
int i;
2012-09-13 15:40:39 +00:00
pos = m_object->GetPosition(0);
angle = m_object->GetAngle(0);
if ( m_bFlyFix &&
pos.x == m_wheelLastPos.x &&
pos.y == m_wheelLastPos.y &&
pos.z == m_wheelLastPos.z &&
angle.x == m_wheelLastAngle.x &&
angle.y == m_wheelLastAngle.y &&
angle.z == m_wheelLastAngle.z ) return true;
m_wheelLastPos = pos;
m_wheelLastAngle = angle;
2012-09-13 15:40:39 +00:00
if ( m_physics->GetLand() ) // on the ground?
{
2012-09-13 15:40:39 +00:00
mat = m_object->GetWorldMatrix(0);
paw[0] = Transform(*mat, Math::Vector( 4.2f, 0.0f, 0.0f)); // front
paw[1] = Transform(*mat, Math::Vector(-3.0f, 0.0f, -3.7f)); // right back
paw[2] = Transform(*mat, Math::Vector(-3.0f, 0.0f, 3.7f)); // left back
for ( i=0 ; i<3 ; i++ )
{
2012-09-13 15:40:39 +00:00
h = m_terrain->GetHeightToFloor(paw[i]);
a = -atanf(h*0.5f);
if ( a > Math::PI*0.2f ) a = Math::PI*0.2f;
if ( a < -Math::PI*0.2f ) a = -Math::PI*0.2f;
hope[i] = a;
}
}
else // in flight?
{
hope[0] = 0.0f; // front
hope[1] = 0.0f; // right back
hope[2] = 0.0f; // left back
}
m_bFlyFix = true;
for ( i=0 ; i<3 ; i++ )
{
2012-09-13 15:40:39 +00:00
actual = m_object->GetAngleZ(6+i);
final = Math::Smooth(actual, hope[i], event.rTime*5.0f);
if ( final != actual )
{
m_bFlyFix = false; // it is moving
m_object->SetAngleZ(6+i, final);
}
}
return true;
}
// Event management for insect legs.
bool CMotionVehicle::EventFrameInsect(const Event &event)
{
Math::Vector dir;
float s, a, prog, time;
int i, st, nd, action;
bool bStop, bOnBoard;
static int table[] =
{
// x1,y1,z1, x2,y2,z2, x3,y3,z3, // in the air:
60,25,0, 60,0,0, 60,-25,0, // t0: thighs 1..4
-35,0,0, -35,0,0, -35,0,0, // t0: legs 1..4
-65,0,0, -65,0,0, -65,0,0, // t0: feet 1..4
// on the ground:
30,10,0, 30,-15,0, 30,-40,0, // t1: thighs 1..4
-45,0,0, -45,0,0, -45,0,0, // t1: legs 1..4
-20,0,0, -20,0,0, -20,0,0, // t1: feet 1..4
// on the ground back:
35,40,0, 40,15,0, 40,-10,0, // t2: thighs 1..4
-35,0,0, -35,0,0, -35,0,0, // t2: legs 1..4
-50,0,0, -65,0,0, -65,0,0, // t2: feet 1..4
// stop:
35,35,0, 40,10,0, 40,-15,0, // s0: thighs 1..4
-35,0,0, -35,0,0, -35,0,0, // s0: legs 1..4
-50,0,0, -65,0,0, -65,0,0, // s0: feet 1..4
};
bOnBoard = false;
2012-09-13 15:40:39 +00:00
if ( m_object->GetSelect() &&
m_camera->GetType() == Gfx::CAM_TYPE_ONBOARD )
{
bOnBoard = true;
}
2012-09-13 15:40:39 +00:00
s = m_physics->GetLinMotionX(MO_MOTSPEED)*1.5f;
a = fabs(m_physics->GetCirMotionY(MO_MOTSPEED)*2.0f);
if ( s == 0.0f && a != 0.0f ) a *= 1.5f;
m_armTimeAbs += event.rTime;
m_armMember += (s+a)*event.rTime*0.15f;
bStop = ( a == 0.0f && s == 0.0f ); // stop?
action = 0; // walking
if ( s == 0.0f && a == 0.0f )
{
action = 3; // stop
}
if ( bStop )
{
prog = Math::Mod(m_armTimeAbs, 2.0f)/10.0f;
a = Math::Mod(m_armMember, 1.0f);
a = (prog-a)*event.rTime*2.0f; // stop position is pleasantly
m_armMember += a;
}
2012-09-13 15:40:39 +00:00
if ( m_object->GetRuin() ) // burn or explode?
{
action = 3;
}
for ( i=0 ; i<6 ; i++ ) // the six legs
{
if ( action != 0 ) // special action in progress?
{
st = 3*3*3*action + (i%3)*3;
nd = st;
time = event.rTime*5.0f;
}
else
{
if ( i < 3 ) prog = Math::Mod(m_armMember+(2.0f-(i%3))*0.33f+0.0f, 1.0f);
else prog = Math::Mod(m_armMember+(2.0f-(i%3))*0.33f+0.3f, 1.0f);
if ( prog < 0.33f ) // t0..t1 ?
{
prog = prog/0.33f; // 0..1
st = 0; // index start
nd = 1; // index end
}
else if ( prog < 0.67f ) // t1..t2 ?
{
prog = (prog-0.33f)/0.33f; // 0..1
st = 1; // index start
nd = 2; // index end
}
else // t2..t0 ?
{
prog = (prog-0.67f)/0.33f; // 0..1
st = 2; // index start
nd = 0; // index end
}
st = 3*3*3*action + st*3*3*3 + (i%3)*3;
nd = 3*3*3*action + nd*3*3*3 + (i%3)*3;
// Less and less soft ...
time = event.rTime*20.0f;
}
if ( i < 3 ) // right leg (1..3) ?
{
2012-09-13 15:40:39 +00:00
m_object->SetAngleX(6+3*i+0, Math::Smooth(m_object->GetAngleX(6+3*i+0), Math::PropAngle(table[st+ 0], table[nd+ 0], prog), time));
m_object->SetAngleY(6+3*i+0, Math::Smooth(m_object->GetAngleY(6+3*i+0), Math::PropAngle(table[st+ 1], table[nd+ 1], prog), time));
m_object->SetAngleZ(6+3*i+0, Math::Smooth(m_object->GetAngleZ(6+3*i+0), Math::PropAngle(table[st+ 2], table[nd+ 2], prog), time));
m_object->SetAngleX(6+3*i+1, Math::Smooth(m_object->GetAngleX(6+3*i+1), Math::PropAngle(table[st+ 9], table[nd+ 9], prog), time));
m_object->SetAngleY(6+3*i+1, Math::Smooth(m_object->GetAngleY(6+3*i+1), Math::PropAngle(table[st+10], table[nd+10], prog), time));
m_object->SetAngleZ(6+3*i+1, Math::Smooth(m_object->GetAngleZ(6+3*i+1), Math::PropAngle(table[st+11], table[nd+11], prog), time));
m_object->SetAngleX(6+3*i+2, Math::Smooth(m_object->GetAngleX(6+3*i+2), Math::PropAngle(table[st+18], table[nd+18], prog), time));
m_object->SetAngleY(6+3*i+2, Math::Smooth(m_object->GetAngleY(6+3*i+2), Math::PropAngle(table[st+19], table[nd+19], prog), time));
m_object->SetAngleZ(6+3*i+2, Math::Smooth(m_object->GetAngleZ(6+3*i+2), Math::PropAngle(table[st+20], table[nd+20], prog), time));
}
else // left leg (4..6) ?
{
2012-09-13 15:40:39 +00:00
m_object->SetAngleX(6+3*i+0, Math::Smooth(m_object->GetAngleX(6+3*i+0), Math::PropAngle(-table[st+ 0], -table[nd+ 0], prog), time));
m_object->SetAngleY(6+3*i+0, Math::Smooth(m_object->GetAngleY(6+3*i+0), Math::PropAngle(-table[st+ 1], -table[nd+ 1], prog), time));
m_object->SetAngleZ(6+3*i+0, Math::Smooth(m_object->GetAngleZ(6+3*i+0), Math::PropAngle( table[st+ 2], table[nd+ 2], prog), time));
m_object->SetAngleX(6+3*i+1, Math::Smooth(m_object->GetAngleX(6+3*i+1), Math::PropAngle(-table[st+ 9], -table[nd+ 9], prog), time));
m_object->SetAngleY(6+3*i+1, Math::Smooth(m_object->GetAngleY(6+3*i+1), Math::PropAngle(-table[st+10], -table[nd+10], prog), time));
m_object->SetAngleZ(6+3*i+1, Math::Smooth(m_object->GetAngleZ(6+3*i+1), Math::PropAngle( table[st+11], table[nd+11], prog), time));
m_object->SetAngleX(6+3*i+2, Math::Smooth(m_object->GetAngleX(6+3*i+2), Math::PropAngle(-table[st+18], -table[nd+18], prog), time));
m_object->SetAngleY(6+3*i+2, Math::Smooth(m_object->GetAngleY(6+3*i+2), Math::PropAngle(-table[st+19], -table[nd+19], prog), time));
m_object->SetAngleZ(6+3*i+2, Math::Smooth(m_object->GetAngleZ(6+3*i+2), Math::PropAngle( table[st+20], table[nd+20], prog), time));
}
}
if ( bStop )
{
}
else
{
a = Math::Mod(m_armMember, 1.0f);
if ( a < 0.5f ) a = -1.0f+4.0f*a; // -1..1
else a = 3.0f-4.0f*a; // 1..-1
dir.x = sinf(a)*0.05f;
s = Math::Mod(m_armMember/2.0f, 1.0f);
if ( s < 0.5f ) s = -1.0f+4.0f*s; // -1..1
else s = 3.0f-4.0f*s; // 1..-1
dir.z = sinf(s)*0.1f;
dir.y = 0.0f;
if ( bOnBoard ) dir *= 0.6f;
SetInclinaison(dir);
}
return true;
}
// Event management for a insect cannon.
bool CMotionVehicle::EventFrameCanoni(const Event &event)
{
CObject* power;
Math::Vector pos, speed;
Math::Point dim;
float zoom, angle, energy, factor;
bool bOnBoard = false;
m_canonTime += event.rTime;
2012-09-13 15:40:39 +00:00
if ( m_object->GetSelect() &&
m_camera->GetType() == Gfx::CAM_TYPE_ONBOARD )
{
bOnBoard = true;
}
2012-09-13 15:40:39 +00:00
power = m_object->GetPower();
if ( power == 0 )
{
energy = 0.0f;
}
else
{
2012-09-13 15:40:39 +00:00
energy = power->GetEnergy();
}
if ( energy == 0.0f ) return true;
factor = 0.5f+energy*0.5f;
if ( bOnBoard ) factor *= 0.8f;
zoom = 1.3f+
sinf(m_canonTime*Math::PI*0.31f)*0.10f+
sinf(m_canonTime*Math::PI*0.52f)*0.08f+
sinf(m_canonTime*Math::PI*1.53f)*0.05f;
zoom *= factor;
m_object->SetZoomY(2, zoom);
zoom = 1.0f+
sinf(m_canonTime*Math::PI*0.27f)*0.07f+
sinf(m_canonTime*Math::PI*0.62f)*0.06f+
sinf(m_canonTime*Math::PI*1.73f)*0.03f;
zoom *= factor;
m_object->SetZoomZ(2, zoom);
angle = sinf(m_canonTime*1.0f)*0.10f+
sinf(m_canonTime*1.3f)*0.15f+
sinf(m_canonTime*2.7f)*0.05f;
m_object->SetAngleX(2, angle);
#if 0
m_lastTimeCanon -= event.rTime;
if ( m_lastTimeCanon <= 0.0f )
{
m_lastTimeCanon = m_engine->ParticuleAdapt(0.5f+Math::Rand()*0.5f);
2012-09-13 15:40:39 +00:00
pos = m_object->GetPosition(0);
pos.y += 8.0f;
speed.y = 7.0f+Math::Rand()*3.0f;
speed.x = (Math::Rand()-0.5f)*2.0f;
speed.z = 2.0f+Math::Rand()*2.0f;
if ( Math::Rand() < 0.5f ) speed.z = -speed.z;
2012-09-13 15:40:39 +00:00
mat = m_object->GetRotateMatrix(0);
speed = Transform(*mat, speed);
dim.x = Math::Rand()*0.1f+0.1f;
if ( bOnBoard ) dim.x *= 0.4f;
dim.y = dim.x;
m_particule->CreateParticule(pos, speed, dim, PARTIORGANIC2, 2.0f, 10.0f);
}
#endif
return true;
}
// Updates the mapping of the texture of the caterpillars.
void CMotionVehicle::UpdateTrackMapping(float left, float right, ObjectType type)
{
2012-09-13 15:40:39 +00:00
Gfx::Material mat;
float limit[4];
int rRank, lRank, i;
2012-09-13 15:40:39 +00:00
memset( &mat, 0, sizeof(Gfx::Material) );
mat.diffuse.r = 1.0f;
mat.diffuse.g = 1.0f;
mat.diffuse.b = 1.0f; // white
mat.ambient.r = 0.5f;
mat.ambient.g = 0.5f;
mat.ambient.b = 0.5f;
2012-09-13 15:40:39 +00:00
rRank = m_object->GetObjectRank(6);
lRank = m_object->GetObjectRank(7);
if ( type == OBJECT_MOBILEdr )
{
limit[0] = 0.0f;
limit[1] = 1000000.0f;
limit[2] = limit[1];
2012-09-13 15:40:39 +00:00
limit[3] = m_engine->GetLimitLOD(1);
m_engine->TrackTextureMapping(rRank, mat, Gfx::ENG_RSTATE_PART1, "drawer.png", "",
2012-09-13 15:40:39 +00:00
limit[0], limit[1], Gfx::ENG_TEX_MAPPING_X,
right, 1.0f, 8.0f, 192.0f, 256.0f);
m_engine->TrackTextureMapping(lRank, mat, Gfx::ENG_RSTATE_PART2, "drawer.png", "",
2012-09-13 15:40:39 +00:00
limit[0], limit[1], Gfx::ENG_TEX_MAPPING_X,
left, 1.0f, 8.0f, 192.0f, 256.0f);
}
else
{
limit[0] = 0.0f;
2012-09-13 15:40:39 +00:00
limit[1] = m_engine->GetLimitLOD(0);
limit[2] = limit[1];
2012-09-13 15:40:39 +00:00
limit[3] = m_engine->GetLimitLOD(1);
for ( i=0 ; i<2 ; i++ )
{
m_engine->TrackTextureMapping(rRank, mat, Gfx::ENG_RSTATE_PART1, "lemt.png", "",
2012-09-13 15:40:39 +00:00
limit[i*2+0], limit[i*2+1], Gfx::ENG_TEX_MAPPING_X,
right, 1.0f, 8.0f, 192.0f, 256.0f);
m_engine->TrackTextureMapping(lRank, mat, Gfx::ENG_RSTATE_PART2, "lemt.png", "",
2012-09-13 15:40:39 +00:00
limit[i*2+0], limit[i*2+1], Gfx::ENG_TEX_MAPPING_X,
left, 1.0f, 8.0f, 192.0f, 256.0f);
}
}
}
// State management of the pencil drawing robot.
2012-09-13 15:40:39 +00:00
bool CMotionVehicle::GetTraceDown()
{
return m_bTraceDown;
}
void CMotionVehicle::SetTraceDown(bool bDown)
{
m_bTraceDown = bDown;
}
2012-09-13 15:40:39 +00:00
int CMotionVehicle::GetTraceColor()
{
return m_traceColor;
}
void CMotionVehicle::SetTraceColor(int color)
{
m_traceColor = color;
}
2012-09-13 15:40:39 +00:00
float CMotionVehicle::GetTraceWidth()
{
return m_traceWidth;
}
void CMotionVehicle::SetTraceWidth(float width)
{
m_traceWidth = width;
}