Skip to content

Commit d08d712

Browse files
committed
Working bullet system
0 parents  commit d08d712

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Aaron Olkin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

base.py

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#!/usr/bin/env python3
2+
3+
from math import pi, sin, cos
4+
from random import random, randint
5+
6+
from panda3d.core import loadPrcFileData
7+
#loadPrcFileData("", "want-directtools #t")
8+
#loadPrcFileData("", "want-tk #t")
9+
10+
from panda3d.core import Point3, Vec3
11+
from panda3d.core import TextNode, TextFont, AntialiasAttrib
12+
13+
from panda3d.bullet import *
14+
15+
from direct.showbase.ShowBase import ShowBase
16+
from direct.task import Task
17+
from direct.actor.Actor import Actor
18+
from direct.interval.IntervalGlobal import Sequence
19+
20+
class TextApp(ShowBase):
21+
22+
def __init__(self):
23+
super().__init__(self)
24+
#self.tutorialScene()
25+
26+
self.font = self.loader.loadFont(
27+
'/System/Library/Fonts/Supplemental/arial.ttf')
28+
self.font.setRenderMode(TextFont.RMPolygon)
29+
30+
debugNode = BulletDebugNode('Debug')
31+
debugNode.showWireframe(True)
32+
debugNode.showConstraints(True)
33+
debugNode.showBoundingBoxes(False)
34+
debugNode.showNormals(False)
35+
debugNP = self.render.attachNewNode(debugNode)
36+
debugNP.show()
37+
38+
39+
self.world = BulletWorld()
40+
self.world.setGravity(Vec3(0, 0, -.1))
41+
self.world.setDebugNode(debugNP.node())
42+
self.taskMgr.add(self.update, 'update')
43+
44+
self.camera.setPos(0, -20, 0)
45+
self.disableMouse()
46+
47+
for i in range(5):
48+
self.addText("Sample %s" % i, random() * 5, random() * 5, 2)
49+
50+
self.targets = []
51+
self.createTarget("A", -2, 5, -1)
52+
53+
def createTarget(self, name, x=0, y=0, z=0):
54+
shape = BulletSphereShape(0.5)
55+
ghost = BulletGhostNode('GhostTarget_'+name)
56+
ghost.addShape(shape)
57+
ghostNP = self.render.attachNewNode(ghost)
58+
ghostNP.setPos(x, y, z)
59+
self.world.attachGhost(ghost)
60+
self.targets.append(ghost)
61+
62+
def addText(self, value, x=0, y=0, z=0):
63+
text = TextNode("T1")
64+
text.setFont(self.font)
65+
text.setText(value)
66+
67+
shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
68+
node = BulletRigidBodyNode("Text")
69+
node.setMass(1)
70+
node.addShape(shape)
71+
72+
np = self.render.attachNewNode(node)
73+
np.setPos(x, y, z)
74+
np.attachNewNode(text)
75+
76+
self.world.attachRigidBody(node)
77+
78+
#self.render.attachNewNode(text)#.setAntialias(AntialiasAttrib.MMultisample)
79+
80+
def update(self, task):
81+
dt = globalClock.getDt()
82+
self.world.doPhysics(dt)
83+
return task.cont
84+
85+
def tutorialScene(self):
86+
# Load the environment model.
87+
self.scene = self.loader.loadModel("models/environment")
88+
# Reparent the model to render.
89+
self.scene.reparentTo(self.render)
90+
# Apply scale and position transforms on the model.
91+
self.scene.setScale(0.25, 0.25, 0.25)
92+
self.scene.setPos(-8, 42, 0)
93+
94+
# Load and transform the panda actor.
95+
self.pandaActor = Actor("models/panda-model",
96+
{"walk": "models/panda-walk4"})
97+
self.pandaActor.setScale(0.005, 0.005, 0.005)
98+
self.pandaActor.reparentTo(self.render)
99+
# Loop its animation.
100+
self.pandaActor.loop("walk")
101+
102+
posInterval1 = self.pandaActor.posInterval(13,
103+
Point3(0, -10, 0),
104+
startPos=Point3(0, 10, 0))
105+
posInterval2 = self.pandaActor.posInterval(13,
106+
Point3(0, 10, 0),
107+
startPos=Point3(0, -10, 0))
108+
hprInterval1 = self.pandaActor.hprInterval(3,
109+
Point3(180, 0, 0),
110+
startHpr=Point3(0, 0, 0))
111+
hprInterval2 = self.pandaActor.hprInterval(3,
112+
Point3(0, 0, 0),
113+
startHpr=Point3(180, 0, 0))
114+
115+
# Create and play the sequence that coordinates the intervals.
116+
self.pandaPace = Sequence(posInterval1, hprInterval1,
117+
posInterval2, hprInterval2,
118+
name="pandaPace")
119+
self.pandaPace.loop()
120+
121+
# Define a procedure to move the camera.
122+
def spinCameraTask(self, task):
123+
angleDegrees = abs(task.time * 6.0 % 360 - 180) - 90
124+
angleRadians = angleDegrees * (pi / 180.0)
125+
self.camera.setPos(20 * sin(angleRadians), -20 * cos(angleRadians), 0)
126+
self.camera.setHpr(angleDegrees, 0, 0)
127+
return Task.cont
128+
129+
app = TextApp()
130+
app.run()

0 commit comments

Comments
 (0)