Hi,
As I understand it, you can either make cgo's that are 'static' in
shape (like a 3D stamp) or use pymol.callback objects, which can use
arbitrary opengl commands (such as matrix rotations).
I actually made a cone, in response to someone's query, only I had to
use callbacks to get triangle fans, and it appears that macpymol
doesn't have opengl compiled in by default or something.
Here is my Cone class (mostly nicked from a tutorial on the web):
import math
from pymol.opengl.gl import *
from pymol.callback import Callback
from pymol import cmd
class Cone(Callback):
def get_extent(self):
return [[-10.0, -10.0, -10.0], [10.0, 10.0, 10.0]]
def __call__(self):
glPushMatrix()
glRotatef(xRot, 1.0, 0.0, 0.0)
glRotatef(yRot, 0.0, 1.0, 0.0)
# Begin a triangle fan
glBegin(GL_TRIANGLE_FAN)
# Pinnacle of cone is shared vertex for fan, moved up z-axis
# to produce a cone instead of a circle
glVertex3f(0.0, 0.0, 75.0)
# Loop around in a circle and specify even points along the
circle
# as the vertices of the triangle fan
angle = 0.0
while angle < 2.0 * math.pi:
# Calculate x and y position of the next vertex
x = 50.0 * math.sin(angle)
y = 50.0 * math.cos(angle)
# Alternate color between red and green
if((iPivot %2) == 0):
glColor3f(0.0, 1.0, 0.0)
else:
glColor3f(1.0, 0.0, 0.0)
# Increment pivot to change color next time
iPivot += 1
# Specify the next vertex for the triangle fan
glVertex2f(x, y)
angle += (math.pi / 8.0)
# Done drawing fan for cone
glEnd()
# Begin a new triangle fan to cover the bottom
glBegin(GL_TRIANGLE_FAN)
# Center of fan is at the origin
glVertex2f(0.0, 0.0)
angle = 0.0
while angle < 2.0 * math.pi:
# Calculate x and y position of the next vertex
x = 50.0 * math.sin(angle)
y = 50.0 * math.cos(angle)
# Alternate color between red and green
if((iPivot %2) == 0):
glColor3f(0.0, 1.0, 0.0)
else:
glColor3f(1.0, 0.0, 0.0)
# Increment pivot to change color next time
iPivot += 1
# Specify the next vertex for the triangle fan
glVertex2f(x, y)
angle += (math.pi / 8.0)
# Done drawing the fan that covers the bottom
glEnd()
# Restore transformations
glPopMatrix()
rx, ry, rz = 1, 2, 3
cmd.load_callback(Cone(), 'cone')
Gilleain Torrance
On 8 Nov 2005, at 06:44, Andrew Wollacott wrote:
Hey all,
I recently made a cone class that will display cones using pymol
cgo's. I built the cones using triangles as suggested by Warren Now
I need to get the cones oriented properly, so I was wondering if it's
possible to apply a GL or rotation matrix when making the cgo. I
guess if I can't do this then I can rotate the vertices of each
individual triangle, but I only want to do this as a last resort.
Any help would be appreciated.
Thanks,
Andrew Wollacott, PhD
Baker Research Group
The University of Washington
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server.
Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
PyMOL-users mailing list
PyMOL-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pymol-users