zenilib: zenilib/jni/external/lib3ds/src/lib3ds_viewport.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lib3ds_viewport.c
Go to the documentation of this file.
1 /*
2 Copyright (C) 1996-2008 by Jan Eric Kyprianidis <www.kyprianidis.com>
3 All rights reserved.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation, either version 2.1 of the License, or
8 (at your option) any later version.
9
10 Thisprogram is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program; If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "lib3ds_impl.h"
19
20
21 void
22 lib3ds_viewport_read(Lib3dsViewport *viewport, Lib3dsIo *io) {
23 Lib3dsChunk c;
24 uint16_t chunk;
25
26 memset(viewport, 0, sizeof(*viewport));
27 lib3ds_chunk_read_start(&c, 0, io);
28 switch (c.chunk) {
29 case CHK_VIEWPORT_LAYOUT: {
30 int cur = 0;
31 viewport->layout_style = lib3ds_io_read_word(io);
32 viewport->layout_active = lib3ds_io_read_intw(io);
33 lib3ds_io_read_intw(io);
34 viewport->layout_swap = lib3ds_io_read_intw(io);
35 lib3ds_io_read_intw(io);
36 viewport->layout_swap_prior = lib3ds_io_read_intw(io);
37 viewport->layout_swap_view = lib3ds_io_read_intw(io);
38 lib3ds_chunk_read_tell(&c, io);
39 while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
40 switch (chunk) {
41 case CHK_VIEWPORT_SIZE: {
42 viewport->layout_position[0] = lib3ds_io_read_word(io);
43 viewport->layout_position[1] = lib3ds_io_read_word(io);
44 viewport->layout_size[0] = lib3ds_io_read_word(io);
45 viewport->layout_size[1] = lib3ds_io_read_word(io);
46 break;
47 }
48
49 case CHK_VIEWPORT_DATA_3: {
50 if (cur < LIB3DS_LAYOUT_MAX_VIEWS) {
51 lib3ds_io_read_intw(io);
52 viewport->layout_views[cur].axis_lock = lib3ds_io_read_word(io);
53 viewport->layout_views[cur].position[0] = lib3ds_io_read_intw(io);
54 viewport->layout_views[cur].position[1] = lib3ds_io_read_intw(io);
55 viewport->layout_views[cur].size[0] = lib3ds_io_read_intw(io);
56 viewport->layout_views[cur].size[1] = lib3ds_io_read_intw(io);
57 viewport->layout_views[cur].type = lib3ds_io_read_word(io);
58 viewport->layout_views[cur].zoom = lib3ds_io_read_float(io);
59 lib3ds_io_read_vector(io, viewport->layout_views[cur].center);
60 viewport->layout_views[cur].horiz_angle = lib3ds_io_read_float(io);
61 viewport->layout_views[cur].vert_angle = lib3ds_io_read_float(io);
62 lib3ds_io_read(io, viewport->layout_views[cur].camera, 11);
63 ++cur;
64 }
65 break;
66 }
67
68 case CHK_VIEWPORT_DATA:
69 /* 3DS R2 & R3 chunk unsupported */
70 break;
71
72 default:
73 lib3ds_chunk_unknown(chunk, io);
74 }
75 }
76 break;
77 }
78
79 case CHK_DEFAULT_VIEW: {
80 while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
81 switch (chunk) {
82 case CHK_VIEW_TOP: {
83 viewport->default_type = LIB3DS_VIEW_TOP;
84 lib3ds_io_read_vector(io, viewport->default_position);
85 viewport->default_width = lib3ds_io_read_float(io);
86 break;
87 }
88
89 case CHK_VIEW_BOTTOM: {
90 viewport->default_type = LIB3DS_VIEW_BOTTOM;
91 lib3ds_io_read_vector(io, viewport->default_position);
92 viewport->default_width = lib3ds_io_read_float(io);
93 break;
94 }
95
96 case CHK_VIEW_LEFT: {
97 viewport->default_type = LIB3DS_VIEW_LEFT;
98 lib3ds_io_read_vector(io, viewport->default_position);
99 viewport->default_width = lib3ds_io_read_float(io);
100 break;
101 }
102
103 case CHK_VIEW_RIGHT: {
104 viewport->default_type = LIB3DS_VIEW_RIGHT;
105 lib3ds_io_read_vector(io, viewport->default_position);
106 viewport->default_width = lib3ds_io_read_float(io);
107 break;
108 }
109
110 case CHK_VIEW_FRONT: {
111 viewport->default_type = LIB3DS_VIEW_FRONT;
112 lib3ds_io_read_vector(io, viewport->default_position);
113 viewport->default_width = lib3ds_io_read_float(io);
114 break;
115 }
116
117 case CHK_VIEW_BACK: {
118 viewport->default_type = LIB3DS_VIEW_BACK;
119 lib3ds_io_read_vector(io, viewport->default_position);
120 viewport->default_width = lib3ds_io_read_float(io);
121 break;
122 }
123
124 case CHK_VIEW_USER: {
125 viewport->default_type = LIB3DS_VIEW_USER;
126 lib3ds_io_read_vector(io, viewport->default_position);
127 viewport->default_width = lib3ds_io_read_float(io);
128 viewport->default_horiz_angle = lib3ds_io_read_float(io);
129 viewport->default_vert_angle = lib3ds_io_read_float(io);
130 viewport->default_roll_angle = lib3ds_io_read_float(io);
131 break;
132 }
133
134 case CHK_VIEW_CAMERA: {
135 viewport->default_type = LIB3DS_VIEW_CAMERA;
136 lib3ds_io_read(io, viewport->default_camera, 11);
137 break;
138 }
139
140 default:
141 lib3ds_chunk_unknown(chunk, io);
142 }
143 }
144 break;
145 }
146 }
147
148 lib3ds_chunk_read_end(&c, io);
149 }
150
151
152 void
153 lib3ds_viewport_write(Lib3dsViewport *viewport, Lib3dsIo *io) {
154 if (viewport->layout_nviews) {
155 Lib3dsChunk c;
156 int i;
157
158 c.chunk = CHK_VIEWPORT_LAYOUT;
159 lib3ds_chunk_write_start(&c, io);
160
161 lib3ds_io_write_word(io, viewport->layout_style);
162 lib3ds_io_write_intw(io, viewport->layout_active);
163 lib3ds_io_write_intw(io, 0);
164 lib3ds_io_write_intw(io, viewport->layout_swap);
165 lib3ds_io_write_intw(io, 0);
166 lib3ds_io_write_intw(io, viewport->layout_swap_prior);
167 lib3ds_io_write_intw(io, viewport->layout_swap_view);
168
169 {
170 Lib3dsChunk c;
171 c.chunk = CHK_VIEWPORT_SIZE;
172 c.size = 14;
173 lib3ds_chunk_write(&c, io);
174 lib3ds_io_write_intw(io, viewport->layout_position[0]);
175 lib3ds_io_write_intw(io, viewport->layout_position[1]);
176 lib3ds_io_write_intw(io, viewport->layout_size[0]);
177 lib3ds_io_write_intw(io, viewport->layout_size[1]);
178 }
179
180 for (i = 0; i < viewport->layout_nviews; ++i) {
181 Lib3dsChunk c;
182 c.chunk = CHK_VIEWPORT_DATA_3;
183 c.size = 55;
184 lib3ds_chunk_write(&c, io);
185
186 lib3ds_io_write_intw(io, 0);
187 lib3ds_io_write_word(io, viewport->layout_views[i].axis_lock);
188 lib3ds_io_write_intw(io, viewport->layout_views[i].position[0]);
189 lib3ds_io_write_intw(io, viewport->layout_views[i].position[1]);
190 lib3ds_io_write_intw(io, viewport->layout_views[i].size[0]);
191 lib3ds_io_write_intw(io, viewport->layout_views[i].size[1]);
192 lib3ds_io_write_word(io, viewport->layout_views[i].type);
193 lib3ds_io_write_float(io, viewport->layout_views[i].zoom);
194 lib3ds_io_write_vector(io, viewport->layout_views[i].center);
195 lib3ds_io_write_float(io, viewport->layout_views[i].horiz_angle);
196 lib3ds_io_write_float(io, viewport->layout_views[i].vert_angle);
197 lib3ds_io_write(io, viewport->layout_views[i].camera, 11);
198 }
199
200 lib3ds_chunk_write_end(&c, io);
201 }
202
203 if (viewport->default_type) {
204 Lib3dsChunk c;
205
206 c.chunk = CHK_DEFAULT_VIEW;
207 lib3ds_chunk_write_start(&c, io);
208
209 switch (viewport->default_type) {
210 case LIB3DS_VIEW_TOP: {
211 Lib3dsChunk c;
212 c.chunk = CHK_VIEW_TOP;
213 c.size = 22;
214 lib3ds_chunk_write(&c, io);
215 lib3ds_io_write_vector(io, viewport->default_position);
216 lib3ds_io_write_float(io, viewport->default_width);
217 break;
218 }
219
220 case LIB3DS_VIEW_BOTTOM: {
221 Lib3dsChunk c;
222 c.chunk = CHK_VIEW_BOTTOM;
223 c.size = 22;
224 lib3ds_chunk_write(&c, io);
225 lib3ds_io_write_vector(io, viewport->default_position);
226 lib3ds_io_write_float(io, viewport->default_width);
227 break;
228 }
229
230 case LIB3DS_VIEW_LEFT: {
231 Lib3dsChunk c;
232 c.chunk = CHK_VIEW_LEFT;
233 c.size = 22;
234 lib3ds_chunk_write(&c, io);
235 lib3ds_io_write_vector(io, viewport->default_position);
236 lib3ds_io_write_float(io, viewport->default_width);
237 break;
238 }
239
240 case LIB3DS_VIEW_RIGHT: {
241 Lib3dsChunk c;
242 c.chunk = CHK_VIEW_RIGHT;
243 c.size = 22;
244 lib3ds_chunk_write(&c, io);
245 lib3ds_io_write_vector(io, viewport->default_position);
246 lib3ds_io_write_float(io, viewport->default_width);
247 break;
248 }
249
250 case LIB3DS_VIEW_FRONT: {
251 Lib3dsChunk c;
252 c.chunk = CHK_VIEW_FRONT;
253 c.size = 22;
254 lib3ds_chunk_write(&c, io);
255 lib3ds_io_write_vector(io, viewport->default_position);
256 lib3ds_io_write_float(io, viewport->default_width);
257 break;
258 }
259
260 case LIB3DS_VIEW_BACK: {
261 Lib3dsChunk c;
262 c.chunk = CHK_VIEW_BACK;
263 c.size = 22;
264 lib3ds_chunk_write(&c, io);
265 lib3ds_io_write_vector(io, viewport->default_position);
266 lib3ds_io_write_float(io, viewport->default_width);
267 break;
268 }
269
270 case LIB3DS_VIEW_USER: {
271 Lib3dsChunk c;
272 c.chunk = CHK_VIEW_USER;
273 c.size = 34;
274 lib3ds_chunk_write(&c, io);
275 lib3ds_io_write_vector(io, viewport->default_position);
276 lib3ds_io_write_float(io, viewport->default_width);
277 lib3ds_io_write_float(io, viewport->default_horiz_angle);
278 lib3ds_io_write_float(io, viewport->default_vert_angle);
279 lib3ds_io_write_float(io, viewport->default_roll_angle);
280 break;
281 }
282
283 case LIB3DS_VIEW_CAMERA: {
284 Lib3dsChunk c;
285 c.chunk = CHK_VIEW_CAMERA;
286 c.size = 17;
287 lib3ds_chunk_write(&c, io);
288 lib3ds_io_write(io, viewport->default_camera, 11);
289 break;
290 }
291 }
292
293 lib3ds_chunk_write_end(&c, io);
294 }
295 }
296
CHK_VIEW_USER
Definition: lib3ds_impl.h:282
lib3ds_io_write_intw
void lib3ds_io_write_intw(Lib3dsIo *io, int16_t w)
Definition: lib3ds_io.c:368
Lib3dsViewport::layout_position
unsigned short layout_position[2]
Definition: lib3ds.h:163
Lib3dsViewport::layout_swap_view
int layout_swap_view
Definition: lib3ds.h:162
LIB3DS_VIEW_TOP
Definition: lib3ds.h:114
lib3ds_io_read_intw
int16_t lib3ds_io_read_intw(Lib3dsIo *io)
Definition: lib3ds_io.c:203
CHK_VIEW_RIGHT
Definition: lib3ds_impl.h:279
chunk
else Out of place iCCP chunk
Definition: pngrutil.c:1260
lib3ds_io_read
size_t lib3ds_io_read(Lib3dsIo *io, void *buffer, size_t size)
Definition: lib3ds_io.c:72
Lib3dsViewport::layout_style
int layout_style
Definition: lib3ds.h:158
Lib3dsViewport::default_roll_angle
float default_roll_angle
Definition: lib3ds.h:172
CHK_VIEWPORT_DATA
Definition: lib3ds_impl.h:289
Lib3dsChunk
Definition: lib3ds_impl.h:295
Lib3dsViewport::default_vert_angle
float default_vert_angle
Definition: lib3ds.h:171
Lib3dsViewport::default_position
float default_position[3]
Definition: lib3ds.h:168
LIB3DS_VIEW_RIGHT
Definition: lib3ds.h:117
uint16_t
unsigned short uint16_t
Definition: SDL_config_windows.h:60
Lib3dsView::size
short size[2]
Definition: lib3ds.h:146
lib3ds_viewport_write
void lib3ds_viewport_write(Lib3dsViewport *viewport, Lib3dsIo *io)
Definition: lib3ds_viewport.c:153
Lib3dsView::type
int type
Definition: lib3ds.h:143
LIB3DS_VIEW_USER
Definition: lib3ds.h:120
CHK_VIEWPORT_DATA_3
Definition: lib3ds_impl.h:290
lib3ds_io_read_vector
void lib3ds_io_read_vector(Lib3dsIo *io, float v[3])
Definition: lib3ds_io.c:258
CHK_VIEW_BOTTOM
Definition: lib3ds_impl.h:277
memset
#define memset
Definition: SDL_malloc.c:633
lib3ds_viewport_read
void lib3ds_viewport_read(Lib3dsViewport *viewport, Lib3dsIo *io)
Definition: lib3ds_viewport.c:22
lib3ds_chunk_unknown
void lib3ds_chunk_unknown(uint16_t chunk, Lib3dsIo *io)
Definition: lib3ds_chunk.c:140
LIB3DS_LAYOUT_MAX_VIEWS
#define LIB3DS_LAYOUT_MAX_VIEWS
Definition: lib3ds.h:154
Lib3dsView::vert_angle
float vert_angle
Definition: lib3ds.h:150
Lib3dsChunk::size
uint32_t size
Definition: lib3ds_impl.h:297
lib3ds_io_write
size_t lib3ds_io_write(Lib3dsIo *io, const void *buffer, size_t size)
Definition: lib3ds_io.c:82
LIB3DS_VIEW_BACK
Definition: lib3ds.h:119
lib3ds_chunk_read_next
uint16_t lib3ds_chunk_read_next(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:68
CHK_VIEWPORT_SIZE
Definition: lib3ds_impl.h:291
CHK_VIEW_BACK
Definition: lib3ds_impl.h:281
CHK_VIEW_LEFT
Definition: lib3ds_impl.h:278
Lib3dsView::axis_lock
unsigned axis_lock
Definition: lib3ds.h:144
lib3ds_chunk_write_start
void lib3ds_chunk_write_start(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:119
lib3ds_io_write_vector
void lib3ds_io_write_vector(Lib3dsIo *io, float v[3])
Definition: lib3ds_io.c:422
Lib3dsViewport::default_width
float default_width
Definition: lib3ds.h:169
Lib3dsViewport::layout_nviews
int layout_nviews
Definition: lib3ds.h:165
Lib3dsViewport::layout_views
Lib3dsView layout_views[LIB3DS_LAYOUT_MAX_VIEWS]
Definition: lib3ds.h:166
lib3ds_io_write_float
void lib3ds_io_write_float(Lib3dsIo *io, float l)
Definition: lib3ds_io.c:402
Lib3dsViewport::layout_active
int layout_active
Definition: lib3ds.h:159
LIB3DS_VIEW_LEFT
Definition: lib3ds.h:116
LIB3DS_VIEW_FRONT
Definition: lib3ds.h:118
Lib3dsView::horiz_angle
float horiz_angle
Definition: lib3ds.h:149
Lib3dsViewport::default_type
int default_type
Definition: lib3ds.h:167
LIB3DS_VIEW_CAMERA
Definition: lib3ds.h:122
CHK_DEFAULT_VIEW
Definition: lib3ds_impl.h:275
Lib3dsViewport::layout_size
unsigned short layout_size[2]
Definition: lib3ds.h:164
c
const GLfloat * c
Definition: glew.h:14913
Lib3dsViewport::layout_swap
int layout_swap
Definition: lib3ds.h:160
CHK_VIEW_CAMERA
Definition: lib3ds_impl.h:283
Lib3dsView::position
short position[2]
Definition: lib3ds.h:145
Lib3dsView::camera
char camera[11]
Definition: lib3ds.h:151
lib3ds_io_read_word
uint16_t lib3ds_io_read_word(Lib3dsIo *io)
Definition: lib3ds_io.c:156
lib3ds_io_read_float
float lib3ds_io_read_float(Lib3dsIo *io)
Definition: lib3ds_io.c:237
lib3ds_chunk_read_end
void lib3ds_chunk_read_end(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:96
Lib3dsViewport::default_camera
char default_camera[64]
Definition: lib3ds.h:173
lib3ds_chunk_read_tell
void lib3ds_chunk_read_tell(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:62
Lib3dsViewport::layout_swap_prior
int layout_swap_prior
Definition: lib3ds.h:161
CHK_VIEW_TOP
Definition: lib3ds_impl.h:276
Lib3dsView::zoom
float zoom
Definition: lib3ds.h:147
Lib3dsView::center
float center[3]
Definition: lib3ds.h:148
Lib3dsIo
Definition: lib3ds.h:56
CHK_VIEW_FRONT
Definition: lib3ds_impl.h:280
Lib3dsViewport
Definition: lib3ds.h:157
lib3ds_chunk_write
void lib3ds_chunk_write(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:111
lib3ds_chunk_read_start
void lib3ds_chunk_read_start(Lib3dsChunk *c, uint16_t chunk, Lib3dsIo *io)
Definition: lib3ds_chunk.c:50
CHK_VIEWPORT_LAYOUT
Definition: lib3ds_impl.h:288
Lib3dsChunk::chunk
uint16_t chunk
Definition: lib3ds_impl.h:296
i
int i
Definition: pngrutil.c:1377
LIB3DS_VIEW_BOTTOM
Definition: lib3ds.h:115
lib3ds_impl.h
lib3ds_chunk_write_end
void lib3ds_chunk_write_end(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:129
Lib3dsViewport::default_horiz_angle
float default_horiz_angle
Definition: lib3ds.h:170
lib3ds_io_write_word
void lib3ds_io_write_word(Lib3dsIo *io, uint16_t w)
Definition: lib3ds_io.c:322