code cleanup:
- move object_iterators.c --> view3d_iterators. (ED_object.h had to include ED_view3d.h which isn't so nice) - move projection functions from view3d_view.c --> view3d_project.c (view3d_view was becoming a mishmash of utility functions and operators). - some some cmake includes as system-includes.
This commit is contained in:
6
extern/libmv/CMakeLists.txt
vendored
6
extern/libmv/CMakeLists.txt
vendored
@@ -28,14 +28,14 @@
|
|||||||
|
|
||||||
set(INC
|
set(INC
|
||||||
.
|
.
|
||||||
../Eigen3
|
|
||||||
third_party/ssba
|
|
||||||
third_party/ldl/Include
|
|
||||||
../colamd/Include
|
../colamd/Include
|
||||||
third_party/ceres/include
|
third_party/ceres/include
|
||||||
)
|
)
|
||||||
|
|
||||||
set(INC_SYS
|
set(INC_SYS
|
||||||
|
../Eigen3
|
||||||
|
third_party/ssba
|
||||||
|
third_party/ldl/Include
|
||||||
${PNG_INCLUDE_DIR}
|
${PNG_INCLUDE_DIR}
|
||||||
${ZLIB_INCLUDE_DIRS}
|
${ZLIB_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
|
6
extern/libmv/bundle.sh
vendored
6
extern/libmv/bundle.sh
vendored
@@ -124,14 +124,14 @@ cat > CMakeLists.txt << EOF
|
|||||||
|
|
||||||
set(INC
|
set(INC
|
||||||
.
|
.
|
||||||
../Eigen3
|
|
||||||
third_party/ssba
|
|
||||||
third_party/ldl/Include
|
|
||||||
../colamd/Include
|
../colamd/Include
|
||||||
third_party/ceres/include
|
third_party/ceres/include
|
||||||
)
|
)
|
||||||
|
|
||||||
set(INC_SYS
|
set(INC_SYS
|
||||||
|
../Eigen3
|
||||||
|
third_party/ssba
|
||||||
|
third_party/ldl/Include
|
||||||
\${PNG_INCLUDE_DIR}
|
\${PNG_INCLUDE_DIR}
|
||||||
\${ZLIB_INCLUDE_DIRS}
|
\${ZLIB_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
|
2
extern/libmv/third_party/ceres/bundle.sh
vendored
2
extern/libmv/third_party/ceres/bundle.sh
vendored
@@ -117,13 +117,13 @@ cat > CMakeLists.txt << EOF
|
|||||||
|
|
||||||
set(INC
|
set(INC
|
||||||
.
|
.
|
||||||
../../../Eigen3
|
|
||||||
include
|
include
|
||||||
internal
|
internal
|
||||||
../gflags
|
../gflags
|
||||||
)
|
)
|
||||||
|
|
||||||
set(INC_SYS
|
set(INC_SYS
|
||||||
|
../../../Eigen3
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SRC
|
set(SRC
|
||||||
|
@@ -29,11 +29,10 @@ set(INC
|
|||||||
../guardedalloc
|
../guardedalloc
|
||||||
../memutil
|
../memutil
|
||||||
../moto/include
|
../moto/include
|
||||||
../../extern/carve/include
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(INC_SYS
|
set(INC_SYS
|
||||||
|
../../extern/carve/include
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SRC
|
set(SRC
|
||||||
|
@@ -7,6 +7,7 @@ set(INC
|
|||||||
../util
|
../util
|
||||||
../device
|
../device
|
||||||
)
|
)
|
||||||
|
|
||||||
set(INC_SYS
|
set(INC_SYS
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -7,6 +7,7 @@ set(INC
|
|||||||
../util
|
../util
|
||||||
../render
|
../render
|
||||||
)
|
)
|
||||||
|
|
||||||
set(INC_SYS
|
set(INC_SYS
|
||||||
${OPENGL_INCLUDE_DIR}
|
${OPENGL_INCLUDE_DIR}
|
||||||
${GLEW_INCLUDE_PATH}
|
${GLEW_INCLUDE_PATH}
|
||||||
|
@@ -5,7 +5,9 @@ set(INC
|
|||||||
osl
|
osl
|
||||||
svm
|
svm
|
||||||
)
|
)
|
||||||
|
|
||||||
set(INC_SYS
|
set(INC_SYS
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SRC
|
set(SRC
|
||||||
|
@@ -7,7 +7,9 @@ set(INC
|
|||||||
../../util
|
../../util
|
||||||
../../device
|
../../device
|
||||||
)
|
)
|
||||||
|
|
||||||
set(INC_SYS
|
set(INC_SYS
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SRC
|
set(SRC
|
||||||
|
@@ -8,6 +8,7 @@ set(INC
|
|||||||
../bvh
|
../bvh
|
||||||
../util
|
../util
|
||||||
)
|
)
|
||||||
|
|
||||||
set(INC_SYS
|
set(INC_SYS
|
||||||
${GLEW_INCLUDE_PATH}
|
${GLEW_INCLUDE_PATH}
|
||||||
)
|
)
|
||||||
|
@@ -6,7 +6,9 @@ set(INC
|
|||||||
../kernel/svm
|
../kernel/svm
|
||||||
../render
|
../render
|
||||||
)
|
)
|
||||||
|
|
||||||
set(INC_SYS
|
set(INC_SYS
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SRC
|
set(SRC
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
set(INC
|
set(INC
|
||||||
.
|
.
|
||||||
)
|
)
|
||||||
|
|
||||||
set(INC_SYS
|
set(INC_SYS
|
||||||
${GLEW_INCLUDE_PATH}
|
${GLEW_INCLUDE_PATH}
|
||||||
${OPENGL_INCLUDE_DIR}
|
${OPENGL_INCLUDE_DIR}
|
||||||
|
@@ -30,6 +30,7 @@ set(INC
|
|||||||
)
|
)
|
||||||
|
|
||||||
set(INC_SYS
|
set(INC_SYS
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SRC
|
set(SRC
|
||||||
|
@@ -40,11 +40,10 @@ add_definitions(
|
|||||||
set(INC
|
set(INC
|
||||||
extern
|
extern
|
||||||
superlu
|
superlu
|
||||||
../../extern/colamd/Include
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(INC_SYS
|
set(INC_SYS
|
||||||
|
../../extern/colamd/Include
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SRC
|
set(SRC
|
||||||
|
@@ -197,50 +197,6 @@ int ED_object_multires_update_totlevels_cb(struct Object *ob, void *totlevel_v);
|
|||||||
/* object_select.c */
|
/* object_select.c */
|
||||||
void ED_object_select_linked_by_id(struct bContext *C, struct ID *id);
|
void ED_object_select_linked_by_id(struct bContext *C, struct ID *id);
|
||||||
|
|
||||||
|
|
||||||
/* object_iterators.c */
|
|
||||||
|
|
||||||
#include "ED_view3d.h" /* XXX, needed for eV3DProjTest */
|
|
||||||
|
|
||||||
/* foreach iterators */
|
|
||||||
void mesh_foreachScreenVert(
|
|
||||||
struct ViewContext *vc,
|
|
||||||
void (*func)(void *userData, struct BMVert *eve, const float screen_co[2], int index),
|
|
||||||
void *userData, const eV3DProjTest clip_flag);
|
|
||||||
void mesh_foreachScreenEdge(
|
|
||||||
struct ViewContext *vc,
|
|
||||||
void (*func)(void *userData, struct BMEdge *eed, const float screen_co_a[2], const float screen_co_b[2],
|
|
||||||
int index),
|
|
||||||
void *userData, const eV3DProjTest clip_flag);
|
|
||||||
void mesh_foreachScreenFace(
|
|
||||||
struct ViewContext *vc,
|
|
||||||
void (*func)(void *userData, struct BMFace *efa, const float screen_co[2], int index),
|
|
||||||
void *userData, const eV3DProjTest clip_flag);
|
|
||||||
void nurbs_foreachScreenVert(
|
|
||||||
struct ViewContext *vc,
|
|
||||||
void (*func)(void *userData, struct Nurb *nu, struct BPoint *bp, struct BezTriple *bezt,
|
|
||||||
int beztindex, const float screen_co[2]),
|
|
||||||
void *userData, const eV3DProjTest clip_flag);
|
|
||||||
void mball_foreachScreenElem(
|
|
||||||
struct ViewContext *vc,
|
|
||||||
void (*func)(void *userData, struct MetaElem *ml, const float screen_co[2]),
|
|
||||||
void *userData, const eV3DProjTest clip_flag);
|
|
||||||
void lattice_foreachScreenVert(
|
|
||||||
struct ViewContext *vc,
|
|
||||||
void (*func)(void *userData, struct BPoint *bp,
|
|
||||||
const float screen_co[2]),
|
|
||||||
void *userData, const eV3DProjTest clip_flag);
|
|
||||||
void armature_foreachScreenBone(
|
|
||||||
struct ViewContext *vc,
|
|
||||||
void (*func)(void *userData, struct EditBone *ebone,
|
|
||||||
const float screen_co_a[2], const float screen_co_b[2]),
|
|
||||||
void *userData, const eV3DProjTest clip_flag);
|
|
||||||
void pose_foreachScreenBone(
|
|
||||||
struct ViewContext *vc,
|
|
||||||
void (*func)(void *userData, struct bPoseChannel *pchan,
|
|
||||||
const float screen_co_a[2], const float screen_co_b[2]),
|
|
||||||
void *userData, const eV3DProjTest clip_flag);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -37,6 +37,7 @@ struct BMEdge;
|
|||||||
struct BMFace;
|
struct BMFace;
|
||||||
struct BMVert;
|
struct BMVert;
|
||||||
struct BPoint;
|
struct BPoint;
|
||||||
|
struct Base;
|
||||||
struct BezTriple;
|
struct BezTriple;
|
||||||
struct BezTriple;
|
struct BezTriple;
|
||||||
struct BoundBox;
|
struct BoundBox;
|
||||||
@@ -50,11 +51,12 @@ struct Nurb;
|
|||||||
struct Object;
|
struct Object;
|
||||||
struct RegionView3D;
|
struct RegionView3D;
|
||||||
struct Scene;
|
struct Scene;
|
||||||
struct bScreen;
|
|
||||||
struct ScrArea;
|
struct ScrArea;
|
||||||
struct View3D;
|
struct View3D;
|
||||||
struct ViewContext;
|
struct ViewContext;
|
||||||
struct bContext;
|
struct bContext;
|
||||||
|
struct bPoseChannel;
|
||||||
|
struct bScreen;
|
||||||
struct bglMats;
|
struct bglMats;
|
||||||
struct rcti;
|
struct rcti;
|
||||||
struct wmOperator;
|
struct wmOperator;
|
||||||
@@ -84,15 +86,6 @@ typedef struct ViewDepths {
|
|||||||
|
|
||||||
float *give_cursor(struct Scene *scene, struct View3D *v3d);
|
float *give_cursor(struct Scene *scene, struct View3D *v3d);
|
||||||
|
|
||||||
int initgrabz(struct RegionView3D *rv3d, float x, float y, float z);
|
|
||||||
|
|
||||||
void ED_view3d_win_to_3d(struct ARegion *ar, const float depth_pt[3], const float mval[2], float out[3]);
|
|
||||||
void ED_view3d_win_to_delta(struct ARegion *ar, const float mval[2], float out[3]);
|
|
||||||
void ED_view3d_win_to_vector(struct ARegion *ar, const float mval[2], float out[3]);
|
|
||||||
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]);
|
|
||||||
void ED_view3d_win_to_ray(struct ARegion *ar, struct View3D *v3d, const float mval[2], float ray_start[3], float ray_normal[3]);
|
|
||||||
|
|
||||||
void ED_view3d_global_to_vector(struct RegionView3D *rv3d, const float coord[3], float vec[3]);
|
|
||||||
void ED_view3d_to_m4(float mat[][4], const float ofs[3], const float quat[4], const float dist);
|
void ED_view3d_to_m4(float mat[][4], const float ofs[3], const float quat[4], const float dist);
|
||||||
void ED_view3d_from_m4(float mat[][4], float ofs[3], float quat[4], float *dist);
|
void ED_view3d_from_m4(float mat[][4], float ofs[3], float quat[4], float *dist);
|
||||||
|
|
||||||
@@ -132,6 +125,55 @@ typedef enum {
|
|||||||
#define V3D_PROJ_TEST_ALL (V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN)
|
#define V3D_PROJ_TEST_ALL (V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN)
|
||||||
|
|
||||||
|
|
||||||
|
/* view3d_iterators.c */
|
||||||
|
|
||||||
|
/* foreach iterators */
|
||||||
|
void mesh_foreachScreenVert(
|
||||||
|
struct ViewContext *vc,
|
||||||
|
void (*func)(void *userData, struct BMVert *eve, const float screen_co[2], int index),
|
||||||
|
void *userData, const eV3DProjTest clip_flag);
|
||||||
|
void mesh_foreachScreenEdge(
|
||||||
|
struct ViewContext *vc,
|
||||||
|
void (*func)(void *userData, struct BMEdge *eed, const float screen_co_a[2], const float screen_co_b[2],
|
||||||
|
int index),
|
||||||
|
void *userData, const eV3DProjTest clip_flag);
|
||||||
|
void mesh_foreachScreenFace(
|
||||||
|
struct ViewContext *vc,
|
||||||
|
void (*func)(void *userData, struct BMFace *efa, const float screen_co[2], int index),
|
||||||
|
void *userData, const eV3DProjTest clip_flag);
|
||||||
|
void nurbs_foreachScreenVert(
|
||||||
|
struct ViewContext *vc,
|
||||||
|
void (*func)(void *userData, struct Nurb *nu, struct BPoint *bp, struct BezTriple *bezt,
|
||||||
|
int beztindex, const float screen_co[2]),
|
||||||
|
void *userData, const eV3DProjTest clip_flag);
|
||||||
|
void mball_foreachScreenElem(
|
||||||
|
struct ViewContext *vc,
|
||||||
|
void (*func)(void *userData, struct MetaElem *ml, const float screen_co[2]),
|
||||||
|
void *userData, const eV3DProjTest clip_flag);
|
||||||
|
void lattice_foreachScreenVert(
|
||||||
|
struct ViewContext *vc,
|
||||||
|
void (*func)(void *userData, struct BPoint *bp,
|
||||||
|
const float screen_co[2]),
|
||||||
|
void *userData, const eV3DProjTest clip_flag);
|
||||||
|
void armature_foreachScreenBone(
|
||||||
|
struct ViewContext *vc,
|
||||||
|
void (*func)(void *userData, struct EditBone *ebone,
|
||||||
|
const float screen_co_a[2], const float screen_co_b[2]),
|
||||||
|
void *userData, const eV3DProjTest clip_flag);
|
||||||
|
void pose_foreachScreenBone(
|
||||||
|
struct ViewContext *vc,
|
||||||
|
void (*func)(void *userData, struct bPoseChannel *pchan,
|
||||||
|
const float screen_co_a[2], const float screen_co_b[2]),
|
||||||
|
void *userData, const eV3DProjTest clip_flag);
|
||||||
|
/* *** end iterators *** */
|
||||||
|
|
||||||
|
|
||||||
|
/* view3d_project.c */
|
||||||
|
void ED_view3d_project_float_v2_m4(const struct ARegion *a, const float co[3], float r_co[2], float mat[4][4]);
|
||||||
|
void ED_view3d_project_float_v3_m4(struct ARegion *a, const float co[3], float r_co[3], float mat[4][4]);
|
||||||
|
|
||||||
|
eV3DProjStatus ED_view3d_project_base(struct ARegion *ar, struct Base *base);
|
||||||
|
|
||||||
/* *** short *** */
|
/* *** short *** */
|
||||||
eV3DProjStatus ED_view3d_project_short_ex(struct ARegion *ar, float perspmat[4][4], const int is_local,
|
eV3DProjStatus ED_view3d_project_short_ex(struct ARegion *ar, float perspmat[4][4], const int is_local,
|
||||||
const float co[3], short r_co[2], const eV3DProjTest flag);
|
const float co[3], short r_co[2], const eV3DProjTest flag);
|
||||||
@@ -150,17 +192,22 @@ eV3DProjStatus ED_view3d_project_float_ex(struct ARegion *ar, float perspmat[4][
|
|||||||
eV3DProjStatus ED_view3d_project_float_global(struct ARegion *ar, const float co[3], float r_co[2], const eV3DProjTest flag);
|
eV3DProjStatus ED_view3d_project_float_global(struct ARegion *ar, const float co[3], float r_co[2], const eV3DProjTest flag);
|
||||||
eV3DProjStatus ED_view3d_project_float_object(struct ARegion *ar, const float co[3], float r_co[2], const eV3DProjTest flag);
|
eV3DProjStatus ED_view3d_project_float_object(struct ARegion *ar, const float co[3], float r_co[2], const eV3DProjTest flag);
|
||||||
|
|
||||||
void ED_view3d_project_float_v2_m4(const struct ARegion *a, const float co[3], float r_co[2], float mat[4][4]);
|
int initgrabz(struct RegionView3D *rv3d, float x, float y, float z);
|
||||||
void ED_view3d_project_float_v3_m4(struct ARegion *a, const float co[3], float r_co[3], float mat[4][4]);
|
void ED_view3d_win_to_ray(struct ARegion *ar, struct View3D *v3d, const float mval[2], float ray_start[3], float ray_normal[3]);
|
||||||
|
void ED_view3d_global_to_vector(struct RegionView3D *rv3d, const float coord[3], float vec[3]);
|
||||||
/* Base's get their own function since its a common operation */
|
void ED_view3d_win_to_3d(struct ARegion *ar, const float depth_pt[3], const float mval[2], float out[3]);
|
||||||
eV3DProjStatus ED_view3d_project_base(struct ARegion *ar, struct Base *base);
|
void ED_view3d_win_to_delta(struct ARegion *ar, const float mval[2], float out[3]);
|
||||||
|
void ED_view3d_win_to_vector(struct ARegion *ar, const float mval[2], float out[3]);
|
||||||
|
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]);
|
||||||
|
void ED_view3d_ob_project_mat_get(struct RegionView3D *v3d, struct Object *ob, float pmat[4][4]);
|
||||||
void ED_view3d_unproject(struct bglMats *mats, float out[3], const float x, const float y, const float z);
|
void ED_view3d_unproject(struct bglMats *mats, float out[3], const float x, const float y, const float z);
|
||||||
|
|
||||||
|
/* end */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int ED_view3d_clip_range_get(struct View3D *v3d, struct RegionView3D *rv3d, float *clipsta, float *clipend);
|
int ED_view3d_clip_range_get(struct View3D *v3d, struct RegionView3D *rv3d, float *clipsta, float *clipend);
|
||||||
int ED_view3d_viewplane_get(struct View3D *v3d, struct RegionView3D *rv3d, int winxi, int winyi, struct rctf *viewplane, float *clipsta, float *clipend);
|
int ED_view3d_viewplane_get(struct View3D *v3d, struct RegionView3D *rv3d, int winxi, int winyi, struct rctf *viewplane, float *clipsta, float *clipend);
|
||||||
void ED_view3d_ob_project_mat_get(struct RegionView3D *v3d, struct Object *ob, float pmat[4][4]);
|
|
||||||
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);
|
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);
|
||||||
void ED_view3d_calc_camera_border_size(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, float size_r[2]);
|
void ED_view3d_calc_camera_border_size(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, float size_r[2]);
|
||||||
|
|
||||||
|
@@ -46,7 +46,6 @@ set(SRC
|
|||||||
object_edit.c
|
object_edit.c
|
||||||
object_group.c
|
object_group.c
|
||||||
object_hook.c
|
object_hook.c
|
||||||
object_iterators.c
|
|
||||||
object_lattice.c
|
object_lattice.c
|
||||||
object_modifier.c
|
object_modifier.c
|
||||||
object_ops.c
|
object_ops.c
|
||||||
|
@@ -51,7 +51,9 @@ set(SRC
|
|||||||
view3d_edit.c
|
view3d_edit.c
|
||||||
view3d_fly.c
|
view3d_fly.c
|
||||||
view3d_header.c
|
view3d_header.c
|
||||||
|
view3d_iterators.c
|
||||||
view3d_ops.c
|
view3d_ops.c
|
||||||
|
view3d_project.c
|
||||||
view3d_select.c
|
view3d_select.c
|
||||||
view3d_snap.c
|
view3d_snap.c
|
||||||
view3d_toolbar.c
|
view3d_toolbar.c
|
||||||
|
@@ -51,8 +51,6 @@ struct wmNDOFMotionData;
|
|||||||
struct wmOperatorType;
|
struct wmOperatorType;
|
||||||
struct wmWindowManager;
|
struct wmWindowManager;
|
||||||
|
|
||||||
#define BL_NEAR_CLIP 0.001
|
|
||||||
|
|
||||||
/* drawing flags: */
|
/* drawing flags: */
|
||||||
enum {
|
enum {
|
||||||
DRAW_PICKING = (1 << 0),
|
DRAW_PICKING = (1 << 0),
|
||||||
|
@@ -20,8 +20,8 @@
|
|||||||
* ***** END GPL LICENSE BLOCK *****
|
* ***** END GPL LICENSE BLOCK *****
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** \file blender/editors/object/object_iterators.c
|
/** \file blender/editors/object/view3d_iterators.c
|
||||||
* \ingroup edobj
|
* \ingroup spview3d
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "DNA_curve_types.h"
|
#include "DNA_curve_types.h"
|
493
source/blender/editors/space_view3d/view3d_project.c
Normal file
493
source/blender/editors/space_view3d/view3d_project.c
Normal file
@@ -0,0 +1,493 @@
|
|||||||
|
/*
|
||||||
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* The Original Code is Copyright (C) 2008 Blender Foundation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Contributor(s): Blender Foundation
|
||||||
|
*
|
||||||
|
* ***** END GPL LICENSE BLOCK *****
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** \file blender/editors/space_view3d/view3d_project.c
|
||||||
|
* \ingroup spview3d
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "DNA_object_types.h"
|
||||||
|
#include "DNA_screen_types.h"
|
||||||
|
#include "DNA_scene_types.h"
|
||||||
|
#include "DNA_view3d_types.h"
|
||||||
|
|
||||||
|
#include "BLO_sys_types.h" /* int64_t */
|
||||||
|
|
||||||
|
#include "BIF_gl.h" /* bglMats */
|
||||||
|
#include "BIF_glutil.h" /* bglMats */
|
||||||
|
|
||||||
|
#include "BLI_math_vector.h"
|
||||||
|
|
||||||
|
#include "ED_view3d.h" /* own include */
|
||||||
|
|
||||||
|
#define BL_NEAR_CLIP 0.001
|
||||||
|
|
||||||
|
/* Non Clipping Projection Functions
|
||||||
|
* ********************************* */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \note use #ED_view3d_ob_project_mat_get to get the projection matrix
|
||||||
|
*/
|
||||||
|
void ED_view3d_project_float_v2_m4(const ARegion *ar, const float co[3], float r_co[2], float mat[4][4])
|
||||||
|
{
|
||||||
|
float vec4[4];
|
||||||
|
|
||||||
|
copy_v3_v3(vec4, co);
|
||||||
|
vec4[3] = 1.0;
|
||||||
|
/* r_co[0] = IS_CLIPPED; */ /* always overwritten */
|
||||||
|
|
||||||
|
mul_m4_v4(mat, vec4);
|
||||||
|
|
||||||
|
if (vec4[3] > FLT_EPSILON) {
|
||||||
|
r_co[0] = (float)(ar->winx / 2.0f) + (ar->winx / 2.0f) * vec4[0] / vec4[3];
|
||||||
|
r_co[1] = (float)(ar->winy / 2.0f) + (ar->winy / 2.0f) * vec4[1] / vec4[3];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
zero_v2(r_co);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \note use #ED_view3d_ob_project_mat_get to get projecting mat
|
||||||
|
*/
|
||||||
|
void ED_view3d_project_float_v3_m4(ARegion *ar, const float vec[3], float r_co[3], float mat[4][4])
|
||||||
|
{
|
||||||
|
float vec4[4];
|
||||||
|
|
||||||
|
copy_v3_v3(vec4, vec);
|
||||||
|
vec4[3] = 1.0;
|
||||||
|
/* r_co[0] = IS_CLIPPED; */ /* always overwritten */
|
||||||
|
|
||||||
|
mul_m4_v4(mat, vec4);
|
||||||
|
|
||||||
|
if (vec4[3] > FLT_EPSILON) {
|
||||||
|
r_co[0] = (float)(ar->winx / 2.0f) + (ar->winx / 2.0f) * vec4[0] / vec4[3];
|
||||||
|
r_co[1] = (float)(ar->winy / 2.0f) + (ar->winy / 2.0f) * vec4[1] / vec4[3];
|
||||||
|
r_co[2] = vec4[2] / vec4[3];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
zero_v3(r_co);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Clipping Projection Functions
|
||||||
|
* ***************************** */
|
||||||
|
|
||||||
|
eV3DProjStatus ED_view3d_project_base(struct ARegion *ar, struct Base *base)
|
||||||
|
{
|
||||||
|
eV3DProjStatus ret = ED_view3d_project_short_global(ar, base->object->obmat[3], &base->sx, V3D_PROJ_TEST_CLIP_DEFAULT);
|
||||||
|
|
||||||
|
if (ret != V3D_PROJ_RET_OK) {
|
||||||
|
base->sx = IS_CLIPPED;
|
||||||
|
base->sy = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* perspmat is typically...
|
||||||
|
* - 'rv3d->perspmat', is_local == FALSE
|
||||||
|
* - 'rv3d->perspmatob', is_local == TRUE
|
||||||
|
*/
|
||||||
|
static eV3DProjStatus ed_view3d_project__internal(ARegion *ar,
|
||||||
|
float perspmat[4][4], const int is_local, /* normally hidden */
|
||||||
|
const float co[3], float r_co[2], const eV3DProjTest flag)
|
||||||
|
{
|
||||||
|
float fx, fy, vec4[4];
|
||||||
|
|
||||||
|
/* check for bad flags */
|
||||||
|
BLI_assert((flag & V3D_PROJ_TEST_ALL) == flag);
|
||||||
|
|
||||||
|
if (flag & V3D_PROJ_TEST_CLIP_BB) {
|
||||||
|
RegionView3D *rv3d = ar->regiondata;
|
||||||
|
if (rv3d->rflag & RV3D_CLIPPING) {
|
||||||
|
if (ED_view3d_clipping_test(rv3d, co, is_local)) {
|
||||||
|
return V3D_PROJ_RET_CLIP_BB;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
copy_v3_v3(vec4, co);
|
||||||
|
vec4[3] = 1.0;
|
||||||
|
mul_m4_v4(perspmat, vec4);
|
||||||
|
|
||||||
|
if (vec4[3] > (float)BL_NEAR_CLIP) {
|
||||||
|
fx = ((float)ar->winx / 2.0f) * (1.0f + vec4[0] / vec4[3]);
|
||||||
|
if (((flag & V3D_PROJ_TEST_CLIP_WIN) == 0) || (fx > 0 && fx < ar->winx)) {
|
||||||
|
fy = ((float)ar->winy / 2.0f) * (1.0f + vec4[1] / vec4[3]);
|
||||||
|
if (((flag & V3D_PROJ_TEST_CLIP_WIN) == 0) || (fy > 0.0f && fy < (float)ar->winy)) {
|
||||||
|
r_co[0] = (short)floor(fx);
|
||||||
|
r_co[1] = (short)floor(fy);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return V3D_PROJ_RET_CLIP_WIN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return V3D_PROJ_RET_CLIP_WIN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return V3D_PROJ_RET_CLIP_NEAR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return V3D_PROJ_RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
eV3DProjStatus ED_view3d_project_short_ex(ARegion *ar, float perspmat[4][4], const int is_local,
|
||||||
|
const float co[3], short r_co[2], const eV3DProjTest flag)
|
||||||
|
{
|
||||||
|
float tvec[2];
|
||||||
|
eV3DProjStatus ret = ed_view3d_project__internal(ar, perspmat, is_local, co, tvec, flag);
|
||||||
|
if (ret == V3D_PROJ_RET_OK) {
|
||||||
|
if ((tvec[0] > -32700.0 && tvec[0] < 32700.0f) &&
|
||||||
|
(tvec[1] > -32700.0 && tvec[1] < 32700.0f))
|
||||||
|
{
|
||||||
|
r_co[0] = (short)floor(tvec[0]);
|
||||||
|
r_co[1] = (short)floor(tvec[1]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ret = V3D_PROJ_RET_OVERFLOW;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
eV3DProjStatus ED_view3d_project_int_ex(ARegion *ar, float perspmat[4][4], const int is_local,
|
||||||
|
const float co[3], int r_co[2], const eV3DProjTest flag)
|
||||||
|
{
|
||||||
|
float tvec[2];
|
||||||
|
eV3DProjStatus ret = ed_view3d_project__internal(ar, perspmat, is_local, co, tvec, flag);
|
||||||
|
if (ret == V3D_PROJ_RET_OK) {
|
||||||
|
if ((tvec[0] > -2140000000.0 && tvec[0] < 2140000000.0f) &&
|
||||||
|
(tvec[1] > -2140000000.0 && tvec[1] < 2140000000.0f))
|
||||||
|
{
|
||||||
|
r_co[0] = (int)floor(tvec[0]);
|
||||||
|
r_co[1] = (int)floor(tvec[1]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ret = V3D_PROJ_RET_OVERFLOW;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
eV3DProjStatus ED_view3d_project_float_ex(ARegion *ar, float perspmat[4][4], const int is_local,
|
||||||
|
const float co[3], float r_co[2], const eV3DProjTest flag)
|
||||||
|
{
|
||||||
|
float tvec[2];
|
||||||
|
eV3DProjStatus ret = ed_view3d_project__internal(ar, perspmat, is_local, co, tvec, flag);
|
||||||
|
if (ret == V3D_PROJ_RET_OK) {
|
||||||
|
if (finite(tvec[0]) &&
|
||||||
|
finite(tvec[1]))
|
||||||
|
{
|
||||||
|
copy_v2_v2(r_co, tvec);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ret = V3D_PROJ_RET_OVERFLOW;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --- short --- */
|
||||||
|
eV3DProjStatus ED_view3d_project_short_global(ARegion *ar, const float co[3], short r_co[2], const eV3DProjTest flag)
|
||||||
|
{
|
||||||
|
RegionView3D *rv3d = ar->regiondata;
|
||||||
|
return ED_view3d_project_short_ex(ar, rv3d->persmat, FALSE, co, r_co, flag);
|
||||||
|
}
|
||||||
|
/* object space, use ED_view3d_init_mats_rv3d before calling */
|
||||||
|
eV3DProjStatus ED_view3d_project_short_object(ARegion *ar, const float co[3], short r_co[2], const eV3DProjTest flag)
|
||||||
|
{
|
||||||
|
RegionView3D *rv3d = ar->regiondata;
|
||||||
|
return ED_view3d_project_short_ex(ar, rv3d->persmatob, TRUE, co, r_co, flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --- int --- */
|
||||||
|
eV3DProjStatus ED_view3d_project_int_global(ARegion *ar, const float co[3], int r_co[2], const eV3DProjTest flag)
|
||||||
|
{
|
||||||
|
RegionView3D *rv3d = ar->regiondata;
|
||||||
|
return ED_view3d_project_int_ex(ar, rv3d->persmat, FALSE, co, r_co, flag);
|
||||||
|
}
|
||||||
|
/* object space, use ED_view3d_init_mats_rv3d before calling */
|
||||||
|
eV3DProjStatus ED_view3d_project_int_object(ARegion *ar, const float co[3], int r_co[2], const eV3DProjTest flag)
|
||||||
|
{
|
||||||
|
RegionView3D *rv3d = ar->regiondata;
|
||||||
|
return ED_view3d_project_int_ex(ar, rv3d->persmatob, TRUE, co, r_co, flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --- float --- */
|
||||||
|
eV3DProjStatus ED_view3d_project_float_global(ARegion *ar, const float co[3], float r_co[2], const eV3DProjTest flag)
|
||||||
|
{
|
||||||
|
RegionView3D *rv3d = ar->regiondata;
|
||||||
|
return ED_view3d_project_float_ex(ar, rv3d->persmat, FALSE, co, r_co, flag);
|
||||||
|
}
|
||||||
|
/* object space, use ED_view3d_init_mats_rv3d before calling */
|
||||||
|
eV3DProjStatus ED_view3d_project_float_object(ARegion *ar, const float co[3], float r_co[2], const eV3DProjTest flag)
|
||||||
|
{
|
||||||
|
RegionView3D *rv3d = ar->regiondata;
|
||||||
|
return ED_view3d_project_float_ex(ar, rv3d->persmatob, TRUE, co, r_co, flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* More Generic Window/Ray/Vector projection functions
|
||||||
|
* *************************************************** */
|
||||||
|
|
||||||
|
/* odd function, need to document better */
|
||||||
|
int initgrabz(RegionView3D *rv3d, float x, float y, float z)
|
||||||
|
{
|
||||||
|
int flip = FALSE;
|
||||||
|
if (rv3d == NULL) return flip;
|
||||||
|
rv3d->zfac = rv3d->persmat[0][3] * x + rv3d->persmat[1][3] * y + rv3d->persmat[2][3] * z + rv3d->persmat[3][3];
|
||||||
|
if (rv3d->zfac < 0.0f)
|
||||||
|
flip = TRUE;
|
||||||
|
/* if x,y,z is exactly the viewport offset, zfac is 0 and we don't want that
|
||||||
|
* (accounting for near zero values)
|
||||||
|
*/
|
||||||
|
if (rv3d->zfac < 1.e-6f && rv3d->zfac > -1.e-6f) rv3d->zfac = 1.0f;
|
||||||
|
|
||||||
|
/* Negative zfac means x, y, z was behind the camera (in perspective).
|
||||||
|
* This gives flipped directions, so revert back to ok default case.
|
||||||
|
*/
|
||||||
|
/* NOTE: I've changed this to flip zfac to be positive again for now so that GPencil draws ok
|
||||||
|
* Aligorith, 2009Aug31 */
|
||||||
|
//if (rv3d->zfac < 0.0f) rv3d->zfac = 1.0f;
|
||||||
|
if (rv3d->zfac < 0.0f) rv3d->zfac = -rv3d->zfac;
|
||||||
|
|
||||||
|
return flip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate a 3d viewpoint and direction vector from 2d window coordinates.
|
||||||
|
* This ray_start is located at the viewpoint, ray_normal is the direction towards mval.
|
||||||
|
* ray_start is clipped by the view near limit so points in front of it are always in view.
|
||||||
|
* In orthographic view the resulting ray_normal will match the view vector.
|
||||||
|
* \param ar The region (used for the window width and height).
|
||||||
|
* \param v3d The 3d viewport (used for near clipping value).
|
||||||
|
* \param mval The area relative 2d location (such as event->mval, converted into float[2]).
|
||||||
|
* \param ray_start The world-space starting point of the segment.
|
||||||
|
* \param ray_normal The normalized world-space direction of towards mval.
|
||||||
|
*/
|
||||||
|
void ED_view3d_win_to_ray(ARegion *ar, View3D *v3d, const float mval[2], float ray_start[3], float ray_normal[3])
|
||||||
|
{
|
||||||
|
float ray_end[3];
|
||||||
|
|
||||||
|
ED_view3d_win_to_segment_clip(ar, v3d, mval, ray_start, ray_end);
|
||||||
|
sub_v3_v3v3(ray_normal, ray_end, ray_start);
|
||||||
|
normalize_v3(ray_normal);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate a normalized 3d direction vector from the viewpoint towards a global location.
|
||||||
|
* In orthographic view the resulting vector will match the view vector.
|
||||||
|
* \param rv3d The region (used for the window width and height).
|
||||||
|
* \param coord The world-space location.
|
||||||
|
* \param vec The resulting normalized vector.
|
||||||
|
*/
|
||||||
|
void ED_view3d_global_to_vector(RegionView3D *rv3d, const float coord[3], float vec[3])
|
||||||
|
{
|
||||||
|
if (rv3d->is_persp) {
|
||||||
|
float p1[4], p2[4];
|
||||||
|
|
||||||
|
copy_v3_v3(p1, coord);
|
||||||
|
p1[3] = 1.0f;
|
||||||
|
copy_v3_v3(p2, p1);
|
||||||
|
p2[3] = 1.0f;
|
||||||
|
mul_m4_v4(rv3d->viewmat, p2);
|
||||||
|
|
||||||
|
mul_v3_fl(p2, 2.0f);
|
||||||
|
|
||||||
|
mul_m4_v4(rv3d->viewinv, p2);
|
||||||
|
|
||||||
|
sub_v3_v3v3(vec, p1, p2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
copy_v3_v3(vec, rv3d->viewinv[2]);
|
||||||
|
}
|
||||||
|
normalize_v3(vec);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate a 3d location from 2d window coordinates.
|
||||||
|
* \param ar The region (used for the window width and height).
|
||||||
|
* \param depth_pt The reference location used to calculate the Z depth.
|
||||||
|
* \param mval The area relative location (such as event->mval converted to floats).
|
||||||
|
* \param out The resulting world-space location.
|
||||||
|
*/
|
||||||
|
void ED_view3d_win_to_3d(ARegion *ar, const float depth_pt[3], const float mval[2], float out[3])
|
||||||
|
{
|
||||||
|
RegionView3D *rv3d = ar->regiondata;
|
||||||
|
|
||||||
|
float line_sta[3];
|
||||||
|
float line_end[3];
|
||||||
|
|
||||||
|
if (rv3d->is_persp) {
|
||||||
|
float mousevec[3];
|
||||||
|
copy_v3_v3(line_sta, rv3d->viewinv[3]);
|
||||||
|
ED_view3d_win_to_vector(ar, mval, mousevec);
|
||||||
|
add_v3_v3v3(line_end, line_sta, mousevec);
|
||||||
|
|
||||||
|
if (isect_line_plane_v3(out, line_sta, line_end, depth_pt, rv3d->viewinv[2], TRUE) == 0) {
|
||||||
|
/* highly unlikely to ever happen, mouse vec paralelle with view plane */
|
||||||
|
zero_v3(out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const float dx = (2.0f * mval[0] / (float)ar->winx) - 1.0f;
|
||||||
|
const float dy = (2.0f * mval[1] / (float)ar->winy) - 1.0f;
|
||||||
|
line_sta[0] = (rv3d->persinv[0][0] * dx) + (rv3d->persinv[1][0] * dy) + rv3d->viewinv[3][0];
|
||||||
|
line_sta[1] = (rv3d->persinv[0][1] * dx) + (rv3d->persinv[1][1] * dy) + rv3d->viewinv[3][1];
|
||||||
|
line_sta[2] = (rv3d->persinv[0][2] * dx) + (rv3d->persinv[1][2] * dy) + rv3d->viewinv[3][2];
|
||||||
|
|
||||||
|
add_v3_v3v3(line_end, line_sta, rv3d->viewinv[2]);
|
||||||
|
closest_to_line_v3(out, depth_pt, line_sta, line_end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate a 3d difference vector from 2d window offset.
|
||||||
|
* note that initgrabz() must be called first to determine
|
||||||
|
* the depth used to calculate the delta.
|
||||||
|
* \param ar The region (used for the window width and height).
|
||||||
|
* \param mval The area relative 2d difference (such as event->mval[0] - other_x).
|
||||||
|
* \param out The resulting world-space delta.
|
||||||
|
*/
|
||||||
|
void ED_view3d_win_to_delta(ARegion *ar, const float mval[2], float out[3])
|
||||||
|
{
|
||||||
|
RegionView3D *rv3d = ar->regiondata;
|
||||||
|
float dx, dy;
|
||||||
|
|
||||||
|
dx = 2.0f * mval[0] * rv3d->zfac / ar->winx;
|
||||||
|
dy = 2.0f * mval[1] * rv3d->zfac / ar->winy;
|
||||||
|
|
||||||
|
out[0] = (rv3d->persinv[0][0] * dx + rv3d->persinv[1][0] * dy);
|
||||||
|
out[1] = (rv3d->persinv[0][1] * dx + rv3d->persinv[1][1] * dy);
|
||||||
|
out[2] = (rv3d->persinv[0][2] * dx + rv3d->persinv[1][2] * dy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate a 3d direction vector from 2d window coordinates.
|
||||||
|
* This direction vector starts and the view in the direction of the 2d window coordinates.
|
||||||
|
* In orthographic view all window coordinates yield the same vector.
|
||||||
|
*
|
||||||
|
* \note doesn't rely on initgrabz
|
||||||
|
* for perspective view, get the vector direction to
|
||||||
|
* the mouse cursor as a normalized vector.
|
||||||
|
*
|
||||||
|
* \param ar The region (used for the window width and height).
|
||||||
|
* \param mval The area relative 2d location (such as event->mval converted to floats).
|
||||||
|
* \param out The resulting normalized world-space direction vector.
|
||||||
|
*/
|
||||||
|
void ED_view3d_win_to_vector(ARegion *ar, const float mval[2], float out[3])
|
||||||
|
{
|
||||||
|
RegionView3D *rv3d = ar->regiondata;
|
||||||
|
|
||||||
|
if (rv3d->is_persp) {
|
||||||
|
out[0] = 2.0f * (mval[0] / ar->winx) - 1.0f;
|
||||||
|
out[1] = 2.0f * (mval[1] / ar->winy) - 1.0f;
|
||||||
|
out[2] = -0.5f;
|
||||||
|
mul_project_m4_v3(rv3d->persinv, out);
|
||||||
|
sub_v3_v3(out, rv3d->viewinv[3]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
copy_v3_v3(out, rv3d->viewinv[2]);
|
||||||
|
}
|
||||||
|
normalize_v3(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate a 3d segment from 2d window coordinates.
|
||||||
|
* This ray_start is located at the viewpoint, ray_end is a far point.
|
||||||
|
* ray_start and ray_end are clipped by the view near and far limits
|
||||||
|
* so points along this line are always in view.
|
||||||
|
* In orthographic view all resulting segments will be parallel.
|
||||||
|
* \param ar The region (used for the window width and height).
|
||||||
|
* \param v3d The 3d viewport (used for near and far clipping range).
|
||||||
|
* \param mval The area relative 2d location (such as event->mval, converted into float[2]).
|
||||||
|
* \param ray_start The world-space starting point of the segment.
|
||||||
|
* \param ray_end The world-space end point of the segment.
|
||||||
|
*/
|
||||||
|
void ED_view3d_win_to_segment_clip(ARegion *ar, View3D *v3d, const float mval[2], float ray_start[3], float ray_end[3])
|
||||||
|
{
|
||||||
|
RegionView3D *rv3d = ar->regiondata;
|
||||||
|
|
||||||
|
if (rv3d->is_persp) {
|
||||||
|
float vec[3];
|
||||||
|
ED_view3d_win_to_vector(ar, mval, vec);
|
||||||
|
|
||||||
|
copy_v3_v3(ray_start, rv3d->viewinv[3]);
|
||||||
|
madd_v3_v3v3fl(ray_start, rv3d->viewinv[3], vec, v3d->near);
|
||||||
|
madd_v3_v3v3fl(ray_end, rv3d->viewinv[3], vec, v3d->far);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
float vec[4];
|
||||||
|
vec[0] = 2.0f * mval[0] / ar->winx - 1;
|
||||||
|
vec[1] = 2.0f * mval[1] / ar->winy - 1;
|
||||||
|
vec[2] = 0.0f;
|
||||||
|
vec[3] = 1.0f;
|
||||||
|
|
||||||
|
mul_m4_v4(rv3d->persinv, vec);
|
||||||
|
|
||||||
|
madd_v3_v3v3fl(ray_start, vec, rv3d->viewinv[2], 1000.0f);
|
||||||
|
madd_v3_v3v3fl(ray_end, vec, rv3d->viewinv[2], -1000.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* clipping */
|
||||||
|
if (rv3d->rflag & RV3D_CLIPPING) {
|
||||||
|
int a;
|
||||||
|
for (a = 0; a < 4; a++) {
|
||||||
|
clip_line_plane(ray_start, ray_end, rv3d->clip[a]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Utility functions for projection
|
||||||
|
* ******************************** */
|
||||||
|
|
||||||
|
void ED_view3d_ob_project_mat_get(RegionView3D *rv3d, Object *ob, float pmat[4][4])
|
||||||
|
{
|
||||||
|
float vmat[4][4];
|
||||||
|
|
||||||
|
mult_m4_m4m4(vmat, rv3d->viewmat, ob->obmat);
|
||||||
|
mult_m4_m4m4(pmat, rv3d->winmat, vmat);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses window coordinates (x,y) and depth component z to find a point in
|
||||||
|
* modelspace */
|
||||||
|
void ED_view3d_unproject(bglMats *mats, float out[3], const float x, const float y, const float z)
|
||||||
|
{
|
||||||
|
double ux, uy, uz;
|
||||||
|
|
||||||
|
gluUnProject(x, y, z, mats->modelview, mats->projection,
|
||||||
|
(GLint *)mats->viewport, &ux, &uy, &uz);
|
||||||
|
|
||||||
|
out[0] = ux;
|
||||||
|
out[1] = uy;
|
||||||
|
out[2] = uz;
|
||||||
|
}
|
@@ -571,306 +571,6 @@ void ED_view3d_clipping_calc(BoundBox *bb, float planes[4][4], bglMats *mats, co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate a 3d segment from 2d window coordinates.
|
|
||||||
* This ray_start is located at the viewpoint, ray_end is a far point.
|
|
||||||
* ray_start and ray_end are clipped by the view near and far limits
|
|
||||||
* so points along this line are always in view.
|
|
||||||
* In orthographic view all resulting segments will be parallel.
|
|
||||||
* \param ar The region (used for the window width and height).
|
|
||||||
* \param v3d The 3d viewport (used for near and far clipping range).
|
|
||||||
* \param mval The area relative 2d location (such as event->mval, converted into float[2]).
|
|
||||||
* \param ray_start The world-space starting point of the segment.
|
|
||||||
* \param ray_end The world-space end point of the segment.
|
|
||||||
*/
|
|
||||||
void ED_view3d_win_to_segment_clip(ARegion *ar, View3D *v3d, const float mval[2], float ray_start[3], float ray_end[3])
|
|
||||||
{
|
|
||||||
RegionView3D *rv3d = ar->regiondata;
|
|
||||||
|
|
||||||
if (rv3d->is_persp) {
|
|
||||||
float vec[3];
|
|
||||||
ED_view3d_win_to_vector(ar, mval, vec);
|
|
||||||
|
|
||||||
copy_v3_v3(ray_start, rv3d->viewinv[3]);
|
|
||||||
madd_v3_v3v3fl(ray_start, rv3d->viewinv[3], vec, v3d->near);
|
|
||||||
madd_v3_v3v3fl(ray_end, rv3d->viewinv[3], vec, v3d->far);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
float vec[4];
|
|
||||||
vec[0] = 2.0f * mval[0] / ar->winx - 1;
|
|
||||||
vec[1] = 2.0f * mval[1] / ar->winy - 1;
|
|
||||||
vec[2] = 0.0f;
|
|
||||||
vec[3] = 1.0f;
|
|
||||||
|
|
||||||
mul_m4_v4(rv3d->persinv, vec);
|
|
||||||
|
|
||||||
madd_v3_v3v3fl(ray_start, vec, rv3d->viewinv[2], 1000.0f);
|
|
||||||
madd_v3_v3v3fl(ray_end, vec, rv3d->viewinv[2], -1000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* clipping */
|
|
||||||
if (rv3d->rflag & RV3D_CLIPPING) {
|
|
||||||
int a;
|
|
||||||
for (a = 0; a < 4; a++) {
|
|
||||||
clip_line_plane(ray_start, ray_end, rv3d->clip[a]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate a 3d viewpoint and direction vector from 2d window coordinates.
|
|
||||||
* This ray_start is located at the viewpoint, ray_normal is the direction towards mval.
|
|
||||||
* ray_start is clipped by the view near limit so points in front of it are always in view.
|
|
||||||
* In orthographic view the resulting ray_normal will match the view vector.
|
|
||||||
* \param ar The region (used for the window width and height).
|
|
||||||
* \param v3d The 3d viewport (used for near clipping value).
|
|
||||||
* \param mval The area relative 2d location (such as event->mval, converted into float[2]).
|
|
||||||
* \param ray_start The world-space starting point of the segment.
|
|
||||||
* \param ray_normal The normalized world-space direction of towards mval.
|
|
||||||
*/
|
|
||||||
void ED_view3d_win_to_ray(ARegion *ar, View3D *v3d, const float mval[2], float ray_start[3], float ray_normal[3])
|
|
||||||
{
|
|
||||||
float ray_end[3];
|
|
||||||
|
|
||||||
ED_view3d_win_to_segment_clip(ar, v3d, mval, ray_start, ray_end);
|
|
||||||
sub_v3_v3v3(ray_normal, ray_end, ray_start);
|
|
||||||
normalize_v3(ray_normal);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate a normalized 3d direction vector from the viewpoint towards a global location.
|
|
||||||
* In orthographic view the resulting vector will match the view vector.
|
|
||||||
* \param rv3d The region (used for the window width and height).
|
|
||||||
* \param coord The world-space location.
|
|
||||||
* \param vec The resulting normalized vector.
|
|
||||||
*/
|
|
||||||
void ED_view3d_global_to_vector(RegionView3D *rv3d, const float coord[3], float vec[3])
|
|
||||||
{
|
|
||||||
if (rv3d->is_persp) {
|
|
||||||
float p1[4], p2[4];
|
|
||||||
|
|
||||||
copy_v3_v3(p1, coord);
|
|
||||||
p1[3] = 1.0f;
|
|
||||||
copy_v3_v3(p2, p1);
|
|
||||||
p2[3] = 1.0f;
|
|
||||||
mul_m4_v4(rv3d->viewmat, p2);
|
|
||||||
|
|
||||||
mul_v3_fl(p2, 2.0f);
|
|
||||||
|
|
||||||
mul_m4_v4(rv3d->viewinv, p2);
|
|
||||||
|
|
||||||
sub_v3_v3v3(vec, p1, p2);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
copy_v3_v3(vec, rv3d->viewinv[2]);
|
|
||||||
}
|
|
||||||
normalize_v3(vec);
|
|
||||||
}
|
|
||||||
|
|
||||||
int initgrabz(RegionView3D *rv3d, float x, float y, float z)
|
|
||||||
{
|
|
||||||
int flip = FALSE;
|
|
||||||
if (rv3d == NULL) return flip;
|
|
||||||
rv3d->zfac = rv3d->persmat[0][3] * x + rv3d->persmat[1][3] * y + rv3d->persmat[2][3] * z + rv3d->persmat[3][3];
|
|
||||||
if (rv3d->zfac < 0.0f)
|
|
||||||
flip = TRUE;
|
|
||||||
/* if x,y,z is exactly the viewport offset, zfac is 0 and we don't want that
|
|
||||||
* (accounting for near zero values)
|
|
||||||
*/
|
|
||||||
if (rv3d->zfac < 1.e-6f && rv3d->zfac > -1.e-6f) rv3d->zfac = 1.0f;
|
|
||||||
|
|
||||||
/* Negative zfac means x, y, z was behind the camera (in perspective).
|
|
||||||
* This gives flipped directions, so revert back to ok default case.
|
|
||||||
*/
|
|
||||||
/* NOTE: I've changed this to flip zfac to be positive again for now so that GPencil draws ok
|
|
||||||
* Aligorith, 2009Aug31 */
|
|
||||||
//if (rv3d->zfac < 0.0f) rv3d->zfac = 1.0f;
|
|
||||||
if (rv3d->zfac < 0.0f) rv3d->zfac = -rv3d->zfac;
|
|
||||||
|
|
||||||
return flip;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate a 3d location from 2d window coordinates.
|
|
||||||
* \param ar The region (used for the window width and height).
|
|
||||||
* \param depth_pt The reference location used to calculate the Z depth.
|
|
||||||
* \param mval The area relative location (such as event->mval converted to floats).
|
|
||||||
* \param out The resulting world-space location.
|
|
||||||
*/
|
|
||||||
void ED_view3d_win_to_3d(ARegion *ar, const float depth_pt[3], const float mval[2], float out[3])
|
|
||||||
{
|
|
||||||
RegionView3D *rv3d = ar->regiondata;
|
|
||||||
|
|
||||||
float line_sta[3];
|
|
||||||
float line_end[3];
|
|
||||||
|
|
||||||
if (rv3d->is_persp) {
|
|
||||||
float mousevec[3];
|
|
||||||
copy_v3_v3(line_sta, rv3d->viewinv[3]);
|
|
||||||
ED_view3d_win_to_vector(ar, mval, mousevec);
|
|
||||||
add_v3_v3v3(line_end, line_sta, mousevec);
|
|
||||||
|
|
||||||
if (isect_line_plane_v3(out, line_sta, line_end, depth_pt, rv3d->viewinv[2], TRUE) == 0) {
|
|
||||||
/* highly unlikely to ever happen, mouse vec paralelle with view plane */
|
|
||||||
zero_v3(out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
const float dx = (2.0f * mval[0] / (float)ar->winx) - 1.0f;
|
|
||||||
const float dy = (2.0f * mval[1] / (float)ar->winy) - 1.0f;
|
|
||||||
line_sta[0] = (rv3d->persinv[0][0] * dx) + (rv3d->persinv[1][0] * dy) + rv3d->viewinv[3][0];
|
|
||||||
line_sta[1] = (rv3d->persinv[0][1] * dx) + (rv3d->persinv[1][1] * dy) + rv3d->viewinv[3][1];
|
|
||||||
line_sta[2] = (rv3d->persinv[0][2] * dx) + (rv3d->persinv[1][2] * dy) + rv3d->viewinv[3][2];
|
|
||||||
|
|
||||||
add_v3_v3v3(line_end, line_sta, rv3d->viewinv[2]);
|
|
||||||
closest_to_line_v3(out, depth_pt, line_sta, line_end);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate a 3d difference vector from 2d window offset.
|
|
||||||
* note that initgrabz() must be called first to determine
|
|
||||||
* the depth used to calculate the delta.
|
|
||||||
* \param ar The region (used for the window width and height).
|
|
||||||
* \param mval The area relative 2d difference (such as event->mval[0] - other_x).
|
|
||||||
* \param out The resulting world-space delta.
|
|
||||||
*/
|
|
||||||
void ED_view3d_win_to_delta(ARegion *ar, const float mval[2], float out[3])
|
|
||||||
{
|
|
||||||
RegionView3D *rv3d = ar->regiondata;
|
|
||||||
float dx, dy;
|
|
||||||
|
|
||||||
dx = 2.0f * mval[0] * rv3d->zfac / ar->winx;
|
|
||||||
dy = 2.0f * mval[1] * rv3d->zfac / ar->winy;
|
|
||||||
|
|
||||||
out[0] = (rv3d->persinv[0][0] * dx + rv3d->persinv[1][0] * dy);
|
|
||||||
out[1] = (rv3d->persinv[0][1] * dx + rv3d->persinv[1][1] * dy);
|
|
||||||
out[2] = (rv3d->persinv[0][2] * dx + rv3d->persinv[1][2] * dy);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate a 3d direction vector from 2d window coordinates.
|
|
||||||
* This direction vector starts and the view in the direction of the 2d window coordinates.
|
|
||||||
* In orthographic view all window coordinates yield the same vector.
|
|
||||||
*
|
|
||||||
* \note doesn't rely on initgrabz
|
|
||||||
* for perspective view, get the vector direction to
|
|
||||||
* the mouse cursor as a normalized vector.
|
|
||||||
*
|
|
||||||
* \param ar The region (used for the window width and height).
|
|
||||||
* \param mval The area relative 2d location (such as event->mval converted to floats).
|
|
||||||
* \param out The resulting normalized world-space direction vector.
|
|
||||||
*/
|
|
||||||
void ED_view3d_win_to_vector(ARegion *ar, const float mval[2], float out[3])
|
|
||||||
{
|
|
||||||
RegionView3D *rv3d = ar->regiondata;
|
|
||||||
|
|
||||||
if (rv3d->is_persp) {
|
|
||||||
out[0] = 2.0f * (mval[0] / ar->winx) - 1.0f;
|
|
||||||
out[1] = 2.0f * (mval[1] / ar->winy) - 1.0f;
|
|
||||||
out[2] = -0.5f;
|
|
||||||
mul_project_m4_v3(rv3d->persinv, out);
|
|
||||||
sub_v3_v3(out, rv3d->viewinv[3]);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
copy_v3_v3(out, rv3d->viewinv[2]);
|
|
||||||
}
|
|
||||||
normalize_v3(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
float ED_view3d_depth_read_cached(ViewContext *vc, int x, int y)
|
|
||||||
{
|
|
||||||
ViewDepths *vd = vc->rv3d->depths;
|
|
||||||
|
|
||||||
x -= vc->ar->winrct.xmin;
|
|
||||||
y -= vc->ar->winrct.ymin;
|
|
||||||
|
|
||||||
if (vd && vd->depths && x > 0 && y > 0 && x < vd->w && y < vd->h)
|
|
||||||
return vd->depths[y * vd->w + x];
|
|
||||||
else
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ED_view3d_depth_tag_update(RegionView3D *rv3d)
|
|
||||||
{
|
|
||||||
if (rv3d->depths)
|
|
||||||
rv3d->depths->damaged = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ED_view3d_ob_project_mat_get(RegionView3D *rv3d, Object *ob, float pmat[4][4])
|
|
||||||
{
|
|
||||||
float vmat[4][4];
|
|
||||||
|
|
||||||
mult_m4_m4m4(vmat, rv3d->viewmat, ob->obmat);
|
|
||||||
mult_m4_m4m4(pmat, rv3d->winmat, vmat);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Uses window coordinates (x,y) and depth component z to find a point in
|
|
||||||
* modelspace */
|
|
||||||
void ED_view3d_unproject(bglMats *mats, float out[3], const float x, const float y, const float z)
|
|
||||||
{
|
|
||||||
double ux, uy, uz;
|
|
||||||
|
|
||||||
gluUnProject(x, y, z, mats->modelview, mats->projection,
|
|
||||||
(GLint *)mats->viewport, &ux, &uy, &uz);
|
|
||||||
|
|
||||||
out[0] = ux;
|
|
||||||
out[1] = uy;
|
|
||||||
out[2] = uz;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* use #ED_view3d_ob_project_mat_get to get projecting mat */
|
|
||||||
void ED_view3d_project_float_v2_m4(const ARegion *ar, const float co[3], float r_co[2], float mat[4][4])
|
|
||||||
{
|
|
||||||
float vec4[4];
|
|
||||||
|
|
||||||
copy_v3_v3(vec4, co);
|
|
||||||
vec4[3] = 1.0;
|
|
||||||
/* r_co[0] = IS_CLIPPED; */ /* always overwritten */
|
|
||||||
|
|
||||||
mul_m4_v4(mat, vec4);
|
|
||||||
|
|
||||||
if (vec4[3] > FLT_EPSILON) {
|
|
||||||
r_co[0] = (float)(ar->winx / 2.0f) + (ar->winx / 2.0f) * vec4[0] / vec4[3];
|
|
||||||
r_co[1] = (float)(ar->winy / 2.0f) + (ar->winy / 2.0f) * vec4[1] / vec4[3];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
zero_v2(r_co);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* use #ED_view3d_ob_project_mat_get to get projecting mat */
|
|
||||||
void ED_view3d_project_float_v3_m4(ARegion *ar, const float vec[3], float r_co[3], float mat[4][4])
|
|
||||||
{
|
|
||||||
float vec4[4];
|
|
||||||
|
|
||||||
copy_v3_v3(vec4, vec);
|
|
||||||
vec4[3] = 1.0;
|
|
||||||
/* r_co[0] = IS_CLIPPED; */ /* always overwritten */
|
|
||||||
|
|
||||||
mul_m4_v4(mat, vec4);
|
|
||||||
|
|
||||||
if (vec4[3] > FLT_EPSILON) {
|
|
||||||
r_co[0] = (float)(ar->winx / 2.0f) + (ar->winx / 2.0f) * vec4[0] / vec4[3];
|
|
||||||
r_co[1] = (float)(ar->winy / 2.0f) + (ar->winy / 2.0f) * vec4[1] / vec4[3];
|
|
||||||
r_co[2] = vec4[2] / vec4[3];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
zero_v3(r_co);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
eV3DProjStatus ED_view3d_project_base(struct ARegion *ar, struct Base *base)
|
|
||||||
{
|
|
||||||
eV3DProjStatus ret = ED_view3d_project_short_global(ar, base->object->obmat[3], &base->sx, V3D_PROJ_TEST_CLIP_DEFAULT);
|
|
||||||
|
|
||||||
if (ret != V3D_PROJ_RET_OK) {
|
|
||||||
base->sx = IS_CLIPPED;
|
|
||||||
base->sy = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ED_view3d_boundbox_clip(RegionView3D *rv3d, float obmat[][4], BoundBox *bb)
|
int ED_view3d_boundbox_clip(RegionView3D *rv3d, float obmat[][4], BoundBox *bb)
|
||||||
{
|
{
|
||||||
@@ -907,148 +607,23 @@ int ED_view3d_boundbox_clip(RegionView3D *rv3d, float obmat[][4], BoundBox *bb)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* perspmat is typically...
|
float ED_view3d_depth_read_cached(ViewContext *vc, int x, int y)
|
||||||
* - 'rv3d->perspmat', is_local == FALSE
|
|
||||||
* - 'rv3d->perspmatob', is_local == TRUE
|
|
||||||
*/
|
|
||||||
static eV3DProjStatus ed_view3d_project__internal(ARegion *ar,
|
|
||||||
float perspmat[4][4], const int is_local, /* normally hidden */
|
|
||||||
const float co[3], float r_co[2], const eV3DProjTest flag)
|
|
||||||
{
|
{
|
||||||
float fx, fy, vec4[4];
|
ViewDepths *vd = vc->rv3d->depths;
|
||||||
|
|
||||||
/* check for bad flags */
|
x -= vc->ar->winrct.xmin;
|
||||||
BLI_assert((flag & V3D_PROJ_TEST_ALL) == flag);
|
y -= vc->ar->winrct.ymin;
|
||||||
|
|
||||||
if (flag & V3D_PROJ_TEST_CLIP_BB) {
|
if (vd && vd->depths && x > 0 && y > 0 && x < vd->w && y < vd->h)
|
||||||
RegionView3D *rv3d = ar->regiondata;
|
return vd->depths[y * vd->w + x];
|
||||||
if (rv3d->rflag & RV3D_CLIPPING) {
|
else
|
||||||
if (ED_view3d_clipping_test(rv3d, co, is_local)) {
|
return 1;
|
||||||
return V3D_PROJ_RET_CLIP_BB;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
copy_v3_v3(vec4, co);
|
|
||||||
vec4[3] = 1.0;
|
|
||||||
mul_m4_v4(perspmat, vec4);
|
|
||||||
|
|
||||||
if (vec4[3] > (float)BL_NEAR_CLIP) {
|
|
||||||
fx = ((float)ar->winx / 2.0f) * (1.0f + vec4[0] / vec4[3]);
|
|
||||||
if (((flag & V3D_PROJ_TEST_CLIP_WIN) == 0) || (fx > 0 && fx < ar->winx)) {
|
|
||||||
fy = ((float)ar->winy / 2.0f) * (1.0f + vec4[1] / vec4[3]);
|
|
||||||
if (((flag & V3D_PROJ_TEST_CLIP_WIN) == 0) || (fy > 0.0f && fy < (float)ar->winy)) {
|
|
||||||
r_co[0] = (short)floor(fx);
|
|
||||||
r_co[1] = (short)floor(fy);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return V3D_PROJ_RET_CLIP_WIN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return V3D_PROJ_RET_CLIP_WIN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return V3D_PROJ_RET_CLIP_NEAR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return V3D_PROJ_RET_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
eV3DProjStatus ED_view3d_project_short_ex(ARegion *ar, float perspmat[4][4], const int is_local,
|
void ED_view3d_depth_tag_update(RegionView3D *rv3d)
|
||||||
const float co[3], short r_co[2], const eV3DProjTest flag)
|
|
||||||
{
|
{
|
||||||
float tvec[2];
|
if (rv3d->depths)
|
||||||
eV3DProjStatus ret = ed_view3d_project__internal(ar, perspmat, is_local, co, tvec, flag);
|
rv3d->depths->damaged = 1;
|
||||||
if (ret == V3D_PROJ_RET_OK) {
|
|
||||||
if ((tvec[0] > -32700.0 && tvec[0] < 32700.0f) &&
|
|
||||||
(tvec[1] > -32700.0 && tvec[1] < 32700.0f))
|
|
||||||
{
|
|
||||||
r_co[0] = (short)floor(tvec[0]);
|
|
||||||
r_co[1] = (short)floor(tvec[1]);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ret = V3D_PROJ_RET_OVERFLOW;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
eV3DProjStatus ED_view3d_project_int_ex(ARegion *ar, float perspmat[4][4], const int is_local,
|
|
||||||
const float co[3], int r_co[2], const eV3DProjTest flag)
|
|
||||||
{
|
|
||||||
float tvec[2];
|
|
||||||
eV3DProjStatus ret = ed_view3d_project__internal(ar, perspmat, is_local, co, tvec, flag);
|
|
||||||
if (ret == V3D_PROJ_RET_OK) {
|
|
||||||
if ((tvec[0] > -2140000000.0 && tvec[0] < 2140000000.0f) &&
|
|
||||||
(tvec[1] > -2140000000.0 && tvec[1] < 2140000000.0f))
|
|
||||||
{
|
|
||||||
r_co[0] = (int)floor(tvec[0]);
|
|
||||||
r_co[1] = (int)floor(tvec[1]);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ret = V3D_PROJ_RET_OVERFLOW;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
eV3DProjStatus ED_view3d_project_float_ex(ARegion *ar, float perspmat[4][4], const int is_local,
|
|
||||||
const float co[3], float r_co[2], const eV3DProjTest flag)
|
|
||||||
{
|
|
||||||
float tvec[2];
|
|
||||||
eV3DProjStatus ret = ed_view3d_project__internal(ar, perspmat, is_local, co, tvec, flag);
|
|
||||||
if (ret == V3D_PROJ_RET_OK) {
|
|
||||||
if (finite(tvec[0]) &&
|
|
||||||
finite(tvec[1]))
|
|
||||||
{
|
|
||||||
copy_v2_v2(r_co, tvec);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ret = V3D_PROJ_RET_OVERFLOW;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --- short --- */
|
|
||||||
eV3DProjStatus ED_view3d_project_short_global(ARegion *ar, const float co[3], short r_co[2], const eV3DProjTest flag)
|
|
||||||
{
|
|
||||||
RegionView3D *rv3d = ar->regiondata;
|
|
||||||
return ED_view3d_project_short_ex(ar, rv3d->persmat, FALSE, co, r_co, flag);
|
|
||||||
}
|
|
||||||
/* object space, use ED_view3d_init_mats_rv3d before calling */
|
|
||||||
eV3DProjStatus ED_view3d_project_short_object(ARegion *ar, const float co[3], short r_co[2], const eV3DProjTest flag)
|
|
||||||
{
|
|
||||||
RegionView3D *rv3d = ar->regiondata;
|
|
||||||
return ED_view3d_project_short_ex(ar, rv3d->persmatob, TRUE, co, r_co, flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --- int --- */
|
|
||||||
eV3DProjStatus ED_view3d_project_int_global(ARegion *ar, const float co[3], int r_co[2], const eV3DProjTest flag)
|
|
||||||
{
|
|
||||||
RegionView3D *rv3d = ar->regiondata;
|
|
||||||
return ED_view3d_project_int_ex(ar, rv3d->persmat, FALSE, co, r_co, flag);
|
|
||||||
}
|
|
||||||
/* object space, use ED_view3d_init_mats_rv3d before calling */
|
|
||||||
eV3DProjStatus ED_view3d_project_int_object(ARegion *ar, const float co[3], int r_co[2], const eV3DProjTest flag)
|
|
||||||
{
|
|
||||||
RegionView3D *rv3d = ar->regiondata;
|
|
||||||
return ED_view3d_project_int_ex(ar, rv3d->persmatob, TRUE, co, r_co, flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --- float --- */
|
|
||||||
eV3DProjStatus ED_view3d_project_float_global(ARegion *ar, const float co[3], float r_co[2], const eV3DProjTest flag)
|
|
||||||
{
|
|
||||||
RegionView3D *rv3d = ar->regiondata;
|
|
||||||
return ED_view3d_project_float_ex(ar, rv3d->persmat, FALSE, co, r_co, flag);
|
|
||||||
}
|
|
||||||
/* object space, use ED_view3d_init_mats_rv3d before calling */
|
|
||||||
eV3DProjStatus ED_view3d_project_float_object(ARegion *ar, const float co[3], float r_co[2], const eV3DProjTest flag)
|
|
||||||
{
|
|
||||||
RegionView3D *rv3d = ar->regiondata;
|
|
||||||
return ED_view3d_project_float_ex(ar, rv3d->persmatob, TRUE, co, r_co, flag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copies logic of get_view3d_viewplane(), keep in sync */
|
/* copies logic of get_view3d_viewplane(), keep in sync */
|
||||||
|
@@ -25,6 +25,10 @@
|
|||||||
|
|
||||||
set(INC
|
set(INC
|
||||||
.
|
.
|
||||||
|
composite
|
||||||
|
intern
|
||||||
|
shader
|
||||||
|
texture
|
||||||
../blenfont
|
../blenfont
|
||||||
../blenkernel
|
../blenkernel
|
||||||
../blenlib
|
../blenlib
|
||||||
@@ -39,10 +43,6 @@ set(INC
|
|||||||
|
|
||||||
set(INC_SYS
|
set(INC_SYS
|
||||||
${GLEW_INCLUDE_PATH}
|
${GLEW_INCLUDE_PATH}
|
||||||
intern
|
|
||||||
composite
|
|
||||||
shader
|
|
||||||
texture
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(SRC
|
set(SRC
|
||||||
|
@@ -30,12 +30,12 @@ set(INC
|
|||||||
../../blenlib
|
../../blenlib
|
||||||
../../blenloader
|
../../blenloader
|
||||||
../../editors/include
|
../../editors/include
|
||||||
|
../../gpu
|
||||||
../../makesdna
|
../../makesdna
|
||||||
../../makesrna
|
../../makesrna
|
||||||
../../windowmanager
|
../../windowmanager
|
||||||
../../gpu
|
|
||||||
../../../../intern/guardedalloc
|
|
||||||
../../../../intern/cycles/blender
|
../../../../intern/cycles/blender
|
||||||
|
../../../../intern/guardedalloc
|
||||||
)
|
)
|
||||||
|
|
||||||
set(INC_SYS
|
set(INC_SYS
|
||||||
|
@@ -29,6 +29,7 @@ set(INC
|
|||||||
../blenkernel
|
../blenkernel
|
||||||
../blenlib
|
../blenlib
|
||||||
../blenloader
|
../blenloader
|
||||||
|
../compositor
|
||||||
../editors/include
|
../editors/include
|
||||||
../editors/io
|
../editors/io
|
||||||
../gpu
|
../gpu
|
||||||
@@ -36,7 +37,6 @@ set(INC
|
|||||||
../makesdna
|
../makesdna
|
||||||
../makesrna
|
../makesrna
|
||||||
../nodes
|
../nodes
|
||||||
../compositor
|
|
||||||
../render/extern/include
|
../render/extern/include
|
||||||
../../gameengine/BlenderRoutines
|
../../gameengine/BlenderRoutines
|
||||||
../../../intern/elbeem/extern
|
../../../intern/elbeem/extern
|
||||||
|
@@ -53,10 +53,10 @@ set(INC
|
|||||||
../../../intern/guardedalloc
|
../../../intern/guardedalloc
|
||||||
../../../intern/moto/include
|
../../../intern/moto/include
|
||||||
../../../intern/string
|
../../../intern/string
|
||||||
../../../extern/recastnavigation/Detour/Include
|
|
||||||
)
|
)
|
||||||
|
|
||||||
set(INC_SYS
|
set(INC_SYS
|
||||||
|
../../../extern/recastnavigation/Detour/Include
|
||||||
../../../extern/Eigen3
|
../../../extern/Eigen3
|
||||||
${PTHREADS_INCLUDE_DIRS}
|
${PTHREADS_INCLUDE_DIRS}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user