Определение состава и структуры автоматизированной системы визуализации технологических процессов, страница 8

 glRotatef(rotation_x,1.0,0.0,0.0); // Rotations of the object (the model matrix is multiplied by the rotation matrices)

 glRotatef(rotation_y,0.0,1.0,0.0);

 glRotatef(rotation_z,0.0,0.0,1.0);

 glScaled(scale_x, scale_y, scale_z);

 glBindTexture(GL_TEXTURE_2D, object.id_texture); // We set the active texture

 glBegin(GL_TRIANGLES); // glBegin and glEnd delimit the vertices that define a primitive (in our case triangles)

 for (l_index=0;l_index<object.polygons_qty;l_index++)

 {

 //----------------- FIRST VERTEX -----------------

 // Texture coordinates of the first vertex

 glTexCoord2f( object.mapcoord[ object.polygon[l_index].a ].u,

 object.mapcoord[ object.polygon[l_index].a ].v);

 // Coordinates of the first vertex

 glVertex3f( object.vertex[ object.polygon[l_index].a ].x,

 object.vertex[ object.polygon[l_index].a ].y,

 object.vertex[ object.polygon[l_index].a ].z); //Vertex definition

 //----------------- SECOND VERTEX -----------------

 // Texture coordinates of the second vertex

 glTexCoord2f( object.mapcoord[ object.polygon[l_index].b ].u,

 object.mapcoord[ object.polygon[l_index].b ].v);

 // Coordinates of the second vertex

 glVertex3f( object.vertex[ object.polygon[l_index].b ].x,

 object.vertex[ object.polygon[l_index].b ].y,

 object.vertex[ object.polygon[l_index].b ].z);

 //----------------- THIRD VERTEX -----------------

 // Texture coordinates of the third vertex

 glTexCoord2f( object.mapcoord[ object.polygon[l_index].c ].u,

 object.mapcoord[ object.polygon[l_index].c ].v);

 // Coordinates of the Third vertex

 glVertex3f( object.vertex[ object.polygon[l_index].c ].x,

 object.vertex[ object.polygon[l_index].c ].y,

 object.vertex[ object.polygon[l_index].c ].z);

 }

 glEnd();

 glFlush(); // This force the execution of OpenGL commands

 glutSwapBuffers(); // In double buffered mode we invert the positions of the visible buffer and the writing buffer

}

/**********************************************************

 *

 * The main routine

 *

 *********************************************************/

int main(int argc, char **argv)

{

 // We use the GLUT utility to initialize the window, to handle the input and to interact with the windows system

 glutInit(&argc, argv); 

 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

 glutInitWindowSize(screen_width,screen_height);

 glutInitWindowPosition(0,0);

 glutCreateWindow("3D Viewer"); 

 glutDisplayFunc(display);

 glutIdleFunc(display);

 glutReshapeFunc (resize);

 glutKeyboardFunc (keyboard);

 glutSpecialFunc (keyboard_s);

 init();

 glutMainLoop();

 return(0); 

}


Приложение 4 (Графический интерфейс)

from tkinter import *

from tkinter.filedialog import *

import os

import shutil

makemodal = 1

def dialog():

win = Toplevel()

Label(win, text = "неверный формат файла!").pack()

Button(win, text = "Ok", command = win.destroy).pack()

if makemodal:

win.focus_set()

win.grab_set()

win.wait_window()

def start_program():

os.system('tutorial4.exe')

root=Tk()

root.geometry('300x200+300+200')

v = StringVar()

def _open():

op = askopenfilename()

#print(op)

#print(op[:-3])

if op[-3:] == '3DS':

shutil.copy(op, 'file.3DS')

lst_ok = Label(root, text = 'ok').place(x= 100, y = 60)

elif op[-3:] == '3ds':

shutil.copy(op, 'file.3ds')

lst_ok = Label(root, text = 'ok').place(x= 100, y = 60)

elif op[-3:] == 'bmp':

shutil.copy(op, 'file.bmp')

lst_ok = Label(root, text = 'ok').place(x= 100, y = 25)

else:

a = dialog()

def gett():

s = record_3ds_file_name(v.get())

but = Button(root, width = 10, height = 1, text ='Текстура', command = _open).place(x = 15, y = 25)

but = Button(root, width = 10, height = 1, text ='3дс', command = _open).place(x = 15, y = 60)

start = Button(root,width = 10, height = 1, text ='Запуск',command = start_program ).place(x = 15, y = 95)

root.mainloop()