def init( self, grid ): '''Initializes the grid creating both a vertex_list for an independent-tiled grid and creating also a vertex_list_indexed for a "united" (non independent tile) grid. :Parameters: `grid` : euclid.Point2 size of a 2D grid ''' #: size of the grid. (rows, columns) self.grid = grid width, height = director.get_window_size() if self.texture is None: self.texture = image.Texture.create_for_size( GL_TEXTURE_2D, width, height, GL_RGBA) self.grabber = framegrabber.TextureGrabber() self.grabber.grab(self.texture) #: x pixels between each vertex (float) self.x_step = width / self.grid.x #: y pixels between each vertex (float) self.y_step = height / self.grid.y self._init()
def in_proyect(self, x, y): if not (x==0 and y!=0): return x,y xz, yz = director.get_window_size() dt = (self.dt/self.duration) x = xz * (1-dt) y = yz * dt return (x, y)
def restore( self ): '''Restore the camera to the initial position and sets it's ``dirty`` attribute in False and ``once`` in true. If you use the camera, for a while and you want to stop using it call this method. ''' width, height = director.get_window_size() # tuple (x,y,z) that says where is the eye of the camera. # used by ``gluLookAt()`` self._eye = Point3( width /2.0, height /2.0, self.get_z_eye() ) # tuple (x,y,z) that says where is pointing to the camera. # used by ``gluLookAt()`` self._center = Point3( width /2.0, height /2.0, 0.0 ) # tuple (x,y,z) that says the up vector for the camera. # used by ``gluLookAt()`` self._up_vector = Point3( 0.0, 1.0, 0.0) #: whether or not the camera is 'dirty' #: It is dirty if it is not in the original position self.dirty = False #: optimization. Only renders the camera once self.once = False
def transform( self ): """ Apply ModelView transformations you will most likely want to wrap calls to this function with glPushMatrix/glPopMatrix """ x,y = director.get_window_size() if not(self.grid and self.grid.active): # only apply the camera if the grid is not active # otherwise, the camera will be applied inside the grid self.camera.locate() glTranslatef( self.position[0], self.position[1], 0 ) glTranslatef( self.transform_anchor_x, self.transform_anchor_y, 0 ) if self.rotation != 0.0: glRotatef( -self._rotation, 0, 0, 1) if self.scale != 1.0: glScalef( self._scale, self._scale, 1) if self.transform_anchor != (0,0): glTranslatef( - self.transform_anchor_x, - self.transform_anchor_y, 0 )
def __init__(self): self.before = None x1 = y1 = 0 x2, y2 = director.get_window_size() self.vertex_list = pyglet.graphics.vertex_list( 4, ('v2f', [x1, y1, x2, y1, x2, y2, x1, y2]), ('c4B', [255, 255, 255, 255] * 4))
def restore(self): '''Restore the camera to the initial position and sets it's ``dirty`` attribute in False and ``once`` in true. If you use the camera, for a while and you want to stop using it call this method. ''' width, height = director.get_window_size() # tuple (x,y,z) that says where is the eye of the camera. # used by ``gluLookAt()`` self._eye = Point3(width / 2.0, height / 2.0, self.get_z_eye()) # tuple (x,y,z) that says where is pointing to the camera. # used by ``gluLookAt()`` self._center = Point3(width / 2.0, height / 2.0, 0.0) # tuple (x,y,z) that says the up vector for the camera. # used by ``gluLookAt()`` self._up_vector = Point3(0.0, 1.0, 0.0) #: whether or not the camera is 'dirty' #: It is dirty if it is not in the original position self.dirty = False #: optimization. Only renders the camera once self.once = False
def __init__(self): self.before = None x1 = y1 = 0 x2, y2 = director.get_window_size() self.vertex_list = pyglet.graphics.vertex_list(4, ('v2f', [x1, y1, x2, y1, x2, y2, x1, y2]), ('c4B', [255,255,255,255]*4) )
def get_z_eye( cls ): '''Returns the best distance for the camera for the current window size cocos2d uses a Filed Of View (fov) of 60 ''' width, height = director.get_window_size() eye_z = height / 1.1566 return eye_z
def get_z_eye(cls): '''Returns the best distance for the camera for the current window size cocos2d uses a Filed Of View (fov) of 60 ''' width, height = director.get_window_size() eye_z = height / 1.1566 return eye_z
def _set_2d_projection(cls): # director.set_2d_projection() width, height = director.get_window_size() glLoadIdentity() glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0, width, 0, height, -100, 100) glMatrixMode(GL_MODELVIEW)
def blit_texture(self, texture, p): x, y = director.get_window_size() glEnable(GL_TEXTURE_2D) glBindTexture(texture.target, texture.id) txz = director._offset_x/float(texture.width) tyz = director._offset_y/float(texture.height) rx = director.window.width - 2*director._offset_x ry = director.window.height - 2*director._offset_y tx = float(rx)/texture.width+txz ty = float(ry)/texture.height+tyz glBegin(GL_QUADS) glTexCoord2d(txz,tyz); glVertex2d(*p(0.0,0.0)); glTexCoord2d(tx,tyz); glVertex2d(*p(x,0.0)); glTexCoord2d(tx,ty); glVertex2d(*p(x,y)); glTexCoord2d(txz,ty); glVertex2d(*p(0.0,y)); glEnd() glDisable(GL_TEXTURE_2D)
def out_proyect(self, x, y): dy = director.get_window_size()[1] * (self.dt/self.duration) return (x, y+dy)
def in_proyect(self, x, y): dy = director.get_window_size()[1] * (1-self.dt/self.duration) return (x, y-dy)
def in_proyect(self, x, y): dx = director.get_window_size()[0] * (1-self.dt/self.duration) return (x+dx, y)
def in_proyect(self, x, y): dx = director.get_window_size()[0] * ((self.dt/self.duration)) if x==0: return (director.get_window_size()[0]-dx, y) return (x, y)
def out_proyect(self, x, y): dx = director.get_window_size()[0] * (self.dt/self.duration) return (x-dx, y)
def in_proyect(self, x, y): dt = (self.dt/self.duration) cx = director.get_window_size()[0]/4*3 cy = director.get_window_size()[1]/2 return ((x-cx)*(dt)+cx, (y-cy)*(dt)+cy)