Changeset 2459 for GTP/trunk/App/Demos/Illum/Ogre
- Timestamp:
- 06/24/07 11:00:20 (18 years ago)
- Location:
- GTP/trunk/App/Demos/Illum/Ogre/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Illum/Ogre/src/Common/include/FPSPlayer.h
r2418 r2459 2 2 3 3 #include "Ogre.h" 4 #include "OgreBillboardParticleRenderer.h" 5 #include "OgreIlluminationManager.h" 4 6 #include "NXOgre.h" 5 7 … … 16 18 PLAYERANIMSTATE_PAIN, 17 19 PLAYERANIMSTATE_DEATH, 18 PLAYERANIMSTATE_URN 19 }; 20 20 PLAYERANIMSTATE_TURN 21 }; 22 23 class PlayerCharacter; 24 class FireBall; 21 25 class MyCharMoveController; 22 26 27 class CharacterManager 28 { 29 public: 30 static CharacterManager& getSingleton() 31 { 32 if(mSingleton == 0) 33 mSingleton = new CharacterManager(); 34 return *mSingleton; 35 } 36 PlayerCharacter* getTrigger(NxOgre::Actor* a) 37 { 38 if(triggers.find(a)== triggers.end()) 39 return 0; 40 return triggers[a]; 41 } 42 PlayerCharacter* getTarget(NxOgre::Actor* a) 43 { 44 if(targets.find(a)== targets.end()) 45 return 0; 46 return targets[a]; 47 } 48 49 void addTrigger(NxOgre::Actor* a, PlayerCharacter* c){triggers[a] = c;} 50 void addTarget(NxOgre::Actor* a, PlayerCharacter* c){targets[a] = c;} 51 52 void levelUP(); 53 54 SceneManager* mSceneManager; 55 Scene* mScene; 56 57 protected: 58 CharacterManager(){} 59 static CharacterManager* mSingleton; 60 std::map<NxOgre::Actor*, PlayerCharacter*> triggers; 61 std::map<NxOgre::Actor*, PlayerCharacter*> targets; 62 63 }; 64 65 23 66 class PlayerCharacter : public FrameListener 24 67 { … … 28 71 29 72 virtual void addPlayerMesh(String meshname, float meshscale, bool rotateModel); 30 bool frameStarted(const FrameEvent& evt);73 virtual bool frameStarted(const FrameEvent& evt); 31 74 virtual void addWeaponModel(String meshname, String attachBoneName); 32 void doAction(float dt); 33 75 virtual void doAction(float dt){} 76 virtual float getHit(){return 0;} 77 virtual void addHit(float hit){mHealth -= hit; if(mHealth < 0) mHealth = 0;} 78 34 79 static unsigned int frameListenerPriority; 35 80 … … 58 103 Vector3 mPlayerDimensions; 59 104 bool mRunning; 105 bool isAlive; 60 106 61 107 SceneNode* mWeaponNode2; 62 108 bool mDebug; 63 109 110 float mHealth; 111 112 float getAnimSpeed(){return 1.2;} 64 113 virtual String getAnimStateName(PlayerAnimState as, int option = 0){return "stand";} 65 virtual void setAnimState(PlayerAnimState as) 66 { 67 if(mCurrentAnimState != PLAYERANIMSTATE_WALK) 68 { 69 mCharacterMesh_AnimState = mCharacterMeshEntity->getAnimationState(getAnimStateName(as)); 70 mCharacterMesh_AnimState->setLoop(true); 71 mCharacterMesh_AnimState->setEnabled(true); 72 } 73 } 114 virtual void setAnimState(PlayerAnimState as){} 115 116 }; 117 118 class TrollCharacter : public PlayerCharacter 119 { 120 public: 121 TrollCharacter(String name, Scene* scene, SceneManager* sceneManager, Vector3 dimensions, Vector3 startPosition, bool debug = false); 122 ~TrollCharacter(){} 123 124 void doAction(float dt); 125 float getHit(){ if(mCurrentAnimState == PLAYERANIMSTATE_ATTACK) return 20; else return 0;} 126 void addHit(float hit); 127 128 bool frameStarted(const FrameEvent& evt) 129 { 130 /* OverlayElement* healthUI = OverlayManager::getSingleton().getOverlayElement("MannaColumn"); 131 float relHealth = mHealth / MaxHealth; 132 healthUI->setHeight(0.29 * relHealth); 133 healthUI->setTop(0.005 + (1.0 - relHealth) * 0.29);*/ 134 135 return PlayerCharacter::frameStarted(evt); 136 } 137 protected: 138 String getAnimStateName(PlayerAnimState as, int option = 0); 139 void setAnimState(PlayerAnimState as); 140 141 static float MaxHealth; 74 142 }; 75 143 … … 87 155 Vector3 getPosition(){return mPlayerNode->getWorldPosition(); 88 156 return mPlayerCharacter->getGlobalPosition();} 157 Vector3 getDirection() 158 { 159 Vector3 dir = mCamera->getDerivedDirection(); 160 dir.normalise(); 161 return dir; 162 } 89 163 // Vector3 getOrienation(){return mPlayerCharacter->getGlobalOrientation();} 164 float getHit() 165 { 166 if(mCurrentAnimState == PLAYERANIMSTATE_ATTACK){ 167 if(mWeapon) return 20; 168 else return 15; 169 }else return 0; 170 } 171 void addHit(float hit) 172 { 173 if(isAlive) 174 { 175 PlayerCharacter::addHit(hit); 176 if(mHealth <= 0)//death 177 { 178 static deaths = 0; 179 deaths++; 180 isAlive = false; 181 OverlayElement* deathsTextBox = OverlayManager::getSingleton().getOverlayElement("Deaths"); 182 deathsTextBox->setCaption("Deaths: "+StringConverter::toString(deaths)); 183 } 184 } 185 } 186 187 void levelUp(){mMaxHealth += 30; mHealth = mMaxHealth;} 90 188 91 189 static FPSPlayer* thePlayer; 92 190 static FPSPlayer* getPlayer(){return thePlayer;} 191 void addCharacterInRange(PlayerCharacter* c){mCharactersInRange.insert(c);} 192 void removeCharacterInRange(PlayerCharacter* c){mCharactersInRange.erase(c);} 93 193 94 194 protected: 95 195 96 196 Camera* mCamera; 97 float mCameraHeight; 197 float mCameraHeight; 198 float mStrength; 199 float mMaxStrength; 200 float mManna; 201 float mMaxManna; 202 float mMaxHealth; 203 FireBall* mFireBall; 204 205 std::set<PlayerCharacter*> mCharactersInRange; 98 206 99 207 String getAnimStateName(PlayerAnimState as, int option = 0); -
GTP/trunk/App/Demos/Illum/Ogre/src/Common/src/FPSPlayer.cpp
r2443 r2459 3 3 FPSPlayer* FPSPlayer::thePlayer = NULL; 4 4 unsigned int PlayerCharacter::frameListenerPriority = 1; 5 float TrollCharacter::MaxHealth = 350; 6 CharacterManager* CharacterManager::mSingleton = 0; 7 8 void CharacterManager::levelUP() 9 { 10 //player level up 11 FPSPlayer::thePlayer->levelUp(); 12 //add 2 new trolls 13 static int trollID = 2; 14 static int kills = 0; 15 kills++; 16 17 OverlayElement* killsTextBox = OverlayManager::getSingleton().getOverlayElement("Level"); 18 killsTextBox->setCaption("Kills: "+StringConverter::toString(kills)); 19 20 for(int i = 0; i < 2; i++) 21 { 22 TrollCharacter* troll = new TrollCharacter("troll" + StringConverter::toString(trollID), 23 mScene, 24 mSceneManager, 25 Vector3(1.5, 3.0, 1.2), 26 Vector3(25, 10, 25 - i * 10), false); 27 28 troll->addPlayerMesh("troll.mesh", 0.05, false); 29 troll->addWeaponModel("trollMace.mesh", "RightHand"); 30 trollID++; 31 } 32 33 34 35 } 5 36 6 37 class MyTrigger : public Trigger … … 14 45 void onEnter(Actor* a) 15 46 { 16 int ize = 0; 47 PlayerCharacter* trigger = CharacterManager::getSingleton().getTrigger(this); 48 PlayerCharacter* target = CharacterManager::getSingleton().getTarget(a); 49 50 if(target != trigger && target == FPSPlayer::thePlayer) 51 target->addHit(trigger->getHit()); 52 17 53 } 18 54 }; 19 55 20 class MyCharMoveController : public CharacterMovementVectorController 56 class FireBall : public Trigger 57 { 58 public: 59 FireBall(String& name, 60 SceneManager* sm, 61 SceneNode* meshNode, 62 Bone* attachBone, 63 const NxString& meshIdentifier, 64 Scene* scene, 65 ShapeDescription* shape, 66 const NxOgre::Pose& pose, 67 ActorParams params = "") 68 : Trigger(meshIdentifier, scene, shape, pose, params) 69 { 70 mFire=false; 71 isActive = false; 72 mFireBall = sm->createParticleSystem("FPS_PLAYER_FIREBALL", "Moria/FireBall"); 73 74 mFireBallLight = sm->createLight(mName+"FireBallLight"); 75 mFireBallLight->setType(Light::LT_POINT); 76 mFireBallLight->setCastShadows(true); 77 mFireBallLight->setDiffuseColour(ColourValue(0.95,0.98,0.8)); 78 mFireBallLight->setPowerScale(200); 79 mFireBallLight->setAttenuation(200.0, 0, 0, 6); 80 81 attachNode = meshNode->createChildSceneNode(name + "_AttachNode"); 82 fireBallNode = attachNode->createChildSceneNode(name + "_FireBallNode"); 83 fireBallNode->attachObject(mFireBall); 84 //fireBallNode->attachObject(mFireBallLight); 85 BillboardSet* bbs = ((BillboardParticleRenderer*)mFireBall->getRenderer())->getBillboardSet(); 86 bbs->setMaterialName(mFireBall->getMaterialName()); 87 OgreIlluminationManager::getSingleton().initTechniques( 88 bbs, 89 mFireBall); 90 fireBallNode->detachObject(mFireBall); 91 sceneManager = sm; 92 this->attachBone = attachBone; 93 94 /* explosionNode = sm->getRootSceneNode()->createChildSceneNode(name + "_EXPLOSION_NODE"); 95 mExplosion = sm->createParticleSystem("FPS_PLAYER_EXPLOSION", "Moria/Explosion"); 96 explosionNode->attachObject(mExplosion); 97 bbs = ((BillboardParticleRenderer*)mExplosion->getRenderer())->getBillboardSet(); 98 bbs->setMaterialName(mExplosion->getMaterialName()); 99 OgreIlluminationManager::getSingleton().initTechniques( 100 bbs, 101 mExplosion);*/ 102 103 } 104 void update(float dt) 105 { 106 if(isActive) 107 { 108 /*if(explodeTimer.getMilliseconds() > 1000) 109 mExplosion->getEmitter(0)->setEmissionRate(0);*/ 110 111 Vector3 pos = attachBone->getWorldPosition(); 112 Quaternion orientation = attachBone->getWorldOrientation(); 113 114 attachNode->setPosition(pos); 115 attachNode->setOrientation(orientation); 116 117 if(mFire) 118 { 119 Vector3 testCenter = position - direction; 120 bool collidedWithStatic = getScene()->getNxScene()->checkOverlapSphere( 121 NxSphere(NxVec3(testCenter.x,testCenter.y,testCenter.z), 0.4), 122 NX_STATIC_SHAPES); 123 position += direction * dt * 10.0; 124 fireBallNode->setPosition(position); 125 126 if(collidedWithStatic) 127 explode(); 128 } 129 130 this->setGlobalPosition(fireBallNode->getWorldPosition()); 131 this->setGlobalOrientation(fireBallNode->getWorldOrientation()); 132 } 133 } 134 void fire() 135 { 136 mFire = true; 137 position = fireBallNode->getWorldPosition(); 138 direction = FPSPlayer::getPlayer()->getDirection(); 139 //position += direction * 2.0; 140 141 attachNode->removeChild(fireBallNode); 142 sceneManager->getRootSceneNode()->addChild(fireBallNode); 143 } 144 void activate() 145 { 146 isActive = true; 147 fireBallNode->attachObject(mFireBall); 148 fireBallNode->attachObject(mFireBallLight); 149 //mFireBallLight->setPowerScale(200); 150 CompositorManager::getSingleton().setCompositorEnabled( 151 OgreIlluminationManager::getSingleton().getMainViewport(), 152 "FireHeatCompositor", true); 153 154 } 155 void deactivate() 156 { 157 isActive = false; 158 fireBallNode->detachObject(mFireBall); 159 fireBallNode->detachObject(mFireBallLight); 160 //mFireBallLight->setPowerScale(0); 161 CompositorManager::getSingleton().setCompositorEnabled( 162 OgreIlluminationManager::getSingleton().getMainViewport(), 163 "FireHeatCompositor", false); 164 } 165 166 void onEnter(Actor* a) 167 { 168 PlayerCharacter* target = CharacterManager::getSingleton().getTarget(a); 169 if(target != FPSPlayer::thePlayer) 170 { 171 if(mFire) 172 { 173 if(target) 174 target->addHit(30); 175 explode(); 176 } 177 } 178 } 179 180 protected: 181 Vector3 position; 182 Vector3 direction; 183 bool mFire; 184 bool isActive; 185 SceneNode* fireBallNode; 186 SceneNode* explosionNode; 187 SceneNode* attachNode; 188 ParticleSystem* mFireBall; 189 ParticleSystem* mExplosion; 190 Light* mFireBallLight; 191 Bone* attachBone; 192 SceneManager* sceneManager; 193 Timer explodeTimer; 194 195 void explode() 196 { 197 /*mExplosion->getEmitter(0)->setEmissionRate(100); 198 explodeTimer.reset(); 199 mExplosion->getEmitter(0)->setPosition(position);*/ 200 sceneManager->getRootSceneNode()->removeChild(fireBallNode); 201 attachNode->addChild(fireBallNode); 202 fireBallNode->setPosition(2.8, -2.28, 0.47); 203 mFire = false; 204 } 205 }; 206 207 class MyCharMoveController : public CharacterController 21 208 { 22 209 public: … … 28 215 out = ((dir * movespeed) + g) * t; 29 216 } 217 NxControllerAction onShapeHit(const NxControllerShapeHit & hit) 218 { 219 return CharacterController::onShapeHit(hit); 220 } 221 NxControllerAction onControllerHit(const NxControllersHit & hit) 222 { 223 return CharacterController::onControllerHit(hit); 224 } 30 225 }; 31 226 32 227 PlayerCharacter::PlayerCharacter(String name, Scene* scene, SceneManager* sceneManager, Vector3 dimensions, Vector3 startPosition, bool debug) 33 228 { 229 mCurrentAnimState = PLAYERANIMSTATE_STAND; 230 isAlive = true; 34 231 mName = name; 35 232 mPlayerDimensions = dimensions; … … 42 239 cp.mType = CharacterParams::CT_Box; 43 240 mPlayerCharacter = mScene->createCharacter(mName, startPosition, cp); 241 NxActor* a = mPlayerCharacter->getNxController()->getActor(); 242 CharacterManager::getSingleton().addTarget((Actor*) a->userData, this); 44 243 mPlayerCharacter->createNode(); 45 244 mPlayerNode = mPlayerCharacter->getNode(); … … 51 250 if(mDebug) 52 251 { 252 53 253 mPlayerBoundDebugNode = mPlayerNode->createChildSceneNode(mName + "_BoundDebugNode"); 54 mPlayerBoundDebugNode->setScale(dimensions); 55 mPlayerBoundDebugNode->attachObject(mSceneManager->createEntity(mName + "_BoundDebug", "cube.mesh")); 254 mPlayerBoundDebugNode->setScale(Vector3(dimensions.x, dimensions.y, dimensions.z)); 255 // mPlayerBoundDebugNode->attachObject(mSceneManager->createEntity(mName + "_BoundDebug", "cube.mesh")); 256 257 //mPlayerNode->setScale(Vector3(dimensions.x, dimensions.y, dimensions.z)); 258 //mPlayerNode->attachObject(mSceneManager->createEntity(mName + "_BoundDebug", "cube.mesh")); 56 259 } 57 260 … … 78 281 } 79 282 283 TrollCharacter::TrollCharacter(String name, Scene* scene, SceneManager* sceneManager, Vector3 dimensions, Vector3 startPosition, bool debug) 284 : PlayerCharacter(name, scene, sceneManager, dimensions, startPosition, debug) 285 { 286 mHealth = MaxHealth; 287 } 288 80 289 FPSPlayer::FPSPlayer(Scene* scene, SceneManager* sceneManager, Vector3 dimensions, Vector3 startPosition, float cameraHeight, Camera* cam, bool debug) 81 290 : PlayerCharacter("FPSPlayerCharacter", scene, sceneManager, dimensions, startPosition, debug) 82 291 { 292 mMaxHealth = 50; 293 mMaxStrength = 100; 294 mMaxManna = 100; 295 mStrength = mMaxStrength; 296 mHealth = mMaxHealth; 297 mManna = mMaxManna; 298 83 299 mCameraHeight = cameraHeight - dimensions.y / 2.0; 84 300 mCamera = cam; 85 301 mPlayerNode->attachObject(cam); 302 mCamera->rotate(Vector3(0,1,0), Radian(Degree(180))); 86 303 87 304 thePlayer = this; 305 mFireBall = 0; 306 88 307 } 89 308 … … 95 314 { 96 315 mCharacterMeshEntity = mSceneManager->createEntity(mName, meshname); 97 mCharacterMeshEntity->setCastShadows( false);316 mCharacterMeshEntity->setCastShadows(true); 98 317 mMeshScale = meshscale; 99 318 mCurrentAnimState = PLAYERANIMSTATE_STAND; … … 123 342 FPSArmNode->setScale(meshscale, meshscale, meshscale); 124 343 if(rotateModel) 125 FPSArmNode->rotate(Vector3::UNIT_Y, Degree(180.0)); 344 FPSArmNode->rotate(Vector3::UNIT_Y, Degree(180.0)); 345 346 mFireBall = new FireBall(mName+"_FIREBALL", 347 mSceneManager, 348 FPSArmNode, 349 mCharacterMeshEntity->getSkeleton()->getBone("joint4"), 350 mName+"FireBallTrigger", 351 mScene, 352 new SphereShape(0.5, "trigger: yes"), 353 Vector3(0,0,0), 354 "mass: 0, density: 0"); 355 mScene->addTrigger(mFireBall); 126 356 } 127 357 … … 133 363 mWeaponNode = mCharacterMeshEntity->getParentSceneNode()->createChildSceneNode(mName + "_WeaponNode"); 134 364 mWeaponNode->attachObject(mWeaponEntity); 365 mWeaponEntity->setCastShadows(true); 135 366 136 367 AxisAlignedBox bb = mWeaponEntity->getBoundingBox(); 137 368 138 369 Vector3 max = bb.getMaximum(); 139 //max.z *= 2.0;140 370 Vector3 min = bb.getMinimum(); 141 371 Vector3 center = (min + max) / 2.0; 142 //center.z = max.z; 143 372 144 373 mWeaponBoundNode = mWeaponNode->createChildSceneNode(mName + "_WeaponBoundNode"); 145 374 mWeaponBoundNode->setPosition(center); … … 162 391 mWeaponBound = new MyTrigger(mName + "_WeaponTrigger", mScene, new CubeShape(dimX, dimY, dimZ, "trigger: yes"), Vector3(0,0,0), "mass: 0, density: 0"); 163 392 mScene->addTrigger((Trigger*)mWeaponBound); 164 393 394 CharacterManager::getSingleton().addTrigger(mWeaponBound, this); 165 395 if(mDebug) 166 396 { … … 174 404 175 405 void FPSPlayer::addWeaponModel(String meshname, String attachBoneName) 176 { 406 { 407 mWeaponEntity = mSceneManager->createEntity(mName + "_Weapon", meshname); 408 mWeaponAttachBone = mCharacterMeshEntity->getSkeleton()->getBone(attachBoneName); 409 mWeaponNode = mCharacterMeshEntity->getParentSceneNode()->createChildSceneNode(mName + "_WeaponNode"); 410 mWeaponNode->attachObject(mWeaponEntity); 411 mWeaponEntity->setCastShadows(false); 412 413 AxisAlignedBox bb = mWeaponEntity->getBoundingBox(); 414 415 mWeaponBoundNode = mPlayerNode->createChildSceneNode(mName + "_WeaponBoundNode"); 416 mWeaponBoundNode->setPosition(0,1.5,0.5); 177 417 178 mWeaponEntity = mSceneManager->createEntity(mName + "_Weapon", meshname); 179 mWeaponEntity->setCastShadows(false); 180 mWeaponAttachBone = mCharacterMeshEntity->getSkeleton()->getBone(attachBoneName); 181 mWeaponNode = mCharacterMeshEntity->getParentSceneNode()->createChildSceneNode(mName+"_WeaponNode"); 182 mWeaponNode->attachObject(mWeaponEntity); 183 184 AxisAlignedBox bb = mWeaponEntity->getBoundingBox(); 185 186 Vector3 max = bb.getMaximum(); 187 //max.z *= 2.0; 188 Vector3 min = bb.getMinimum(); 189 Vector3 center = (min + max) / 2.0; 190 //center.z = max.z; 191 192 //mWeaponBoundNode = mWeaponNode->createChildSceneNode(); 193 //mWeaponBoundNode->setPosition(center); 194 195 SceneNode* ArmNode2 = mPlayerNode->createChildSceneNode(mName+"_ArmNode2"); 196 ArmNode2->setPosition(0,mCameraHeight , -mPlayerDimensions.z); 197 ArmNode2->rotate(Vector3::UNIT_Y, Degree(180.0)); 198 mWeaponNode2 = ArmNode2->createChildSceneNode(); 199 mWeaponBoundNode = mWeaponNode2->createChildSceneNode(mName+"_WeaponBoundNode"); 200 mWeaponBoundNode->setPosition(center * mMeshScale ); 201 202 203 max *= mMeshScale; 204 min *= mMeshScale; 205 float dimX = max.x-min.x; 206 float dimY = max.y-min.y; 207 dimY *=3; 208 float dimZ = max.z-min.z; 209 Vector3 dim(dimX, dimY, dimZ); 210 211 // mWeaponBound = mScene->createActor("FPSPlayerWeapon", new CubeShape(dimX, dimY, dimZ), Vector3(0,0,0), "kinematic: yes, mass: 10"); 212 mWeaponBound = new MyTrigger(mName + "_WeaponTrigger", mScene, new CubeShape(dimX, dimY, dimZ, "trigger: yes"), Vector3(0,0,0), "mass: 0, density: 0"); 418 mWeaponBound = new MyTrigger(mName + "_WeaponTrigger", mScene, new CubeShape(0.5, 0.5, 0.5, "trigger: yes"), Vector3(0,0,0), "mass: 0, density: 0"); 213 419 mScene->addTrigger((Trigger*)mWeaponBound); 214 420 421 CharacterManager::getSingleton().addTrigger(mWeaponBound, this); 215 422 if(mDebug) 216 423 { 217 424 mWeaponBoundDebugNode = mSceneManager->getRootSceneNode()->createChildSceneNode(mName+"_WeaponBoundDebugNode"); 218 mWeaponBoundDebugNode->setScale(dim); 219 mWeaponBoundDebugNode->attachObject(mSceneManager->createEntity(mName+"_WeaponBoundDebug", "cube.mesh")); 220 } 221 222 mWeaponBound->setCharacterCollisionGroup(NX_CHARACTER_COL_GROUP_NON_COLLIDABLE); 223 } 224 225 void PlayerCharacter::doAction(float dt) 226 { 425 mWeaponBoundDebugNode->setScale(0.5,0.5,0.5); 426 // mWeaponBoundDebugNode->attachObject(mSceneManager->createEntity(mName+"_WeaponBoundDebug", "cube.mesh")); 427 } 428 429 //mWeaponBound->setCharacterCollisionGroup(NX_CHARACTER_COL_GROUP_NON_COLLIDABLE); 430 } 431 432 void TrollCharacter::doAction(float dt) 433 { 434 if(mCurrentAnimState == PLAYERANIMSTATE_DEATH) 435 return; 436 227 437 FPSPlayer* thePlayer = FPSPlayer::getPlayer(); 228 438 … … 231 441 Vector3 playerPos = thePlayer->getPosition(); 232 442 Vector3 myPos = mPlayerNode->getWorldPosition(); 233 Vector3 dir = playerPos - myPos; 443 static Vector3 dir = Vector3(0,0,1); 444 Vector3 lastDir = dir; 445 dir = playerPos - myPos; 234 446 dir.y = 0; 235 //if( dir.length() > 1.0) 236 //{ 237 dir.normalise(); 238 Vector3 right = -dir.crossProduct(Vector3::UNIT_Y); 239 Quaternion q; 240 q.FromAxes(right,Vector3::UNIT_Y,dir); 241 //mPlayerCharacter->setDirection(q); 242 if(mCharacterController ) 243 ((MyCharMoveController*)mCharacterController)->movespeed = 1.5; 244 //mPlayerCharacter->addMovement(Character::DR_StepRight); 245 //} 246 247 } 248 //if(mCharacterMeshEntity) 249 //setAnimState(PLAYERANIMSTATE_WALK); 250 } 251 252 bool PlayerCharacter::frameStarted(const FrameEvent& evt) 253 { 254 // LogManager::getSingleton().logMessage("CHARACTERPLAYER_FRAMESTARTED"); 255 doAction(evt.timeSinceLastFrame); 256 257 float dt = evt.timeSinceLastFrame; 258 259 if(mCharacterMesh_AnimState) 260 { 261 float animspeed = 1.2; 262 if(mCurrentAnimState == PLAYERANIMSTATE_WALK && !mRunning) 263 animspeed /= 2; 264 265 mCharacterMesh_AnimState->addTime(dt*animspeed); 266 } 267 268 return true; 269 } 270 271 void FPSPlayer::processKeyInputs(InputReader* inputDevice) 272 { 273 mMoving = false; 274 if (inputDevice->isKeyDown(KC_W)) 275 { 276 mPlayerCharacter->addMovement(Character::DR_StepLeft); 277 mMoving = true; 278 } 279 if (inputDevice->isKeyDown(KC_S)) 280 { 281 mPlayerCharacter->addMovement(Character::DR_StepRight); 282 mMoving = true; 283 } 284 if (inputDevice->isKeyDown(KC_A)) 285 { 286 mPlayerCharacter->addMovement(Character::DR_Forward); 287 mMoving = true; 288 } 289 if (inputDevice->isKeyDown(KC_D)) 290 { 291 mPlayerCharacter->addMovement(Character::DR_Backward); 292 mMoving = true; 293 } 294 295 if (inputDevice->isKeyDown(KC_1)) 296 { 297 mWeapon = 0; 298 mForceAnimChange = true; 299 } 300 if (inputDevice->isKeyDown(KC_2)) 301 { 302 mWeapon = 1; 303 mForceAnimChange = true; 304 } 305 306 if (inputDevice->isKeyDown(KC_LSHIFT)) 307 { 308 if(mCharacterController) 309 ((MyCharMoveController*)mCharacterController)->movespeed = 4.0; 310 mRunning = true; 447 448 float dist = dir.length(); 449 450 dir.normalise(); 451 Vector3 right = -dir.crossProduct(Vector3::UNIT_Y); 452 Quaternion q; 453 q.FromAxes(right,Vector3::UNIT_Y, dir); 454 mPlayerCharacter->setDirection(q); 455 456 if(dist < 1.8) 457 { 458 if(dist < 1.2) 459 { 460 setAnimState(PLAYERANIMSTATE_WALK); 461 if(mCurrentAnimState != PLAYERANIMSTATE_DEATH && 462 mCurrentAnimState != PLAYERANIMSTATE_ATTACK && 463 mCurrentAnimState != PLAYERANIMSTATE_PAIN) 464 { 465 if(mCharacterController ) 466 ((MyCharMoveController*)mCharacterController)->movespeed = 1.5; 467 mPlayerCharacter->addMovement(Character::DR_Backward); 468 469 } 470 FPSPlayer::thePlayer->addCharacterInRange(this); 471 } 472 else 473 { 474 if(Math::UnitRandom()>0.6) 475 { 476 if(Math::ACos(dir.dotProduct(lastDir)).valueDegrees() > 2.0) 477 setAnimState(PLAYERANIMSTATE_TURN); 478 else 479 setAnimState(PLAYERANIMSTATE_STAND); 480 } 481 else 482 { 483 setAnimState(PLAYERANIMSTATE_ATTACK); 484 } 485 } 311 486 } 312 487 else 313 488 { 314 if(mCharacterController) 315 ((MyCharMoveController*)mCharacterController)->movespeed = 2.0; 316 mRunning = false; 317 } 318 } 319 320 void FPSPlayer::processMouseInputs(InputReader* inputDevice) 321 { 322 if( inputDevice->getMouseButton( 0 ) )//attack 323 setAnimState(PLAYERANIMSTATE_ATTACK); 324 325 else if( inputDevice->getMouseButton( 1 ) )//block 326 setAnimState(PLAYERANIMSTATE_BLOCK); 327 328 Quaternion q; 329 q.FromAngleAxis( Radian(Degree(-inputDevice->getMouseRelX() * 0.13)), Vector3::UNIT_Y ); 330 q = mPlayerCharacter->getGlobalOrientation() * q; 331 mPlayerCharacter->setDirection(q); 332 333 mCamera->pitch(Radian(Degree(-inputDevice->getMouseRelY() * 0.13))); 334 } 335 336 bool FPSPlayer::frameStarted(const FrameEvent& evt) 337 { 338 // LogManager::getSingleton().logMessage("FPSPLAYER_FRAMESTARTED"); 339 340 float dt = evt.timeSinceLastFrame; 341 342 if(mCharacterMesh_AnimState) 343 { 344 float animspeed = 1.2; 345 if(mCurrentAnimState == PLAYERANIMSTATE_WALK && mRunning) 346 animspeed *= 1.5; 347 if(mCurrentAnimState == PLAYERANIMSTATE_ATTACK) 348 animspeed *= 2.0; 349 350 mCharacterMesh_AnimState->addTime(dt*animspeed); 351 } 352 353 static float moveTime=0; 354 355 float movecameraup = 0; 356 if(mDebug)movecameraup = 20.0; 357 358 if(mMoving) 359 { 360 setAnimState(PLAYERANIMSTATE_WALK); 361 362 moveTime += dt; 363 mCamera->setPosition(Vector3(0,mCameraHeight + movecameraup,0) + Vector3(0,0.009 * pow(sin(moveTime*5.0), 2),0)); 364 } 365 else 366 { 367 if(Math::UnitRandom() > 0.98) 368 setAnimState(PLAYERANIMSTATE_IDLE); 369 else 370 setAnimState(PLAYERANIMSTATE_STAND); 371 372 moveTime = 0; 373 mCamera->setPosition(Vector3(0,mCameraHeight + movecameraup,0)); 374 } 375 376 if(mCharacterMeshEntity) 377 this->mCharacterMeshEntity->_updateAnimation(); 378 379 if(mWeaponEntity) 380 { 381 mWeaponNode->setPosition(mWeaponAttachBone->getWorldPosition()); 382 mWeaponNode->setOrientation(mWeaponAttachBone->getWorldOrientation()); 383 384 mWeaponNode2->setPosition(mWeaponAttachBone->getWorldPosition() * mMeshScale); 385 mWeaponNode2->setOrientation(mWeaponAttachBone->getWorldOrientation()); 386 387 Vector3 translation = mWeaponBoundNode->getWorldPosition(); 388 Quaternion orientation = mWeaponBoundNode->getWorldOrientation(); 389 390 mWeaponBound->setGlobalOrientation(orientation); 391 mWeaponBound->setGlobalPosition(translation); 392 393 //mWeaponBound->setGlobalPosition(translation); 394 //mWeaponBound->setGlobalOrientation(orientation); 395 396 if(mDebug) 397 { 398 mWeaponBoundDebugNode->setPosition(translation); 399 mWeaponBoundDebugNode->setOrientation(orientation); 400 } 401 } 402 403 return true; 404 } 405 406 String FPSPlayer::getAnimStateName(PlayerAnimState as, int option) 407 { 408 switch (as) 409 { 410 case PLAYERANIMSTATE_IDLE: 411 { 412 if(mWeapon < 1) 413 return "sword_idle"; 414 else 415 return "magic_idle"; 416 } 417 case PLAYERANIMSTATE_STAND: 418 { 419 if(mWeapon < 1) 420 return "sword_stand"; 421 else 422 return "magic_stand"; 423 } 424 case PLAYERANIMSTATE_BLOCK: 425 { 426 return "block"; 427 } 428 case PLAYERANIMSTATE_WALK: 429 { 430 return "walk"; 431 } 432 case PLAYERANIMSTATE_ATTACK: 433 { 434 if(option) 435 { 436 if(mWeapon < 1) 437 return "attack1"; 438 else 439 return "magic_attack"; 440 } 441 else 442 { 443 if(mWeapon < 1) 444 return "attack2"; 445 else 446 return "magic_attack"; 447 } 448 } 449 } 450 return ""; 451 } 452 453 void FPSPlayer::setAnimState(PlayerAnimState as) 489 FPSPlayer::thePlayer->removeCharacterInRange(this); 490 491 setAnimState(PLAYERANIMSTATE_WALK); 492 if(mCurrentAnimState != PLAYERANIMSTATE_DEATH && 493 mCurrentAnimState != PLAYERANIMSTATE_ATTACK && 494 mCurrentAnimState != PLAYERANIMSTATE_PAIN) 495 { 496 if(mCharacterController ) 497 ((MyCharMoveController*)mCharacterController)->movespeed = 1.5; 498 mPlayerCharacter->addMovement(Character::DR_Forward); 499 500 } 501 } 502 } 503 } 504 505 void TrollCharacter::addHit(float hit) 506 { 507 if(hit == 0 || !isAlive) 508 return; 509 510 PlayerCharacter::addHit(hit); 511 512 if(mHealth <= 0)//death 513 { 514 isAlive = false; 515 setAnimState(PLAYERANIMSTATE_DEATH); 516 517 //TODO: free character controller 518 mScene->destroyCharacter(mName); 519 CharacterManager::getSingleton().levelUP(); 520 } 521 else//pain 522 { 523 setAnimState(PLAYERANIMSTATE_PAIN); 524 } 525 } 526 527 void TrollCharacter::setAnimState(PlayerAnimState as) 454 528 { 455 529 if(!mCharacterMeshEntity) 530 return; 531 532 if(mCurrentAnimState == PLAYERANIMSTATE_DEATH) 456 533 return; 457 534 … … 497 574 if(mCurrentAnimState != PLAYERANIMSTATE_WALK) 498 575 { 576 if(mCurrentAnimState == PLAYERANIMSTATE_IDLE || mCurrentAnimState == PLAYERANIMSTATE_STAND || mCurrentAnimState == PLAYERANIMSTATE_TURN 577 || mCharacterMesh_AnimState->getTimePosition() >= mCharacterMesh_AnimState->getLength()) 578 { 579 mCurrentAnimState = PLAYERANIMSTATE_WALK; 580 mCharacterMesh_AnimState->setEnabled(false); 581 mCharacterMesh_AnimState = mCharacterMeshEntity->getAnimationState(getAnimStateName(PLAYERANIMSTATE_WALK)); 582 mCharacterMesh_AnimState->setLoop(true); 583 mCharacterMesh_AnimState->setEnabled(true); 584 } 585 } 586 break; 587 } 588 case PLAYERANIMSTATE_TURN: 589 { 590 if(mCurrentAnimState != PLAYERANIMSTATE_TURN) 591 { 592 if(mCurrentAnimState == PLAYERANIMSTATE_IDLE || mCurrentAnimState == PLAYERANIMSTATE_STAND) 593 { 594 int turnType = 0; 595 if(Math::UnitRandom() > 0.5) 596 turnType = 1; 597 598 mCurrentAnimState = PLAYERANIMSTATE_TURN; 599 mCharacterMesh_AnimState->setEnabled(false); 600 mCharacterMesh_AnimState = mCharacterMeshEntity->getAnimationState(getAnimStateName(PLAYERANIMSTATE_TURN, turnType)); 601 mCharacterMesh_AnimState->setLoop(true); 602 mCharacterMesh_AnimState->setEnabled(true); 603 } 604 } 605 break; 606 } 607 case PLAYERANIMSTATE_ATTACK: 608 { 609 if(mCharacterMesh_AnimState->getTimePosition() >= 610 mCharacterMesh_AnimState->getLength() || mCharacterMesh_AnimState->getLoop() || mCurrentAnimState == PLAYERANIMSTATE_IDLE) 611 { 612 int attackType = 0; 613 if(Math::UnitRandom() > 0.5) 614 attackType = 1; 615 616 mCurrentAnimState = PLAYERANIMSTATE_ATTACK; 617 mCharacterMesh_AnimState->setEnabled(false); 618 mCharacterMesh_AnimState = mCharacterMeshEntity->getAnimationState(getAnimStateName(PLAYERANIMSTATE_ATTACK, attackType)); 619 mCharacterMesh_AnimState->setTimePosition(0); 620 mCharacterMesh_AnimState->setLoop(false); 621 mCharacterMesh_AnimState->setEnabled(true); 622 } 623 break; 624 } 625 case PLAYERANIMSTATE_PAIN: 626 { 627 if(mCharacterMesh_AnimState->getTimePosition() >= 628 mCharacterMesh_AnimState->getLength() || mCharacterMesh_AnimState->getLoop() 629 //mCurrentAnimState != PLAYERANIMSTATE_PAIN 630 ) 631 { 632 int painType = 0; 633 if(Math::UnitRandom() > 0.5) 634 painType = 1; 635 636 mCurrentAnimState = PLAYERANIMSTATE_PAIN; 637 mCharacterMesh_AnimState->setEnabled(false); 638 mCharacterMesh_AnimState = mCharacterMeshEntity->getAnimationState(getAnimStateName(PLAYERANIMSTATE_PAIN, painType)); 639 mCharacterMesh_AnimState->setTimePosition(0); 640 mCharacterMesh_AnimState->setLoop(false); 641 mCharacterMesh_AnimState->setEnabled(true); 642 } 643 break; 644 } 645 case PLAYERANIMSTATE_DEATH: 646 { 647 if(mCurrentAnimState != PLAYERANIMSTATE_DEATH) 648 { 649 int deathType = 0; 650 if(Math::UnitRandom() > 0.5) 651 deathType = 1; 652 653 mCurrentAnimState = PLAYERANIMSTATE_DEATH; 654 mCharacterMesh_AnimState->setEnabled(false); 655 mCharacterMesh_AnimState = mCharacterMeshEntity->getAnimationState(getAnimStateName(PLAYERANIMSTATE_DEATH, deathType)); 656 mCharacterMesh_AnimState->setTimePosition(0); 657 mCharacterMesh_AnimState->setLoop(false); 658 mCharacterMesh_AnimState->setEnabled(true); 659 } 660 break; 661 } 662 } 663 664 if(mForceAnimChange) 665 mForceAnimChange = false; 666 } 667 668 String TrollCharacter::getAnimStateName(PlayerAnimState as, int option) 669 { 670 switch (as) 671 { 672 case PLAYERANIMSTATE_IDLE: 673 { 674 if(option) 675 return "turn_idle1"; 676 else 677 return "turn_idle2"; 678 } 679 case PLAYERANIMSTATE_TURN: 680 { 681 if(option) 682 return "turn_idle1"; 683 else 684 return "turn_idle2"; 685 } 686 case PLAYERANIMSTATE_STAND: 687 { 688 return "stand"; 689 } 690 case PLAYERANIMSTATE_WALK: 691 { 692 return "walk"; 693 } 694 case PLAYERANIMSTATE_ATTACK: 695 { 696 if(option) 697 return "attack1"; 698 else 699 return "attack2"; 700 } 701 case PLAYERANIMSTATE_PAIN: 702 { 703 if(option) 704 return "pain1"; 705 else 706 return "pain2"; 707 } 708 case PLAYERANIMSTATE_DEATH: 709 { 710 if(option) 711 return "death1"; 712 else 713 return "death2"; 714 } 715 } 716 return ""; 717 } 718 719 bool PlayerCharacter::frameStarted(const FrameEvent& evt) 720 { 721 // LogManager::getSingleton().logMessage("CHARACTERPLAYER_FRAMESTARTED"); 722 doAction(evt.timeSinceLastFrame); 723 724 float dt = evt.timeSinceLastFrame; 725 726 if(mCharacterMesh_AnimState) 727 mCharacterMesh_AnimState->addTime(dt * getAnimSpeed()); 728 729 if(mCharacterMeshEntity) 730 this->mCharacterMeshEntity->_updateAnimation(); 731 732 if(mWeaponEntity) 733 { 734 mWeaponNode->setPosition(mWeaponAttachBone->getWorldPosition()); 735 mWeaponNode->setOrientation(mWeaponAttachBone->getWorldOrientation()); 736 737 Vector3 translation = mWeaponBoundNode->getWorldPosition(); 738 Quaternion orientation = mWeaponBoundNode->getWorldOrientation(); 739 740 mWeaponBound->setGlobalOrientation(orientation); 741 mWeaponBound->setGlobalPosition(translation); 742 743 if(mDebug) 744 { 745 mWeaponBoundDebugNode->setPosition(translation); 746 mWeaponBoundDebugNode->setOrientation(orientation); 747 } 748 } 749 750 return true; 751 } 752 753 void FPSPlayer::processKeyInputs(InputReader* inputDevice) 754 { 755 if(mHealth > 0) 756 { 757 mMoving = false; 758 if (inputDevice->isKeyDown(KC_W)) 759 { 760 mPlayerCharacter->addMovement(Character::DR_Forward); 761 mMoving = true; 762 } 763 if (inputDevice->isKeyDown(KC_S)) 764 { 765 mPlayerCharacter->addMovement(Character::DR_Backward); 766 mMoving = true; 767 } 768 if (inputDevice->isKeyDown(KC_A)) 769 { 770 mPlayerCharacter->addMovement(Character::DR_StepRight); 771 mMoving = true; 772 } 773 if (inputDevice->isKeyDown(KC_D)) 774 { 775 mPlayerCharacter->addMovement(Character::DR_StepLeft); 776 mMoving = true; 777 } 778 779 if (inputDevice->isKeyDown(KC_1)) 780 { 781 if(mWeapon != 0) 782 { 783 mWeapon = 0; 784 mForceAnimChange = true; 785 if(mFireBall) 786 mFireBall->deactivate(); 787 788 OverlayElement* SwordIcon = OverlayManager::getSingleton().getOverlayElement("Sword"); 789 SwordIcon->setHeight(0.1); 790 SwordIcon->setWidth(0.1); 791 SwordIcon->setTop(0.89); 792 SwordIcon->setLeft(0.1); 793 794 OverlayElement* FBIcon = OverlayManager::getSingleton().getOverlayElement("FireBall"); 795 FBIcon->setHeight(0.04); 796 FBIcon->setWidth(0.04); 797 FBIcon->setTop(0.92); 798 FBIcon->setLeft(0.22); 799 } 800 } 801 if (inputDevice->isKeyDown(KC_2)) 802 { 803 if(mWeapon!= 1) 804 { 805 mWeapon = 1; 806 mForceAnimChange = true; 807 if(mFireBall) 808 mFireBall->activate(); 809 810 OverlayElement* SwordIcon = OverlayManager::getSingleton().getOverlayElement("Sword"); 811 SwordIcon->setHeight(0.04); 812 SwordIcon->setWidth(0.04); 813 SwordIcon->setTop(0.92); 814 SwordIcon->setLeft(0.13); 815 816 OverlayElement* FBIcon = OverlayManager::getSingleton().getOverlayElement("FireBall"); 817 FBIcon->setHeight(0.1); 818 FBIcon->setWidth(0.1); 819 FBIcon->setTop(0.89); 820 FBIcon->setLeft(0.18); 821 } 822 } 823 824 if (inputDevice->isKeyDown(KC_LSHIFT)) 825 { 826 mStrength -= 1.5 * mMaxStrength * 0.018; 827 if(mStrength < 0.0) mStrength = 0.0; 828 829 if(mStrength > 0.1 * mMaxStrength) 830 { 831 if(mCharacterController) 832 ((MyCharMoveController*)mCharacterController)->movespeed = 2.0; 833 mRunning = true; 834 } 835 else 836 { 837 if(mCharacterController) 838 ((MyCharMoveController*)mCharacterController)->movespeed = 1.0; 839 mRunning = false; 840 } 841 } 842 else 843 { 844 if(mCharacterController) 845 ((MyCharMoveController*)mCharacterController)->movespeed = 1.0; 846 mRunning = false; 847 } 848 } 849 } 850 851 void FPSPlayer::processMouseInputs(InputReader* inputDevice) 852 { 853 if(mHealth > 0) 854 { 855 if( inputDevice->getMouseButton( 0 ) )//attack 856 setAnimState(PLAYERANIMSTATE_ATTACK); 857 858 //else if( inputDevice->getMouseButton( 1 ) )//block 859 // setAnimState(PLAYERANIMSTATE_BLOCK); 860 } 861 else if( inputDevice->getMouseButton( 1 ))//respawn 862 { 863 mHealth = mMaxHealth; 864 CompositorManager::getSingleton().setCompositorEnabled(OgreIlluminationManager::getSingleton().getMainViewport(), 865 "GTP/PostProc/MotionBlur", false); 866 this->mWeaponEntity->setVisible(true); 867 this->mCharacterMeshEntity->setVisible(true); 868 mWeapon = 0; 869 isAlive = true; 870 } 871 872 Quaternion q; 873 q.FromAngleAxis( Radian(Degree(-inputDevice->getMouseRelX() * 0.13)), Vector3::UNIT_Y ); 874 q = mPlayerCharacter->getGlobalOrientation() * q; 875 mPlayerCharacter->setDirection(q); 876 877 mCamera->pitch(Radian(Degree(-inputDevice->getMouseRelY() * 0.13))); 878 } 879 880 bool FPSPlayer::frameStarted(const FrameEvent& evt) 881 { 882 // LogManager::getSingleton().logMessage("FPSPLAYER_FRAMESTARTED"); 883 884 float dt = evt.timeSinceLastFrame; 885 886 if(mHealth == 0)//we are dead 887 { 888 CompositorManager::getSingleton().setCompositorEnabled(OgreIlluminationManager::getSingleton().getMainViewport(), 889 "GTP/PostProc/MotionBlur", true); 890 if(mFireBall) 891 mFireBall->deactivate(); 892 static float dedanimT = 0; 893 894 this->mWeaponEntity->setVisible(false); 895 this->mCharacterMeshEntity->setVisible(false); 896 897 float cameraPos = - dedanimT; 898 if(cameraPos < -mCameraHeight) cameraPos = -mCameraHeight; 899 900 mCamera->setPosition(Vector3(0,cameraPos,0)); 901 902 dedanimT += dt * 0.7; 903 904 OverlayElement* healthUI = OverlayManager::getSingleton().getOverlayElement("HealthColumn"); 905 healthUI->setHeight(0); 906 } 907 else 908 { 909 mStrength += mMaxStrength * 0.018; 910 if(mStrength > mMaxStrength) mStrength = mMaxStrength; 911 912 OverlayElement* strengthUI = OverlayManager::getSingleton().getOverlayElement("StrengthColumn"); 913 float relStrength = mStrength / mMaxStrength; 914 strengthUI->setHeight(0.29 * relStrength); 915 strengthUI->setTop(0.005 + (1.0 - relStrength) * 0.29); 916 917 mHealth += mMaxHealth * 0.005; 918 if(mHealth > mMaxHealth) mHealth = mMaxHealth; 919 920 OverlayElement* healthUI = OverlayManager::getSingleton().getOverlayElement("HealthColumn"); 921 float relHealth = mHealth / mMaxHealth; 922 healthUI->setHeight(0.29 * relHealth); 923 healthUI->setTop(0.005 + (1.0 - relHealth) * 0.29); 924 925 mManna += mMaxManna * 0.005; 926 if(mManna > mMaxManna) mManna = mMaxManna; 927 928 OverlayElement* mannaUI = OverlayManager::getSingleton().getOverlayElement("MannaColumn"); 929 float relManna = mManna / mMaxManna; 930 mannaUI->setHeight(0.29 * relManna); 931 mannaUI->setTop(0.005 + (1.0 - relManna) * 0.29); 932 933 934 if(mCharacterMesh_AnimState) 935 { 936 float animspeed = 1.2; 937 if(mCurrentAnimState == PLAYERANIMSTATE_WALK && mRunning) 938 animspeed *= 1.5; 939 if(mCurrentAnimState == PLAYERANIMSTATE_ATTACK) 940 animspeed *= 2.0; 941 942 mCharacterMesh_AnimState->addTime(dt*animspeed); 943 } 944 945 static float moveTime=0; 946 947 float movecameraup = 0; 948 if(mDebug)movecameraup = 2.0; 949 950 if(mMoving) 951 { 952 setAnimState(PLAYERANIMSTATE_WALK); 953 954 moveTime += dt; 955 mCamera->setPosition(Vector3(0,mCameraHeight + movecameraup,0) + Vector3(0,0.009 * pow(sin(moveTime*5.0), 2),0)); 956 } 957 else 958 { 959 if(Math::UnitRandom() > 0.98) 960 setAnimState(PLAYERANIMSTATE_IDLE); 961 else 962 setAnimState(PLAYERANIMSTATE_STAND); 963 964 moveTime = 0; 965 mCamera->setPosition(Vector3(0,mCameraHeight + movecameraup,0)); 966 } 967 968 if(mCharacterMeshEntity) 969 this->mCharacterMeshEntity->_updateAnimation(); 970 971 if(mWeaponEntity) 972 { 973 mWeaponNode->setPosition(mWeaponAttachBone->getWorldPosition()); 974 mWeaponNode->setOrientation(mWeaponAttachBone->getWorldOrientation()); 975 976 Vector3 translation = mWeaponBoundNode->getWorldPosition(); 977 Quaternion orientation = mWeaponBoundNode->getWorldOrientation(); 978 979 mWeaponBound->setGlobalOrientation(orientation); 980 mWeaponBound->setGlobalPosition(translation); 981 982 if(mDebug) 983 { 984 mWeaponBoundDebugNode->setPosition(translation); 985 mWeaponBoundDebugNode->setOrientation(orientation); 986 } 987 } 988 if(mFireBall) 989 mFireBall->update(dt); 990 } 991 return true; 992 } 993 994 String FPSPlayer::getAnimStateName(PlayerAnimState as, int option) 995 { 996 switch (as) 997 { 998 case PLAYERANIMSTATE_IDLE: 999 { 1000 if(mWeapon < 1) 1001 return "sword_idle"; 1002 else 1003 return "magic_idle"; 1004 } 1005 case PLAYERANIMSTATE_STAND: 1006 { 1007 if(mWeapon < 1) 1008 return "sword_stand"; 1009 else 1010 return "magic_stand"; 1011 } 1012 case PLAYERANIMSTATE_BLOCK: 1013 { 1014 return "block"; 1015 } 1016 case PLAYERANIMSTATE_WALK: 1017 { 1018 return "walk"; 1019 } 1020 case PLAYERANIMSTATE_ATTACK: 1021 { 1022 if(option) 1023 { 1024 if(mWeapon < 1) 1025 return "attack1"; 1026 else 1027 return "magic_attack"; 1028 } 1029 else 1030 { 1031 if(mWeapon < 1) 1032 return "attack2"; 1033 else 1034 return "magic_attack"; 1035 } 1036 } 1037 } 1038 return ""; 1039 } 1040 1041 void FPSPlayer::setAnimState(PlayerAnimState as) 1042 { 1043 if(!mCharacterMeshEntity) 1044 return; 1045 1046 switch(as) 1047 { 1048 case PLAYERANIMSTATE_STAND: 1049 { 1050 if(mCurrentAnimState != PLAYERANIMSTATE_STAND || mForceAnimChange) 1051 { 1052 //wait until anim finishes 1053 if(mCharacterMesh_AnimState->getTimePosition() >= 1054 mCharacterMesh_AnimState->getLength() || mCharacterMesh_AnimState->getLoop()) 1055 { 1056 mCurrentAnimState = PLAYERANIMSTATE_STAND; 1057 mCharacterMesh_AnimState->setEnabled(false); 1058 mCharacterMesh_AnimState = mCharacterMeshEntity->getAnimationState(getAnimStateName(PLAYERANIMSTATE_STAND)); 1059 mCharacterMesh_AnimState->setLoop(true); 1060 mCharacterMesh_AnimState->setEnabled(true); 1061 } 1062 } 1063 break; 1064 } 1065 case PLAYERANIMSTATE_IDLE: 1066 { 1067 if(mCurrentAnimState != PLAYERANIMSTATE_IDLE || mForceAnimChange) 1068 { 1069 //wait until anim finishes 1070 if(mCharacterMesh_AnimState->getTimePosition() >= 1071 mCharacterMesh_AnimState->getLength() || mCharacterMesh_AnimState->getLoop() || mCurrentAnimState == PLAYERANIMSTATE_IDLE) 1072 { 1073 mCurrentAnimState = PLAYERANIMSTATE_IDLE; 1074 mCharacterMesh_AnimState->setEnabled(false); 1075 mCharacterMesh_AnimState = mCharacterMeshEntity->getAnimationState(getAnimStateName(PLAYERANIMSTATE_IDLE)); 1076 mCharacterMesh_AnimState->setTimePosition(0); 1077 mCharacterMesh_AnimState->setLoop(false); 1078 mCharacterMesh_AnimState->setEnabled(true); 1079 } 1080 } 1081 break; 1082 } 1083 case PLAYERANIMSTATE_WALK: 1084 { 1085 if(mCurrentAnimState != PLAYERANIMSTATE_WALK) 1086 { 499 1087 if(mCurrentAnimState == PLAYERANIMSTATE_IDLE || mCurrentAnimState == PLAYERANIMSTATE_STAND) 500 1088 { … … 523 1111 mCharacterMesh_AnimState->setLoop(false); 524 1112 mCharacterMesh_AnimState->setEnabled(true); 1113 1114 if(mWeapon == 0) 1115 { 1116 for(std::set<PlayerCharacter*>::iterator it = mCharactersInRange.begin(); 1117 it != mCharactersInRange.end(); it++) 1118 (*it)->addHit(getHit()); 1119 } 1120 else 1121 { 1122 if(mManna > 20) 1123 { 1124 mManna -= 20; 1125 mStrength = 0; 1126 if(mFireBall) 1127 mFireBall->fire(); 1128 } 1129 } 525 1130 } 526 1131 break; -
GTP/trunk/App/Demos/Illum/Ogre/src/Common/src/SceneSerializer.cpp
r2388 r2459 78 78 context.sceneNode->attachObject(context.entity); 79 79 #endif 80 context.entity->setCastShadows(true); 80 81 return false; 81 82 } -
GTP/trunk/App/Demos/Illum/Ogre/src/Moria/include/Moria.h
r2446 r2459 64 64 this->sysNode = sysNode; 65 65 66 mStatsOn = false; 67 showDebugOverlay(mStatsOn); 68 66 69 } 67 70 … … 82 85 83 86 //sysNode->setPosition(mCamera->getPosition() - Vector3(0,1.5,0)); 84 sysNode->setPosition(FPSPlayer::thePlayer->getPosition() - Vector3(0,1.5,0));87 //sysNode->setPosition(FPSPlayer::thePlayer->getPosition() - Vector3(0,1.5,0)); 85 88 86 89 return ExampleFrameListener::frameStarted(evt); … … 259 262 void createPostproc() 260 263 { 264 CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0), 265 "FireHeatCompositor"); 266 CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0), 267 "FireHeatCompositor", false); 261 268 262 269 CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0), … … 275 282 CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0), 276 283 "GTP/PostProc/ToneMap", true); 277 278 279 280 281 282 283 /* 284 284 285 CompositorManager::getSingleton().addCompositor(mWindow->getViewport(0), 285 286 "GTP/PostProc/MotionBlur"); 286 287 CompositorManager::getSingleton().setCompositorEnabled(mWindow->getViewport(0), 287 "GTP/PostProc/MotionBlur", true); */288 "GTP/PostProc/MotionBlur", false); 288 289 289 290 } … … 291 292 void chooseSceneManager() 292 293 { 293 mSceneMgr = mRoot->createSceneManager("OctreeSceneManager");294 //mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager");294 //mSceneMgr = mRoot->createSceneManager("OctreeSceneManager"); 295 mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager"); 295 296 } 296 297 … … 298 299 { 299 300 std::string occlusion_cfg("OcclusionCulling.cfg"); 300 //mSceneMgr->setWorldGeometry(occlusion_cfg); 301 301 mSceneMgr->setWorldGeometry(occlusion_cfg); 302 303 Overlay* mainOverlay = OverlayManager::getSingleton().getByName("MORIA/MainOverlay"); 304 mainOverlay->show(); 305 302 306 createPostproc(); 303 307 … … 316 320 //mCamera->setPosition(0,100,0); 317 321 //mCamera->lookAt(0,-1,0); 318 mCamera->setFOVy(Radian(Degree( 100)));322 mCamera->setFOVy(Radian(Degree(80))); 319 323 mCamera->setNearClipDistance(0.001); 320 324 mCamera->setFarClipDistance(150); … … 329 333 inputStream = ResourceGroupManager::getSingleton().openResource("moria.level"); //towers2.level 330 334 World* NXWorld = new World("FrameListener: no, log: html"); 331 NXWorld->getPhysXDriver()->createFrameListener( 25);335 NXWorld->getPhysXDriver()->createFrameListener(90); 332 336 NXScene = NXWorld->createScene("Main", mSceneMgr, "gravity: yes, floor: no"); 333 337 s.setScene(NXScene); … … 336 340 s.parseEntryPoints("prmEntryPoints.text"); 337 341 338 NXScene->createActor("FakeFloor", new CubeShape(100,2,100), Vector3(0,-1,0), "static: yes"); 339 340 /* 341 Body* b = NXScene->createBody("ize", 342 "sphere.mesh", 343 new SphereShape(0.5f), 344 Vector3(5,0,5), 345 "mass: 10"); 346 b->getNode()->setScale(0.005,0.005,0.005); 347 b->setGlobalPosition(Vector3(5,10,5));*/ 348 342 NXScene->createActor("FakeFloor", new CubeShape(140,2,60), Vector3(0,-1,0), "static: yes"); 343 NXScene->createActor("FakeCeiling", new CubeShape(140,2,60), Vector3(0,17,0), "static: yes"); 344 NXScene->createActor("Wall1", new CubeShape(140,16,2), Vector3(0,8,30), "static: yes"); 345 NXScene->createActor("Wall2", new CubeShape(140,16,2), Vector3(0,8,-30), "static: yes"); 346 NXScene->createActor("Wall3", new CubeShape(2,16,60), Vector3(70,8,0), "static: yes"); 347 NXScene->createActor("Wall4", new CubeShape(2,16,60), Vector3(-70,8,0), "static: yes"); 349 348 /* 350 349 ParticleSystem* pSys1 = mSceneMgr->createParticleSystem("psys1", "GTP/Moria/Smoke_Large"); … … 353 352 pSysNode->attachObject(pSys1); 354 353 pSysNode->setPosition(-40,-1,-15);*/ 355 356 /*Entity* object = mSceneMgr->createEntity("object", "head.mesh"); 357 object->setMaterialName("GTP/Caustic/Glass"); 358 SceneNode* objectNode = rootNode->createChildSceneNode(); 359 objectNode->attachObject(object); 360 objectNode->scale(0.1,0.1,0.1); 361 objectNode->rotate(Vector3(0,1,0),Radian(0.2)); 362 objectNode->setPosition(-30,2.0,-5); 363 objectNode->_updateBounds();*/ 364 365 //createPlane("p","groundmaterial",Vector3(0,-0.3,0),Vector2(150,150)); 366 354 367 355 mainLight = mSceneMgr->createLight("MainLight"); 368 356 mainLight->setType(Light::LT_POINT); … … 378 366 //mainLight->setSpotlightRange(Degree(0),Degree(120)); 379 367 mainLight->setAttenuation(200.0, 0, 0, 3); 380 /* 381 Light* blueLight = mSceneMgr->createLight("blueLight"); 382 blueLight->setType(Light::LT_POINT); 383 blueLight->setCastShadows(true); 384 blueLight->setDiffuseColour(ColourValue(0.45,0.75,0.8)); 385 blueLight->setPowerScale(30); 386 blueLight->setAttenuation(40.0, 0, 4, 0); 387 SceneNode* blueLightNode = rootNode->createChildSceneNode(); 388 blueLightNode->setPosition(15,10,15); 389 blueLightNode->attachObject(blueLight);*/ 390 368 391 369 Vector4 v = mainLight->getAs4DVector(); 392 370 … … 407 385 408 386 PlayerCharacter::frameListenerPriority = 20; 387 409 388 gFPSPlayer = new FPSPlayer(NXScene, mSceneMgr, Vector3(0.5, 1.8, 0.3), Vector3(5, 10, 15), 1.6, mCamera, false); 410 gFPSPlayer->addPlayerMesh("FPSarm.mesh", 0.02, true);389 gFPSPlayer->addPlayerMesh("FPSarm.mesh", 0.02, false); 411 390 gFPSPlayer->addWeaponModel("sword.mesh", "joint28"); 412 413 PlayerCharacter* troll = new PlayerCharacter("troll1", NXScene, mSceneMgr, Vector3(1.5, 3.0, 1.2), Vector3(15, 10, 15), false);391 392 TrollCharacter* troll = new TrollCharacter("troll1", NXScene, mSceneMgr, Vector3(1.5, 3.0, 1.2), Vector3(15, 10, 15), false); 414 393 troll->addPlayerMesh("troll.mesh", 0.05, false); 394 troll->addWeaponModel("trollMace.mesh", "RightHand"); 395 396 CharacterManager::getSingleton().mScene = NXScene; 397 CharacterManager::getSingleton().mSceneManager = mSceneMgr; 398 415 399 /* 416 for(float i = 0; i< 7; i++) 400 TrollCharacter* troll2 = new TrollCharacter("troll2", NXScene, mSceneMgr, Vector3(1.5, 3.0, 1.2), Vector3(25, 10, 15), false); 401 troll2->addPlayerMesh("troll.mesh", 0.05, false); 402 troll2->addWeaponModel("trollMace.mesh", "RightHand"); 403 404 TrollCharacter* troll3 = new TrollCharacter("troll3", NXScene, mSceneMgr, Vector3(1.5, 3.0, 1.2), Vector3(35, 10, 15), false); 405 troll3->addPlayerMesh("troll.mesh", 0.05, false); 406 troll3->addWeaponModel("trollMace.mesh", "RightHand"); 407 */ 408 409 /*for(float i = 0; i< 7; i++) 417 410 { 418 411 float size = 0.5; … … 426 419 ac); 427 420 b->setCharacterCollisionGroup(NX_CHARACTER_COL_GROUP_PUSHABLE); 428 } 429 */ 430 ParticleSystem* pSys1 = mSceneMgr->createParticleSystem("psys1", "MoriaDust"); 421 422 }*/ 423 424 425 /* ParticleSystem* pSys1 = mSceneMgr->createParticleSystem("psys1", "MoriaDust"); 431 426 pSys1->setKeepParticlesInLocalSpace(true); 432 427 pSysNode = rootNode->createChildSceneNode("psys1"); 433 428 pSysNode->attachObject(pSys1); 434 pSysNode->setPosition(0,0,0); 435 429 pSysNode->setPosition(0,0,0);*/ 430 431 // LightList LL; 432 // mSceneMgr->_populateLightList(Vector3(0,0,0), 200, LL); 433 // int numlights = LL.size(); 436 434 437 435 OgreIlluminationManager::getSingleton().initTechniques(); … … 467 465 // gFPSPlayer->setPriority(20); 468 466 // mRoot->addFrameListener(gFPSPlayer); 469 OgreIlluminationManager::getSingleton().setPriority( 40);467 OgreIlluminationManager::getSingleton().setPriority(100); 470 468 mRoot->addFrameListener(&OgreIlluminationManager::getSingleton()); 471 469 -
GTP/trunk/App/Demos/Illum/Ogre/src/Moria/scripts/Moria.7.10.vcproj
r2391 r2459 90 90 StringPooling="TRUE" 91 91 MinimalRebuild="TRUE" 92 BasicRuntimeChecks="0" 92 93 RuntimeLibrary="2" 93 94 BufferSecurityCheck="FALSE"
Note: See TracChangeset
for help on using the changeset viewer.