This commit is contained in:
2021-04-25 17:19:49 -05:00
parent 4e17a68e45
commit 45c857508e
13 changed files with 0 additions and 0 deletions

124
pyqt/test003.py Executable file
View File

@@ -0,0 +1,124 @@
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import numpy as np
import sys
global lp, lq, rp, rq, z, eyeX, eyeY, eyeZ
lp = 0.0
lq = 2.5
rp = 0.0
rq = 2.5
z = 0.0
# gluLookAt 'eye' coordinates
eyeX = 0.0
eyeY = 0.0
eyeZ = 10.0
def init():
global eyeX, eyeY, eyeZ
glClearColor(0.0, 0.0, 0.0, 1.0)
glMatrixMode(GL_PROJECTION)
glOrtho(-10.0, 10.0, -10.0, 10.0, -10.0, 10.0)
glClear(GL_COLOR_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
gluLookAt(eyeX, eyeY, eyeZ, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
def plotdial():
global lp, lq, rp, rq, eyeX, eyeY, eyeZ
#lOrigin = np.array((0.0, 0.0, 0.0))
rOrigin = np.array((5.0, 0.0, 0.0))
radius = 2.5
glClear(GL_COLOR_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
gluLookAt(eyeX, eyeY, eyeZ, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
# Left arm unit vector calculation
lVec = np.array((lp, lq, z))
lMag = np.linalg.norm(lVec)
lVec = (lVec/lMag)*radius
glColor3f(1.0, 0.0, 0.0)
glLineWidth(3.0)
glBegin(GL_LINES)
glVertex3f(0.0, 0.0, z)
glVertex3f(lVec[0], lVec[1], z)
glEnd()
glLineWidth(1.0)
glColor3f(0.0, 0.0, 1.0)
glutWireSphere(2.5, 25, 25)
# Right
glPushMatrix()
glTranslatef(rOrigin[0], rOrigin[1], z)
glColor3f(0.0, 1.0, 0.0)
glLineWidth(3.0)
glBegin(GL_LINES)
glVertex3f(0.0, 0.0, z)
rVec = np.array((rp, rq, z))
rMag = np.linalg.norm(rVec)
rVec = (rVec/rMag)*radius
glVertex3f(rVec[0], rVec[1], z)
glEnd()
glLineWidth(1.0)
glColor3f(0.0, 0.0, 1.0)
glutWireSphere(2.5, 25, 25)
glPopMatrix()
glFlush()
def keyboard(key, x, y):
global glutshape, solid, eyeX, eyeY, eyeZ
step = 0.01
if key == chr(27) or key == "q":
sys.exit()
if key == "x":
eyeX -= step
if key == "X":
eyeX += step
if key == "y":
eyeY -= step
if key == "Y":
eyeY += step
if key == "z":
eyeZ -= step
if key == "Z":
eyeZ -= step
glutPostRedisplay()
def mouse(button, state, x, y):
global lp, lq, rp, rq
o_lp = lp
o_lq = lq
o_rp = rp
o_rq = rq
if button == GLUT_LEFT_BUTTON and state == GLUT_DOWN:
lp = -10.0 + x/500.0 * 20
lq = 10 - y/500.0 * 20
if lq < 0.0:
lp = o_lp
lq = o_lq
if button == GLUT_RIGHT_BUTTON and state == GLUT_DOWN:
rp = -10.0 + x/500.0 * 20 - 5 # -5 is 2*radius
rq = 10 - y/500.0 * 20
if rq < 0.0:
rp = o_rp
rq = o_rq
glutPostRedisplay()
def main():
glutInit(sys.argv)
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB)
glutInitWindowSize(500,500)
glutInitWindowPosition(50,50)
glutCreateWindow('Dial Trial')
glutDisplayFunc(plotdial)
glutKeyboardFunc(keyboard)
glutMouseFunc(mouse)
init()
glutMainLoop()
main()