1 /* 2 * GPAC - Multimedia Framework C SDK 3 * 4 * Authors: Jean Le Feuvre 5 * Copyright (c) Telecom ParisTech 2000-2012 6 * All rights reserved 7 * 8 * This file is part of GPAC / Scene Compositor sub-project 9 * 10 * GPAC is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU Lesser General Public License as published by 12 * the Free Software Foundation; either version 2, or (at your option) 13 * any later version. 14 * 15 * GPAC is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License for more details. 19 * 20 * You should have received a copy of the GNU Lesser General Public 21 * License along with this library; see the file COPYING. If not, write to 22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 23 * 24 */ 25 26 #ifndef _CAMERA_H_ 27 #define _CAMERA_H_ 28 29 //#include <gpac/internal/compositor_dev.h> 30 #include <gpac/scenegraph_vrml.h> 31 32 /*camera flags*/ 33 enum 34 { 35 /*if set frustum needs to be recomputed 36 we avoid computing it at each frame/interaction since that's a lot of matrix maths*/ 37 CAM_IS_DIRTY = 1, 38 /*if set when ortho, indicates the viewport matrix shall be used when computing modelview (2D only)*/ 39 CAM_HAS_VIEWPORT = 1<<2, 40 /*if set when ortho to disable LookAt mode*/ 41 CAM_NO_LOOKAT = 1<<3, 42 }; 43 44 enum 45 { 46 /*only valid at root node*/ 47 CULL_NOT_SET = 0, 48 /*subtree completely outside view vol*/ 49 CULL_OUTSIDE, 50 /*subtree completely inside view vol*/ 51 CULL_INSIDE, 52 /*subtree overlaps view vol - FIXME: would be nice to keep track of intersecting planes*/ 53 CULL_INTERSECTS 54 }; 55 56 /*navigation info flags - non-VRML ones are simply blaxxun contact ones */ 57 enum 58 { 59 /*headlight is on*/ 60 NAV_HEADLIGHT = 1, 61 /*navigtion is selectable*/ 62 NAV_SELECTABLE = 1<<1, 63 /*any navigation (eg, user-interface navigation control allowed)*/ 64 NAV_ANY = 1<<2 65 }; 66 67 /*frustum object*/ 68 enum 69 { 70 FRUS_NEAR_PLANE = 0, 71 FRUS_FAR_PLANE, 72 FRUS_LEFT_PLANE, 73 FRUS_RIGHT_PLANE, 74 FRUS_BOTTOM_PLANE, 75 FRUS_TOP_PLANE 76 }; 77 78 79 80 enum 81 { 82 /*nothing detected*/ 83 CF_NONE = 0, 84 /*collision detected*/ 85 CF_COLLISION = 1, 86 /*gravity detecion enabled*/ 87 CF_DO_GRAVITY = (1<<1), 88 /*gravity detected*/ 89 CF_GRAVITY = (1<<2), 90 /*viewpoint is stored at end of animation*/ 91 CF_STORE_VP = (1<<3), 92 }; 93 94 typedef struct _camera 95 { 96 /*this flag MUST be set by the owner of the camera*/ 97 Bool is_3D; 98 99 u32 flags; 100 101 /*viewport info*/ 102 GF_Rect vp, proj_vp; 103 /*not always same as VP due to aspect ratio*/ 104 Fixed width, height; 105 Fixed z_near, z_far; 106 107 /*current vectors*/ 108 Fixed fieldOfView; 109 SFVec3f up, position, target; 110 111 /*initial vp for reset*/ 112 SFVec3f vp_position; 113 SFRotation vp_orientation; 114 Fixed vp_fov, vp_dist; 115 116 /*animation path*/ 117 SFVec3f start_pos, end_pos; 118 SFRotation start_ori, end_ori; 119 Fixed start_fov, end_fov; 120 /*for 2D cameras we never animate except for vp reset*/ 121 Fixed start_zoom, end_zoom; 122 SFVec2f start_trans, start_rot; 123 124 /*center of examine movement*/ 125 SFVec3f examine_center; 126 127 /*anim*/ 128 u32 anim_len, anim_start; 129 Bool jumping; 130 Fixed dheight; 131 132 /*navigation info - overwridden by any bindable NavigationInfo node*/ 133 u32 navigation_flags, navigate_mode; 134 SFVec3f avatar_size; 135 Fixed visibility, speed; 136 Bool had_nav_info; 137 u32 had_viewpoint; 138 139 /*last camera position before collision& gravity detection*/ 140 SFVec3f last_pos; 141 u32 collide_flags; 142 /*collision point in world coord*/ 143 SFVec3f collide_point; 144 /*collide dist in world coord, used to check if we have a closer collision*/ 145 Fixed collide_dist; 146 /*ground in world coord*/ 147 SFVec3f ground_point; 148 /*ground dist in world coord, used to check if we have a closer ground*/ 149 Fixed ground_dist; 150 /*for obstacle detection*/ 151 Bool last_had_ground; 152 Bool last_had_col; 153 154 /*projection & modelview matrices*/ 155 GF_Matrix projection, modelview; 156 /*unprojection matrix = INV(P*M) used for screen->world compute*/ 157 GF_Matrix unprojection; 158 /*viewport matrix*/ 159 GF_Matrix viewport; 160 /*frustum planes*/ 161 GF_Plane planes[6]; 162 /*p vertex idx per plane (for bbox-frustum intersection checks)*/ 163 u32 p_idx[6]; 164 /*frustrum bounding sphere (for sphere-sphere frustum intersection checks)*/ 165 SFVec3f center; 166 Fixed radius; 167 168 GF_BBox world_bbox; 169 } GF_Camera; 170 171 /*invalidate camera to force recompute of all params*/ 172 void camera_invalidate(GF_Camera *cam); 173 /*updates camera. user transform is only used in 2D to set global user zoom/pan/translate*/ 174 void camera_update(GF_Camera *cam, GF_Matrix2D *user_transform, Bool center_coords); 175 /*updates camera. user transform is only used in 2D to set global user zoom/pan/translate + stereo param*/ 176 void camera_update_stereo(GF_Camera *cam, GF_Matrix2D *user_transform, Bool center_coords, Fixed horizontal_shift, Fixed viewing_distance, Fixed viewing_distance_offset, u32 camlay); 177 /*reset to last viewport*/ 178 void camera_reset_viewpoint(GF_Camera *cam, Bool animate); 179 /*move camera to given vp*/ 180 void camera_move_to(GF_Camera *cam, SFVec3f pos, SFVec3f target, SFVec3f up); 181 Bool camera_animate(GF_Camera *cam, void *compositor); 182 void camera_stop_anim(GF_Camera *cam); 183 /*start jump mode*/ 184 void camera_jump(GF_Camera *cam); 185 186 void camera_set_vectors(GF_Camera *cam, SFVec3f pos, SFRotation ori, Fixed fov); 187 188 SFRotation camera_get_orientation(SFVec3f pos, SFVec3f target, SFVec3f up); 189 SFVec3f camera_get_pos_dir(GF_Camera *cam); 190 SFVec3f camera_get_target_dir(GF_Camera *cam); 191 SFVec3f camera_get_right_dir(GF_Camera *cam); 192 void camera_set_2d(GF_Camera *cam); 193 194 #endif 195 196