Blender V2.61 - r43446

ED_view3d.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version. 
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2008 Blender Foundation.
00019  * All rights reserved.
00020  *
00021  * 
00022  * Contributor(s): Blender Foundation
00023  *
00024  * ***** END GPL LICENSE BLOCK *****
00025  */
00026 
00031 #ifndef ED_VIEW3D_H
00032 #define ED_VIEW3D_H
00033 
00034 /* ********* exports for space_view3d/ module ********** */
00035 struct ARegion;
00036 struct bContext;
00037 struct BezTriple;
00038 struct bglMats;
00039 struct BoundBox;
00040 struct BPoint;
00041 struct EditEdge;
00042 struct EditFace;
00043 struct EditVert;
00044 struct ImBuf;
00045 struct Main;
00046 struct Nurb;
00047 struct Object;
00048 struct rcti;
00049 struct RegionView3D;
00050 struct Scene;
00051 struct View3D;
00052 struct ViewContext;
00053 struct wmWindow;
00054 struct MVert;
00055 
00056 
00057 /* for derivedmesh drawing callbacks, for view3d_select, .... */
00058 typedef struct ViewContext {
00059     struct Scene *scene;
00060     struct Object *obact;
00061     struct Object *obedit;
00062     struct ARegion *ar;
00063     struct View3D *v3d;
00064     struct RegionView3D *rv3d;
00065     struct EditMesh *em;
00066     int mval[2];
00067 } ViewContext;
00068 
00069 typedef struct ViewDepths {
00070     unsigned short w, h;
00071     short x, y; /* only for temp use for sub-rects, added to ar->winx/y */
00072     float *depths;
00073     double depth_range[2];
00074     
00075     char damaged;
00076 } ViewDepths;
00077 
00078 /* enum for passing to foreach functions to test RV3D_CLIPPING */
00079 typedef enum eV3DClipTest {
00080     V3D_CLIP_TEST_OFF =            0, /* clipping is off */
00081     V3D_CLIP_TEST_RV3D_CLIPPING =  1, /* clip single points */
00082     V3D_CLIP_TEST_REGION =         2  /* use for edges to check if both verts are in the view, but not RV3D_CLIPPING */
00083 } eV3DClipTest;
00084 
00085 float *give_cursor(struct Scene *scene, struct View3D *v3d);
00086 
00087 int initgrabz(struct RegionView3D *rv3d, float x, float y, float z);
00088 
00096 void ED_view3d_win_to_3d(struct ARegion *ar, const float depth_pt[3], const float mval[2], float out[3]);
00097 
00106 void ED_view3d_win_to_delta(struct ARegion *ar, const float mval[2], float out[3]);
00107 
00116 void ED_view3d_win_to_vector(struct ARegion *ar, const float mval[2], float out[3]);
00117 
00130 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]);
00131 
00143 void ED_view3d_win_to_ray(struct ARegion *ar, struct View3D *v3d, const float mval[2], float ray_start[3], float ray_normal[3]);
00144 
00152 void ED_view3d_global_to_vector(struct RegionView3D *rv3d, const float coord[3], float vec[3]);
00153 
00162 void ED_view3d_to_m4(float mat[][4], const float ofs[3], const float quat[4], const float dist);
00163 
00171 void ED_view3d_from_m4(float mat[][4], float ofs[3], float quat[4], float *dist);
00172 
00181 void ED_view3d_from_object(struct Object *ob, float ofs[3], float quat[4], float *dist, float *lens);
00182 
00190 void ED_view3d_to_object(struct Object *ob, const float ofs[3], const float quat[4], const float dist);
00191 
00192 #if 0 /* UNUSED */
00193 void view3d_unproject(struct bglMats *mats, float out[3], const short x, const short y, const float z);
00194 #endif
00195 
00196 /* Depth buffer */
00197 void ED_view3d_depth_update(struct ARegion *ar);
00198 float ED_view3d_depth_read_cached(struct ViewContext *vc, int x, int y);
00199 void ED_view3d_depth_tag_update(struct RegionView3D *rv3d);
00200 
00201 /* Projection */
00202 #define IS_CLIPPED        12000
00203 
00204 void ED_view3d_calc_clipping(struct BoundBox *bb, float planes[4][4], struct bglMats *mats, const struct rcti *rect);
00205 
00206 void project_short(struct ARegion *ar, const float vec[3], short adr[2]);
00207 void project_short_noclip(struct ARegion *ar, const float vec[3], short adr[2]);
00208 
00209 void project_int(struct ARegion *ar, const float vec[3], int adr[2]);
00210 void project_int_noclip(struct ARegion *ar, const float vec[3], int adr[2]);
00211 
00212 void project_float(struct ARegion *ar, const float vec[3], float adr[2]);
00213 void project_float_noclip(struct ARegion *ar, const float vec[3], float adr[2]);
00214 
00215 int ED_view3d_clip_range_get(struct View3D *v3d, struct RegionView3D *rv3d, float *clipsta, float *clipend);
00216 int ED_view3d_viewplane_get(struct View3D *v3d, struct RegionView3D *rv3d, int winxi, int winyi, struct rctf *viewplane, float *clipsta, float *clipend);
00217 void ED_view3d_ob_project_mat_get(struct RegionView3D *v3d, struct Object *ob, float pmat[4][4]);
00218 void ED_view3d_project_float(const struct ARegion *a, const float vec[3], float adr[2], float mat[4][4]);
00219 void ED_view3d_calc_camera_border(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, struct rctf *viewborder_r, short no_shift);
00220 void ED_view3d_calc_camera_border_size(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, float size_r[2]);
00221 
00222 /* drawobject.c iterators */
00223 void mesh_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct EditVert *eve, int x, int y, int index), void *userData, eV3DClipTest clipVerts);
00224 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, eV3DClipTest clipVerts);
00225 void mesh_foreachScreenFace(struct ViewContext *vc, void (*func)(void *userData, struct EditFace *efa, int x, int y, int index), void *userData);
00226 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);
00227 void lattice_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct BPoint *bp, int x, int y), void *userData);
00228 
00229 void ED_view3d_local_clipping(struct RegionView3D *rv3d, float mat[][4]);
00230 int ED_view3d_test_clipping(struct RegionView3D *rv3d, const float vec[3], const int local);
00231 void ED_view3d_align_axis_to_vector(struct View3D *v3d, struct RegionView3D *rv3d, int axisidx, float vec[3]);
00232 float ED_view3d_pixel_size(struct RegionView3D *rv3d, const float co[3]);
00233 
00234 void drawcircball(int mode, const float cent[3], float rad, float tmat[][4]);
00235 
00236 /* backbuffer select and draw support */
00237 void view3d_validate_backbuf(struct ViewContext *vc);
00238 struct ImBuf *view3d_read_backbuf(struct ViewContext *vc, short xmin, short ymin, short xmax, short ymax);
00239 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,
00240                                         void *handle, unsigned int (*indextest)(void *handle, unsigned int index));
00241 unsigned int view3d_sample_backbuf(struct ViewContext *vc, int x, int y);
00242 
00243 /* draws and does a 4x4 sample */
00244 int ED_view3d_autodist(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, const int mval[2], float mouse_worldloc[3]);
00245 
00246 /* only draw so ED_view3d_autodist_simple can be called many times after */
00247 int ED_view3d_autodist_init(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, int mode);
00248 int ED_view3d_autodist_simple(struct ARegion *ar, const int mval[2], float mouse_worldloc[3], int margin, float *force_depth);
00249 int ED_view3d_autodist_depth(struct ARegion *ar, const int mval[2], int margin, float *depth);
00250 int ED_view3d_autodist_depth_seg(struct ARegion *ar, const int mval_sta[2], const int mval_end[2], int margin, float *depth);
00251 
00252 /* select */
00253 #define MAXPICKBUF      10000
00254 short view3d_opengl_select(struct ViewContext *vc, unsigned int *buffer, unsigned int bufsize, rcti *input);
00255 
00256 void view3d_set_viewcontext(struct bContext *C, struct ViewContext *vc);
00257 void view3d_operator_needs_opengl(const struct bContext *C);
00258 void view3d_region_operator_needs_opengl(struct wmWindow *win, struct ARegion *ar);
00259 int view3d_get_view_aligned_coordinate(struct ViewContext *vc, float fp[3], const int mval[2], const short do_fallback);
00260 void view3d_get_transformation(const struct ARegion *ar, struct RegionView3D *rv3d, struct Object *ob, struct bglMats *mats);
00261 
00262 /* XXX should move to BLI_math */
00263 int edge_inside_circle(short centx, short centy, short rad, short x1, short y1, short x2, short y2);
00264 int lasso_inside(int mcords[][2], short moves, int sx, int sy);
00265 int lasso_inside_edge(int mcords[][2], short moves, int x0, int y0, int x1, int y1);
00266 
00267 /* get 3d region from context, also if mouse is in header or toolbar */
00268 struct RegionView3D *ED_view3d_context_rv3d(struct bContext *C);
00269 int ED_view3d_context_user_region(struct bContext *C, struct View3D **v3d_r, struct ARegion **ar_r);
00270 int ED_operator_rv3d_user_region_poll(struct bContext *C);
00271 
00272 void ED_view3d_init_mats_rv3d(struct Object *ob, struct RegionView3D *rv3d);
00273 void ED_view3d_init_mats_rv3d_gl(struct Object *ob, struct RegionView3D *rv3d);
00274 
00275 int ED_view3d_scene_layer_set(int lay, const int *values, int *active);
00276 
00277 int ED_view3d_context_activate(struct bContext *C);
00278 void ED_view3d_draw_offscreen(struct Scene *scene, struct View3D *v3d, struct ARegion *ar,
00279     int winx, int winy, float viewmat[][4], float winmat[][4]);
00280 
00281 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]);
00282 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]);
00283 
00284 
00285 Base *ED_view3d_give_base_under_cursor(struct bContext *C, const int mval[2]);
00286 void ED_view3d_quadview_update(struct ScrArea *sa, struct ARegion *ar, short do_clip);
00287 int ED_view3d_lock(struct RegionView3D *rv3d);
00288 
00289 uint64_t ED_view3d_datamask(struct Scene *scene, struct View3D *v3d);
00290 uint64_t ED_view3d_screen_datamask(struct bScreen *screen);
00291 uint64_t ED_view3d_object_datamask(struct Scene *scene);
00292 
00293 /* camera lock functions */
00294 int ED_view3d_camera_lock_check(struct View3D *v3d, struct RegionView3D *rv3d);
00295 /* copy the camera to the view before starting a view transformation */
00296 void ED_view3d_camera_lock_init(struct View3D *v3d, struct RegionView3D *rv3d);
00297 /* copy the view to the camera, return TRUE if */
00298 int ED_view3d_camera_lock_sync(struct View3D *v3d, struct RegionView3D *rv3d);
00299 
00300 struct BGpic *ED_view3D_background_image_new(struct View3D *v3d);
00301 void ED_view3D_background_image_remove(struct View3D *v3d, struct BGpic *bgpic);
00302 void ED_view3D_background_image_clear(struct View3D *v3d);
00303 
00304 #endif /* ED_VIEW3D_H */