Mercurial > touhou
comparison src/th06/anm0_vm.rs @ 643:01849ffd0180
Add an anmrenderer binary.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 02 Aug 2019 20:24:45 +0200 |
parents | 9e40bd5cc26d |
children | 7bde50132735 |
comparison
equal
deleted
inserted
replaced
642:9e40bd5cc26d | 643:01849ffd0180 |
---|---|
5 Anm0, | 5 Anm0, |
6 Call, | 6 Call, |
7 Instruction, | 7 Instruction, |
8 }; | 8 }; |
9 use crate::th06::interpolator::{Interpolator1, Interpolator2, Interpolator3, Formula}; | 9 use crate::th06::interpolator::{Interpolator1, Interpolator2, Interpolator3, Formula}; |
10 use crate::util::math::Mat4; | |
10 use std::cell::RefCell; | 11 use std::cell::RefCell; |
11 use std::rc::Rc; | 12 use std::rc::Rc; |
13 | |
14 /// TODO | |
15 #[repr(C)] | |
16 #[derive(Debug)] | |
17 pub struct Vertex { | |
18 /// XXX | |
19 pub pos: [i16; 3], | |
20 /// XXX | |
21 pub uv: [f32; 2], | |
22 /// XXX | |
23 pub color: [u8; 4], | |
24 } | |
12 | 25 |
13 /// Base visual element. | 26 /// Base visual element. |
14 #[derive(Debug, Clone, Default)] | 27 #[derive(Debug, Clone, Default)] |
15 pub struct Sprite { | 28 pub struct Sprite { |
16 blendfunc: u32, | 29 blendfunc: u32, |
59 color: [255, 255, 255, 255], | 72 color: [255, 255, 255, 255], |
60 ..Default::default() | 73 ..Default::default() |
61 } | 74 } |
62 } | 75 } |
63 | 76 |
77 /// TODO | |
78 pub fn fill_vertices(&self, vertices: &mut [Vertex; 4]) { | |
79 let mut mat = Mat4::new([[-0.5, 0.5, 0.5, -0.5], | |
80 [-0.5, -0.5, 0.5, 0.5], | |
81 [0., 0., 0., 0.], | |
82 [1., 1., 1., 1.]]); | |
83 | |
84 let [tx, ty, tw, th] = self.texcoords; | |
85 let [sx, sy] = self.rescale; | |
86 let width = if self.width_override > 0. { self.width_override } else { tw * sx }; | |
87 let height = if self.height_override > 0. { self.height_override } else { th * sy }; | |
88 | |
89 mat.scale2d(width, height); | |
90 if self.mirrored { | |
91 mat.flip(); | |
92 } | |
93 | |
94 let [rx, ry, mut rz] = self.rotations_3d; | |
95 if self.automatic_orientation { | |
96 rz += std::f32::consts::PI / 2. - self.angle; | |
97 } else if self.force_rotation { | |
98 rz += self.angle; | |
99 } | |
100 | |
101 if rx != 0. { | |
102 mat.rotate_x(-rx); | |
103 } | |
104 if ry != 0. { | |
105 mat.rotate_y(ry); | |
106 } | |
107 if rz != 0. { | |
108 mat.rotate_z(-rz); | |
109 } | |
110 | |
111 if self.allow_dest_offset { | |
112 mat.translate(self.dest_offset); | |
113 } | |
114 if self.corner_relative_placement { | |
115 mat.translate_2d(width / 2., height / 2.); | |
116 } | |
117 | |
118 let mat = mat.borrow_inner(); | |
119 vertices[0].pos[0] = mat[0][0] as i16; | |
120 vertices[0].pos[1] = mat[1][0] as i16; | |
121 vertices[0].pos[2] = mat[2][0] as i16; | |
122 vertices[1].pos[0] = mat[0][1] as i16; | |
123 vertices[1].pos[1] = mat[1][1] as i16; | |
124 vertices[1].pos[2] = mat[2][1] as i16; | |
125 vertices[2].pos[0] = mat[0][2] as i16; | |
126 vertices[2].pos[1] = mat[1][2] as i16; | |
127 vertices[2].pos[2] = mat[2][2] as i16; | |
128 vertices[3].pos[0] = mat[0][3] as i16; | |
129 vertices[3].pos[1] = mat[1][3] as i16; | |
130 vertices[3].pos[2] = mat[2][3] as i16; | |
131 | |
132 // XXX: don’t clone here. | |
133 let (x_1, y_1) = self.anm.clone().unwrap().inv_size(); | |
134 let [tox, toy] = self.texoffsets; | |
135 let left = tx * x_1 + tox; | |
136 let right = (tx + tw) * x_1 + tox; | |
137 let bottom = ty * y_1 + toy; | |
138 let top = (ty + th) * y_1 + toy; | |
139 | |
140 vertices[0].uv[0] = left; | |
141 vertices[0].uv[1] = bottom; | |
142 vertices[1].uv[0] = right; | |
143 vertices[1].uv[1] = bottom; | |
144 vertices[2].uv[0] = right; | |
145 vertices[2].uv[1] = top; | |
146 vertices[3].uv[0] = left; | |
147 vertices[3].uv[1] = top; | |
148 | |
149 vertices[0].color = self.color; | |
150 vertices[1].color = self.color; | |
151 vertices[2].color = self.color; | |
152 vertices[3].color = self.color; | |
153 } | |
154 | |
64 /// Update sprite values from the interpolators. | 155 /// Update sprite values from the interpolators. |
65 pub fn update(&mut self) { | 156 pub fn update(&mut self) { |
66 self.frame += 1; | 157 self.frame += 1; |
158 self.corner_relative_placement = true; | |
67 | 159 |
68 let [sax, say, saz] = self.rotations_speed_3d; | 160 let [sax, say, saz] = self.rotations_speed_3d; |
69 if sax != 0. || say != 0. || saz != 0. { | 161 if sax != 0. || say != 0. || saz != 0. { |
70 let [ax, ay, az] = self.rotations_3d; | 162 let [ax, ay, az] = self.rotations_3d; |
71 self.rotations_3d = [ax + sax, ay + say, az + saz]; | 163 self.rotations_3d = [ax + sax, ay + say, az + saz]; |