Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Eagar <joeedh@gmail.com>2011-05-09 03:43:18 +0400
committerJoseph Eagar <joeedh@gmail.com>2011-05-09 03:43:18 +0400
commit6ef77cf95accc3cb914e7efd964118ce6e9521cf (patch)
tree1d8dbf95355038c93f79f9053a0bf1d55b561ec3 /source/blender/editors/space_view3d
parent3462ddf17f38eb61fc3bb2751d55de15a47455c3 (diff)
parent770119d16f7dbee99a60d19540818892c970c4e2 (diff)
=bmesh= merge from trunk at r36529
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r--source/blender/editors/space_view3d/CMakeLists.txt2
-rw-r--r--source/blender/editors/space_view3d/SConscript2
-rw-r--r--source/blender/editors/space_view3d/drawarmature.c69
-rw-r--r--source/blender/editors/space_view3d/drawobject.c2
-rw-r--r--source/blender/editors/space_view3d/space_view3d.c47
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c12
-rw-r--r--source/blender/editors/space_view3d/view3d_edit.c349
-rw-r--r--source/blender/editors/space_view3d/view3d_fly.c4
-rw-r--r--source/blender/editors/space_view3d/view3d_header.c51
-rw-r--r--source/blender/editors/space_view3d/view3d_intern.h7
-rw-r--r--source/blender/editors/space_view3d/view3d_ops.c2
-rw-r--r--source/blender/editors/space_view3d/view3d_select.c60
-rw-r--r--source/blender/editors/space_view3d/view3d_snap.c9
-rw-r--r--source/blender/editors/space_view3d/view3d_view.c163
14 files changed, 552 insertions, 227 deletions
diff --git a/source/blender/editors/space_view3d/CMakeLists.txt b/source/blender/editors/space_view3d/CMakeLists.txt
index 8c1ad00742d..95a278e329a 100644
--- a/source/blender/editors/space_view3d/CMakeLists.txt
+++ b/source/blender/editors/space_view3d/CMakeLists.txt
@@ -59,7 +59,7 @@ set(SRC
)
if(WITH_GAMEENGINE)
- list(APPEND INC ../../../kernel/gen_system)
+ list(APPEND INC ../../../../source/gameengine/BlenderRoutines)
add_definitions(-DWITH_GAMEENGINE)
endif()
diff --git a/source/blender/editors/space_view3d/SConscript b/source/blender/editors/space_view3d/SConscript
index 9c1c03ff373..53bd7828b63 100644
--- a/source/blender/editors/space_view3d/SConscript
+++ b/source/blender/editors/space_view3d/SConscript
@@ -9,7 +9,7 @@ incs += ' ../../windowmanager #/intern/guardedalloc #/extern/glew/include'
incs += ' ../../render/extern/include ../../blenloader'
incs += ' ../../gpu ../../makesrna ../../blenfont ../../bmesh'
incs += ' #/intern/smoke/extern'
-incs += ' #source/kernel/gen_system'
+incs += ' #source/gameengine/BlenderRoutines'
if env['WITH_BF_GAMEENGINE']:
defs.append('WITH_GAMEENGINE')
diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c
index e68e1657096..7c66cec5730 100644
--- a/source/blender/editors/space_view3d/drawarmature.c
+++ b/source/blender/editors/space_view3d/drawarmature.c
@@ -129,7 +129,7 @@ static void set_pchan_colorset (Object *ob, bPoseChannel *pchan)
}
/* This function is for brightening/darkening a given color (like UI_ThemeColorShade()) */
-static void cp_shade_color3ub (char cp[], int offset)
+static void cp_shade_color3ub (unsigned char cp[3], const int offset)
{
int r, g, b;
@@ -152,7 +152,7 @@ static short set_pchan_glColor (short colCode, int boneflag, int constflag)
case PCHAN_COLOR_NORMAL:
{
if (bcolor) {
- char cp[3];
+ unsigned char cp[3];
if (boneflag & BONE_DRAW_ACTIVE) {
VECCOPY(cp, bcolor->active);
@@ -169,7 +169,7 @@ static short set_pchan_glColor (short colCode, int boneflag, int constflag)
cp_shade_color3ub(cp, -50);
}
- glColor3ub(cp[0], cp[1], cp[2]);
+ glColor3ubv(cp);
}
else {
if (boneflag & BONE_DRAW_ACTIVE && boneflag & BONE_SELECTED) UI_ThemeColorShade(TH_BONE_POSE, 40);
@@ -185,8 +185,7 @@ static short set_pchan_glColor (short colCode, int boneflag, int constflag)
case PCHAN_COLOR_SOLID:
{
if (bcolor) {
- char *cp= bcolor->solid;
- glColor3ub(cp[0], cp[1], cp[2]);
+ glColor3ubv((unsigned char *)bcolor->solid);
}
else
UI_ThemeColor(TH_BONE_SOLID);
@@ -215,7 +214,7 @@ static short set_pchan_glColor (short colCode, int boneflag, int constflag)
case PCHAN_COLOR_SPHEREBONE_BASE:
{
if (bcolor) {
- char cp[3];
+ unsigned char cp[3];
if (boneflag & BONE_DRAW_ACTIVE) {
VECCOPY(cp, bcolor->active);
@@ -227,7 +226,7 @@ static short set_pchan_glColor (short colCode, int boneflag, int constflag)
VECCOPY(cp, bcolor->solid);
}
- glColor3ub(cp[0], cp[1], cp[2]);
+ glColor3ubv(cp);
}
else {
if (boneflag & BONE_DRAW_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 40);
@@ -241,7 +240,7 @@ static short set_pchan_glColor (short colCode, int boneflag, int constflag)
case PCHAN_COLOR_SPHEREBONE_END:
{
if (bcolor) {
- char cp[3];
+ unsigned char cp[3];
if (boneflag & BONE_DRAW_ACTIVE) {
VECCOPY(cp, bcolor->active);
@@ -256,7 +255,7 @@ static short set_pchan_glColor (short colCode, int boneflag, int constflag)
cp_shade_color3ub(cp, -30);
}
- glColor3ub(cp[0], cp[1], cp[2]);
+ glColor3ubv(cp);
}
else {
if (boneflag & BONE_DRAW_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 10);
@@ -1537,7 +1536,7 @@ static void draw_pose_dofs(Object *ob)
}
if (pchan->ikflag & BONE_IK_XLIMIT) {
- /* OpenGL requires rotations in degrees; so we're taking the average angle here */
+ /* OpenGL requires rotations in degrees; so we're taking the average angle here */
theta= RAD2DEGF(0.5f * (pchan->limitmin[0] + pchan->limitmax[0]));
glRotatef(theta, 1.0f, 0.0f, 0.0f);
@@ -1615,10 +1614,17 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
bone= pchan->bone;
- if (bone && !(bone->flag & (BONE_HIDDEN_P|BONE_NO_DEFORM|BONE_HIDDEN_PG))) {
- if (bone->flag & (BONE_SELECTED)) {
- if (bone->layer & arm->layer)
- draw_sphere_bone_dist(smat, imat, pchan, NULL);
+ if (bone) {
+ /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194]
+ * NOTE: this is the only case with NO_DEFORM==0 flag, as this is for envelope influence drawing
+ */
+ if ( (bone->flag & (BONE_HIDDEN_P|BONE_NO_DEFORM|BONE_HIDDEN_PG))==0 &&
+ ((G.f & G_PICKSEL)==0 || (bone->flag & BONE_UNSELECTABLE)==0) )
+ {
+ if (bone->flag & (BONE_SELECTED)) {
+ if (bone->layer & arm->layer)
+ draw_sphere_bone_dist(smat, imat, pchan, NULL);
+ }
}
}
}
@@ -1642,14 +1648,18 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
bone= pchan->bone;
arm->layer_used |= bone->layer;
- if ( (bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG)) ) {
+ /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194] */
+ if ( (bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))==0 &&
+ ((G.f & G_PICKSEL)==0 || (bone->flag & BONE_UNSELECTABLE)==0) )
+ {
if (bone->layer & arm->layer) {
int use_custom = (pchan->custom) && !(arm->flag & ARM_NO_CUSTOM);
glPushMatrix();
-
+
if(use_custom && pchan->custom_tx) {
glMultMatrixf(pchan->custom_tx->pose_mat);
- } else {
+ }
+ else {
glMultMatrixf(pchan->pose_mat);
}
@@ -1710,15 +1720,19 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
bone= pchan->bone;
- if ((bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
+ /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194] */
+ if ( (bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))==0 &&
+ ((G.f & G_PICKSEL)==0 || (bone->flag & BONE_UNSELECTABLE)==0) )
+ {
if (bone->layer & arm->layer) {
if (pchan->custom) {
if ((dt < OB_SOLID) || (bone->flag & BONE_DRAWWIRE)) {
glPushMatrix();
-
+
if(pchan->custom_tx) {
glMultMatrixf(pchan->custom_tx->pose_mat);
- } else {
+ }
+ else {
glMultMatrixf(pchan->pose_mat);
}
@@ -1788,7 +1802,10 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
bone= pchan->bone;
arm->layer_used |= bone->layer;
- if ((bone) && !(bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))) {
+ /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194] */
+ if ( (bone->flag & (BONE_HIDDEN_P|BONE_HIDDEN_PG))==0 &&
+ ((G.f & G_PICKSEL)==0 || (bone->flag & BONE_UNSELECTABLE)==0) )
+ {
if (bone->layer & arm->layer) {
if ((do_dashed & 1) && (pchan->parent)) {
/* Draw a line from our root to the parent's tip
@@ -1892,7 +1909,7 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
/* patch for several 3d cards (IBM mostly) that crash on glSelect with text drawing */
if ((G.f & G_PICKSEL) == 0) {
float vec[3];
-
+
unsigned char col[4];
float col_f[4];
glGetFloatv(GL_CURRENT_COLOR, col_f); /* incase this is not set below */
@@ -1911,7 +1928,7 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
else if (dt > OB_WIRE) {
UI_GetThemeColor3ubv(TH_TEXT, col);
}
-
+
/* Draw names of bone */
if (arm->flag & ARM_DRAWNAMES) {
mid_v3_v3v3(vec, pchan->pose_head, pchan->pose_tail);
@@ -1924,10 +1941,10 @@ static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
copy_m4_m4(bmat, pchan->pose_mat);
bone_matrix_translate_y(bmat, pchan->bone->length);
glMultMatrixf(bmat);
-
+
glColor3ubv(col);
drawaxes(pchan->bone->length*0.25f, OB_ARROWS);
-
+
glPopMatrix();
}
}
@@ -2440,7 +2457,7 @@ int draw_armature(Scene *scene, View3D *v3d, ARegion *ar, Base *base, int dt, in
/* we use color for solid lighting */
glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
glEnable(GL_COLOR_MATERIAL);
- glColor3ub(255,0,255); // clear spec
+ glColor3ub(255,255,255); // clear spec
glDisable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index ad84ffebdb9..6b042b22d74 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -4418,7 +4418,7 @@ static void draw_ptcache_edit(Scene *scene, View3D *v3d, PTCacheEdit *edit)
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glShadeModel(GL_FLAT);
- glEnable(GL_DEPTH_TEST);
+ if(v3d->zbuf) glEnable(GL_DEPTH_TEST);
glLineWidth(1.0f);
glPointSize(1.0);
}
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 3d29d9d0fda..c4eba5e0962 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -156,6 +156,44 @@ RegionView3D *ED_view3d_context_rv3d(bContext *C)
return rv3d;
}
+/* ideally would return an rv3d but in some cases the region is needed too
+ * so return that, the caller can then access the ar->regiondata */
+ARegion *ED_view3d_context_region_unlock(bContext *C)
+{
+ ScrArea *sa= CTX_wm_area(C);
+ if(sa && sa->spacetype==SPACE_VIEW3D) {
+ ARegion *ar= CTX_wm_region(C);
+ if(ar) {
+ RegionView3D *rv3d= ar->regiondata;
+ if(rv3d && rv3d->viewlock == 0) {
+ return ar;
+ }
+ else {
+ ARegion *ar_unlock_user= NULL;
+ ARegion *ar_unlock= NULL;
+ for(ar= sa->regionbase.first; ar; ar= ar->next) {
+ /* find the first unlocked rv3d */
+ if(ar->regiondata && ar->regiontype == RGN_TYPE_WINDOW) {
+ rv3d= ar->regiondata;
+ if(rv3d->viewlock == 0) {
+ ar_unlock= ar;
+ if(rv3d->persp==RV3D_PERSP || rv3d->persp==RV3D_CAMOB) {
+ ar_unlock_user= ar;
+ break;
+ }
+ }
+ }
+ }
+
+ /* camera/perspective view get priority when the active region is locked */
+ if(ar_unlock_user) return ar_unlock_user;
+ if(ar_unlock) return ar_unlock;
+ }
+ }
+ }
+ return NULL;
+}
+
/* Most of the time this isn't needed since you could assume the view matrix was
* set while drawing, however when functions like mesh_foreachScreenVert are
* called by selection tools, we can't be sure this object was the last.
@@ -938,7 +976,14 @@ static void space_view3d_listener(struct ScrArea *sa, struct wmNotifier *wmn)
break;
}
break;
-
+ case NC_MATERIAL:
+ switch(wmn->data) {
+ case ND_NODES:
+ if(v3d->drawtype == OB_TEXTURE)
+ ED_area_tag_redraw_regiontype(sa, RGN_TYPE_WINDOW);
+ break;
+ }
+ break;
}
#if 0 // removed since BKE_image_user_calc_frame is now called in draw_bgpic because screen_ops doesnt call the notifier.
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 1c830b7022a..1bbad6220ef 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -189,7 +189,7 @@ void view3d_clr_clipping(void)
}
}
-static int test_clipping(float *vec, float clip[][4])
+static int test_clipping(const float vec[3], float clip[][4])
{
float view[3];
copy_v3_v3(view, vec);
@@ -205,7 +205,7 @@ static int test_clipping(float *vec, float clip[][4])
/* for 'local' ED_view3d_local_clipping must run first
* then all comparisons can be done in localspace */
-int view3d_test_clipping(RegionView3D *rv3d, float *vec, int local)
+int view3d_test_clipping(RegionView3D *rv3d, const float vec[3], const int local)
{
return test_clipping(vec, local ? rv3d->clip_local : rv3d->clip);
}
@@ -993,7 +993,7 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
cpack(0x4040FF);
glRectf(x3, y3, x4, y4);
}
-
+
/* safety border */
if (ca && (ca->flag & CAM_SHOWTITLESAFE)) {
fac= 0.1;
@@ -1172,7 +1172,7 @@ ImBuf *view3d_read_backbuf(ViewContext *vc, short xmin, short ymin, short xmax,
}
/* smart function to sample a rect spiralling outside, nice for backbuf selection */
-unsigned int view3d_sample_backbuf_rect(ViewContext *vc, short mval[2], int size,
+unsigned int view3d_sample_backbuf_rect(ViewContext *vc, const short mval[2], int size,
unsigned int min, unsigned int max, int *dist, short strict,
void *handle, unsigned int (*indextest)(void *handle, unsigned int index))
{
@@ -2212,7 +2212,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar, in
}
/* creates own 3d views, used by the sequencer */
-ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Scene *scene, int width, int height, unsigned int flag, int drawtype, char err_out[256])
+ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Scene *scene, Object *camera, int width, int height, unsigned int flag, int drawtype, char err_out[256])
{
View3D v3d= {NULL};
ARegion ar= {NULL};
@@ -2223,7 +2223,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Scene *scene, int width, int height
ar.regiondata= &rv3d;
ar.regiontype= RGN_TYPE_WINDOW;
- v3d.camera= scene->camera;
+ v3d.camera= camera;
v3d.lay= scene->lay;
v3d.drawtype = drawtype;
v3d.flag2 = V3D_RENDER_OVERRIDE;
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 7d0312a79f2..051a972df35 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -286,6 +286,7 @@ typedef struct ViewOpsData {
float oldquat[4];
float trackvec[3];
+ float mousevec[3]; /* dolly only */
float reverse, dist0;
float grid, far;
short axis_snap; /* view rotate only */
@@ -347,9 +348,9 @@ static void viewops_data_create(bContext *C, wmOperator *op, wmEvent *event)
vod->origy= vod->oldy= event->y;
vod->origkey= event->type; /* the key that triggered the operator. */
vod->use_dyn_ofs= (U.uiflag & USER_ORBIT_SELECTION) ? 1:0;
+ copy_v3_v3(vod->ofs, rv3d->ofs);
if (vod->use_dyn_ofs) {
- copy_v3_v3(vod->ofs, rv3d->ofs);
/* If there's no selection, lastofs is unmodified and last value since static */
calculateTransformCenter(C, V3D_CENTROID, lastofs);
negate_v3_v3(vod->dyn_ofs, lastofs);
@@ -395,6 +396,9 @@ static void viewops_data_create(bContext *C, wmOperator *op, wmEvent *event)
}
}
+ /* for dolly */
+ window_to_3d_vector(vod->ar, vod->mousevec, (vod->oldx - vod->ar->winrct.xmin)-(vod->ar->winx)/2, (vod->oldy - vod->ar->winrct.ymin)-(vod->ar->winy)/2);
+
/* lookup, we dont pass on v3d to prevent confusement */
vod->grid= v3d->grid;
vod->far= v3d->far;
@@ -787,7 +791,7 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, wmEvent *event)
View3D *v3d = vod->sa->spacedata.first;
if(v3d->camera) {
- view3d_settings_from_ob(v3d->camera, rv3d->ofs, rv3d->viewquat, &rv3d->dist, NULL);
+ view3d_apply_ob(v3d->camera, rv3d->ofs, rv3d->viewquat, &rv3d->dist, NULL);
}
if(rv3d->persp==RV3D_CAMOB) {
@@ -1076,16 +1080,28 @@ static void view_zoom_mouseloc(ARegion *ar, float dfac, int mx, int my)
}
-static void viewzoom_apply(ViewOpsData *vod, int x, int y, short viewzoom)
+static void viewzoom_apply(ViewOpsData *vod, int x, int y, const short viewzoom, const short zoom_invert)
{
float zfac=1.0;
if(viewzoom==USER_ZOOM_CONT) {
double time= PIL_check_seconds_timer();
float time_step= (float)(time - vod->timer_lastdraw);
+ float fac;
+
+ if (U.uiflag & USER_ZOOM_HORIZ) {
+ fac= (float)(x - vod->origx);
+ }
+ else {
+ fac= (float)(y - vod->origy);
+ }
+
+ if(zoom_invert) {
+ fac= -fac;
+ }
// oldstyle zoom
- zfac = 1.0f + (((float)(vod->origx - x + vod->origy - y) / 20.0f) * time_step);
+ zfac = 1.0f + ((fac / 20.0f) * time_step);
vod->timer_lastdraw= time;
}
else if(viewzoom==USER_ZOOM_SCALE) {
@@ -1103,7 +1119,7 @@ static void viewzoom_apply(ViewOpsData *vod, int x, int y, short viewzoom)
else { /* USER_ZOOM_DOLLY */
float len1, len2;
- if (U.uiflag & USER_ZOOM_DOLLY_HORIZ) {
+ if (U.uiflag & USER_ZOOM_HORIZ) {
len1 = (vod->ar->winrct.xmax - x) + 5;
len2 = (vod->ar->winrct.xmax - vod->origx) + 5;
}
@@ -1111,14 +1127,15 @@ static void viewzoom_apply(ViewOpsData *vod, int x, int y, short viewzoom)
len1 = (vod->ar->winrct.ymax - y) + 5;
len2 = (vod->ar->winrct.ymax - vod->origy) + 5;
}
- if (U.uiflag & USER_ZOOM_INVERT)
+ if (zoom_invert) {
SWAP(float, len1, len2);
+ }
zfac = vod->dist0 * (2.0f * ((len2/len1)-1.0f) + 1.0f) / vod->rv3d->dist;
}
if(zfac != 1.0f && zfac*vod->rv3d->dist > 0.001f * vod->grid &&
- zfac * vod->rv3d->dist < 10.0f * vod->far)
+ zfac * vod->rv3d->dist < 10.0f * vod->far)
view_zoom_mouseloc(vod->ar, zfac, vod->oldx, vod->oldy);
@@ -1180,7 +1197,7 @@ static int viewzoom_modal(bContext *C, wmOperator *op, wmEvent *event)
}
if(event_code==VIEW_APPLY) {
- viewzoom_apply(vod, event->x, event->y, U.viewzoom);
+ viewzoom_apply(vod, event->x, event->y, U.viewzoom, (U.uiflag & USER_ZOOM_INVERT) != 0);
}
else if (event_code==VIEW_CONFIRM) {
request_depth_update(vod->rv3d);
@@ -1250,6 +1267,7 @@ static int viewzoom_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
+/* viewdolly_invoke() copied this function, changes here may apply there */
static int viewzoom_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
/* if one or the other zoom position aren't set, set from event */
@@ -1273,18 +1291,16 @@ static int viewzoom_invoke(bContext *C, wmOperator *op, wmEvent *event)
vod= op->customdata;
if (event->type == MOUSEZOOM) {
- if (U.uiflag & USER_ZOOM_INVERT) /* Bypass Zoom invert flag */
- SWAP(int, event->x, event->prevx);
+ /* Bypass Zoom invert flag for track pads (pass FALSE always) */
- if (U.uiflag & USER_ZOOM_DOLLY_HORIZ) {
+ if (U.uiflag & USER_ZOOM_HORIZ) {
vod->origx = vod->oldx = event->x;
- viewzoom_apply(vod, event->prevx, event->prevy, USER_ZOOM_DOLLY);
+ viewzoom_apply(vod, event->prevx, event->prevy, USER_ZOOM_DOLLY, FALSE);
}
else {
-
/* Set y move = x move as MOUSEZOOM uses only x axis to pass magnification value */
vod->origy = vod->oldy = vod->origy + event->x - event->prevx;
- viewzoom_apply(vod, event->prevx, event->prevy, USER_ZOOM_DOLLY);
+ viewzoom_apply(vod, event->prevx, event->prevy, USER_ZOOM_DOLLY, FALSE);
}
request_depth_update(vod->rv3d);
@@ -1311,7 +1327,7 @@ static int viewzoom_invoke(bContext *C, wmOperator *op, wmEvent *event)
void VIEW3D_OT_zoom(wmOperatorType *ot)
{
/* identifiers */
- ot->name= "Zoom view";
+ ot->name= "Zoom View";
ot->description = "Zoom in/out in the view";
ot->idname= "VIEW3D_OT_zoom";
@@ -1329,6 +1345,232 @@ void VIEW3D_OT_zoom(wmOperatorType *ot)
RNA_def_int(ot->srna, "my", 0, 0, INT_MAX, "Zoom Position Y", "", 0, INT_MAX);
}
+
+/* ************************ viewdolly ******************************** */
+static void view_dolly_mouseloc(ARegion *ar, float orig_ofs[3], float dvec[3], float dfac)
+{
+ RegionView3D *rv3d= ar->regiondata;
+ madd_v3_v3v3fl(rv3d->ofs, orig_ofs, dvec, 1.0 - dfac);
+}
+
+static void viewdolly_apply(ViewOpsData *vod, int x, int y, const short zoom_invert)
+{
+ float zfac=1.0;
+
+ {
+ float len1, len2;
+
+ if (U.uiflag & USER_ZOOM_HORIZ) {
+ len1 = (vod->ar->winrct.xmax - x) + 5;
+ len2 = (vod->ar->winrct.xmax - vod->origx) + 5;
+ }
+ else {
+ len1 = (vod->ar->winrct.ymax - y) + 5;
+ len2 = (vod->ar->winrct.ymax - vod->origy) + 5;
+ }
+ if (zoom_invert)
+ SWAP(float, len1, len2);
+
+ zfac = 1.0 + ((len2 - len1) * 0.01 * vod->rv3d->dist);
+ }
+
+ if(zfac != 1.0f)
+ view_dolly_mouseloc(vod->ar, vod->ofs, vod->mousevec, zfac);
+
+ if(vod->rv3d->viewlock & RV3D_BOXVIEW)
+ view3d_boxview_sync(vod->sa, vod->ar);
+
+ ED_region_tag_redraw(vod->ar);
+}
+
+
+static int viewdolly_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+ ViewOpsData *vod= op->customdata;
+ short event_code= VIEW_PASS;
+
+ /* execute the events */
+ if(event->type==MOUSEMOVE) {
+ event_code= VIEW_APPLY;
+ }
+ else if(event->type==EVT_MODAL_MAP) {
+ switch (event->val) {
+ case VIEW_MODAL_CONFIRM:
+ event_code= VIEW_CONFIRM;
+ break;
+ case VIEWROT_MODAL_SWITCH_MOVE:
+ WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, NULL);
+ event_code= VIEW_CONFIRM;
+ break;
+ case VIEWROT_MODAL_SWITCH_ROTATE:
+ WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, NULL);
+ event_code= VIEW_CONFIRM;
+ break;
+ }
+ }
+ else if(event->type==vod->origkey && event->val==KM_RELEASE) {
+ event_code= VIEW_CONFIRM;
+ }
+
+ if(event_code==VIEW_APPLY) {
+ viewdolly_apply(vod, event->x, event->y, (U.uiflag & USER_ZOOM_INVERT) != 0);
+ }
+ else if (event_code==VIEW_CONFIRM) {
+ request_depth_update(vod->rv3d);
+ viewops_data_free(C, op);
+
+ return OPERATOR_FINISHED;
+ }
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static int viewdolly_exec(bContext *C, wmOperator *op)
+{
+ View3D *v3d;
+ RegionView3D *rv3d;
+ ScrArea *sa;
+ ARegion *ar;
+ float mousevec[3];
+
+ int delta= RNA_int_get(op->ptr, "delta");
+ int mx, my;
+
+ if(op->customdata) {
+ ViewOpsData *vod= op->customdata;
+
+ sa= vod->sa;
+ ar= vod->ar;
+ copy_v3_v3(mousevec, vod->mousevec);
+ }
+ else {
+ sa= CTX_wm_area(C);
+ ar= CTX_wm_region(C);
+ normalize_v3_v3(mousevec, ((RegionView3D *)ar->regiondata)->viewinv[2]);
+ }
+
+ v3d= sa->spacedata.first;
+ rv3d= ar->regiondata;
+
+ /* overwrite the mouse vector with the view direction (zoom into the center) */
+ if((U.uiflag & USER_ZOOM_TO_MOUSEPOS) == 0) {
+ normalize_v3_v3(mousevec, rv3d->viewinv[2]);
+ }
+
+ mx= RNA_property_is_set(op->ptr, "mx") ? RNA_int_get(op->ptr, "mx") : ar->winx / 2;
+ my= RNA_property_is_set(op->ptr, "my") ? RNA_int_get(op->ptr, "my") : ar->winy / 2;
+
+
+
+ if(delta < 0) {
+ view_dolly_mouseloc(ar, rv3d->ofs, mousevec, 1.2f);
+ }
+ else {
+ view_dolly_mouseloc(ar, rv3d->ofs, mousevec, .83333f);
+ }
+
+ if(rv3d->viewlock & RV3D_BOXVIEW)
+ view3d_boxview_sync(sa, ar);
+
+ request_depth_update(rv3d);
+ ED_region_tag_redraw(ar);
+
+ viewops_data_free(C, op);
+
+ return OPERATOR_FINISHED;
+}
+
+/* copied from viewzoom_invoke(), changes here may apply there */
+static int viewdolly_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+ /* if one or the other zoom position aren't set, set from event */
+ if (!RNA_property_is_set(op->ptr, "mx") || !RNA_property_is_set(op->ptr, "my"))
+ {
+ RNA_int_set(op->ptr, "mx", event->x);
+ RNA_int_set(op->ptr, "my", event->y);
+ }
+
+ if(RNA_property_is_set(op->ptr, "delta")) {
+ /* makes op->customdata */
+ viewops_data_create(C, op, event);
+ viewdolly_exec(C, op);
+ }
+ else {
+ ViewOpsData *vod;
+
+ /* makes op->customdata */
+ viewops_data_create(C, op, event);
+
+ vod= op->customdata;
+
+ /* overwrite the mouse vector with the view direction (zoom into the center) */
+ if((U.uiflag & USER_ZOOM_TO_MOUSEPOS) == 0) {
+ normalize_v3_v3(vod->mousevec, vod->rv3d->viewinv[2]);
+ }
+
+ if (event->type == MOUSEZOOM) {
+ /* Bypass Zoom invert flag for track pads (pass FALSE always) */
+
+ if (U.uiflag & USER_ZOOM_HORIZ) {
+ vod->origx = vod->oldx = event->x;
+ viewdolly_apply(vod, event->prevx, event->prevy, FALSE);
+ }
+ else {
+
+ /* Set y move = x move as MOUSEZOOM uses only x axis to pass magnification value */
+ vod->origy = vod->oldy = vod->origy + event->x - event->prevx;
+ viewdolly_apply(vod, event->prevx, event->prevy, FALSE);
+ }
+ request_depth_update(vod->rv3d);
+
+ viewops_data_free(C, op);
+ return OPERATOR_FINISHED;
+ }
+ else {
+ /* add temp handler */
+ WM_event_add_modal_handler(C, op);
+
+ return OPERATOR_RUNNING_MODAL;
+ }
+ }
+ return OPERATOR_FINISHED;
+}
+
+/* like ED_operator_region_view3d_active but check its not in ortho view */
+static int viewdolly_poll(bContext *C)
+{
+ RegionView3D *rv3d= CTX_wm_region_view3d(C);
+
+ if (rv3d && rv3d->persp == RV3D_PERSP) {
+ return 1;
+ }
+
+ return 0;
+}
+
+void VIEW3D_OT_dolly(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Dolly view";
+ ot->description = "Dolly in/out in the view";
+ ot->idname= "VIEW3D_OT_dolly";
+
+ /* api callbacks */
+ ot->invoke= viewdolly_invoke;
+ ot->exec= viewdolly_exec;
+ ot->modal= viewdolly_modal;
+ ot->poll= viewdolly_poll;
+
+ /* flags */
+ ot->flag= OPTYPE_BLOCKING|OPTYPE_GRAB_POINTER;
+
+ RNA_def_int(ot->srna, "delta", 0, INT_MIN, INT_MAX, "Delta", "", INT_MIN, INT_MAX);
+ RNA_def_int(ot->srna, "mx", 0, 0, INT_MAX, "Zoom Position X", "", 0, INT_MAX);
+ RNA_def_int(ot->srna, "my", 0, 0, INT_MAX, "Zoom Position Y", "", 0, INT_MAX);
+}
+
+
+
static int view3d_all_exec(bContext *C, wmOperator *op) /* was view3d_home() in 2.4x */
{
ARegion *ar= CTX_wm_region(C);
@@ -1394,10 +1636,10 @@ static int view3d_all_exec(bContext *C, wmOperator *op) /* was view3d_home() in
if (rv3d->persp==RV3D_CAMOB) {
rv3d->persp= RV3D_PERSP;
- smooth_view(C, v3d->camera, NULL, new_ofs, NULL, &new_dist, NULL);
+ smooth_view(C, v3d, ar, v3d->camera, NULL, new_ofs, NULL, &new_dist, NULL);
}
else {
- smooth_view(C, NULL, NULL, new_ofs, NULL, &new_dist, NULL);
+ smooth_view(C, v3d, ar, NULL, NULL, new_ofs, NULL, &new_dist, NULL);
}
}
// XXX BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
@@ -1537,10 +1779,10 @@ static int viewselected_exec(bContext *C, wmOperator *UNUSED(op)) /* like a loca
if (rv3d->persp==RV3D_CAMOB) {
rv3d->persp= RV3D_PERSP;
- smooth_view(C, v3d->camera, NULL, new_ofs, NULL, &new_dist, NULL);
+ smooth_view(C, v3d, ar, v3d->camera, NULL, new_ofs, NULL, &new_dist, NULL);
}
else {
- smooth_view(C, NULL, NULL, new_ofs, NULL, ok_dist ? &new_dist : NULL, NULL);
+ smooth_view(C, v3d, ar, NULL, NULL, new_ofs, NULL, ok_dist ? &new_dist : NULL, NULL);
}
/* smooth view does viewlock RV3D_BOXVIEW copy */
@@ -1573,10 +1815,12 @@ static int viewcenter_cursor_exec(bContext *C, wmOperator *UNUSED(op))
Scene *scene= CTX_data_scene(C);
if (rv3d) {
+ ARegion *ar= CTX_wm_region(C);
+
/* non camera center */
float new_ofs[3];
negate_v3_v3(new_ofs, give_cursor(scene, v3d));
- smooth_view(C, NULL, NULL, new_ofs, NULL, NULL, NULL);
+ smooth_view(C, v3d, ar, NULL, NULL, new_ofs, NULL, NULL, NULL);
/* smooth view does viewlock RV3D_BOXVIEW copy */
}
@@ -1679,7 +1923,7 @@ void VIEW3D_OT_render_border(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Set Render Border";
- ot->description = "Set the boundries of the border render and enables border render ";
+ ot->description = "Set the boundaries of the border render and enables border render ";
ot->idname= "VIEW3D_OT_render_border";
/* api callbacks */
@@ -1806,7 +2050,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
new_dist = ((new_dist*scale) >= 0.001f * v3d->grid)? new_dist*scale:0.001f * v3d->grid;
}
- smooth_view(C, NULL, NULL, new_ofs, NULL, &new_dist, NULL);
+ smooth_view(C, v3d, ar, NULL, NULL, new_ofs, NULL, &new_dist, NULL);
if(rv3d->viewlock & RV3D_BOXVIEW)
view3d_boxview_sync(CTX_wm_area(C), ar);
@@ -1905,14 +2149,14 @@ static EnumPropertyItem prop_view_items[] = {
/* would like to make this a generic function - outside of transform */
-static void axis_set_view(bContext *C, float q1, float q2, float q3, float q4, short view, int perspo, int align_active)
+static void axis_set_view(bContext *C, View3D *v3d, ARegion *ar, float q1, float q2, float q3, float q4, short view, int perspo, int align_active)
{
- View3D *v3d = CTX_wm_view3d(C);
- RegionView3D *rv3d= CTX_wm_region_view3d(C);
+ RegionView3D *rv3d= ar->regiondata; /* no NULL check is needed, poll checks */
float new_quat[4];
new_quat[0]= q1; new_quat[1]= q2;
new_quat[2]= q3; new_quat[3]= q4;
+ normalize_qt(new_quat);
if(align_active) {
/* align to active object */
@@ -1953,7 +2197,7 @@ static void axis_set_view(bContext *C, float q1, float q2, float q3, float q4, s
}
if(rv3d->viewlock) {
- ED_region_tag_redraw(CTX_wm_region(C));
+ ED_region_tag_redraw(ar);
return;
}
@@ -1962,14 +2206,14 @@ static void axis_set_view(bContext *C, float q1, float q2, float q3, float q4, s
if (U.uiflag & USER_AUTOPERSP) rv3d->persp= view ? RV3D_ORTHO : RV3D_PERSP;
else if(rv3d->persp==RV3D_CAMOB) rv3d->persp= perspo;
- smooth_view(C, v3d->camera, NULL, rv3d->ofs, new_quat, NULL, NULL);
+ smooth_view(C, v3d, ar, v3d->camera, NULL, rv3d->ofs, new_quat, NULL, NULL);
}
else {
if (U.uiflag & USER_AUTOPERSP) rv3d->persp= view ? RV3D_ORTHO : RV3D_PERSP;
else if(rv3d->persp==RV3D_CAMOB) rv3d->persp= perspo;
- smooth_view(C, NULL, NULL, NULL, new_quat, NULL, NULL);
+ smooth_view(C, v3d, ar, NULL, NULL, NULL, new_quat, NULL, NULL);
}
}
@@ -1977,7 +2221,8 @@ static void axis_set_view(bContext *C, float q1, float q2, float q3, float q4, s
static int viewnumpad_exec(bContext *C, wmOperator *op)
{
View3D *v3d = CTX_wm_view3d(C);
- RegionView3D *rv3d= CTX_wm_region_view3d(C);
+ ARegion *ar= ED_view3d_context_region_unlock(C);
+ RegionView3D *rv3d= ar->regiondata; /* no NULL check is needed, poll checks */
Scene *scene= CTX_data_scene(C);
static int perspo=RV3D_PERSP;
int viewnum, align_active, nextperspo;
@@ -1999,27 +2244,27 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
switch (viewnum) {
case RV3D_VIEW_BOTTOM :
- axis_set_view(C, 0.0, -1.0, 0.0, 0.0, viewnum, nextperspo, align_active);
+ axis_set_view(C, v3d, ar, 0.0, -1.0, 0.0, 0.0, viewnum, nextperspo, align_active);
break;
case RV3D_VIEW_BACK:
- axis_set_view(C, 0.0, 0.0, (float)-cos(M_PI/4.0), (float)-cos(M_PI/4.0), viewnum, nextperspo, align_active);
+ axis_set_view(C, v3d, ar, 0.0, 0.0, (float)-cos(M_PI/4.0), (float)-cos(M_PI/4.0), viewnum, nextperspo, align_active);
break;
case RV3D_VIEW_LEFT:
- axis_set_view(C, 0.5, -0.5, 0.5, 0.5, viewnum, nextperspo, align_active);
+ axis_set_view(C, v3d, ar, 0.5, -0.5, 0.5, 0.5, viewnum, nextperspo, align_active);
break;
case RV3D_VIEW_TOP:
- axis_set_view(C, 1.0, 0.0, 0.0, 0.0, viewnum, nextperspo, align_active);
+ axis_set_view(C, v3d, ar, 1.0, 0.0, 0.0, 0.0, viewnum, nextperspo, align_active);
break;
case RV3D_VIEW_FRONT:
- axis_set_view(C, (float)cos(M_PI/4.0), (float)-sin(M_PI/4.0), 0.0, 0.0, viewnum, nextperspo, align_active);
+ axis_set_view(C, v3d, ar, (float)cos(M_PI/4.0), (float)-sin(M_PI/4.0), 0.0, 0.0, viewnum, nextperspo, align_active);
break;
case RV3D_VIEW_RIGHT:
- axis_set_view(C, 0.5, -0.5, -0.5, -0.5, viewnum, nextperspo, align_active);
+ axis_set_view(C, v3d, ar, 0.5, -0.5, -0.5, -0.5, viewnum, nextperspo, align_active);
break;
case RV3D_VIEW_CAMERA:
@@ -2075,13 +2320,13 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
/* finally do snazzy view zooming */
rv3d->persp= RV3D_CAMOB;
- smooth_view(C, NULL, v3d->camera, rv3d->ofs, rv3d->viewquat, &rv3d->dist, &v3d->lens);
+ smooth_view(C, v3d, ar, NULL, v3d->camera, rv3d->ofs, rv3d->viewquat, &rv3d->dist, &v3d->lens);
}
else{
/* return to settings of last view */
/* does smooth_view too */
- axis_set_view(C, rv3d->lviewquat[0], rv3d->lviewquat[1], rv3d->lviewquat[2], rv3d->lviewquat[3], rv3d->lview, rv3d->lpersp, 0);
+ axis_set_view(C, v3d, ar, rv3d->lviewquat[0], rv3d->lviewquat[1], rv3d->lviewquat[2], rv3d->lviewquat[3], rv3d->lview, rv3d->lpersp, 0);
}
}
break;
@@ -2105,7 +2350,7 @@ void VIEW3D_OT_viewnumpad(wmOperatorType *ot)
/* api callbacks */
ot->exec= viewnumpad_exec;
- ot->poll= ED_operator_region_view3d_active;
+ ot->poll= ED_operator_rv3d_unlock_poll;
/* flags */
ot->flag= 0;
@@ -2123,7 +2368,8 @@ static EnumPropertyItem prop_view_orbit_items[] = {
static int vieworbit_exec(bContext *C, wmOperator *op)
{
- RegionView3D *rv3d= CTX_wm_region_view3d(C);
+ ARegion *ar= ED_view3d_context_region_unlock(C);
+ RegionView3D *rv3d= ar->regiondata; /* no NULL check is needed, poll checks */
float phi, q1[4], new_quat[4];
int orbitdir;
@@ -2157,7 +2403,7 @@ static int vieworbit_exec(bContext *C, wmOperator *op)
rv3d->view= 0;
}
- smooth_view(C, NULL, NULL, NULL, new_quat, NULL, NULL);
+ smooth_view(C, CTX_wm_view3d(C), ar, NULL, NULL, NULL, new_quat, NULL, NULL);
}
}
@@ -2173,7 +2419,7 @@ void VIEW3D_OT_view_orbit(wmOperatorType *ot)
/* api callbacks */
ot->exec= vieworbit_exec;
- ot->poll= ED_operator_region_view3d_active;
+ ot->poll= ED_operator_rv3d_unlock_poll;
/* flags */
ot->flag= 0;
@@ -2229,8 +2475,8 @@ void VIEW3D_OT_view_pan(wmOperatorType *ot)
static int viewpersportho_exec(bContext *C, wmOperator *UNUSED(op))
{
- ARegion *ar= CTX_wm_region(C);
- RegionView3D *rv3d= CTX_wm_region_view3d(C);
+ ARegion *ar= ED_view3d_context_region_unlock(C);
+ RegionView3D *rv3d= ar->regiondata; /* no NULL check is needed, poll checks */
if(rv3d->viewlock==0) {
if(rv3d->persp!=RV3D_ORTHO)
@@ -2252,12 +2498,13 @@ void VIEW3D_OT_view_persportho(wmOperatorType *ot)
/* api callbacks */
ot->exec= viewpersportho_exec;
- ot->poll= ED_operator_region_view3d_active;
+ ot->poll= ED_operator_rv3d_unlock_poll;
/* flags */
ot->flag= 0;
}
+
/* ******************** add background image operator **************** */
static BGpic *background_image_add(bContext *C)
@@ -2566,10 +2813,10 @@ void VIEW3D_OT_cursor3d(wmOperatorType *ot)
ot->invoke= set_3dcursor_invoke;
ot->poll= ED_operator_view3d_active;
-
+
/* flags */
// ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-
+
/* rna later */
}
@@ -2651,7 +2898,7 @@ void VIEW3D_OT_enable_manipulator(wmOperatorType *ot)
/* ************************* below the line! *********************** */
-static float view_autodist_depth_margin(ARegion *ar, short mval[2], int margin)
+static float view_autodist_depth_margin(ARegion *ar, const short mval[2], int margin)
{
ViewDepths depth_temp= {0};
rcti rect;
@@ -2679,7 +2926,7 @@ static float view_autodist_depth_margin(ARegion *ar, short mval[2], int margin)
}
/* XXX todo Zooms in on a border drawn by the user */
-int view_autodist(Scene *scene, ARegion *ar, View3D *v3d, short *mval, float mouse_worldloc[3] ) //, float *autodist )
+int view_autodist(Scene *scene, ARegion *ar, View3D *v3d, const short mval[2], float mouse_worldloc[3] ) //, float *autodist )
{
bglMats mats; /* ZBuffer depth vars */
float depth_close= FLT_MAX;
@@ -2722,7 +2969,7 @@ int view_autodist_init(Scene *scene, ARegion *ar, View3D *v3d, int mode) //, flo
}
// no 4x4 sampling, run view_autodist_init first
-int view_autodist_simple(ARegion *ar, short *mval, float mouse_worldloc[3], int margin, float *force_depth) //, float *autodist )
+int view_autodist_simple(ARegion *ar, const short mval[2], float mouse_worldloc[3], int margin, float *force_depth) //, float *autodist )
{
bglMats mats; /* ZBuffer depth vars, could cache? */
float depth;
@@ -2750,7 +2997,7 @@ int view_autodist_simple(ARegion *ar, short *mval, float mouse_worldloc[3], int
return 1;
}
-int view_autodist_depth(struct ARegion *ar, short mval[2], int margin, float *depth)
+int view_autodist_depth(struct ARegion *ar, const short mval[2], int margin, float *depth)
{
*depth= view_autodist_depth_margin(ar, mval, margin);
@@ -2777,7 +3024,7 @@ static int depth_segment_cb(int x, int y, void *userData)
}
}
-int view_autodist_depth_segment(struct ARegion *ar, short mval_sta[2], short mval_end[2], int margin, float *depth)
+int view_autodist_depth_segment(struct ARegion *ar, const short mval_sta[2], const short mval_end[2], int margin, float *depth)
{
struct { struct ARegion *ar; int margin; float depth; } data = {NULL};
int p1[2];
diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c
index 7d84a47bddf..32deee50fb2 100644
--- a/source/blender/editors/space_view3d/view3d_fly.c
+++ b/source/blender/editors/space_view3d/view3d_fly.c
@@ -540,7 +540,7 @@ static int flyApply(bContext *C, FlyInfo *fly)
{
#define FLY_ROTATE_FAC 2.5f /* more is faster */
-#define FLY_ZUP_CORRECT_FAC 0.1f /* ammount to correct per step */
+#define FLY_ZUP_CORRECT_FAC 0.1f /* amount to correct per step */
#define FLY_ZUP_CORRECT_ACCEL 0.05f /* increase upright momentum each step */
/*
@@ -793,7 +793,7 @@ static int flyApply(bContext *C, FlyInfo *fly)
/* transform the parent or the camera? */
if(fly->root_parent) {
Object *ob_update;
-
+
float view_mat[4][4];
float prev_view_imat[4][4];
float diff_mat[4][4];
diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c
index fea3ac20ca9..4adfcd51f56 100644
--- a/source/blender/editors/space_view3d/view3d_header.c
+++ b/source/blender/editors/space_view3d/view3d_header.c
@@ -273,7 +273,7 @@ void VIEW3D_OT_layers(wmOperatorType *ot)
static char *view3d_modeselect_pup(Scene *scene)
{
Object *ob= OBACT;
- static char string[1024];
+ static char string[256];
static char formatstr[] = "|%s %%x%d %%i%d";
char *str = string;
@@ -314,7 +314,7 @@ static char *view3d_modeselect_pup(Scene *scene)
if (ob->particlesystem.first || modifiers_findByType(ob, eModifierType_Cloth) || modifiers_findByType(ob, eModifierType_Softbody)) {
str += sprintf(str, formatstr, "Particle Mode", OB_MODE_PARTICLE_EDIT, ICON_PARTICLEMODE);
}
-
+ (void)str;
return (string);
}
@@ -429,6 +429,25 @@ static int object_mode_icon(int mode)
return ICON_OBJECT_DATAMODE;
}
+void uiTemplateEditModeSelection(uiLayout *layout, struct bContext *C)
+{
+ Object *obedit = CTX_data_edit_object(C);
+ uiBlock *block= uiLayoutGetBlock(layout);
+
+ uiBlockSetHandleFunc(block, do_view3d_header_buttons, NULL);
+
+ if(obedit && (obedit->type == OB_MESH)) {
+ BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh;
+ uiLayout *row;
+
+ row= uiLayoutRow(layout, 1);
+ block= uiLayoutGetBlock(row);
+ uiDefIconButBitS(block, TOG, SCE_SELECT_VERTEX, B_SEL_VERT, ICON_VERTEXSEL, 0,0,XIC,YIC, &em->selectmode, 1.0, 0.0, 0, 0, "Vertex select mode");
+ uiDefIconButBitS(block, TOG, SCE_SELECT_EDGE, B_SEL_EDGE, ICON_EDGESEL, 0,0,XIC,YIC, &em->selectmode, 1.0, 0.0, 0, 0, "Edge select mode");
+ uiDefIconButBitS(block, TOG, SCE_SELECT_FACE, B_SEL_FACE, ICON_FACESEL, 0,0,XIC,YIC, &em->selectmode, 1.0, 0.0, 0, 0, "Face select mode");
+ }
+}
+
void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
{
bScreen *screen= CTX_wm_screen(C);
@@ -441,6 +460,7 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
Object *obedit = CTX_data_edit_object(C);
uiBlock *block;
uiLayout *row;
+ const float dpi_fac= UI_DPI_FAC;
RNA_pointer_create(&screen->id, &RNA_SpaceView3D, v3d, &v3dptr);
RNA_pointer_create(&scene->id, &RNA_ToolSettings, ts, &toolsptr);
@@ -466,7 +486,7 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
uiBlockBeginAlign(block);
uiDefIconTextButS(block, MENU, B_MODESELECT, object_mode_icon(v3d->modeselect), view3d_modeselect_pup(scene) ,
- 0,0,126,20, &(v3d->modeselect), 0, 0, 0, 0, "Mode");
+ 0,0,126 * dpi_fac,20, &(v3d->modeselect), 0, 0, 0, 0, "Mode");
uiBlockEndAlign(block);
/* Draw type */
@@ -488,12 +508,12 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
/* NDOF */
/* Not implemented yet
- if (G.ndofdevice ==0 ) {
+ if (G.ndofdevice ==0 ) {
uiDefIconTextButC(block, ICONTEXTROW,B_NDOF, ICON_NDOF_TURN, ndof_pup(), 0,0,XIC+10,YIC, &(v3d->ndofmode), 0, 3.0, 0, 0, "Ndof mode");
-
+
uiDefIconButC(block, TOG, B_NDOF, ICON_NDOF_DOM,
- 0,0,XIC,YIC,
- &v3d->ndoffilter, 0, 1, 0, 0, "dominant axis");
+ 0,0,XIC,YIC,
+ &v3d->ndoffilter, 0, 1, 0, 0, "dominant axis");
}
*/
@@ -513,10 +533,10 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
}
str_menu = BIF_menustringTransformOrientation(C, "Orientation");
- uiDefButS(block, MENU, B_MAN_MODE, str_menu,0,0,70,YIC, &v3d->twmode, 0, 0, 0, 0, "Transform Orientation");
+ uiDefButS(block, MENU, B_MAN_MODE, str_menu,0,0,70 * dpi_fac, YIC, &v3d->twmode, 0, 0, 0, 0, "Transform Orientation");
MEM_freeN((void *)str_menu);
}
-
+
if(obedit==NULL && v3d->localvd==NULL) {
unsigned int ob_lay = ob ? ob->lay : 0;
@@ -530,16 +550,5 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
uiItemR(layout, &v3dptr, "lock_camera_and_layers", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
}
- /* selection modus, dont use python for this since it cant do the toggle buttons with shift+click as well as clicking to set one. */
- if(obedit && (obedit->type == OB_MESH)) {
- BMEditMesh *em= ((Mesh *)obedit->data)->edit_btmesh;
-
- ts->selectmode = em->selectmode;
-
- row= uiLayoutRow(layout, 1);
- block= uiLayoutGetBlock(row);
- uiDefIconButBitI(block, TOG, SCE_SELECT_VERTEX, B_SEL_VERT, ICON_VERTEXSEL, 0,0,XIC,YIC, &em->selectmode, 1.0, 0.0, 0, 0, "Vertex select mode");
- uiDefIconButBitI(block, TOG, SCE_SELECT_EDGE, B_SEL_EDGE, ICON_EDGESEL, 0,0,XIC,YIC, &em->selectmode, 1.0, 0.0, 0, 0, "Edge select mode");
- uiDefIconButBitI(block, TOG, SCE_SELECT_FACE, B_SEL_FACE, ICON_FACESEL, 0,0,XIC,YIC, &em->selectmode, 1.0, 0.0, 0, 0, "Face select mode");
- }
+ uiTemplateEditModeSelection(layout, C);
}
diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h
index 4ad0b6acbc3..be2a7e876b4 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -68,6 +68,7 @@ void view3d_operatortypes(void);
/* view3d_edit.c */
void VIEW3D_OT_zoom(struct wmOperatorType *ot);
+void VIEW3D_OT_dolly(struct wmOperatorType *ot);
void VIEW3D_OT_zoom_camera_1_to_1(struct wmOperatorType *ot);
void VIEW3D_OT_move(struct wmOperatorType *ot);
void VIEW3D_OT_rotate(struct wmOperatorType *ot);
@@ -146,10 +147,6 @@ void VIEW3D_OT_select_circle(struct wmOperatorType *ot);
void VIEW3D_OT_select_border(struct wmOperatorType *ot);
void VIEW3D_OT_select_lasso(struct wmOperatorType *ot);
-/* view3d_view.c */
-void view3d_settings_from_ob(struct Object *ob, float *ofs, float *quat, float *dist, float *lens);
-int view3d_is_ortho(View3D *v3d, RegionView3D *rv3d);
-
void VIEW3D_OT_smoothview(struct wmOperatorType *ot);
void VIEW3D_OT_setcameratoview(struct wmOperatorType *ot);
void VIEW3D_OT_object_as_camera(struct wmOperatorType *ot);
@@ -161,7 +158,7 @@ int boundbox_clip(RegionView3D *rv3d, float obmat[][4], struct BoundBox *bb);
void centerview(struct ARegion *ar, View3D *v3d);
-void smooth_view(struct bContext *C, struct Object *, struct Object *, float *ofs, float *quat, float *dist, float *lens);
+void smooth_view(struct bContext *C, struct View3D *v3d, struct ARegion *ar, struct Object *, struct Object *, float *ofs, float *quat, float *dist, float *lens);
void setwinmatrixview3d(ARegion *ar, View3D *v3d, rctf *rect); /* rect: for picking */
void setviewmatrixview3d(Scene *scene, View3D *v3d, RegionView3D *rv3d);
diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c
index 1b1a66db95e..288072e8e08 100644
--- a/source/blender/editors/space_view3d/view3d_ops.c
+++ b/source/blender/editors/space_view3d/view3d_ops.c
@@ -66,6 +66,7 @@ void view3d_operatortypes(void)
WM_operatortype_append(VIEW3D_OT_move);
WM_operatortype_append(VIEW3D_OT_zoom);
WM_operatortype_append(VIEW3D_OT_zoom_camera_1_to_1);
+ WM_operatortype_append(VIEW3D_OT_dolly);
WM_operatortype_append(VIEW3D_OT_view_all);
WM_operatortype_append(VIEW3D_OT_viewnumpad);
WM_operatortype_append(VIEW3D_OT_view_orbit);
@@ -132,6 +133,7 @@ void view3d_keymap(wmKeyConfig *keyconf)
WM_keymap_verify_item(keymap, "VIEW3D_OT_rotate", MIDDLEMOUSE, KM_PRESS, 0, 0);
WM_keymap_verify_item(keymap, "VIEW3D_OT_move", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
WM_keymap_verify_item(keymap, "VIEW3D_OT_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
+ WM_keymap_verify_item(keymap, "VIEW3D_OT_dolly", MIDDLEMOUSE, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
WM_keymap_verify_item(keymap, "VIEW3D_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
WM_keymap_verify_item(keymap, "VIEW3D_OT_view_center_cursor", PADPERIOD, KM_PRESS, KM_CTRL, 0);
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index 522ec117b37..ebbe2fced62 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -93,24 +93,38 @@ void view3d_set_viewcontext(bContext *C, ViewContext *vc)
vc->obedit= CTX_data_edit_object(C);
}
-void view3d_get_view_aligned_coordinate(ViewContext *vc, float *fp, short mval[2])
+
+int view3d_get_view_aligned_coordinate(ViewContext *vc, float fp[3], const short mval[2], const short do_fallback)
{
float dvec[3];
- short mx, my;
-
- mx= mval[0];
- my= mval[1];
-
- project_short_noclip(vc->ar, fp, mval);
-
+ short mval_cpy[2];
+
+ mval_cpy[0]= mval[0];
+ mval_cpy[1]= mval[1];
+
+ project_short_noclip(vc->ar, fp, mval_cpy);
+
initgrabz(vc->rv3d, fp[0], fp[1], fp[2]);
-
- if(mval[0]!=IS_CLIPPED) {
- window_to_3d_delta(vc->ar, dvec, mval[0]-mx, mval[1]-my);
+
+ if(mval_cpy[0]!=IS_CLIPPED) {
+ window_to_3d_delta(vc->ar, dvec, mval_cpy[0]-mval[0], mval_cpy[1]-mval[1]);
sub_v3_v3(fp, dvec);
+
+ return TRUE;
+ }
+ else {
+ /* fallback to the view center */
+ if(do_fallback) {
+ negate_v3_v3(fp, vc->rv3d->ofs);
+ return view3d_get_view_aligned_coordinate(vc, fp, mval, FALSE);
+ }
+ else {
+ return FALSE;
+ }
}
}
+
/*
* ob == NULL if you want global matrices
* */
@@ -947,7 +961,7 @@ static void deselectall_except(Scene *scene, Base *b) /* deselect all except b
}
}
-static Base *mouse_select_menu(bContext *C, ViewContext *vc, unsigned int *buffer, int hits, short *mval, short extend)
+static Base *mouse_select_menu(bContext *C, ViewContext *vc, unsigned int *buffer, int hits, const short mval[2], short extend)
{
short baseCount = 0;
short ok;
@@ -1033,7 +1047,7 @@ static Base *mouse_select_menu(bContext *C, ViewContext *vc, unsigned int *buffe
/* we want a select buffer with bones, if there are... */
/* so check three selection levels and compare */
-static short mixed_bones_object_selectbuffer(ViewContext *vc, unsigned int *buffer, short *mval)
+static short mixed_bones_object_selectbuffer(ViewContext *vc, unsigned int *buffer, const short *mval)
{
rcti rect;
int offs;
@@ -1090,7 +1104,7 @@ static short mixed_bones_object_selectbuffer(ViewContext *vc, unsigned int *buff
}
/* returns basact */
-static Base *mouse_select_eval_buffer(ViewContext *vc, unsigned int *buffer, int hits, short *mval, Base *startbase, int has_bones)
+static Base *mouse_select_eval_buffer(ViewContext *vc, unsigned int *buffer, int hits, const short *mval, Base *startbase, int has_bones)
{
Scene *scene= vc->scene;
View3D *v3d= vc->v3d;
@@ -1183,7 +1197,7 @@ static Base *mouse_select_eval_buffer(ViewContext *vc, unsigned int *buffer, int
}
/* mval comes from event->mval, only use within region handlers */
-Base *ED_view3d_give_base_under_cursor(bContext *C, short *mval)
+Base *ED_view3d_give_base_under_cursor(bContext *C, const short *mval)
{
ViewContext vc;
Base *basact= NULL;
@@ -1208,7 +1222,7 @@ Base *ED_view3d_give_base_under_cursor(bContext *C, short *mval)
}
/* mval is region coords */
-static int mouse_select(bContext *C, short *mval, short extend, short obcenter, short enumerate)
+static int mouse_select(bContext *C, const short *mval, short extend, short obcenter, short enumerate)
{
ViewContext vc;
ARegion *ar= CTX_wm_region(C);
@@ -1926,7 +1940,7 @@ static void mesh_circle_doSelectFace(void *userData, BMFace *efa, int x, int y,
}
}
-static void mesh_circle_select(ViewContext *vc, int select, short *mval, float rad)
+static void mesh_circle_select(ViewContext *vc, int select, const short *mval, float rad)
{
ToolSettings *ts= vc->scene->toolsettings;
int bbsel;
@@ -1971,7 +1985,7 @@ static void mesh_circle_select(ViewContext *vc, int select, short *mval, float r
EDBM_selectmode_flush(vc->em);
}
-static void paint_facesel_circle_select(ViewContext *vc, int select, short *mval, float rad)
+static void paint_facesel_circle_select(ViewContext *vc, int select, const short *mval, float rad)
{
Object *ob= vc->obact;
Mesh *me = ob?ob->data:NULL;
@@ -2018,7 +2032,7 @@ static void nurbscurve_circle_doSelect(void *userData, Nurb *UNUSED(nu), BPoint
}
}
}
-static void nurbscurve_circle_select(ViewContext *vc, int select, short *mval, float rad)
+static void nurbscurve_circle_select(ViewContext *vc, int select, const short *mval, float rad)
{
struct {ViewContext *vc; short select, mval[2]; float radius; } data;
@@ -2045,7 +2059,7 @@ static void latticecurve_circle_doSelect(void *userData, BPoint *bp, int x, int
bp->f1 = data->select?(bp->f1|SELECT):(bp->f1&~SELECT);
}
}
-static void lattice_circle_select(ViewContext *vc, int select, short *mval, float rad)
+static void lattice_circle_select(ViewContext *vc, int select, const short *mval, float rad)
{
struct {ViewContext *vc; short select, mval[2]; float radius; } data;
@@ -2077,7 +2091,7 @@ static short pchan_circle_doSelectJoint(void *userData, bPoseChannel *pchan, int
}
return 0;
}
-static void pose_circle_select(ViewContext *vc, int select, short *mval, float rad)
+static void pose_circle_select(ViewContext *vc, int select, const short *mval, float rad)
{
struct {ViewContext *vc; short select, mval[2]; float radius; } data;
bPose *pose = vc->obact->pose;
@@ -2145,7 +2159,7 @@ static short armature_circle_doSelectJoint(void *userData, EditBone *ebone, int
}
return 0;
}
-static void armature_circle_select(ViewContext *vc, int select, short *mval, float rad)
+static void armature_circle_select(ViewContext *vc, int select, const short *mval, float rad)
{
struct {ViewContext *vc; short select, mval[2]; float radius; } data;
bArmature *arm= vc->obedit->data;
@@ -2204,7 +2218,7 @@ static void armature_circle_select(ViewContext *vc, int select, short *mval, flo
/** Callbacks for circle selection in Editmode */
-static void obedit_circle_select(ViewContext *vc, short select, short *mval, float rad)
+static void obedit_circle_select(ViewContext *vc, short select, const short *mval, float rad)
{
switch(vc->obedit->type) {
case OB_MESH:
diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c
index 61118805a4e..14e46a2c65b 100644
--- a/source/blender/editors/space_view3d/view3d_snap.c
+++ b/source/blender/editors/space_view3d/view3d_snap.c
@@ -839,9 +839,7 @@ static int snap_curs_to_sel(bContext *C, wmOperator *UNUSED(op))
VECCOPY(curs, centroid);
}
else {
- curs[0]= (min[0]+max[0])/2;
- curs[1]= (min[1]+max[1])/2;
- curs[2]= (min[2]+max[2])/2;
+ mid_v3_v3v3(curs, min, max);
}
MEM_freeN(transvmain);
transvmain= NULL;
@@ -879,9 +877,7 @@ static int snap_curs_to_sel(bContext *C, wmOperator *UNUSED(op))
VECCOPY(curs, centroid);
}
else {
- curs[0]= (min[0]+max[0])/2;
- curs[1]= (min[1]+max[1])/2;
- curs[2]= (min[2]+max[2])/2;
+ mid_v3_v3v3(curs, min, max);
}
}
}
@@ -1022,4 +1018,3 @@ int minmax_verts(Object *obedit, float *min, float *max)
return 1;
}
-
diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c
index 1d93f5ebc83..124b7949658 100644
--- a/source/blender/editors/space_view3d/view3d_view.c
+++ b/source/blender/editors/space_view3d/view3d_view.c
@@ -65,7 +65,7 @@
#include "ED_armature.h"
#ifdef WITH_GAMEENGINE
-#include "SYS_System.h"
+#include "BL_System.h"
#endif
#include "view3d_intern.h" // own include
@@ -106,9 +106,7 @@ float *give_cursor(Scene *scene, View3D *v3d)
/* Gets the lens and clipping values from a camera of lamp type object */
static void object_lens_clip_settings(Object *ob, float *lens, float *clipsta, float *clipend)
-{
- if (!ob) return;
-
+{
if(ob->type==OB_LAMP ) {
Lamp *la = ob->data;
if (lens) {
@@ -137,39 +135,42 @@ static void object_lens_clip_settings(Object *ob, float *lens, float *clipsta, f
*
* The dist is not modified for this function, if NULL its assimed zero
* */
-void view3d_settings_from_ob(Object *ob, float *ofs, float *quat, float *dist, float *lens)
+void view3d_apply_mat4(float mat[][4], float *ofs, float *quat, float *dist)
{
- if (!ob) return;
-
/* Offset */
if (ofs)
- negate_v3_v3(ofs, ob->obmat[3]);
+ negate_v3_v3(ofs, mat[3]);
/* Quat */
if (quat) {
float imat[4][4];
- invert_m4_m4(imat, ob->obmat);
+ invert_m4_m4(imat, mat);
mat4_to_quat(quat, imat);
}
if (dist) {
- float tquat[4];
+ float nmat[3][3];
float vec[3];
vec[0]= 0.0f;
vec[1]= 0.0f;
vec[2]= -(*dist);
- mat4_to_quat(tquat, ob->obmat);
-
- mul_qt_v3(tquat, vec);
+ copy_m3_m4(nmat, mat);
+ normalize_m3(nmat);
+ mul_m3_v3(nmat, vec);;
sub_v3_v3(ofs, vec);
}
+}
+
+void view3d_apply_ob(Object *ob, float *ofs, float *quat, float *dist, float *lens)
+{
+ view3d_apply_mat4(ob->obmat, ofs, quat, dist);
- /* Lens */
- if (lens)
+ if (lens) {
object_lens_clip_settings(ob, lens, NULL, NULL);
+ }
}
@@ -189,10 +190,13 @@ struct SmoothViewStore {
/* will start timer if appropriate */
/* the arguments are the desired situation */
-void smooth_view(bContext *C, Object *oldcamera, Object *camera, float *ofs, float *quat, float *dist, float *lens)
+void smooth_view(bContext *C, View3D *v3d, ARegion *ar, Object *oldcamera, Object *camera, float *ofs, float *quat, float *dist, float *lens)
{
- View3D *v3d = CTX_wm_view3d(C);
- RegionView3D *rv3d= CTX_wm_region_view3d(C);
+ wmWindowManager *wm= CTX_wm_manager(C);
+ wmWindow *win= CTX_wm_window(C);
+ ScrArea *sa= CTX_wm_area(C);
+
+ RegionView3D *rv3d= ar->regiondata;
struct SmoothViewStore sms= {0};
short ok= FALSE;
@@ -210,7 +214,7 @@ void smooth_view(bContext *C, Object *oldcamera, Object *camera, float *ofs, flo
if(lens) sms.new_lens= *lens;
if (camera) {
- view3d_settings_from_ob(camera, sms.new_ofs, sms.new_quat, &sms.new_dist, &sms.new_lens);
+ view3d_apply_ob(camera, sms.new_ofs, sms.new_quat, &sms.new_dist, &sms.new_lens);
sms.to_camera= 1; /* restore view3d values in end */
}
@@ -235,7 +239,7 @@ void smooth_view(bContext *C, Object *oldcamera, Object *camera, float *ofs, flo
/* original values */
if (oldcamera) {
sms.orig_dist= rv3d->dist; // below function does weird stuff with it...
- view3d_settings_from_ob(oldcamera, sms.orig_ofs, sms.orig_quat, &sms.orig_dist, &sms.orig_lens);
+ view3d_apply_ob(oldcamera, sms.orig_ofs, sms.orig_quat, &sms.orig_dist, &sms.orig_lens);
}
else {
copy_v3_v3(sms.orig_ofs, rv3d->ofs);
@@ -280,9 +284,9 @@ void smooth_view(bContext *C, Object *oldcamera, Object *camera, float *ofs, flo
rv3d->sms= MEM_mallocN(sizeof(struct SmoothViewStore), "smoothview v3d");
*rv3d->sms= sms;
if(rv3d->smooth_timer)
- WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), rv3d->smooth_timer);
+ WM_event_remove_timer(wm, win, rv3d->smooth_timer);
/* TIMER1 is hardcoded in keymap */
- rv3d->smooth_timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER1, 1.0/100.0); /* max 30 frs/sec */
+ rv3d->smooth_timer= WM_event_add_timer(wm, win, TIMER1, 1.0/100.0); /* max 30 frs/sec */
ok= TRUE;
}
@@ -290,8 +294,6 @@ void smooth_view(bContext *C, Object *oldcamera, Object *camera, float *ofs, flo
/* if we get here nothing happens */
if(ok == FALSE) {
- ARegion *ar= CTX_wm_region(C);
-
if(sms.to_camera==0) {
copy_v3_v3(rv3d->ofs, sms.new_ofs);
copy_qt_qt(rv3d->viewquat, sms.new_quat);
@@ -300,7 +302,7 @@ void smooth_view(bContext *C, Object *oldcamera, Object *camera, float *ofs, flo
}
if(rv3d->viewlock & RV3D_BOXVIEW)
- view3d_boxview_copy(CTX_wm_area(C), ar);
+ view3d_boxview_copy(sa, ar);
ED_region_tag_redraw(ar);
}
@@ -464,19 +466,20 @@ void VIEW3D_OT_setcameratoview(wmOperatorType *ot)
static int view3d_setobjectascamera_exec(bContext *C, wmOperator *UNUSED(op))
{
View3D *v3d = CTX_wm_view3d(C);
- RegionView3D *rv3d= CTX_wm_region_view3d(C);
+ ARegion *ar= ED_view3d_context_region_unlock(C);
+ RegionView3D *rv3d= ar->regiondata; /* no NULL check is needed, poll checks */
Scene *scene= CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
if(ob) {
- Object *camera_old= (rv3d->persp == RV3D_CAMOB && scene->camera) ? scene->camera : NULL;
+ Object *camera_old= (rv3d->persp == RV3D_CAMOB) ? V3D_CAMERA_SCENE(scene, v3d) : NULL;
rv3d->persp= RV3D_CAMOB;
v3d->camera= ob;
if(v3d->scenelock)
scene->camera= ob;
if(camera_old != ob) /* unlikely but looks like a glitch when set to the same */
- smooth_view(C, camera_old, v3d->camera, rv3d->ofs, rv3d->viewquat, &rv3d->dist, &v3d->lens);
+ smooth_view(C, v3d, ar, camera_old, v3d->camera, rv3d->ofs, rv3d->viewquat, &rv3d->dist, &v3d->lens);
WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS|NC_OBJECT|ND_DRAW, CTX_data_scene(C));
}
@@ -484,13 +487,11 @@ static int view3d_setobjectascamera_exec(bContext *C, wmOperator *UNUSED(op))
return OPERATOR_FINISHED;
}
-static int region3d_unlocked_poll(bContext *C)
+int ED_operator_rv3d_unlock_poll(bContext *C)
{
- RegionView3D *rv3d= CTX_wm_region_view3d(C);
- return (rv3d && rv3d->viewlock==0);
+ return ED_view3d_context_region_unlock(C) != NULL;
}
-
void VIEW3D_OT_object_as_camera(wmOperatorType *ot)
{
@@ -501,7 +502,7 @@ void VIEW3D_OT_object_as_camera(wmOperatorType *ot)
/* api callbacks */
ot->exec= view3d_setobjectascamera_exec;
- ot->poll= region3d_unlocked_poll;
+ ot->poll= ED_operator_rv3d_unlock_poll;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -646,25 +647,25 @@ int initgrabz(RegionView3D *rv3d, float x, float y, float z)
}
/* always call initgrabz */
-void window_to_3d(ARegion *ar, float *vec, short mx, short my)
+void window_to_3d(ARegion *ar, float out[3], short mx, short my)
{
RegionView3D *rv3d= ar->regiondata;
float dx= ((float)(mx-(ar->winx/2)))*rv3d->zfac/(ar->winx/2);
float dy= ((float)(my-(ar->winy/2)))*rv3d->zfac/(ar->winy/2);
- float fz= rv3d->persmat[0][3]*vec[0]+ rv3d->persmat[1][3]*vec[1]+ rv3d->persmat[2][3]*vec[2]+ rv3d->persmat[3][3];
+ float fz= rv3d->persmat[0][3]*out[0]+ rv3d->persmat[1][3]*out[1]+ rv3d->persmat[2][3]*out[2]+ rv3d->persmat[3][3];
fz= fz/rv3d->zfac;
- vec[0]= (rv3d->persinv[0][0]*dx + rv3d->persinv[1][0]*dy+ rv3d->persinv[2][0]*fz)-rv3d->ofs[0];
- vec[1]= (rv3d->persinv[0][1]*dx + rv3d->persinv[1][1]*dy+ rv3d->persinv[2][1]*fz)-rv3d->ofs[1];
- vec[2]= (rv3d->persinv[0][2]*dx + rv3d->persinv[1][2]*dy+ rv3d->persinv[2][2]*fz)-rv3d->ofs[2];
+ out[0]= (rv3d->persinv[0][0]*dx + rv3d->persinv[1][0]*dy+ rv3d->persinv[2][0]*fz)-rv3d->ofs[0];
+ out[1]= (rv3d->persinv[0][1]*dx + rv3d->persinv[1][1]*dy+ rv3d->persinv[2][1]*fz)-rv3d->ofs[1];
+ out[2]= (rv3d->persinv[0][2]*dx + rv3d->persinv[1][2]*dy+ rv3d->persinv[2][2]*fz)-rv3d->ofs[2];
}
/* always call initgrabz */
/* only to detect delta motion */
-void window_to_3d_delta(ARegion *ar, float *vec, short mx, short my)
+void window_to_3d_delta(ARegion *ar, float out[3], short mx, short my)
{
RegionView3D *rv3d= ar->regiondata;
float dx, dy;
@@ -672,15 +673,15 @@ void window_to_3d_delta(ARegion *ar, float *vec, short mx, short my)
dx= 2.0f*mx*rv3d->zfac/ar->winx;
dy= 2.0f*my*rv3d->zfac/ar->winy;
- vec[0]= (rv3d->persinv[0][0]*dx + rv3d->persinv[1][0]*dy);
- vec[1]= (rv3d->persinv[0][1]*dx + rv3d->persinv[1][1]*dy);
- vec[2]= (rv3d->persinv[0][2]*dx + rv3d->persinv[1][2]*dy);
+ 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);
}
/* doesn't rely on initgrabz */
/* for perspective view, get the vector direction to
* the mouse cursor as a normalized vector */
-void window_to_3d_vector(ARegion *ar, float *vec, short mx, short my)
+void window_to_3d_vector(ARegion *ar, float out[3], short mx, short my)
{
RegionView3D *rv3d= ar->regiondata;
float dx, dy;
@@ -692,11 +693,11 @@ void window_to_3d_vector(ARegion *ar, float *vec, short mx, short my)
/* normalize here so vecs are proportional to eachother */
normalize_v3_v3(viewvec, rv3d->viewinv[2]);
- vec[0]= viewvec[0] - (rv3d->persinv[0][0]*dx + rv3d->persinv[1][0]*dy);
- vec[1]= viewvec[1] - (rv3d->persinv[0][1]*dx + rv3d->persinv[1][1]*dy);
- vec[2]= viewvec[2] - (rv3d->persinv[0][2]*dx + rv3d->persinv[1][2]*dy);
+ out[0]= viewvec[0] - (rv3d->persinv[0][0]*dx + rv3d->persinv[1][0]*dy);
+ out[1]= viewvec[1] - (rv3d->persinv[0][1]*dx + rv3d->persinv[1][1]*dy);
+ out[2]= viewvec[2] - (rv3d->persinv[0][2]*dx + rv3d->persinv[1][2]*dy);
- normalize_v3(vec);
+ normalize_v3(out);
}
float read_cached_depth(ViewContext *vc, int x, int y)
@@ -740,7 +741,7 @@ void view3d_unproject(bglMats *mats, float out[3], const short x, const short y,
}
/* use view3d_get_object_project_mat to get projecting mat */
-void view3d_project_float(ARegion *ar, float *vec, float *adr, float mat[4][4])
+void view3d_project_float(ARegion *ar, const float vec[3], float adr[2], float mat[4][4])
{
float vec4[4];
@@ -814,7 +815,7 @@ int boundbox_clip(RegionView3D *rv3d, float obmat[][4], BoundBox *bb)
return 0;
}
-void project_short(ARegion *ar, float *vec, short *adr) /* clips */
+void project_short(ARegion *ar, const float vec[3], short adr[2]) /* clips */
{
RegionView3D *rv3d= ar->regiondata;
float fx, fy, vec4[4];
@@ -845,7 +846,7 @@ void project_short(ARegion *ar, float *vec, short *adr) /* clips */
}
}
-void project_int(ARegion *ar, float *vec, int *adr)
+void project_int(ARegion *ar, const float vec[3], int adr[2])
{
RegionView3D *rv3d= ar->regiondata;
float fx, fy, vec4[4];
@@ -870,7 +871,7 @@ void project_int(ARegion *ar, float *vec, int *adr)
}
}
-void project_int_noclip(ARegion *ar, float *vec, int *adr)
+void project_int_noclip(ARegion *ar, const float vec[3], int adr[2])
{
RegionView3D *rv3d= ar->regiondata;
float fx, fy, vec4[4];
@@ -894,7 +895,7 @@ void project_int_noclip(ARegion *ar, float *vec, int *adr)
}
}
-void project_short_noclip(ARegion *ar, float *vec, short *adr)
+void project_short_noclip(ARegion *ar, const float vec[3], short adr[2])
{
RegionView3D *rv3d= ar->regiondata;
float fx, fy, vec4[4];
@@ -920,7 +921,7 @@ void project_short_noclip(ARegion *ar, float *vec, short *adr)
}
}
-void project_float(ARegion *ar, float *vec, float *adr)
+void project_float(ARegion *ar, const float vec[3], float adr[2])
{
RegionView3D *rv3d= ar->regiondata;
float vec4[4];
@@ -937,7 +938,7 @@ void project_float(ARegion *ar, float *vec, float *adr)
}
}
-void project_float_noclip(ARegion *ar, float *vec, float *adr)
+void project_float_noclip(ARegion *ar, const float vec[3], float adr[2])
{
RegionView3D *rv3d= ar->regiondata;
float vec4[4];
@@ -960,25 +961,25 @@ void project_float_noclip(ARegion *ar, float *vec, float *adr)
int get_view3d_ortho(View3D *v3d, RegionView3D *rv3d)
{
- Camera *cam;
-
- if(rv3d->persp==RV3D_CAMOB) {
- if(v3d->camera && v3d->camera->type==OB_CAMERA) {
- cam= v3d->camera->data;
-
- if(cam && cam->type==CAM_ORTHO)
- return 1;
- else
- return 0;
- }
- else
- return 0;
- }
-
- if(rv3d->persp==RV3D_ORTHO)
- return 1;
-
- return 0;
+ Camera *cam;
+
+ if(rv3d->persp==RV3D_CAMOB) {
+ if(v3d->camera && v3d->camera->type==OB_CAMERA) {
+ cam= v3d->camera->data;
+
+ if(cam && cam->type==CAM_ORTHO)
+ return 1;
+ else
+ return 0;
+ }
+ else
+ return 0;
+ }
+
+ if(rv3d->persp==RV3D_ORTHO)
+ return 1;
+
+ return 0;
}
/* copies logic of get_view3d_viewplane(), keep in sync */
@@ -1208,14 +1209,14 @@ static void obmat_to_viewmat(View3D *v3d, RegionView3D *rv3d, Object *ob, short
rv3d->persp=RV3D_PERSP;
rv3d->dist= 0.0;
- view3d_settings_from_ob(v3d->camera, rv3d->ofs, NULL, NULL, &v3d->lens);
- smooth_view(NULL, NULL, NULL, orig_ofs, new_quat, &orig_dist, &orig_lens); // XXX
+ view3d_apply_ob(v3d->camera, rv3d->ofs, NULL, NULL, &v3d->lens);
+ smooth_view(NULL, NULL, NULL, NULL, NULL, orig_ofs, new_quat, &orig_dist, &orig_lens); // XXX
rv3d->persp=RV3D_CAMOB; /* just to be polite, not needed */
} else {
mat3_to_quat( new_quat,tmat);
- smooth_view(NULL, NULL, NULL, NULL, new_quat, NULL, NULL); // XXX
+ smooth_view(NULL, NULL, NULL, NULL, NULL, NULL, new_quat, NULL, NULL); // XXX
}
} else {
mat3_to_quat( rv3d->viewquat,tmat);
@@ -1691,6 +1692,7 @@ void VIEW3D_OT_localview(wmOperatorType *ot)
/* api callbacks */
ot->exec= localview_exec;
+ ot->flag= OPTYPE_UNDO; /* localview changes object layer bitflags */
ot->poll= ED_operator_view3d_active;
}
@@ -1783,9 +1785,6 @@ static void game_set_commmandline_options(GameData *gm)
}
}
-/* maybe we need this defined somewhere else */
-extern void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *cam_frame, int always_use_expand_framing);
-
#endif // WITH_GAMEENGINE
static int game_engine_poll(bContext *C)
@@ -1950,11 +1949,11 @@ void view3d_align_axis_to_vector(View3D *v3d, RegionView3D *rv3d, int axisidx, f
copy_v3_v3(orig_ofs, rv3d->ofs);
rv3d->persp= RV3D_PERSP;
rv3d->dist= 0.0;
- view3d_settings_from_ob(v3d->camera, rv3d->ofs, NULL, NULL, &v3d->lens);
- smooth_view(NULL, NULL, NULL, orig_ofs, new_quat, &orig_dist, &orig_lens); // XXX
+ view3d_apply_ob(v3d->camera, rv3d->ofs, NULL, NULL, &v3d->lens);
+ smooth_view(NULL, NULL, NULL, NULL, NULL, orig_ofs, new_quat, &orig_dist, &orig_lens); // XXX
} else {
if (rv3d->persp==RV3D_CAMOB) rv3d->persp= RV3D_PERSP; /* switch out of camera mode */
- smooth_view(NULL, NULL, NULL, NULL, new_quat, NULL, NULL); // XXX
+ smooth_view(NULL, NULL, NULL, NULL, NULL, NULL, new_quat, NULL, NULL); // XXX
}
}