How to use the panda3d.core.LVector3 function in Panda3D

To help you get started, we’ve selected a few Panda3D examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github art-programmer / PlaneNet / code / polls / polls.py View on Github external
def hit(self):
        if self.cuePos[0] < 5:
            cueDirection = self.ballRoots[0].getPos() - LVector3(self.cuePos[0], self.cuePos[1], self.cuePos[2])
            #power = cueDirection.length()
            cueDirection = cueDirection / cueDirection.length()
            if self.hitIndex < 0:
                self.ballVs[0] = cueDirection * self.cuePower * 8
            elif self.hitIndex == 0:
                self.ballVs[0] = LVector3(0.5, 0.47, 0)
                self.hitIndex += 1
            elif self.hitIndex == 1:
                self.ballVs[0] = LVector3(0.072, 0.62, 0)
                self.hitIndex += 1
            elif self.hitIndex == 2:
                self.ballVs[0] = LVector3(0.7, 0.0, 0)
                self.hitIndex += 1                                
                pass
            self.started = True
            print('hit', cueDirection)
github cosmonium / cosmonium / cosmonium / tiles.py View on Github external
def get_scale(self):
        return LVector3(self.size, self.size, 1.0)
github panda3d / panda3d / samples / fractal-plants / main.py View on Github external
def makeFractalTree(bodydata, nodePath, length, pos=LVector3(0, 0, 0), numIterations=11, numCopies=4, vecList=[LVector3(0, 0, 1), LVector3(1, 0, 0), LVector3(0, -1, 0)]):
    if numIterations > 0:

        drawBody(nodePath, bodydata, pos, vecList, length.getX())

        # move foward along the right axis
        newPos = pos + vecList[0] * length.length()

        # only branch every third level (sorta)
        if numIterations % 3 == 0:
            # decrease dimensions when we branch
            length = LVector3(
                length.getX() / 2, length.getY() / 2, length.getZ() / 1.1)
            for i in range(numCopies):
                makeFractalTree(bodydata, nodePath, length, newPos,
                                numIterations - 1, numCopies, randomAxis(vecList))
        else:
github panda3d / panda3d / samples / fractal-plants / main.py View on Github external
def drawLeaf(nodePath, vdata, pos=LVector3(0, 0, 0), vecList=[LVector3(0, 0, 1), LVector3(1, 0, 0), LVector3(0, -1, 0)], scale=0.125):

    # use the vectors that describe the direction the branch grows to make the right
        # rotation matrix
    newCs = LMatrix4(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
    newCs.setRow(0, vecList[2])  # right
    newCs.setRow(1, vecList[1])  # up
    newCs.setRow(2, vecList[0])  # forward
    newCs.setRow(3, (0, 0, 0))
    newCs.setCol(3, (0, 0, 0, 1))

    axisAdj = LMatrix4.scaleMat(scale) * newCs * LMatrix4.translateMat(pos)

    # orginlly made the leaf out of geometry but that didnt look good
    # I also think there should be a better way to handle the leaf texture other than
    # hardcoding the filename
    leafModel = loader.loadModel('models/shrubbery')
github art-programmer / PlaneNet / code / polls / polls.py View on Github external
def portal(self, colEntry):
        ballName = colEntry.getFromNode().getName()
        print('portal', ballName)
        ballIndex = int(ballName[5:])
        
        #norm = colEntry.getSurfaceNormal(render) * -1  # The normal of the wall
        norm = LVector3(self.portalNormal[0], self.portalNormal[1], self.portalNormal[2])
        norm.normalize()
        curSpeed = self.ballVs[ballIndex].length()                # The current speed
        inVec = self.ballVs[ballIndex] / curSpeed                 # The direction of travel
        velAngle = norm.dot(inVec)                    # Angle of incidance
        hitDir = colEntry.getSurfacePoint(render) - self.ballRoots[ballIndex].getPos()
        hitDir.normalize()
        # The angle between the ball and the normal
        #print(colEntry.getSurfacePoint(render), self.ballRoots[ballIndex].getPos())
        #print(norm, hitDir)
        hitAngle = norm.dot(hitDir)
        
        # Ignore the collision if the ball is either moving away from the wall
        # already (so that we don't accidentally send it back into the wall)
        # and ignore it if the collision isn't dead-on (to avoid getting caught on
        # corners)
        #print(velAngle, hitAngle)
github RealHacker / python-gems / Pycraft / pycraft.py View on Github external
def normalized(*args):
    myVec = LVector3(*args)
    myVec.normalize()
    return myVec
github panda3d / panda3d / samples / fractal-plants / main.py View on Github external
def makeFractalTree(bodydata, nodePath, length, pos=LVector3(0, 0, 0), numIterations=11, numCopies=4, vecList=[LVector3(0, 0, 1), LVector3(1, 0, 0), LVector3(0, -1, 0)]):
    if numIterations > 0:

        drawBody(nodePath, bodydata, pos, vecList, length.getX())

        # move foward along the right axis
        newPos = pos + vecList[0] * length.length()

        # only branch every third level (sorta)
        if numIterations % 3 == 0:
            # decrease dimensions when we branch
            length = LVector3(
                length.getX() / 2, length.getY() / 2, length.getZ() / 1.1)
            for i in range(numCopies):
                makeFractalTree(bodydata, nodePath, length, newPos,
                                numIterations - 1, numCopies, randomAxis(vecList))
        else:
            # just make another branch connected to this one with a small
            # variation in direction
            makeFractalTree(bodydata, nodePath, length, newPos,
                            numIterations - 1, numCopies, smallRandomAxis(vecList))

    else:
        drawBody(nodePath, bodydata, pos, vecList, length.getX(), False)
        drawLeaf(nodePath, bodydata, pos, vecList)
github cosmonium / cosmonium / cosmonium / bodies.py View on Github external
def configure_shape(self):
        if self.scale is not None:
            scale = self.scale
        elif self.oblateness is not None:
            scale = LVector3(1.0, 1.0, 1.0 - self.oblateness) * self.radius
        else:
            scale = LVector3(self.radius, self.radius, self.radius)
        #TODO: should be done on all components
        if self.surface is not None:
            self.surface.set_scale(scale)
        if self.clouds is not None:
            self.clouds.set_scale(scale)
github panda3d / panda3d / samples / fractal-plants / main.py View on Github external
def __init__(self):
        formatArray = GeomVertexArrayFormat()
        formatArray.addColumn(
            InternalName.make("drawFlag"), 1, Geom.NTUint8, Geom.COther)

        format = GeomVertexFormat(GeomVertexFormat.getV3n3cpt2())
        format.addArray(formatArray)
        self.format = GeomVertexFormat.registerFormat(format)

        bodydata = GeomVertexData("body vertices", format, Geom.UHStatic)

        self.barkTexture = loader.loadTexture("barkTexture.jpg")
        treeNodePath = NodePath("Tree Holder")
        makeFractalTree(bodydata, treeNodePath, LVector3(4, 4, 7))

        treeNodePath.setTexture(self.barkTexture, 1)
        treeNodePath.reparentTo(render)

        self.accept("q", self.regenTree)
        self.accept("w", self.addTree)
        self.accept("arrow_up", self.upIterations)
        self.accept("arrow_down", self.downIterations)
        self.accept("arrow_right", self.upCopies)
        self.accept("arrow_left", self.downCopies)

        self.numIterations = 11
        self.numCopies = 4

        self.upDownEvent = OnscreenText(
            text="Up/Down: Increase/Decrease the number of iterations (" + str(
github panda3d / panda3d / samples / asteroids / main.py View on Github external
# This is kind of a hack, but it keeps the asteroids from spawning
            # near the player.  It creates the list (-20, -19 ... -5, 5, 6, 7,
            # ... 20) and chooses a value from it. Since the player starts at 0
            # and this list doesn't contain anything from -4 to 4, it won't be
            # close to the player.
            asteroid.setX(choice(tuple(range(-SCREEN_X, -5)) + tuple(range(5, SCREEN_X))))
            # Same thing for Y
            asteroid.setZ(choice(tuple(range(-SCREEN_Y, -5)) + tuple(range(5, SCREEN_Y))))

            # Heading is a random angle in radians
            heading = random() * 2 * pi

            # Converts the heading to a vector and multiplies it by speed to
            # get a velocity vector
            v = LVector3(sin(heading), 0, cos(heading)) * AST_INIT_VEL
            self.setVelocity(self.asteroids[i], v)