-
Notifications
You must be signed in to change notification settings - Fork 1
/
Player.cpp
executable file
·131 lines (102 loc) · 3.21 KB
/
Player.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <Player.h>
#include <btBulletDynamicsCommon.h>
using std::cout;
//multiplayer stuff
Player::Player(Ogre::SceneManager* smp, Ogre::String inname, Ogre::Vector3 startPos):
l(25),
w(25),
h(50)
// playerState(PlayerState::NoFire),
// weapon(Weapon0)
{
//set scene manager pointer
sceneMgr=smp;
playerLV=btVector3(0,0,0);
//physical constants
l=.5;
w=.6;
h=1.6;
ori=btVector3(startPos.x,startPos.y,startPos.z);
cout << "player start position: "<<startPos.x<<" "<<startPos.y<<" "<<startPos.z<<"\n";
restitution=1.0;//avg of allowable extremes
name=inname;
position = btVector3(ori);
inertia= btVector3(0,0,0);
rotation=btQuaternion(0,0,0,1);
mass=1000.0f;
restitution=1.0;
friction=0;
player_health = 10.0;
//bind player
rootNode=sceneMgr->getRootSceneNode()->createChildSceneNode(name + "Node");
p_entity=sceneMgr->createEntity(inname,"ninja.mesh");
rootNode->attachObject(p_entity);
//purdiness
p_entity->setCastShadows(true);
std::string namest = name;
if(namest.compare("player")==0)
p_entity->setMaterialName("redninja");
else
p_entity->setMaterialName("PlayerWire2");
rootNode->translate(position.getX(),position.getY()-1.2,position.getZ());
rootNode->scale(1.2/100.,1.2/100.,1.2/100.);
//bt values
shape = new btBoxShape(btVector3(w/2.,h/2.,l/2.));
shape->calculateLocalInertia(mass,inertia);
ms = new btDefaultMotionState(btTransform(rotation, position));
btRigidBody::btRigidBodyConstructionInfo bodyCI(mass, ms, shape, inertia);
//add other physics constants
bodyCI.m_restitution=restitution;
bodyCI.m_friction=friction;
bodyCI.m_rollingFriction=0.2;//!!!
body = new btRigidBody(bodyCI);
body->setActivationState(DISABLE_DEACTIVATION);
btTransform btt;
ms->getWorldTransform(btt);
btVector3 org=btt.getOrigin();
}
void Player::setLV(btVector3 lvin){
playerLV=lvin;
}
void Player::updateTransform(){
btTransform tr;
ms->getWorldTransform(tr);
btVector3 origin = tr.getOrigin();
float mod = -2.1;
if(origin.getY()<mod || origin.getY()>mod){
//cout <<(float)((int)(origin.getY()/5.0))*5.0-2.2<<"it aint where it should be\n";
origin.setY(mod);
tr.setOrigin(origin);
ms->setWorldTransform(tr);
}
ms->getWorldTransform(tr);
origin=tr.getOrigin();
cout << origin.getY()<<"\n";
rootNode->setPosition(tr.getOrigin().getX(),
tr.getOrigin().getY(),
tr.getOrigin().getZ());
//rootNode->translate(0,-0.5,0);
Ogre::Quaternion quat = Ogre::Quaternion(rotation.getW(),rotation.getX(),rotation.getY(),rotation.getZ());
rootNode->setOrientation(quat);
position=btVector3(tr.getOrigin().getX(),
tr.getOrigin().getY(),
tr.getOrigin().getZ());
}
void Player::setLV(Ogre::Vector3 lvin){
playerLV=btVector3(lvin.x,lvin.y,lvin.z);
}
void Player::setPos(Ogre::Vector3 pos){
position = btVector3(pos.x,pos.y,pos.z);
}
void Player::setPos(btVector3 pos){
position=pos;
}
btScalar Player::getX(){
return position.getX();
}
btScalar Player::getY(){
return position.getY();
}
btScalar Player::getZ(){
return position.getZ();
}