-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMOUSE02.py
76 lines (60 loc) · 2.71 KB
/
MOUSE02.py
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
from direct.showbase.ShowBase import *
from direct.task import Task
from direct.showbase import DirectObject
from direct.actor.Actor import Actor
from panda3d.core import LPoint3, LVector3, BitMask32
from panda3d.core import AmbientLight, DirectionalLight, LightAttrib
def color(r,g,b):
return((r/255,g/255,b/255))
def SquarePos(i):
# print(LPoint3((i % 8) - 3.5, int(i // 8) - 3.5, 0))
return LPoint3(1,10,0)
class ChessBoard(ShowBase):
def __init__(self):
ShowBase.__init__(self)
# self.disable_mouse()
self.mousePressed = taskMgr.add(self.mousePressed, 'mousePressed')
# self.accept("mouse1",self.mousePressed )
self.squares1 = loader.loadModel("models/square.egg")
self.squares1.reparentTo(render)
self.squares1.setPos(0,10,0)
self.squares1.setColor(0,0,0)
self.squares2 = loader.loadModel("models/square.egg")
self.squares2.reparentTo(render)
self.squares2.setPos(1,10,0)
self.squares2.setColor(1,1,1)
self.squares3= loader.loadModel("models/square.egg")
self.squares3.reparentTo(render)
self.squares3.setPos(1,9,0)
self.squares3.setColor(0,0,0)
self.squares4= loader.loadModel("models/square.egg")
self.squares4.reparentTo(render)
self.squares4.setPos(0,9,0)
self.squares4.setColor(1,1,1)
self.pawn = loader.loadModel("models/pawn.egg")
self.pawn.reparentTo(render)
self.pawn.setPos(0,9,0)
self.pawn.setColor(color(125,0,255)[0],color(125,0,255)[1],color(125,0,255)[2])
# if self.mouseWatcherNode.hasMouse():
# # get the mouse position
# mpos = self.mouseWatcherNode.getMouse()
# print(mpos)
self.setBackgroundColor(0.5,0.5,0)
self.camera.setPos(0,-7,10)
self.camera.setHpr(0,-30,0)
self.setupLights()
def mousePressed(self, task):
if self.mouseWatcherNode.hasMouse():
# get the mouse position
mpos = self.mouseWatcherNode.getMouse()
print(mpos)
def setupLights(self): # This function sets up some default lighting
ambientLight = AmbientLight("ambientLight")
ambientLight.setColor((.8, .8, .8, 1))
directionalLight = DirectionalLight("directionalLight")
directionalLight.setDirection(LVector3(0, 45, -45))
directionalLight.setColor((0.2, 0.2, 0.2, 1))
render.setLight(render.attachNewNode(directionalLight))
render.setLight(render.attachNewNode(ambientLight))
chess = ChessBoard()
chess.run()