IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Ogre Discussion :

Collision entre mesh et terrain


Sujet :

Ogre

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Débutant
    Inscrit en
    Mai 2014
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Belgique

    Informations professionnelles :
    Activité : Débutant
    Secteur : Enseignement

    Informations forums :
    Inscription : Mai 2014
    Messages : 10
    Points : 6
    Points
    6
    Par défaut Collision entre mesh et terrain
    Bonjour à tous,

    étant assez avancé dans mon projet de petit jeu-vidéo en ligne , j'aimerais savoir comment gérer les collisions entre le terrain et un mesh ?

    j'ai testé avec un ray mais ça ne fonctionne pas .... :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    charCurrentPos = mCharNode->getPosition();
     
        Ray characterRay(Vector3(charCurrentPos.x, 5000.0f, charCurrentPos.z),Vector3::NEGATIVE_UNIT_Y);
     
        mRaySceneQuery->setRay(characterRay);       
        mRaySceneQuery->setSortByDistance(false);
     
        RaySceneQueryResult &result=mRaySceneQuery->execute();
        RaySceneQueryResult::iterator itr;
     
        for(itr = result.begin(); itr != result.end(); itr++){         
            if(itr->worldFragment){             
                Real terrainHeight = itr->worldFragment->singleIntersection.y;               
                if(terrainHeight!=charCurrentPos.y){               
                    mCharNode->setPosition(Vector3(charCurrentPos.x, terrainHeight, charCurrentPos.z));                                                         
                    break;
                }
            }
        }
    J'ai également testé avec la fonction getHeightAtWoldPosition mais ça ne fonctionne toujours pas (quoique maintenant le mesh se trouve au dessus du terrain) :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    Ogre::Vector3 robotPos = mRobotNode->getPosition();
        Ogre::Ray robotRay(Ogre::Vector3(robotPos.x,5000.0f,robotPos.z),Ogre::Vector3::NEGATIVE_UNIT_Y);
     
        mRaySceneQuery->setRay(robotRay);
        mRaySceneQuery->setSortByDistance(false);
     
        Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
        Ogre::RaySceneQueryResult::iterator itr = result.begin();
     
        if(itr != result.end() && itr->movable)
        {
            float terrainHeight = mTerrain->getHeightAtWorldPosition(Ogre::Vector3(robotPos.x,0.0f, robotPos.z));
                if(terrainHeight > robotPos.y)
                {
                    mRobotNode->setPosition(robotPos.x,terrainHeight,robotPos.z);
                    mCameraNode->setPosition(robotPos.x,terrainHeight,robotPos.z);
     
                }
        }

    Nom : Untitled.png
Affichages : 345
Taille : 649,9 Ko
    Voilà ce que ça donne

    Merci beaucoup pour votre aide précieuse

  2. #2
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 859
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 859
    Points : 218 580
    Points
    218 580
    Billets dans le blog
    120
    Par défaut
    Bonjour,

    Dans quel cas cela ne fonctionne pas l'histoire de la hauteur du terrain ? Cela devrait pourtant assez bien fonctionné ? Qu'est ce qui ne vous convient pas.
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Débutant
    Inscrit en
    Mai 2014
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Belgique

    Informations professionnelles :
    Activité : Débutant
    Secteur : Enseignement

    Informations forums :
    Inscription : Mai 2014
    Messages : 10
    Points : 6
    Points
    6
    Par défaut
    Ca ne se voit pas bien sur la photo mais j'aimerais que mon mesh descende quand le terrain descend et vis vers ça en fait là mon mesh reste en ligne droite et "vole" malgré le code :s

  4. #4
    Expert éminent sénior
    Avatar de Kannagi
    Homme Profil pro
    cyber-paléontologue
    Inscrit en
    Mai 2010
    Messages
    3 214
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : cyber-paléontologue

    Informations forums :
    Inscription : Mai 2010
    Messages : 3 214
    Points : 10 140
    Points
    10 140
    Par défaut
    Il suffit de regarder avec cout la valeur de terrainHeight.
    Après sur le net j'ai vu qu'il mettait une valeur assez élevé pour y (peut être qu'il test vers le bas) , ça donnerai donc ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    terrainHeight= mTerrain->getHeightAtWorldPosition(Ogre::Vector3(robotPos.500000, robotPos.z));

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Débutant
    Inscrit en
    Mai 2014
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Belgique

    Informations professionnelles :
    Activité : Débutant
    Secteur : Enseignement

    Informations forums :
    Inscription : Mai 2014
    Messages : 10
    Points : 6
    Points
    6
    Par défaut
    Aucun changement, le mesh vole toujours :/ par contre j'ai remarqué que c'était peut-être un problème de : mSceneMgr = mRoot->createSceneManager(Ogre::ST_EXTERIOR_CLOSE);

    je vois souvent que des gens mette après : mgr->setWorldGeometry("terrain.cfg");

    j'espère que vous allez m'aider Merci

  6. #6
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 859
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 859
    Points : 218 580
    Points
    218 580
    Billets dans le blog
    120
    Par défaut
    Bonjour,

    Moi, j'afficherai la valeur de mTerrain->getHeightAtWorldPosition(Ogre::Vector3(robotPos.500000, robotPos.z)); pour savoir ce que "voit" Ogre.
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  7. #7
    Futur Membre du Club
    Homme Profil pro
    Débutant
    Inscrit en
    Mai 2014
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Belgique

    Informations professionnelles :
    Activité : Débutant
    Secteur : Enseignement

    Informations forums :
    Inscription : Mai 2014
    Messages : 10
    Points : 6
    Points
    6
    Par défaut
    Merci pour ta réponse . J'ai donc testé la valeur avec un simple cout et la variable renvoi la valeur : 249.412 quelque soit la valeur du y de mterrainheight

    Enfait la valeur de terraiHeight reste fixe, et c'est de là que vient le problème à mon avis, mais comment faire ...

  8. #8
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 859
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 859
    Points : 218 580
    Points
    218 580
    Billets dans le blog
    120
    Par défaut
    Je pense que le terrain est mal interprété. Peut être un soucis de configuration ?
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  9. #9
    Futur Membre du Club
    Homme Profil pro
    Débutant
    Inscrit en
    Mai 2014
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Belgique

    Informations professionnelles :
    Activité : Débutant
    Secteur : Enseignement

    Informations forums :
    Inscription : Mai 2014
    Messages : 10
    Points : 6
    Points
    6
    Par défaut
    Je vais vous poster mon projet en entier dans la soirée ou demain car je ne l'ai pas sous le main en ce moment même . Merci encore pour votre aide précieuse

  10. #10
    Futur Membre du Club
    Homme Profil pro
    Débutant
    Inscrit en
    Mai 2014
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Belgique

    Informations professionnelles :
    Activité : Débutant
    Secteur : Enseignement

    Informations forums :
    Inscription : Mai 2014
    Messages : 10
    Points : 6
    Points
    6
    Par défaut
    Character.cpp :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    #include "Character.h"
     
    appDemarrage::appDemarrage() : mRoot(0),mWindow(0),mSceneMgr(0),mCamera(0)
    {
    	mSpeed = 50.0f;
    	mDestination = Ogre::Vector3::ZERO;
    	mDistance = 0.0f;
    }
    appDemarrage::~appDemarrage()
    {
    	delete mRoot;
    	delete mInputListener;
    }
    bool appDemarrage::start()
    {
        mRoot = new Ogre::Root("plugins_d.cfg","ogre.cfg","Ogre.log");
     
        Ogre::ConfigFile configFile;
     
        configFile.load("resources_d.cfg");
     
        Ogre::ConfigFile::SectionIterator seci = configFile.getSectionIterator();
     
        Ogre::String secName, typeName, archType;
     
        while(seci.hasMoreElements())
        {
            secName = seci.peekNextKey();
            Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
            Ogre::ConfigFile::SettingsMultiMap::iterator i;
     
            for(i = settings->begin(); i != settings->end();++i)
            {
                typeName = i->first;
                archType = i->second;
     
                Ogre::ResourceGroupManager::getSingleton().addResourceLocation(archType,typeName,secName);
            }
        }
     
        if(!(mRoot->restoreConfig() || mRoot->showConfigDialog()))
        {
            return false;
        }
     
        Ogre::RenderSystem *rs = mRoot->getRenderSystemByName("Direct3D9 Rendering Subsystem");
        mRoot->setRenderSystem(rs);
        rs->setConfigOption("Full Screen","No");
        rs->setConfigOption("Video Mode","1600 x 900 @ 32-bit colour");
        rs->setConfigOption("VSync","Yes");
     
    	mWindow = mRoot->initialise(true,"Eroilor");
     
    	Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
    	Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
     
    	createScene();
    	createFrameListener();
     
    	while(true)
    	{
    		Ogre::WindowEventUtilities::messagePump();
     
    		if(mWindow->isClosed())
    			return false;
    		if(!mRoot->renderOneFrame()) 
    			return false;
     
    	}
     
        return true;
    }
    void appDemarrage::createScene()
    {
     
    	mSceneMgr = mRoot->createSceneManager("DefaultSceneManager","Scene Mgr");
    	mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5f, 0.5f, 0.5f));
        Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(Ogre::TFO_ANISOTROPIC);
        Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(8);
     
    	mSceneMgr->setSkyDome(true,"Examples/CloudySky",2,10.0);
     
    	Ogre::Vector3 lightdir(0.55f, -0.3f, 0.75f);
            mLight = mSceneMgr->createLight("terrainLight");
            mLight->setType(Ogre::Light::LT_DIRECTIONAL);
            mLight->setDirection(lightdir);
            mLight->setDiffuseColour(Ogre::ColourValue::White);
            mLight->setSpecularColour(Ogre::ColourValue(0.4f, 0.4f, 0.4f));
     
    	mCamera = mSceneMgr->createCamera("Camera");
        mCamera->setPosition(Ogre::Vector3(0,15,-50));
        mCamera->lookAt(Ogre::Vector3(0,0,0));
        mCamera->setNearClipDistance(5);
     
        Ogre::Viewport* vp = mWindow->addViewport(mCamera);
        vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
     
     
        mCamera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));
     
    	mMainNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("MainNode");
    	mMainNode->translate(Ogre::Vector3(0,100,0));
     
    	mRobotNode = mMainNode->createChildSceneNode("PlayerNode");
    	mCameraNode = mMainNode->createChildSceneNode("CameraNode");
     
    	mCameraPitchNode = mCameraNode->createChildSceneNode("CameraPitchNode");
    	mCameraPitchNode->attachObject(mCamera);
     
    	mCameraNode->setPosition(0,0,150);
     
    	mCamera->setFOVy(Ogre::Radian(0.7f));
     
    	mRobot = mSceneMgr->createEntity("Sinbad","Sinbad/Sinbad.mesh");
    	mRobotNode->attachObject(mRobot);
     
    	mRobotNode->setPosition(0,0,150);
     
    	createTerrain();
     
    	mSword1 = mSceneMgr->createEntity("SinbadSword1","Sword.mesh");
    	mSword2 = mSceneMgr->createEntity("SinbadSword2","Sword.mesh");
    	mRobot->attachObjectToBone("Sheath.L",mSword1);
    	mRobot->attachObjectToBone("Sheath.R",mSword2);
     
    	mAnimationStateBase = mRobot->getAnimationState("IdleBase");
    	mAnimationStateTop = mRobot->getAnimationState("IdleTop");
     
    	mAnimationStateBase->setEnabled(true);
    	mAnimationStateTop->setEnabled(true);
     
    	mAnimationStateBase->setLoop(true);
    	mAnimationStateTop->setLoop(true);
     
     
    }
    void appDemarrage::createFrameListener()
    {
     
    	mInputListener = new InputListener(mWindow,mCamera,mSceneMgr);
    	mRoot->addFrameListener(mInputListener);
     
    	mRoot->addFrameListener(this);
     
    }
    void appDemarrage::createTerrain()
        {
    		mTerrain = OGRE_NEW Ogre::Terrain(mSceneMgr);
     
    		// options globales
    		mGlobals = OGRE_NEW Ogre::TerrainGlobalOptions();
    		mGlobals->setMaxPixelError(10);
    		mGlobals->setCompositeMapDistance(8000);
    		mGlobals->setLightMapDirection(mLight->getDerivedDirection());
    		mGlobals->setCompositeMapAmbient(mSceneMgr->getAmbientLight());
    		mGlobals->setCompositeMapDiffuse(mLight->getDiffuseColour());
     
    		Ogre::Image img;
    		img.load("terrain.png", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
     
    		// informations géométriques
    		Ogre::Terrain::ImportData imp;
    		imp.inputImage = &img;
    		imp.terrainSize = img.getWidth();
    		imp.worldSize = 8000;
    		imp.inputScale = 600;
    		imp.minBatchSize = 33;
    		imp.maxBatchSize = 65;
     
    		// textures
    		imp.layerList.resize(3);
    		imp.layerList[0].worldSize = 100;
    		imp.layerList[0].textureNames.push_back("grass_green-01_diffusespecular.dds");
    		imp.layerList[0].textureNames.push_back("grass_green-01_normalheight.dds");
    		imp.layerList[1].worldSize = 30;
    		imp.layerList[1].textureNames.push_back("growth_weirdfungus-03_diffusespecular.dds");
    		imp.layerList[1].textureNames.push_back("growth_weirdfungus-03_normalheight.dds");
    		imp.layerList[2].worldSize = 200;
    		imp.layerList[2].textureNames.push_back("dirt_grayrocky_diffusespecular.dds");
    		imp.layerList[2].textureNames.push_back("dirt_grayrocky_normalheight.dds");
    		mTerrain->prepare(imp);
    		mTerrain->load();
     
    		// plaquage de texture
    		Ogre::TerrainLayerBlendMap* blendMap1 = mTerrain->getLayerBlendMap(1);
    		float* pBlend1 = blendMap1->getBlendPointer();
     
    		for (Ogre::uint16 y = 0; y < mTerrain->getLayerBlendMapSize(); ++y)
    			{
    				for (Ogre::uint16 x = 0; x < mTerrain->getLayerBlendMapSize(); ++x)
    					{
    						*pBlend1++ = 150;
    					}
    			}
     
    		blendMap1->dirty();
    		blendMap1->update();
     
    		mTerrain->freeTemporaryResources();
        }
     
    bool appDemarrage::frameRenderingQueued(const Ogre::FrameEvent& evt)
    {
     
    	Ogre::Vector3 Direction = mRobotNode->getOrientation()*Ogre::Vector3::NEGATIVE_UNIT_X;
    	Direction.normalise();
    	Ogre::Vector3 Movement;
    	Movement = Ogre::Vector3(0,0,0);
     
     
    	mAnimationStateBase->setEnabled(false);
    	mAnimationStateTop->setEnabled(false);
     
    	if(mInputListener->getKeyboard()->isKeyDown(OIS::KC_W))
    	{
    		Movement.z += Direction.x * -1;
    		Movement.x += Direction.z;
    	}
    	if(mInputListener->getKeyboard()->isKeyDown(OIS::KC_S))
    	{
    		Movement.x += Direction.z * -1;
    		Movement.z += Direction.x;
    	}
    	if(mInputListener->getKeyboard()->isKeyDown(OIS::KC_D))
    	{
    		mRobotNode->yaw(Ogre::Radian(-2*evt.timeSinceLastFrame));
    	}
    	if(mInputListener->getKeyboard()->isKeyDown(OIS::KC_A))
    	{
    		mRobotNode->yaw(Ogre::Radian(2*evt.timeSinceLastFrame));
    	}
     
    	if(Movement.x == 0 && Movement.z == 0 )
    	{
    		mAnimationStateBase = mRobot->getAnimationState("IdleBase");
    		mAnimationStateTop = mRobot->getAnimationState("IdleTop");
    	}
    	else
    	{
    		Movement = Movement * evt.timeSinceLastFrame * 35;
    		mMainNode->translate(Movement);
    		mAnimationStateBase = mRobot->getAnimationState("RunBase");
    		mAnimationStateTop = mRobot->getAnimationState("RunTop");
    	}
    	if(mInputListener->getMouse()->getMouseState().buttonDown(OIS::MB_Right))
    	{
    		mCameraNode->yaw(mInputListener->getRotationY());
    		mCameraPitchNode->pitch(mInputListener->getRotationX());
    	}
     
    	if(mInputListener->getKeyboard()->isKeyDown(OIS::KC_T))
    	{
    		mSwordsDrawn = true;
    		mAnimationStateTop = mRobot->getAnimationState("DrawSwords");
    		mAnimationStateTop->setLoop(false);
    		mAnimationStateTop->setEnabled(true);
     
    		mRobot->detachAllObjectsFromBone();
    		mRobot->attachObjectToBone("Handle.L",mSword1);
    		mRobot->attachObjectToBone("Handle.R",mSword2);
     
     
    	}
    	if(mInputListener->getMouse()->getMouseState().buttonDown(OIS::MB_Left))
    	{
    		if(mSwordsDrawn == true)
    		{
    			mAnimationStateTop = mRobot->getAnimationState("SliceHorizontal");
    			mAnimationStateTop->setEnabled(true);
    			mAnimationStateTop->setLoop(false);
    		}
     
    	}
    	if(mInputListener->getKeyboard()->isKeyDown(OIS::KC_R))
    	{
    		mSwordsDrawn = false;
    		mAnimationStateTop = mRobot->getAnimationState("HandsClosed");
    		mRobot->detachAllObjectsFromBone();
    		mRobot->attachObjectToBone("Sheath.L",mSword1);
    		mRobot->attachObjectToBone("Sheath.R",mSword2);
    	}
     
    	mAnimationStateBase->setLoop( true );
    	mAnimationStateTop->setLoop(true);
    	mAnimationStateBase->setEnabled( true );
    	mAnimationStateTop->setEnabled(true);
    	mAnimationStateBase->addTime(evt.timeSinceLastFrame);
    	mAnimationStateTop->addTime(evt.timeSinceLastFrame);
     
    	Ogre::Vector3 robotPos = mRobotNode->getPosition();
        Ogre::Ray robotRay(Ogre::Vector3(robotPos.x,5000.0f,robotPos.z),Ogre::Vector3::NEGATIVE_UNIT_Y);
     
        mRaySceneQuery->setRay(robotRay);
        mRaySceneQuery->setSortByDistance(false);
     
        Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
        Ogre::RaySceneQueryResult::iterator itr = result.begin();
     
        if(itr != result.end() && itr->movable)
        {
            float terrainHeight = mTerrain->getHeightAtWorldPosition(Ogre::Vector3(robotPos.x,0.0f, robotPos.z));
                if(terrainHeight > robotPos.y)
                {
                    mRobotNode->setPosition(robotPos.x,terrainHeight,robotPos.z);
                    mCameraNode->setPosition(robotPos.x,terrainHeight,robotPos.z);
     
                }
        }
     
     
        return true;
    }
    Character.h :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    #ifndef APPDEMARRAGE_H_INCLUDED
    #define APPDEMARRAGE_H_INCLUDED
    #include <Ogre.h>
    #include <OGRE\Terrain\OgreTerrain.h>
    #include <OGRE\Terrain\OgreTerrainGroup.h>
    #include "InputListener.h"
     
    class appDemarrage : public Ogre::FrameListener
    {
    public:
        appDemarrage();
        ~appDemarrage();
    	void createScene();
    	void createFrameListener();
    	bool frameRenderingQueued(const Ogre::FrameEvent& evt);
    	void createTerrain();
        bool start();
     
    private:
        Ogre::Root *mRoot;
    	Ogre::RenderWindow *mWindow;
    	Ogre::SceneManager *mSceneMgr;
    	Ogre::Camera *mCamera;
    	Ogre::SceneNode* mRobotNode;
    	Ogre::SceneNode* mPlaneNode;
    	Ogre::Entity* mRobot;
    	Ogre::Entity* mSword1;
    	Ogre::Entity* mSword2;
    	Ogre::SceneNode* node;
    	bool mSwordsDrawn;
    	InputListener* mInputListener;
    	Ogre::AnimationState* mAnimationStateBase;
    	Ogre::AnimationState* mAnimationStateTop;
     
    	Ogre::Vector3 mDestination;
    	Ogre::Vector3 mDirection;
     
    	Ogre::Real mSpeed;
    	Ogre::Real mDistance;
     
    	Ogre::SceneNode* mMainNode;
    	Ogre::SceneNode* mCameraNode;
    	Ogre::SceneNode* mCameraPitchNode;
     
     
    	Ogre::Light* mLight;
     
    	Ogre::Terrain *mTerrain;
    	Ogre::TerrainGlobalOptions *mGlobals;
     
    };
     
    #endif // APPDEMARRAGE_H_INCLUDED
    InputListener.cpp :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    #include "InputListener.h"
     
     
    InputListener::InputListener(Ogre::RenderWindow *wnd, Ogre::Camera *cam,Ogre::SceneManager *sceneMgr)
    {
    	mWindow = wnd;
    	mCamera = cam;
    	mSceneMgr = sceneMgr;
    	mVitesse = 50;
    	mVitesseRotationY = 0.02;
    	mVitesseRotationX = 0.06;
     
    	mToucheAppuyee = false;	
     
    	startOIS();
    }
     
    void InputListener::startOIS()
    {
    	Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
     
    	OIS::ParamList pl;
    	size_t windowHnd = 0;
    	std::ostringstream windowHndStr;
     
    	mWindow->getCustomAttribute("WINDOW", &windowHnd);
    	windowHndStr << windowHnd;
    	pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
     
    	mInputMgr = OIS::InputManager::createInputSystem(pl);
     
    	mMouse = static_cast<OIS::Mouse*>(mInputMgr->createInputObject(OIS::OISMouse,false));
    	mKeyboard = static_cast<OIS::Keyboard*>(mInputMgr->createInputObject(OIS::OISKeyboard,false));
     
    	windowResized(mWindow);
    	Ogre::WindowEventUtilities::addWindowEventListener(mWindow,this);
     
    }
    void InputListener::windowResized(Ogre::RenderWindow* wnd)
    {
    	unsigned int width, height, depth;
    	int left,top;
     
    	wnd->getMetrics(width,height,depth,left,top);
     
    	const OIS::MouseState &ms = mMouse->getMouseState();
     
    	ms.width = width;
    	ms.height = height;
     
    }
     
    void InputListener::windowClosed(Ogre::RenderWindow* wnd)
    {
    	if(wnd == mWindow)
    	{
    		if(mInputMgr)
    		{
    			mInputMgr->destroyInputObject(mMouse);
    			mInputMgr->destroyInputObject(mKeyboard);
     
    			OIS::InputManager::destroyInputSystem(mInputMgr);
    			mInputMgr = 0;
    		}
    	}
    }
    bool InputListener::frameRenderingQueued(const Ogre::FrameEvent& evt)
    {
    	if(mWindow->isClosed())
    		return false;
    	mKeyboard->capture();
    	mMouse->capture();
     
    	if(mKeyboard->isKeyDown(OIS::KC_ESCAPE))
    		return false;
    	const OIS::MouseState &mouseState = mMouse->getMouseState();
     
    	 mRotationX = Ogre::Degree(-mouseState.Y.rel * mVitesseRotationY);
    	 mRotationY = Ogre::Degree(-mouseState.X.rel * mVitesseRotationX);
     
     
    	return true;
    }
    InputListener::~InputListener()
    {
    	Ogre::WindowEventUtilities::removeWindowEventListener(mWindow,this);
    	windowClosed(mWindow);
    }
    OIS::Keyboard* InputListener::getKeyboard()
    {
    	return mKeyboard;
    }
    Ogre::Radian InputListener::getRotationX()
    {
    	return mRotationX;
    }
    Ogre::Radian InputListener::getRotationY()
    {
    	return mRotationY;
    }
    OIS::Mouse* InputListener::getMouse()
    {
    	return mMouse;
    }
    InputListener.h:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    #include <Ogre.h>
    #include <OIS/OIS.h>
     
    class InputListener : public Ogre::FrameListener,public Ogre::WindowEventListener
    {
    public:
    	InputListener(Ogre::RenderWindow *wnd, Ogre::Camera *cam,Ogre::SceneManager *sceneMgr);
    	~InputListener();
    	bool frameRenderingQueued(const Ogre::FrameEvent& evt);
    	void startOIS();
    	OIS::Keyboard* getKeyboard();
    	OIS::Mouse* getMouse();
    	Ogre::Radian getRotationX();
    	Ogre::Radian getRotationY();
     
    	virtual void windowResized(Ogre::RenderWindow* wnd);
    	virtual void windowClosed(Ogre::RenderWindow* wnd);
    protected:
    	Ogre::RenderWindow* mWindow;
    	Ogre::Camera* mCamera;
    	Ogre::SceneManager* mSceneMgr;
     
    	OIS::InputManager *mInputMgr;
    	OIS::Mouse* mMouse;
    	OIS::Keyboard* mKeyboard;
    	InputListener* mInputListener;
     
    	Ogre::Real mVitesse;
    	Ogre::Real mMouvement;
    	Ogre::Real mVitesseRotationX;
    	Ogre::Real mVitesseRotationY;
     
    	Ogre::Radian mRotationX;
    	Ogre::Radian mRotationY;
     
    	bool mToucheAppuyee;
     
    };
    main.cpp :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    #include <Ogre.h>
    #include "Character.h"
     
    #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    #define WIN32_LEAN_AND_MEAN
    #include "windows.h"
     
    INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
    #else
    int main(int argc, char **argv)
    #endif
    {
    	appDemarrage app;
        try {
    		app.start();
    	} catch(Ogre::Exception& e) {
    #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
            MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
    #else
            fprintf(stderr, "An exception has occurred: %s\n",
                e.getFullDescription().c_str());
    #endif
        }
    	system("PAUSE");
        return 0;
    }

  11. #11
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 859
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 859
    Points : 218 580
    Points
    218 580
    Billets dans le blog
    120
    Par défaut
    Dans ce tutoriel, il utilise un constructeur un peu plus compliqué :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    mTerrainGroup = OGRE_NEW Ogre::TerrainGroup(mSceneMgr, Ogre::Terrain::ALIGN_X_Z, 513, 12000.0f);
    Après, je n'ai rien vu d'autres
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  12. #12
    Futur Membre du Club
    Homme Profil pro
    Débutant
    Inscrit en
    Mai 2014
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Belgique

    Informations professionnelles :
    Activité : Débutant
    Secteur : Enseignement

    Informations forums :
    Inscription : Mai 2014
    Messages : 10
    Points : 6
    Points
    6
    Par défaut
    En fait , dans mon programme je n'utilise pas de groupe de terrain mais juste un simple terrain.

    J'ai déjà essayé d'utiliser les groupes de terrain mais mon programme plante donc je suis resté sur un simple terrain pour effectuer des tests .

    Au pire , je vais retenter d'utiliser les groupes de terrain peut-être?

  13. #13
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 859
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 859
    Points : 218 580
    Points
    218 580
    Billets dans le blog
    120
    Par défaut
    Arf, j'avais mal lu.
    Hum, je ne vois pas toujours pas ce qui choque. Pourriez vous tester le getHeight() tout en utilisant vos fichiers, mais le code du tutoriel de Ogre voir si le bogue persiste ou non ?
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  14. #14
    Futur Membre du Club
    Homme Profil pro
    Débutant
    Inscrit en
    Mai 2014
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : Belgique

    Informations professionnelles :
    Activité : Débutant
    Secteur : Enseignement

    Informations forums :
    Inscription : Mai 2014
    Messages : 10
    Points : 6
    Points
    6
    Par défaut
    Je vous posterai ça dans 2 semaines car je suis actuellement en vacances ... En espérant que le problème sera réglé merci encore pour votre aide . On se recontacte dans 2 semaines donc

Discussions similaires

  1. Irrlicht Collision entre 2 Mesh
    Par suyeon dans le forum Irrlicht
    Réponses: 3
    Dernier message: 07/07/2010, 12h40
  2. Détection de collisions entre rectangles
    Par davcha dans le forum Algorithmes et structures de données
    Réponses: 4
    Dernier message: 13/04/2006, 18h26
  3. Détection de collision entre un cube et un carré
    Par Mat 74 dans le forum Physique
    Réponses: 15
    Dernier message: 17/03/2006, 14h01
  4. GLScene et les collisions entre les objets
    Par HopeLeaves dans le forum API, COM et SDKs
    Réponses: 5
    Dernier message: 13/06/2005, 19h45
  5. Réponses: 4
    Dernier message: 25/09/2004, 09h58

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo