-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtitle.py
66 lines (51 loc) · 1.62 KB
/
title.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import numpy as np
from scipy.spatial.transform import Rotation as R
from vtk import *
from structures import *
from rendering import *
game = Game()
ram = np.fromfile("ram.dat", dtype=np.uint8)
game.update(ram)
ship = game.ship_data[10]
print("Vertices:", ship.num_vertices)
print("Edges:", ship.num_edges)
print("Faces:", ship.num_faces)
matrix = np.array([
[ 0, 0, 1, 0],
[ 0, 1, 0, 0],
[-1, 0, 0,-150],
[ 0, 0, 0, 1]], dtype=float)
transform = vtkTransform()
transform.PostMultiply()
transform.SetMatrix(matrix.reshape(16))
filter = vtkTransformPolyDataFilter()
filter.SetTransform(transform)
filter.SetInputData(ship_model(ship))
filter.Update()
mapper = vtkPolyDataMapper()
mapper.SetInputConnection(filter.GetOutputPort())
actor = vtkActor()
actor.SetMapper(mapper)
prop = actor.GetProperty()
prop.SetColor(0.4,0.4,0.4)
prop.SetEdgeColor(1,1,1)
prop.SetLineWidth(10)
renderer = vtkOpenVRRenderer()
renderWindow = vtkOpenVRRenderWindow()
renderWindow.Initialize()
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtkOpenVRRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
renderer.AddActor(actor)
renderer.SetBackground(0.0, 0.0, 0.0)
renderWindow.Render()
renderWindowInteractor.Initialize()
while True:
renderWindowInteractor.DoOneEvent(renderWindow, renderer)
old = R.from_matrix(matrix[0:3,0:3])
local_delta = 0.005 * np.array([0,-1,2])
global_delta = old.apply(local_delta, inverse=True)
new = old * R.from_rotvec(global_delta)
matrix[0:3,0:3] = new.as_matrix()
transform.SetMatrix(matrix.reshape(16))
filter.Update()