コード例 #1
0
ファイル: ModPlayerAI.py プロジェクト: tsp-team/ttsp-src
 def setView(self, x, y, z, h, p, r):
     self.viewOrigin = Vec3(x, y, z)
     self.viewAngles = Vec3(h, p, r)
     quat = Quat()
     quat.setHpr(self.viewAngles)
     self.viewAngleVectors = [
         quat.getRight(), quat.getForward(),
         quat.getUp()
     ]
コード例 #2
0
def getUpHPR(hpr):
    q = Quat()
    q.setHpr(VBase3(math.degrees(hpr.h), math.degrees(hpr.p), math.degrees(hpr.r)))
    v = q.getUp()
    return SP3(v.x, v.y, v.z)
コード例 #3
0
def generate_roads(models, terrain, map, json_out):
    numroads = 0
    for center in progress.bar(map.centers.values(),
                               label='Generating roads... '):
        road_edges = [
            e for e in center.edges
            if e.is_road and e.corner0 is not None and e.corner1 is not None
        ]
        if len(road_edges) != 2:
            continue

        e1, e2 = road_edges
        e1_0 = numpy.array(
            [e1.corner0.x, e1.corner0.y, e1.corner0.elevation * Z_SCALE],
            dtype=numpy.float32)
        e1_1 = numpy.array(
            [e1.corner1.x, e1.corner1.y, e1.corner1.elevation * Z_SCALE],
            dtype=numpy.float32)
        e2_0 = numpy.array(
            [e2.corner0.x, e2.corner0.y, e2.corner0.elevation * Z_SCALE],
            dtype=numpy.float32)
        e2_1 = numpy.array(
            [e2.corner1.x, e2.corner1.y, e2.corner1.elevation * Z_SCALE],
            dtype=numpy.float32)

        region_center = numpy.array(
            [center.x, center.y, center.elevation * Z_SCALE])

        for end1, edge1, edge2 in [(region_center, e1_0, e1_1),
                                   (region_center, e2_0, e2_1)]:
            end2 = v3mid(edge1, edge2)

            midpt = v3mid(end1, end2)
            midpt = scene.mapgen_coords_to_sirikata(midpt, terrain)

            kata_pt1 = scene.mapgen_coords_to_sirikata(end1, terrain)
            kata_pt2 = scene.mapgen_coords_to_sirikata(end2, terrain)

            scale = v3dist(kata_pt1, kata_pt2) / 2

            m = scene.SceneModel(ROAD_PATH,
                                 x=float(midpt[0]),
                                 y=float(midpt[1]),
                                 z=float(midpt[2]),
                                 scale=scale,
                                 model_type='road')

            kataboundmin, kataboundmax = scene.sirikata_bounds(m.boundsInfo)
            scenemin = kataboundmin * scale + midpt
            scenemax = kataboundmax * scale + midpt
            xmid = (scenemax[0] - scenemin[0]) / 2.0 + scenemin[0]
            road_edge1 = numpy.array([xmid, scenemin[1], scenemin[2]],
                                     dtype=numpy.float32)
            road_edge2 = numpy.array([xmid, scenemax[1], scenemin[2]],
                                     dtype=numpy.float32)

            midv3 = Vec3(midpt[0], midpt[1], midpt[2])
            src = Vec3(road_edge2[0], road_edge2[1], road_edge2[2])
            src -= midv3
            src_copy = Vec3(src)
            target = Vec3(kata_pt1[0], kata_pt1[1], kata_pt1[2])
            target -= midv3
            cross = src.cross(target)
            w = math.sqrt(
                src.lengthSquared() * target.lengthSquared()) + src.dot(target)
            q = Quat(w, cross)
            q.normalize()

            orig_up = q.getUp()
            orig_up.normalize()

            edge1_kata = scene.mapgen_coords_to_sirikata(edge1, terrain)
            edge2_kata = scene.mapgen_coords_to_sirikata(edge2, terrain)
            new_up = normal_vector(kata_pt1, edge1_kata, edge2_kata)
            new_up = Vec3(new_up[0], new_up[1], new_up[2])
            rotate_about = orig_up.cross(new_up)
            rotate_about.normalize()
            angle_between = orig_up.angleDeg(new_up)
            r = Quat()
            r.setFromAxisAngle(angle_between, rotate_about)
            r.normalize()
            q *= r
            q.normalize()

            m.orient_x = q.getI()
            m.orient_y = q.getJ()
            m.orient_z = q.getK()
            m.orient_w = q.getR()

            numroads += 1
            json_out.append(m.to_json())

    print 'Generated (%d) road objects' % numroads
コード例 #4
0
    def drawFern(self, LOD, pos, quat, drawResourcesFactory, scale=1.0):
        scalar = random.random()
        scale *= scalar

        if scale < .3: return

        count = int((scalar**.7) * 12)

        if scale < .8:
            if LOD == self.lowLOD: return
        else:
            if LOD == self.midLOD: return

        leafResources = drawResourcesFactory.getDrawResources(
            self.leafDataIndex[LOD])
        leafTri = leafResources.getGeomTriangles()
        vertexWriter = leafResources.getWriter("vertex")
        normalWriter = leafResources.getWriter("normal")

        if self.leafTexture:
            texcoordWriter = leafResources.getWriter("texcoord")

        scale *= self.scalar * 3

        q2 = Quat()
        q3 = Quat()

        for i in xrange(count):
            p = (random.random()**2) * 60 + 20
            h = random.random() * 360
            q2.setHpr((h, p, 0))
            q3.setHpr((h, p - 20 - p / 4, 0))

            length1 = scale * 4
            length2 = scale * 3

            f = q2.getForward() * length1
            r = q2.getRight() * scale * .5
            f2 = q3.getForward() * length2 + f
            norm0 = q2.getUp()
            norm2 = q3.getUp()
            norm1 = norm0 + norm2
            norm1.normalize()

            for x in range(2):
                leafRow = vertexWriter.getWriteRow()

                vertexWriter.addData3f(pos)
                vertexWriter.addData3f(pos + f + r)
                vertexWriter.addData3f(pos + f - r)
                vertexWriter.addData3f(pos + f2)

                if self.leafTexture:
                    texcoordWriter.addData2f(0, 0)
                    texcoordWriter.addData2f(0, 1)
                    texcoordWriter.addData2f(1, 0)
                    texcoordWriter.addData2f(1, 1)

                if x == 1:
                    # back sides
                    norm0 = -norm0
                    norm1 = -norm1
                    norm2 = -norm2
                    leafTri.addVertices(leafRow + 1, leafRow, leafRow + 2)
                    leafTri.addVertices(leafRow + 3, leafRow + 1, leafRow + 2)
                else:
                    leafTri.addVertices(leafRow, leafRow + 1, leafRow + 2)
                    leafTri.addVertices(leafRow + 1, leafRow + 3, leafRow + 2)

                normalWriter.addData3f(norm0)
                normalWriter.addData3f(norm1)
                normalWriter.addData3f(norm1)
                normalWriter.addData3f(norm2)
コード例 #5
0
ファイル: SHPR.py プロジェクト: MillerRidgeway/ReactivePanda
def getUpHPR(hpr):
    q = Quat()
    q.setHpr(VBase3(math.degrees(hpr.h), math.degrees(hpr.p),
                math.degrees(hpr.r)))
    v = q.getUp()
    return SP3(v.x, v.y, v.z)
コード例 #6
0
 def drawFern(self,LOD,pos,quat,drawResourcesFactory,scale=1.0):
     scalar=random.random()
     scale*=scalar
     
     if scale<.3: return
     
     count=int((scalar**.7)*12)
     
     if scale<.8:
         if LOD==self.lowLOD: return
     else:
         if LOD==self.midLOD: return
     
     
     leafResources=drawResourcesFactory.getDrawResources(self.leafDataIndex[LOD])
     leafTri=leafResources.getGeomTriangles()
     vertexWriter=leafResources.getWriter("vertex")
     normalWriter=leafResources.getWriter("normal")
     
     if self.leafTexture:
         texcoordWriter = leafResources.getWriter("texcoord")
     
     
     
     scale*=self.scalar*3
     
     q2=Quat()
     q3=Quat()
     
     for i in xrange(count):
         p=(random.random()**2)*60+20
         h=random.random()*360
         q2.setHpr((h,p,0))
         q3.setHpr((h,p-20-p/4,0))
         
         length1=scale*4
         length2=scale*3
         
         f=q2.getForward()*length1
         r=q2.getRight()*scale*.5
         f2=q3.getForward()*length2+f
         norm0=q2.getUp()
         norm2=q3.getUp()
         norm1=norm0+norm2
         norm1.normalize()
         
         for x in range(2):
             leafRow = vertexWriter.getWriteRow()
         
             vertexWriter.addData3f(pos)
             vertexWriter.addData3f(pos+f+r)
             vertexWriter.addData3f(pos+f-r)
             vertexWriter.addData3f(pos+f2)
             
             
             if self.leafTexture:
                 texcoordWriter.addData2f(0,0)
                 texcoordWriter.addData2f(0,1)
                 texcoordWriter.addData2f(1,0)
                 texcoordWriter.addData2f(1,1)
         
             if x==1:
                 # back sides
                 norm0=-norm0
                 norm1=-norm1
                 norm2=-norm2
                 leafTri.addVertices(leafRow+1,leafRow,leafRow+2)
                 leafTri.addVertices(leafRow+3,leafRow+1,leafRow+2)
             else:
                 leafTri.addVertices(leafRow,leafRow+1,leafRow+2)
                 leafTri.addVertices(leafRow+1,leafRow+3,leafRow+2)
                 
             normalWriter.addData3f(norm0)
             normalWriter.addData3f(norm1) 
             normalWriter.addData3f(norm1) 
             normalWriter.addData3f(norm2)
コード例 #7
0
def generate_roads(models, terrain, map, json_out):
    numroads = 0
    for center in progress.bar(map.centers.values(), label='Generating roads... '):
        road_edges = [e for e in center.edges if e.is_road and e.corner0 is not None and e.corner1 is not None]
        if len(road_edges) != 2:
            continue
        
        e1, e2 = road_edges
        e1_0 = numpy.array([e1.corner0.x, e1.corner0.y, e1.corner0.elevation * Z_SCALE], dtype=numpy.float32)
        e1_1 = numpy.array([e1.corner1.x, e1.corner1.y, e1.corner1.elevation * Z_SCALE], dtype=numpy.float32)
        e2_0 = numpy.array([e2.corner0.x, e2.corner0.y, e2.corner0.elevation * Z_SCALE], dtype=numpy.float32)
        e2_1 = numpy.array([e2.corner1.x, e2.corner1.y, e2.corner1.elevation * Z_SCALE], dtype=numpy.float32)
        
        region_center = numpy.array([center.x, center.y, center.elevation * Z_SCALE])
        
        for end1, edge1, edge2 in [(region_center, e1_0, e1_1), (region_center, e2_0, e2_1)]:
            end2 = v3mid(edge1, edge2)
            
            midpt = v3mid(end1, end2)
            midpt = scene.mapgen_coords_to_sirikata(midpt, terrain)
            
            kata_pt1 = scene.mapgen_coords_to_sirikata(end1, terrain)
            kata_pt2 = scene.mapgen_coords_to_sirikata(end2, terrain)
            
            scale = v3dist(kata_pt1, kata_pt2) / 2
            
            m = scene.SceneModel(ROAD_PATH,
                           x=float(midpt[0]),
                           y=float(midpt[1]),
                           z=float(midpt[2]),
                           scale=scale,
                           model_type='road')
            
            kataboundmin, kataboundmax = scene.sirikata_bounds(m.boundsInfo)
            scenemin = kataboundmin * scale + midpt
            scenemax = kataboundmax * scale + midpt
            xmid = (scenemax[0] - scenemin[0]) / 2.0 + scenemin[0]
            road_edge1 = numpy.array([xmid, scenemin[1], scenemin[2]], dtype=numpy.float32)
            road_edge2 = numpy.array([xmid, scenemax[1], scenemin[2]], dtype=numpy.float32)
            
            midv3 = Vec3(midpt[0], midpt[1], midpt[2])
            src = Vec3(road_edge2[0], road_edge2[1], road_edge2[2])
            src -= midv3
            src_copy = Vec3(src)
            target = Vec3(kata_pt1[0], kata_pt1[1], kata_pt1[2])
            target -= midv3
            cross = src.cross(target)
            w = math.sqrt(src.lengthSquared() * target.lengthSquared()) + src.dot(target)
            q = Quat(w, cross)
            q.normalize()
            
            orig_up = q.getUp()
            orig_up.normalize()
            
            edge1_kata = scene.mapgen_coords_to_sirikata(edge1, terrain)
            edge2_kata = scene.mapgen_coords_to_sirikata(edge2, terrain)
            new_up = normal_vector(kata_pt1, edge1_kata, edge2_kata)
            new_up = Vec3(new_up[0], new_up[1], new_up[2])
            rotate_about = orig_up.cross(new_up)
            rotate_about.normalize()
            angle_between = orig_up.angleDeg(new_up)
            r = Quat()
            r.setFromAxisAngle(angle_between, rotate_about)
            r.normalize()
            q *= r
            q.normalize()
            
            m.orient_x = q.getI()
            m.orient_y = q.getJ()
            m.orient_z = q.getK()
            m.orient_w = q.getR()
            
            numroads += 1
            json_out.append(m.to_json())
    
    print 'Generated (%d) road objects' % numroads