mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
Changed input to Event in entity na
This commit is contained in:
parent
081d8f0052
commit
15f382d754
@ -107,12 +107,12 @@ class CutScene(Entity.Entity, DirectObject.DirectObject):
|
|||||||
self.subjectNodePath.setPos(self.pos)
|
self.subjectNodePath.setPos(self.pos)
|
||||||
self.subjectNodePath.setHpr(self.hpr)
|
self.subjectNodePath.setHpr(self.hpr)
|
||||||
#self.setSubjectNodePath(self.subjectNodePath)
|
#self.setSubjectNodePath(self.subjectNodePath)
|
||||||
self.setStartStop(self.startStop)
|
self.setStartStop(self.startStopEvent)
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
assert(self.debugPrint("destroy()"))
|
assert(self.debugPrint("destroy()"))
|
||||||
self.ignore(self.startStop)
|
self.ignore(self.startStopEvent)
|
||||||
self.startStop = None
|
self.startStopEvent = None
|
||||||
Entity.Entity.destroy(self)
|
Entity.Entity.destroy(self)
|
||||||
#DirectObject.DirectObject.destroy(self)
|
#DirectObject.DirectObject.destroy(self)
|
||||||
|
|
||||||
@ -142,6 +142,7 @@ class CutScene(Entity.Entity, DirectObject.DirectObject):
|
|||||||
track = Parallel(name = trackName)
|
track = Parallel(name = trackName)
|
||||||
track = self.getEffect(self, track, self.subjectNodePath, self.duration)
|
track = self.getEffect(self, track, self.subjectNodePath, self.duration)
|
||||||
track = self.getMotion(self, track, self.subjectNodePath, self.duration)
|
track = self.getMotion(self, track, self.subjectNodePath, self.duration)
|
||||||
|
track = Sequence(Wait(0.8), track)
|
||||||
track.start(0.0)
|
track.start(0.0)
|
||||||
self.track = track
|
self.track = track
|
||||||
else:
|
else:
|
||||||
@ -151,11 +152,11 @@ class CutScene(Entity.Entity, DirectObject.DirectObject):
|
|||||||
|
|
||||||
def setStartStop(self, event):
|
def setStartStop(self, event):
|
||||||
assert(self.debugPrint("setStartStop(event=%s)"%(event,)))
|
assert(self.debugPrint("setStartStop(event=%s)"%(event,)))
|
||||||
if self.startStop:
|
if self.startStopEvent:
|
||||||
self.ignore(self.startStop)
|
self.ignore(self.startStopEvent)
|
||||||
self.startStop = "switch-%s"%(event,)
|
self.startStopEvent = "switch-%s"%(event,)
|
||||||
if self.startStop:
|
if self.startStopEvent:
|
||||||
self.accept(self.startStop, self.startOrStop)
|
self.accept(self.startStopEvent, self.startOrStop)
|
||||||
|
|
||||||
def getName(self):
|
def getName(self):
|
||||||
#return "CutScene-%s"%(self.entId,)
|
#return "CutScene-%s"%(self.entId,)
|
||||||
|
@ -43,8 +43,8 @@ class LogicGate(Entity):
|
|||||||
type = 'logicGate'
|
type = 'logicGate'
|
||||||
output = 'bool'
|
output = 'bool'
|
||||||
attribs = (
|
attribs = (
|
||||||
('input_input1_bool', 0, 'entId', {'output':'bool'}),
|
('input1Event', 0, 'entId', {'output':'bool'}),
|
||||||
('input_input2_bool', 0, 'entId', {'output':'bool'}),
|
('input2Event', 0, 'entId', {'output':'bool'}),
|
||||||
('isInput1', 0, 'bool'),
|
('isInput1', 0, 'bool'),
|
||||||
('isInput2', 0, 'bool'),
|
('isInput2', 0, 'bool'),
|
||||||
('logicType', 'or', 'choice',
|
('logicType', 'or', 'choice',
|
||||||
@ -91,7 +91,7 @@ class CutScene(Entity):
|
|||||||
attribs = (
|
attribs = (
|
||||||
('pos', Point3(0,0,0), 'pos'),
|
('pos', Point3(0,0,0), 'pos'),
|
||||||
('hpr', Vec3(0,0,0), 'hpr'),
|
('hpr', Vec3(0,0,0), 'hpr'),
|
||||||
('startStop', 0),
|
('startStopEvent', 0, 'entId', {'output':'bool'}),
|
||||||
('effect', 'irisInOut'),
|
('effect', 'irisInOut'),
|
||||||
('motion', 'foo1'),
|
('motion', 'foo1'),
|
||||||
('duration', 5.0),
|
('duration', 5.0),
|
||||||
@ -121,7 +121,7 @@ class Switch(Entity, NodepathImpl):
|
|||||||
('scale', Vec3(1), 'scale'),
|
('scale', Vec3(1), 'scale'),
|
||||||
('color', Vec4(1,1,1,1), 'color'),
|
('color', Vec4(1,1,1,1), 'color'),
|
||||||
('model', '', 'bamfilename'),
|
('model', '', 'bamfilename'),
|
||||||
('input_isOn_bool', 0, 'entId', {'output':'bool'}),
|
('isOnEvent', 0, 'entId', {'output':'bool'}),
|
||||||
('isOn', 0, 'bool'),
|
('isOn', 0, 'bool'),
|
||||||
('secondsOn', 1, 'float'),
|
('secondsOn', 1, 'float'),
|
||||||
)
|
)
|
||||||
@ -159,23 +159,23 @@ class Door(Entity):
|
|||||||
output = 'bool'
|
output = 'bool'
|
||||||
attribs = (
|
attribs = (
|
||||||
('parent', 0, 'entId'),
|
('parent', 0, 'entId'),
|
||||||
('pos', Point3(0,0,0), 'pos'),
|
('pos', Point3(0,0,0), 'pos'), # Client Only
|
||||||
('hpr', Vec3(0,0,0), 'hpr'),
|
('hpr', Vec3(0,0,0), 'hpr'), # Client Only
|
||||||
('scale', Vec3(1,1,1), 'scale'),
|
('scale', Vec3(1,1,1), 'scale'), # Client Only
|
||||||
('color', Vec4(1,1,1,1), 'color'),
|
('color', Vec4(1,1,1,1), 'color'), # Client Only
|
||||||
('model', "", 'bamfilename'),
|
('model', "", 'bamfilename'), # Client Only
|
||||||
('doorwayNum', 0), # Obsolete
|
('doorwayNum', 0), # Obsolete
|
||||||
('input_Lock0_bool', 0, 'entId', {'output':'bool'}),
|
('unlock0Event', 0, 'entId', {'output':'bool'}), # AI Only
|
||||||
('input_Lock1_bool', 0, 'entId', {'output':'bool'}),
|
('unlock1Event', 0, 'entId', {'output':'bool'}), # AI Only
|
||||||
('input_Lock2_bool', 0, 'entId', {'output':'bool'}),
|
('unlock2Event', 0, 'entId', {'output':'bool'}), # AI Only
|
||||||
('input_Lock3_bool', 0, 'entId', {'output':'bool'}),
|
('unlock3Event', 0, 'entId', {'output':'bool'}), # AI Only
|
||||||
('input_isOpen_bool', 0, 'entId', {'output':'bool'}),
|
('isOpenEvent', 0, 'entId', {'output':'bool'}),
|
||||||
('isLock0Unlocked', 0, 'bool'),
|
('isLock0Unlocked', 0, 'bool'), # AI Only
|
||||||
('isLock1Unlocked', 0, 'bool'),
|
('isLock1Unlocked', 0, 'bool'), # AI Only
|
||||||
('isLock2Unlocked', 0, 'bool'),
|
('isLock2Unlocked', 0, 'bool'), # AI Only
|
||||||
('isLock3Unlocked', 0, 'bool'),
|
('isLock3Unlocked', 0, 'bool'), # AI Only
|
||||||
('isOpen', 0, 'bool'),
|
('isOpen', 0, 'bool'), # AI Only
|
||||||
('secondsOpen', 1, 'float'),
|
('secondsOpen', 1, 'float'), # AI Only
|
||||||
)
|
)
|
||||||
|
|
||||||
class Grid(Nodepath):
|
class Grid(Nodepath):
|
||||||
|
@ -1,39 +1,40 @@
|
|||||||
"""LogicGateAI.py: contains the OrLoEntity class"""
|
"""
|
||||||
|
LogicGateAI.py
|
||||||
|
|
||||||
|
Logic Gates:
|
||||||
|
|
||||||
|
and: 0 0 = 0 or: 0 0 = 0 xor: 0 0 = 0
|
||||||
|
0 1 = 0 0 1 = 1 0 1 = 1
|
||||||
|
1 0 = 0 1 0 = 1 1 0 = 1
|
||||||
|
1 1 = 1 1 1 = 1 1 1 = 0
|
||||||
|
|
||||||
|
nand: 0 0 = 1 nor: 0 0 = 1 xnor: 0 0 = 1
|
||||||
|
0 1 = 1 0 1 = 0 0 1 = 0
|
||||||
|
1 0 = 1 1 0 = 0 1 0 = 0
|
||||||
|
1 1 = 0 1 1 = 0 1 1 = 1
|
||||||
|
|
||||||
|
In the following:
|
||||||
|
1: send a true message
|
||||||
|
0: send a false message
|
||||||
|
-: don't send a message
|
||||||
|
|
||||||
|
a b and or xor nand nor xnor
|
||||||
|
(0 0) (0) (0) (0) (1) (1) (1) <--- initial state
|
||||||
|
1 0 - 1 1 - 0 0
|
||||||
|
0 0 - 0 0 - 1 1
|
||||||
|
1 0 - 1 1 - 0 0
|
||||||
|
1 1 1 - 0 0 - 1
|
||||||
|
0 1 0 - 1 1 - 0
|
||||||
|
1 1 1 - 0 0 - 1
|
||||||
|
0 1 0 - 1 1 - 0
|
||||||
|
0 0 - 0 0 - 1 1
|
||||||
|
"""
|
||||||
|
|
||||||
import PandaObject
|
import PandaObject
|
||||||
import DirectNotifyGlobal
|
import DirectNotifyGlobal
|
||||||
import Entity
|
import Entity
|
||||||
|
|
||||||
|
|
||||||
# Logic Gates:
|
|
||||||
#
|
|
||||||
# and: 0 0 = 0 or: 0 0 = 0 xor: 0 0 = 0
|
|
||||||
# 0 1 = 0 0 1 = 1 0 1 = 1
|
|
||||||
# 1 0 = 0 1 0 = 1 1 0 = 1
|
|
||||||
# 1 1 = 1 1 1 = 1 1 1 = 0
|
|
||||||
#
|
|
||||||
# nand: 0 0 = 1 nor: 0 0 = 1 xnor: 0 0 = 1
|
|
||||||
# 0 1 = 1 0 1 = 0 0 1 = 0
|
|
||||||
# 1 0 = 1 1 0 = 0 1 0 = 0
|
|
||||||
# 1 1 = 0 1 1 = 0 1 1 = 1
|
|
||||||
#
|
|
||||||
# In the following:
|
|
||||||
# 1: send a true message
|
|
||||||
# 0: send a false message
|
|
||||||
# -: don't send a message
|
|
||||||
#
|
|
||||||
# a b and or xor nand nor xnor
|
|
||||||
# (0 0) (0) (0) (0) (1) (1) (1) <--- initial state
|
|
||||||
# 1 0 - 1 1 - 0 0
|
|
||||||
# 0 0 - 0 0 - 1 1
|
|
||||||
# 1 0 - 1 1 - 0 0
|
|
||||||
# 1 1 1 - 0 0 - 1
|
|
||||||
# 0 1 0 - 1 1 - 0
|
|
||||||
# 1 1 1 - 0 0 - 1
|
|
||||||
# 0 1 0 - 1 1 - 0
|
|
||||||
# 0 0 - 0 0 - 1 1
|
|
||||||
|
|
||||||
def andTest(self, a, b):
|
def andTest(self, a, b):
|
||||||
assert(self.debugPrint("andTest(a=%s, b=%s)"%(a, b)))
|
assert(self.debugPrint("andTest(a=%s, b=%s)"%(a, b)))
|
||||||
if b:
|
if b:
|
||||||
@ -83,12 +84,15 @@ class LogicGateAI(Entity.Entity, PandaObject.PandaObject):
|
|||||||
assert(self.debugPrint(
|
assert(self.debugPrint(
|
||||||
"LogicGateAI(entId=%s)"
|
"LogicGateAI(entId=%s)"
|
||||||
%(entId)))
|
%(entId)))
|
||||||
self.input1 = None
|
self.input1Event = None
|
||||||
self.input2 = None
|
self.input2Event = None
|
||||||
|
PandaObject.PandaObject.__init__(self)
|
||||||
Entity.Entity.__init__(self, level, entId)
|
Entity.Entity.__init__(self, level, entId)
|
||||||
self.setLogicType(self.logicType)
|
self.setLogicType(self.logicType)
|
||||||
self.setInput_input1_bool(self.input_input1_bool)
|
self.setIsInput1(self.isInput1)
|
||||||
self.setInput_input2_bool(self.input_input2_bool)
|
self.setIsInput2(self.isInput2)
|
||||||
|
self.setInput1Event(self.input1Event)
|
||||||
|
self.setInput2Event(self.input2Event)
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
assert(self.debugPrint("destroy()"))
|
assert(self.debugPrint("destroy()"))
|
||||||
@ -119,21 +123,21 @@ class LogicGateAI(Entity.Entity, PandaObject.PandaObject):
|
|||||||
self.isInput2=isTrue
|
self.isInput2=isTrue
|
||||||
self.logicTest(self, isTrue, self.isInput1)
|
self.logicTest(self, isTrue, self.isInput1)
|
||||||
|
|
||||||
def setInput_input1_bool(self, event):
|
def setInput1Event(self, event):
|
||||||
assert(self.debugPrint("setInput_input1_bool(event=%s)"%(event,)))
|
assert(self.debugPrint("setInput1Event(event=%s)"%(event,)))
|
||||||
if self.input1:
|
if self.input1Event:
|
||||||
self.ignore(self.input1)
|
self.ignore(self.input1Event)
|
||||||
self.input1 = "switch-%s"%(event,)
|
self.input1Event = "switch-%s"%(event,)
|
||||||
if self.input1:
|
if self.input1Event:
|
||||||
self.accept(self.input1, self.setIsInput1)
|
self.accept(self.input1Event, self.setIsInput1)
|
||||||
|
|
||||||
def setInput_input2_bool(self, event):
|
def setInput2Event(self, event):
|
||||||
assert(self.debugPrint("setInput_input2_bool(event=%s)"%(event,)))
|
assert(self.debugPrint("setInput2Event(event=%s)"%(event,)))
|
||||||
if self.input2:
|
if self.input2Event:
|
||||||
self.ignore(self.input2)
|
self.ignore(self.input2Event)
|
||||||
self.input2 = "switch-%s"%(event,)
|
self.input2Event = "switch-%s"%(event,)
|
||||||
if self.input2:
|
if self.input2Event:
|
||||||
self.accept(self.input2, self.setIsInput2)
|
self.accept(self.input2Event, self.setIsInput2)
|
||||||
|
|
||||||
def getName(self):
|
def getName(self):
|
||||||
#return "logicGate-%s"%(self.entId,)
|
#return "logicGate-%s"%(self.entId,)
|
||||||
|
@ -67,6 +67,9 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||||||
Set up the avatar collisions
|
Set up the avatar collisions
|
||||||
"""
|
"""
|
||||||
assert(self.debugPrint("initializeCollisions()"))
|
assert(self.debugPrint("initializeCollisions()"))
|
||||||
|
|
||||||
|
assert not avatarNodePath.isEmpty()
|
||||||
|
|
||||||
self.cTrav = collisionTraverser
|
self.cTrav = collisionTraverser
|
||||||
|
|
||||||
# Set up the collision sphere
|
# Set up the collision sphere
|
||||||
@ -308,6 +311,105 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||||||
# Clear the contact vector so we can tell if we contact something next frame:
|
# Clear the contact vector so we can tell if we contact something next frame:
|
||||||
self.actorNode.setContactVector(Vec3.zero())
|
self.actorNode.setContactVector(Vec3.zero())
|
||||||
return Task.cont
|
return Task.cont
|
||||||
|
|
||||||
|
def handleAvatarControls_wip(self, task):
|
||||||
|
"""
|
||||||
|
Check on the arrow keys and update the avatar.
|
||||||
|
"""
|
||||||
|
#assert(self.debugPrint("handleAvatarControls(task=%s)"%(task,)))
|
||||||
|
physObject=self.actorNode.getPhysicsObject()
|
||||||
|
rotAvatarToPhys=Mat3.rotateMatNormaxis(-self.avatarNodePath.getH(), Vec3.up())
|
||||||
|
#rotPhysToAvatar=Mat3.rotateMatNormaxis(self.avatarNodePath.getH(), Vec3.up())
|
||||||
|
contact=self.actorNode.getContactVector()
|
||||||
|
|
||||||
|
# hack fix for falling through the floor:
|
||||||
|
if contact==Vec3.zero() and self.avatarNodePath.getZ()<-50.0:
|
||||||
|
# reset:
|
||||||
|
self.avatarNodePath.setPos(Vec3(0.0, 0.0, 20.0))
|
||||||
|
|
||||||
|
# Determine what the speeds are based on the buttons:
|
||||||
|
self.__speed=(self.__forwardButton and self.avatarControlForwardSpeed or
|
||||||
|
self.__reverseButton and -self.avatarControlReverseSpeed)
|
||||||
|
self.__slideSpeed=self.__slideButton and (
|
||||||
|
(self.__leftButton and -self.avatarControlForwardSpeed) or
|
||||||
|
(self.__rightButton and self.avatarControlForwardSpeed))
|
||||||
|
self.__rotationSpeed=not self.__slideButton and (
|
||||||
|
(self.__leftButton and self.avatarControlRotateSpeed) or
|
||||||
|
(self.__rightButton and -self.avatarControlRotateSpeed))
|
||||||
|
# How far did we move based on the amount of time elapsed?
|
||||||
|
dt=min(ClockObject.getGlobalClock().getDt(), 0.1)
|
||||||
|
|
||||||
|
doPhysics=1
|
||||||
|
if not contact.almostEqual(Vec3.zero()):
|
||||||
|
contactLength = contact.length()
|
||||||
|
contact.normalize()
|
||||||
|
angle=contact.dot(Vec3.up())
|
||||||
|
if angle>self.__standableGround:
|
||||||
|
# ...avatar is on standable ground.
|
||||||
|
#print "standableGround"
|
||||||
|
if self.__old_contact==Vec3.zero():
|
||||||
|
jumpTime = 0.0
|
||||||
|
if contactLength>self.__hardLandingForce:
|
||||||
|
# ...avatar was airborne.
|
||||||
|
messenger.send("jumpHardLand")
|
||||||
|
else:
|
||||||
|
messenger.send("jumpLand")
|
||||||
|
if self.__jumpButton:
|
||||||
|
self.__jumpButton=0
|
||||||
|
messenger.send("jumpStart")
|
||||||
|
jump=Vec3(contact+Vec3.up())
|
||||||
|
#jump=Vec3(rotAvatarToPhys.xform(jump))
|
||||||
|
jump.normalize()
|
||||||
|
jump*=self.avatarControlJumpForce
|
||||||
|
physObject.addImpulse(Vec3(jump))
|
||||||
|
else:
|
||||||
|
physObject.setVelocity(Vec3(0.0))
|
||||||
|
self.__vel.set(0.0, 0.0, 0.0)
|
||||||
|
doPhysics=0
|
||||||
|
if contact!=self.__old_contact:
|
||||||
|
# We must copy the vector to preserve it:
|
||||||
|
self.__old_contact=Vec3(contact)
|
||||||
|
#print "doPhysics", doPhysics
|
||||||
|
#print "contact", contact
|
||||||
|
if doPhysics:
|
||||||
|
self.phys.doPhysics(dt)
|
||||||
|
# Check to see if we're moving at all:
|
||||||
|
if self.__speed or self.__slideSpeed or self.__rotationSpeed:
|
||||||
|
distance = dt * self.__speed
|
||||||
|
slideDistance = dt * self.__slideSpeed
|
||||||
|
rotation = dt * self.__rotationSpeed
|
||||||
|
|
||||||
|
#debugTempH=self.avatarNodePath.getH()
|
||||||
|
assert self.avatarNodePath.getHpr().almostEqual(physObject.getOrientation().getHpr(), 0.0001)
|
||||||
|
assert self.avatarNodePath.getPos().almostEqual(physObject.getPosition(), 0.0001)
|
||||||
|
|
||||||
|
# update pos:
|
||||||
|
# Take a step in the direction of our previous heading.
|
||||||
|
self.__vel=Vec3(Vec3.forward() * distance +
|
||||||
|
Vec3.right() * slideDistance)
|
||||||
|
# rotMat is the rotation matrix corresponding to
|
||||||
|
# our previous heading.
|
||||||
|
rotMat=Mat3.rotateMatNormaxis(self.avatarNodePath.getH(), Vec3.up())
|
||||||
|
step=rotMat.xform(self.__vel)
|
||||||
|
physObject.setPosition(Point3(
|
||||||
|
physObject.getPosition()+step))
|
||||||
|
# update hpr:
|
||||||
|
o=physObject.getOrientation()
|
||||||
|
r=LOrientationf()
|
||||||
|
r.setHpr(Vec3(rotation, 0.0, 0.0))
|
||||||
|
physObject.setOrientation(o*r)
|
||||||
|
# sync the change:
|
||||||
|
self.actorNode.updateTransform()
|
||||||
|
|
||||||
|
assert self.avatarNodePath.getHpr().almostEqual(physObject.getOrientation().getHpr(), 0.0001)
|
||||||
|
assert self.avatarNodePath.getPos().almostEqual(physObject.getPosition(), 0.0001)
|
||||||
|
#assert self.avatarNodePath.getH()==debugTempH-rotation
|
||||||
|
messenger.send("avatarMoving")
|
||||||
|
else:
|
||||||
|
self.__vel.set(0.0, 0.0, 0.0)
|
||||||
|
# Clear the contact vector so we can tell if we contact something next frame:
|
||||||
|
self.actorNode.setContactVector(Vec3.zero())
|
||||||
|
return Task.cont
|
||||||
|
|
||||||
def resetPhys(self):
|
def resetPhys(self):
|
||||||
assert(self.debugPrint("resetPhys()"))
|
assert(self.debugPrint("resetPhys()"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user