Here's the model and pick. Only one joint labeled "Link". Notice the nose of the car is at the origin.
[img]http://www.scmlaw.com\trailer.jpg[/img]
Milkshape Trailer
and here's the code
Code: Select all
#include <irrlicht.h>
using namespace irr;
using namespace scene;
using namespace core;
#pragma comment(lib, "Irrlicht.lib")
class car
{
public:
car(scene::IAnimatedMeshSceneNode* Node, scene::ISceneNode* Link)
{
node=Node;
lastpos=node->getAbsolutePosition();
link=Link;
}
void update()
{
if (link)
node->setPosition(link->getAbsolutePosition());
vector3df rot=node->getAbsolutePosition()-lastpos;
node->setRotation(rot.getHorizontalAngle());
lastpos=node->getAbsolutePosition();
}
scene::IAnimatedMeshSceneNode* node;
private:
scene::ISceneNode* link;
vector3df lastpos;
};
void main()
{
IrrlichtDevice* device=irr::createDevice(video::EDT_DIRECT3D9, dimension2d<s32>(320, 240));
ISceneManager* smgr=device->getSceneManager();
video::IVideoDriver* driver=device->getVideoDriver();
array<car> train;
train.push_back(car(smgr->addAnimatedMeshSceneNode(smgr->getMesh("../trailer.ms3d")),0));
train.push_back(car(smgr->addAnimatedMeshSceneNode(smgr->getMesh("../trailer.ms3d")), train[train.size()-1].node->getMS3DJointNode("Link")));
train.push_back(car(smgr->addAnimatedMeshSceneNode(smgr->getMesh("../trailer.ms3d")), train[train.size()-1].node->getMS3DJointNode("Link")));
train.push_back(car(smgr->addAnimatedMeshSceneNode(smgr->getMesh("../trailer.ms3d")), train[train.size()-1].node->getMS3DJointNode("Link")));
train.push_back(car(smgr->addAnimatedMeshSceneNode(smgr->getMesh("../trailer.ms3d")), train[train.size()-1].node->getMS3DJointNode("Link")));
for (int i=0; i<train.size(); i++)
train[i].node->setMaterialFlag(video::EMF_LIGHTING, false);
smgr->addCubeSceneNode(1,0,-1,vector3df(0,-10,0),vector3df(0,0,0), vector3df(500,1,500));
array<vector3df> points;
points.push_back(vector3df(-200,0,-100));
points.push_back(vector3df(200,100,-100));
points.push_back(vector3df(100,50,200));
points.push_back(vector3df(0,0,0));
ISceneNodeAnimator* anim=smgr->createFollowSplineAnimator(device->getTimer()->getTime(), points, .10);
train[0].node->addAnimator(anim);
anim->drop();
smgr->addCameraSceneNodeFPS();
while (device->run())
{
for (int i=0; i<train.size(); i++)
train[i].update();
driver->beginScene(true,true, video::SColor(255,80,80,80));
smgr->drawAll();
driver->endScene();
}
device->drop();
}