本文整理匯總了Python中pi3d.util.Utility類的典型用法代碼示例。如果您正苦於以下問題:Python Utility類的具體用法?Python Utility怎麽用?Python Utility使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Utility類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: perspective
def perspective(self, w, h, zoom, near=1, far=500):
opengles.glMatrixMode(GL_PROJECTION)
Utility.load_identity()
hht = near * math.tan(math.radians(45.0))
hwd = hht * w / h
opengles.glFrustumf(c_float(-hwd), c_float(hwd), c_float(-hht), c_float(hht), c_float(near), c_float(far))
opengles.glMatrixMode(GL_MODELVIEW)
示例2: __init__
def __init__(
self,
camera=None,
light=None,
radius=1,
slices=12,
sides=12,
hemi=0.0,
name="",
x=0.0,
y=0.0,
z=0.0,
rx=0.0,
ry=0.0,
rz=0.0,
sx=1.0,
sy=1.0,
sz=1.0,
cx=0.0,
cy=0.0,
cz=0.0,
invert=False,
):
"""uses standard constructor for Shape extra Keyword arguments:
*radius*
radius of sphere
*slices*
number of latitude edges
*hemi*
if set to 0.5 it will only construct the top half of sphere
*sides*
number of sides for Shape._lathe() to use
*invert*
normals will face inwards, Texture will need flip=True
"""
super(Sphere, self).__init__(camera, light, name, x, y, z, rx, ry, rz, sx, sy, sz, cx, cy, cz)
if VERBOSE:
print("Creating sphere ...")
path = []
# extra points added at poles to reduce distortion (mainly normals)
st = ((math.pi - 0.002) * (1.0 - hemi)) / slices
path.append((0.0, radius))
for r in range(slices + 1):
x, y = Utility.from_polar_rad(r * st + 0.001, radius)
path.append((y, x))
x, y = Utility.from_polar_rad(r * st + 0.002, radius)
path.append((y, x))
if invert:
path.reverse()
self.radius = radius
self.slices = slices
self.hemi = hemi
self.ttype = GL_TRIANGLES
self.buf = []
self.buf.append(self._lathe(path, sides))
示例3: create3D
def create3D(self, x=0, y=0, w=0, h=0,
near=1.0, far=800.0, aspect=60.0, depth=24):
if w <= 0 or h <= 0:
w = self.max_width
h = self.max_height
self.win_width = w
self.win_height = h
self.near = near
self.far = far
self.left = x
self.top = y
self.right = x + w
self.bottom = y + h
self.create_display(x, y, w, h, depth)
#Setup perspective view
opengles.glMatrixMode(GL_PROJECTION)
Utility.load_identity()
hht = near * math.tan(math.radians(aspect / 2.0))
hwd = hht * w / h
opengles.glFrustumf(c_float(-hwd), c_float(hwd),
c_float(-hht), c_float(hht),
c_float(near), c_float(far))
opengles.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
opengles.glMatrixMode(GL_MODELVIEW)
Utility.load_identity()
示例4: string
def string(font, string, x, y, z, rot, sclx, scly):
opengles.glNormalPointer(GL_BYTE, 0, RECT_NORMALS)
Utility.texture_min_mag()
opengles.glEnableClientState(GL_TEXTURE_COORD_ARRAY)
opengles.glBindTexture(GL_TEXTURE_2D,font.tex)
opengles.glEnable(GL_TEXTURE_2D)
opengles.glDisable(GL_DEPTH_TEST)
opengles.glDisable(GL_CULL_FACE)
opengles.glEnable(GL_BLEND)
opengles.glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
mtrx =(c_float * 16)()
opengles.glGetFloatv(GL_MODELVIEW_MATRIX,ctypes.byref(mtrx))
Utility.translatef(x, y, z)
Utility.rotatef(rot, 0, 0, 1)
Utility.scalef(sclx, scly, 1)
for c in range(0,len(string)):
v = ord(string[c])-32
w, h, texc, verts = font.chr[v]
if v > 0:
opengles.glVertexPointer(3, GL_FLOAT, 0,verts)
opengles.glTexCoordPointer(2, GL_FLOAT,0,texc)
opengles.glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, RECT_TRIANGLES)
Utility.translatef(w, 0, 0)
opengles.glLoadMatrixf(mtrx)
opengles.glDisable(GL_TEXTURE_2D)
opengles.glDisable(GL_BLEND)
opengles.glEnable(GL_DEPTH_TEST)
opengles.glEnable(GL_CULL_FACE)
示例5: calc_normals
def calc_normals(self):
normals = np.zeros((len(self.array_buffer), 3), dtype="float32") #empty array rights size
fv = self.array_buffer[self.element_array_buffer,0:3] #expand faces with x,y,z values for each vertex
#cross product of two edges of triangles
fn = np.cross(fv[:,1] - fv[:,0], fv[:,2] - fv[:,0])
fn = Utility.normalize_v3(fn)
normals[self.element_array_buffer[:,0]] += fn #add up all normal vectors for a vertex
normals[self.element_array_buffer[:,1]] += fn
normals[self.element_array_buffer[:,2]] += fn
return Utility.normalize_v3(normals)
示例6: position
def position(self, x, y, z, w=1):
""" move or rotate the light and change its type
x,y,z -- location or direction components
w -- type 0 for directional, 1 for point (default 1)
"""
mtrx = (ctypes.c_float * 16)()
opengles.glGetFloatv(GL_MODELVIEW_MATRIX, ctypes.byref(mtrx))
Utility.load_identity()
self.xyz = c_floats((x, y, z , w))
opengles.glLightfv(self.no, GL_POSITION, self.xyz)
opengles.glLoadMatrixf(mtrx)
示例7: orthographic
def orthographic(self, left, right, bottom, top, zoom=1, near=-1, far=10):
opengles.glMatrixMode(GL_PROJECTION)
Utility.load_identity()
# opengles.glOrthof(c_float(-10), c_float(10), c_float(10), c_float(-10.0), c_float(near), c_float(far))
opengles.glOrthof(
c_float(left / zoom),
c_float(right / zoom),
c_float(bottom / zoom),
c_float(top / zoom),
c_float(near),
c_float(far),
)
opengles.glMatrixMode(GL_MODELVIEW)
Utility.load_identity()
示例8: __init__
def __init__(self, radius=1, slices=12, sides=12, hemi=0.0, name="",
x=0.0, y=0.0, z=0.0, rx=0.0, ry=0.0, rz=0.0,
sx=1.0, sy=1.0, sz=1.0, cx=0.0, cy=0.0, cz=0.0):
super(Sphere,self).__init__(name, x, y, z, rx, ry, rz,
sx, sy, sz, cx, cy, cz)
if VERBOSE:
print "Creating sphere ..."
path = []
st = (math.pi * (1.0 - hemi)) / slices
for r in range(slices + 1):
x, y = Utility.from_polar_rad(r * st, radius)
path.append((y, x)) # TODO: why is the reversal here?
self.radius = radius
self.slices = slices
self.sides = sides
self.hemi = hemi
self.ttype = GL_TRIANGLES
results = self.lathe(path)
self.vertices = c_floats(results[0])
self.normals = c_floats(results[1])
self.indices = c_shorts(results[2])
self.tex_coords = c_floats(results[3])
self.ssize = results[4]
示例9: __init__
def __init__(self,radius=2.0, thickness=0.5, ringrots=6, sides=12, name="",
x=0.0, y=0.0, z=0.0, rx=0.0, ry=0.0, rz=0.0,
sx=1.0, sy=1.0, sz=1.0, cx=0.0, cy=0.0, cz=0.0):
super(Torus,self).__init__(name, x, y, z, rx, ry, rz,
sx, sy, sz, cx, cy, cz)
if VERBOSE:
print "Creating Torus ..."
path = []
st = (math.pi * 2)/ringrots
for r in range(ringrots + 1):
x, y = Utility.from_polar_rad(r * st, thickness)
path.append((radius + y, x)) # TODO: why the reversal?
self.radius = radius
self.thickness = thickness
self.ringrots = ringrots
self.sides = sides
self.ttype = GL_TRIANGLES
results = self.lathe(path)
self.vertices = c_floats(results[0])
self.normals = c_floats(results[1])
self.indices = c_shorts(results[2])
self.tex_coords = c_floats(results[3])
self.ssize = results[4]
示例10: __init__
def __init__(self, camera=None, light=None,
radius=1, slices=12, sides=12, hemi=0.0, name="",
x=0.0, y=0.0, z=0.0, rx=0.0, ry=0.0, rz=0.0,
sx=1.0, sy=1.0, sz=1.0, cx=0.0, cy=0.0, cz=0.0):
"""uses standard constructor for Shape extra Keyword arguments:
*radius*
radius of sphere
*slices*
number of latitude edges
*hemi*
if set to 0.5 it will only construct the top half of sphere
*sides*
number of sides for Shape._lathe() to use
"""
super(Sphere, self).__init__(camera, light, name, x, y, z, rx, ry, rz,
sx, sy, sz, cx, cy, cz)
if VERBOSE:
print "Creating sphere ..."
path = []
st = (math.pi * (1.0 - hemi)) / slices
for r in range(slices + 1):
x, y = Utility.from_polar_rad(r * st, radius)
path.append((y, x)) # TODO: why is the reversal here?
self.radius = radius
self.slices = slices
self.hemi = hemi
self.ttype = GL_TRIANGLES
self.buf = []
self.buf.append(self._lathe(path, sides))
示例11: __init__
def __init__(self, camera=None, light=None, radius=2.0, thickness=0.5, ringrots=6, sides=12, name="",
x=0.0, y=0.0, z=0.0, rx=0.0, ry=0.0, rz=0.0,
sx=1.0, sy=1.0, sz=1.0, cx=0.0, cy=0.0, cz=0.0):
"""uses standard constructor for Shape extra Keyword arguments:
*radius*
Major radius of torus
*thickness*
Minor radius, section through one side of torus
*ringrots*
Sides around minor radius circle
*sides*
Number of sides for Shape._lathe() to use
"""
super(Torus,self).__init__(camera, light, name, x, y, z, rx, ry, rz,
sx, sy, sz, cx, cy, cz)
if VERBOSE:
print "Creating Torus ..."
path = []
st = (math.pi * 2)/ringrots
for r in range(ringrots + 1):
x, y = Utility.from_polar_rad(r * st, thickness)
path.append((radius + y, x)) # TODO: why the reversal?
self.radius = radius
self.thickness = thickness
self.ringrots = ringrots
self.ttype = GL_TRIANGLES
self.buf = []
self.buf.append(self._lathe(path, sides))
示例12: __init__
def __init__(self, radius=1, sides=12, name="", x=0.0, y=0.0, z=0.0,
rx=0.0, ry=0.0, rz=0.0, sx=1.0, sy=1.0, sz=1.0,
cx=0.0, cy=0.0, cz=0.0):
super(Disk, self).__init__(name, x, y, z, rx, ry, rz, sx, sy, sz,
cx, cy, cz)
if VERBOSE:
print "Creating disk ..."
self.verts = []
self.norms = []
self.inds = []
self.texcoords = []
self.ttype = GL_TRIANGLES
self.sides = sides
st = math.pi / slices
self.add_vertex(x, y, z, 0, 1, 0, 0.5, 0.5)
for r in range(sides+1):
ca, sa = Utility.from_polar_rad(r * st)
self.add_vertex(x + radius * sa, y, z + radius * ca,
0, 1, 0, sa * 0.5 + 0.5, ca * 0.5 + 0.5)
# TODO: why the reversal?
for r in range(sides):
self.add_tri(0, r + 1, r + 2)
self.vertices = c_floats(self.verts);
self.indices = c_shorts(self.inds);
self.normals = c_floats(self.norms);
self.tex_coords = c_floats(self.texcoords);
self.ssize = sides * 3
示例13: _draw
def _draw(verts, tex, x, y, w, h, r, z):
opengles.glNormalPointer(GL_BYTE, 0, RECT_NORMALS);
opengles.glVertexPointer(3, GL_BYTE, 0, verts);
Utility.load_identity()
Utility.translatef(x, y, z)
Utility.scalef(w, h, 1)
if r:
Utility.rotatef(r, 0, 0, 1)
with Texture.Loader(tex,RECT_TEX_COORDS,GL_BYTE):
opengles.glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, RECT_TRIANGLES)
示例14: __init__
def __init__(
self,
camera=None,
light=None,
radius=1,
sides=12,
name="",
x=0.0,
y=0.0,
z=0.0,
rx=0.0,
ry=0.0,
rz=0.0,
sx=1.0,
sy=1.0,
sz=1.0,
cx=0.0,
cy=0.0,
cz=0.0,
):
"""uses standard constructor for Shape extra Keyword arguments:
*radius*
Radius of disk.
*sides*
Number of sides to polygon representing disk.
"""
super(Disk, self).__init__(camera, light, name, x, y, z, rx, ry, rz, sx, sy, sz, cx, cy, cz)
if VERBOSE:
print "Creating disk ..."
self.verts = []
self.norms = []
self.inds = []
self.texcoords = []
self.ttype = GL_TRIANGLES
self.sides = sides
st = 2 * pi / sides
for j in range(-1, 1):
self._add_vertex((0.0, -0.1 * j, 0.0), (0.0, -j, 0.0), (0.5, 0.5))
for r in range(sides + 1):
ca, sa = Utility.from_polar_rad(r * st)
self._add_vertex(
(radius * sa, 0.0, radius * ca), (0.0, -j - 0.1 * j, 0.0), (sa * 0.5 + 0.5, ca * 0.5 + 0.5)
)
if j == -1:
v0, v1, v2 = 0, 1, 2
else:
v0, v1, v2 = sides + 2, sides + 4, sides + 3 # i.e. reverse direction to show on back
for r in range(sides):
self._add_tri((v0, r + v1, r + v2))
self.but = []
self.buf.append(Buffer(self, self.verts, self.texcoords, self.inds, self.norms))
示例15: rotate
def rotate(self, rx, ry, rz):
if rz:
Utility.rotatef(rz, 0, 0, 1)
if rx:
Utility.rotatef(rx, 1, 0, 0)
if ry:
Utility.rotatef(ry, 0, 1, 0)