-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathButton.cpp
122 lines (105 loc) · 3.22 KB
/
Button.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
#include "Button.h"
#include "Timeshift.h"
using namespace Run3;
Run3::Button::Button()
{
showFrame=true;
d_b=Vector3::ZERO;
p=false;
}
Run3::Button::~Button()
{
}
void Run3::Button::init(SceneNode* node,int type)
{
mNode=node;
mWorld=global::getSingleton().getWorld();
mSceneMgr=global::getSingleton().getSceneManager();
pLuaState=global::getSingleton().getLuaState();
// Standart static object
Vector3 size=node->getScale();
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::TreeCollision(mWorld, node,true);
bod = new OgreNewt::Body( mWorld, col );
bod->attachToNode( node );
bod->setName(node->getName());
bod->setPositionOrientation( node->getPosition(), node->getOrientation() );
delete col;
}
void Run3::Button::initMovable(SceneNode* node,int type,Real mass)
{
mNode=node;
mWorld=global::getSingleton().getWorld();
mSceneMgr=global::getSingleton().getSceneManager();
pLuaState=global::getSingleton().getLuaState();
// Dyn from PhysObject
Entity* ent = (Entity*)mNode->getAttachedObject(0);
AxisAlignedBox aab=ent->getBoundingBox();
Ogre::Vector3 scale=node->getScale();
Ogre::Vector3 min = aab.getMinimum()*scale;
Ogre::Vector3 max = aab.getMaximum()*scale;
Ogre::Vector3 center = aab.getCenter()*node->getScale();
Ogre::Vector3 size = Vector3(fabs(max.x-min.x),fabs(max.y-min.y),fabs(max.z-min.z));
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Box(mWorld, size,Quaternion::IDENTITY,center);
bod = new OgreNewt::Body( mWorld, col );
delete col;
//Make it movable!
//mass;
Ogre::Vector3 inertia;
inertia = OgreNewt::MomentOfInertia::CalcBoxSolid( mass, size);
bod->setMassMatrix( mass, inertia );
bod->attachToNode( node );
bod->setName(node->getName());
bod->setPositionOrientation( node->getPosition(), node->getOrientation() );
bod->setCustomForceAndTorqueCallback<Run3::Button>( &Run3::Button::camera_force_callback ,this);
bod->setAutoFreeze(0);
//delete col;
}
void Run3::Button::camera_force_callback( OgreNewt::Body* me )
{
//apply a simple gravity force.
Ogre::Real mass;
Ogre::Vector3 inertia;
me->getMassMatrix(mass, inertia);
Ogre::Vector3 force(0,-500,0);
force *= mass;
me->addForce( force*TIME_SHIFT*TIME_SHIFT );
}
void Run3::Button::init(SceneNode* node,int type,SceneNode* parent)
{
mNode=node;
mWorld=global::getSingleton().getWorld();
mSceneMgr=global::getSingleton().getSceneManager();
pLuaState=global::getSingleton().getLuaState();
// Standart static object
Vector3 size=node->getScale();
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::TreeCollision(mWorld, node,true);
bod = new OgreNewt::Body( mWorld, col );
bod->attachToNode( node );
bod->setName(node->getName());
bod->setPositionOrientation( node->getPosition(), node->getOrientation() );
delete col;
mparent=parent;
d_b=node->getPosition()-parent->getPosition();
p=true;
}
bool Run3::Button::frameStarted(const Ogre::FrameEvent &evt)
{
if (showFrame)
{
if(p)
bod->setPositionOrientation(mparent->getPosition()+d_b,mNode->getOrientation());
if (bod->getUsing())
{
this->use();
}
}
return true;
}
void Run3::Button::setCallback(String luaScript)
{
mLuaScript=luaScript;
}
void Run3::Button::use()
{
RunLuaScript(pLuaState,mLuaScript.c_str());
}