Retourner au sujet

  Message initiale datant du 25 October 2010 à 23h 20mn 19s

ben je vient de faire t'es modification mais quand je monte et que je tourne a droite ou a gauche il fait une boucle bizard qui n'est pas bon voila le code que j'ai fait

Code:

#include <irrlicht.h>
#include "CShieldManager.h"
#include "Following_Camera.h"
#include "CEventManager.h"

using namespace irr;
using namespace core;
using namespace gui;
using namespace video;
using namespace scene;

void event_manager(MyEventReceiver *receiver, IAnimatedMeshSceneNode *battle_turtle1, ISceneNode* plane)
{
    int rot1 = 0, rot2 = 0;
    vector3df rot, rrot;
    rot.Y += 0.7;

    if(receiver->IsKeyDown(KEY_KEY_Z))
    {
        vector3df facing(cos(battle_turtle1->getRotation().Y * PI/180.0f), -sin(battle_turtle1->getRotation().Z * PI/180.0f), -sin(battle_turtle1->getRotation().Y * PI/180.0f));
        facing.normalize();
        vector3df newPos = battle_turtle1->getPosition() - (facing + (facing * (f32)0.5f));
        battle_turtle1->setPosition(newPos);

        if(receiver->IsKeyDown(KEY_KEY_Q))
        {
            if (battle_turtle1->getRotation().X <= -30)
            {
                rot1 = 0;
            }
            else
            {
                rot1 = rot1 + 1;
            }

            battle_turtle1->setRotation(battle_turtle1->getRotation() + vector3df(-rot1,-rot.Y,0));
        }
        else if(receiver->IsKeyDown(KEY_KEY_D))
        {
            if (battle_turtle1->getRotation().X >= 30)
            {
                rot2 = 0;
            }
            else
            {
                rot2 = rot2 + 1;
            }

            battle_turtle1->setRotation(battle_turtle1->getRotation()+ vector3df(rot2,rot.Y,0));
        }
        else if(receiver->IsKeyDown(KEY_KEY_Q) == false && receiver->IsKeyDown(KEY_KEY_D) == false)
        {
            if (battle_turtle1->getRotation().X < 0)
            {
                rot1 = rot1 + 1;
            }
            else if (battle_turtle1->getRotation().X == 0)
            {
                rot1 = 0;
                rot2 = 0;
            }
            else if (battle_turtle1->getRotation().X > 0)
            {
                rot2 = rot2 - 1;
            }

            battle_turtle1->setRotation(battle_turtle1->getRotation() + vector3df(rot1,0,0));
            battle_turtle1->setRotation(battle_turtle1->getRotation() + vector3df(rot2,0,0));
        }
    }
    else if(receiver->IsKeyDown(KEY_KEY_Q))
    {
        if (battle_turtle1->getRotation().X <= -30)
        {
            rot1 = 0;
        }
        else
        {
            rot1 = rot1 + 1;
        }

        battle_turtle1->setRotation(battle_turtle1->getRotation()+vector3df(-rot1,-rot.Y,0));
    }

    else if(receiver->IsKeyDown(KEY_KEY_A))
    {
        battle_turtle1->setRotation(battle_turtle1->getRotation()+vector3df(0,0,1));
    }
    else if(receiver->IsKeyDown(KEY_KEY_E))
    {
        battle_turtle1->setRotation(battle_turtle1->getRotation()-vector3df(0,0,1));
    }

    else if(receiver->IsKeyDown(KEY_KEY_D))
    {
        if (battle_turtle1->getRotation().X >= 30)
        {
            rot2 = 0;
        }
        else
        {
            rot2 = rot2 + 1;
        }

        battle_turtle1->setRotation(battle_turtle1->getRotation()+ vector3df(rot2,rot.Y,0));
    }

    else if(receiver->IsKeyDown(KEY_KEY_Q) == false && receiver->IsKeyDown(KEY_KEY_D) == false)
    {
        if (battle_turtle1->getRotation().X < 0)
        {
            rot1 = rot1 + 1;
        }
        else if (battle_turtle1->getRotation().X == 0)
        {
            rot1 = 0;
            rot2 = 0;
        }
        else if (battle_turtle1->getRotation().X > 0)
        {
            rot2 = rot2 - 1;
        }

        battle_turtle1->setRotation(battle_turtle1->getRotation() + vector3df(rot1,0,0));
        battle_turtle1->setRotation(battle_turtle1->getRotation() + vector3df(rot2,0,0));
    }
}

int main(void)
{

    IrrlichtDevice* device = irr::createDevice(EDT_OPENGL,dimension2d<irr::u32>(1024,768),32,false,false,true);
    IVideoDriver* driver = device->getVideoDriver ();
    ISceneManager *sceneManager = device->getSceneManager ();

    scene::IAnimatedMeshSceneNode *shield_node;

    sceneManager->addSkyBoxSceneNode(
            driver->getTexture("Data/skybox/irrlicht2_up.jpg"),
            driver->getTexture("Data/skybox/irrlicht2_dn.jpg"),
            driver->getTexture("Data/skybox/irrlicht2_lf.jpg"),
            driver->getTexture("Data/skybox/irrlicht2_rt.jpg"),
            driver->getTexture("Data/skybox/irrlicht2_ft.jpg"),
            driver->getTexture("Data/skybox/irrlicht2_bk.jpg"));

    scene::ILightSceneNode* lumiere = sceneManager->addLightSceneNode(0,vector3df(500000,0,10000),SColorf(255, 255, 255),5000000.0f);

    lumiere->getLightData().Type = ELT_POINT;

    f32 radius = 0.1;
    u32 duration = 500;
    video::SColorf impact_color(1,1,1,1);

    device->getCursorControl ()-> setVisible (true);    // curseur invisible

    scene::IMeshManipulator *manipulator = sceneManager->getMeshManipulator();

    CShieldManager *shieldmanager = new CShieldManager(sceneManager,device->getTimer());

    scene::ISceneNode * plane = sceneManager->addCubeSceneNode(0.0001f);
    scene::IAnimatedMeshSceneNode *battle_turtle1 = sceneManager->addAnimatedMeshSceneNode(sceneManager->getMesh("Data/model/dedale/dedale.b3d"), plane);
    scene::ISceneNode * planet = sceneManager->addSphereSceneNode(5,96);
    scene::ISceneNode * soleil = sceneManager->addSphereSceneNode(5,96);

    planet->setScale(vector3df(20,20,20));
    planet->setPosition(vector3df(20000,0,0));
    soleil->setScale(vector3df(20*18,20*18,20*18));
    soleil->setPosition(vector3df(0,0,0));
    soleil->setMaterialFlag(EMF_LIGHTING, false);
    lumiere->setPosition(soleil->getPosition());
    battle_turtle1->setScale(core::vector3df(1,1,1));
    battle_turtle1->setPosition(core::vector3df(20000,0,100));

    battle_turtle1->setMaterialFlag(EMF_LIGHTING, true);
    shield_node = sceneManager->addAnimatedMeshSceneNode(sceneManager->getMesh("Data/model/dedale/shield_dedale.b3d"),battle_turtle1);
    shield_node->setMaterialTexture(0,driver->getTexture("Data/textures/water.jpg"));
    shield_node->setMaterialTexture(1,driver->getTexture("Data/textures/gradient_blinds.png"));
    planet->setMaterialTexture(0,driver->getTexture("Data/textures/terre.jpg"));
    soleil->setMaterialTexture(0,driver->getTexture("Data/textures/soleil.png"));

    manipulator->scaleTCoords(shield_node->getMesh(),core::vector2df(6,6),1);
    shield_node->setMaterialFlag(video::EMF_BACK_FACE_CULLING,false);
    shield_node->setScale(core::vector3df(1,1,1));
    shield_node->setVisible(false);

    scene::ITriangleSelector *selector = sceneManager->createTriangleSelector(shield_node->getMesh(),shield_node);
    selector = sceneManager->createTriangleSelector(shield_node->getMesh(),shield_node);
    shield_node->setTriangleSelector(selector);
    selector->drop();

    scene::ITriangleSelector *selector1;

    shieldmanager->addShield(shield_node);

    FollowingCamera* MaCamera = new FollowingCamera(battle_turtle1, sceneManager,false, 50000,selector1,-3,0.5f,0,vector3df(7,2,0));   // Position initiale.

    MyEventReceiver receiver;
    device->setEventReceiver(&receiver);

    int lastFPS = -1;
    u32 lastMS = device->getTimer()->getRealTime();

    while (device->run())                                // la boucle de rendu
    {
        u32 difMs = device->getTimer()->getRealTime()-lastMS;
        lastMS = device->getTimer()->getRealTime();
        f32 alignSpeed = difMs/16.0;

        if(lastMS%(rand()%20+30)==0)
        {
            core::vector3df source = vector3df(50,10,50);
            core::vector3df target = battle_turtle1->getPosition();

            const core::line3df ray(source,target);

            core::vector3df result = shieldmanager->addImpact(shield_node, ray,radius*250,duration,impact_color);
            core::matrix4 trans = shield_node->getAbsoluteTransformation();
            trans.makeInverse();
            trans.transformVect(result);
        }

        event_manager(&receiver,battle_turtle1,plane );

        driver->beginScene(true,true,SColor(0,200,200,200));
        MaCamera->Update();
        sceneManager->drawAll ();
        shieldmanager->drawAll();
        driver->endScene ();
    }

    device->drop ();
    delete shieldmanager;
    delete MaCamera;
    return 0;
}


Options Liens officiels Caractéristiques Statistiques Communauté
Corrections
irrlicht
irrklang
irredit
irrxml
xhtml 1.0
css 2.1
Propulsé par FluxBB
Traduit par FluxBB.fr
883 membres
1429 sujets
11121 messages
Dernier membre inscrit: Saidov17
130 invités en ligne
Aucun membre connecté
RSS Feed