def __init__(self, window, directory): super().__init__(window, directory, bindings = self.bindings) #self.ground = ground.create(self) self.player = player.create(self) self.darklings = [ darkling.create(self, x, y) for x, y in [ (-5, 0), (-5, -10), (5, 0), (5, -10), ] ] self.camera = gl.Camera() self.camera.position = gl.vec3f(.5, 10, 10) self.camera.look_at(gl.vec3f(0, 0, -40)) self.camera.init_frustum( units.deg(45), self.window.width / self.window.height, 0.005, 300.0 ) self.__bind_camera_controls() self.scene_view = self.scene.drawable(self.renderer) self.world = cubeapp.world.World( storage = cubeapp.world.Storage(), generator = cubeapp.world.Generator(), renderer = cubeapp.world.Renderer(self.renderer), ) self.referential = cubeapp.world.world.coord_type() self.__has_focus = False self.window.inputs.on_mousedown.connect(self.__enter) self.__enter() self.world.start(self.camera, self.referential)
def __init__(self, window, directory): super().__init__(window, directory, bindings=self.bindings) #self.ground = ground.create(self) self.player = player.create(self) self.darklings = [ darkling.create(self, x, y) for x, y in [ (-5, 0), (-5, -10), (5, 0), (5, -10), ] ] self.camera = gl.Camera() self.camera.position = gl.vec3f(.5, 10, 10) self.camera.look_at(gl.vec3f(0, 0, -40)) self.camera.init_frustum(units.deg(45), self.window.width / self.window.height, 0.005, 300.0) self.__bind_camera_controls() self.scene_view = self.scene.drawable(self.renderer) self.world = cubeapp.world.World( storage=cubeapp.world.Storage(), generator=cubeapp.world.Generator(), renderer=cubeapp.world.Renderer(self.renderer), ) self.referential = cubeapp.world.world.coord_type() self.__has_focus = False self.window.inputs.on_mousedown.connect(self.__enter) self.__enter() self.world.start(self.camera, self.referential)
def setUp(self): fov = deg(45.0) ratio = 640 / 480 near_dist = 1 far_dist = 300 self.frustum = frustum.Frustumil(fov, ratio, near_dist, far_dist) up = vec3f(0,1,0) front = vec3f(0,0,-1) self.frustum.update(front, up)
def __call__(self, ev, elapsed): if ev.channel == 'tick': if self.dir: self.camera.move(self.dir * elapsed * self.velocity) self.dir = self.dir * .8 self.camera.rotate(units.deg(self.mouse.yrel / 10), self.camera.right) self.camera.rotate(units.deg(self.mouse.xrel / 10), gl.vec3f(0, 1, 0)) else: if hasattr(ev.channel, 'dir'): dir = ev.channel.dir else: if ev.channel == self.move_left: dir = -self.camera.right elif ev.channel == self.move_right: dir = self.camera.right elif ev.channel == self.move_forward: dir = self.camera.front elif ev.channel == self.move_backward: dir = -self.camera.front dir.y = 0 self.dir = gl.vector.normalize(self.dir + dir)
def render(self): new_time = time.time() self.title.text = "%.2f ms" % ((new_time - self.last_time) * 1000) self.last_time = new_time with self.renderer.begin(gl.mode_3d) as painter: painter.state.look_at( gl.vec3f(0,0,-10), gl.vec3f(0, 0, 0), gl.vec3f(0, 1, 0) ) painter.state.perspective( units.deg(45), self.window.width / self.window.height, 0.005, 300.0 ) with painter.bind([self.light]): painter.draw([self.scene_view])
def create(game): mat = gl.Material('ground') mat.ambient = gl.col3f('black') mat.diffuse = gl.col3f('brown') mat.specular = gl.col3f('gray') mat.shininess = 1000 mat.shading_model = gl.material.ShadingModel.gouraud mat.add_texture("ground.bmp", gl.TextureType.ambient, gl.TextureMapping.uv, gl.StackOperation.add, gl.TextureMapMode.wrap, gl.BlendMode.basic) mesh = gl.Mesh() mesh.mode = gl.DrawMode.quads size = 40 step = 1.0 / size for i in (i / size for i in range(size)): x = i for j in (i / size for i in range(size)): y = 1.0 - j mesh.kind = gl.ContentKind.vertex mesh.append(gl.vec3f(x, y, 0)) mesh.append(gl.vec3f(x, y - step, 0)) mesh.append(gl.vec3f(x + step, y - step, 0)) mesh.append(gl.vec3f(x + step, y, 0)) mesh.kind = gl.ContentKind.tex_coord0 mesh.append(gl.vec2f(i, j)) mesh.append(gl.vec2f(i, j + step)) mesh.append(gl.vec2f(i + step, j + step)) mesh.append(gl.vec2f(i + step, j)) mesh.kind = gl.ContentKind.normal mesh.append(gl.vec3f(0, 0, 1)) mesh.append(gl.vec3f(0, 0, 1)) mesh.append(gl.vec3f(0, 0, 1)) mesh.append(gl.vec3f(0, 0, 1)) light = game.renderer.new_light( gl.PointLightInfo( gl.vec3f(0, 2, -1), gl.Color3f("#888"), gl.Color3f("#333"), )) ground = game.entity_manager.create("ground") ground.add_component( cubeapp.game.entity.component.Transform( gl.matrix.rotate( gl.matrix.translate(gl.matrix.scale(gl.mat4f(), gl.vec3f(20)), gl.vec3f(-.5, 0, 0)), units.deg(-90), gl.vec3f(1, 0, 0)))) ground.add_component(cubeapp.game.entity.component.Bindable(mat)) ground.add_component(cubeapp.game.entity.component.Drawable(mesh)) return ground
def create(game): mat = gl.Material('ground') mat.ambient = gl.col3f('black') mat.diffuse = gl.col3f('brown') mat.specular = gl.col3f('gray') mat.shininess = 1000 mat.shading_model = gl.material.ShadingModel.gouraud mat.add_texture( "ground.bmp", gl.TextureType.ambient, gl.TextureMapping.uv, gl.StackOperation.add, gl.TextureMapMode.wrap, gl.BlendMode.basic ) mesh = gl.Mesh() mesh.mode = gl.DrawMode.quads size = 40 step = 1.0 / size for i in (i / size for i in range(size)): x = i for j in (i / size for i in range(size)): y = 1.0 - j mesh.kind = gl.ContentKind.vertex mesh.append(gl.vec3f(x, y, 0)) mesh.append(gl.vec3f(x, y - step, 0)) mesh.append(gl.vec3f(x + step, y - step, 0)) mesh.append(gl.vec3f(x + step, y, 0)) mesh.kind = gl.ContentKind.tex_coord0 mesh.append(gl.vec2f(i, j)) mesh.append(gl.vec2f(i, j + step)) mesh.append(gl.vec2f(i + step, j + step)) mesh.append(gl.vec2f(i + step, j)) mesh.kind = gl.ContentKind.normal mesh.append(gl.vec3f(0, 0, 1)) mesh.append(gl.vec3f(0, 0, 1)) mesh.append(gl.vec3f(0, 0, 1)) mesh.append(gl.vec3f(0, 0, 1)) light = game.renderer.new_light( gl.PointLightInfo( gl.vec3f(0, 2, -1), gl.Color3f("#888"), gl.Color3f("#333"), ) ) ground = game.entity_manager.create("ground") ground.add_component( cubeapp.game.entity.component.Transform( gl.matrix.rotate( gl.matrix.translate( gl.matrix.scale(gl.mat4f(), gl.vec3f(20)), gl.vec3f(-.5, 0, 0) ), units.deg(-90), gl.vec3f(1, 0, 0) ) ) ) ground.add_component( cubeapp.game.entity.component.Bindable(mat) ) ground.add_component( cubeapp.game.entity.component.Drawable(mesh) ) return ground
def player_matrix(pos, radius): return gl.matrix.rotate( gl.matrix.scale(gl.matrix.translate(gl.mat4f(), pos), gl.vec3f(radius, radius, 1)), units.deg(0), gl.vec3f(1, 1, 0))
def __call__(self, ev, delta): transform.node.rotate(units.deg(45) * delta * self.velocity, gl.vec3f(1, .5, 0))