def render_cb(dev): global START_TIME current = time.clock() m = geo2.MatrixRotationY((current - START_TIME) * rad_per_sec) trinity.SetViewTransform( geo2.MatrixMultiply(m, trinity.GetViewTransform())) START_TIME = current
def Update(self): parentMat = geo2.MatrixTranslation(*self.parentPos) viewInv = geo2.MatrixInverse(self.localViewMatrix) newT = geo2.MatrixMultiply(viewInv, parentMat) self.viewMatrix = geo2.MatrixInverse(newT) trinity.SetViewTransform(self.viewMatrix) trinity.SetPerspectiveProjection(self.fieldOfView, self.frontClip, self.backClip, self.aspectRatio) self.projection.PerspectiveFov(self.fieldOfView, self.aspectRatio, self.frontClip, self.backClip)
def WndProc(hwnd, message, wParam, lParam): dev = trinity.device if message == WM_DESTROY: blue.os.Terminate() return 0 elif message == WM_CLOSE: blue.os.Terminate() return 0 if message == WM_SIZE: if dev.GetWindow(): rect = RECT() ctypes.windll.user32.GetClientRect(hwnd, ctypes.byref(rect)) viewTrans = trinity.GetViewTransform() fov = trinity.GetFieldOfView() front = trinity.GetFrontClip() back = trinity.GetBackClip() w, h = rect.right, rect.bottom defaultBackBuffer = trinity.device.GetRenderContext().GetDefaultBackBuffer() if w == defaultBackBuffer.width and h == defaultBackBuffer.height: return 0 asp = float(w) / float(h) dev.ChangeBackBufferSize(w, h) trinity.SetPerspectiveProjection(fov, front, back, asp) trinity.SetViewTransform(viewTrans) elif message == WM_LBUTTONDOWN: rect = RECT() ctypes.windll.user32.GetClientRect(hwnd, ctypes.byref(rect)) offset = POINT() ctypes.windll.user32.ClientToScreen(hwnd, ctypes.byref(offset)) ctypes.windll.user32.OffsetRect(ctypes.byref(rect), offset.x, offset.y) ctypes.windll.user32.ClipCursor(ctypes.byref(rect)) PostOnMouse('LEFT_BUTTON_DOWN', wParam, lParam) elif message == WM_LBUTTONUP: ctypes.windll.user32.ClipCursor(0) PostOnMouse('LEFT_BUTTON_UP', wParam, lParam) elif message == WM_LBUTTONDBLCLK: PostOnMouse('LEFT_BUTTON_DBLCLK', wParam, lParam) elif message == WM_RBUTTONUP: PostOnMouse('RIGHT_BUTTON_UP', wParam, lParam) elif message == WM_RBUTTONDOWN: PostOnMouse('RIGHT_BUTTON_DOWN', wParam, lParam) elif message == WM_RBUTTONDBLCLK: PostOnMouse('RIGHT_BUTTON_DBLCLK', wParam, lParam) elif message == WM_MBUTTONUP: PostOnMouse('MIDDLE_BUTTON_UP', wParam, lParam) elif message == WM_MBUTTONDOWN: PostOnMouse('MIDDLE_BUTTON_DOWN', wParam, lParam) elif message == WM_MBUTTONDBLCLK: PostOnMouse('MIDDLE_BUTTON_DBLCLK', wParam, lParam) elif message == WM_MOUSEMOVE: PostOnMouse('MOUSE_MOVE', wParam, lParam) elif message == WM_MOUSEWHEEL: PostOnMouse('MOUSE_WHEEL', wParam, lParam) elif message == WM_ACTIVATE: if not (wParam == WA_ACTIVE and wParam == WA_CLICKACTIVE): ctypes.windll.user32.ClipCursor(0) elif message == WM_SYSCOMMAND: if wParam == SC_KEYMENU: return 0 else: if message == WM_ERASEBKGND: return 0 if message == WM_KEYDOWN: if OnKeyDown is not None and callable(OnKeyDown): OnKeyDown(wParam) elif message == WM_KEYUP: if OnKeyUp is not None and callable(OnKeyUp): OnKeyUp(wParam) elif message == WM_CHAR: if OnChar is not None and callable(OnChar): OnChar(wParam) if uilib is not None: try: return int(uilib.OnAppEvent(message, wParam, lParam)) except: import traceback traceback.print_exc() return 0 else: return ctypes.windll.user32.DefWindowProcA(ctypes.c_int(hwnd), ctypes.c_int(message), ctypes.c_int(wParam), ctypes.c_int(lParam))