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))
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))
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
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
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
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
def kick(self, direction, intensity): directionNorm = normalize(direction) if self.isDynamic: self.velocity = directionNorm * intensity
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)
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)