Chopper scene node for the Bell UH-1 helicopter

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Chopper scene node for the Bell UH-1 helicopter

Post by smso »

The chopper scene node shows how different parts of a chopper e.g. body, rotors, blades can be combined using empty scene nodes, completed with animation of rotating parts.

The chopper model is uh-1:
http://en.wikipedia.org/wiki/Bell_UH-1_Iroquois

Requirement
===========
(1) You have to obtain .obj files for the uh-1 chopper scene node. (See below)

(2) Your have to change a few (#define) params to point to the proper directories, e.g.

uh1.h file:

Code: Select all

#define UH1_MODEL_DIR "/home/smso/downloads/irrlicht/aircraft/UH-1/Models/"
 
main.cpp:

Code: Select all

#define IRRLICHT_DIR "/home/smso/downloads/irrlicht/irrlicht-svn/"
(3) You will also need the chopper_control.h and chopper_control.cpp files from:
http://irrlicht.sourceforge.net/forum/v ... =9&t=46226

Steps to obtain the required .obj files:
========================================
1. download the uh-1 chopper file from FlightGear:

http://ftp.linux.kiev.ua/pub/fgfs/Aircr ... 120217.zip


2. unzip the file and find the following .ac files (6 in total):

dir file(s)
=== ======
UH-1/Models uh1.ac
UH-1/Models/MainRotor mainrotor.ac , blade.ac
UH-1/Models/TailRotor tailrotor.ac , blade.ac
UH-1/Models/Interior interior.ac

3. convert all the .ac files in step (2) into .obj files using blender,
name them as follows:

dir file(s)
=== ======
UH-1/Models body.obj
UH-1/Models/MainRotor mainrotor.obj , mainblade.obj
UH-1/Models/TailRotor tailrotor.obj , tailblade.obj
UH-1/Models/Interior interior.obj
Last edited by smso on Wed May 02, 2012 7:49 am, edited 1 time in total.
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Chopper scene node for the Bell UH-1 helicopter

Post by smso »

uh1.h

Code: Select all

#ifndef _UH1_SCENE_NODE_H_
#define _UH1_SCENE_NODE_H_
#include <irrlicht.h>
using namespace irr;
#ifndef UH1_SCENE_NODE_PROPERTIES
#define UH1_SCENE_NODE_PROPERTIES
#define UH1_MODEL_DIR "/home/smso/downloads/irrlicht/aircraft/UH-1/Models/"
#endif
class Uh1SceneNode: public scene::IMeshSceneNode
{
        public:
        Uh1SceneNode
        (
                scene::ISceneNode* parent,
                scene::ISceneManager* smgr,
                s32 id = -1,
                const core::vector3df& position = core::vector3df(0.0f),
                const core::vector3df& rotation = core::vector3df(0.0f),
                const core::vector3df& scale = core::vector3df(1.0f)
        );
        
        virtual ~Uh1SceneNode();
        virtual void setPosition(const core::vector3df& newpos);
        virtual core::vector3df getAbsolutePosition() const;
        virtual void setMesh(scene::IMesh* mesh);
        virtual scene::IMesh* getMesh(void);
        virtual void setReadOnlyMaterials(bool readonly);
        virtual bool isReadOnlyMaterials() const;
        virtual void OnRegisterSceneNode();
        virtual void render();
        virtual const core::aabbox3d<f32>& getBoundingBox() const;
        virtual u32 getMaterialCount() const;
        virtual video::SMaterial& getMaterial(u32 i);
        virtual void OnAnimate(u32 timeMs);
        virtual core::matrix4 getRelativeTransformation() const;
        void drawDownwardLinesFromBB();
        void drawVerticalLine();
        core::vector3df getMatrixRotation(const core::matrix4& mx);
        void update(u32 deltaTime);
        bool isVisible() const
        {
                return Body->isVisible();
        }
        
        // setters + getters:
        //void setModel(Ka50Model* model) { Model = model; }
        
        scene::ISceneNode* getRootEmpty() const { return RootEmpty; }
        scene::IMeshSceneNode* getBody() const { return Body; }
        scene::IMeshSceneNode* getInterior() const { return Interior; }
        scene::IMeshSceneNode* getMainRotor() const { return MainRotor; }
        scene::ISceneNode* getTailRotorEmpty() const { return TailRotorEmpty; }
        scene::ISceneNode* getTailRotor() const { return TailRotor; }
        core::vector3df getTailRotorOffset() const { return TailRotorOffset; }
        void setTailRotorOffset(const core::vector3df& offset);
        core::vector3df getMainRotorOffset() const { return MainRotorOffset; }
        void setMainRotorOffset(const core::vector3df& offset);
        core::vector3df getTailBladeEmptyOffset() const { return TailBladeEmptyOffset; }
        void setTailBladeEmptyOffset(const core::vector3df& offset);
        protected:
        
        private:
        //IrrlichtDevice* _device;
        scene::ISceneManager* Smgr;
        scene::ISceneNode* RootEmpty;
        scene::IMeshSceneNode* Body;
        scene::IMesh* BodyMesh;
        scene::IMeshSceneNode* Interior;
        scene::ISceneNode* MainRotorEmpty;
        scene::IMeshSceneNode* MainRotor;
        core::vector3df MainRotorOffset;
        scene::ISceneNode* TailRotorEmpty;
        scene::IMeshSceneNode* TailRotor;
        core::vector3df TailRotorOffset;
        scene::ISceneNode* MainBladeEmpty;
        scene::ISceneNode* TailBladeEmpty;
        core::vector3df TailBladeEmptyOffset;
         
        scene::IMeshSceneNode* Blade;
        core::aabbox3d<f32> Box;
        video::SMaterial BodyMaterial;
        video::SMaterial MainRotorMaterial;
        video::SMaterial TailRotorMaterial;
};
#endif // _UH1_SCENE_NODE_H_
 
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Chopper scene node for the Bell UH-1 helicopter

Post by smso »

uh1.cpp

Code: Select all

#include "uh1.h"
using namespace irr;
Uh1SceneNode::Uh1SceneNode
(
        scene::ISceneNode* parent,
        scene::ISceneManager* smgr,
        s32 id,
        const core::vector3df& position,
        const core::vector3df& rotation,
        const core::vector3df& scale
)
:       scene::IMeshSceneNode(parent ? parent : smgr->getRootSceneNode(), smgr, 0, position, rotation, scale),
        Smgr(smgr),
        RootEmpty(0),
        Body(0),
        BodyMesh(0),
        Interior(0),
        MainRotor(0),
        TailRotorEmpty(0),
        TailRotor(0),
        TailRotorOffset(-4.271f, 1.555f, 0.473f),
        MainRotorOffset(4.767f, 1.0f, 0.0f),
        //MainRotorOffset(0.0f),
        MainBladeEmpty(0),
        TailBladeEmpty(0),
        TailBladeEmptyOffset(0.0f),
        Blade(0)
{
        Smgr->getFileSystem()->addFileArchive(UH1_MODEL_DIR);
        // parent-child relationship:
        // root -> body -> main rotor empty -> main rotor -> main blade empty -> main blades
        //              -> tail rotor empty -> tail rotor -> tail blade empty -> tail blades
        // root -> interior
        // setup root: for correcting orientation of model!
        RootEmpty = Smgr->addEmptySceneNode(Parent);
        // setup body:
        BodyMesh = Smgr->getMesh("body.obj");
        Body = Smgr->addMeshSceneNode(BodyMesh, RootEmpty);
        // workaround to correct for yaw-, roll- and pitch-controls:
        Body->setRotation(core::vector3df(0.0f, -90.0f, 0.0f));
        //Body->setDebugDataVisible(scene::EDS_BBOX);
        //printf("Body->getMaterialCount()=%u\n", Body->getMaterialCount());
        for (u32 n=0; n<Body->getMaterialCount(); ++n)
        {
                Body->getMaterial(n).setFlag(video::EMF_LIGHTING, false);
                Body->getMaterial(n).NormalizeNormals = true;
        }
        BodyMaterial = Body->getMaterial(0);
        Box = Body->getBoundingBox();
        // setup interior:
        Interior = Smgr->addMeshSceneNode(Smgr->getMesh("Interior/interior.obj"), RootEmpty);
        Interior->setRotation(core::vector3df(0.0f, -90.0f, 0.0f));
        Interior->setVisible(false);
        // setup main rotor:
        MainRotorEmpty = Smgr->addEmptySceneNode(Body);
        MainRotorEmpty->setRotation(core::vector3df(0.0f, 0.0f, -5.0f));
        MainRotor = Smgr->addMeshSceneNode(Smgr->getMesh("MainRotor/mainrotor.obj"), MainRotorEmpty);
        for (u32 n=0; n<MainRotor->getMaterialCount(); ++n)
        {
                MainRotor->getMaterial(n).setFlag(video::EMF_LIGHTING, false);
                MainRotor->getMaterial(n).NormalizeNormals = true;
        }
        MainRotor->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
        Box.addInternalBox(MainRotor->getBoundingBox());
        this->setMainRotorOffset(MainRotorOffset);
        ////////////////////////////////////////////////////////////////////////////
        // setup tail rotor:
        TailRotorEmpty = Smgr->addEmptySceneNode(Body);
        TailRotorEmpty->setRotation(core::vector3df(90.0f, 0.0f, 0.0f));
        TailRotor = Smgr->addMeshSceneNode(Smgr->getMesh("TailRotor/tailrotor.obj"), TailRotorEmpty);
        TailRotor->getMaterial(0).setFlag(video::EMF_LIGHTING, false);
        TailRotor->getMaterial(0).NormalizeNormals = true;
        TailRotor->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
        Box.addInternalBox(TailRotor->getBoundingBox());
        this->setTailRotorOffset(TailRotorOffset);
        ////////////////////////////////////////////////////////////////////////////
        // setup tail blades:
        TailBladeEmpty = Smgr->addEmptySceneNode(TailRotor);
        //TailBladeEmpty->setPosition(core::vector3df(3.047f, 0.811f, 0.0f));
        TailBladeEmpty->setPosition(core::vector3df(0.0f, -0.1f, 0.0f));
        for (u32 n=0; n<2; ++n)
        {
                Blade = Smgr->addMeshSceneNode(Smgr->getMesh("TailRotor/tailblade.obj"), TailBladeEmpty);
                //Blade->setRotation(core::vector3df(0.0f, 0.0f, 0.0f));
                Blade->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
                //Blade->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
                Blade->getMaterial(0).setFlag(video::EMF_LIGHTING, false);
                Blade->getMaterial(0).NormalizeNormals = true;
                Box.addInternalBox(Blade->getBoundingBox());
                if (n==1)
                        Blade->setRotation(core::vector3df(0.0f, 180.0f, 0.0f));
        }
        ////////////////////////////////////////////////////////////////////////////
        // setup main blades:
        MainBladeEmpty = Smgr->addEmptySceneNode(MainRotor);
        //MainBladeEmpty->setPosition(core::vector3df(0.0f, -0.1f, 0.0f));
        for (u32 n=0; n<2; ++n)
        {
                Blade = Smgr->addMeshSceneNode(Smgr->getMesh("MainRotor/mainblade.obj"), MainBladeEmpty);
                //Blade->setRotation(core::vector3df(0.0f, 0.0f, 0.0f));
                Blade->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
                //Blade->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
                Blade->getMaterial(0).setFlag(video::EMF_LIGHTING, false);
                Blade->getMaterial(0).NormalizeNormals = true;
                Box.addInternalBox(Blade->getBoundingBox());
                if (n==1)
                        Blade->setRotation(core::vector3df(0.0f, 180.0f, 0.0f));
        }       
        //this->getMaterial(0).setFlag(video::EMF_LIGHTING, false);
}
Uh1SceneNode::~Uh1SceneNode()
{
}       
void Uh1SceneNode::setPosition(const core::vector3df& newpos)
{
        if (!RootEmpty)
                return;
        RootEmpty->setPosition(newpos);
}
core::vector3df Uh1SceneNode::getAbsolutePosition() const
{
        if (!RootEmpty)
                return core::vector3df(0.0f);
        return RootEmpty->getAbsolutePosition();
}
void Uh1SceneNode::setMesh(scene::IMesh* mesh)
{
}
scene::IMesh* Uh1SceneNode::getMesh(void)
{
        return BodyMesh;
}
void Uh1SceneNode::setReadOnlyMaterials(bool readonly)
{
}
bool Uh1SceneNode::isReadOnlyMaterials() const
{
        return true;
}
void Uh1SceneNode::OnRegisterSceneNode()
{
        if (IsVisible)
        {
                SceneManager->registerNodeForRendering(Body);
                SceneManager->registerNodeForRendering(MainRotor);
                SceneManager->registerNodeForRendering(TailRotor);
        }
        scene::IMeshSceneNode::OnRegisterSceneNode();
}
void Uh1SceneNode::render()
{
}
//FIXME:
const core::aabbox3d<f32>& Uh1SceneNode::getBoundingBox() const
{
        return Box;
}
u32 Uh1SceneNode::getMaterialCount() const
{
        return 3;
}
video::SMaterial& Uh1SceneNode::getMaterial(u32 i)
{
        if (i == 0)
                return BodyMaterial;
        else if (i == 1)
                return MainRotorMaterial;
        else if (i == 2)
                return TailRotorMaterial;
        else
                return BodyMaterial;
}
void Uh1SceneNode::OnAnimate(u32 timeMs)
{
}
core::matrix4 Uh1SceneNode::getRelativeTransformation() const
{
        return Body->getRelativeTransformation();
}
 
void Uh1SceneNode::update(u32 deltaTime)
{
        f32 rotRate = 180.0f; // degs per second:
        f32 deltaRot = rotRate * (f32)deltaTime * 0.001f;
        core::vector3df rot1 = TailRotor->getRotation();
        rot1.Y -= deltaRot;
        TailRotor->setRotation(rot1);
        core::vector3df rot2 = MainRotor->getRotation();
        //rot2.Y += deltaRot;
        rot2.Y -= deltaRot;
        MainRotor->setRotation(rot2);
}
void Uh1SceneNode::setTailRotorOffset(const core::vector3df& offset)
{
        TailRotorOffset = offset;
        //TailRotor->setPosition(offset);
        TailRotorEmpty->setPosition(offset);
}
void Uh1SceneNode::setMainRotorOffset(const core::vector3df& offset)
{
        MainRotorOffset = offset;
        //MainRotor->setPosition(offset);
        MainRotorEmpty->setPosition(offset);
}
void Uh1SceneNode::setTailBladeEmptyOffset(const core::vector3df& offset)
{
        TailBladeEmptyOffset = offset;
        TailBladeEmpty->setPosition(offset);
}
 
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Chopper scene node for the Bell UH-1 helicopter

Post by smso »

main.cpp

Code: Select all

#include <irrlicht.h>
#include <iomanip>
#include <iostream>
#include <sstream>
#include "uh1.h"
#include "chopper_control.h"
#ifndef MAIN_CPP_PROPERTIES
#define MAIN_CPP_PROPERTIES
#define IRRLICHT_DIR "/home/smso/downloads/irrlicht/irrlicht-svn/"
#endif
using namespace irr;
IrrlichtDevice* device = 0;
scene::ICameraSceneNode* camera = 0;
scene::ICameraSceneNode* cockpitCamera = 0;
//core::vector3df cameraOffset(0.0f);
core::vector3df cameraOffset(0.0f, -0.3f, 6.2f);
scene::ITriangleSelector* selector = 0;
Uh1SceneNode* uh1 = 0;
ChopperControl* model = 0;
enum
{
        ID_IsNotPickable = 0,
        IDFlag_IsPickable = 1 << 0,
        IDFlag_IsHighlightable = 1 << 1
};
void rotateCameraTowardsNodeAroundYAxis
(
    scene::ICameraSceneNode* camera,
    scene::ISceneNode* node,
    f32 minDist = 1.0f,
    bool rotateCameraBy90Deg = false
)
{
    node->updateAbsolutePosition();
    core::vector3df pos = node->getAbsolutePosition();
    camera->updateAbsolutePosition();
    core::vector3df cameraPos = camera->getAbsolutePosition();
    core::vector3df delta = pos - cameraPos;
    core::vector3df rot = delta.getHorizontalAngle();
    rot.X = 0.0f;
    rot.Z = 0.0f;
    if (rotateCameraBy90Deg)
        rot.Y -= 90.0f;
    camera->setRotation(rot);
    // bring camera nearer to node:
    if (minDist <= 1.0f)
        return;
    if (delta.getLengthSQ() < (minDist * minDist))
        return;
    delta *= 0.5f;
    camera->setPosition(core::vector3df
    (
        cameraPos.X + delta.X,
        cameraPos.Y + delta.Y,
        cameraPos.Z + delta.Z
    ));
}
void print(const core::vector3df& vec)
{
        printf("(%.2f,%.2f,%.2f)\n", vec.X, vec.Y, vec.Z);
}
////////////////////////////////////////////////////////////////////////////////
class EventReceiver: public IEventReceiver
{
public:
virtual bool OnEvent(const SEvent& event)
{
        if (model)
                model->OnEvent(event);
        if
        (
                (event.EventType == EET_KEY_INPUT_EVENT)
                && (event.KeyInput.PressedDown == true)
        )
        {
                if (event.KeyInput.Key == irr::KEY_ESCAPE)
                {
                        device->closeDevice();
                        device->run();
                        return true;
                }
                else if (event.KeyInput.Key == irr::KEY_F1)
                {
                        if (uh1->getBody())
                                rotateCameraTowardsNodeAroundYAxis(camera, uh1->getBody(), 5.0f);
                }
                else if (event.KeyInput.Key == irr::KEY_F2)
                {
                        //if (uh1->getTailRotor())
                                //rotateCameraTowardsNodeAroundYAxis(camera, uh1->getTailRotor(), 5.0f);
                        print(camera->getTarget());
                }
                else if (event.KeyInput.Key == irr::KEY_F3)
                {
                        bool enabled = camera->isInputReceiverEnabled();
                        camera->setInputReceiverEnabled(!enabled);
                        device->getCursorControl()->setVisible(enabled);
                }
                else if (event.KeyInput.Key == irr::KEY_F4)
                {
                        if (device->getSceneManager()->getActiveCamera() == camera)
                        {
                                device->getSceneManager()->setActiveCamera(cockpitCamera);
                                uh1->getBody()->setVisible(false);
                                uh1->getInterior()->setVisible(true);
                        }
                        else
                        {
                                device->getSceneManager()->setActiveCamera(camera);
                                uh1->getBody()->setVisible(true);
                                uh1->getInterior()->setVisible(false);
                                rotateCameraTowardsNodeAroundYAxis(camera, uh1->getBody(), 5.0f);
                        }
                }
                else if (event.KeyInput.Key == irr::KEY_F5)
                {
                        cameraOffset.Z += 0.1f;
                        printf("cameraOffset="); print(cameraOffset);
                }
                else if (event.KeyInput.Key == irr::KEY_F6)
                {
                        cameraOffset.Z -= 0.1f;
                        printf("cameraOffset="); print(cameraOffset);
                }
 
                else if (event.KeyInput.Key == irr::KEY_F7)
                {
                        cameraOffset.Y += 0.1f;
                        printf("cameraOffset="); print(cameraOffset);
                }
                else if (event.KeyInput.Key == irr::KEY_F8)
                {
                        cameraOffset.Y -= 0.1f;
                        printf("cameraOffset="); print(cameraOffset);
                }
 
                else if (event.KeyInput.Key == irr::KEY_F9)
                {
                        cameraOffset.X += 0.1f;
                        printf("cameraOffset="); print(cameraOffset);
                }
                else if (event.KeyInput.Key == irr::KEY_F10)
                {
                        cameraOffset.X -= 0.1f;
                        printf("cameraOffset="); print(cameraOffset);
                }
        }
        else
        {
        }
 
        return false;
}
};
////////////////////////////////////////////////////////////////////////////////
int main()
{
        video::E_DRIVER_TYPE driverType = video::EDT_OPENGL;
        // create device
        EventReceiver receiver; //<---------------------------------------------------
        device
        = createDevice(driverType, core::dimension2d<u32>(1024, 768), 32, false, false, false, &receiver);
        if (device == 0)
                return 1; // could not create selected driver.
        video::IVideoDriver* driver = device->getVideoDriver();
        scene::ISceneManager* smgr = device->getSceneManager();
        io::IFileSystem* fs = device->getFileSystem();
        fs->addFileArchive(IRRLICHT_DIR);
        // create skybox
        driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
        smgr->addSkyBoxSceneNode
        (
                driver->getTexture("media/irrlicht2_up.jpg"),
                driver->getTexture("media/irrlicht2_dn.jpg"),
                driver->getTexture("media/irrlicht2_lf.jpg"),
                driver->getTexture("media/irrlicht2_rt.jpg"),
                driver->getTexture("media/irrlicht2_ft.jpg"),
                driver->getTexture("media/irrlicht2_bk.jpg")
        );
        driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
 
 
        // add uh60:
        uh1 = new Uh1SceneNode(0, smgr, -1);
        uh1->getBody()->setScale(core::vector3df(10.0f));
        ////////////////////////////////////////////////////////////////////////////
        // setup model of uh1
        model = new ChopperControl(device, uh1->getRootEmpty());
        model->getRootEmpty()->setPosition(core::vector3df(100.0f, 1000.0f, 0.0f));
 
    // load building:
    scene::IMeshSceneNode* q3node = 0;
    c8* filename = "media/map-20kdm2.pk3";
    bool fileOk = fs->addZipFileArchive(filename);
    if (!fileOk)
    {
        printf("Error adding file:\n%s\nto the file system\n\n", filename);
        return -1;
    }
    io::path bspPath = "20kdm2.bsp";
    scene::IAnimatedMesh* q3levelmesh = smgr->getMesh(bspPath);
    if (q3levelmesh)
        q3node = smgr->addOctreeSceneNode(q3levelmesh->getMesh(0), 0, IDFlag_IsPickable);
    if (q3node)
        q3node->setPosition(core::vector3df(-1350.0f, -130.0f, -1400.0f));
        // setup selector for collision detection:
        selector = smgr->createOctreeTriangleSelector(q3node->getMesh(), q3node, 128);
        if (selector)
        {
                q3node->setTriangleSelector(selector);
 
                const core::aabbox3d<f32>& box = uh1->getBoundingBox();
                core::vector3df radius = box.MaxEdge - box.getCenter();
 
                scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator
                (
                        selector,
                        //uh1->getBody(),
                        model->getRootEmpty(),
                        radius * 10.0f,
                        core::vector3df(0.0f), // gravity was (0,-10,0)
                        radius * 10.0f
                );
 
                model->getRootEmpty()->addAnimator(anim);
 
                ((scene::ISceneNodeAnimatorCollisionResponse*)anim)->setCollisionCallback(model);
                anim->drop(); 
                //selector->drop(); we need this for drawing landing guide!
        }
        else
                printf("selector == 0\n");
        ////////////////////////////////////////////////////////////////////////////
        // add cam:
        f32 camRotateSpeed = 100.0f;
        f32 camMoveSpeed = 0.2f;
        f32 camJumpSpeed = 3.0f;
        camera = smgr->addCameraSceneNodeFPS(0, camRotateSpeed, camMoveSpeed, -1, 0, 0, false, camJumpSpeed);
        camera->setFarValue(40000.0f);
        camera->setPosition(core::vector3df(-20.0f, 1000.0f, 260.0f));
        model->getRootEmpty()->updateAbsolutePosition();
        camera->setTarget(model->getRootEmpty()->getAbsolutePosition());
 
        // setup cockpitCamera:
        cockpitCamera = smgr->addCameraSceneNode(0);
        cockpitCamera->bindTargetAndRotation(false);
        cockpitCamera->setFarValue(40000.0f);
        cockpitCamera->setNearValue(0.1f);
        smgr->setActiveCamera(camera);
        device->getCursorControl()->setVisible(false);
        // Add a light
        //scene::ILightSceneNode* light = smgr->addLightSceneNode
        smgr->addLightSceneNode
        (
                0,
                core::vector3df(600,1100,400),
                video::SColorf(1.0f,1.0f,1.0f,1.0f),
                1000.0f // radius
        );
        smgr->addLightSceneNode
        (
                0,
                core::vector3df(-600,1100,-400),
                video::SColorf(1.0f,1.0f,1.0f,1.0f),
                1000.0f // radius
        );
 
        int lastFPS = -1;
        u32 lastTime = device->getTimer()->getTime();
        u32 deltaTime = 0;
 
        while(device->run())
        if (device->isWindowActive())
        {
                deltaTime = device->getTimer()->getTime() - lastTime; //<---------
                uh1->update(deltaTime);
                model->update();
 
                if (smgr->getActiveCamera() == cockpitCamera)
                {
                        model->updateCockpitCamera(cockpitCamera, cameraOffset);
                }
 
                driver->beginScene(true, true, 0);
                smgr->drawAll();
 
                model->drawLandingGuide(selector, 0xFFFF0000);
 
                driver->endScene();
 
                int fps = driver->getFPS();
                if (lastFPS != fps)
                {
                        core::stringw str = L"Irrlicht Engine [";
                        str += driver->getName();
                        str += "] FPS:";
                        str += fps;
                        device->setWindowCaption(str.c_str());
                        lastFPS = fps;
                }
 
                lastTime = device->getTimer()->getTime(); //<---------
        }
 
        if (uh1) { delete uh1; uh1 = 0; }
        if (model) { delete model; model = 0; }
        //device->drop();
        return 0;
}
 
ACE247
Posts: 704
Joined: Tue Mar 16, 2010 12:31 am

Re: Chopper scene node for the Bell UH-1 helicopter

Post by ACE247 »

Nice work! Figure I might convert this into a generic chopper scene node that takes an xml as input to create a chopper ;)
Edit: Wait, even better make a general vehicle creator aswell for my game engine.
Allthough this isn't really a scene node as such, it merely constructs a new scene node from lots of others, going to see if that can be fixed to reduce the number of draw calls.
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Chopper scene node for the Bell UH-1 helicopter

Post by smso »

ACE247 wrote:Nice work! Figure I might convert this into a generic chopper scene node that takes an xml as input to create a chopper ;)
Edit: Wait, even better make a general vehicle creator aswell for my game engine.
Allthough this isn't really a scene node as such, it merely constructs a new scene node from lots of others, going to see if that can be fixed to reduce the number of draw calls.
I'm happy to see these codes are of some use to you.

I'm working on using an xml file to set the positional offsets, rotations, etc. of the chopper scene node. However, I would like to input/output xml in text form instead of in binary form (of the io::IXMLReader and io::IXMLWriter). Any suggestion?

Regards
smso
ACE247
Posts: 704
Joined: Tue Mar 16, 2010 12:31 am

Re: Chopper scene node for the Bell UH-1 helicopter

Post by ACE247 »

Have a look at the xml handling example. Im pretty sure everyhtings covered in there ;)
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Chopper scene node for the Bell UH-1 helicopter

Post by smso »

ACE247 wrote:Have a look at the xml handling example. Im pretty sure everyhtings covered in there ;)
Thanks for the info.
I studied CXMLWriter.cpp and CXMLWriter.h in the irrlicht source and I think I have to write my own binary-to-text and text-to-binary functions.

Regards
smso
ACE247
Posts: 704
Joined: Tue Mar 16, 2010 12:31 am

Re: Chopper scene node for the Bell UH-1 helicopter

Post by ACE247 »

huh? Why's that? You should be able to just get the model path strings and floats from an xml file no problem.
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Chopper scene node for the Bell UH-1 helicopter

Post by smso »

ACE247 wrote:huh? Why's that? You should be able to just get the model path strings and floats from an xml file no problem.
I know that but I just want to open the xml file in a text editor and do some quick edit.

Regards
smso
Katsankat
Posts: 178
Joined: Sun Mar 12, 2006 4:15 am
Contact:

Re: Chopper scene node for the Bell UH-1 helicopter

Post by Katsankat »

Flightgear... gotta dig more into JSBSim they do with XML too
Post Reply