# # -*- coding: utf-8 -*-
# # @Time : 2019/3/7 19:11
# # @Author : SilverMaple
# # @Site : https://github.com/SilverMaple
# # @File : algorithmView.py
#
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
import math
import numpy as np
from copy import deepcopy
# epochs = 34
# n = 7
# outer_radius = .3
# inner_radius = outer_radius * 2 * np.pi / n
# theta = np.linspace(0, 2 * np.pi, n + 1)[:-1]
# length = np.random.rand(n)
class OpenGLText():
# bitmap_fonts = [
# GLUT_BITMAP_9_BY_15,
# GLUT_BITMAP_8_BY_13,
# GLUT_BITMAP_TIMES_ROMAN_10,
# GLUT_BITMAP_TIMES_ROMAN_24,
# GLUT_BITMAP_HELVETICA_10,
# GLUT_BITMAP_HELVETICA_12,
# GLUT_BITMAP_HELVETICA_18]
def print_bitmap_string(self, fonts, s):
for c in s:
glutBitmapCharacter(fonts, * s)
def TextOut(self, x, y, s):
glRasterPos2f(x, y)
self.print_bitmap_string(self.bitmap_fonts[4], s)
class Camera:
origin = [0.0, 0.0, 0.0]
length = 100.
yangle = 0.
zangle = 0.
scaleFactor = 1.0
__bthree = False
def __init__(self):
self.mouseLocation = [0.0, 0.0]
self.offest = .1
self.zangle = 0. if not self.__bthree else math.pi
def setThirdPersonPerspective(self, value):
self.__bthree = value
self.zangle = self.zangle + math.pi
self.yangle = -self.yangle
def eye(self):
return self.origin if not self.__bthree else self.direction()
def target(self):
return self.origin if self.__bthree else self.direction()
def direction(self):
if self.zangle > math.pi * 2.0:
self.zangle = self.zangle - math.pi * 2.0
elif self.zangle < 0.:
self.zangle = self.zangle + math.pi * 2.0
length = 1. if not self.__bthree else self.length if 0. else 1.
xy = math.cos(self.yangle) * length
x = self.origin[0] + xy * math.sin(self.zangle)
y = self.origin[1] + length * math.sin(self.yangle)
z = self.origin[2] + xy * math.cos(self.zangle)
return [x, y, z]
def move(self, x, y, z):
sinz, cosz = math.sin(self.zangle), math.cos(self.zangle)
xstep, zstep = x * cosz + z * sinz, z * cosz - x * sinz
if self.__bthree:
xstep = -xstep
zstep = -zstep
self.origin = [self.origin[0] + xstep, self.origin[1] + y, self.origin[2] + zstep]
def rotate(self, z, y):
self.zangle, self.yangle = self.zangle - z, self.yangle + y if not self.__bthree else -y
def scale(self, step):
self.scaleFactor += step
if self.scaleFactor