473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Want connect planes to eachother in OpenGl example, but can't pass a tuple as vertex.

Basically, I want to connect the tip of each plane to the other. So I thought I might try creating a variable specifically for the points I want to connect: The tip of each plane.

Then, for each plane in the planes list, I would get the point of that specified tuple of each plane, add it to a list of points, and draw a line to each.

But it's not working. When I try to pass planes[n].tip: glVertex3f(planes[n].tip), I get the following error;

exceptions.EOFError: [Errno 10054] An existing connection was forcibly closed by the remote host

I don't NEED this...I'm just messing around, but I'd still like to know what I am doing wrong.
Also, if there is a more efficient way I could go about drawing the lines, please let me know about it. :P
Expand|Select|Wrap|Line Numbers
  1.  
  2. import sys
  3.  
  4. from OpenGL.GLUT import *
  5. from OpenGL.GLU import *
  6. from OpenGL.GL import *
  7. from math import *
  8. from random import random, choice, randint, getrandbits
  9.  
  10. """
  11.    Copyright (c) Mark J. Kilgard, 1994.
  12.  
  13.    This program is freely distributable without licensing fees
  14.    and is provided without guarantee or warrantee expressed or
  15.    implied. This program is -not- in the public domain.
  16. """
  17.  
  18. M_PI   = pi
  19. M_PI_2 = pi / 2.0
  20.  
  21. moving = False
  22. MAX_PLANES = 15
  23.  
  24. # define plane object#
  25.  
  26. class plane(object):
  27.     def __init__(self, speed, red, green, blue, theta, x, y, z, angle):
  28.         self.speed = speed
  29.         self.red   = red
  30.         self.green = green
  31.         self.blue  = blue
  32.         self.theta = theta
  33.         self.angle = angle
  34.         self.x = x
  35.         self.y = y
  36.         self.z = z
  37.         self.tip = (0.0, 8.0, 0.0)#I want to pass this  
  38.               # variable as a vertex3f tuple, but it  
  39.               # stops the program.
  40.  
  41. # create list of planes#
  42.  
  43. planes = []
  44. for n in range(MAX_PLANES) :
  45.     p = plane(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
  46.     planes.append(p)
  47.  
  48.  
  49. # define the GLUT display function#
  50.  
  51. def draw():
  52.     glClear(GL_DEPTH_BUFFER_BIT)
  53.     # paint black to blue smooth shaded polygon for background
  54.     glDisable(GL_DEPTH_TEST)
  55.     glShadeModel(GL_SMOOTH)
  56.     glBegin(GL_POLYGON);
  57.     glColor3f(0.0, 0.0, 0.0);
  58.     glVertex3f(-20.0, 20.0, -19.0)
  59.     glVertex3f( 20.0, 20.0, -19.0)
  60.     glColor3f(0.0, 0.0, 1.0)
  61.     glVertex3f( 20.0, -20.0, -19.0)
  62.     glVertex3f(-20.0, -20.0, -10.0)
  63.     glEnd()
  64.     # paint planes
  65.     glEnable(GL_DEPTH_TEST)
  66.     glShadeModel(GL_FLAT)
  67.     for n in range(MAX_PLANES) :
  68.         if (planes[n].speed != 0.0) :
  69.             glPushMatrix()
  70.             glTranslatef(planes[n].x, planes[n].y, planes[n].z)
  71.             glRotatef(290.0, 1.0, 0.0, 0.0)
  72.             glRotatef(planes[n].angle, 0.0, 0.0, 1.9)
  73.             glScalef(1.0 / 10.0, 1.0 / 4.0, 1.0 / 10.0)
  74.             glTranslatef(0.0, -4.0, -1.5)
  75.             glBegin(GL_TRIANGLE_STRIP)
  76.             # left wing
  77.             glVertex3f(-7.0, 0.0, 2.0)
  78.             glVertex3f(-1.0, 0.0, 3.0)
  79.             red   = planes[n].red
  80.             green = planes[n].green
  81.             blue  = planes[n].blue
  82.             glColor3f(red, green, blue)
  83.             glVertex3f(-1.0, 7.0, 3.0)
  84.             # left side
  85.             glColor3f(0.6 * red, 0.6 * green, 0.6 * blue)
  86.             glVertex3f(0.0, 0.0, 0.0)
  87.             glVertex3f(planes[n].tip)
  88.             # right side
  89.             glVertex3f(1.0, 0.0, 3.0)
  90.             glVertex3f(1.0, 7.0, 3.0)
  91.             # final tip of right wing */
  92.             glColor3f(red, green, blue)
  93.             glVertex3f(7.0, 0.0, 2.0)
  94.             glEnd()
  95.             glPopMatrix()
  96.             print planes[n].x
  97.  
  98.  
  99.     glutSwapBuffers()
  100.     return
  101.  
  102. # define the plane position and speed incrementor#
  103.  
  104. def tick_per_plane(i):
  105.     planes[i].theta += planes[i].speed
  106.     theta = planes[i].theta
  107.     planes[i].z = -10 + 4 * cos(theta)
  108.     planes[i].x = 5 * sin(2 * theta)
  109.     planes[i].y = sin(theta / 3.4) * 3
  110.     planes[i].angle = ((atan(2.0) + M_PI_2) * sin(theta) - M_PI_2) * 180 / M_PI
  111.     if (planes[i].speed < 0.0) :
  112.         planes[i].angle += 180.0
  113.     return
  114.  
  115. #define the list of rgb tuples for setting plane colours by random choice#
  116.  
  117. rgblist = [(1.0, 0.0, 0.0),  # red
  118.            (1.0, 1.0, 1.0),  # white
  119.            (0.0, 1.0, 0.0),  # green
  120.            (1.0, 0.0, 1.0),  # magenta
  121.            (1.0, 1.0, 0.0),  # yellow
  122.            (0.0, 1.0, 1.0)   # cyan
  123.           ]
  124.  
  125. # define add planes to display of planes#
  126.  
  127. def add_plane():
  128.     for i in range(MAX_PLANES) :
  129.         if (planes[i].speed == 0.0) :
  130.             planes[i].red, planes[i].green, planes[i].blue = choice(rgblist)
  131.             planes[i].speed = (float(randint(0, 19)) * 0.001) + 0.02
  132.             if (getrandbits(32) & 0x1) :
  133.                 planes[i].speed *= -1
  134.             planes[i].theta = float(randint(0, 256)) * 0.1111
  135.             tick_per_plane(i)
  136.             if (not moving) :
  137.                 glutPostRedisplay()
  138.             return
  139.     return
  140.  
  141.  
  142. # define remove a plane from display of planes#
  143.  
  144. def remove_plane():
  145.     for i in range(MAX_PLANES-1, -1, -1) :
  146.       if (planes[i].speed != 0) :
  147.           planes[i].speed = 0
  148.           if (not moving) :
  149.               glutPostRedisplay()
  150.           return
  151.     return
  152.  
  153. #define choice of planes to animate#
  154.  
  155. def tick():
  156.     for i in range(MAX_PLANES) :
  157.         if (planes[i].speed != 0.0) :
  158.             tick_per_plane(i)
  159.     return
  160.  
  161. # define animator so that motion can be started#
  162.  
  163. def animate():
  164.     tick()
  165.     glutPostRedisplay()
  166.     return
  167.  
  168.  
  169. def visible(state):
  170.     if (state == GLUT_VISIBLE) :
  171.         if (moving) :
  172.             glutIdleFunc(animate)
  173.     else :
  174.         if (moving) :
  175.             glutIdleFunc(None)
  176.     return
  177.  
  178.  
  179. # ARGSUSED1 #
  180.  
  181. def keyboard( ch,  x,  y):
  182.     if(ch == ' ') :
  183.         if (not moving) :
  184.             tick()
  185.             glutPostRedisplay()
  186.     elif (ch == chr(27)) :
  187.         sys.exit(0)
  188.     return 0
  189.  
  190. VOID, ADD_PLANE, REMOVE_PLANE, MOTION_ON, MOTION_OFF, QUIT = range(6)
  191.  
  192. def domotion_on():
  193.     moving = GL_TRUE
  194.     glutChangeToMenuEntry(3, "Motion off", MOTION_OFF)
  195.     glutIdleFunc(animate)
  196.     return
  197.  
  198. def domotion_off():
  199.     moving = GL_FALSE
  200.     glutChangeToMenuEntry(3, "Motion", MOTION_ON)
  201.     glutIdleFunc(None)
  202.     return
  203.  
  204. def doquit():
  205.     sys.exit(0)
  206.     return
  207.  
  208. menudict ={ADD_PLANE : add_plane,
  209.            REMOVE_PLANE : remove_plane,
  210.            MOTION_ON : domotion_on,
  211.            MOTION_OFF: domotion_off,
  212.            QUIT : doquit}
  213.  
  214. def dmenu(item):
  215.     menudict[item]()
  216.     return 0
  217.  
  218. if __name__ == "__main__":
  219.     glutInit(['glutplane'])
  220.     glutInitWindowPosition(112, 84)
  221.     glutInitWindowSize(800, 600)
  222.     # use multisampling if available
  223.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_MULTISAMPLE)
  224.     wintitle = "glutplane  Copyright (c) Mark J. Kilgard, 1994. RIGHT-CLICK for menu"
  225.     glutCreateWindow(wintitle)
  226.     glutDisplayFunc(draw)
  227.     glutKeyboardFunc(keyboard)
  228.     glutVisibilityFunc(visible)
  229.     #
  230.     # This program fails if PyOpenGL-3.0.0b1-py2.5.egg\OpenGL\GLUT\special.py
  231.     # is not corrected at line 158 to read :
  232.     # callbackType = ctypes.CFUNCTYPE( None, ctypes.c_int )
  233.     # instead of :
  234.     # callbackType = ctypes.CFUNCTYPE( ctypes.c_int, ctypes.c_int )
  235.     #
  236.     # RIGHT-CLICK to display the menu
  237.     #
  238.     glutCreateMenu(dmenu)
  239.     glutAddMenuEntry("Add plane", ADD_PLANE)
  240.     glutAddMenuEntry("Remove plane", REMOVE_PLANE)
  241.     glutAddMenuEntry("Motion", MOTION_ON)
  242.     glutAddMenuEntry("Quit", QUIT)
  243.     glutAttachMenu(GLUT_RIGHT_BUTTON)
  244.  
  245.     # setup OpenGL state
  246.     glClearDepth(1.0)
  247.     glClearColor(0.0, 0.0, 0.0, 0.0)
  248.     glMatrixMode(GL_PROJECTION)
  249.     glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 30)
  250.     glMatrixMode(GL_MODELVIEW)
  251.     # add three initial random planes
  252.     add_plane()
  253.     add_plane()
  254.     add_plane()
  255.     # start event processing */
  256.     print 'RIGHT-CLICK to display the menu.'
  257.     glutMainLoop()
  258.  
  259.  
  260.  
Apr 4 '12 #1
0 1948

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Gram | last post by:
Hello, Can anyone tell me if ASP can pass an Array intp a Function? If so, can anyone point me to an example? Thanks in advance. Gram.
1
by: Andrés Giraldo | last post by:
Hi! I'm trying to pass trough all the objects of a form but I have some text inputs in a DIV and I have many DIVs like this on my form. I'm doing something like: for (i = 0; i <...
2
by: seamoon | last post by:
ENG> How can I pass a value through CREATESTRUCT in MDI applications? How can I pass a parameter to CREATESTRUCT in VC++ MDI application. For example, Dialogue based examples can pass a value to...
23
by: John | last post by:
Last year, I remember finding a web page describing how to pass the name of a file to another web page, and have that web page load that image file. Now, I can't find my record of that (it was...
4
by: quiteblack | last post by:
howdy~ i wrote a .py file and it works fine, my goal is to pass argument to that py file when it get executed, and accept that argument within py file, eg. i prefer a command like below: ...
5
by: Apollo0130 | last post by:
hi, i want to pass a parameter (a string) between two forms. i have a Webform A (default.aspx) with a button and a Webform B (detail.aspx). i want to click the button and open the webform B with...
6
by: Woody Splawn | last post by:
I am using SQL Server 2000 as a back-end to a VS.net Client/Server app. In a certain report I use a view as part of the query spec. For the view, at present, I am querying for all the records in...
4
by: bobueland | last post by:
I want to calculate f(0) + f(1) + ...+ f(100) over some function f which I can change. So I would like to create a function taking f as argument giving back the sum. How do you do that in Python?
5
by: techbuddha | last post by:
Hi new to the forum and visual basic. I am attempting to fix a migration of excel to access. The excel sheets where simple copied as is into access. for example one table lists the academic...
4
by: tarek01 | last post by:
Hi, I made a function whereby clicking a radio button will show a hidden radio button sub-group, and when it's unchecked, the radio button sub-group hides again and all the radios in the sub-group...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.