def _ChangeMotionMode_(self, drag, spin, auto ): new_drag = drag new_auto = auto if not new_drag else False new_spin = spin if new_auto else False change = self.__mouse_drag != new_drag or self.__auto_rotate != new_auto or self.__auto_spin != new_spin if not change: return if new_drag and not self.__mouse_drag: self.__dragStartTime = time() self.__mouse_drag_angle = 0 self.__mouse_drag_time = 0 if new_auto and not self.__auto_rotate: self.__rotateStartTime = time() self.__mouse_drag = new_drag self.__auto_rotate = new_auto self.__auto_spin = new_spin self.__orbit_mat = mat.Multiply(self.__current_orbit_mat, self.__orbit_mat) self.__current_orbit_mat = mat.IdentityMat44() self.__model_mat = mat.Multiply(self.__current_model_mat, self.__model_mat) self.__current_model_mat = mat.IdentityMat44() return
def OnDraw(self): # set up projection matrix prjMat = self.Perspective() # set up view matrix viewMat = self.LookAt() # set up light source lightSourceBuffer.BindDataFloat( b'u_lightSource.dir', mat.TransformVec4([-1.0, -1.0, -5.0, 0.0], viewMat)) # set up icosahedron model matrix modelMat = mat.IdentityMat44() modelMat = self.AutoModelMatrix() #modelMat = mat.RotateX( modelMat, self.CalcAng( 13.0 ) ) #modelMat = mat.RotateY( modelMat, self.CalcAng( 17.0 ) ) # set up attributes and shader program glEnable(GL_DEPTH_TEST) glClearColor(1, 1, 1, 0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) progTess.Use() progTess.SetUniformM44(b"u_projectionMat44", prjMat) lightSourceBuffer.BindToTarget() # draw icosahedron icoMaterialBuffer.BindToTarget() modelViewMat = mat.Multiply(viewMat, modelMat) progTess.SetUniformM44(b"u_modelViewMat44", modelViewMat) progTess.SetUniformM33(b"u_normalMat33", mat.ToMat33(modelViewMat)) icoVAO.Draw()
def OnDraw(self): # set up attributes and shader program fbX.Bind() glEnable(GL_DEPTH_TEST) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) progDraw.Use() progDraw.SetUniform(b"u_projectionMat44", self.Perspective()) viewMat = self.LookAt() modelMat = mat.IdentityMat44() modelMat = self.AutoModelMatrix() #modelMat = mat.RotateX( modelMat, self.CalcAng( 13.0 ) ) #modelMat = mat.RotateY( modelMat, self.CalcAng( 17.0 ) ) progDraw.SetUniform(b"u_modelViewMat44", mat.Multiply(viewMat, modelMat)) progDraw.SetUniform(b"u_glow", 3.0) objVAO.Draw() sigma = 0.8 blurWidth = 20 # blur X fbX.UnBind() fbY.Bind() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) texUnitAttach0 = 1 fbX.BindTextures([texUnitAttach0]) progBlurX.Use() progBlurX.SetUniform(b"u_textureCol", texUnitAttach0) progBlurX.SetUniform(b"u_textureSize", self.VPSize()) progBlurX.SetUniform(b"u_sigma", sigma) progBlurX.SetUniform(b"u_width", blurWidth) # TODO SetUniforms( { } ) # draw screen sapce quadVAO.Draw() # blur Y fbY.UnBind() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) texUnitAttach0 = 2 fbY.BindTextures([texUnitAttach0]) progBlurY.Use() progBlurY.SetUniform(b"u_textureCol", texUnitAttach0) progBlurY.SetUniform(b"u_textureSize", self.VPSize()) progBlurY.SetUniform(b"u_sigma", sigma) progBlurY.SetUniform(b"u_width", blurWidth) # draw screen sapce quadVAO.Draw()
def AutoModelMatrix( self ): if self.__auto_rotate: return mat.Multiply(self.__current_model_mat, self.__model_mat) return self.__model_mat
def OrbitMatrix( self ): if self.__mouse_drag or (self.__auto_rotate and self.__auto_spin): return mat.Multiply(self.__current_orbit_mat, self.__orbit_mat) return self.__orbit_mat
def LookAt(self): return mat.Multiply(self._camera.LookAt(), self.OrbitMatrix())