zenilib: zenilib/jni/external/lib3ds/src/lib3ds_camera.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_camera.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
31 Lib3dsCamera*
32 lib3ds_camera_new(const char *name) {
33 Lib3dsCamera *camera;
34
35 assert(name);
36 assert(strlen(name) < 64);
37
38 camera = (Lib3dsCamera*)calloc(sizeof(Lib3dsCamera), 1);
39 if (!camera) {
40 return(0);
41 }
42 strcpy(camera->name, name);
43 camera->fov = 45.0f;
44 return(camera);
45 }
46
47
53 void
54 lib3ds_camera_free(Lib3dsCamera *camera) {
55 memset(camera, 0, sizeof(Lib3dsCamera));
56 free(camera);
57 }
58
59
71 void
72 lib3ds_camera_read(Lib3dsCamera *camera, Lib3dsIo *io) {
73 Lib3dsChunk c;
74 uint16_t chunk;
75
76 lib3ds_chunk_read_start(&c, CHK_N_CAMERA, io);
77
78 {
79 int i;
80 for (i = 0; i < 3; ++i) {
81 camera->position[i] = lib3ds_io_read_float(io);
82 }
83 for (i = 0; i < 3; ++i) {
84 camera->target[i] = lib3ds_io_read_float(io);
85 }
86 }
87 camera->roll = lib3ds_io_read_float(io);
88 {
89 float s;
90 s = lib3ds_io_read_float(io);
91 if (fabs(s) < LIB3DS_EPSILON) {
92 camera->fov = 45.0;
93 } else {
94 camera->fov = 2400.0f / s;
95 }
96 }
97 lib3ds_chunk_read_tell(&c, io);
98
99 while ((chunk = lib3ds_chunk_read_next(&c, io)) != 0) {
100 switch (chunk) {
101 case CHK_CAM_SEE_CONE: {
102 camera->see_cone = TRUE;
103 }
104 break;
105
106 case CHK_CAM_RANGES: {
107 camera->near_range = lib3ds_io_read_float(io);
108 camera->far_range = lib3ds_io_read_float(io);
109 }
110 break;
111
112 default:
113 lib3ds_chunk_unknown(chunk, io);
114 }
115 }
116
117 lib3ds_chunk_read_end(&c, io);
118 }
119
120
132 void
133 lib3ds_camera_write(Lib3dsCamera *camera, Lib3dsIo *io) {
134 Lib3dsChunk c;
135
136 c.chunk = CHK_N_CAMERA;
137 lib3ds_chunk_write_start(&c, io);
138
139 lib3ds_io_write_vector(io, camera->position);
140 lib3ds_io_write_vector(io, camera->target);
141 lib3ds_io_write_float(io, camera->roll);
142 if (fabs(camera->fov) < LIB3DS_EPSILON) {
143 lib3ds_io_write_float(io, 2400.0f / 45.0f);
144 } else {
145 lib3ds_io_write_float(io, 2400.0f / camera->fov);
146 }
147
148 if (camera->see_cone) {
149 Lib3dsChunk c;
150 c.chunk = CHK_CAM_SEE_CONE;
151 c.size = 6;
152 lib3ds_chunk_write(&c, io);
153 }
154 {
155 Lib3dsChunk c;
156 c.chunk = CHK_CAM_RANGES;
157 c.size = 14;
158 lib3ds_chunk_write(&c, io);
159 lib3ds_io_write_float(io, camera->near_range);
160 lib3ds_io_write_float(io, camera->far_range);
161 }
162
163 lib3ds_chunk_write_end(&c, io);
164 }
165
Lib3dsCamera
Definition: lib3ds.h:283
s
GLdouble s
Definition: glew.h:1376
chunk
else Out of place iCCP chunk
Definition: pngrutil.c:1260
Lib3dsChunk
Definition: lib3ds_impl.h:295
f
GLclampf f
Definition: glew.h:3390
Lib3dsCamera::name
char name[64]
Definition: lib3ds.h:286
uint16_t
unsigned short uint16_t
Definition: SDL_config_windows.h:60
free
SDL_EventEntry * free
Definition: SDL_events.c:80
lib3ds_camera_read
void lib3ds_camera_read(Lib3dsCamera *camera, Lib3dsIo *io)
Definition: lib3ds_camera.c:72
memset
#define memset
Definition: SDL_malloc.c:633
lib3ds_camera_new
LIB3DSAPI Lib3dsCamera * lib3ds_camera_new(const char *name)
Definition: lib3ds_camera.c:32
Lib3dsCamera::position
float position[3]
Definition: lib3ds.h:288
CHK_CAM_RANGES
Definition: lib3ds_impl.h:201
lib3ds_chunk_unknown
void lib3ds_chunk_unknown(uint16_t chunk, Lib3dsIo *io)
Definition: lib3ds_chunk.c:140
name
EGLImageKHR EGLint * name
Definition: eglext.h:284
Lib3dsCamera::see_cone
int see_cone
Definition: lib3ds.h:292
assert
#define assert(x)
Definition: SDL_malloc.c:1234
calloc
#define calloc
Definition: SDL_malloc.c:636
Lib3dsChunk::size
uint32_t size
Definition: lib3ds_impl.h:297
lib3ds_chunk_read_next
uint16_t lib3ds_chunk_read_next(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:68
Lib3dsCamera::roll
float roll
Definition: lib3ds.h:290
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
lib3ds_camera_free
LIB3DSAPI void lib3ds_camera_free(Lib3dsCamera *mesh)
Definition: lib3ds_camera.c:54
lib3ds_io_write_float
void lib3ds_io_write_float(Lib3dsIo *io, float l)
Definition: lib3ds_io.c:402
Lib3dsCamera::far_range
float far_range
Definition: lib3ds.h:294
CHK_N_CAMERA
Definition: lib3ds_impl.h:199
c
const GLfloat * c
Definition: glew.h:14913
Lib3dsCamera::fov
float fov
Definition: lib3ds.h:291
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
lib3ds_chunk_read_tell
void lib3ds_chunk_read_tell(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:62
LIB3DS_EPSILON
#define LIB3DS_EPSILON
Definition: lib3ds_impl.h:55
Lib3dsIo
Definition: lib3ds.h:56
CHK_CAM_SEE_CONE
Definition: lib3ds_impl.h:200
Lib3dsCamera::near_range
float near_range
Definition: lib3ds.h:293
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
Lib3dsChunk::chunk
uint16_t chunk
Definition: lib3ds_impl.h:296
i
int i
Definition: pngrutil.c:1377
Lib3dsCamera::target
float target[3]
Definition: lib3ds.h:289
lib3ds_camera_write
void lib3ds_camera_write(Lib3dsCamera *camera, Lib3dsIo *io)
Definition: lib3ds_camera.c:133
fabs
double fabs(double x)
Definition: s_fabs.c:29
TRUE
#define TRUE
Definition: ftobjs.h:53
lib3ds_impl.h
lib3ds_chunk_write_end
void lib3ds_chunk_write_end(Lib3dsChunk *c, Lib3dsIo *io)
Definition: lib3ds_chunk.c:129