-
Notifications
You must be signed in to change notification settings - Fork 1
/
LaserPistolBullet.cpp
102 lines (88 loc) · 3.87 KB
/
LaserPistolBullet.cpp
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
/*
Copyright (C) 2011-2012 Alican Sekerefe
TeamTwo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
TeamTwo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Contact: projectteamtwo@gmail.com
*/
#include "LaserPistolBullet.h"
#include "Util/Converter.h"
LaserPistolBullet::LaserPistolBullet(SceneManager* sceneManager,OgreBulletDynamics::DynamicsWorld* dynamics,int ownerId,unsigned char team):Bullet(sceneManager,dynamics,1000*60,16*60,ownerId)
{
diffColor=ColourValue(0,0,1);
if(team==0)
materialName="Laserball_Blue";
else
materialName="Laserball_Red";
scaleValue=Ogre::Vector3(.1,.1,.1);
this->ownerID=ownerId;
}
void LaserPistolBullet::createPhysics(Ogre::Vector3 hitboxSize,std::string name)
{
if (bulletNode == NULL)
return;
this->dynamics = dynamics;
this->hitBoxSize = hitboxSize;
//OgreBulletCollisions::BoxCollisionShape* box = new OgreBulletCollisions::BoxCollisionShape(hitboxSize);
OgreBulletCollisions::SphereCollisionShape* sphere=new OgreBulletCollisions::SphereCollisionShape((hitboxSize.x+hitboxSize.z)/4.);
bulletRigid = new OgreBulletDynamics::RigidBody(name, dynamics);
bulletRigid->setShape(bulletNode, sphere, 0, 0, .000001, position, orientation);
bulletRigid->getBulletRigidBody()->setActivationState(DISABLE_DEACTIVATION);
bulletRigid->getBulletRigidBody()->setLinearFactor(btVector3(0, 0, 0));
bulletRigid->getBulletRigidBody()->setAngularFactor(btVector3(0, 0, 0));
bulletRigid->getBulletRigidBody()->setGravity(btVector3(0, 0, 0));
bulletRigid->getBulletRigidBody()->setCollisionFlags(bulletRigid->getBulletRigidBody()->getCollisionFlags());
bulletRigid->getBulletObject()->setUserPointer(new CollisionObjectInfo(bulletNode,bulletRigid,CollisionObjectTypes::BULLET,this));
bulletRigid->getBulletRigidBody()->setCcdMotionThreshold(.0001);
bulletRigid->getBulletRigidBody()->setCcdSweptSphereRadius(.2);
}
void LaserPistolBullet::update(double time)
{
//if ((light->getVisible() && maxDistance - TTL > (speed * 2)) || isHit())
// light->setVisible(false);
if(TTL>0 && !isHit())
{
Ogre::Vector3 wd=bulletNode->getOrientation()*Ogre::Vector3(0,0,-speed);
bulletRigid->getBulletRigidBody()->setLinearVelocity(btVector3(wd.x,wd.y,wd.z));
TTL-=speed;
double scalar=((float)TTL)/(float)maxDistance;
//light->setDiffuseColour(diffColor*scalar);
}
else
{
alive=false;
bulletNode->setVisible(false);
delete bulletRigid;
}
}
void LaserPistolBullet::createVisual(Ogre::Vector3 pos, Quaternion orientation)
{
this->position=pos;
this->orientation=orientation;
if(bulletNode!=NULL)
sceneManager->destroySceneNode(bulletNode);
bbset=sceneManager->createBillboardSet();
bbset->setMaterialName(materialName);
bbset->createBillboard(0,0,0);
bulletNode=sceneManager->getRootSceneNode()->createChildSceneNode();
//bulletNode->attachObject(light);
bulletNode->attachObject(bbset);
bulletNode->setPosition(pos);
bulletNode->setOrientation(orientation);
bulletNode->scale(scaleValue);
}
void LaserPistolBullet::changeColor(unsigned char color)
{
if(color==0)
materialName="Laserball_Blue";
else
materialName="Laserball_Red";
bbset->setMaterialName(materialName);
}