示例#1
0
    def __init__(self, light_id):
        self.ambient = (0.5, 0.5, 0.5, 1.0)
        self.diffuse = (0.8, 0.8, 0.8, 1.0)
        self.specular = (1.0, 1.0, 1.0, 1.0)
        self.position = [0.0, 0.0, -2.0, 1.0]
        self.light_id = light_id
        self.mat_specular = (0.0, 0.0, 0.0, 1.0)
        self.mat_diffuse = (0.3, 0.3, 0.3, 1.0)
        self.mat_emission = (1.0, 1.0, 1.0, 1.0)
        self.mat_shininess = (128)
        self.counter = 0

        glEnable(light_id)
        glLightfv(self.light_id, GL_AMBIENT, self.ambient)
        glLightfv(self.light_id, GL_DIFFUSE, self.diffuse)
        glLightfv(self.light_id, GL_SPECULAR, self.specular)

        self.scene_ambient = (0.3, 0.3, 0.3, 1.0)
        glLightModelfv(GL_LIGHT_MODEL_AMBIENT, self.scene_ambient)

        self.sphere = glGenLists(1)
        glNewList(self.sphere, GL_COMPILE)

        glMaterialfv(GL_FRONT, GL_DIFFUSE, self.mat_diffuse)
        glMaterialfv(GL_FRONT, GL_SHININESS, self.mat_shininess)
        glMaterialfv(GL_FRONT, GL_SPECULAR, self.mat_specular)
        glMaterialfv(GL_FRONT, GL_EMISSION, self.mat_emission)
        glScalef(0.1, 0.1, 0.1)
        glColor3f(1, 1, 1)
        objects.sphere()

        glEndList()
示例#2
0
	def __init__(self, light_id):
		self.ambient = (0.5, 0.5, 0.5, 1.0)
		self.diffuse = (0.8, 0.8, 0.8, 1.0)
		self.specular = (1.0, 1.0, 1.0, 1.0)
		self.position = [0.0, 0.0, -2.0, 1.0]
		self.light_id = light_id
		self.mat_specular = (0.0, 0.0, 0.0, 1.0);
		self.mat_diffuse = (0.3, 0.3, 0.3, 1.0);
		self.mat_emission = (1.0, 1.0, 1.0, 1.0);
		self.mat_shininess = (128);
		self.counter = 0
		
		glEnable(light_id)
		glLightfv(self.light_id, GL_AMBIENT, self.ambient)
		glLightfv(self.light_id, GL_DIFFUSE, self.diffuse)
		glLightfv(self.light_id, GL_SPECULAR, self.specular)
		
		self.scene_ambient = (0.3, 0.3, 0.3, 1.0);
		glLightModelfv(GL_LIGHT_MODEL_AMBIENT, self.scene_ambient);
		
		self.sphere = glGenLists(1)
		glNewList(self.sphere, GL_COMPILE)
		
		glMaterialfv(GL_FRONT, GL_DIFFUSE, self.mat_diffuse)
		glMaterialfv(GL_FRONT, GL_SHININESS, self.mat_shininess)
		glMaterialfv(GL_FRONT, GL_SPECULAR, self.mat_specular)
		glMaterialfv(GL_FRONT, GL_EMISSION, self.mat_emission)
		glScalef(0.1, 0.1, 0.1)
		glColor3f(1, 1, 1)
		objects.sphere()
		
		glEndList()
示例#3
0
def draw(*args, **kwargs):
    global angle_delta

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
    gluLookAt(
        camPOS.x,
        camPOS.y,
        camPOS.z,  # camera position
        planePOS.x,
        planePOS.y,
        planePOS.z + 2,  # point camera is looking at
        camUP.x,
        camUP.y,
        camUP.z)  # up direction of camera
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

    glPushMatrix()
    glTranslated(planePOS.x, planePOS.y, planePOS.z)
    glCallList(skybox_model)
    glPopMatrix()

    glPushMatrix()
    glTranslated(planePOS.x, planePOS.y, planePOS.z)
    glRotated(plane_angle_counter * 10, 0, 0, 1)
    objects.plane()

    # propeller
    angle_delta += 20 * plane_force_fwd / 50
    if angle_delta >= 720:
        angle_delta = 0
    glPushMatrix()
    glTranslated(1.015, 1.015, 0)
    glRotated(45, 0, 0, 1)
    glTranslated(0, 0, 0)
    glRotated(90, 1, 0, 0)
    glRotated(-45 - angle_delta, 1, 0, 0)
    glScaled(0.01, 2, 0.3)
    objects.sphere()
    glPopMatrix()
    glPopMatrix()

    glPushMatrix()
    landscape_x = length * (planePOS.x // length)
    landscape_y = length * (planePOS.y // length)
    glTranslated(landscape_x, landscape_y, 0)
    glCallList(landspace_model)
    glPopMatrix()

    keyboard()
    glutSwapBuffers()
    glutPostRedisplay()
示例#4
0
 def make(self):
     """
     This function creates vertices and indices
     :return:
     """
     if self.shape is "sphere":
         v, t, n, tex = objects.sphere(self.size)
         self.vertices = vbo.VBO(v, target=GL_ARRAY_BUFFER, usage=GL_STATIC_DRAW)
         self.indices = vbo.VBO(t, target=GL_ELEMENT_ARRAY_BUFFER)
     elif self.shape is "parallelepiped":
         v, t, = objects.parallelepiped(self.size)
         self.vertices = vbo.VBO(v, target=GL_ARRAY_BUFFER, usage=GL_STATIC_DRAW)
         self.indices = vbo.VBO(t, target=GL_ELEMENT_ARRAY_BUFFER)
     elif self.shape is "cross":
         # Fixation cross
         v, t = objects.cross()
         self.vertices = vbo.VBO(v, target=GL_ARRAY_BUFFER, usage=GL_STATIC_DRAW)
         self.indices = vbo.VBO(t, target=GL_ELEMENT_ARRAY_BUFFER)
     elif self.shape is 'line':
         v = np.array([
                 [-1.0, 0.0, 0.0],
                 [1.0, 0.0, 0.0]
             ], dtype='float32')
         t = np.array([0, 1], np.int32)
         self.vertices = vbo.VBO(v*self.size, target=GL_ARRAY_BUFFER, usage=GL_STATIC_DRAW)
         self.indices = vbo.VBO(t, target=GL_ELEMENT_ARRAY_BUFFER)
     else:
         raise Exception('{} is not a valid object shape'.format(self.shape))
示例#5
0
	def initializeObjects(self):

	#velocity is sampled from a norm sphere and multipled to create equal speed for each object
		# see sampling_test.py for simulation of the sampling.
		# need to make sure we recall this at beginning of new trial
		#adding 2-d change
		if self.dimType=="3D":
			self.sBalls=self.conditions.trial['sBalls']
			self.nBalls=self.conditions.trial['nBalls'] #required parameters go here.
			self.nTargets=self.conditions.trial['nTargets']
			self.lTrial=self.conditions.trial['lTrial']
			self.selected=np.zeros(self.conditions.trial['nTargets']).astype(np.float32)
			self.ballSelected=0
			self.nCorrect=0
			self.pCorrect=float('nan')
			self.responses=np.zeros(self.conditions.trial['nBalls']).astype(np.float32)

			Angles           = np.random.uniform(0, 1, (self.nBalls, 2)).astype(np.float32) 
			Theta            = 2*math.pi*Angles[:,0]
			Phi              = np.arccos(2*Angles[:,1]-1)
			self.motionTrigger = 0 #predefined
			if self.moveType == "ConstantVelocity":
				self.vBalls      = np.zeros((self.nBalls,3), dtype="float32")
				self.vBalls[:,0] =(np.cos(Theta)*np.sin(Phi))*self.sBalls  # m/s x
				self.vBalls[:,1] =(np.sin(Theta)*np.sin(Phi))*self.sBalls # m/s y 
				self.vBalls[:,2] =(np.cos(Phi)*self.sBalls)               # m/s z

			elif self.moveType == "virtualSpring":
				self.pBalls      = np.zeros((self.nBalls,3), dtype="float32")
				self.vBalls      = np.zeros((self.nBalls,3), dtype="float32")

			distance=np.zeros((self.nBalls*self.nBalls))
			distance[0]=1 
			while (sum(distance)>0):	# repeat until no balls overlap
				distance=np.zeros((self.nBalls*self.nBalls))
				self.pBalls=np.zeros((self.nBalls,3), dtype="float32")# m
				self.pBalls[:,0] = np.random.uniform(self.wall[0][0],self.wall[0][1], (self.nBalls)).astype(np.float32) #initialize balls to be between walls
				self.pBalls[:,1] = np.random.uniform(self.wall[1][0],self.wall[1][1], (self.nBalls)).astype(np.float32)
				self.pBalls[:,2] = np.random.uniform(self.wall[2][0],self.wall[2][1], (self.nBalls)).astype(np.float32)
				for i in range(0,self.nBalls-1):
					for j in range(i+1,self.nBalls):
						if np.sqrt(sum(np.square(self.pBalls[i,:] -self.pBalls[j,:]))) < self.rBalls*2: #check euclidean distance
							distance[i]=1
		#if self.moveType=="virtualSpring":
			self.targets=np.random.permutation(self.nBalls) #create randon permutation of balls
			self.targets=self.targets[0:self.nTargets] #define targets
			self.pBallStart=self.pBalls[self.targets,:] #randomise and find targets
			self.currentTarget=0 #start response from first balls
			self.ballColor=np.ones((self.nBalls,3), 'f') #everything grey
			self.ballColor[self.targets,:]=numpy.matlib.repmat([1,0,0],self.nTargets,1) #num targets cannot be less than num of balls
			self.resBallColor=np.ones((self.nBalls,3), 'f') #initiale response balls color


		else:
			self.sBalls=self.conditions.trial['sBalls']
			self.nBalls=self.conditions.trial['nBalls'] #required parameters go here.
			self.nTargets=self.conditions.trial['nTargets']
			self.lTrial=self.conditions.trial['lTrial']
			self.selected=np.zeros(self.conditions.trial['nTargets']).astype(np.float32)
			self.ballSelected=0
			self.nCorrect=0
			self.pCorrect=float('nan')
			self.responses=np.zeros(self.conditions.trial['nBalls']).astype(np.float32)

			Angles           = np.random.uniform(0, 1, (self.nBalls, 2)).astype(np.float32) 
			Theta            = 2*math.pi*Angles[:,0]
			Phi              = np.arccos(2*Angles[:,1]-1)
			self.motionTrigger = 0 #predefined
			if self.moveType == "ConstantVelocity":
				self.vBalls      = np.zeros((self.nBalls,3), dtype="float32")
				self.vBalls[:,0] =(np.cos(Theta)*np.sin(Phi))*self.sBalls  # m/s x
				self.vBalls[:,1] =(np.sin(Theta)*np.sin(Phi))*self.sBalls # m/s y 
				#self.vBalls[:,2] =(np.cos(Phi)*self.sBalls)               # m/s z

			elif self.moveType == "virtualSpring":
				self.pBalls      = np.zeros((self.nBalls,3), dtype="float32")
				self.vBalls      = np.zeros((self.nBalls,3), dtype="float32")

			distance=np.zeros((self.nBalls*self.nBalls))
			distance[0]=1 
			while (sum(distance)>0):	# repeat until no balls overlap
				distance=np.zeros((self.nBalls*self.nBalls))
				self.pBalls=np.zeros((self.nBalls,3), dtype="float32")# m
				self.pBalls[:,0] = np.random.uniform(self.wall[0][0],self.wall[0][1], (self.nBalls)).astype(np.float32) #initialize balls to be between walls
				self.pBalls[:,1] = np.random.uniform(self.wall[1][0],self.wall[1][1], (self.nBalls)).astype(np.float32)
				if self.dimType=="3D":
					self.pBalls[:,2] = np.random.uniform(self.wall[2][0],self.wall[2][1], (self.nBalls)).astype(np.float32)
				else:
					self.pBalls[:,2] = np.zeros((self.nBalls), dtype="float32")
				for i in range(0,self.nBalls-1):
					for j in range(i+1,self.nBalls):
						if np.sqrt(sum(np.square(self.pBalls[i,:] -self.pBalls[j,:]))) < self.rBalls*2: #check euclidean distance
							distance[i]=1
		#if self.moveType=="virtualSpring":
			self.targets=np.random.permutation(self.nBalls) #create randon permutation of balls
			self.targets=self.targets[0:self.nTargets] #define targets
			self.pBallStart=self.pBalls[self.targets,:] #randomise and find targets
			self.currentTarget=0 #start response from first balls
			self.ballColor=np.ones((self.nBalls,3), 'f') #everything grey
			self.ballColor[self.targets,:]=numpy.matlib.repmat([1,0,0],self.nTargets,1) #num targets cannot be less than num of balls
			self.resBallColor=np.ones((self.nBalls,3), 'f') #initiale response balls color







		# set uniform variables and set up VBO's for the attribute values
		# reference triangles, do not move in model coordinates
		# position of the center
		
		p, t, n, pTex = objects.sphere(1.0)

		# each vertex has:
		# 3 floats for position (x, y, z)
 		self.ballVertices = vbo.VBO(p, target=GL_ARRAY_BUFFER, usage=GL_STATIC_DRAW)
		self.ballIndices = vbo.VBO(t, target=GL_ELEMENT_ARRAY_BUFFER)
		
		# fixation cross
		xFixation = self.pViewer[0]

		p = np.hstack((
			np.array((xFixation-.1, 0, 0, 
			 xFixation+.1, 0, 0, 
			 xFixation, .1, 0), dtype='float32'), 
			np.array((0,0,1, 0,0,1, 0,0,1), dtype='float32')
		))

		# send the whole array to the video card
		self.fixationVertices = vbo.VBO(p, usage='GL_STATIC_DRAW')
示例#6
0
    im = Image.new("RGB", img_size, 'rgb(128,128,128)')
    draw = ImageDraw.Draw(im)

    ##  objects in virtual space  ##
    ''' set light '''
    light = ray(vector3(1.0,-1.8,5.0), vector3(0.0,1.0,0.0))
    ''' set eye position'''
    eye = vector3(0.0,0.0,-1.0)
    ''' primitive objects '''
    obj_list = []
    obj_list.append(face(vector3(0.0,-2.0,0.0), vector3(0.0,1.0,0.0), 255))
    obj_list.append(face(vector3(0.0, 2.0,0.0), vector3(0.0,-1.0,0.0), 255<<8))
    obj_list.append(face(vector3(-2.0,0.0,0.0), vector3(1.0,0.0,0.0), 255<<16))
    obj_list.append(face(vector3( 2.0,0.0,0.0), vector3(-1.0,0.0,0.0), 255 + (255<<8)))
    obj_list.append(face(vector3(0.0,0.0,10.0), vector3(0.0,0.0,-1.0), 255 + (255<<8) + (255<<16)))
    obj_list.append(sphere(vector3(0.0,0.7,5.0), 1.5, 255 + (255<<16)))

    v_percentage = 1
    ##  each line  ##
    for y in range(0,h):
        if  v_percentage <= y*100 // h :
            print str(v_percentage) + " %" 
            v_percentage = y*100//h + 1
        ##  each pixel  ##
        for x in range(0,w):
            screen = vector3((x-w/2)*view_ratio, (y-h/2)*view_ratio, 0.0)
            inv_eyevec = vector3.sub_vec(screen, eye)
            inv_ray = ray(eye,inv_eyevec)
            ##  calc color  ##
            pixel_color = inv_ray.calcColor(light, obj_list)
            draw.point((x,y), pixel_color)