def createCar(r,g,b): gpuBlackQuad = es.toGPUShape(bs.createColorCube(0,0,0)) gpuChasisQuad = es.toGPUShape(bs.createColorCube(r,g,b)) # Cheating a single wheel wheel = sg.SceneGraphNode("wheel") wheel.transform = tr.scale(0.2, 0.8, 0.2) wheel.childs += [gpuBlackQuad] wheelRotation = sg.SceneGraphNode("wheelRotation") wheelRotation.childs += [wheel] # Instanciating 2 wheels, for the front and back parts frontWheel = sg.SceneGraphNode("frontWheel") frontWheel.transform = tr.translate(0.3,0,-0.3) frontWheel.childs += [wheelRotation] backWheel = sg.SceneGraphNode("backWheel") backWheel.transform = tr.translate(-0.3,0,-0.3) backWheel.childs += [wheelRotation] # Creating the chasis of the car chasis = sg.SceneGraphNode("chasis") chasis.transform = tr.scale(1,0.7,0.5) chasis.childs += [gpuChasisQuad] # All pieces together car = sg.SceneGraphNode("car") car.childs += [chasis] car.childs += [frontWheel] car.childs += [backWheel] return car
def __init__(self): #crea una barra gpu_barra = es.toGPUShape(bs.createColorCube(0.7, 0.4, 0)) self.model = gpu_barra self.dibujo = True self.real = True self.posx = 0 self.posy = 0 self.posz = 0
def createFish(r, g, b): gpu_body = es.toGPUShape(bs.createColorCube(r, g, b)) gpu_tail = es.toGPUShape(bs.createColorCube(r, g, b)) # Body of the fish body = sg.SceneGraphNode('body') body.transform = tr.matmul([tr.uniformScale(2), tr.scale(0.6, 0.2, 0.3)]) body.childs += [gpu_body] # Tail of the fish tail = sg.SceneGraphNode('tail') tail.transform = tr.matmul([tr.uniformScale(2), tr.translate(-0.4, 0, 0), tr.scale(0.2, 0.05, 0.2)]) tail.childs += [gpu_tail] tailRotation = sg.SceneGraphNode('tailRotation') tailRotation.childs += [tail] # Creating the fish fish = sg.SceneGraphNode('fish') fish.childs += [body] fish.childs += [tailRotation] return fish
# Assembling the shader program pipeline = es.SimpleModelViewProjectionShaderProgram() # Telling OpenGL to use our shader program glUseProgram(pipeline.shaderProgram) # Setting up the clear screen color glClearColor(0.15, 0.15, 0.15, 1.0) # As we work in 3D, we need to check which part is in front, # and which one is at the back glEnable(GL_DEPTH_TEST) # Creating shapes on GPU memory gpuAxis = es.toGPUShape(bs.createAxis(7)) gpuRedCube = es.toGPUShape(bs.createColorCube(1, 0, 0)) gpuGreenCube = es.toGPUShape(bs.createColorCube(0, 1, 0)) gpuBlueCube = es.toGPUShape(bs.createColorCube(0, 0, 1)) gpuYellowCube = es.toGPUShape(bs.createColorCube(1, 1, 0)) gpuCyanCube = es.toGPUShape(bs.createColorCube(0, 1, 1)) gpuPurpleCube = es.toGPUShape(bs.createColorCube(1, 0, 1)) gpuRainbowCube = es.toGPUShape(bs.createRainbowCube()) t0 = glfw.get_time() camera_theta = np.pi / 4 while not glfw.window_should_close(window): # Using GLFW to check for input events glfw.poll_events() # Getting the time difference from the previous iteration
def __init__(self, texture_head): gpu_body = es.toGPUShape(bs.createColorCube(1, 0, 0)) gpu_leg = es.toGPUShape(bs.createColorCube(0, 0, 1)) gpu_skin = es.toGPUShape(bs.createColorCube(1, 1, 0)) gpu_head = es.toGPUShape(bs.createTextureCube(texture_head), GL_REPEAT, GL_LINEAR) # Creamos el nucleo core = sg.SceneGraphNode('core') core.transform = tr.scale(0.32, 0.5, 0.6) core.childs += [gpu_body] # Piernas leg = sg.SceneGraphNode('leg') leg.transform = tr.scale(0.14, 0.14, 0.5) leg.childs += [gpu_leg] leg_left = sg.SceneGraphNode('leg_left') leg_left.transform = tr.translate(0, -0.17, -0.5) leg_left.childs += [leg] leg_right = sg.SceneGraphNode('leg_right') leg_right.transform = tr.translate(0, 0.17, -0.5) leg_right.childs += [leg] # Brazos arm = sg.SceneGraphNode('arm') arm.transform = tr.scale(0.13, 0.5, 0.13) arm.childs += [gpu_skin] arm_left = sg.SceneGraphNode('arm_left') arm_left.transform = tr.translate(0, -0.4, 0.23) arm_left.childs += [arm] arm_right = sg.SceneGraphNode('arm_right') arm_right.transform = tr.translate(0, 0.4, 0.23) arm_right.childs += [arm] # Cuello neck = sg.SceneGraphNode('neck') neck.transform = tr.matmul( [tr.scale(0.12, 0.12, 0.2), tr.translate(0, 0, 1.6)]) neck.childs += [gpu_skin] # Cabeza head = sg.SceneGraphNode('head') head.transform = tr.matmul( [tr.scale(0.35, 0.35, 0.35), tr.translate(-0.08, 0, 1.75)]) head.childs += [gpu_skin] body = sg.SceneGraphNode('body') body.childs += [ arm_left, arm_right, leg_left, leg_right, core, neck, head ] face = sg.SceneGraphNode('face') face.transform = tr.matmul( [tr.scale(0.3, 0.3, 0.3), tr.translate(0, 0, 2)]) face.childs += [gpu_head] body_tr = sg.SceneGraphNode('bodyTR') body_tr.childs += [body, face] self.face = face self.body = body self.model = body_tr self.show_face = True