Blender  V2.59
ED_view3d.h
Go to the documentation of this file.
00001 /*
00002  * $Id: ED_view3d.h 37327 2011-06-09 03:56:32Z campbellbarton $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version. 
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2008 Blender Foundation.
00021  * All rights reserved.
00022  *
00023  * 
00024  * Contributor(s): Blender Foundation
00025  *
00026  * ***** END GPL LICENSE BLOCK *****
00027  */
00028 
00033 #ifndef ED_VIEW3D_H
00034 #define ED_VIEW3D_H
00035 
00036 /* ********* exports for space_view3d/ module ********** */
00037 struct ARegion;
00038 struct bContext;
00039 struct BezTriple;
00040 struct bglMats;
00041 struct BoundBox;
00042 struct BPoint;
00043 struct EditEdge;
00044 struct EditFace;
00045 struct EditVert;
00046 struct ImBuf;
00047 struct Main;
00048 struct Nurb;
00049 struct Object;
00050 struct rcti;
00051 struct RegionView3D;
00052 struct Scene;
00053 struct View3D;
00054 struct ViewContext;
00055 struct wmWindow;
00056 
00057 
00058 /* for derivedmesh drawing callbacks, for view3d_select, .... */
00059 typedef struct ViewContext {
00060         struct Scene *scene;
00061         struct Object *obact;
00062         struct Object *obedit;
00063         struct ARegion *ar;
00064         struct View3D *v3d;
00065         struct RegionView3D *rv3d;
00066         struct EditMesh *em;
00067         int mval[2];
00068 } ViewContext;
00069 
00070 typedef struct ViewDepths {
00071         unsigned short w, h;
00072         short x, y; /* only for temp use for sub-rects, added to ar->winx/y */
00073         float *depths;
00074         double depth_range[2];
00075         
00076         char damaged;
00077 } ViewDepths;
00078 
00079 
00080 float *give_cursor(struct Scene *scene, struct View3D *v3d);
00081 
00082 int initgrabz(struct RegionView3D *rv3d, float x, float y, float z);
00083 
00091 void ED_view3d_win_to_3d(struct ARegion *ar, const float depth_pt[3], const float mval[2], float out[3]);
00092 
00101 void ED_view3d_win_to_delta(struct ARegion *ar, const float mval[2], float out[3]);
00102 
00111 void ED_view3d_win_to_vector(struct ARegion *ar, const float mval[2], float out[3]);
00112 
00125 void ED_view3d_win_to_segment_clip(struct ARegion *ar, struct View3D *v3d, const float mval[2], float ray_start[3], float ray_end[3]);
00126 
00139 void ED_view3d_win_to_ray(struct ARegion *ar, struct View3D *v3d, const float mval[2], float ray_start[3], float ray_normal[3]);
00140 
00148 void ED_view3d_global_to_vector(struct RegionView3D *rv3d, const float coord[3], float vec[3]);
00149 
00158 void ED_view3d_to_m4(float mat[][4], const float ofs[3], const float quat[4], const float dist);
00159 
00167 void ED_view3d_from_m4(float mat[][4], float ofs[3], float quat[4], float *dist);
00168 
00176 void ED_view3d_from_object(struct Object *ob, float ofs[3], float quat[4], float *dist, float *lens);
00177 
00185 void ED_view3d_to_object(struct Object *ob, const float ofs[3], const float quat[4], const float dist);
00186 
00187 #if 0 /* UNUSED */
00188 void view3d_unproject(struct bglMats *mats, float out[3], const short x, const short y, const float z);
00189 #endif
00190 
00191 /* Depth buffer */
00192 void ED_view3d_depth_update(struct ARegion *ar);
00193 float ED_view3d_depth_read_cached(struct ViewContext *vc, int x, int y);
00194 void ED_view3d_depth_tag_update(struct RegionView3D *rv3d);
00195 
00196 /* Projection */
00197 #define IS_CLIPPED        12000
00198 
00199 void ED_view3d_calc_clipping(struct BoundBox *bb, float planes[4][4], struct bglMats *mats, struct rcti *rect);
00200 
00201 void project_short(struct ARegion *ar, const float vec[3], short adr[2]);
00202 void project_short_noclip(struct ARegion *ar, const float vec[3], short adr[2]);
00203 
00204 void project_int(struct ARegion *ar, const float vec[3], int adr[2]);
00205 void project_int_noclip(struct ARegion *ar, const float vec[3], int adr[2]);
00206 
00207 void project_float(struct ARegion *ar, const float vec[3], float adr[2]);
00208 void project_float_noclip(struct ARegion *ar, const float vec[3], float adr[2]);
00209 
00210 void ED_view3d_ob_clip_range_get(struct Object *ob, float *lens, float *clipsta, float *clipend);
00211 int ED_view3d_clip_range_get(struct View3D *v3d, struct RegionView3D *rv3d, float *clipsta, float *clipend);
00212 int ED_view3d_viewplane_get(struct View3D *v3d, struct RegionView3D *rv3d, int winxi, int winyi, struct rctf *viewplane, float *clipsta, float *clipend, float *pixsize);
00213 void ED_view3d_ob_project_mat_get(struct RegionView3D *v3d, struct Object *ob, float pmat[4][4]);
00214 void ED_view3d_project_float(struct ARegion *a, const float vec[3], float adr[2], float mat[4][4]);
00215 void ED_view3d_calc_camera_border(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, struct rctf *viewborder_r, short do_shift);
00216 
00217 /* drawobject.c iterators */
00218 void mesh_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct EditVert *eve, int x, int y, int index), void *userData, int clipVerts);
00219 void mesh_foreachScreenEdge(struct ViewContext *vc, void (*func)(void *userData, struct EditEdge *eed, int x0, int y0, int x1, int y1, int index), void *userData, int clipVerts);
00220 void mesh_foreachScreenFace(struct ViewContext *vc, void (*func)(void *userData, struct EditFace *efa, int x, int y, int index), void *userData);
00221 void nurbs_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct Nurb *nu, struct BPoint *bp, struct BezTriple *bezt, int beztindex, int x, int y), void *userData);
00222 void lattice_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct BPoint *bp, int x, int y), void *userData);
00223 
00224 void ED_view3d_local_clipping(struct RegionView3D *rv3d, float mat[][4]);
00225 int ED_view3d_test_clipping(struct RegionView3D *rv3d, const float vec[3], const int local);
00226 void ED_view3d_align_axis_to_vector(struct View3D *v3d, struct RegionView3D *rv3d, int axisidx, float vec[3]);
00227 float ED_view3d_pixel_size(struct RegionView3D *rv3d, const float co[3]);
00228 
00229 void drawcircball(int mode, const float cent[3], float rad, float tmat[][4]);
00230 
00231 /* backbuffer select and draw support */
00232 void view3d_validate_backbuf(struct ViewContext *vc);
00233 struct ImBuf *view3d_read_backbuf(struct ViewContext *vc, short xmin, short ymin, short xmax, short ymax);
00234 unsigned int view3d_sample_backbuf_rect(struct ViewContext *vc, const int mval[2], int size, unsigned int min, unsigned int max, int *dist, short strict,
00235                                                                                 void *handle, unsigned int (*indextest)(void *handle, unsigned int index));
00236 unsigned int view3d_sample_backbuf(struct ViewContext *vc, int x, int y);
00237 
00238 /* draws and does a 4x4 sample */
00239 int ED_view3d_autodist(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, const int mval[2], float mouse_worldloc[3]);
00240 
00241 /* only draw so ED_view3d_autodist_simple can be called many times after */
00242 int ED_view3d_autodist_init(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, int mode);
00243 int ED_view3d_autodist_simple(struct ARegion *ar, const int mval[2], float mouse_worldloc[3], int margin, float *force_depth);
00244 int ED_view3d_autodist_depth(struct ARegion *ar, const int mval[2], int margin, float *depth);
00245 int ED_view3d_autodist_depth_seg(struct ARegion *ar, const int mval_sta[2], const int mval_end[2], int margin, float *depth);
00246 
00247 /* select */
00248 #define MAXPICKBUF      10000
00249 short view3d_opengl_select(struct ViewContext *vc, unsigned int *buffer, unsigned int bufsize, rcti *input);
00250 
00251 void view3d_set_viewcontext(struct bContext *C, struct ViewContext *vc);
00252 void view3d_operator_needs_opengl(const struct bContext *C);
00253 void view3d_region_operator_needs_opengl(struct wmWindow *win, struct ARegion *ar);
00254 int view3d_get_view_aligned_coordinate(struct ViewContext *vc, float fp[3], const int mval[2], const short do_fallback);
00255 void view3d_get_transformation(struct ARegion *ar, struct RegionView3D *rv3d, struct Object *ob, struct bglMats *mats);
00256 
00257 /* XXX should move to BLI_math */
00258 int edge_inside_circle(short centx, short centy, short rad, short x1, short y1, short x2, short y2);
00259 int lasso_inside(int mcords[][2], short moves, int sx, int sy);
00260 int lasso_inside_edge(int mcords[][2], short moves, int x0, int y0, int x1, int y1);
00261 
00262 /* get 3d region from context, also if mouse is in header or toolbar */
00263 struct RegionView3D *ED_view3d_context_rv3d(struct bContext *C);
00264 struct ARegion *ED_view3d_context_region_unlock(struct bContext *C);
00265 int ED_operator_rv3d_unlock_poll(struct bContext *C);
00266 
00267 void ED_view3d_init_mats_rv3d(struct Object *ob, struct RegionView3D *rv3d);
00268 void ED_view3d_init_mats_rv3d_gl(struct Object *ob, struct RegionView3D *rv3d);
00269 
00270 int ED_view3d_scene_layer_set(int lay, const int *values, int *active);
00271 
00272 int ED_view3d_context_activate(struct bContext *C);
00273 void ED_view3d_draw_offscreen(struct Scene *scene, struct View3D *v3d, struct ARegion *ar,
00274         int winx, int winy, float viewmat[][4], float winmat[][4]);
00275 
00276 struct ImBuf *ED_view3d_draw_offscreen_imbuf(struct Scene *scene, struct View3D *v3d, struct ARegion *ar, int sizex, int sizey, unsigned int flag, char err_out[256]);
00277 struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Scene *scene, struct Object *camera, int width, int height, unsigned int flag, int drawtype, char err_out[256]);
00278 
00279 
00280 Base *ED_view3d_give_base_under_cursor(struct bContext *C, const int mval[2]);
00281 void ED_view3d_quadview_update(struct ScrArea *sa, struct ARegion *ar, short do_clip);
00282 int ED_view3d_lock(struct RegionView3D *rv3d);
00283 
00284 unsigned int ED_view3d_datamask(struct Scene *scene, struct View3D *v3d);
00285 unsigned int ED_viewedit_datamask(struct bScreen *screen);
00286 
00287 /* camera lock functions */
00288 int ED_view3d_camera_lock_check(struct View3D *v3d, struct RegionView3D *rv3d);
00289 /* copy the camera to the view before starting a view transformation */
00290 void ED_view3d_camera_lock_init(struct View3D *v3d, struct RegionView3D *rv3d);
00291 /* copy the view to the camera */
00292 void ED_view3d_camera_lock_sync(struct View3D *v3d, struct RegionView3D *rv3d);
00293 
00294 #endif /* ED_VIEW3D_H */