Пример #1
0
def getClosestAxis(normal):
    absNormal = Vec3(abs(normal.x), abs(normal.y), abs(normal.z))
    if absNormal.almostEqual(Vec3.unitX(), 0.5):
        return Vec3.unitX()
    elif absNormal.almostEqual(Vec3.unitY(), 0.5):
        return Vec3.unitY()
    else:
        return Vec3.unitZ()
Пример #2
0
    def fromPlaneAndRadius(plane, radius=32768):
        normal = plane.getNormal()
        dist = -plane.getW()

        # Find the major axis
        x = plane.getClosestAxisToNormal()
        up = Vec3.unitX() if x == Vec3.unitZ() else Vec3.unitZ()

        v = up.dot(normal)
        up = BSPUtils.extrude(up, -v, normal)
        up.normalize()

        org = normal * dist

        right = up.cross(normal)

        up = up * radius
        right = right * radius

        # Project a really big axis aligned box onto the plane
        verts = [
            org - right + up, org + right + up, org + right - up,
            org - right - up
        ]

        poly = Winding(verts, plane)

        return poly
Пример #3
0
    def __build_ocean_mesh(self):
        vdata = GeomVertexData('data', GeomVertexFormat.getV3n3c4t2(),
                               Geom.UHStatic)
        vertex = GeomVertexWriter(vdata, 'vertex')
        normal = GeomVertexWriter(vdata, 'normal')
        texcoord = GeomVertexWriter(vdata, 'texcoord')
        color = GeomVertexWriter(vdata, 'color')

        axes = [Vec3.unitX(), Vec3.unitY(), Vec3.unitZ()]
        face = 0

        for x in range(3):
            for s in [-1, 1]:
                for i in range(self.__n + 1):
                    for j in range(self.__n + 1):
                        a = (i * 1.0 / self.__n) * (pi / 2) - (pi / 4)
                        b = (j * 1.0 / self.__n) * (pi / 2) - (pi / 4)
                        xAxis = axes[(x + 3) % 3]
                        yAxis = axes[(x + 4) % 3]
                        zAxis = axes[(x + 5) % 3]
                        v = (xAxis * (-cos(a) * sin(b)) + yAxis *
                             (sin(a) * cos(b)) + zAxis * (cos(a) * cos(b))) * s
                        v.normalize()
                        normal.addData3f(v)
                        vertex.addData3f(v * self.__radius)
                        texcoord.addData2f(i * 1.0, j * 1.0)
                        color.addData4f(self.__ocean_color)
                face = face + 1
        prim = self.__heightmap_primitive()
        geom = Geom(vdata)
        geom.addPrimitive(prim)
        return geom
Пример #4
0
    def __init__(self):
        ShowBase.__init__(self)
        self.disableMouse()

        self.keyMap = {
            "up": False,
            "down": False,
            "right": False,
            "left": False,
            "sink": False,
            "rise": False
        }

        self.keymapping = zip(
            (",", "a", "e", "o", "lshift", "space"),
            #  ("w", "a", "s", "d", "lshift", "space"),
            ("up", "left", "right", "down", "sink", "rise"))
        for key, keyname in self.keymapping:
            self.accept(key, self.updateKeyMap, [keyname, True])
            self.accept(key + "-up", self.updateKeyMap, [keyname, False])
        self.accept('escape', sys.exit, [0])

        self.movementDirs = [("up", Vec3.unitY()), ("left", -Vec3.unitX()),
                             ("right", Vec3.unitX()), ("down", -Vec3.unitY())]

        self.plane = self.loader.loadModel("models/plane.bam")
        self.plane.reparentTo(self.render)
        self.cube = self.loader.loadModel("models/cube.bam")
        self.cube.reparentTo(self.render)

        self.cTrav = CollisionTraverser()

        self.camera.setPos(0, -20, 3)
        self.cube.setPos(0, 0, 1)
        self.camera.lookAt(self.cube)

        self.taskMgr.add(self.mouseWatchTask, "Mouse Watch Task")
        self.taskMgr.add(self.keyboardWatchTask, "Keyboard Watch Task")

        self.debugText = self.genLabelText("", 1)

        wp = WindowProperties()
        wp.setMouseMode(WindowProperties.M_relative)
        wp.setCursorHidden(True)
        self.win.requestProperties(wp)
Пример #5
0
    def getClosestAxisToNormal(self):
        # VHE Prioritizes the axes in order of X, Y, Z

        norm = self.getNormal()
        norm[0] = abs(norm[0])
        norm[1] = abs(norm[1])
        norm[2] = abs(norm[2])

        if norm.x >= norm.y and norm.x >= norm.z:
            return Vec3.unitX()
        if norm.y >= norm.z:
            return Vec3.unitY()
        return Vec3.unitZ()
Пример #6
0
    def __build_land_mesh(self):
        vdata = GeomVertexData('data', GeomVertexFormat.getV3n3c4t2(),
                               Geom.UHStatic)
        vertex = GeomVertexWriter(vdata, 'vertex')
        normal = GeomVertexWriter(vdata, 'normal')
        texcoord = GeomVertexWriter(vdata, 'texcoord')
        color = GeomVertexWriter(vdata, 'color')

        axes = [Vec3.unitX(), Vec3.unitY(), Vec3.unitZ()]
        face = 0

        for x in range(3):
            for s in [-1, 1]:
                for i in range(self.__n + 1):
                    for j in range(self.__n + 1):
                        a = (i * 1.0 / self.__n) * (pi / 2) - (pi / 4)
                        b = (j * 1.0 / self.__n) * (pi / 2) - (pi / 4)
                        xAxis = axes[(x + 3) % 3]
                        yAxis = axes[(x + 4) % 3]
                        zAxis = axes[(x + 5) % 3]
                        v = (xAxis * (-cos(a) * sin(b)) + yAxis *
                             (sin(a) * cos(b)) + zAxis * (cos(a) * cos(b))) * s
                        v.normalize()
                        normal.addData3f(v)
                        index = self.__height_i(face, i, j)
                        v = v * (
                            1.0 +
                            (self.__height_factor * self.__height_unit *
                             (self.__heightmap[index] - 0.5))) * self.__radius
                        vertex.addData3f(v)
                        texcoord.addData2f(i * 1.0, j * 1.0)
                        c = self.__gradient(self.__color_gradient,
                                            self.__heightmap[index])
                        color.addData4f(c[0] / 255.0, c[1] / 255.0,
                                        c[2] / 255.0, 1.0)
                face = face + 1

        prim = self.__heightmap_primitive()
        geom = Geom(vdata)
        geom.addPrimitive(prim)
        return geom