Exemplo n.º 1
0
 def rotateAgent(self, rotation):
     #clamping
     if not self.isStunned:
         rotation = clampRotation(rotation, self.maxRot)
         self.rotation += rotation
         self.forward = normalize(dot(array([1, 0, 0]), rotMatrixFromYPR(self.rotation)))    
         self.right = normalize(dot(array([0, 1, 0]), rotMatrixFromYPR(self.rotation)))      
         self.up = normalize(cross(self.forward, self.right))
Exemplo n.º 2
0
 def rotateAgent(self, rotation):
     #clamping
     if not self.isStunned:
         rotation = clampRotation(rotation, self.maxRot)
         self.rotation += rotation
         self.forward = normalize(
             dot(array([1, 0, 0]), rotMatrixFromYPR(self.rotation)))
         self.right = normalize(
             dot(array([0, 1, 0]), rotMatrixFromYPR(self.rotation)))
         self.up = normalize(cross(self.forward, self.right))
Exemplo n.º 3
0
    def updatePhysics(self, world):
        if self.isDynamic:
            #move with velocity
            self.position += self.velocity * SimTime.fixedDeltaTime
#             print "Ballin to"+str(self.velocity * SimTime.fixedDeltaTime)
            self.velocity *= 0.99  

            #Handle collisions with world bounds
            if self.position[2] < -world.height:
                self.position[2] = -world.height + 0.1
                self.velocity = reflectVector(self.velocity, array([0, 0, 1]))
            if self.position[2] > world.height:
                self.position[2] = world.height - 0.1
                self.velocity = reflectVector(self.velocity, array([0, 0, -1]))
            if self.position[1] < -world.width:
                self.position[1] = -world.width + 0.1
                self.velocity = reflectVector(self.velocity, array([0, 1, 0]))
            if self.position[1] > world.width:
                self.position[1] = world.width - 0.1
                self.velocity = reflectVector(self.velocity, array([0, -1, 0]))
            if self.position[0] < -world.width:
                self.position[0] = -world.width + 0.1
                self.velocity = reflectVector(self.velocity, array([1, 0, 0]))
            if self.position[0] > world.width:
                self.position[0] = world.width - 0.1
                self.velocity = reflectVector(self.velocity, array([-1, 0, 0]))
            
            #collision of obstacles
            for obstacle in world.obstacles:
                nextPos = self.position + self.velocity
                if distBetween(nextPos, obstacle.position) < self.radius + obstacle.radius:
                    normal = normalize(nextPos - obstacle.position)
                    self.velocity = reflectVector(self.velocity, normal)
                    
            
            #stop when ball hits agents
            for agent in world.agents:
                nextPos = self.position + self.velocity
                if distBetween(nextPos, agent.position) < self.radius + agent.colRadius:
                    self.velocity = array([0, 0, 0])
                    
            #clamp ball speed
            mag = np.linalg.norm(self.velocity)
            if mag > 200:
                self.velocity = normalize(self.velocity) * 200
Exemplo n.º 4
0
    def updatePhysics(self, world):
        if self.isDynamic:
            # move with velocity
            self.position += self.velocity * SimTime.fixedDeltaTime
            #             print "Ballin to"+str(self.velocity * SimTime.fixedDeltaTime)
            self.velocity *= 0.99

            # Handle collisions with world bounds
            if self.position[2] < -world.height:
                self.position[2] = -world.height + 0.1
                self.velocity = reflectVector(self.velocity, array([0, 0, 1]))
            if self.position[2] > world.height:
                self.position[2] = world.height - 0.1
                self.velocity = reflectVector(self.velocity, array([0, 0, -1]))
            if self.position[1] < -world.width:
                self.position[1] = -world.width + 0.1
                self.velocity = reflectVector(self.velocity, array([0, 1, 0]))
            if self.position[1] > world.width:
                self.position[1] = world.width - 0.1
                self.velocity = reflectVector(self.velocity, array([0, -1, 0]))
            if self.position[0] < -world.width:
                self.position[0] = -world.width + 0.1
                self.velocity = reflectVector(self.velocity, array([1, 0, 0]))
            if self.position[0] > world.width:
                self.position[0] = world.width - 0.1
                self.velocity = reflectVector(self.velocity, array([-1, 0, 0]))

            # collision of obstacles
            for obstacle in world.obstacles:
                nextPos = self.position + self.velocity
                if distBetween(nextPos, obstacle.position) < self.radius + obstacle.radius:
                    normal = normalize(nextPos - obstacle.position)
                    self.velocity = reflectVector(self.velocity, normal)

            # stop when ball hits agents
            for agent in world.agents:
                nextPos = self.position + self.velocity
                if distBetween(nextPos, agent.position) < self.radius + agent.colRadius:
                    self.velocity = array([0, 0, 0])

            # clamp ball speed
            mag = np.linalg.norm(self.velocity)
            if mag > 200:
                self.velocity = normalize(self.velocity) * 200
Exemplo n.º 5
0
 def translateAgent(self, direction):
     #clamp the direction by normalizing
     if not self.isStunned:
         globaldirection = dot(direction, rotMatrixFromYPR(self.rotation))
         globaldirection = normalize(globaldirection) * self.maxMove
         self.position = self.position + globaldirection
Exemplo n.º 6
0
 def translateAgent(self, direction):
     #clamp the direction by normalizing
     if not self.isStunned:
         globaldirection = dot(direction, rotMatrixFromYPR(self.rotation))
         globaldirection = normalize(globaldirection) * self.maxMove
         self.position =self.position + globaldirection
Exemplo n.º 7
0
 def kick(self, direction, intensity):
     directionNorm = normalize(direction)
     if self.isDynamic:
         self.velocity = directionNorm * intensity
Exemplo n.º 8
0
 def moveBall(self, position, speed):
     #move the ball to specified position at the specified speed, speed is distance per frame  
     if not self.isDynamic:
         moveVector = position - self.position
         moveVector = normalize(moveVector)
         self.position += moveVector * float(speed)
Exemplo n.º 9
0
 def kick(self, direction, intensity):
     directionNorm = normalize(direction)
     if self.isDynamic:
         self.velocity = directionNorm * intensity
Exemplo n.º 10
0
 def moveBall(self, position, speed):
     # move the ball to specified position at the specified speed, speed is distance per frame
     if not self.isDynamic:
         moveVector = position - self.position
         moveVector = normalize(moveVector)
         self.position += moveVector * float(speed)