-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhysicsManager.py
More file actions
35 lines (26 loc) · 1021 Bytes
/
PhysicsManager.py
File metadata and controls
35 lines (26 loc) · 1021 Bytes
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
#PhysicsManager.py
from Vector import Vector3
ALL_RIGIDBODIES = 100
activeForces = []
bodies = []
#add a new force to a rigidbody
def addForce(vector, duration, target):
if isinstance(target, Rigidbody):
activeForces.append(Force(vector, duration, target))
elif isinstance(target, Object):
activeForces.append(Force(vector, duration, target))
else:
raise TypeError("Force must be applied to a Rigidbody type target.")
def applyActiveForces():
for force in activeForces:
force.applyForce()
#called by main physics thread - update positions of all physics objects
def update(deltaTime):
for body in bodies:
body.velocity += body.acceleration * deltaTime
body.parent.move(body.velocity * deltaTime * (1-body.airResistance))
body.parent.rotateWorld(body.rotationVelocity * deltaTime * (1-body.airResistance))
def addRigidbody(body):
bodies.append(body)
def getActiveForces():
return activeForces