-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ball.h
58 lines (39 loc) · 1.21 KB
/
Ball.h
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
#pragma once
#include <Urho3D/Scene/LogicComponent.h>
namespace Urho3D {
class RigidBody;
}
using namespace Urho3D;
// interesting billiards physical properties
// http://billiards.colostate.edu/threads/physics.html
const float BALL_SCALE = 0.7f;
const float BALL_MASS = 1.0f;
//const float BALL_FRICTION = 0.2f;
const float BALL_FRICTION = 0.8f;
const float BALL_LINEAR_DAMPING = 0.1f;
const float BALL_ANGULAR_DAMPING = 0.8f;
//const float BALL_ANGULAR_DAMPING = 0.3f;
const float BALL_RESTITUTION = 0.7f;
// Events
URHO3D_EVENT(E_BALLINPOCKET, BallInPocket) {
URHO3D_PARAM(P_BALLNAME, BallName);
}
class Ball : public LogicComponent {
URHO3D_OBJECT(Ball, LogicComponent);
public:
/// Construct.
Ball(Context *context);
virtual void Start();
/// Register object factory and attributes.
static void RegisterObject(Context *context);
/// Initialize ball
void Init(String material);
bool IsMoving();
String GetName();
protected:
WeakPtr<RigidBody> body_;
virtual void HandleCollisionWithPocket(VariantMap &eventData);
private:
bool IsCollidingWithPocket(VariantMap &eventData);
void HandleNodeCollisionStart(StringHash eventType, VariantMap &eventData);
};