当前位置: 首页>>代码示例>>Python>>正文


Python Vector.to_3d方法代码示例

本文整理汇总了Python中mathutils.Vector.to_3d方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.to_3d方法的具体用法?Python Vector.to_3d怎么用?Python Vector.to_3d使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mathutils.Vector的用法示例。


在下文中一共展示了Vector.to_3d方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: spawn_resource

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import to_3d [as 别名]
def spawn_resource(tiles, min_amount, max_amount):
    cont = bge.logic.getCurrentController()
    
    for i in range(0, random.randint(min_amount, max_amount)):
        tile = Vector(( random.randint(-128, 128), random.randint(-128, 128) ))
        
        # leave a clearing in the center of the map, but offset
        if (tile - Vector((0,-6))).length > 14:
            d = spawn_object(cont, "Large_clearance_detector", tile.to_3d())
            Detector(d, random.choice(tiles), i)
开发者ID:gandalf3,项目名称:The-Queen-s-Workers,代码行数:12,代码来源:main.py

示例2: draw_polygon_object

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import to_3d [as 别名]

#.........这里部分代码省略.........
            vert_i_global = 0
            for line in wire_lines:
                # glLineWidth(2.0)
                glEnable(GL_LINE_STIPPLE)
                glBegin(GL_LINES)
                glColor3f(wire_color[0], wire_color[1], wire_color[2])

                for vert_i, vert1 in enumerate(line):
                    if vert_i + 1 < len(line):
                        vert2 = line[vert_i + 1]
                    else:
                        continue

                    # SEPARATE PART TRANSFORMATIONS
                    if wire_transforms:
                        trans1 = trans2 = mat
                        for transformation in wire_transforms:
                            if vert_i_global in transformation[1]:
                                trans1 = trans1 * transformation[0]
                            if vert_i_global + 1 in transformation[1]:
                                trans2 = trans2 * transformation[0]
                        glVertex3f(*(trans1 * Vector(vert1)))
                        glVertex3f(*(trans2 * Vector(vert2)))
                    else:
                        glVertex3f(*(mat * Vector(vert1)))
                        glVertex3f(*(mat * Vector(vert2)))
                    vert_i_global += 1
                vert_i_global += 1
                glEnd()
                glDisable(GL_LINE_STIPPLE)
                # glLineWidth(1.0)
        else:
            for face in faces:
                # glLineWidth(2.0)
                glEnable(GL_LINE_STIPPLE)
                glBegin(GL_LINES)
                glColor3f(wire_color[0], wire_color[1], wire_color[2])
                for vert_i, vert1 in enumerate(face):
                    if vert_i + 1 == len(face):
                        vert2 = face[0]
                    else:
                        vert2 = face[vert_i + 1]
                    if face_transforms:
                        trans1 = mat
                        trans2 = mat
                        vec1 = Vector(vertices[vert1])
                        vec2 = Vector(vertices[vert2])
                        for transformation in face_transforms:
                            if vert1 in transformation[1]:
                                trans1 = trans1 * transformation[0]
                            if vert2 in transformation[1]:
                                trans2 = trans2 * transformation[0]
                        glVertex3f(*(trans1 * vec1))
                        glVertex3f(*(trans2 * vec2))
                    else:
                        glVertex3f(*(mat * Vector(vertices[vert1])))
                        glVertex3f(*(mat * Vector(vertices[vert2])))
                glEnd()
                glDisable(GL_LINE_STIPPLE)
                # glLineWidth(1.0)
    if 0:  # DEBUG: draw points from faces geometry
        glPointSize(3.0)
        glBegin(GL_POINTS)
        glColor3f(0.5, 0.5, 1)
        for vertex_i, vertex in enumerate(vertices):
            vec = Vector(vertex)
            if face_transforms:
                trans = mat
                for transformation in face_transforms:
                    if vertex_i in transformation[1]:
                        trans = trans * transformation[0]
                glVertex3f(*(trans * vec))
            else:
                glVertex3f(*(mat * vec.to_3d()))
        glEnd()
        glPointSize(1.0)
    if 0:  # DEBUG: draw points from lines geometry
        if wire_lines:
            glPointSize(3.0)
            glBegin(GL_POINTS)
            glColor3f(1, 0, 0.5)
            vert_i_global = 0
            for line in wire_lines:
                for vert_i, vertex in enumerate(line):
                    if vert_i + 1 < len(line):
                        vec = Vector(vertex)
                    else:
                        continue
                    if wire_transforms:
                        trans = mat
                        for transformation in wire_transforms:
                            if vert_i_global in transformation[1]:
                                trans = trans * transformation[0]
                        glVertex3f(*(trans * vec.to_3d()))
                    else:
                        glVertex3f(*(mat * vec.to_3d()))
                    vert_i_global += 1
                vert_i_global += 1
            glEnd()
            glPointSize(1.0)
开发者ID:miranbox,项目名称:BlenderTools,代码行数:104,代码来源:primitive.py

示例3: Ant

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import to_3d [as 别名]
class Ant(bge.types.BL_ArmatureObject):
    
    antlist = []
    
    def __init__(self, own):
        self["ant_init"] = True
        Ant.antlist.append(self)
        
        bge.logic.globalDict["pop"] = len(Ant.antlist)
        
        
        # Modes:
        
        # DROP: drop off self.carrying at an appropriate building
        # GOGET: go to self.collect
        # GOTO: go to self.target
        # GOBACK: go to 0,0
        
        self.mode = "GOTO"
        
        self.idle = True
        
        self.target = Vector((0, 0))

        self.collect = None
        # useful to store this in case self.collect becomes invalid due to being used up
        self.collect_category = None
        
        self.carrying = None
        self.carry_type = None
        self.carry_category = None
        
        self.destination = None
        
        self.vision_distance = 5
        self.stopping_margin = .5
        
        self.acceleration = .005
        self.max_speed = .1
        #self.max_turning_speed
        self.near_sens = self.sensors["Near"]
        
        self.zoffset = self.worldPosition.copy().z
        
        self.nearest_ant = 100
        
        self.speed = 0
        self.target_direction = Vector((0, -1, 0))
        self.direction = self.getAxisVect((0,-1,0))
        
        #self.wander_direction = Vector((.5,.5))
        
        self.currently_considering = 0
        
        self.ticks_since_last_meal = random.randint(0, 600)
        self.return_home_timer = None
    
    def eat(self):
        if self.ticks_since_last_meal > 900:
            if bge.logic.globalDict["food"] > 0:
                bge.logic.globalDict["food"] -= 1
                bge.logic.sendMessage("GUI")

                self.ticks_since_last_meal = 0
            else:
                # go without food
                self.ticks_since_last_meal = 0
                if random.random() < .3:
                    bge.logic.sendMessage("notify", "An ant starved!")
                    self.die()
                else:
                    bge.logic.sendMessage("notify", "An ant is hungry")

        self.ticks_since_last_meal += 1
        
    def die(self):
        if self.carrying is not None:
            self.carrying.endObject()
            self.carrying = None
            
        for o in self.children:
            o.endObject()
            
        Ant.antlist.remove(self)
        
        bge.logic.globalDict["pop"] = len(Ant.antlist)
        bge.logic.sendMessage("GUI")
        self.endObject()
        
    def towards_target(self):
        dist, vect, lvect = self.getVectTo(self.target.to_3d())
        
        vect.normalize()

        if dist < self.vision_distance:
            # apply braking force proportional to distance
            vect = vect - (vect * min((dist/-self.vision_distance) + 1/self.vision_distance + self.stopping_margin, 1))
            self.stopping_margin = min(self.stopping_margin +.01, 1)
        else:
            self.stopping_margin = .5
#.........这里部分代码省略.........
开发者ID:gandalf3,项目名称:The-Queen-s-Workers,代码行数:103,代码来源:ant.py


注:本文中的mathutils.Vector.to_3d方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。