PageRenderTime 34ms CodeModel.GetById 17ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 1ms

/TGame/TCommon/Gene/Status/GERPGStatus.cpp

http://awoe.googlecode.com/
C++ | 148 lines | 107 code | 31 blank | 10 comment | 23 complexity | f2b6b83141ca06b3f2706baf786a7bd3 MD5 | raw file
  1///////////////////////////////////////////////////////////////////////////////////////////////////
  2// GERPGStatus.h
  3// Tuesday, July 20, 2010
  4// Copyright ?2009, 2010, 8DWorld, Inc. All rights reserved.
  5//
  6// $Description$
  7///////////////////////////////////////////////////////////////////////////////////////////////////
  8#include "StdAfx.h"
  9#include "UGRPGStatus.h"
 10#include "base/HWBase.h"
 11#include "Data/StaticUnitDataLoader.h"
 12#include "Data/StaticDataFactoryIf.h"
 13#include "Data/Static2DRenderPictureData.h"
 14#include "Util/MovableTextConstants.h"
 15#include "Unit/ObserverCliUnit.h"
 16
 17extern HWBase* GetRootApp();
 18
 19UGRPGStatus::GERPGStatus(void) :
 20m_nStatusId(0),
 21m_pMovablePic(NULL),
 22m_pSceneNode(NULL),
 23m_nExistTime(0),
 24m_ptStart(0,0,0),
 25m_ptVector(-4, 2, 0)//Test data
 26{
 27}
 28
 29UGRPGStatus::GERPGStatus(int nStatusID) :
 30m_nStatusId(nStatusID),
 31m_pMovablePic(NULL),
 32m_pSceneNode(NULL),
 33m_nExistTime(0),
 34m_ptStart(0,0,0),
 35m_ptVector(0, 0, 50) //Test data
 36{
 37}
 38
 39UGRPGStatus::~UGRPGStatus(void)
 40{
 41}
 42
 43
 44bool GERPGStatus::OnAttach()
 45{
 46	ObserverCliUnit* pObs = dynamic_cast<ObserverCliUnit*>(m_pUnit->GetObserver());
 47
 48	if (pObs==NULL)
 49	{
 50		return false;
 51	}
 52
 53	m_pSceneNode = pObs->GetSceneNode();
 54	if(NULL == m_pSceneNode)
 55	{
 56		return false;
 57	}
 58
 59    //To create sence node
 60     Ogre::SceneManager* pSceneMgr = GetRootApp()->GetOgreBase()->GetSceneManager();
 61    if(NULL == pSceneMgr)
 62        return false;
 63
 64    IStaticDataLoader* pStaticLoader = g_StaticDataFactory->GetLoader(Static2DRenderPictureData::category);
 65    if(NULL == pStaticLoader)
 66        return false;
 67
 68    Static2DRenderPictureData* p2DPicData = dynamic_cast<Static2DRenderPictureData*>(pStaticLoader->Get(m_nStatusId));  
 69    if(NULL == p2DPicData)
 70        return false;
 71
 72    Vector3 unitPos(Vector3::ZERO);
 73    Vector3 vct3ScreenPt;
 74	Ogre::Camera* pCamera = GetRootApp()->GetOgreBase()->GetCamera();
 75	if (pCamera)
 76	{
 77		vct3ScreenPt = pCamera->getProjectionMatrix() * pCamera->getViewMatrix() * unitPos;
 78	}
 79
 80    Vector4 area(p2DPicData->m_TexUV.left, p2DPicData->m_TexUV.top, p2DPicData->m_TexUV.right,p2DPicData->m_TexUV.bottom);
 81    Vector2 init(vct3ScreenPt.x, vct3ScreenPt.y);
 82    Vector2 sizeTex(p2DPicData->m_TexWidth, p2DPicData->m_TexHeight);
 83    Vector2 sizeWin(defaultRenderWindowWidth, defaultRenderWindowHeight);
 84
 85
 86    m_area1 = area;
 87
 88    p2DPicData = dynamic_cast<Static2DRenderPictureData*>(pStaticLoader->Get(1003));  
 89    if(NULL == p2DPicData)
 90        return false;
 91
 92    Vector4 area2(p2DPicData->m_TexUV.left, p2DPicData->m_TexUV.top, p2DPicData->m_TexUV.right,p2DPicData->m_TexUV.bottom);
 93
 94    m_area2 = area2;
 95
 96    if(NULL == m_pSceneNode)
 97        return false;
 98
 99    string strName = "UGRPGStatus_";
100    strName += StringConverter::toString((int)this);
101
102    m_pMovablePic = new Movable2DPicture(strName ,p2DPicData->m_TexName, vct3ScreenPt, area, init, sizeTex, sizeWin, RENDER_QUEUE_6, 0, 0, 0, false );
103    m_pSceneNode->attachObject(m_pMovablePic);
104   
105
106    m_nExistTime = m_nTTL;
107
108    return true;
109}
110
111bool GERPGStatus::OnDetach()
112{
113    if(NULL != m_pSceneNode && NULL != m_pMovablePic)
114    {
115        m_pSceneNode->detachObject(m_pMovablePic->getName());
116        SAFE_DELETE(m_pMovablePic);
117    }    
118
119    return true;
120}
121void GERPGStatus::SetStatusId(int nId)
122{
123    m_nStatusId = nId;
124}
125
126
127bool GERPGStatus::OnUpdate(int nElapse)
128{
129    //if(!__super::OnUpdate(nElapse))
130    //    return false;
131
132    return OnUpdatePosition();
133}
134
135bool GERPGStatus::OnUpdatePosition()
136{
137    if(NULL == m_pSceneNode || NULL == m_pMovablePic)
138        return false;
139	if (m_nExistTime<=40)
140	{
141		m_nExistTime++;
142		Vector3 ptOffset =  m_ptVector * (Real(m_nExistTime) / 40);
143		ptOffset.x = m_ptVector.x;
144		m_pMovablePic->SetOffset(ptOffset);
145	}
146
147    return true;
148}