Переведи код игры на Ursina: --- Start of game_objects.py --- import math from OpenGL.GL…
- User
Переведи код игры на Ursina:
--- Start of game_objects.py ---
import math from OpenGL.GL import * from OpenGL.arrays import vbo import numpy as np
class Cube: def init(self, size=50, position=(0, 0, -200)): self.size = size self.position = list(position) self.vertices = [ ((-size / 2, -size / 2, -size / 2), (0, 0, -1)), ((size / 2, -size / 2, -size / 2), (0, 0, -1)), ((size / 2, size / 2, -size / 2), (0, 0, -1)), ((-size / 2, size / 2, -size / 2), (0, 0, -1)), ((-size / 2, -size / 2, size / 2), (0, 0, 1)), ((size / 2, -size / 2, size / 2), (0, 0, 1)), ((size / 2, size / 2, size / 2), (0, 0, 1)), ((-size / 2, size / 2, size / 2), (0, 0, 1)), ] self.faces = [ (0, 1, 2, 3), (4, 5, 6, 7), (0, 1, 5, 4), (2, 3, 7, 6), (1, 2, 6, 5), (0, 3, 7, 4), ] self.vbo_data = self.generate_vbo_data() self.vbo = vbo.VBO(np.array(self.vbo_data, dtype=np.float32))
def generate_vbo_data(self): data = [] for face in self.faces: for vertex_index in face: normal = self.vertices[vertex_index][1] vertex = self.vertices[vertex_index][0] data.extend(normal) data.extend(vertex) return data def render(self): glPushMatrix() glTranslatef(*self.position) self.vbo.bind() glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_NORMAL_ARRAY) glVertexPointer(3, GL_FLOAT, 24, self.vbo + 12) glNormalPointer(GL_FLOAT, 24, self.vbo) glDrawArrays(GL_QUADS, 0, len(self.vbo_data) // 6) glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_NORMAL_ARRAY) self.vbo.unbind() glPopMatrix()--- End of game_objects.py ---
--- Start of interface_module.py ---
from PIL import Image import numpy as np from OpenGL.GL import * from OpenGL.GLU import *
class GameInterface: def init(self, minimap_filename="mini_map.png", minimap_size=200): self.minimap_texture = self.load_minimap_texture(minimap_filename) self.minimap_size = minimap_size
def load_minimap_texture(self, filename): """Загружает текстуру миникарты из файла PNG.""" img = Image.open(filename).transpose(Image.FLIP_TOP_BOTTOM) if img.mode != "RGB": img = img.convert("RGB") img_data = np.array(list(img.getdata()), np.uint8) texture_id = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, texture_id) glEnable(GL_TEXTURE_2D) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img.size[0], img.size[1], 0, GL_RGB, GL_UNSIGNED_BYTE, img_data) return texture_id def render_minimap(self, player_x, player_z, plane_size): glPushMatrix() glDisable(GL_DEPTH_TEST) glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() gluOrtho2D(0, 800, 0, 600) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glEnable(GL_TEXTURE_2D) glBindTexture(GL_TEXTURE_2D, self.minimap_texture) glBegin(GL_QUADS) glTexCoord2f(0, 0) glVertex2f(800 - self.minimap_size, 600 - self.minimap_size) glTexCoord2f(1, 0) glVertex2f(800, 600 - self.minimap_size) glTexCoord2f(1, 1) glVertex2f(800, 600) glTexCoord2f(0, 1) glVertex2f(800 - self.minimap_size, 600) glEnd() glDisable(GL_TEXTURE_2D) glColor3f(1, 0, 0) glBegin(GL_QUADS) vertex_size = 2 x = (player_x / plane_size) * self.minimap_size + (800 - self.minimap_size/2) z = (player_z / plane_size) * self.minimap_size + (600 - self.minimap_size/2) glVertex2f(x - vertex_size, z - vertex_size) glVertex2f(x + vertex_size, z - vertex_size) glVertex2f(x + vertex_size, z + vertex_size) glVertex2f(x - vertex_size, z + vertex_size) glEnd() glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW) glEnable(GL_DEPTH_TEST) glPopMatrix() - Assistant
- User
Переведи весь код, со всеми привязанностями
- Assistant
- User
При запуске main.py не отображается сцена
- Assistant
- User
Traceback (most recent call last): File "D:\dis\python\QWEN\main.py", line 148, in MyApp() File "C:\Users\shash\AppData\Roaming\Python\Python312\site-packages\ursina\ursinastuff.py", line 230, in call obj = type.call(cls, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\dis\python\QWEN\main.py", line 89, in init self.window.fullscreen = False ^^^^^^^^^^^ AttributeError: 'MyApp' object has no attribute 'window'
- Assistant
- User
info: Using primary monitor: Monitor(x=0, y=0, width=1920, height=1080, width_mm=527, height_mm=296, name='\\.\DISPLAY1', is_primary=True) :prc(warning): Invalid integer value for ConfigVariable win-size: 864.0 :prc(warning): Invalid integer value for ConfigVariable win-size: 1536.0 Known pipe types: wglGraphicsPipe (3 aux display modules not yet loaded.) set window position: Vec2(192, 108) :prc(warning): changing default value for ConfigVariable paste-emit-keystrokes from '1' to '0'. :pnmimage:png(warning): iCCP: known incorrect sRGB profile package_folder: C:\Users\shash\AppData\Roaming\Python\Python312\site-packages\ursina asset_folder: . os: Windows development mode: True application successfully started info: changed aspect ratio: 1.778 -> 1.778 :display:windisplay(warning): Could not find icon filename textures/ursina.ico PS D:\dis\python\QWEN> python main.py info: Using primary monitor: Monitor(x=0, y=0, width=1920, height=1080, width_mm=527, height_mm=296, name='\\.\DISPLAY1', is_primary=True) :prc(warning): Invalid integer value for ConfigVariable win-size: 864.0 :prc(warning): Invalid integer value for ConfigVariable win-size: 1536.0 Known pipe types: wglGraphicsPipe (3 aux display modules not yet loaded.) set window position: Vec2(192, 108) :prc(warning): changing default value for ConfigVariable paste-emit-keystrokes from '1' to '0'. :pnmimage:png(warning): iCCP: known incorrect sRGB profile package_folder: C:\Users\shash\AppData\Roaming\Python\Python312\site-packages\ursina asset_folder: . Traceback (most recent call last): File "D:\dis\python\QWEN\main.py", line 148, in MyApp() File "C:\Users\shash\AppData\Roaming\Python\Python312\site-packages\ursina\ursinastuff.py", line 230, in obj = type.(cls, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\dis\python\QWEN\main.py", line 89, in self.window.fullscreen = False ^^^^^^^^^^^ AttributeError: 'MyApp' object has no attribute 'window' PS D:\dis\python\QWEN> python main.py info: Using primary monitor: Monitor(x=0, y=0, width=1920, height=1080, width_mm=527, height_mm=296, name='\\.\DISPLAY1', is_primary=True) :prc(warning): Invalid integer value for ConfigVariable win-size: 864.0 :prc(warning): Invalid integer value for ConfigVariable win-size: 1536.0 Known pipe types: wglGraphicsPipe (3 aux display modules not yet loaded.) set window position: Vec2(192, 108) :prc(warning): changing default value for ConfigVariable paste-emit-keystrokes from '1' to '0'. :pnmimage:png(warning): iCCP: known incorrect sRGB profile package_folder: C:\Users\shash\AppData\Roaming\Python\Python312\site-packages\ursina asset_folder: .
- Assistant
- User
Вылетает после запуска info: Using primary monitor: Monitor(x=0, y=0, width=1920, height=1080, width_mm=527, height_mm=296, name='\\.\DISPLAY1', is_primary=True) :prc(warning): Invalid integer value for ConfigVariable win-size: 864.0 :prc(warning): Invalid integer value for ConfigVariable win-size: 1536.0 Known pipe types: wglGraphicsPipe (3 aux display modules not yet loaded.) set window position: Vec2(192, 108) :prc(warning): changing default value for ConfigVariable paste-emit-keystrokes from '1' to '0'. :pnmimage:png(warning): iCCP: known incorrect sRGB profile package_folder: C:\Users\shash\AppData\Roaming\Python\Python312\site-packages\ursina asset_folder: .
- Assistant
Если программа вылетает сразу после запуска, но вы не получаете конкретных ошибок Python, это может быть связано с проблемами в настройках графики, несовместимыми файлами или отсутствием необходимых ресурсов, а также неправильным кодом.
Чтобы помочь вам лучше справиться с этой ситуацией, попробуем сделать несколько вещей:
- User
Все ресурсы на месте. Используй полный изначальный код на pyopengl и верни весь функционал
- Assistant
- User
info: Using primary monitor: Monitor(x=0, y=0, width=1920, height=1080, width_mm=527, height_mm=296, name='\\.\DISPLAY1', is_primary=True) :prc(warning): Invalid integer value for ConfigVariable win-size: 864.0 :prc(warning): Invalid integer value for ConfigVariable win-size: 1536.0 Known pipe types: wglGraphicsPipe (3 aux display modules not yet loaded.) set window position: Vec2(192, 108) :prc(warning): changing default value for ConfigVariable paste-emit-keystrokes from '1' to '0'. :pnmimage:png(warning): iCCP: known incorrect sRGB profile package_folder: C:\Users\shash\AppData\Roaming\Python\Python312\site-packages\ursina asset_folder: .
- Assistant
- User
Добавь дополнительное логирование
- Assistant
- User
Добавь логирование в переведённый с pyopengl на Ursina код
- Assistant