/src/NPC.cpp
C++ | 91 lines | 75 code | 12 blank | 4 comment | 9 complexity | 620d7f51d78ebe92ef27110d256d17b8 MD5 | raw file
1#include "NPC.h"
2
3NPC::NPC (IrrlichtDevice *device, IVideoDriver* driver, char caminhoModelo [], char caminhoTextura [], bool lightning)
4{
5 this->smgr = device->getSceneManager();
6 this->mesh = this->smgr->getMesh(caminhoModelo);
7 this->node = this->smgr->addAnimatedMeshSceneNode( mesh );
8 this->caminhotexture = caminhoTextura;
9 this->driver = driver;
10 this->speed = 2.0;
11 this->lightning = lightning;
12 if (node)
13 {
14 node->setMD2Animation(scene::EMAT_STAND);
15 node->setMaterialFlag(EMF_LIGHTING, lightning);
16 node->setMaterialTexture( 0, driver->getTexture(caminhoTextura) );
17 if(lightning == true){
18 this->node->addShadowVolumeSceneNode();
19 smgr->setShadowColor(video::SColor(150,0,0,0));
20 //this->node->setScale(core::vector3df(1,1,1));
21 this->node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, lightning);
22 }
23 }
24 this->LapFlag = 0;
25}
26
27void NPC::setMesh(char caminho_mesh[]){
28 IAnimatedMesh* tempMesh = this->smgr->getMesh(caminho_mesh);
29 this->node->setMesh(tempMesh);
30 this->node->setMaterialTexture( 0, driver->getTexture(this->caminhotexture) );
31 this->node->addShadowVolumeSceneNode();
32 node->setMaterialFlag(EMF_LIGHTING, false);
33 //smgr->setShadowColor(video::SColor(150,0,0,0));
34 //this->node->setScale(core::vector3df(1,1,1));
35 //this->node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, this->ligthning);
36}
37
38IAnimatedMesh* NPC::getMesh(){
39 return this->mesh;
40}
41
42void NPC::setLapFlag(short flag){
43 this->LapFlag = flag;
44}
45
46short NPC::getLapFlag(){
47 return this->LapFlag;
48}
49
50IAnimatedMeshSceneNode* NPC::getNode(){
51 return this->node;
52}
53
54void NPC::setPosition(float posX, float posY, float posZ)
55{
56 core::vector3df playerPos;
57 playerPos.X = posX;
58 playerPos.Y = posY;
59 playerPos.Z = posZ;
60 this->node->setPosition(playerPos);
61}
62
63void NPC::setModelSpeed(float speed){
64 this->speed = speed;
65 if(speed >= 2.0 && speed <= 3.9){
66 this->node->setAnimationSpeed(75);
67 }else if (speed >= 4.0 && speed <= 5.9){
68 this->node->setAnimationSpeed(95);
69 }else if (speed >= 6.0 && speed <= 7.5){
70 this->node->setAnimationSpeed(115);
71 }
72}
73void NPC::setPosition(core::vector3df npcPos){
74 this->node->setPosition(npcPos);
75}
76
77void NPC::rotateNPC(float x, float y, float z){
78 this->node->setRotation(core::vector3df(x,y,z));
79}
80
81void NPC::setAnimationMD2(irr::scene::EMD2_ANIMATION_TYPE anim){
82 this->node->setMD2Animation(anim);
83}
84
85void NPC::setAnimationMD2(char path[]){
86 this->node->setMD2Animation(path);
87}
88
89vector3df NPC::getPosition(){
90 return this->node->getPosition();
91}