-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBullet.cpp
47 lines (41 loc) · 1.25 KB
/
Bullet.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
/////////////////////////////////////////////////////////////////////
///////////////Original file by:Fyodor Zagumennov aka Sgw32//////////
///////////////Copyright(c) 2010 Fyodor Zagumennov //////////
/////////////////////////////////////////////////////////////////////
#include "Bullet.h"
Bullet::Bullet()
{
startadd = false;
}
Bullet::~Bullet()
{
}
void Bullet::init(Ogre::Vector3 pos,Ogre::Vector3 dir,Ogre::Real force,OgreNewt::World* world,Ogre::SceneManager* scene)
{
mPos = pos;
mDir = dir;
mForce = force;
mWorld = world;
Ogre::SceneNode* node = scene->getRootSceneNode()->createChildSceneNode(mPos);
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Box(mWorld, Ogre::Vector3(10,1,10));
bod = new OgreNewt::Body( mWorld, col );
bod->attachToNode( node );
bod->setPositionOrientation( node->getPosition(), node->getOrientation() );
delete col;
inertia = OgreNewt::MomentOfInertia::CalcBoxSolid( 1, Ogre::Vector3(10,1,10) );
bod->setMassMatrix( 1, inertia );
Ogre::String n = node->getName();
bod->setName(n);
bod->setCustomForceAndTorqueCallback<Bullet>( &Bullet::bullet_force_callback ,this);
}
void Bullet::start()
{
startadd = true;
}
void Bullet::bullet_force_callback(OgreNewt::Body* me)
{
if (startadd)
{
me->addForce(mDir*mForce);
}
}