Пример #1
0
 def lerpECSLPos(self):
     self.remoteVel = vector3(self.statusData.vel[0], self.statusData.vel[1], self.statusData.vel[2])
     self.remotePos = vector3(self.statusData.pos[0], self.statusData.pos[1], self.statusData.pos[2])
     self.nextRemotePos = self.remotePos + (self.remoteVel * self.latency)
     self.nextPos = self.ent.pos + (self.ent.velocity * self.latency)
     self.diffPos = self.nextPos - self.nextRemotePos
     self.diffPosFrac = self.diffPos/self.nSteps
Пример #2
0
    def multiPlayerNetTest(self, numSpeedBoats):
        spawnCarrier = True

        if spawnCarrier:
            carrier = self.engine.entMgr.createEntity(self.engine.entMgr.createHandle(), boat.CVN68, additionalAspects = self.additionalAspects, playerInfo = entMgr.Player(entMgr.Side.BLUE, 0))
            carrier.pos.x = 5
            carrier.pos.z = 12
            carrier.yaw = mathlib.halfpi
            desiredState = StoppedAtPosition(vector3(0, 0, -5000))
            cmd = command.MoveTo(self.engine, desiredState, desiredSpeed=knots(10))
            #carrier.squad.strategicData.commands = [cmd]
            carrier.squad.SquadAI.commands = [cmd]

        startPositionCenters        = [vector3(2000,0,-1000), vector3(2000,0,1000)]
        targetOffsets               = [vector3(50,0,150)]#, vector3(-50,0,150)]
        kStartPosSize               = 600
        kApproachRadiusSizeMinMax   = (300, 500)
        for i in range(numSpeedBoats):
            startPosCenter = startPositionCenters[i % len(startPositionCenters)]
            offset = mathlib.randomVectorSquare(kStartPosSize)
            startPos = startPosCenter + offset

            smallBoat = self.engine.entMgr.createEntity(self.engine.entMgr.createHandle(), boat.SPEEDBOAT, additionalAspects = self.additionalAspects, playerInfo = entMgr.Player(entMgr.Side.RED, 1))
            smallBoat.pos.x = startPos.x
            smallBoat.pos.z = startPos.z
            smallBoat.yaw = mathlib.pi
            assert carrier

            #offset = targetOffsets[i % len(targetOffsets)]
            offset = mathlib.randomVectorCircular(*kApproachRadiusSizeMinMax)
            desiredState = MaintainingRelativeToEnt(carrier, offset)
            cmd = command.MoveTo(self.engine, desiredState)
            smallBoat.squad.SquadAI.commands = [cmd]
Пример #3
0
 def setupAvoidanceTest3(self):
     self.createObstactleCourseEntities(5)
     for i in range(3):
         ent = self.engine.entMgr.createEntity(self.engine.entMgr.createHandle(), boat.DDG51, additionalAspects = self.additionalAspects)
         ent.pos = mathlib.randomVectorSquare(500) + vector3(0, 0, 500)
         #ent.yaw = random.uniform(0, mathlib.twopi)
         ent.yaw = math.radians(90)
         desiredState = StoppedAtPosition(vector3(0, 0, -2000))
         cmd = command.MoveTo(self.engine, desiredState)
         ent.squad.SquadAI.commands = [cmd]
Пример #4
0
    def __init__(self, engine):
        """Constructor"""
        System.__init__(self, engine)
        ogre.FrameListener.__init__(self)
        ogre.WindowEventListener.__init__(self)
        OIS.KeyListener.__init__(self)
        OIS.MouseListener.__init__(self)
        OIS.JoyStickListener.__init__(self)

        self.handlers = [dict() for x in range(InputEvent.NUM)]
        self.mouse_handlers = [dict() for x in range(MouseEvent.NUM)]
        self.joy_handlers = [dict() for x in range(JoyEvent.NUM)]
        self.key_states = {}
        self.keys_down = list()
        self.mouse_buttons_down = {}
        self.mouse_down_pos = {}
        self.mouse_down_over = {}
        self.mouse_down_modifiers = {}
        self.input_locks = {}
        for mb in MouseButton.LIST:
            self.mouse_buttons_down[mb] = False
            self.mouse_down_pos[mb] = None
            self.mouse_down_over[mb] = None
            self.mouse_down_modifiers[mb] = [False for x in range(Modifier.NUM)]
            self.input_locks[mb] = InputLock()
        self.mouse_state = None

        #box selection
        #self.selection_dd_context = self.engine.debugDrawSystem.getContext()
        #self.boxSelection = None
        #self.maintainDDContext = self.engine.debugDrawSystem.getContext()
        self.translation_to_apply = vector3(0,0,0)

        self.translation_to_apply_time_left = 0
Пример #5
0
    def tick(self, dtime):
        self.ddContext.clear()        
        if self.ent.isSelected:
            if self.ent.UnitAI.state == self.ent.UnitAI.State.MANUAL_CONTROL:

                if self.engine.inputSystem.joystick:
                    joyState = self.gamepad.getJoyStickState()
                    if joyState.mAxes[JoyAxes.LEFT_LEFTRIGHT].abs > 10000: #right
                        self.desiredHeading = self.turnRight(self.desiredHeading, dtime)
                    if joyState.mAxes[JoyAxes.LEFT_LEFTRIGHT].abs < -10000: #left
                        self.desiredHeading = self.turnLeft(self.desiredHeading, dtime)
                    if joyState.mAxes[JoyAxes.LEFT_UPDOWN].abs > 10000:  #slower
                        self.desiredSpeed = self.slowDown(self.desiredSpeed, self.ent.maxSpeed)
                    if joyState.mAxes[JoyAxes.LEFT_UPDOWN].abs < -10000:   #faster
                        self.desiredSpeed = self.speedUp(self.desiredSpeed, self.ent.maxSpeed)

                # in any case you can use keyboard arrow control

                if self.keyboard.isKeyDown(OIS.KC_LEFT): 
                    self.desiredHeading = self.turnLeft(self.desiredHeading, dtime)
                if self.keyboard.isKeyDown(OIS.KC_RIGHT): 
                    self.desiredHeading = self.turnRight(self.desiredHeading, dtime)
                if self.keyboard.isKeyDown(OIS.KC_UP): 
                    self.desiredSpeed = self.speedUp(self.desiredSpeed, self.ent.maxSpeed)
                if self.keyboard.isKeyDown(OIS.KC_DOWN): 
                    self.desiredSpeed = self.slowDown(self.desiredSpeed, self.ent.maxSpeed)

                if self.timer.check(dtime):
                    v = vector3(self.ent.avoidanceSize.x/2.0 *  self.desiredSpeed, 0, 0)
                    sv = mathlib.yawwedVector(v, self.ent.yaw)
                    offset = mathlib.yawwedVector(v, self.desiredHeading)
                    self.engine.debugDrawSystem.drawRay(self.ddContext, self.ent.pos, offset, color = colors.BLUE)
Пример #6
0
    def __init__(self, engine):
        mgr.System.__init__(self, engine)
        ogre.FrameListener.__init__(self)
        ogre.WindowEventListener.__init__(self)
        OIS.KeyListener.__init__(self)
        OIS.MouseListener.__init__(self)
        OIS.JoyStickListener.__init__(self)

        self.handlers = [dict() for x in range(InputEvent.NUM)]
        self.mouseHandlers = [dict() for x in range(MouseEvent.NUM)]
        self.joyHandlers = [dict() for x in range(JoyEvent.NUM)]
        self.keyStates = {}
        self.mouseButtonsDown = {}
        self.mouseDownPos = {}
        self.mouseDownOver = {}
        self.mouseDownModifiers = {}
        self.inputLocks = {}
        for mb in MouseButton.LIST:
            self.mouseButtonsDown[mb] = False
            self.mouseDownPos[mb] = None
            self.mouseDownOver[mb] = None
            self.mouseDownModifiers[mb] = [False for x in range(Modifier.NUM)]
            self.inputLocks[mb] = InputLock()

        self.ms = None

        #box selection
        self.selectionDDContext = self.engine.debugDrawSystem.getContext()
        self.boxSelection = None
        self.maintainDDContext = self.engine.debugDrawSystem.getContext()
        self.translationToApply = vector3(0,0,0)
        self.translationToApplyTimeLeft = 0
Пример #7
0
    def init(self):
        self.ent.squad = None
        self.destination = None

        self.ddContextLong = self.engine.debugDrawSystem.getContext()

        self._commands = []
        self.updateTimer = timer.Timer(self.updateFrequency, fireFirstCheck=True)

        self.cent = cent.CEnt(self.ent.maxSpeed, 
                self.ent.maxSpeed * -.5, 
                self.ent.accelSpeed, 
                self.ent.rotationalSpeed, 
                self.ent.avoidanceSize.x, 
                self.ent.avoidanceSize.z,
                self.ent.collisionLookAheadTime,
                self.ent.maxDistanceForFullStop,
                self.ent.minDistanceForFullStop,
                self.ent.crampDistance,
                self.ent.collisionClass
        )

        self.ent.desiredHeading = 0
        self.ent.desiredSpeed = 0
        self.ent.speed = 0
        self.ent.velocity = vector3(0,0,0)
        #self.helmDesiredSpeed   = 0
        #self.helmDesiredHeading = 0

        self.ent.uiDesiredSpeed = kCEntInvalidFloat

        self.ddContext = self.engine.debugDrawSystem.getContext()
        self.updateCounter = 0
        self.state = self.State.AI
        self.stopAtDestination = True
Пример #8
0
def randomVectorCircular(minRadius, maxRadius):
    import random
    import vector

    r = random.uniform(minRadius, maxRadius)
    t = random.uniform(0, twopi)
    return vector.vector3(r * math.cos(t), 0, r * math.sin(t))
Пример #9
0
def randomVectorSquare(maxRadius):
    import random
    import vector

    x = random.uniform(-maxRadius, maxRadius)
    z = random.uniform(-maxRadius, maxRadius)
    return vector.vector3(x, 0, z)
Пример #10
0
    def init_engine(self):
        """Load camera data and setup the camera"""
        try:
            f = open(self.filename, 'r')
            self.data = yaml.load(f)
            f.close()
        except IOError:
            self.data = CameraData()
            self.save_data()
        scene_manager = self.engine.graphics_system.scene_manager
        self.camera = scene_manager.createCamera("PlayerCamera")
        self.camera.nearClipDistance = 5
        self.camera.setFarClipDistance(99999*6)

        self.camera_node = scene_manager.getRootSceneNode().createChildSceneNode("CamYawNode", (0, 100, 500))
        self.camera_pitch_node = self.camera_node.createChildSceneNode("CameraPitchNode")
        self.camera_pitch_node.attachObject(self.camera)

        self.fps_camera_node = scene_manager.getRootSceneNode().createChildSceneNode("FPSCamYawNode")
        self.fps_camera_pitch_node = self.fps_camera_node.createChildSceneNode("FPSCamPitchNode")

        self.load_pos1()
        self.is_data_dirty = False
        self.using_fps_camera = False
        self.height = 100

        self.wvp = self.camera.getProjectionMatrix() * self.camera.getViewMatrix()
#        self.dd_context = self.engine.debug_draw_system.get_context()
        self.mouse_pos_world = vector3(0, 0, 0)
        self.camera_center_pos = None
Пример #11
0
def lineCollision(p1, p2, p3, p4):
    from vector import vector3

    ua, ub = lineCollisionBase(p1, p2, p3, p4)
    px = p1.x + ua * (p2.x - p1.x)
    pz = p1.z + ua * (p2.z - p1.z)
    return vector3(px, 0.0, pz)
Пример #12
0
    def attachCamera(self):
        if self.engine.selectionSystem.selectedEnts:
            self.camera.parentSceneNode.detachObject(self.camera)
            self.fpsCameraNode.parentSceneNode.removeChild(self.fpsCameraNode)
            self.fpsCameraPitchNode.attachObject(self.camera)

            renderAspect = self.engine.selectionSystem.primaryEnt.findAspect(Renderable)
            renderAspect._node.addChild(self.fpsCameraNode)
            self.fpsCameraNode.setPosition(vector3(-self.engine.selectionSystem.primaryEnt.length, self.engine.selectionSystem.primaryEnt.height, 0))

            self.fpsCameraNode.resetOrientation()
            self.fpsCameraPitchNode.resetOrientation()

            self.fpsCameraPitchNode.lookAt(vector3(0,0,0), ogre.Node.TS_PARENT)
            self.fpsCameraNode.yaw(ogre.Degree(-90))
            self.usingFPSCamera = True
Пример #13
0
def lineSegmentCollision(p1, p2, p3, p4):
    from vector import vector3

    ua, ub = lineCollisionBase(p1, p2, p3, p4)
    if ua >= 0.0 and ua <= 1.0 and ub >= 0.0 and ub <= 1.0:
        px = p1.x + ua * (p2.x - p1.x)
        pz = p1.z + ua * (p2.z - p1.z)
        return vector3(px, 0.0, pz)
    else:
        return None
Пример #14
0
 def rawShipPosOrientation(self, unpkdMsg):
     '''Updates forced move pos and orientations
     '''
     for data in unpkdMsg.data:
         if data.id in self.engine.entMgr.entMap.keys():
             ent = self.engine.entMgr.entMap[data.id]
             ent.pos = vector3(data.pos[0], data.pos[1], data.pos[2])
             ent.yaw = data.yaw
             #ent.uiname = str(data.label)
     pass
Пример #15
0
    def setupAvoidanceTest2(self):
        """
        Lets do a basic cross between two ddgs moving towards each other
        """
        ent1 = self.engine.entMgr.createEntity(self.engine.entMgr.createHandle(), boat.DDG51, additionalAspects = self.additionalAspects)
        ent1.pos.x = 0
        ent1.yaw = -mathlib.halfpi
        ent1.pos.z = -1000 
        desiredState = StoppedAtPosition(vector3(0, 0, +1000))
        cmd = command.MoveTo(self.engine, desiredState)
        ent1.squad.SquadAI.commands = [cmd]

        ent2 = self.engine.entMgr.createEntity(self.engine.entMgr.createHandle(), boat.DDG51, additionalAspects = self.additionalAspects)
        ent2.pos.x = 0
        ent2.pos.z = +1000 
        ent2.yaw = mathlib.halfpi
        desiredState = StoppedAtPosition(vector3(0, 0, -1000))
        cmd = command.MoveTo(self.engine, desiredState)
        ent2.squad.SquadAI.commands = [cmd]
Пример #16
0
 def test(self):
     m1 = matrix33()
     m2 = matrix33()
     m1.rotateX(2.22)
     m2.rotateY(3.33)
     m = matrix33()
     m.mulMatrix(m1, m2)
     v = vector3()
     v.set(1, 1, 1)
     v = m * v
     print(v)
Пример #17
0
    def setupRightAngleAvoidanceTest(self):
        """
        The one case we could never get well with lagoon
        Two ddg's at right angles
        """
        ent1 = self.engine.entMgr.createEntity(self.engine.entMgr.createHandle(), boat.DDG51, additionalAspects = self.additionalAspects)
        ent1.pos.x = 0
        ent1.yaw = -mathlib.halfpi
        ent1.pos.z = -1000 
        desiredState = StoppedAtPosition(vector3(0, 0, +1000))
        cmd = command.MoveTo(self.engine, desiredState)
        ent1.squad.SquadAI.commands = [cmd]

        ent2 = self.engine.entMgr.createEntity(self.engine.entMgr.createHandle(), boat.DDG51, additionalAspects = self.additionalAspects)
        ent2.pos.x = -1000
        ent2.pos.z = 0 
        ent2.yaw = 0.0
        desiredState = StoppedAtPosition(vector3(1000, 0, 0))
        cmd = command.MoveTo(self.engine, desiredState)
        ent2.squad.SquadAI.commands = [cmd]
Пример #18
0
    def initNetworking(self, id, status):
        self.id = id
        self.statusData = status
        # for now --> this should go away as soon as Mike changes the 
        # rotational speed to be math.halfpi - rotationalSpeed in the Daemon
        self.lerpRot = self.lerpECSLRot
        self.lerpPos = self.lerpECSLPos

        self.remotePos = vector3(self.statusData.pos[0], self.statusData.pos[1], self.statusData.pos[2])
        self.ent.pos = self.remotePos
        import netMgr
        if netMgr.gMoveCameraToEntPos == self.ent and self.engine.cameraSystem.cameraCenterPos:
            self.engine.cameraSystem.lookAt(self.ent)
            netMgr.gMoveCameraToEntPos = None

        self.newPos  = self.ent.pos
        self.ent.yaw = self.statusData.yaw 
        self.remoteVel = vector3(self.statusData.vel[0], self.statusData.vel[1], self.statusData.vel[2])
        self.ent.speed = self.remoteVel.length()
        self.ent.desiredHeading, self.ent.desiredSpeed = (self.statusData.dh, self.statusData.ds)

        self.oldTime = 0
        self.latency = 0
        self.ent.updateQueue = deque(maxlen=LAG_LENGTH)

        self.netCommand  = None
        self.squelchCommand = None

        # let us create all local vars here
        self.dh, self.ds = (0.0, 0.0)

        # for interpolation
        self.nSteps        = 0
        self.nextRemotePos = None
        self.diffPos       = None
        self.diffPosFrac   = None
        self.remoteQuat    = None
        self.destOrie      = None
        self.srcOrie       = None
        self.rotFactor     = 0
        self.rotProgress   = 1.0
Пример #19
0
    def init(self):
        self.ent.ogreName = str(self.ent)
        self.ent.pos = vector3(0.0, 0.0, 0.0)
        self.ent.yaw = 0.0

        self._rootNode = self.engine.gfxSystem.sceneManager.getRootSceneNode().createChildSceneNode(self.ent.ogreName, self.ent.pos)

        gent = self.engine.gfxSystem.sceneManager.createEntity(self.ent.ogreName + '_0', self.ent.mesh)
        self._node = self._rootNode.createChildSceneNode(self.ent.ogreName + '_0', self.ent.pos)
        self._node.attachObject(gent)      

        if self.ent.lod1:
            gent1 = self.engine.gfxSystem.sceneManager.createEntity(self.ent.ogreName + '_1', self.ent.lod1[1])
            self._node1 = self._rootNode.createChildSceneNode(self.ent.ogreName + '_1', self.ent.pos)
            self._node1.attachObject(gent1)
            self._node1.translate(vector3(0, 1.00, 0))
            self._node1.setScale(vector3(48.0, 1, 48.0))
        if self.ent.lod2:
            gent2 = self.engine.gfxSystem.sceneManager.createEntity(self.ent.ogreName + '_2', self.ent.lod2[1])
            self._node2 = self._rootNode.createChildSceneNode(self.ent.ogreName + '_2', self.ent.pos)
            self._node2.attachObject(gent2)
            self._node2.translate(vector3(0, 10, 0))
            self._node2.setScale(vector3(96.0, 1, 96.0))
			
        if self.ent.selectable:
            self.selectionCircle = ThickCircle(self.ent.ogreName + '.selectionCircle', self.engine.gfxSystem.sceneManager, parentNode=self._rootNode, color=(1.0, 1.0, 0.0))
            self.mouseOverCircle = ThickCircle(self.ent.ogreName + '.mouseOverCircle', self.engine.gfxSystem.sceneManager, parentNode=self._rootNode, color=(1.0, 1.0, 1.0))
            self.updateOverlaySizes()
            self.selectionCircle.hide()
            self.mouseOverCircle.hide()

            self.prevSelectionState = None
            self.prevMouseOverState = None

        import timer
        self.updateOverlayTimer = timer.Timer(0.1, fireFirstCheck=True)
Пример #20
0
 def init(self):
     """Setup the entity with the graphics system"""
     self.entity.ogre_name = str(self.entity)
     if not self.entity.position:
         self.entity.position = vector3(0.0, 0.0, 0.0)
     self.entity.yaw = 0.0
     scene_manager = self.engine.graphics_system.scene_manager
     self._root_node = scene_manager.getRootSceneNode().createChildSceneNode(self.entity.ogre_name,
                                                                             self.entity.position)
     self._camera_node = self._root_node.createChildSceneNode((0, 0, 0))
     gent = scene_manager.createEntity(self.entity.ogre_name + '_0', self.entity.mesh)
     if self.entity.material:
         gent.setMaterialName("test/" + self.entity.material)
     if self.entity.size:
         scale = self.entity.size / 100.0
         self._root_node.scale((scale, scale, scale))
     self._root_node.attachObject(gent)
     self.entity.graphical_entity = gent
Пример #21
0
    def body(self, master):

        box = Frame(self)

        w = Button(box,
                   text="Y",
                   width=4,
                   command=lambda: self.apply(vector3(0.0, 1.0, 0.0)),
                   default=ACTIVE)
        w.grid(row=0, column=0)
        w = Button(box,
                   text="-Y",
                   width=4,
                   command=lambda: self.apply(vector3(0.0, -1.0, 0.0)),
                   default=ACTIVE)
        w.grid(row=1, column=0)

        w = Button(box,
                   text="-X",
                   width=4,
                   command=lambda: self.apply(vector3(-1.0, 0.0, 0.0)),
                   default=ACTIVE)
        w.grid(row=2, column=1)
        w = Button(box,
                   text="X",
                   width=4,
                   command=lambda: self.apply(vector3(1.0, 0.0, 0.0)))
        w.grid(row=2, column=2)

        w = Button(box,
                   text="Z",
                   width=4,
                   command=lambda: self.apply(vector3(0.0, 0.0, 1.0)),
                   default=ACTIVE)
        w.grid(row=0, column=2)
        w = Button(box,
                   text="-Z",
                   width=4,
                   command=lambda: self.apply(vector3(0.0, 0.0, -1.0)))
        w.grid(row=1, column=1)

        self.value_variable.set("1.0")
        self.value_element = Entry(box,
                                   textvariable=self.value_variable,
                                   width=4)
        self.value_element.grid(row=2, column=0)

        box.pack()

        self.bind("<Escape>", self.cancel)
Пример #22
0
    def init(self):
        self.emitterList = [0,0,0]

        #set wake attributes based on boat size(1=small,2=med,3=large)
        if self.ent.wakeSize == 1:
            self.wake = self.initWake(dimensions=(5,5), scalerRate=0.15, colorFaderAlpha=-0.06)
            self.midEmitter = Emitter(self.ent, ttl = 15, emissionRate = 50)
            self.midEmitter.setColorRange(startColorAlpha = (1, 1, 1, 0.5), endColorAlpha = (1, 1, 1, 0.8))
            '''            self.leftEmitter = Emitter(self.ent, ttl = 15, direction = vector3(-3, 0, -2))
            self.leftEmitter.setColorRange(startColorAlpha = (1, 1, 1, 0.3), endColorAlpha = (1, 1, 1, 0.8))
            self.rightEmitter = Emitter(self.ent, ttl = 15, direction = vector3(-3, 0, 2))
            self.rightEmitter.setColorRange(startColorAlpha = (1, 1, 1, 0.3), endColorAlpha = (1, 1, 1, 0.8))
            '''

        elif self.ent.wakeSize == 2:
            self.wake = self.initWake(dimensions = (18, 18), scalerRate = 0.5, colorFaderAlpha = -0.002)
            self.midEmitter = Emitter(self.ent, ttl = 40, emissionRate = 12, position = vector3(-self.ent.length/2.5, 0.5, 0))
            self.midEmitter.setColorRange(startColorAlpha = (1, 1, 1, 0.3), endColorAlpha = (1, 1, 1, 1.0))
            '''
            self.leftEmitter = Emitter(self.ent, ttl = 40, emissionRate = 12, direction = vector3(-5, 0, -2), 
                                       position = vector3(self.ent.length/3.0, 0.5, -self.ent.beam/3.0))
            self.leftEmitter.setColorRange(startColorAlpha = (1, 1, 1, 0.3), endColorAlpha = (1, 1, 1, 1.0))
            self.rightEmitter = Emitter(self.ent, ttl = 40, emissionRate = 12, direction = vector3(-5, 0, 2), 
                                        position = vector3(self.ent.length/3.0, 0.5, self.ent.beam/3.0))
            self.rightEmitter.setColorRange(startColorAlpha = (1, 1, 1, 0.3), endColorAlpha = (1, 1, 1, 1.0))
            '''
        elif self.ent.wakeSize == 3:
            self.wake = self.initWake(dimensions = (25, 25), scalerRate = 0.7, colorFaderAlpha = -0.0014)
            self.midEmitter = Emitter(self.ent, angle = ogre.Degree(4), ttl = 70, particleVelocity = (1, 5), emissionRate = 5, 
                                      position = vector3(-self.ent.length/2.5, 0.5, 0))
            self.midEmitter.setColorRange(startColorAlpha = (1, 1, 1, 0.3), endColorAlpha = (1, 1, 1, 1.0))
            '''
            self.leftEmitter = Emitter(self.ent, angle = ogre.Degree(4), ttl = 65, particleVelocity = (1, 5), emissionRate = 5, 
                                       direction = vector3(-5, 0, -2), position = vector3(self.ent.length/3.0, 0.5, -self.ent.beam/4.0))
            self.leftEmitter.setColorRange(startColorAlpha = (1, 1, 1, 0.3), endColorAlpha = (1, 1, 1, 1.0))

            self.rightEmitter = Emitter(self.ent, angle = ogre.Degree(4), ttl = 65, particleVelocity = (1, 5), emissionRate = 5, 
                                        direction = vector3(-5, 0, 2), position = vector3(self.ent.length/3.0, 0.5, self.ent.beam/4.0))
            self.rightEmitter.setColorRange(startColorAlpha = (1, 1, 1, 0.3), endColorAlpha = (1, 1, 1, 1.0))
            '''
        else:
            print "No wakes for this type of entity", str(self.ent)
Пример #23
0
    def initEngine(self):
        try:
            f = open(self.filename, 'r')
            self.data = yaml.load(f)
            f.close()
        except IOError:
            self.data = CameraData()
            self.saveData()

        self.camera = self.engine.gfxSystem.sceneManager.createCamera("PlayerCamera")
        #self.camera.position = (0, 10, 500)
        #self.camera.lookAt((0,0,0))
        self.camera.nearClipDistance = 5
        self.camera.setFarClipDistance(99999*6)
        self.engine.cameraSystem.camera = self.camera

        #----------------attach camera to node so we can move camera---------------------------
        self.cameraNode = self.engine.gfxSystem.sceneManager.getRootSceneNode().createChildSceneNode("CamYawNode", (0, 100, 500))
        self.cameraPitchNode = self.cameraNode.createChildSceneNode("CamPitchNode");
        self.cameraPitchNode.attachObject(self.camera)

        self.fpsCameraNode = self.engine.gfxSystem.sceneManager.getRootSceneNode().createChildSceneNode("FPSCamYawNode")
        self.fpsCameraPitchNode = self.fpsCameraNode.createChildSceneNode("FPSCamPitchNode");

        self.loadPos1()
        self.isDataDirty = False

        self.usingFPSCamera = False
        self.height = 100

        self.wvp = self.camera.getProjectionMatrix() * self.camera.getViewMatrix()
        self.ddContext = self.engine.debugDrawSystem.getContext()
        self.mousePosWorld = vector3(0,0,0)
        self.cameraCenterPos = None

        self.engine.inputSystem.registerHandler(inputSystem.InputEvent.KEY_PRESSED, OIS.KC_TAB, self.lookatNextEnt)
Пример #24
0
def ecslentVector(vsVec):
    z, x, y = vsVec
    return vector3(x, 0, -z)
Пример #25
0
 def __init__(self):
     self.loc1 = (pqPair(vector3(0,500,800), pitchYawRoll(0,35,0) ), pqPair(vector3(0,0,0), pitchYawRoll(-60,0,0)))
     self.loc2 = (pqPair(vector3(0,500,800), pitchYawRoll(0,35,0) ), pqPair(vector3(0,0,0), pitchYawRoll(-60,0,0)))
     self.loc3 = (pqPair(vector3(0,500,800), pitchYawRoll(0,35,0) ), pqPair(vector3(0,0,0), pitchYawRoll(-60,0,0)))
     self.loc4 = (pqPair(vector3(0,500,800), pitchYawRoll(0,35,0) ), pqPair(vector3(0,0,0), pitchYawRoll(-60,0,0)))
Пример #26
0
        mat.z = z
        mat.pos = pos
        return mat

    @classmethod
    def FromRotAndPos(cls, m, pos):
        mat = cls()
        mat.x = vector4.FromVector3(m.x)
        mat.y = vector4.FromVector3(m.y)
        mat.z = vector4.FromVector3(m.z)
        mat.pos = vector4.FromVector3(pos)
        mat.pos.v[3] = 1
        return mat


forward = vector3(7.10119629, -25.3019409, -23.1168213)
up = vector3(0.726603448, -0.341014385, 0.596453547)
pos = vector3(1, 2, 3)
m1 = matrix3.Identity()
print(m1)
mat = matrix3.MakeLookAt(forward, up)
print(mat)

#x4 = vector4.FromVector3(m1.x)
#y4 = vector4.FromVector3(m1.y)
#y4 = vector4.FromVector3(m1.z)
m4 = matrix4.FromRotAndPos(mat, pos)
print(m4)
inv = m4.inverse()
print(inv)
print(inv * m4)
Пример #27
0
def yawwedVector(vec, theta):
    from vector import vector3

    v = vector3(vec.x, vec.y, vec.z)
    return yawVector(v, theta)
Пример #28
0
    def tick(self, dtime):
        if self.commandsDirty or self.updateTimer.check(dtime):
            """
            Translate our desiredState into world coordinates, and let the low level c api do all the work
            """
            self.commandsDirty = False
            self.ddContextLong.clear()
            current = self.command
            if current is None:
                self.ent.hasDestination = False
                return

            elif type(current) == command.MoveTo:
                currentWP = current.desiredState.calcWorldPos(self.ent)
                if len(self.commands) > 1:
                    #we are an interimittent move - if we have a next point see if we rae hitting this one and then mvoe on
                    vecToGoal = self.ent.pos - currentWP
                    distanceToGoal = vecToGoal.length()
                    if distanceToGoal < self.ent.moveToReachedTolerance:
                        del self.commands[0]
                    self.stopAtDestination = False
                else:
                    self.stopAtDestination = True

                self.state = self.State.AI
                self.destination = currentWP

                if current.desiredSpeed is None:
                    self.navDesiredSpeed = self.ent.uiDesiredSpeed
                else:
                    self.navDesiredSpeed = current.desiredSpeed

                if type(current.desiredState) == desiredState.MaintainingRelativeToEnt:
                    self.cent.inRamMode = current.desiredState.offset.length() < 50.0
                    if self.ent.isSelected:
                        self.engine.debugDrawSystem.drawLine(self.ddContextLong, current.desiredState.ent.pos, currentWP)
                else:
                    self.cent.inRamMode = False

                if self.ent.isSelected:
                    p = self.ent.pos
                    for c in self._commands:
                        p2 = c.desiredState.calcWorldPos(self.ent)
                        self.engine.debugDrawSystem.drawLine(self.ddContextLong, p, p2)
                        p = p2
                    self.engine.debugDrawSystem.drawCircle(self.ddContextLong, self.destination, 100.0)
                    if self.cent.inRamMode:
                        import colors
                        self.engine.debugDrawSystem.drawCircle(self.ddContextLong, self.destination, 110.0, color=colors.RED)

            elif type(current) == command.Stop:
                self.state = self.State.STOP
                self.ent.hasDestination = False
                self.destination = None

            elif type(current) == command.NetSlave:
                self.state = self.State.NET_SLAVE
                self.ent.hasDestination = False
                self.destination = None

            elif type(current) == command.ManualControl:
                self.state = self.State.MANUAL_CONTROL
                self.ent.hasDestination = False
                self.destination = None

            else:
                raise Exception('Not Implemented %s' % current)

        if self.state == self.State.AI:
            self.cent.posX = self.ent.pos.x
            self.cent.posY = self.ent.pos.z
            self.cent.yaw  = self.ent.yaw

            #pass control data down to cent land
            if self.destination:
                self.cent.destinationX = self.destination.x
                self.cent.destinationY = self.destination.z
                self.cent.stopAtDestination = self.stopAtDestination
#####get the desired heading and speed
                self.desiredHeading = math.atan2((self.ent.pos.z- self.destination.z), -1*(self.ent.pos.x - self.destination.x))
                if(self.desiredHeading > math.pi):
                    self.desiredHeading -= 2*math.pi
                elif(self.desiredHeading < -(math.pi)):
                    self.desiredHeading += 2*math.pi
                self.cent.helmDesiredHeading = self.desiredHeading

                #get desired speed
                self.distance = pow((self.destination.x - self.ent.pos.x),2) + pow((self.destination.z - self.ent.pos.z),2)
                if(self.distance > 15000):
                    self.desiredSpeed = self.ent.maxSpeed
                else:
                    self.desiredSpeed = 0
                self.cent.helmDesiredSpeed = self.desiredSpeed


            self.cent.tick(dtime)

            self.ent.pos.x = self.cent.posX
            self.ent.pos.z = self.cent.posY
            self.ent.yaw = self.cent.yaw
            self.ent.speed = self.cent.speed
            self.ent.velocity = vector3(self.cent.velX, 0, self.cent.velY)

            #self.helmDesiredSpeed   = self.cent.helmDesiredSpeed   #To tell VShip
            #self.helmDesiredHeading = self.cent.helmDesiredHeading

            #take all my c debugging requests and pass them up to python debug drawer
            if self.ent.isSelected:
                if self.updateCounter != self.cent.updateCounter:
                    self.ddContext.clear()
                    self.updateCounter = self.cent.updateCounter
                    debugLines = self.cent.getDebugLines()
                    for cdebugline in self.cent.getDebugLines():
                        self.engine.debugDrawSystem.drawLine(self.ddContext,
                                                             vector3(cdebugline[0], 0, cdebugline[1]),
                                                             vector3(cdebugline[2], 0, cdebugline[3])
                        )
            else:
                self.ddContext.clear()

        elif self.state == self.State.MANUAL_CONTROL:
            
            self.cent.posX = self.ent.pos.x
            self.cent.posY = self.ent.pos.z
            self.cent.yaw  = self.ent.yaw
            
            self.cent.helmDesiredSpeed = self.controlAspect.desiredSpeed     # keyboard or joystick
            self.cent.helmDesiredHeading = self.controlAspect.desiredHeading

            self.cent.helmTick(dtime);

            self.ent.pos.x = self.cent.posX
            self.ent.pos.z = self.cent.posY
            self.ent.yaw = self.cent.yaw
            self.ent.speed = self.cent.speed            
            self.ent.velocity = vector3(self.cent.velX, 0, self.cent.velY)
            
        elif self.state == self.State.STOP:

            self.cent.posX = self.ent.pos.x
            self.cent.posY = self.ent.pos.z
            self.cent.yaw  = self.ent.yaw
            
            self.cent.helmDesiredSpeed   = 0.0
            self.cent.helmDesiredHeading = self.ent.yaw

            self.cent.helmTick(dtime);

            self.ent.pos.x = self.cent.posX
            self.ent.pos.z = self.cent.posY
            self.ent.yaw = self.cent.yaw
            self.ent.speed = self.cent.speed            
            self.ent.velocity = vector3(self.cent.velX, 0, self.cent.velY)


        else: #state == NET_SLAVE
            self.cent.posX = self.ent.pos.x
            self.cent.posY = self.ent.pos.z
            self.cent.yaw  = self.ent.yaw
            
            self.cent.helmDesiredSpeed = self.ent.desiredSpeed     # from network or keyboard or joystick
            self.cent.helmDesiredHeading = self.ent.desiredHeading
            #print "UnitAI: DS, DH: ", self.ent.desiredSpeed, self.ent.desiredHeading
            self.cent.helmTick(dtime);

            self.ent.pos.x = self.cent.posX
            self.ent.pos.z = self.cent.posY
            self.ent.yaw = self.cent.yaw
            self.ent.speed = self.cent.speed            

            self.ent.velocity = vector3(self.cent.velX, 0, self.cent.velY)
Пример #29
0
 def tick(self, dtime):
     posStride = 1000.0
     if self.waterNode:
         cameraPos = self.engine.cameraSystem.cameraNode.position
         waterPos = vector3(cameraPos.x - cameraPos.x % posStride, 0.0, cameraPos.z - cameraPos.z % posStride)
         self.waterNode.setPosition(waterPos)
Пример #30
0
 def load_level(self):
     logging.info("Setting up test scenario...")
     #self.setup_floor(50, 50)
     player = self.engine.entity_manager.create_entity(self.engine.entity_manager.create_handle(), Player, position=vector3(100, 100, 100))
     player.KinematicPhysics.attach_controls()
     player.ProjectileCreator.set_projectile(Projectile)
     player.ProjectileCreator.attach_controls()
     self.engine.entity_manager.create_entity(self.engine.entity_manager.create_handle(), Player, position=vector3(200, 200, 200))
     self.engine.camera_system.player = player
     logging.info("Test scenario setup!")
Пример #31
0
def randomVectorSquare(maxRadius):
    import random
    import vector
    x = random.uniform(-maxRadius, maxRadius)
    z = random.uniform(-maxRadius, maxRadius)
    return vector.vector3(x, 0, z)
Пример #32
0
 def __init__(self):
     self.v = [vector3(), vector3(), vector3()]
Пример #33
0
def randomVectorCircular(minRadius, maxRadius):
    import random
    import vector
    r = random.uniform(minRadius, maxRadius)
    t = random.uniform(0, twopi)
    return vector.vector3(r * math.cos(t), 0, r * math.sin(t))
Пример #34
0
 def pos(self):
     return vector3(self.posX, 0, self.posY)
Пример #35
0
 def mulVector3(self, v):
     r = vector3()
     r.x = v.dot3(self.v[0].x, self.v[1].x, self.v[2].x)
     r.y = v.dot3(self.v[0].y, self.v[1].y, self.v[2].y)
     r.z = v.dot3(self.v[0].z, self.v[1].z, self.v[2].z)
     return r
Пример #36
0
 def __init__(self, ent, angle = ogre.Degree(8), ttl = 9, particleVelocity = (1, 3), emissionRate = 90, direction = vector3(-1, 0, 0), position = vector3(0, -1, 0)):
     self.ent = ent
     self.emitter = self.ent.pSystem.addEmitter("Point")
     self.emitter.setAngle(angle)
     self.emitter.setTimeToLive(ttl)
     low, high = particleVelocity
     self.emitter.setParticleVelocity(low, high)
     self.emitter.setDirection(direction)
     self.emitter.setEmissionRate(emissionRate)
Пример #37
0
 def offset(self):
     return vector3(self.offsetX, 0, self.offsetY)