Changeset 6

Show
Ignore:
Timestamp:
01/08/09 00:19:15 (3 years ago)
Author:
nktug
Message:

Now it is possible to add object with animation and move it
Prepare object list to handle Building, monster and NPJ

Location:
trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/config/objects.txt

    r4 r6  
    11Batiments                
    22    Empire               
    3         TudorHouse      tudorhouse.mesh         Ogre3D house use for test 
     3        TudorHouse      tudorhouse.mesh         BLD     Ogre3D house mesh use for test 
    44Faune                    
    55    Imperial             
    6         OgreHead        ogrehead.mesh           Ogre3D mesh use for test 
    7         Ninja           ninja.mesh              Ogre3D mesh use for test 
     6        OgreHead        ogrehead.mesh           MSTR    Ogre3D head mesh use for test 
     7        Ninja           ninja.mesh              PJ      Ogre3D ninja mesh use for test 
  • trunk/src/LevelEditor.cc

    r5 r6  
    4343        angleY = 0.0; // when I upgraded to Qt4.2, they were left undefined. 
    4444         
    45         //mCurentObject = 0;  
     45  mName = ""; 
     46  mFile = ""; 
     47  mType = ""; 
    4648        closestObject = 0;// Trace the curent selected object. 
    4749  mTempEnt = 0; 
     
    112114  //QListWidgetItem* item = mObjectList->currentItem(); 
    113115  QModelIndex item = objProperties->objectView->currentIndex(); 
    114   QModelIndex itemTmp = item.sibling( item.row(), item.column()+1); 
     116  QModelIndex item1 = item.sibling( item.row(), item.column()+1); 
     117  QModelIndex item2 = item.sibling( item.row(), item.column()+2); 
    115118    
    116   if(!itemTmp.data().toString().isEmpty()) 
     119  if(!item1.data().toString().isEmpty()) 
    117120  { 
    118121    QString name = item.data().toString(); 
    119     QString meshfile = itemTmp.data().toString(); 
     122    QString meshfile = item1.data().toString(); 
     123    QString type = item2.data().toString(); 
    120124     
    121     this->createTempObject(name.toStdString() , meshfile.toStdString()); 
     125    this->createTempObject(name.toStdString() , meshfile.toStdString(), type.toStdString()); 
    122126  } 
    123127 
     
    365369 
    366370//------------------------------------------------------------------------------------------------  
    367 void LevelEdWidget::createTempObject(std::string& name, std::string& file) 
    368 { 
     371void LevelEdWidget::createTempObject(std::string& name, std::string& file, std::string& type) 
     372{ 
     373  mName = name; 
     374  mFile = file; 
     375  mType = type; 
     376   
    369377  this->changeInsertionMode(true); 
    370378   
     
    616624    { 
    617625      // Next time handle multi insertion object 
     626      ObjectPtr iObj = CObjectFactory::getInstance()->createObject(mType); 
     627      iObj->setObjectName(mName); 
     628      iObj->setObjectMeshFile(mFile); 
     629      iObj->initNodeObject(); 
     630 
     631      Ogre::Ray mouseRay = mCamera->getCameraToViewportRay((double)evt->pos().x()/(double)width(), (double)evt->pos().y()/(double)height()); 
     632      Ogre::RaySceneQuery* mRaySceneQuery = mSceneMgr->createRayQuery(Ogre::Ray());; 
     633      mRaySceneQuery->setRay(mouseRay); 
     634      //mRaySceneQuery->setSortByDistance(true); 
     635      Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute(); 
     636      Ogre::RaySceneQueryResult::iterator itr = result.begin(); 
     637 
     638      if (itr != result.end() && itr->worldFragment) 
     639      {  
     640        iObj->getSceneNode()->setPosition(itr->worldFragment->singleIntersection.x, itr->worldFragment->singleIntersection.y + 5, itr->worldFragment->singleIntersection.z); 
     641      }     
     642      iObj->getSceneNode()->showBoundingBox(false); 
     643      iObj->init(); 
     644       
     645      CObjectManager::getInstance()->addObject(iObj);       
    618646    } 
    619647        } // end LeftButton clic 
     
    640668  if(mouseLeftPressed && mInsertMode) 
    641669  { 
    642      
     670 
    643671  } 
    644672   
  • trunk/src/LevelEditor.hh

    r5 r6  
    2929        ~LevelEdWidget(); 
    3030   
    31   void createTempObject(std::string& name, std::string& file); 
     31  void createTempObject(std::string& name, std::string& file, std::string& type); 
    3232  void changeInsertionMode(bool val); 
    3333   
     
    9595        //float rotX, rotY; 
    9696        /////////////////////// 
     97  std::string mName; 
     98  std::string mFile; 
     99  std::string mType; 
    97100         
    98101        bool mouseLeftPressed; 
  • trunk/src/dreamforge/objects/Avatar.cc

    r3 r6  
    3535        : mIsDead(false)//,CGameObject() 
    3636{ 
    37    
     37  mAnimation = 0; 
    3838} 
    3939 
     
    4141CAvatar::~CAvatar() 
    4242{ 
    43         delete mAnimation; 
    44         mAnimation = 0; 
     43  if(mAnimation) 
     44  { 
     45    delete mAnimation; 
     46    mAnimation = 0; 
     47  } 
    4548} 
    4649 
     
    4851void CAvatar::init( void ) 
    4952{  
    50         mAnimation = new AnimatedObject; 
    51          
    52         // getAnimationState("Idle1") 
    53         mAnimation->setInitAnimState(CGameObject::getEntity()->getAnimationState("Idle1")); 
    54         mAnimation->setAnimLoop(true); 
     53  if(mEntity->hasSkeleton()) 
     54  { 
     55    mAnimation = new AnimatedObject; 
     56 
     57    //Temporatry choose an animation in the list 
     58    Ogre::AnimationStateIterator animIter = mEntity->getAllAnimationStates()->getAnimationStateIterator(); 
     59     
     60    // getAnimationState("Idle1") 
     61    mAnimation->setInitAnimState(mEntity->getAnimationState(animIter.getNext()->getAnimationName())); 
     62    mAnimation->setAnimLoop(true); 
     63  } 
    5564 
    5665/*       
     
    7887void CAvatar::update(float timeT) 
    7988{ 
    80         mAnimation->update(timeT); 
     89  if(mAnimation) 
     90  { 
     91    mAnimation->update(timeT); 
     92  } 
    8193} 
    8294 
     
    189201void CAvatar::move(Ogre::Vector3 tempVector) 
    190202{ 
    191         mAnimation->changeAnimState(CGameObject::getEntity()->getAnimationState("Walk")); 
    192         mAnimation->setAnimLoop(true); 
    193         ////StaticObject::translateObject(0,0,-mMoveSpeed); 
    194         //StaticObject::translateObject(tempVector); 
     203  if(mAnimation) 
     204  { 
     205    mAnimation->changeAnimState(CGameObject::getEntity()->getAnimationState("Walk")); 
     206    mAnimation->setAnimLoop(true); 
     207    ////StaticObject::translateObject(0,0,-mMoveSpeed); 
     208    //StaticObject::translateObject(tempVector); 
     209  } 
    195210} 
    196211 
     
    198213void CAvatar::turn(Ogre::Degree &angle) 
    199214{ 
    200         mAnimation->changeAnimState(CGameObject::getEntity()->getAnimationState("Walk")); 
    201         mAnimation->setAnimLoop(true); 
    202         ////StaticObject::translateObject(0,0,+mMoveSpeed); 
    203         //StaticObject::turnObject(angle); 
    204 } 
    205  
    206  
     215  if(mAnimation) 
     216  { 
     217    mAnimation->changeAnimState(CGameObject::getEntity()->getAnimationState("Walk")); 
     218    mAnimation->setAnimLoop(true); 
     219    ////StaticObject::translateObject(0,0,+mMoveSpeed); 
     220    //StaticObject::turnObject(angle); 
     221  } 
     222} 
     223 
     224