當前位置: 首頁>>代碼示例>>Python>>正文


Python PyUtils.toVector3d方法代碼示例

本文整理匯總了Python中PyUtils.toVector3d方法的典型用法代碼示例。如果您正苦於以下問題:Python PyUtils.toVector3d方法的具體用法?Python PyUtils.toVector3d怎麽用?Python PyUtils.toVector3d使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PyUtils的用法示例。


在下文中一共展示了PyUtils.toVector3d方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _createEllipsoid

# 需要導入模塊: import PyUtils [as 別名]
# 或者: from PyUtils import toVector3d [as 別名]
def _createEllipsoid(proxy, radius, colour, moiScale, withMesh):
    """
    Private function.
    Use createEllipsoid() or createArticulatedEllipsoid() instead.
    """
    # Mesh and cdps will be set manually
    proxy.meshes = None
    proxy.cdps = None

    # Compute box moi
    moi = [0, 0, 0]
    for i in range(3):
        j = (i + 1) % 3
        k = (i + 2) % 3
        moi[i] = proxy.mass * (radius[j] * radius[j] + radius[k] * radius[k]) / 5.0
    proxy.moi = PyUtils.toVector3d(moi) * moiScale

    ellipsoid = proxy.createAndFillObject()

    cdp = Physics.SphereCDP()
    cdp.setCenter(Point3d(0, 0, 0))
    cdp.setRadius(min(radius))

    ellipsoid.addCollisionDetectionPrimitive(cdp)

    if withMesh:
        mesh = Mesh.createEllipsoid((0, 0, 0), radius, colour)
        ellipsoid.addMesh(mesh)

    return ellipsoid
開發者ID:Phong13,項目名稱:cartwheel-3d,代碼行數:32,代碼來源:RigidBody.py

示例2: createBox

# 需要導入模塊: import PyUtils [as 別名]
# 或者: from PyUtils import toVector3d [as 別名]
def createBox( size=(1,1,1), position=(0,0,0), colour=(0.6,0.6,0.6) ):
    """
    Creates the mesh for a box having the specified size and a specified position.
    The size should be a 3-tuple (xSize, ySize, zSize).
    The position should be a 3-tuple.
    Colour should be a 3-tuple (R,G,B) or a 4-tuple (R,G,B,A)
    """
    
    size     = PyUtils.toVector3d(size)
    position = PyUtils.toPoint3d(position)
    vertices = []
    delta = MathLib.Vector3d()
    for repeat in range(3):
        for x in (-0.5,0.5) :
            delta.x = size.x * x
            for y in (-0.5,0.5) :
                delta.y = size.y * y
                for z in (-0.5,0.5) :
                    delta.z = size.z * z
                    vertices.append( position + delta )
    
    faces = [(0,1,3,2),(5,4,6,7),  # YZ Faces
             (9,13,15,11),(12,8,10,14),  # XY Faces
             (18,19,23,22),(17,16,20,21)]  # XZ Faces
    
    return create( vertices, faces, colour )
開發者ID:MontyThibault,項目名稱:cartwheel-3d-Research-Modifications,代碼行數:28,代碼來源:Mesh.py

示例3: _createCylinder

# 需要導入模塊: import PyUtils [as 別名]
# 或者: from PyUtils import toVector3d [as 別名]
def _createCylinder(proxy, axis, basePos, tipPos, radius, colour, moiScale, withMesh):
    """
    Private function.
    Use createCylinder() or createArticulatedCylinder() instead.
    """
    if axis != 0 and axis != 1 and axis != 2:
        raise ValueError("Axis must be 0 for x, 1 for y or 2 for z.")

    # Mesh and cdps will be set manually
    proxy.meshes = None
    proxy.cdps = None

    # Compute box moi
    moi = [0, 0, 0]
    height = math.fabs(tipPos - basePos)
    for i in range(3):
        if i == axis:
            moi[i] = proxy.mass * radius * radius / 2.0
        else:
            moi[i] = proxy.mass * (3 * radius * radius + height * height) / 12.0
        ### HACK!
        moi[i] = max(moi[i], 0.01)
    proxy.moi = PyUtils.toVector3d(moi) * moiScale

    cylinder = proxy.createAndFillObject()

    basePoint = [0, 0, 0]
    tipPoint = [0, 0, 0]
    basePoint[axis] = basePos
    tipPoint[axis] = tipPos
    basePoint3d = PyUtils.toPoint3d(basePoint)
    tipPoint3d = PyUtils.toPoint3d(tipPoint)
    baseToTipVector3d = Vector3d(basePoint3d, tipPoint3d)
    if baseToTipVector3d.isZeroVector():
        raise ValueError("Invalid points for cylinder: base and tip are equal!")
    baseToTipUnitVector3d = baseToTipVector3d.unit()

    if height <= radius * 2.0:
        cdp = Physics.SphereCDP()
        cdp.setCenter(basePoint3d + baseToTipVector3d * 0.5)
        cdp.setRadius(height / 2.0)
    else:
        cdp = Physics.CapsuleCDP()
        cdp.setPoint1(basePoint3d + baseToTipUnitVector3d * radius)
        cdp.setPoint2(tipPoint3d + baseToTipUnitVector3d * -radius)
        cdp.setRadius(radius)

    cylinder.addCollisionDetectionPrimitive(cdp)

    if withMesh:
        mesh = Mesh.createCylinder(basePoint, tipPoint, radius, colour)
        cylinder.addMesh(mesh)

    return cylinder
開發者ID:Phong13,項目名稱:cartwheel-3d,代碼行數:56,代碼來源:RigidBody.py

示例4: _createBox

# 需要導入模塊: import PyUtils [as 別名]
# 或者: from PyUtils import toVector3d [as 別名]
def _createBox(proxy, size, colour, moiScale, withMesh):
    """
    Private function.
    Use createBox() or createArticulatedBox() instead.
    """

    # Mesh and cdps will be set manually
    proxy.meshes = None
    proxy.cdps = None

    # Compute box moi
    size = PyUtils.toVector3d(size)
    proxy.moi = (
        MathLib.Vector3d(
            size.y * size.y + size.z * size.z, size.x * size.x + size.z * size.z, size.x * size.x + size.y * size.y
        )
        * 1.0
        / 12.0
        * proxy.mass
        * moiScale
    )

    box = proxy.createAndFillObject()

    cdp = Physics.BoxCDP()
    halfSize = PyUtils.toVector3d(size) * 0.5

    cdp.setPoint1(MathLib.Point3d(halfSize * -1))
    cdp.setPoint2(MathLib.Point3d(halfSize))

    box.addCollisionDetectionPrimitive(cdp)

    if withMesh:
        mesh = Mesh.createBox(size=size, colour=colour)
        box.addMesh(mesh)

    return box
開發者ID:Phong13,項目名稱:cartwheel-3d,代碼行數:39,代碼來源:RigidBody.py

示例5: interpret

# 需要導入模塊: import PyUtils [as 別名]
# 或者: from PyUtils import toVector3d [as 別名]
 def interpret(self, value):
     value = self.basicInterpret(value)
     if isinstance(value, MathLib.Vector3d) : return value
     else : return PyUtils.toVector3d( value )
開發者ID:MontyThibault,項目名稱:cartwheel-3d-Research-Modifications,代碼行數:6,代碼來源:Member.py


注:本文中的PyUtils.toVector3d方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。