-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameobject.cpp
155 lines (130 loc) · 3.7 KB
/
gameobject.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include "gameobject.hpp"
#include <Urho3D/Graphics/Octree.h>
#include <Urho3D/Scene/Scene.h>
namespace GameLib
{
GameObject::GameObject(Urho3D::Context* context) :
Urho3D::Component(context),
app(nullptr),
handles_physics_collisions(false)
{
}
GameObject::~GameObject()
{
}
void GameObject::setHandlesPhysicsCollisions(bool handles_physics_collisions)
{
this->handles_physics_collisions = handles_physics_collisions;
}
bool GameObject::getHandlesPhysicsCollisions() const
{
return handles_physics_collisions;
}
void GameObject::setApp(App* app)
{
this->app = app;
}
void GameObject::finishCreation(App* app, bool enable_physics, Urho3D::VariantMap* data)
{
this->app = app;
handleCreated(enable_physics, data);
}
bool GameObject::runServerSide(float deltatime, Urho3D::Controls const* controls)
{
(void)deltatime;
(void)controls;
return true;
}
bool GameObject::runClientSide(float deltatime)
{
(void)deltatime;
return true;
}
void GameObject::handleCreated(bool enable_physics, Urho3D::VariantMap* data)
{
(void)enable_physics;
(void)data;
}
void GameObject::handleAddedToClient()
{
}
bool GameObject::handleHitscan(Urho3D::Vector3 const& pos, Urho3D::Vector3 const& dir)
{
(void)pos;
(void)dir;
return false;
}
void GameObject::handleExplosion(Urho3D::Vector3 const& pos)
{
(void)pos;
}
void GameObject::handlePhysicsCollision(Urho3D::Vector3 const& pos, Urho3D::Vector3 const& normal, float distance, Urho3D::Node* node, GameObject* obj)
{
(void)pos;
(void)normal;
(void)distance;
(void)node;
(void)obj;
}
bool GameObject::receiveDecals() const
{
return false;
}
void GameObject::modifyControls(Urho3D::Controls* controls) const
{
(void)controls;
}
Urho3D::Matrix3x4 GameObject::getCameraTransform(Urho3D::Controls const* controls) const
{
(void)controls;
return Urho3D::Matrix3x4::IDENTITY;
}
Shape GameObject::getPlacementShape() const
{
return Shape();
}
bool GameObject::hitscan(Urho3D::Vector3& result_hitpos, Urho3D::Ray const& ray)
{
// Do ray query
Urho3D::PODVector<Urho3D::RayQueryResult> ray_hits;
Urho3D::RayOctreeQuery query(ray_hits, ray, Urho3D::RAY_TRIANGLE, Urho3D::M_INFINITY, Urho3D::DRAWABLE_GEOMETRY);
Urho3D::Octree* octree = GetScene()->GetComponent<Urho3D::Octree>();
octree->Raycast(query);
// Iterate hit objects
for (unsigned i = 0; i < ray_hits.Size(); ++ i) {
Urho3D::RayQueryResult const& ray_hit = ray_hits[i];
Urho3D::Node* node = ray_hit.drawable_->GetNode();
while (node != GetScene()) {
for (unsigned j = 0; j < node->GetNumComponents(); ++ j) {
Urho3D::Component* component = node->GetComponents()[j];
GameLib::GameObject* gameobj = dynamic_cast<GameLib::GameObject*>(component);
if (gameobj && gameobj != this && gameobj->handleHitscan(ray_hit.position_, ray.direction_)) {
result_hitpos = ray_hit.position_;
return true;
}
}
node = node->GetParent();
}
}
return false;
}
void GameObject::explosion(Urho3D::Vector3 const& pos)
{
// Iterate all objects in Scene
Urho3D::PODVector<Urho3D::Node*> nodes = GetScene()->GetChildren(false);
for (unsigned i = 0; i < nodes.Size(); ++ i) {
Urho3D::Node* node = nodes[i];
for (unsigned j = 0; j < node->GetNumComponents(); ++ j) {
Urho3D::Component* component = node->GetComponents()[j];
GameObject* gameobj = dynamic_cast<GameObject*>(component);
if (gameobj) {
gameobj->handleExplosion(pos);
}
}
}
}
App* GameObject::getApp() const
{
return app;
}
}