The idea behind this is to create a detection area for a security camera. Currently, I know how to find and use the modelview matrix data as shown below in the function "matrixTransformation". The value for the matrix should then be calculated for each increase of rotation of the security camera in the initialization function.
I would like to know how you would find coordinates of the edges of each security camera, a cylinder shape, using the matrix. I am using Pygame 1.9.2, Python 3.5 and PyOpenGL-3.1.0.
Picture of coordinates on the security camera which need to be calculated
def matrixTransformation(x,y,z):
matrix = (GLfloat * 16)()
glGetFloatv(GL_MODELVIEW_MATRIX, matrix)
xp = matrix[0] * x + matrix[4] * y + matrix[8] * z + matrix[12]
yp = matrix[1] * x + matrix[5] * y + matrix[9] * z + matrix[13]
zp = matrix[2] * x + matrix[6] * y + matrix[10] * z + matrix[14]
wp = matrix[3] * x + matrix[7] * y + matrix[11] * z + matrix[15]
xp /= wp
yp /= wp
zp /= wp
return xp,yp,zp
def init():
securityCameraRotation=380
glEnable(GL_DEPTH_TEST)
multipleRotations=0
result=[]
glPushMatrix()
glTranslatef(-4,1.5,5.5)
glRotate(315,1,1,1)
while True:
if securityCameraRotation>=380:
clockwise=True
multipleRotations+=1
elif securityCameraRotation<=310:
clockwise=False
glRotate(securityCameraRotation,0,1,0)
#append the transformed coordinates to result
if clockwise==True:
securityCameraRotation-=0.2
elif clockwise==False:
securityCameraRotation+=0.2
if multipleRotations>1:
#End the loop when one complete rotation between 310 and 380 has occured
break
glPopMatrix()
return result
def securityCamera(radius, height, num_slices,frontCircleColour,backCircleColour,tubeColour):
r = radius
h = height
n = float(num_slices)
circle_pts = []
for i in range(int(n) + 1):
angle = 2 * math.pi * (i/n)
x = r * math.cos(angle)
y = r * math.sin(angle)
pt = (x, y)
circle_pts.append(pt)
glBegin(GL_TRIANGLE_FAN) #drawing the back circle
glColor(backCircleColour)
glVertex(0, 0, h/2.0)
for (x, y) in circle_pts:
z = h/2.0
glVertex(x, y, z)
glEnd()
glBegin(GL_TRIANGLE_FAN) #drawing the front circle
glColor(frontCircleColour)
glVertex(0, 0, h/2.0)
for (x, y) in circle_pts:
z = -h/2.0
glVertex(x, y, z)
glEnd()
glBegin(GL_TRIANGLE_STRIP) #draw the tube
glColor(tubeColour)
for (x, y) in circle_pts:
z = h/2.0
glVertex(x, y, z)
glVertex(x, y, -z)
glEnd()